| 71 | // various locations and directories for the file before giving up. |
| 72 | |
| 73 | FILE *FileOpen(CONST char *szFile, int nFileMode, char *szPath) |
| 74 | { |
| 75 | FILE *file; |
| 76 | char szFileT[cchSzMax], szExe[cchSzMax], sz[cchSzMax], szMode[3], *pch; |
| 77 | CONST char *pch2; |
| 78 | #ifdef ENVIRON |
| 79 | char *env; |
| 80 | #endif |
| 81 | int i, j; |
| 82 | |
| 83 | // Some file types we want to open as binary instead of Ascii. |
| 84 | sprintf(szMode, "r%s", nFileMode >= 2 ? "b" : ""); |
| 85 | // Get directory containing Astrolog executable. |
| 86 | #ifdef WIN |
| 87 | GetModuleFileName(wi.hinst, szExe, cchSzMax); |
| 88 | #else |
| 89 | sprintf(szExe, "%s", is.szProgName != NULL ? is.szProgName : ""); |
| 90 | #endif |
| 91 | for (pch = szExe; *pch; pch++) |
| 92 | ; |
| 93 | while (pch > szExe && *pch != chDirSep) |
| 94 | pch--; |
| 95 | if (*pch == chDirSep) |
| 96 | pch++; |
| 97 | *pch = chNull; |
| 98 | |
| 99 | for (i = 0; i <= 1; i++) { |
| 100 | if (i <= 0) |
| 101 | sprintf(szFileT, "%s", szFile); |
| 102 | else { |
| 103 | if (nFileMode > 1) |
| 104 | break; |
| 105 | sprintf(szFileT, "%s.as", szFile); |
| 106 | } |
| 107 | |
| 108 | // First look for the file in the directory of the Astrolog executable. |
| 109 | sprintf(sz, "%s", szExe); |
| 110 | for (pch = sz; *pch; pch++) |
| 111 | ; |
| 112 | sprintf(pch, "%s", szFileT); |
| 113 | file = fopen(sz, szMode); |
| 114 | if (file != NULL) |
| 115 | goto LDone; |
| 116 | |
| 117 | // Next look for the file in the current directory. |
| 118 | sprintf(sz, "%s", szFileT); |
| 119 | file = fopen(sz, szMode); |
| 120 | if (file != NULL) |
| 121 | goto LDone; |
| 122 | |
| 123 | // Next look in the directories indicated by the -Yi switch. |
| 124 | for (j = 0; j < 10; j++) { |
| 125 | pch = us.rgszPath[j]; |
| 126 | if (FSzSet(pch)) { |
| 127 | if ((FCapCh(*pch) || FUncapCh(*pch) || FNumCh(*pch)) && |
| 128 | !(pch[1] == ':')) { |
| 129 | // If dir is relative path, then prepend the path to executable. |
| 130 | sprintf(sz, "%s", szExe); |
no test coverage detected