Changeset 1165 for trunk/src/lib/kDep.c
- Timestamp:
- Sep 30, 2007, 9:36:23 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/kDep.c
r1088 r1165 49 49 typedef unsigned short uint16_t; 50 50 typedef unsigned int uint32_t; 51 extern void nt_fullpath(const char *pszPath, char *pszFull, size_t cchFull); /* nt_fullpath.c */ 51 52 #endif 52 53 … … 82 83 83 84 84 #ifdef __WIN32__ 85 /** 86 * Corrects the case of a path and changes any path components containing 87 * spaces with the short name (which can be longer). 88 * 89 * Expects a _fullpath! 90 * 91 * @param pszPath Pointer to the path, both input and output. 92 * The buffer must be at least MAX_PATH in length. 93 */ 94 static void fixcase(char *pszPath) 95 { 96 #define my_assert(expr) \ 97 do { \ 98 if (!(expr)) { \ 99 printf("my_assert: %s, file %s, line %d\npszPath=%s\npsz=%s\n", \ 100 #expr, __FILE__, __LINE__, pszPath, psz); \ 101 __debugbreak(); \ 102 exit(1); \ 103 } \ 104 } while (0) 105 106 char *psz = pszPath; 107 if (*psz == '/' || *psz == '\\') 108 { 109 if (psz[1] == '/' || psz[1] == '\\') 110 { 111 /* UNC */ 112 my_assert(psz[1] == '/' || psz[1] == '\\'); 113 my_assert(psz[2] != '/' && psz[2] != '\\'); 114 115 /* skip server name */ 116 psz += 2; 117 while (*psz != '\\' && *psz != '/') 118 { 119 if (!*psz) 120 return; 121 *psz++ = toupper(*psz); 122 } 123 124 /* skip the share name */ 125 psz++; 126 my_assert(*psz != '/' && *psz != '\\'); 127 while (*psz != '\\' && *psz != '/') 128 { 129 if (!*psz) 130 return; 131 *psz++ = toupper(*psz); 132 } 133 my_assert(*psz == '/' || *psz == '\\'); 134 psz++; 135 } 136 else 137 { 138 /* Unix spec */ 139 psz++; 140 } 141 } 142 else 143 { 144 /* Drive letter */ 145 my_assert(psz[1] == ':'); 146 *psz = toupper(*psz); 147 my_assert(psz[0] >= 'A' && psz[0] <= 'Z'); 148 my_assert(psz[2] == '/' || psz[2] == '\\'); 149 psz += 3; 150 } 151 152 /* 153 * Pointing to the first char after the unc or drive specifier. 154 */ 155 while (*psz) 156 { 157 WIN32_FIND_DATA FindFileData; 158 HANDLE hDir; 159 char chSaved0; 160 char chSaved1; 161 char *pszEnd; 162 size_t cch; 163 int iLongNameDiff; 164 165 166 /* find the end of the component. */ 167 pszEnd = psz; 168 while (*pszEnd && *pszEnd != '/' && *pszEnd != '\\') 169 pszEnd++; 170 cch = pszEnd - psz; 171 172 /* replace the end with "?\0" */ 173 chSaved0 = pszEnd[0]; 174 chSaved1 = pszEnd[1]; 175 pszEnd[0] = '?'; 176 pszEnd[1] = '\0'; 177 178 /* find the right filename. */ 179 hDir = FindFirstFile(pszPath, &FindFileData); 180 pszEnd[1] = chSaved1; 181 if (!hDir) 182 { 183 pszEnd[0] = chSaved0; 184 return; 185 } 186 pszEnd[0] = '\0'; 187 while ( (iLongNameDiff = _stricmp(FindFileData.cFileName, psz)) 188 && _stricmp(FindFileData.cAlternateFileName, psz)) 189 { 190 if (!FindNextFile(hDir, &FindFileData)) 191 { 192 pszEnd[0] = chSaved0; 193 return; 194 } 195 } 196 pszEnd[0] = chSaved0; 197 if (iLongNameDiff || !FindFileData.cAlternateFileName[0] || !memchr(psz, ' ', cch)) 198 memcpy(psz, !iLongNameDiff ? FindFileData.cFileName : FindFileData.cAlternateFileName, cch); 199 else 200 { 201 /* replace spacy name with the short name. */ 202 const size_t cchAlt = strlen(FindFileData.cAlternateFileName); 203 const size_t cchDelta = cch - cchAlt; 204 my_assert(cchAlt > 0); 205 if (!cchDelta) 206 memcpy(psz, FindFileData.cAlternateFileName, cch); 207 else 208 { 209 size_t cbLeft = strlen(pszEnd) + 1; 210 if ((psz - pszPath) + cbLeft + cchAlt <= _MAX_PATH) 211 { 212 memmove(psz + cchAlt, pszEnd, cbLeft); 213 pszEnd -= cchDelta; 214 memcpy(psz, FindFileData.cAlternateFileName, cchAlt); 215 } 216 else 217 fprintf(stderr, "kDep: case & space fixed filename is growing too long (%d bytes)! '%s'\n", 218 (psz - pszPath) + cbLeft + cchAlt, pszPath); 219 } 220 } 221 my_assert(pszEnd[0] == chSaved0); 222 223 /* advance to the next component */ 224 if (!chSaved0) 225 return; 226 psz = pszEnd + 1; 227 my_assert(*psz != '/' && *psz != '\\'); 228 } 229 #undef my_assert 230 } 231 232 #elif defined(__OS2__) 85 #if defined(__OS2__) 233 86 234 87 /** … … 243 96 } 244 97 245 #el se98 #elif !defined(__WIN32__) && !defined(__WIN64__) 246 99 247 100 /** … … 372 225 if (fFixCase) 373 226 { 374 #ifdef __WIN32__ 375 if (_fullpath(szFilename, pszFilename, sizeof(szFilename))) 376 ; 377 else 378 #endif 379 strcpy(szFilename, pszFilename); 227 #if defined(__WIN32__) || defined(__WIN64__) 228 nt_fullpath(pszFilename, szFilename, sizeof(szFilename)); 229 #else 380 230 fixslash(szFilename); 381 231 fixcase(szFilename); 232 #endif 382 233 pszFilename = szFilename; 383 234 } … … 398 249 } 399 250 400 #if 0 /* waste of time */401 251 /* 402 252 * Free the old ones. … … 408 258 free(pDep); 409 259 } 410 #endif411 260 } 412 261 … … 510 359 return pDep; 511 360 } 361 362 363 /** 364 * Frees the current dependency chain. 365 */ 366 void depCleanup(void) 367 { 368 PDEP pDep = g_pDeps; 369 g_pDeps = NULL; 370 while (pDep) 371 { 372 PDEP pFree = pDep; 373 pDep = pDep->pNext; 374 free(pFree); 375 } 376 } 377
Note:
See TracChangeset
for help on using the changeset viewer.