| 1 | within Modelica.Utilities; |
|---|
| 2 | package System "Interaction with environment" |
|---|
| 3 | extends Modelica.Icons.Library; |
|---|
| 4 | annotation ( |
|---|
| 5 | preferedView="info", |
|---|
| 6 | Documentation(info=" |
|---|
| 7 | <HTML> |
|---|
| 8 | <p> |
|---|
| 9 | This package contains functions to interact with the environment. |
|---|
| 10 | </p> |
|---|
| 11 | </HTML> |
|---|
| 12 | "), Coordsys( |
|---|
| 13 | extent=[0, 0; 417, 614], |
|---|
| 14 | grid=[1, 1], |
|---|
| 15 | component=[20, 20]), |
|---|
| 16 | Window( |
|---|
| 17 | x=0.03, |
|---|
| 18 | y=0.02, |
|---|
| 19 | width=0.42, |
|---|
| 20 | height=0.86, |
|---|
| 21 | library=1, |
|---|
| 22 | autolayout=1)); |
|---|
| 23 | |
|---|
| 24 | function getWorkDirectory "Get full path name of work directory" |
|---|
| 25 | extends Modelica.Icons.Function; |
|---|
| 26 | output String directory "Full path name of work directory"; |
|---|
| 27 | // POSIX function "getcwd" |
|---|
| 28 | external "C" directory = ModelicaInternal_getcwd(0); |
|---|
| 29 | annotation (Documentation(info="<html> |
|---|
| 30 | |
|---|
| 31 | </html>")); |
|---|
| 32 | end getWorkDirectory; |
|---|
| 33 | |
|---|
| 34 | function setWorkDirectory "Set work directory" |
|---|
| 35 | extends Modelica.Icons.Function; |
|---|
| 36 | input String directory "New work directory"; |
|---|
| 37 | // POSIX function "chdir" |
|---|
| 38 | external "C" ModelicaInternal_chdir(directory); |
|---|
| 39 | annotation (Documentation(info="<html> |
|---|
| 40 | |
|---|
| 41 | </html>")); |
|---|
| 42 | end setWorkDirectory; |
|---|
| 43 | |
|---|
| 44 | function getEnvironmentVariable "Get content of environment variable" |
|---|
| 45 | extends Modelica.Icons.Function; |
|---|
| 46 | input String name "Name of environment variable"; |
|---|
| 47 | input Boolean convertToSlash = false |
|---|
| 48 | "True, if native directory separators in 'result' shall be changed to '/'"; |
|---|
| 49 | output String content |
|---|
| 50 | "Content of environment variable (empty, if not existent)"; |
|---|
| 51 | output Boolean exist |
|---|
| 52 | "= true, if environment variable exists; = false, if it does not exist"; |
|---|
| 53 | external "C" ModelicaInternal_getenv(name, convertToSlash, content, exist); |
|---|
| 54 | annotation (Documentation(info="<html> |
|---|
| 55 | |
|---|
| 56 | </html>")); |
|---|
| 57 | end getEnvironmentVariable; |
|---|
| 58 | |
|---|
| 59 | function setEnvironmentVariable "Set content of local environment variable" |
|---|
| 60 | extends Modelica.Icons.Function; |
|---|
| 61 | input String name "Name of environment variable"; |
|---|
| 62 | input String content "Value of the environment variable"; |
|---|
| 63 | input Boolean convertFromSlash = false |
|---|
| 64 | "True, if '/' in content shall be changed to the native directory separator"; |
|---|
| 65 | external "C" ModelicaInternal_setenv(name, content, convertFromSlash); |
|---|
| 66 | annotation (Documentation(info="<html> |
|---|
| 67 | |
|---|
| 68 | </html>")); |
|---|
| 69 | end setEnvironmentVariable; |
|---|
| 70 | |
|---|
| 71 | function command "Execute command in default shell" |
|---|
| 72 | extends Modelica.Icons.Function; |
|---|
| 73 | input String string "String to be passed to shell"; |
|---|
| 74 | output Integer result "Return value from command (depends on environment)"; |
|---|
| 75 | external "C" result = system(string); |
|---|
| 76 | annotation (Documentation(info="<html> |
|---|
| 77 | |
|---|
| 78 | </html>")); |
|---|
| 79 | end command; |
|---|
| 80 | |
|---|
| 81 | function exit "Terminate execution of Modelica environment" |
|---|
| 82 | extends Modelica.Icons.Function; |
|---|
| 83 | input Integer status=0 |
|---|
| 84 | "Result to be returned by environment (0 means success)"; |
|---|
| 85 | external "C" ModelicaInternal_exit(status); |
|---|
| 86 | end exit; |
|---|
| 87 | end System; |
|---|