Skip to content

Commit

Permalink
- Changed systemimpl.c to not use OPENMODELICAHOME during the init call.
Browse files Browse the repository at this point in the history
- Instead, we use Main.main to check for OPENMODELICAHOME (and set mingw paths).
- Updated System.setEnv to take a boolean as third argument instad of int.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5359 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Apr 23, 2010
1 parent c1ab7db commit 84734ff
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Compiler/Interactive.mo
Expand Up @@ -1465,7 +1465,7 @@ algorithm
lstVarVal = iv,compiledFunctions = cf,
loadedFiles = lf))) /* adrpo added 2005-11-24 */
equation
0 = System.setEnv(name, value, 1) "overwrite" ;
0 = System.setEnv(name, value, true);
then
("Ok",st);

Expand All @@ -1477,7 +1477,7 @@ algorithm
lstVarVal = iv,compiledFunctions = cf,
loadedFiles = lf))) /* adrpo added 2005-11-24 */
equation
rest = System.setEnv(name, value, 1) "overwrite" ;
rest = System.setEnv(name, value, true);
(rest == 0) = false;
then
("error",st);
Expand Down
26 changes: 25 additions & 1 deletion Compiler/Main.mo
Expand Up @@ -1184,10 +1184,24 @@ algorithm
String ver_str,errstr;
list<String> args_1,args;
Boolean ismode,icmode,imode,imode_1;
String s,str;
String s,str,omhome,oldpath,newpath;
Interactive.InteractiveSymbolTable symbolTable;
String omhome;

// Setup mingw path only once.
case _
equation
omhome = System.readEnv("OPENMODELICAHOME");
true = "Windows_NT" ==& System.os();
oldpath = System.readEnv("PATH");
newpath = Util.stringAppendList({omhome,"\\mingw\\bin;",omhome,"\\lib;",oldpath});
_ = System.setEnv("PATH",newpath,true);
then fail();

case args as _::_
equation
_ = System.readEnv("OPENMODELICAHOME");

args_1 = RTOpts.args(args);

// we need this as we get the arguments in reverse from RTOpts.args
Expand Down Expand Up @@ -1215,6 +1229,7 @@ algorithm
();
case args as _::_
equation
_ = System.readEnv("OPENMODELICAHOME");
failure(args_1 = RTOpts.args(args));
printUsage();
then ();
Expand All @@ -1224,6 +1239,7 @@ algorithm
then ();
case _
equation
_ = System.readEnv("OPENMODELICAHOME");
print("# Error encountered! Exiting...\n");
print("# Please check the error message and the flags.\n");
errstr = Print.getErrorString();
Expand All @@ -1232,6 +1248,14 @@ algorithm
print(ErrorExt.printMessagesStr()); print("\n");
then
fail();

case _
equation
failure(_ = System.readEnv("OPENMODELICAHOME"));
print("Error: OPENMODELICAHOME was not set.\n");
print(" Read the documentation for instructions on how to set it properly.\n");
print(" Most OpenModelica release distributions have scripts that set OPENMODELICAHOME for you.\n\n");
then fail();
end matchcontinue;
end main;
end Main;
Expand Down
16 changes: 9 additions & 7 deletions Compiler/System.mo
Expand Up @@ -308,10 +308,10 @@ end readEnv;



public function setEnv
input String inString1;
input String inString2;
input Integer inInteger3;
public function setEnv ""
input String varName;
input String value;
input Boolean overwrite "is always true on Windows, so recommended to always call it using true";
output Integer outInteger;

external "C" ;
Expand Down Expand Up @@ -530,10 +530,12 @@ end isIdenticalFile;

public function os "Returns a string with the operating system name

For linux : 'linux'

For Windowns : 'Windows_NT' (the name of env var OS )
For linux: 'linux'
For OSX: 'linux'
For Windows : 'Windows_NT' (the name of env var OS )

Why it returns linux for OSX, we have no clue. But it does, so let's
document it.
"
output String str;
external "C" ;
Expand Down
30 changes: 2 additions & 28 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -218,12 +218,9 @@ void System_5finit(void)
{
char* path;
char* newPath;
char* omhome;
char* mingwpath;
char* qthome;

last_ptr_index = -1;
memset(ptr_vector, 0, sizeof(ptr_vector));
last_ptr_index = -1;
memset(ptr_vector, 0, sizeof(ptr_vector));

set_cc("g++");
set_cxx("g++");
Expand All @@ -246,23 +243,6 @@ void System_5finit(void)
#endif
set_ldflags("-lc_runtime");
path = getenv("PATH");
omhome = getenv("OPENMODELICAHOME");
if (omhome) {
mingwpath = malloc(2*strlen(omhome)+25);
sprintf(mingwpath,"%s\\mingw\\bin;%s\\lib", omhome, omhome);
if (strncmp(mingwpath,path,strlen(mingwpath))!=0) {
newPath = malloc(strlen(path)+strlen(mingwpath)+10);
sprintf(newPath,"PATH=%s;%s",mingwpath,path);
_putenv(newPath);
free(newPath);
}
free(mingwpath);
} else {
fprintf(stderr, "Error: OPENMODELICAHOME was not set.\n");
fprintf(stderr, " Read the documentation for instructions on how to set it properly.\n"
fprintf(stderr, " Most OpenModelica distributions have scripts that set OPENMODELICAHOME for you.\n");
exit(1);
}

_putenv("SENDDATALIBS=-lsendData -lQtNetwork-mingw -lQtCore-mingw -lQtGui-mingw -luuid -lole32 -lws2_32");
}
Expand Down Expand Up @@ -1887,12 +1867,6 @@ void System_5finit(void)
sendDataLibs,
"SENDDATALIBS=-lsendData");
}
if (getenv("OPENMODELICAHOME") == 0) {
fprintf(stderr, "Error: OPENMODELICAHOME was not set.\n");
fprintf(stderr, " Read the documentation for instructions on how to set it properly.\n"
fprintf(stderr, " Most OpenModelica distributions have scripts that set OPENMODELICAHOME for you.\n");
exit(1);
}
/* set the SENDDATALIBS environment variable */
putenv(strdup(sendDataLibs));
}
Expand Down

0 comments on commit 84734ff

Please sign in to comment.