Skip to content

Commit

Permalink
- Added scripting function readFileShowLineNumbers
Browse files Browse the repository at this point in the history
  - It's implemented in OpenModelica script instead of MetaModelica itself


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7854 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 2, 2011
1 parent 4535d12 commit b21bfef
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
23 changes: 23 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -634,6 +634,22 @@ function readFile
external "builtin";
end readFile;

function readFileShowLineNumbers "Prefixes each line in the file with <n>:, where n is the line number"
input String fileName;
output String out;
protected
String str,line,nl:="
";
Integer num:=1;
algorithm
str := readFile(fileName);
out := "";
for line in strtok(str,nl) loop
out := out + String(num) + ": " + line + nl;
num := num + 1;
end for;
end readFileShowLineNumbers;

function readFileNoNumeric
"Returns the contents of the file, with anything resembling a (real) number stripped out, and at the end adding:
Filter count from number domain: n.
Expand Down Expand Up @@ -888,5 +904,12 @@ function val
external "builtin";
end val;

function strtok
input String string;
input String token;
output String[:] strings;
external "builtin";
end strtok;

end Scripting;
end OpenModelica;
7 changes: 7 additions & 0 deletions Compiler/FrontEnd/ValuesUtil.mo
Expand Up @@ -1872,6 +1872,13 @@ algorithm
v := Values.INTEGER(i);
end makeInteger;

public function makeString "Creates a string value "
input String s;
output Value v;
algorithm
v := Values.STRING(s);
end makeString;

public function makeArray "function: makeArray

Construct an array of a list of Values.
Expand Down
8 changes: 7 additions & 1 deletion Compiler/Script/CevalScript.mo
Expand Up @@ -629,7 +629,7 @@ algorithm
list<SCode.Class> scodeP,sp,fp;
list<Env.Frame> env;
SCode.Class c;
String s1,str,varid,cmd,executable,method_str,outputFormat_str,initfilename,cit,pd,executableSuffixedExe,sim_call,result_file,filename_1,filename,omhome_1,plotCmd,tmpPlotFile,call,str_1,mp,pathstr,name,cname,fileNamePrefix_s,str1,errMsg,errorStr,uniqueStr,interpolation, title,xLabel,yLabel,filename2,varNameStr,xml_filename,xml_contents,visvar_str,pwd,omhome,omlib,omcpath,os,platform,usercflags,senddata,res,workdir,gcc,confcmd,touch_file,uname,filenameprefix;
String s1,str,token,varid,cmd,executable,method_str,outputFormat_str,initfilename,cit,pd,executableSuffixedExe,sim_call,result_file,filename_1,filename,omhome_1,plotCmd,tmpPlotFile,call,str_1,mp,pathstr,name,cname,fileNamePrefix_s,str1,errMsg,errorStr,uniqueStr,interpolation, title,xLabel,yLabel,filename2,varNameStr,xml_filename,xml_contents,visvar_str,pwd,omhome,omlib,omcpath,os,platform,usercflags,senddata,res,workdir,gcc,confcmd,touch_file,uname,filenameprefix;
DAE.ComponentRef cr,cref,classname;
Interactive.InteractiveSymbolTable newst,st_1;
Absyn.Program p,pnew,newp,ptot;
Expand Down Expand Up @@ -1325,6 +1325,12 @@ algorithm
case (cache,env,"getAstAsCorbaString",_,st,msg)
then
(cache,Values.STRING("Failed to output string"),st);

case (cache,env,"strtok",{Values.STRING(str),Values.STRING(token)},st,msg)
equation
vals = Util.listMap(System.strtok(str,token), ValuesUtil.makeString);
i = listLength(vals);
then (cache,Values.ARRAY(vals,{i}),st);

/* Checks the installation of OpenModelica and tries to find common errors */
case (cache,env,"checkSettings",{},st,msg)
Expand Down
8 changes: 4 additions & 4 deletions Compiler/Util/System.mo
Expand Up @@ -129,11 +129,11 @@ public function tolower
end tolower;

public function strtok
input String inString1;
input String inString2;
output list<String> outStringLst;
input String string;
input String token;
output list<String> strings;

external "C" outStringLst=System_strtok(inString1,inString2) annotation(Library = "omcruntime");
external "C" outStringLst=System_strtok(string,token) annotation(Library = "omcruntime");
end strtok;

public function substring
Expand Down

0 comments on commit b21bfef

Please sign in to comment.