Skip to content

Commit

Permalink
- Added API call reopenStandardStream(OpenModelica.Scripting.Standard…
Browse files Browse the repository at this point in the history
…Stream.stdin,"program.txt"); for MM course

  + This way, we do not need to redirect stdin in eclipse


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9854 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Sep 17, 2011
1 parent 1a251ee commit c77d682
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -1335,5 +1335,13 @@ function solveLinearSystem
external "builtin";
end solveLinearSystem;

type StandardStream = enumeration(stdin,stdout,stderr);
function reopenStandardStream
input StandardStream _stream;
input String filename;
output Boolean success;
external "builtin";
end reopenStandardStream;

end Scripting;
end OpenModelica;
6 changes: 6 additions & 0 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -1211,6 +1211,12 @@ algorithm
then
(cache,Values.STRING(str),st);

case (cache,env,"reopenStandardStream",{Values.ENUM_LITERAL(index=i),Values.STRING(filename)},st,msg)
equation
b = System.reopenStandardStream(i-1,filename);
then
(cache,Values.BOOL(b),st);

case (cache,env,"setDataPort",{Values.INTEGER(i)},st,msg)
equation
System.setDataPort(i);
Expand Down
7 changes: 7 additions & 0 deletions Compiler/Util/System.mo
Expand Up @@ -867,4 +867,11 @@ public function lpsolve55
external "C" info=SystemImpl__lpsolve55(A,B,intIndices,X) annotation(Library = {"omcruntime"});
end lpsolve55;

public function reopenStandardStream
input Integer _stream "stdin,stdout,stderr";
input String filename;
output Boolean success;
external "C" success=SystemImpl__reopenStandardStream(_stream,filename) annotation(Library = {"omcruntime"});
end reopenStandardStream;

end System;
7 changes: 7 additions & 0 deletions Compiler/runtime/System_rml.c
Expand Up @@ -2081,3 +2081,10 @@ RML_BEGIN_LABEL(System__getLoadModelPath)
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__reopenStandardStream)
{
rmlA0 = mk_icon(SystemImpl__reopenStandardStream(RML_UNTAGFIXNUM(rmlA0),RML_STRINGDATA(rmlA1)));
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
20 changes: 20 additions & 0 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -1541,6 +1541,26 @@ extern void SystemImpl_tmpTickResetIndex(int start, int index)
tmp_tick_no[index] = start;
}

extern int SystemImpl__reopenStandardStream(int id,const char *filename)
{
FILE *file;
const char* mode;
const char* streamName;
switch (id) {
case 0: file=stdin;mode="r";streamName="stdin";break;
case 1: file=stdout;mode="w";streamName="stdout";break;
case 2: file=stderr;mode="w";streamName="stderr";break;
default: return 0;
}
file = freopen(filename,mode,file);
if (file==NULL) {
const char *tokens[4] = {strerror(errno),streamName,mode,filename};
c_add_message(-1,"SCRIPTING","ERROR","freopen(%s,%s,%s) failed: %s",tokens,4);
return 0;
}
return 1;
}

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit c77d682

Please sign in to comment.