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