- Timestamp:
- Oct 30, 2005 7:20:35 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kDepPre/kDepPre.c
r330 r332 29 29 #include <stdlib.h> 30 30 #include <string.h> 31 #include <errno.h> 31 32 #include <ctype.h> 33 #include <sys/stat.h> 32 34 #ifdef __WIN32__ 33 35 #include <windows.h> 34 36 #endif 37 #if !defined(__WIN32__) && !defined(__OS2__) 38 # include <dirent.h> 39 #endif 35 40 36 41 #ifdef HAVE_FGETC_UNLOCKED … … 69 74 /** List of dependencies. */ 70 75 static PDEP g_pDeps = NULL; 76 /** Whether or not to fixup win32 casing. */ 77 static int g_fFixCase = 0; 71 78 72 79 … … 79 86 * The buffer must be able to hold one more byte than the string length. 80 87 */ 81 void w32_fixcase(char *pszPath)88 void fixcase(char *pszPath) 82 89 { 83 90 #define my_assert(expr) \ … … 189 196 } 190 197 198 /** 199 * Corrects all slashes to unix slashes. 200 * 201 * @returns pszFilename. 202 * @param pszFilename The filename to correct. 203 */ 204 char *fixslash(char *pszFilename) 205 { 206 char *psz = pszFilename; 207 while ((psz = strchr(psz, '\\')) != NULL) 208 *psz++ = '/'; 209 return pszFilename; 210 } 211 212 #elif defined(__OS2__) 213 214 /** 215 * Corrects the case of a path. 216 * 217 * @param pszPath Pointer to the path, both input and output. 218 * The buffer must be able to hold one more byte than the string length. 219 */ 220 void fixcase(char *pszFilename) 221 { 222 return; 223 } 224 225 #else 226 227 /** 228 * Corrects the case of a path. 229 * 230 * @param pszPath Pointer to the path, both input and output. 231 */ 232 void fixcase(char *pszFilename) 233 { 234 char *psz; 235 236 /* 237 * Skip the root. 238 */ 239 psz = pszFilename; 240 while (*psz == '/') 241 psz++; 242 243 /* 244 * Iterate all the components. 245 */ 246 while (*psz) 247 { 248 char chSlash; 249 struct stat s; 250 char *pszStart = psz; 251 252 /* 253 * Find the next slash (or end of string) and terminate the string there. 254 */ 255 while (*psz != '/' && *psz) 256 *psz++; 257 chSlash = *psz; 258 *psz = '\0'; 259 260 /* 261 * Does this part exist? 262 * If not we'll enumerate the directory and search for an case-insensitive match. 263 */ 264 if (stat(pszFilename, &s)) 265 { 266 struct dirent *pEntry; 267 DIR *pDir; 268 if (pszStart == pszFilename) 269 pDir = opendir(*pszFilename ? pszFilename : "."); 270 else 271 { 272 pszStart[-1] = '\0'; 273 pDir = opendir(pszFilename); 274 pszStart[-1] = '/'; 275 } 276 if (!pDir) 277 { 278 *psz = chSlash; 279 break; /* giving up, if we fail to open the directory. */ 280 } 281 282 while ((pEntry = readdir(pDir)) != NULL) 283 { 284 if (!strcasecmp(pEntry->d_name, pszStart)) 285 { 286 strcpy(pszStart, pEntry->d_name); 287 break; 288 } 289 } 290 closedir(pDir); 291 if (!pEntry) 292 { 293 *psz = chSlash; 294 break; /* giving up if not found. */ 295 } 296 } 297 298 /* restore the slash and press on. */ 299 *psz = chSlash; 300 while (*psz == '/') 301 psz++; 302 } 303 304 return; 305 } 306 307 191 308 #endif 309 192 310 193 311 … … 203 321 for (pDep = g_pDeps; pDep; pDep = pDep->pNext) 204 322 { 323 struct stat s; 324 #ifdef __WIN32__ 325 char szFilename[_MAX_PATH + 1]; 326 #else 327 char szFilename[PATH_MAX + 1]; 328 #endif 329 char *pszFilename; 330 char *psz; 331 205 332 /* 206 333 * Skip some fictive names like <built-in> and <command line>. … … 209 336 && pDep->szFilename[pDep->cchFilename - 1] == '>') 210 337 continue; 211 212 #if defined(__WIN32__) 213 { 214 char *psz; 215 char szFilename[_MAX_PATH + 1]; 216 if (_fullpath(szFilename, pDep->szFilename, sizeof(szFilename))) 217 w32_fixcase(szFilename); 218 psz = szFilename; 219 while ((psz = strchr(psz, '\\')) != NULL) 220 *psz++ = '/'; 221 fprintf(pOutput, " \\\n\t%s", szFilename); 222 } 223 224 #elif !defined(__OS2__) 225 { 226 const char *psz = strchr(pDep->szFilename, ':'); 227 if (psz) 228 fprintf(pOutput, " \\\n\t%s", psz + 1); 338 pszFilename = pDep->szFilename; 339 340 #if !defined(__OS2__) && !defined(__WIN32__) 341 /* 342 * Skip any drive letters from compilers running in wine. 343 */ 344 if (pszFilename[1] == ':') 345 pszFilename += 2; 346 #endif 347 348 /* 349 * The microsoft compilers are notoriously screwing up the casing. 350 * This will screw with kmk (/ GNU Make) on case sensitive systems, it 351 * may even do so on win32... 352 */ 353 if (g_fFixCase) 354 { 355 #ifdef __WIN32__ 356 if (_fullpath(szFilename, pszFilename, sizeof(szFilename))) 357 fixslash(szFilename); 229 358 else 230 fprintf(pOutput, " \\\n\t%s", pDep->szFilename); 231 } 232 233 #else /* __OS2__ */ 234 fprintf(pOutput, " \\\n\t%s", pDep->szFilename); 235 236 #endif /* __OS2__ */ 237 } 359 #endif 360 strcpy(szFilename, pszFilename); 361 fixcase(szFilename); 362 pszFilename = szFilename; 363 } 364 365 /* 366 * Check that the file exists before we start depending on it. 367 */ 368 if (stat(pszFilename, &s)) 369 { 370 fprintf(stderr, "kDepPre: Skipping '%s' - %s!\n", szFilename, strerror(errno)); 371 continue; 372 } 373 374 fprintf(pOutput, " \\\n\t%s", pszFilename); 375 } /* foreach dependency */ 238 376 fprintf(pOutput, "\n\n"); 239 377 } … … 476 614 static void usage(const char *argv0) 477 615 { 478 printf("syntax: %s [-l=c] -o <output> -t <target> < - | <filename> | -e <cmdline> >\n", argv0);616 printf("syntax: %s [-l=c] -o <output> -t <target> [-f] < - | <filename> | -e <cmdline> >\n", argv0); 479 617 } 480 618 … … 526 664 pszOutput = argv[i]; 527 665 } 528 pOutput = fopen(pszOutput, "w"); 666 if (pszOutput[0] == '-' && !pszOutput[1]) 667 pOutput = stdout; 668 else 669 pOutput = fopen(pszOutput, "w"); 529 670 if (!pOutput) 530 671 { … … 591 732 } 592 733 593 594 734 /* 595 735 * Pipe input. … … 599 739 pInput = stdin; 600 740 fInput = 1; 741 break; 742 } 743 744 /* 745 * Fix case. 746 */ 747 case 'f': 748 { 749 g_fFixCase = 1; 601 750 break; 602 751 }
Note:
See TracChangeset
for help on using the changeset viewer.