Skip to content

Commit

Permalink
Adding API getAvailableLibraries() => {"Modelica","ModelicaServices",…
Browse files Browse the repository at this point in the history
…...}

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15154 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 12, 2013
1 parent 05ddf10 commit df4c38d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
12 changes: 11 additions & 1 deletion Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -1205,7 +1205,7 @@ function getModelicaPath "Get the Modelica Library Path."
external "builtin";
annotation(Documentation(info="<html>
<p>The MODELICAPATH is list of paths to search when trying to <a href=\"modelica://OpenModelica.Scripting.loadModel\">load a library</a>. It is a string separated by colon (:) on all OSes except Windows, which uses semicolon (;).</p>
<p>To override the default path (<a href=\"modelica://OpenModelica.Scripting.getModelicaPath\">getInstallationDirectoryPath()</a>/lib/omlibrary/:~/.openmodelica/libraries/), set the environment variable OPENMODELICALIBRARY=...</p>
<p>To override the default path (<a href=\"modelica://OpenModelica.Scripting.getModelicaPath\">getModelicaPath()</a>/lib/omlibrary/:~/.openmodelica/libraries/), set the environment variable OPENMODELICALIBRARY=...</p>
</html>"),
preferredView="text");
end getModelicaPath;
Expand Down Expand Up @@ -2727,6 +2727,16 @@ annotation(
preferredView="text");
end searchClassNames;

function getAvailableLibraries
output String[:] libraries;
external "builtin";
annotation(
Documentation(info="<html>
Looks for all libraries that are visible from the <a href=\"modelica://OpenModelica.Scripting.getModelicaPath\">getModelicaPath()</a>.
</html>"),
preferredView="text");
end getAvailableLibraries;

annotation(preferredView="text");
end Scripting;

Expand Down
20 changes: 16 additions & 4 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -871,7 +871,7 @@ algorithm
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,compileDir,libDir,exeDir,configDir,from,to,
legendStr, gridStr, logXStr, logYStr, x1Str, x2Str, y1Str, y2Str,scriptFile,logFile, simflags2, outputFile,
systemPath, gccVersion;
systemPath, gccVersion, gd, strlinearizeTime;
list<Values.Value> vals;
Absyn.Path path,classpath,className,baseClassPath;
SCode.Program scodeP,sp;
Expand Down Expand Up @@ -899,9 +899,7 @@ algorithm
list<FMI.ModelVariables> fmiModelVariablesList, fmiModelVariablesList1;
FMI.ExperimentAnnotation fmiExperimentAnnotation;
FMI.Info fmiInfo;
list<String> vars_1,args,strings,strs,strs1,strs2,visvars;
list<String> postOptModStrings,postOptModStringsOrg;
String strlinearizeTime;
list<String> vars_1,args,strings,strs,strs1,strs2,visvars,postOptModStrings,postOptModStringsOrg,mps,files,dirs;
Real timeTotal,timeSimulation,timeStamp,val,x1,x2,y1,y2,r, linearizeTime;
Interactive.Statements istmts;
Boolean have_corba, bval, anyCode, b, b1, b2, externalWindow, legend, grid, logX, logY, gcc_res, omcfound, rm_res, touch_res, uname_res, extended, insensitive,ifcpp, sort, builtin, showProtected, inputConnectors, outputConnectors;
Expand Down Expand Up @@ -2088,6 +2086,20 @@ algorithm
then
(cache,ValuesUtil.makeArray(vals),st);

case (cache,env,"getAvailableLibraries",{},st,_)
equation
mp = Settings.getModelicaPath(Config.getRunningTestsuite());
gd = System.groupDelimiter();
mps = System.strtok(mp, gd);
files = List.flatten(List.map(mps, System.moFiles));
dirs = List.flatten(List.map(mps, System.subDirectories));
files = List.map(List.map1(listAppend(files,dirs), System.strtok, ". "), List.first);
files = List.sort(files,Util.strcmpBool);
files = List.sortedUnique(files, stringEqual);
v = ValuesUtil.makeArray(List.map(files, ValuesUtil.makeString));
then
(cache,v,st);

case (cache,env,"getAstAsCorbaString",{Values.STRING("<interactive>")},st as Interactive.SYMBOLTABLE(ast=p),_)
equation
Print.clearBuf();
Expand Down
43 changes: 43 additions & 0 deletions Compiler/Util/List.mo
Expand Up @@ -956,6 +956,49 @@ algorithm
end match;
end sortedFilterDuplicatesWork;

public function sortedUnique
"Takes a list of elements and returns a list with duplicates removed, so that each element in the new list is unique. Assumes that the input is sorted."
input list<ElementType> inList;
input CompareFunc inCompFunc "Equality comparator";
output list<ElementType> duplicates;

partial function CompareFunc
input ElementType inElement1;
input ElementType inElement2;
output Boolean outRes;
end CompareFunc;
algorithm
duplicates := sortedUniqueWork(inList,inCompFunc,{});
end sortedUnique;

protected function sortedUniqueWork
"Checks if the list has any duplicates in it"
input list<ElementType> inList;
input CompareFunc inCompFunc "Equality comparator";
input list<ElementType> inAcc;
output list<ElementType> duplicates;

partial function CompareFunc
input ElementType inElement1;
input ElementType inElement2;
output Boolean outRes;
end CompareFunc;
algorithm
duplicates := match(inList, inCompFunc, inAcc)
local
ElementType e1,e2;
list<ElementType> rest;
Boolean b;

case ({}, _, _) then listReverse(inAcc);
case (e1::{}, _, _) then listReverse(e1::inAcc);
case (e1::(rest as e2::_), _, _)
equation
b = inCompFunc(e1,e2);
then sortedUniqueWork(rest, inCompFunc, consOnTrue(not b, e1, inAcc));
end match;
end sortedUniqueWork;

protected function merge
"Helper function to sort, merges two sorted lists."
input list<ElementType> inLeft;
Expand Down

0 comments on commit df4c38d

Please sign in to comment.