Changeset 808004bd in OpenModelica


Ignore:
Timestamp:
2022-05-20T15:52:02+02:00 (2 years ago)
Author:
AnHeuermann <andreas.heuermann@…>
Children:
826b68ae
Parents:
c454bc7d
git-author:
AnHeuermann <andreas.heuermann@…> (05/20/22 15:45:23)
git-committer:
AnHeuermann <andreas.heuermann@…> (05/20/22 15:52:02)
Message:

Fixing System_moFiles and System_mocFiles Windows wide chars

  • Wide characters as è can now be handled.
  • Functions unified in omc_scanDirForPackagePattern.
  • Long path not yet supported by omc_scanDirForPackagePattern.

Co-authored-by: mahge <mahge@…>

Location:
OMCompiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/runtime/System_omc.c

    rbfad4b6b r808004bd  
    406406
    407407#if defined(__MINGW32__) || defined(_MSC_VER)
    408 void* System_moFiles(const char *directory)
     408/**
     409 * @brief Scan directory for package files with given pattern except for packageName.
     410 *
     411 * @param directory     Directory to search in
     412 * @param pattern       Pattern to search for, e.g. "*.mo" or "*.moc".
     413 * @param packageName   Name of packages, e.g. "package.mo" or "package.moc"
     414 * @return void*        List of file names matching pattern.
     415 */
     416void* omc_scanDirForPackagePattern(const char* directory, const char* pattern, const wchar_t* packageName)
    409417{
    410418  void *res;
    411   WIN32_FIND_DATA FileData;
     419  WIN32_FIND_DATAW FileData;
    412420  BOOL more = TRUE;
    413   char pattern[1024];
    414421  HANDLE sh;
    415   sprintf(pattern, "%s\\*.mo", directory);
     422  char pattern_mb[1024];
     423
     424  // TODO: Use longabspath for path longer than MAX_PATH
     425  //wchar_t* unicodeAbsDirectory = longabspath(directory);
     426  sprintf(pattern_mb, "%s\\%s", directory, pattern);
     427
     428  MULTIBYTE_TO_WIDECHAR_LENGTH(pattern_mb, pattern_uc_length);
     429  MULTIBYTE_TO_WIDECHAR_VAR(pattern_mb, pattern_uc, pattern_uc_length);
     430
    416431  res = mmc_mk_nil();
    417   sh = FindFirstFile(pattern, &FileData);
     432  sh = FindFirstFileW(pattern_uc, &FileData);
    418433  if (sh != INVALID_HANDLE_VALUE) {
    419434    while(more) {
    420       if (strcmp(FileData.cFileName,"package.mo") != 0)
     435      if (wcscmp(FileData.cFileName, packageName) != 0)
    421436      {
    422         res = mmc_mk_cons(mmc_mk_scon(FileData.cFileName),res);
     437        WIDECHAR_TO_MULTIBYTE_LENGTH(FileData.cFileName, file_name_mb_length);
     438        WIDECHAR_TO_MULTIBYTE_VAR(FileData.cFileName, file_name_mb, file_name_mb_length);
     439
     440        res = mmc_mk_cons(mmc_mk_scon(file_name_mb),res);
     441        MULTIBYTE_OR_WIDECHAR_VAR_FREE(file_name_mb);
    423442      }
    424       more = FindNextFile(sh, &FileData);
     443      more = FindNextFileW(sh, &FileData);
    425444    }
    426445    if (sh != INVALID_HANDLE_VALUE) FindClose(sh);
    427446  }
    428   return res;
     447
     448  MULTIBYTE_OR_WIDECHAR_VAR_FREE(pattern_uc);
     449
     450  return res;
     451}
     452#endif
     453
     454/**
     455 * @brief Scan directory for .mo files excluding package.mo.
     456 *
     457 * @param directory   Directory to search in.
     458 * @return void*      List of file names.
     459 */
     460void* System_moFiles(const char *directory)
     461#if defined(__MINGW32__) || defined(_MSC_VER)
     462{
     463  return omc_scanDirForPackagePattern(directory, "*.mo", L"package.mo");
    429464}
    430465#else
    431 void* System_moFiles(const char *directory)
    432466{
    433467  int i,count;
     
    447481#endif
    448482
     483/**
     484 * @brief Scan directory for .moc files excluding package.moc.
     485 *
     486 * @param directory   Directory to search in.
     487 * @return void*      List of file names.
     488 */
     489void* System_mocFiles(const char *directory)
    449490#if defined(__MINGW32__) || defined(_MSC_VER)
    450 void* System_mocFiles(const char *directory)
    451 {
    452   void *res;
    453   WIN32_FIND_DATA FileData;
    454   BOOL more = TRUE;
    455   char pattern[1024];
    456   HANDLE sh;
    457   sprintf(pattern, "%s\\*.moc", directory);
    458   res = mmc_mk_nil();
    459   sh = FindFirstFile(pattern, &FileData);
    460   if (sh != INVALID_HANDLE_VALUE) {
    461     while(more) {
    462       if (strcmp(FileData.cFileName,"package.moc") != 0)
    463       {
    464         res = mmc_mk_cons(mmc_mk_scon(FileData.cFileName),res);
    465       }
    466       more = FindNextFile(sh, &FileData);
    467     }
    468     if (sh != INVALID_HANDLE_VALUE) FindClose(sh);
    469   }
    470   return res;
     491{
     492  return omc_scanDirForPackagePattern(directory, "*.moc", L"package.moc");
    471493}
    472494#else
    473 void* System_mocFiles(const char *directory)
    474495{
    475496  int i,count;
  • OMCompiler/SimulationRuntime/c/util/omc_file.h

    rf11277c4 r808004bd  
    103103
    104104int omc_unlink(const char *filename);
     105wchar_t* longabspath(wchar_t* unicodePath);
    105106
    106107#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.