Changeset 2942 for trunk/tools
- Timestamp:
- Feb 29, 2000, 11:48:11 AM (26 years ago)
- Location:
- trunk/tools/fastdep
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/fastdep/fastdep.c
r2869 r2942 1 /* $Id: fastdep.c,v 1. 2 2000-02-23 09:26:58bird Exp $1 /* $Id: fastdep.c,v 1.3 2000-02-29 10:48:10 bird Exp $ 2 2 * 3 3 * Fast dependents. (Fast = Quick and Dirty!) 4 4 * 5 * Copyright (c) 1999 knut st. osmundsen5 * Copyright (c) 1999-2000 knut st. osmundsen 6 6 * 7 7 * Project Odin Software License can be found in LICENSE.TXT … … 35 35 const char * pszObjectExt; 36 36 const char * pszObjectDir; 37 const char * pszRsrcExt; 37 38 BOOL fObjRule; 38 39 BOOL fNoObjectPath; … … 42 43 43 44 44 /******************************************************************************* 45 * Global Variables * 46 *******************************************************************************/ 47 static const char pszDefaultDepFile[] = ".depend"; 45 /* 46 * Language specific analysis functions type. 47 */ 48 typedef int ( _FNLANG) (FILE *phDep, const char *pszFilename, FILE *phFile, 49 BOOL fHeader, POPTIONS pOptions); 50 typedef _FNLANG *PFNLANG; 51 52 53 /** 54 * This struct holds the static configuration of the util. 55 */ 56 typedef struct _ConfigEntry 57 { 58 const char **papszExts; /* Pointer to an array of pointer to extentions for this handler. */ 59 /* If NULL this is the last entry. */ 60 int iFirstHdr; /* Index into the papszExts array of the first headerfile/copybook. */ 61 /* Set it to the NULL element of the array if no headers for this extention. */ 62 /* A non-header file may get a object rule. */ 63 PFNLANG pfn; /* Pointer to handler function. */ 64 } CONFIGENTRY, *PCONFIGENTRY; 65 48 66 49 67 /******************************************************************************* … … 52 70 static void syntax(void); 53 71 static int makeDependent(FILE *phDep, const char *pszFilename, POPTIONS pOptions); 54 static int getFullIncludename(char *pszFilename, const char *pszInclude); 72 73 int langC_CPP(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions); 74 int langAsm(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions); 75 int langRC(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions); 76 int langCOBOL(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions); 77 78 79 /* string operations */ 80 static int strnicmpwords(const char *pszS1, const char *pszS2, int cch); 55 81 56 82 /* file operations */ … … 61 87 char *fileExt(const char *pszFilename, char *pszBuffer); 62 88 89 /* pathlist operations */ 63 90 char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer); 91 92 93 /******************************************************************************* 94 * Global Variables * 95 *******************************************************************************/ 96 static const char pszDefaultDepFile[] = ".depend"; 97 static const char *apszExtC_CPP[] = {"c", "sqc", "cpp", "h", "hpp", NULL}; 98 static const char *apszExtAsm[] = {"asm", "inc", NULL}; 99 static const char *apszExtRC[] = {"rc", "dlg", NULL}; 100 static const char *apszExtCOBOL[] = {"cbl", "cob", "sqb", NULL}; 101 102 static CONFIGENTRY aConfig[] = 103 { 104 { 105 apszExtC_CPP, 106 3, 107 langC_CPP, 108 }, 109 110 { 111 apszExtAsm, 112 1, 113 langAsm, 114 }, 115 116 { 117 apszExtRC, 118 1, 119 langRC, 120 }, 121 122 { 123 apszExtCOBOL, 124 3, 125 langCOBOL, 126 }, 127 128 /* terminating entry */ 129 { 130 NULL, 131 -1, 132 NULL 133 } 134 }; 64 135 65 136 … … 86 157 const char *pszDepFile = pszDefaultDepFile; 87 158 88 static char szObjectDir[CCHMAXPATH] = {0}; 89 static char szObjectExt[64] = {"obj"}; 159 static char szObjectDir[CCHMAXPATH]; 160 static char szObjectExt[64] = "obj"; 161 static char szRsrcExt[64] = "res"; 90 162 static char szInclude[32768] = ";"; 91 163 static char szExclude[32768] = ";"; … … 98 170 szObjectExt, /* pszObjectExt */ 99 171 szObjectDir, /* pszObjectDir */ 172 szRsrcExt, /* pszRsrcExt */ 100 173 TRUE, /* fObjRule */ 101 174 FALSE, /* fNoObjectPath */ … … 103 176 FALSE /* fAppend */ 104 177 }; 178 179 szObjectDir[0] = '\0'; 105 180 106 181 if (argc == 1) … … 221 296 break; 222 297 298 case 'r': 299 case 'R': 300 if (strlen(argv[argi]) > 2) 301 strcpy(szObjectExt, argv[argi]+2); 302 else 303 { 304 strcpy(szObjectExt, argv[argi+1]); 305 argi++; 306 } 307 break; 308 223 309 case 'h': 224 310 case 'H': … … 236 322 { /* not a parameter! */ 237 323 ULONG ulRc; 238 FILEFINDBUF3 filebuf = {0};324 FILEFINDBUF3 filebuf; 239 325 HDIR hDir = HDIR_CREATE; 240 326 ULONG ulFound = 1; 327 328 memset(&filebuf, 0, sizeof(filebuf)); 241 329 242 330 /* … … 323 411 " -obr<[+]|-> -obr+: Object rule.\n" 324 412 " -obr-: No object rule, rule for source filename is generated.\n" 413 " -obj[ ]<objext> Object extention. Default: obj\n" 414 " -r[ ]<rsrcext> Resource binary extention. Default: res\n" 325 415 " <files> Files to scan. Wildchars are allowed.\n" 326 416 "\n", … … 341 431 static int makeDependent(FILE *phDep, const char *pszFilename, POPTIONS pOptions) 342 432 { 433 int rc = -1; 343 434 FILE *phFile; 344 435 … … 346 437 if (phFile != NULL) 347 438 { 348 char szBuffer[4096]; /* max line lenght */349 int k = strlen(pszFilename) - 1;350 int l;351 int iLine; 352 353 /**********************************/354 /* print file name to depend file*/355 /**********************************/356 if (pOptions->fObjRule)439 char szExt[CCHMAXPATH]; 440 PCONFIGENTRY pCfg = &aConfig[0]; 441 BOOL fHeader; 442 443 /* 444 * Find which filetype this is... 445 */ 446 fileExt(pszFilename, szExt); 447 while (pCfg->papszExts != NULL) 357 448 { 358 char szExt[CCHMAXPATH]; 359 char szObj[CCHMAXPATH]; 360 361 if (pOptions->fNoObjectPath) 362 fileNameNoExt(pszFilename, szObj); 363 else if (*pOptions->pszObjectDir != '\0') 449 const char **ppsz = pCfg->papszExts; 450 while (*ppsz != NULL && stricmp(*ppsz, szExt) != 0) 451 ppsz++; 452 if (*ppsz != NULL) 364 453 { 365 fileNameNoExt(pszFilename, szExt); 366 strcpy(szObj, pOptions->pszObjectDir); 367 strcat(szObj, szExt); 454 fHeader = &pCfg->papszExts[pCfg->iFirstHdr] <= ppsz; 455 break; 368 456 } 369 else 370 { 371 filePathSlash(pszFilename, szObj); 372 fileNameNoExt(pszFilename, szObj + strlen(szObj)); 373 } 374 375 fileExt(pszFilename, szExt); 376 if (!stricmp(szExt, "c") || !stricmp(szExt, "sqc") 377 || !stricmp(szExt, "cpp") || !stricmp(szExt, "asm") 378 || !stricmp(szExt, "rc")) 379 { 380 if (!stricmp(szExt, "rc")) 381 strcat(szObj, ".res"); 382 else 383 { 384 strcat(szObj, "."); 385 strcat(szObj, pOptions->pszObjectExt); 386 } 387 fprintf(phDep, "%s:", szObj); 388 389 if (pOptions->fSrcWhenObj) 390 fprintf(phDep, " \\\n%6s %s", "", pszFilename); 391 } 392 else 393 fprintf(phDep, "%s:", pszFilename); 457 pCfg++; 394 458 } 459 460 /* Found? */ 461 if (pCfg->papszExts != NULL) 462 rc = (*pCfg->pfn)(phDep, pszFilename, phFile, fHeader, pOptions); 395 463 else 396 fprintf(phDep, "%s:", pszFilename);397 398 /*******************/399 /* find dependants */400 /*******************/401 iLine = 0;402 while (!feof(phFile)) /* line loop */403 464 { 404 if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL) 405 { 406 /* search for #include or RCINCLUDE */ 407 int cbLen; 408 int i = 0; 409 iLine++; 410 411 cbLen = strlen(szBuffer); 412 while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t')) 413 i++; 414 415 /* Found include! */ 416 if (strncmp(&szBuffer[i], "#include", 8) == 0 || strncmp(&szBuffer[i], "RCINCLUDE", 9) == 0) 417 { 418 int f = 0; 419 420 /* extract info between "" or <> */ 421 while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<'))) 422 i++; 423 i++; /* skip '"' or '<' */ 424 if (f) 425 { 426 int j; 427 /* find end */ 428 j = f = 0; 429 while (i + j < cbLen && j < CCHMAXPATH && 430 !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>'))) 431 j++; 432 433 if (f) 434 { 435 char szFullname[CCHMAXPATH]; 436 char *psz; 437 438 /* copy filename */ 439 strncpy(szFullname, &szBuffer[i], j); 440 szFullname[j] = '\0'; /* ensure terminatition. */ 441 442 /* find include file! */ 443 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer); 444 if (psz == NULL) 445 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer); 446 447 if (psz != NULL) 448 { 449 char szBuffer2[CCHMAXPATH]; 450 if (pOptions->fExcludeAll || 451 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL 452 ) 453 strcpy(szBuffer, szFullname); 454 fprintf(phDep, " \\\n%6.s %s", "", szBuffer); 455 } 456 else 457 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n", 458 pszFilename, iLine, szFullname); 459 } 460 } 461 } 462 } 463 /* 464 else 465 break; 466 */ 467 } /*while*/ 465 if (*fileName(pszFilename, szExt) != '.') /* these are 'hidden' files, like .cvsignore, let's ignore them. */ 466 fprintf(stderr, "warning: '%s' has an unknown file type.\n", pszFilename); 467 rc = 0; 468 } 469 468 470 fputs("\n", phDep); 469 471 fclose(phFile); 470 472 } 471 473 else 472 {473 474 fprintf(stderr, "failed to open '%s'\n", pszFilename); 474 return -1; 475 476 return rc; 477 } 478 479 480 /** 481 * Generates depend info on this C or C++ file, and writes it to phDep. 482 * @returns 0 on success. 483 * !0 on error. 484 * @param phDep Pointer to file struct for outfile. 485 * @param pszFilename Pointer to source filename. 486 * @param phFile Pointer to source file handle. 487 * @param pOptions Pointer to options struct. 488 * @status completely implemented. 489 * @author knut st. osmundsen 490 */ 491 int langC_CPP(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 492 { 493 char szBuffer[4096]; /* max line length */ 494 int iLine; 495 496 497 /**********************************/ 498 /* print file name to depend file */ 499 /**********************************/ 500 if (pOptions->fObjRule && !fHeader) 501 { 502 if (pOptions->fNoObjectPath) 503 fprintf(phDep, "%s.%s:", fileNameNoExt(pszFilename, szBuffer), pOptions->pszObjectExt); 504 else 505 fprintf(phDep, "%s%s.%s:", 506 (*pOptions->pszObjectDir != '\0') ? 507 pOptions->pszObjectDir : filePathSlash(pszFilename, szBuffer), 508 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 509 pOptions->pszObjectExt); 510 511 if (pOptions->fSrcWhenObj) 512 fprintf(phDep, " \\\n%4s %s", "", pszFilename); 475 513 } 476 477 return 0; 478 } 479 480 481 482 483 /** 484 * Gets the fullpath include-filename. 485 * @returns 0 on success, -1 on error. 486 * @param pszFilename Input: Pointer to filename to be found, and buffer for output. 487 * Ouput: Buffer now contains fullpath include-filename. 488 * @param pszInclude Additional includepath. 489 */ 490 static int getFullIncludename(char *pszFilename, const char *pszInclude) 491 { 492 const char *pszEnvInclude; 493 const char *psz; 494 495 pszEnvInclude = getenv("INCLUDE"); 496 if ((pszEnvInclude == NULL && (pszInclude == NULL || strlen(pszInclude) == 0)) || strlen(pszFilename) == 0) 497 return -1; 498 499 psz = ""; 500 while (psz != NULL && psz != '\0') 501 { 502 const char *pszNext; 503 int cbLen; 504 char szFileTmpIn[260]; 505 FILEFINDBUF3 filebuf; 506 ULONG ulRc; 507 HDIR hDir = HDIR_CREATE; 508 ULONG ulFound = 1; 509 510 /* get addr of next ';' or '\0' */ 511 pszNext = strchr(psz, ';'); 512 if (pszNext == NULL) 513 pszNext = psz + strlen(psz); 514 515 /* add a '\\' and the pszFilename string to the include path part. */ 516 cbLen = (int)pszNext - (int)psz; 517 if (cbLen > 0) 514 else 515 fprintf(phDep, "%s:", pszFilename); 516 517 518 /*******************/ 519 /* find dependants */ 520 /*******************/ 521 iLine = 0; 522 while (!feof(phFile)) /* line loop */ 523 { 524 if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL) 518 525 { 519 strncpy(szFileTmpIn, psz, (int)pszNext - (int)psz); 520 if (szFileTmpIn[cbLen - 1] != '\\' && szFileTmpIn[cbLen - 1] != '/') 521 szFileTmpIn[cbLen++] = '\\'; 522 } 523 strcpy(&szFileTmpIn[cbLen], pszFilename); 524 525 526 /**************************/ 527 /* check if file is found */ 528 /**************************/ 529 ulRc = DosFindFirst(&szFileTmpIn[0], &hDir, 530 FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_ARCHIVED, 531 &filebuf, sizeof(FILEFINDBUF3), &ulFound, FIL_STANDARD); 532 if (ulRc == NO_ERROR) 533 { 534 strcpy(pszFilename, szFileTmpIn); 535 DosFindClose(hDir); 536 return 0; 537 } 538 539 /* next */ 540 if (*pszNext == ';' && pszNext[1] != '\0') 541 psz = pszNext + 1; 542 else 543 { 544 psz = pszInclude; 545 pszInclude = NULL; 546 547 if (psz == NULL) 526 /* search for #include */ 527 int cbLen; 528 int i = 0; 529 iLine++; 530 531 /* skip blank chars */ 532 cbLen = strlen(szBuffer); 533 while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t')) 534 i++; 535 536 /* is this an include? */ 537 if (szBuffer[i] == '#' && strncmp(&szBuffer[i], "#include", 8) == 0) 548 538 { 549 psz = pszEnvInclude; 550 pszEnvInclude = NULL; 539 char szFullname[CCHMAXPATH]; 540 char *psz; 541 BOOL f = FALSE; 542 int j; 543 544 /* extract info between "" or <> */ 545 while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<'))) 546 i++; 547 i++; /* skip '"' or '<' */ 548 549 /* if invalid statement then continue with the next line! */ 550 if (!f) continue; 551 552 /* find end */ 553 j = f = 0; 554 while (i + j < cbLen && j < CCHMAXPATH && 555 !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>'))) 556 j++; 557 558 /* if invalid statement then continue with the next line! */ 559 if (!f) continue; 560 561 /* copy filename */ 562 strncpy(szFullname, &szBuffer[i], j); 563 szFullname[j] = '\0'; /* ensure terminatition. */ 564 565 /* find include file! */ 566 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer); 567 if (psz == NULL) 568 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer); 569 570 /* did we find the include? */ 571 if (psz != NULL) 572 { 573 char szBuffer2[CCHMAXPATH]; 574 if (pOptions->fExcludeAll || 575 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL 576 ) 577 strcpy(szBuffer, szFullname); 578 fprintf(phDep, " \\\n%4.s %s", "", szBuffer); 579 } 580 else 581 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n", 582 pszFilename, iLine, szFullname); 551 583 } 552 584 } 585 else 586 break; 587 } /*while*/ 588 fputs("\n", phDep); 589 590 return 0; 591 } 592 593 594 /** 595 * Generates depend info on this file, and fwrites it to phDep. 596 * @returns 0 on success. 597 * !0 on error. 598 * @param phDep Pointer to file struct for outfile. 599 * @param pszFilename Pointer to source filename. 600 * @param phFile Pointer to source file handle. 601 * @param pOptions Pointer to options struct. 602 * @status completely implemented. 603 * @author knut st. osmundsen 604 */ 605 int langAsm(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 606 { 607 char szBuffer[4096]; /* max line length */ 608 int iLine; 609 610 611 /**********************************/ 612 /* print file name to depend file */ 613 /**********************************/ 614 if (pOptions->fObjRule && !fHeader) 615 { 616 if (pOptions->fNoObjectPath) 617 fprintf(phDep, "%s.%s:", fileNameNoExt(pszFilename, szBuffer), pOptions->pszObjectExt); 618 else 619 fprintf(phDep, "%s%s.%s:", 620 (*pOptions->pszObjectDir != '\0') ? 621 pOptions->pszObjectDir : filePathSlash(pszFilename, szBuffer), 622 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 623 pOptions->pszObjectExt); 624 625 if (pOptions->fSrcWhenObj) 626 fprintf(phDep, " \\\n%4s %s", "", pszFilename); 553 627 } 554 555 return -1; 556 } 557 558 628 else 629 fprintf(phDep, "%s:", pszFilename); 630 631 632 /*******************/ 633 /* find dependants */ 634 /*******************/ 635 iLine = 0; 636 while (!feof(phFile)) /* line loop */ 637 { 638 if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL) 639 { 640 /* search for include */ 641 int cbLen; 642 int i = 0; 643 iLine++; 644 645 /* skip blank chars */ 646 cbLen = strlen(szBuffer); 647 while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t')) 648 i++; 649 650 /* is this an include? */ 651 if (strnicmp(&szBuffer[i], "include", 7) == 0 652 && (szBuffer[i + 7] == '\t' || szBuffer[i + 7] == ' ') 653 ) 654 { 655 char szFullname[CCHMAXPATH]; 656 char *psz; 657 int j; 658 659 /* skip to first no blank char */ 660 i += 7; 661 while (i < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t')) 662 i++; 663 664 /* comment check - if comment found, no filename was given. continue. */ 665 if (szBuffer[i] == ';') continue; 666 667 /* find end */ 668 j = 0; 669 while (i + j < cbLen 670 && j < CCHMAXPATH 671 && szBuffer[i+j] != ' ' && szBuffer[i+j] != '\t' && szBuffer[i+j] != '\n' 672 && szBuffer[i+j] != '\0' && szBuffer[i+j] != ';' && szBuffer[i+j] != '\r' 673 ) 674 j++; 675 676 /* copy filename */ 677 strncpy(szFullname, &szBuffer[i], j); 678 szFullname[j] = '\0'; /* ensure terminatition. */ 679 680 /* find include file! */ 681 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer); 682 if (psz == NULL) 683 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer); 684 685 /* Did we find the include? */ 686 if (psz != NULL) 687 { 688 char szBuffer2[CCHMAXPATH]; 689 if (pOptions->fExcludeAll || 690 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL 691 ) 692 strcpy(szBuffer, szFullname); 693 fprintf(phDep, " \\\n%4.s %s", "", szBuffer); 694 } 695 else 696 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n", 697 pszFilename, iLine, szFullname); 698 } 699 } 700 else 701 break; 702 } /*while*/ 703 fputs("\n", phDep); 704 705 return 0; 706 } 707 708 709 /** 710 * Generates depend info on this Resource file, and writes it to phDep. 711 * @returns 0 on success. 712 * !0 on error. 713 * @param phDep Pointer to file struct for outfile. 714 * @param pszFilename Pointer to source filename. 715 * @param phFile Pointer to source file handle. 716 * @param pOptions Pointer to options struct. 717 * @status completely implemented. 718 * @author knut st. osmundsen 719 */ 720 int langRC(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 721 { 722 char szBuffer[4096]; /* max line length */ 723 int iLine; 724 725 /**********************************/ 726 /* print file name to depend file */ 727 /**********************************/ 728 if (pOptions->fObjRule && !fHeader) 729 { 730 if (pOptions->fNoObjectPath) 731 fprintf(phDep, "%s.%s:", fileNameNoExt(pszFilename, szBuffer), pOptions->pszRsrcExt); 732 else 733 fprintf(phDep, "%s%s.res:", 734 (*pOptions->pszObjectDir != '\0') ? 735 pOptions->pszObjectDir : filePathSlash(pszFilename, szBuffer), 736 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 737 pOptions->pszRsrcExt); 738 739 if (pOptions->fSrcWhenObj) 740 fprintf(phDep, " \\\n%4s %s", "", pszFilename); 741 } 742 else 743 fprintf(phDep, "%s:", pszFilename); 744 745 746 /*******************/ 747 /* find dependants */ 748 /*******************/ 749 iLine = 0; 750 while (!feof(phFile)) /* line loop */ 751 { 752 if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL) 753 { 754 /* search for #include */ 755 int cbLen; 756 int i = 0; 757 iLine++; 758 759 /* skip blank chars */ 760 cbLen = strlen(szBuffer); 761 while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t')) 762 i++; 763 764 /* is this an include? */ 765 if ( strncmp(&szBuffer[i], "#include", 8) == 0 766 || strncmp(&szBuffer[i], "RCINCLUDE", 9) == 0 767 || strncmp(&szBuffer[i], "DLGINCLUDE", 10) == 0 768 ) 769 { 770 char szFullname[CCHMAXPATH]; 771 char *psz; 772 BOOL f = FALSE; 773 int j; 774 775 /* extract info between "" or <> */ 776 while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<'))) 777 i++; 778 i++; /* skip '"' or '<' */ 779 780 /* if invalid statement then continue with the next line! */ 781 if (!f) continue; 782 783 /* find end */ 784 j = f = 0; 785 while (i + j < cbLen && j < CCHMAXPATH && 786 !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>'))) 787 j++; 788 789 /* if invalid statement then continue with the next line! */ 790 if (!f) continue; 791 792 /* copy filename */ 793 strncpy(szFullname, &szBuffer[i], j); 794 szFullname[j] = '\0'; /* ensure terminatition. */ 795 796 /* find include file! */ 797 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer); 798 if (psz == NULL) 799 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer); 800 801 /* did we find the include? */ 802 if (psz != NULL) 803 { 804 char szBuffer2[CCHMAXPATH]; 805 if (pOptions->fExcludeAll || 806 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL 807 ) 808 strcpy(szBuffer, szFullname); 809 fprintf(phDep, " \\\n%4.s %s", "", szBuffer); 810 } 811 else 812 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n", 813 pszFilename, iLine, szFullname); 814 } 815 } 816 else 817 break; 818 } /*while*/ 819 fputs("\n", phDep); 820 821 return 0; 822 } 823 824 825 /** 826 * Generates depend info on this COBOL file, and writes it to phDep. 827 * @returns 0 on success. 828 * !0 on error. 829 * @param phDep Pointer to file struct for outfile. 830 * @param pszFilename Pointer to source filename. 831 * @param phFile Pointer to source file handle. 832 * @param pOptions Pointer to options struct. 833 * @status completely implemented. 834 * @author knut st. osmundsen 835 */ 836 int langCOBOL(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 837 { 838 char szBuffer[4096]; /* max line length */ 839 int iLine; 840 841 /**********************************/ 842 /* print file name to depend file */ 843 /**********************************/ 844 if (pOptions->fObjRule && !fHeader) 845 { 846 if (pOptions->fNoObjectPath) 847 fprintf(phDep, "%s.%s:", fileNameNoExt(pszFilename, szBuffer), pOptions->pszObjectExt); 848 else 849 fprintf(phDep, "%s%s.%s:", 850 (*pOptions->pszObjectDir != '\0') ? 851 pOptions->pszObjectDir : filePathSlash(pszFilename, szBuffer), 852 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 853 pOptions->pszObjectExt); 854 855 if (pOptions->fSrcWhenObj) 856 fprintf(phDep, " \\\n%4s %s", "", pszFilename); 857 } 858 else 859 fprintf(phDep, "%s:", pszFilename); 860 861 862 /*******************/ 863 /* find dependants */ 864 /*******************/ 865 iLine = 0; 866 while (!feof(phFile)) /* line loop */ 867 { 868 if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL) 869 { 870 /* search for #include */ 871 int cbLen; 872 int i = 0; 873 int i1, i2; 874 iLine++; 875 876 /* check for comment mark (column 7) */ 877 if (szBuffer[6] == '*') 878 continue; 879 880 /* skip blank chars */ 881 cbLen = strlen(szBuffer); 882 while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t')) 883 i++; 884 885 /* is this an include? */ 886 if ( (i1 = strnicmp(&szBuffer[i], "COPY", 4)) == 0 887 || (i2 = strnicmpwords(&szBuffer[i], "EXEC SQL INCLUDE", 16)) == 0 888 ) 889 { 890 char szFullname[CCHMAXPATH]; 891 char *psz; 892 int j; 893 894 /* skip statement */ 895 i += 4; 896 if (i1 != 0) 897 { 898 int y = 2; /* skip two words */ 899 do 900 { 901 /* skip blanks */ 902 while (szBuffer[i] == ' ' || szBuffer[i] == '\t') 903 i++; 904 /* skip word */ 905 while (szBuffer[i] != ' ' && szBuffer[i] != '\t' 906 && szBuffer[i] != '\0' && szBuffer[i] != '\n') 907 i++; 908 y--; 909 } while (y > 0); 910 } 911 912 /* check for blank */ 913 if (szBuffer[i] != ' ' && szBuffer[i] != '\t') /* no copybook specified... */ 914 continue; 915 916 /* skip blanks */ 917 while (szBuffer[i] == ' ' || szBuffer[i] == '\t') 918 i++; 919 920 /* if invalid statement then continue with the next line! */ 921 if (szBuffer[i] == '\0' || szBuffer[i] == '\n') 922 continue; 923 924 /* find end */ 925 j = 0; 926 while (i + j < cbLen && j < CCHMAXPATH 927 && szBuffer[i+j] != '.' 928 && szBuffer[i+j] != ' ' && szBuffer[i+j] != '\t' 929 && szBuffer[i+j] != '\0' && szBuffer[i+j] != '\n' 930 ) 931 j++; 932 933 /* if invalid statement then continue with the next line! */ 934 if (szBuffer[i+j] != '.' && szBuffer[i+j] != ' ' && szBuffer[i] != '\t') 935 continue; 936 937 /* copy filename */ 938 strncpy(szFullname, &szBuffer[i], j); 939 szFullname[j] = '\0'; /* ensure terminatition. */ 940 941 /* add extention .cpy - hardcoded for the moment. */ 942 strcat(szFullname, ".cpy"); 943 944 /* find include file! */ 945 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer); 946 947 /* did we find the include? */ 948 if (psz != NULL) 949 { 950 char szBuffer2[CCHMAXPATH]; 951 if (pOptions->fExcludeAll || 952 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL 953 ) 954 strcpy(szBuffer, szFullname); 955 fprintf(phDep, " \\\n%4.s %s", "", szBuffer); 956 } 957 else 958 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n", 959 pszFilename, iLine, szFullname); 960 } 961 } 962 else 963 break; 964 } /*while*/ 965 fputs("\n", phDep); 966 967 return 0; 968 } 969 970 #define upcase(ch) \ 971 (ch >= 'a' && ch <= 'z' ? ch - ('a' - 'A') : ch) 972 973 /** 974 * Compares words. Multiple spaces are treates as on single blank i both string when comparing them. 975 * @returns 0 equal. (same as strnicmp) 976 * @param pszS1 String 1 977 * @param pszS2 String 2 978 * @param cch Length to compare (relative to string 1) 979 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 980 */ 981 static int strnicmpwords(const char *pszS1, const char *pszS2, int cch) 982 { 983 do 984 { 985 while (cch > 0 && upcase(*pszS1) == upcase(*pszS2) && *pszS1 != ' ') 986 pszS1++, pszS2++, cch--; 987 988 /* blank test and skipping */ 989 if (cch > 0 && *pszS1 == ' ' && *pszS2 == ' ') 990 { 991 while (cch > 0 && *pszS1 == ' ') 992 pszS1++, cch--; 993 994 while (*pszS2 == ' ') 995 pszS2++; 996 } 997 else 998 break; 999 } while (cch > 0); 1000 1001 return cch == 0 ? 0 : *pszS1 - *pszS2; 1002 } 559 1003 560 1004 /** -
trunk/tools/fastdep/makefile
r2714 r2942 1 # $Id: makefile,v 1. 1 2000-02-09 23:48:49bird Exp $1 # $Id: makefile,v 1.2 2000-02-29 10:48:11 bird Exp $ 2 2 3 3 # … … 16 16 !ifdef DEBUG 17 17 CFLAGS = $(CFLAGS) -Ge+ -Tx+ -I$(PDWIN32_INCLUDE) -I..\common \ 18 -W3 # -Wall+ppt-ppc-inl-cnv-gnr-vft--O+18 -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- #-O+ 19 19 LDFLAGS = $(LDFLAGS) -Ge+ -Fe$@ /B"/MAP:full" 20 20 !else 21 21 CFLAGS = $(CFLAGS) -Ge+ -Tx+ -I$(PDWIN32_INCLUDE) -I..\common \ 22 -W3 # -Wall+ppt-ppc-inl-cnv-gnr-vft-22 -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- 23 23 LDFLAGS = $(LDFLAGS) -Ge+ -Fe$@ /B"/MAP:full" 24 24 !endif
Note:
See TracChangeset
for help on using the changeset viewer.