Skip to content

Commit 563d09b

Browse files
committed
- Completed implementation of Settings_omc.cpp
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7132 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 4dc54cb commit 563d09b

File tree

4 files changed

+49
-51
lines changed

4 files changed

+49
-51
lines changed

Compiler/Settings.mo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ end getVersionNr;
4444

4545
public function setCompilePath
4646
input String inString;
47-
external "C" Settings_setCompilePath(inString) annotation(Library = "omcruntime");
47+
external "C" SettingsImpl__setCompilePath(inString) annotation(Library = "omcruntime");
4848
end setCompilePath;
4949

5050
public function getCompilePath
@@ -56,7 +56,7 @@ end getCompilePath;
5656
public function setCompileCommand
5757
input String inString;
5858

59-
external "C" SettingsImpl_setCompileCommand(inString) annotation(Library = "omcruntime");
59+
external "C" SettingsImpl__setCompileCommand(inString) annotation(Library = "omcruntime");
6060
end setCompileCommand;
6161

6262
public function getCompileCommand
@@ -68,7 +68,7 @@ end getCompileCommand;
6868
public function setTempDirectoryPath
6969
input String inString;
7070

71-
external "C" Settings_setTempDirectoryPath(inString) annotation(Library = "omcruntime");
71+
external "C" SettingsImpl__setTempDirectoryPath(inString) annotation(Library = "omcruntime");
7272
end setTempDirectoryPath;
7373

7474
public function getTempDirectoryPath
@@ -95,7 +95,7 @@ end setModelicaPath;
9595

9696
public function getModelicaPath
9797
output String outString;
98-
external "C" outString=Settings__getModelicaPath() annotation(Library = "omcruntime");
98+
external "C" outString=Settings_getModelicaPath() annotation(Library = "omcruntime");
9999
end getModelicaPath;
100100

101101
public function getEcho

Compiler/runtime/Settings_omc.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ extern const char* Settings_getVersionNr()
7070
return CONFIG_VERSION;
7171
}
7272

73-
extern const char* Settings_getTempDirectoryPath();
74-
extern void Settings_setTempDirectoryPath(const char* _inString);
73+
extern const char* Settings_getTempDirectoryPath()
74+
{
75+
return strdup(SettingsImpl__getTempDirectoryPath());
76+
}
7577

7678
}

Compiler/runtime/Settings_rml.c

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,6 @@
3333

3434
void Settings_5finit(void)
3535
{
36-
37-
// On windows, set Temp directory path to Temp directory as returned by GetTempPath,
38-
// which is usually TMP or TEMP or windows catalogue.
39-
#ifdef WIN32
40-
int numChars;
41-
char* str,str1;
42-
char tempDirectory[1024];
43-
//extract the temp path
44-
numChars= GetTempPath(1024, tempDirectory);
45-
if (numChars == 1024 || numChars == 0) {
46-
printf("Error setting temppath in Kernel\n");
47-
}
48-
else {
49-
if (tempDirectoryPath) {
50-
free(tempDirectoryPath);
51-
tempDirectoryPath=0;
52-
}
53-
// Must do replacement in two steps, since the _replace function can not have similar source as target.
54-
str = _replace(tempDirectory,"\\","/");
55-
tempDirectoryPath= _replace(str,"/","\\\\");
56-
free(str);
57-
}
58-
#else
59-
char* str = NULL;
60-
str = getenv("TMPDIR");
61-
if (str == NULL) {
62-
tempDirectoryPath = malloc(sizeof(char)*(strlen("/tmp") + 1));
63-
strcpy(tempDirectoryPath, "/tmp");
64-
}
65-
else {
66-
tempDirectoryPath = malloc(sizeof(char)*(strlen(str) + 1));
67-
strcpy(tempDirectoryPath, str);
68-
}
69-
#endif
7036
}
7137

7238

@@ -122,16 +88,8 @@ RML_END_LABEL
12288

12389
RML_BEGIN_LABEL(Settings__setTempDirectoryPath)
12490
{
125-
char* command = RML_STRINGDATA(rmlA0);
126-
if(tempDirectoryPath)
127-
free(tempDirectoryPath);
128-
129-
tempDirectoryPath = (char*)malloc(strlen(command)+1);
130-
if (tempDirectoryPath == NULL) {
131-
RML_TAILCALLK(rmlFC);
132-
}
133-
memcpy(tempDirectoryPath,command,strlen(command)+1);
134-
91+
const char* command = RML_STRINGDATA(rmlA0);
92+
SettingsImpl__setTempDirectoryPath(command);
13593
RML_TAILCALLK(rmlSC);
13694
}
13795
RML_END_LABEL

Compiler/runtime/settingsimpl.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ static const char* SettingsImpl__getCompileCommand()
104104
return compileCommand;
105105
}
106106

107-
extern void SettingsImpl__setCompileCommand(const char *command) {
107+
extern void SettingsImpl__setCompileCommand(const char *command)
108+
{
108109
if(compileCommand)
109110
free(compileCommand);
110111
compileCommand = strdup(command);
@@ -155,6 +156,43 @@ extern void SettingsImpl__setModelicaPath(const char *value)
155156
commonSetEnvVar("OPENMODELICALIBRARY",value);
156157
}
157158

159+
extern void SettingsImpl__setTempDirectoryPath(const char *path)
160+
{
161+
if (tempDirectoryPath)
162+
free(tempDirectoryPath);
163+
tempDirectoryPath = strdup(path);
164+
}
165+
166+
extern char* SettingsImpl__getTempDirectoryPath()
167+
{
168+
if (tempDirectoryPath == NULL) {
169+
// On windows, set Temp directory path to Temp directory as returned by GetTempPath,
170+
// which is usually TMP or TEMP or windows catalogue.
171+
#ifdef WIN32
172+
int numChars;
173+
char* str,str1;
174+
char tempDirectory[1024];
175+
//extract the temp path
176+
numChars= GetTempPath(1024, tempDirectory);
177+
if (numChars == 1024 || numChars == 0) {
178+
fprintf(stderr, "Error setting temppath in Kernel\n");
179+
exit(1);
180+
} else {
181+
// Must do replacement in two steps, since the _replace function can not have similar source as target.
182+
str = _replace(tempDirectory,"\\","/");
183+
tempDirectoryPath= _replace(str,"/","\\\\");
184+
free(str);
185+
}
186+
#else
187+
const char* str = getenv("TMPDIR");
188+
if (str == NULL)
189+
str = "/tmp";
190+
tempDirectoryPath = strdup(str);
191+
#endif
192+
}
193+
return tempDirectoryPath;
194+
}
195+
158196
#ifdef __cplusplus
159197
}
160198
#endif

0 commit comments

Comments
 (0)