| 42 | } |
| 43 | |
| 44 | void MapFile::ParseMapFile() |
| 45 | { |
| 46 | #if defined _WIN32 |
| 47 | if (_map.Size() > 0) |
| 48 | { |
| 49 | return; // map file already parsed |
| 50 | } |
| 51 | QIFStream in; |
| 52 | char sourceName[256]; |
| 53 | // use program name as given on command line |
| 54 | const char* cLine = GetCommandLine(); |
| 55 | if (*cLine == '"') |
| 56 | { |
| 57 | const char* eName = strchr(cLine + 1, '"'); |
| 58 | if (!eName) |
| 59 | { |
| 60 | LOG_DEBUG(Core, "Cannot get program name from '{}'.", cLine); |
| 61 | return; |
| 62 | } |
| 63 | ::strncpy(sourceName, cLine + 1, eName - 1 - cLine), sourceName[eName - 1 - cLine] = 0; |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | const char* eName = strchr(cLine, ' '); |
| 68 | if (!eName) |
| 69 | { |
| 70 | snprintf(sourceName, sizeof(sourceName), "%s", (const char*)cLine); |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | ::strncpy(sourceName, cLine, eName - cLine), sourceName[eName - cLine] = 0; |
| 75 | } |
| 76 | } |
| 77 | // replace .exe with .map |
| 78 | char* ext = GetFileExt(GetFilenameExt(sourceName)); |
| 79 | if (ext) |
| 80 | { |
| 81 | ::strcpy(ext, ".map"); |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | strncat(sourceName, ".map", sizeof(sourceName) - strlen(sourceName) - 1); |
| 86 | } |
| 87 | _name = sourceName; |
| 88 | |
| 89 | in.open(sourceName); |
| 90 | char line[1024]; |
| 91 | for (;;) |
| 92 | { |
| 93 | GetLine(line, sizeof(line), in); |
| 94 | if (in.eof() || in.fail()) |
| 95 | { |
| 96 | return; |
| 97 | } |
| 98 | if (in.eof()) |
| 99 | { |
| 100 | return; |
| 101 | } |