Skip to content

Commit

Permalink
implemented builtin command mkdir() to avoid trouble using system("mk…
Browse files Browse the repository at this point in the history
…dir -p dir")

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17161 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Henning Kiel committed Sep 10, 2013
1 parent 4988564 commit 2fa4b4d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
14 changes: 11 additions & 3 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ type FileType = enumeration(NoFile, RegularFile, Directory, SpecialFile);
function stat
input String name;
output FileType fileType;
external "C" fileType=ModelicaInternal_stat(name) annotation(Library="ModelicaExternalC");
external "C" fileType = ModelicaInternal_stat(name) annotation(Library="ModelicaExternalC");
end stat;

end Internal;
Expand Down Expand Up @@ -1622,6 +1622,14 @@ external "builtin";
annotation(preferredView="text");
end cd;

function mkdir "create directory of given path (which may be either relative or absolute)
returns true if directory was created or already exists."
input String newDirectory;
output Boolean success;
external "builtin";
annotation(preferredView="text");
end mkdir;

function checkModel "Checks a model and returns number of variables and equations."
input TypeName className;
output String result;
Expand Down Expand Up @@ -3903,11 +3911,11 @@ div.system-message p.system-message-title { font-weight: bold; }
<div id=\"wikipage\">
<div style=\"float: right; margin: 0 1em\" class=\"wikipage\">
<blockquote>
<p> <a class=\"wiki\" href=
<p>&larr; <a class=\"wiki\" href=
\"https://trac.openmodelica.org/OpenModelica/wiki/ReleaseNotes/1.8.1\">
1.8.1</a> | <a class=\"missing wiki\" href=
\"https://trac.openmodelica.org/OpenModelica/wiki/ReleaseNotes/Future\"
rel=\"nofollow\">Future?</a> </p>
rel=\"nofollow\">Future?</a> &rarr;</p>
</blockquote>
</div>
<div style=
Expand Down
12 changes: 12 additions & 0 deletions Compiler/Script/CevalScript.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,18 @@ algorithm
then
(cache,Values.STRING(res),st);

case (cache,env,"mkdir",{Values.STRING(str)},st,_)
equation
true = System.directoryExists(str);
then
(cache,Values.BOOL(true),st);

case (cache,env,"mkdir",{Values.STRING(str)},st,_)
equation
b = System.createDirectory(str);
then
(cache,Values.BOOL(b),st);

case (cache,env,"getVersion",{Values.CODE(Absyn.C_TYPENAME(Absyn.IDENT("OpenModelica")))},st,_)
equation
str_1 = Settings.getVersionNr();
Expand Down
6 changes: 6 additions & 0 deletions Compiler/Util/System.mo
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ public function cd
external "C" outInteger=chdir(inString) annotation(Library = "omcruntime");
end cd;

public function createDirectory
input String inString;
output Boolean outBool;
external "C" outBool=SystemImpl__createDirectory(inString) annotation(Library = "omcruntime");
end createDirectory;

public function pwd
output String outString;
external "C" outString=SystemImpl__pwd() annotation(Library = "omcruntime");
Expand Down
10 changes: 9 additions & 1 deletion Compiler/runtime/System_rml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,14 @@ RML_BEGIN_LABEL(System__directoryExists)
}
RML_END_LABEL

RML_BEGIN_LABEL(System__createDirectory)
{
const char* str = RML_STRINGDATA(rmlA0);
rmlA0 = (void*) mk_icon(SystemImpl__createDirectory(str));
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__userIsRoot)
{
rmlA0 = mk_icon(CONFIG_USER_IS_ROOT);
Expand Down Expand Up @@ -2205,7 +2213,7 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__forkCall)
{
c_add_message(-1,ErrorType_scripting,ErrorLevel_error,gettext("Fork is not available when OpenModelica is compiled using RML"),NULL,0);
c_add_message(-1,ErrorType_scripting,ErrorLevel_error,gettext("Fork is not available when OpenModelica is compiled using RML"),NULL,0);
RML_TAILCALLK(rmlFC);
}
RML_END_LABEL
Expand Down
19 changes: 19 additions & 0 deletions Compiler/runtime/systemimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,25 @@ extern int SystemImpl__directoryExists(const char *str)
#endif
}

extern int SystemImpl__createDirectory(const char *str)
{
int rv;

#if defined(__MINGW32__) || defined(_MSC_VER)
rv = mkdir(str);
#else
rv = mkdir(str, S_IRWXU);
#endif
if (rv == -1)
{
return 0;
}
else
{
return 1;
}
}

char* SystemImpl__readFileNoNumeric(const char* filename)
{
char* buf, *bufRes;
Expand Down

0 comments on commit 2fa4b4d

Please sign in to comment.