Changeset 9dd81ea in OpenModelica
- Timestamp:
- 2019-05-22T09:58:25+02:00 (5 years ago)
- Parents:
- 0e102be
- git-author:
- Adeel Asghar <adeel.asghar@…> (05/21/19 11:07:44)
- git-committer:
- Adeel Asghar <adeel.asghar@…> (05/22/19 09:58:25)
- Location:
- OMCompiler
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
OMCompiler/3rdParty
- Property commit changed from b1095643d59d7298388731a4c6dbc7d6fd9072e2 to 8718bd6164682b71dfa24978b3a7dbcb466b772b
-
OMCompiler/Compiler/Util/System.mo
r83be5f2b r9dd81ea 366 366 input String inString; 367 367 output Integer outInteger; 368 external "C" outInteger= chdir(inString) annotation(Library = "omcruntime");368 external "C" outInteger=SystemImpl__chdir(inString) annotation(Library = "omcruntime"); 369 369 end cd; 370 370 -
OMCompiler/Compiler/runtime/SimulationResults.c
r83be5f2b r9dd81ea 64 64 int len = strlen(filename); 65 65 const char *msg[] = {"",""}; 66 #if defined(__MINGW32__) || defined(_MSC_VER) 67 int unicodeFilenameLength = SystemImpl__stringToUnicodeSize(filename); 68 wchar_t unicodeFilename[unicodeFilenameLength]; 69 SystemImpl__stringToUnicode(filename, unicodeFilename, unicodeFilenameLength); 70 71 struct _stat buf; 72 #else 66 73 struct stat buf = {0} /* Zero this or valgrind complains */; 74 #endif 67 75 68 76 if (simresglob->curFileName && 0==strcmp(filename,simresglob->curFileName)) { 69 77 /* Also check that the file was not modified */ 78 #if defined(__MINGW32__) || defined(_MSC_VER) 79 if (_wstat(unicodeFilename, &buf)==0 && difftime(buf.st_mtime,simresglob->mtime)==0.0) { 80 #else 70 81 if (stat(filename, &buf)==0 && difftime(buf.st_mtime,simresglob->mtime)==0.0) { 82 #endif 71 83 return simresglob->curFormat; // Super cache :) 72 84 } … … 93 105 break; 94 106 case PLT: 107 #if defined(__MINGW32__) || defined(_MSC_VER) 108 simresglob->pltReader = _wfopen(unicodeFilename, L"r"); 109 #else 95 110 simresglob->pltReader = fopen(filename, "r"); 111 #endif 96 112 if (simresglob->pltReader==NULL) { 97 113 msg[1] = filename; -
OMCompiler/Compiler/runtime/System_omc.c
r83be5f2b r9dd81ea 826 826 extern const char* System_realpath(const char *path) 827 827 { 828 #if defined(__MINGW32__) || defined(_MSC_VER) 829 int unicodePathLength = SystemImpl__stringToUnicodeSize(path); 830 wchar_t unicodePath[unicodePathLength]; 831 SystemImpl__stringToUnicode(path, unicodePath, unicodePathLength); 832 833 DWORD bufLen = 0; 834 bufLen = GetFullPathNameW(unicodePath, bufLen, NULL, NULL); 835 if (!bufLen) { 836 fprintf(stderr, "GetFullPathNameW failed. %lu\n", GetLastError()); 837 MMC_THROW(); 838 } 839 840 WCHAR unicodeFullPath[bufLen]; 841 if (!GetFullPathNameW(unicodePath, bufLen, unicodeFullPath, NULL)) { 842 fprintf(stderr, "GetFullPathNameW failed. %lu\n", GetLastError()); 843 MMC_THROW(); 844 } 845 846 int bufferLength = SystemImpl__unicodeToStringSize(unicodeFullPath); 847 char buffer[bufferLength]; 848 SystemImpl__unicodeToString(unicodeFullPath, buffer, bufferLength); 849 SystemImpl__toWindowsSeperators(buffer, bufferLength); 850 return omc_alloc_interface.malloc_strdup(buffer); 851 #else 828 852 char buf[PATH_MAX]; 829 853 if (realpath(path, buf) == NULL) { … … 831 855 } 832 856 return omc_alloc_interface.malloc_strdup(buf); 857 #endif 833 858 } 834 859 -
OMCompiler/Compiler/runtime/systemimpl.c
r83be5f2b r9dd81ea 262 262 } 263 263 264 #if defined(__MINGW32__) || defined(_MSC_VER) 265 extern int SystemImpl__stringToUnicodeSize(const char* str) 266 { 267 return MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); 268 } 269 270 extern int SystemImpl__stringToUnicode(const char* str, wchar_t* unicode, int size) 271 { 272 return MultiByteToWideChar(CP_UTF8, 0, str, -1, unicode, size); 273 } 274 275 int SystemImpl__unicodeToStringSize(const wchar_t* unicode) 276 { 277 return WideCharToMultiByte(CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL); 278 } 279 280 int SystemImpl__unicodeToString(const wchar_t* unicode, char* str, int size) 281 { 282 return WideCharToMultiByte(CP_UTF8, 0, unicode, -1, str, size, NULL, NULL); 283 } 284 285 /* Make sure windows paths use frontslash and not backslash */ 286 void SystemImpl__toWindowsSeperators(char* buffer, int bufferLength) 287 { 288 int i; 289 for (i=0; i<bufferLength && buffer[i]; i++) { 290 if (buffer[i] == '\\') buffer[i] = '/'; 291 } 292 } 293 #endif 294 295 int SystemImpl__chdir(const char* path) 296 { 297 #if defined(__MINGW32__) || defined(_MSC_VER) 298 int unicodePathLength = SystemImpl__stringToUnicodeSize(path); 299 wchar_t unicodePath[unicodePathLength]; 300 SystemImpl__stringToUnicode(path, unicodePath, unicodePathLength); 301 302 if (!SetCurrentDirectoryW(unicodePath)) { 303 c_add_message(NULL,-1,ErrorType_scripting,ErrorLevel_error,gettext("SetCurrentDirectoryW failed."),NULL,0); 304 return -1; 305 } 306 return 0; 307 #else 308 if (chdir(path) != 0) { 309 c_add_message(NULL,-1,ErrorType_scripting,ErrorLevel_error,gettext("chdir failed."),NULL,0); 310 return -1; 311 } 312 return 0; 313 #endif 314 } 315 264 316 extern char* SystemImpl__pwd(void) 265 317 { 318 #if defined(__MINGW32__) || defined(_MSC_VER) 319 DWORD bufLen = 0; 320 bufLen = GetCurrentDirectoryW(bufLen, 0); 321 if (!bufLen) { 322 c_add_message(NULL,-1,ErrorType_scripting,ErrorLevel_error,gettext("GetCurrentDirectoryW failed."),NULL,0); 323 return NULL; 324 } 325 326 WCHAR unicodePath[bufLen]; 327 if (!GetCurrentDirectoryW(bufLen, unicodePath)) { 328 c_add_message(NULL,-1,ErrorType_scripting,ErrorLevel_error,gettext("GetCurrentDirectoryW failed."),NULL,0); 329 return NULL; 330 } 331 int bufferLength = SystemImpl__unicodeToStringSize(unicodePath); 332 char buffer[bufferLength]; 333 SystemImpl__unicodeToString(unicodePath, buffer, bufferLength); 334 SystemImpl__toWindowsSeperators(buffer, bufferLength); 335 return omc_alloc_interface.malloc_strdup(buffer); 336 #else 266 337 char buf[MAXPATHLEN]; 338 if (NULL == getcwd(buf,MAXPATHLEN)) { 339 c_add_message(NULL,-1,ErrorType_scripting,ErrorLevel_error,gettext("System.pwd failed."),NULL,0); 340 return NULL; 341 } 342 return omc_alloc_interface.malloc_strdup(buf); 343 #endif 344 } 345 346 extern int SystemImpl__regularFileExists(const char* str) 347 { 267 348 #if defined(__MINGW32__) || defined(_MSC_VER) 268 int i; 269 LPTSTR bufPtr=buf; 270 DWORD bufLen = MAXPATHLEN; 271 if (!GetCurrentDirectory(bufLen,bufPtr)) { 272 fprintf(stderr, "System.pwd failed\n"); 273 return NULL; 274 } 275 /* Make sure windows paths use frontslash and not backslash */ 276 for (i=0; i<MAXPATHLEN && buf[i]; i++) { 277 if (buf[i] == '\\') buf[i] = '/'; 278 } 279 return omc_alloc_interface.malloc_strdup(buf); 280 #else 281 if (NULL == getcwd(buf,MAXPATHLEN)) { 282 fprintf(stderr, "System.pwd failed\n"); 283 return NULL; 284 } 285 return omc_alloc_interface.malloc_strdup(buf); 286 #endif 287 } 288 289 extern int SystemImpl__regularFileExists(const char* str) 290 { 291 #if defined(_MSC_VER) 292 WIN32_FIND_DATA FileData; 349 WIN32_FIND_DATAW FileData; 293 350 HANDLE sh; 294 351 295 sh = FindFirstFile(str, &FileData); 352 int unicodeFilenameLength = SystemImpl__stringToUnicodeSize(str); 353 wchar_t unicodeFilename[unicodeFilenameLength]; 354 SystemImpl__stringToUnicode(str, unicodeFilename, unicodeFilenameLength); 355 356 sh = FindFirstFileW(unicodeFilename, &FileData); 296 357 297 358 if (sh == INVALID_HANDLE_VALUE) { … … 323 384 if (!SystemImpl__regularFileExists(str)) 324 385 return 0; 386 #if defined(__MINGW32__) || defined(_MSC_VER) 387 int unicodeFilenameLength = SystemImpl__stringToUnicodeSize(str); 388 wchar_t unicodeFilename[unicodeFilenameLength]; 389 SystemImpl__stringToUnicode(str, unicodeFilename, unicodeFilenameLength); 390 391 f = _wfopen(unicodeFilename, L"a"); 392 #else 325 393 f = fopen(str, "a"); 394 #endif 326 395 if (f == NULL) 327 396 return 0; … … 335 404 int res; 336 405 FILE * file = NULL; 406 #if defined(__MINGW32__) || defined(_MSC_VER) 407 int unicodeFilenameLength = SystemImpl__stringToUnicodeSize(filename); 408 wchar_t unicodeFilename[unicodeFilenameLength]; 409 SystemImpl__stringToUnicode(filename, unicodeFilename, unicodeFilenameLength); 410 411 struct _stat statstr; 412 res = _wstat(unicodeFilename, &statstr); 413 #else 337 414 struct stat statstr; 338 415 res = stat(filename, &statstr); 416 #endif 339 417 340 418 if (res != 0) { … … 363 441 #endif 364 442 443 #if defined(__MINGW32__) || defined(_MSC_VER) 444 file = _wfopen(unicodeFilename, L"rb"); 445 #else 365 446 file = fopen(filename,"rb"); 447 #endif 366 448 if (file == NULL) { 367 449 const char *c_tokens[2]={strerror(errno),filename}; … … 396 478 { 397 479 #if defined(__MINGW32__) || defined(_MSC_VER) 398 return _unlink(filename); 480 int unicodeFilenameLength = SystemImpl__stringToUnicodeSize(filename); 481 wchar_t unicodeFilename[unicodeFilenameLength]; 482 SystemImpl__stringToUnicode(filename, unicodeFilename, unicodeFilenameLength); 483 484 return _wunlink(unicodeFilename); 399 485 #else /* unix */ 400 486 return unlink(filename); … … 407 493 #if defined(__MINGW32__) || defined(_MSC_VER) 408 494 const char *fileOpenMode = "wt"; /* on Windows do translation so that \n becomes \r\n */ 495 496 int unicodeFilenameLength = SystemImpl__stringToUnicodeSize(filename); 497 wchar_t unicodeFilename[unicodeFilenameLength]; 498 SystemImpl__stringToUnicode(filename, unicodeFilename, unicodeFilenameLength); 499 500 int unicodeFileOpenModeLength = SystemImpl__stringToUnicodeSize(fileOpenMode); 501 wchar_t unicodeFileOpenMode[unicodeFileOpenModeLength]; 502 SystemImpl__stringToUnicode(fileOpenMode, unicodeFileOpenMode, unicodeFileOpenModeLength); 409 503 #else 410 504 const char *fileOpenMode = "wb"; /* on Unixes don't bother, do it binary mode */ … … 413 507 int len = strlen(data); /* MMC_HDRSTRLEN(MMC_GETHDR(rmlA1)); */ 414 508 #if defined(__APPLE_CC__)||defined(__MINGW32__)||defined(__MINGW64__) 415 unlink(filename);509 SystemImpl__removeFile(filename); 416 510 #endif 417 511 /* adrpo: 2010-09-22 open the file in BINARY mode as otherwise \r\n becomes \r\r\n! */ 512 #if defined(__MINGW32__) || defined(_MSC_VER) 513 file = _wfopen(unicodeFilename, unicodeFileOpenMode); 514 #else 418 515 file = fopen(filename,fileOpenMode); 516 #endif 419 517 if (file == NULL) { 420 518 const char *c_tokens[1]={filename}; … … 546 644 int runProcess(const char* cmd) 547 645 { 548 STARTUPINFO si;646 STARTUPINFOW si; 549 647 PROCESS_INFORMATION pi; 550 648 char *c = "cmd /c"; … … 561 659 /* fprintf(stderr, "%s\n", command); fflush(NULL); */ 562 660 563 if (CreateProcessA(NULL, command, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) 661 int unicodeCommandLength = SystemImpl__stringToUnicodeSize(command); 662 wchar_t unicodeCommand[unicodeCommandLength]; 663 SystemImpl__stringToUnicode(command, unicodeCommand, unicodeCommandLength); 664 665 if (CreateProcessW(NULL, unicodeCommand, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) 564 666 { 565 566 567 568 569 667 WaitForSingleObject(pi.hProcess, INFINITE); 668 // Get the exit code. 669 GetExitCodeProcess(pi.hProcess, &exitCode); 670 CloseHandle(pi.hProcess); 671 CloseHandle(pi.hThread); 570 672 } 571 673 GC_free(command); … … 1176 1278 int res,numCount; 1177 1279 FILE * file = NULL; 1280 #if defined(__MINGW32__) || defined(_MSC_VER) 1281 int unicodeFilenameLength = SystemImpl__stringToUnicodeSize(filename); 1282 wchar_t unicodeFilename[unicodeFilenameLength]; 1283 SystemImpl__stringToUnicode(filename, unicodeFilename, unicodeFilenameLength); 1284 1285 struct _stat statstr; 1286 res = _wstat(unicodeFilename, &statstr); 1287 #else 1178 1288 struct stat statstr; 1179 1289 res = stat(filename, &statstr); 1290 #endif 1180 1291 1181 1292 if(res!=0) { … … 1190 1301 } 1191 1302 1303 #if defined(__MINGW32__) || defined(_MSC_VER) 1304 file = _wfopen(unicodeFilename, L"rb"); 1305 #else 1192 1306 file = fopen(filename,"rb"); 1307 #endif 1193 1308 buf = (char*) omc_alloc_interface.malloc_atomic(statstr.st_size+1); 1194 1309 bufRes = (char*) omc_alloc_interface.malloc_atomic((statstr.st_size+70)*sizeof(char)); … … 2350 2465 const char *ignore = SystemImpl__iconv__ascii(str); 2351 2466 const char *tokens[4] = {res,from,to,ignore}; 2352 c_add_message(NULL,-1,ErrorType_scripting,ErrorLevel_error,gettext("iconv(\"%s\", to=\"%s\",from=\"%s\") failed: %s"),tokens,4);2467 c_add_message(NULL,-1,ErrorType_scripting,ErrorLevel_error,gettext("iconv(\"%s\",from=\"%s\",to=\"%s\") failed: %s"),tokens,4); 2353 2468 omc_alloc_interface.free_uncollectable((char*)ignore); 2354 2469 } -
OMCompiler/Compiler/runtime/systemimpl.h
r83be5f2b r9dd81ea 88 88 extern int SystemImpl__setCFlags(const char *str); 89 89 extern int SystemImpl__setLDFlags(const char *str); 90 #if defined(__MINGW32__) || defined(_MSC_VER) 91 extern int SystemImpl__stringToUnicodeSize(const char* str); 92 extern int SystemImpl__stringToUnicode(const char* str, wchar_t* unicode, int size); 93 #endif 90 94 extern char* SystemImpl__pwd(void); 91 95 extern int SystemImpl__regularFileExists(const char* str); -
OMCompiler/Parser/parse.c
r83be5f2b r9dd81ea 181 181 { 182 182 pANTLR3_PARSER parser; 183 pANTLR3_STRING ttext;184 183 pANTLR3_EXCEPTION ex; 185 184 pANTLR3_COMMON_TOKEN preToken,nextToken; … … 196 195 // Retrieve some info for easy reading. 197 196 ex = recognizer->state->exception; 198 ttext = (pANTLR3_STRING) NULL;199 197 200 198 switch (recognizer->type) … … 436 434 * So we pass an empty string instead :) 437 435 */ 436 #if defined(__MINGW32__) || defined(_MSC_VER) 437 int unicodeFileNameLength = SystemImpl__stringToUnicodeSize(fileName); 438 wchar_t unicodeFileName[unicodeFileNameLength]; 439 SystemImpl__stringToUnicode(fileName, unicodeFileName, unicodeFileNameLength); 440 441 struct _stat st; 442 _wstat(unicodeFileName, &st); 443 #else 438 444 struct stat st; 439 445 stat(members.filename_C, &st); 446 #endif 440 447 members.timestamp = mmc_mk_rcon((double)st.st_mtime); 441 448 if (0 == st.st_size) return parseString("",members.filename_C,ModelicaParser_flags, langStd, runningTestsuite); -
OMCompiler/SimulationRuntime/c/util/read_csv.c
r83be5f2b r9dd81ea 35 35 #include "read_matlab4.h" 36 36 #include "libcsv.h" 37 #if defined(__MINGW32__) || defined(_MSC_VER) 38 #include <windows.h> 39 #endif 37 40 38 41 #if defined(__cplusplus) … … 103 106 size_t offset=0; 104 107 unsigned char delim = CSV_COMMA; 108 #if defined(__MINGW32__) || defined(_MSC_VER) 109 int unicodeFilenameLength = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0); 110 wchar_t unicodeFilename[unicodeFilenameLength]; 111 MultiByteToWideChar(CP_UTF8, 0, filename, -1, unicodeFilename, unicodeFilenameLength); 112 113 f = _wfopen(unicodeFilename, L"r"); 114 #else 105 115 f = fopen(filename,"r"); 116 #endif 106 117 if (f == NULL) { 107 118 return -1; … … 216 227 struct csv_parser p; 217 228 struct csv_body body = {0}; 229 #if defined(__MINGW32__) || defined(_MSC_VER) 230 int unicodeFilenameLength = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0); 231 wchar_t unicodeFilename[unicodeFilenameLength]; 232 MultiByteToWideChar(CP_UTF8, 0, filename, -1, unicodeFilename, unicodeFilenameLength); 233 234 FILE *fin = _wfopen(unicodeFilename, L"r"); 235 #else 218 236 FILE *fin = fopen(filename, "r"); 237 #endif 219 238 size_t offset = 0; 220 239 unsigned char delim = CSV_COMMA; … … 264 283 size_t offset = 0; 265 284 unsigned char delim = CSV_COMMA; 285 #if defined(__MINGW32__) || defined(_MSC_VER) 286 int unicodeFilenameLength = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0); 287 wchar_t unicodeFilename[unicodeFilenameLength]; 288 MultiByteToWideChar(CP_UTF8, 0, filename, -1, unicodeFilename, unicodeFilenameLength); 289 290 FILE *fin = _wfopen(unicodeFilename, L"r"); 291 #else 266 292 FILE *fin = fopen(filename, "r"); 293 #endif 267 294 if (!fin) { 268 295 return NULL; -
OMCompiler/SimulationRuntime/c/util/read_matlab4.c
r83be5f2b r9dd81ea 36 36 #include <ctype.h> 37 37 #include "read_matlab4.h" 38 #if defined(__MINGW32__) || defined(_MSC_VER) 39 #include <windows.h> 40 #endif 38 41 39 42 extern const char *omc_mat_Aclass; … … 227 230 char binTrans = 1; 228 231 memset(reader, 0, sizeof(ModelicaMatReader)); 232 #if defined(__MINGW32__) || defined(_MSC_VER) 233 int unicodeFilenameLength = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0); 234 wchar_t unicodeFilename[unicodeFilenameLength]; 235 MultiByteToWideChar(CP_UTF8, 0, filename, -1, unicodeFilename, unicodeFilenameLength); 236 237 reader->file = _wfopen(unicodeFilename, L"rb"); 238 #else 229 239 reader->file = fopen(filename, "rb"); 240 #endif 230 241 if(!reader->file) return strerror(errno); 231 242 reader->fileName = strdup(filename);
Note: See TracChangeset
for help on using the changeset viewer.