Changeset 3020 for trunk/tools
- Timestamp:
- Mar 5, 2000, 12:51:57 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/fastdep/fastdep.c
r2942 r3020 1 /* $Id: fastdep.c,v 1. 3 2000-02-29 10:48:10bird Exp $1 /* $Id: fastdep.c,v 1.4 2000-03-04 23:51:57 bird Exp $ 2 2 * 3 3 * Fast dependents. (Fast = Quick and Dirty!) … … 21 21 #include <os2.h> 22 22 #include <stdio.h> 23 #include <string.h> 24 #include <stdlib.h> 25 26 /* 27 * This following section is used while testing fastdep. 28 * stdio.h should be included; string.h never included. 29 */ 30 /* 31 #include <stdio.h> 23 32 #include <stdlib.h> 24 33 #include <string.h> 25 34 */ 35 36 #if 1 37 #include <stdio.h> 38 #else 39 #include <string.h> 40 #include <string.h> 41 #endif 42 43 /* 44 */ /* */ /* 45 #include <string.h> 46 */ 47 #if 1 48 # if 1 49 #if 0 50 # include <string.h> 51 #else 52 # if 1 53 #if 1 54 #if 0 55 # include <string.h> 56 #else /* */ /* 57 */ 58 # include <stdio.h> 59 #endif 60 #endif 61 #endif 62 #endif 63 #endif 64 #endif 26 65 27 66 /******************************************************************************* … … 90 129 char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer); 91 130 131 /* word operations */ 132 static char *findEndOfWord(char *psz); 133 #if 0 /* not used */ 134 static char *findStartOfWord(char *psz, const char *pszStart); 135 #endif 92 136 93 137 /******************************************************************************* … … 491 535 int langC_CPP(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 492 536 { 493 char szBuffer[4096]; /* max line length */ 494 int iLine; 537 int iLine; /* Linenumber. */ 538 char szBuffer[4096]; /* Max line length is 4096... should not be a problem. */ 539 BOOL fComment; /* TRUE when within a multiline comment. */ 540 /* FALSE when not within a multiline comment. */ 541 int iIfStack; /* StackPointer. */ 542 struct IfStackEntry 543 { 544 int fIncluded : 1; /* TRUE: include this code; 545 * FALSE: excluded */ 546 int fIf : 1; /* TRUE: #if part of the expression. 547 * FALSE: #else part of the expression. */ 548 int fSupported : 1; /* TRUE: supported if/else statement 549 * FALSE: unsupported all else[<something>] are ignored 550 * All code is included. 551 */ 552 } achIfStack[256]; 495 553 496 554 … … 519 577 /* find dependants */ 520 578 /*******************/ 579 /* Initiate the IF-stack, comment state and line number. */ 580 iIfStack = 0; 581 achIfStack[iIfStack].fIf = TRUE; 582 achIfStack[iIfStack].fIncluded = TRUE; 583 achIfStack[iIfStack].fSupported = TRUE; 584 fComment = FALSE; 585 iLine = 0; 586 while (!feof(phFile)) /* line loop */ 587 { 588 if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL) 589 { 590 /* search for #include */ 591 register char *pszC; 592 int cbLen; 593 int i = 0; 594 iLine++; 595 596 /* skip blank chars */ 597 cbLen = strlen(szBuffer); 598 while (i + 2 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t')) 599 i++; 600 601 /* preprocessor statement? */ 602 if (!fComment && szBuffer[i] == '#') 603 { 604 /* 605 * Preprocessor checks 606 * We known that we have a preprocessor statment (starting with an '#' * at szBuffer[i]). 607 * Depending on the word afterwards we'll take some different actions. 608 * So we'll start of by extracting that word and make a string swich on it. 609 * Note that there might be some blanks between the hash and the word. 610 */ 611 int cchWord; 612 char * pszEndWord; 613 char * pszArgument; 614 i++; /* skip hash ('#') */ 615 while (szBuffer[i] == '\t' || szBuffer[i] == ' ') /* skip blanks */ 616 i++; 617 pszArgument = pszEndWord = findEndOfWord(&szBuffer[i]); 618 cchWord = pszEndWord - &szBuffer[i]; 619 620 /* 621 * Find the argument by skipping the blanks. 622 */ 623 while (*pszArgument == '\t' || *pszArgument == ' ') /* skip blanks */ 624 pszArgument++; 625 626 /* 627 * string switch. 628 */ 629 if (strncmp(&szBuffer[i], "include", cchWord) == 0) 630 { 631 /* 632 * #include 633 * 634 * Are we in a state where this file is to be included? 635 */ 636 if (achIfStack[iIfStack].fIncluded) 637 { 638 char szFullname[CCHMAXPATH]; 639 char *psz; 640 BOOL f = FALSE; 641 int j; 642 643 /* extract info between "" or <> */ 644 while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<'))) 645 i++; 646 i++; /* skip '"' or '<' */ 647 648 /* if invalid statement then continue with the next line! */ 649 if (!f) continue; 650 651 /* find end */ 652 j = f = 0; 653 while (i + j < cbLen && j < CCHMAXPATH && 654 !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>'))) 655 j++; 656 657 /* if invalid statement then continue with the next line! */ 658 if (!f) continue; 659 660 /* copy filename */ 661 strncpy(szFullname, &szBuffer[i], j); 662 szFullname[j] = '\0'; /* ensure terminatition. */ 663 664 /* find include file! */ 665 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer); 666 if (psz == NULL) 667 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer); 668 669 /* did we find the include? */ 670 if (psz != NULL) 671 { 672 char szBuffer2[CCHMAXPATH]; 673 if (pOptions->fExcludeAll || 674 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL 675 ) 676 strcpy(szBuffer, szFullname); 677 fprintf(phDep, " \\\n%4.s %s", "", szBuffer); 678 } 679 else 680 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n", 681 pszFilename, iLine, szFullname); 682 } 683 } 684 else 685 /* 686 * #if 687 */ 688 if (strncmp(&szBuffer[i], "if", cchWord) == 0) 689 { /* #if 0 and #if <1-9> are supported */ 690 pszEndWord = findEndOfWord(pszArgument); 691 iIfStack++; 692 if ((pszEndWord - pszArgument) == 1 693 && *pszArgument >= '0' && *pszArgument <= '9') 694 { 695 if (*pszArgument != '0') 696 achIfStack[iIfStack].fIncluded = TRUE; 697 else 698 achIfStack[iIfStack].fIncluded = FALSE; 699 } 700 else 701 achIfStack[iIfStack].fSupported = FALSE; 702 achIfStack[iIfStack].fIncluded = TRUE; 703 achIfStack[iIfStack].fIf = TRUE; 704 } 705 else 706 /* 707 * #else 708 */ 709 if (strncmp(&szBuffer[i], "else", cchWord) == 0) 710 { 711 if (achIfStack[iIfStack].fSupported) 712 { 713 if (achIfStack[iIfStack].fIncluded) /* ARG!! this'll prevent warning */ 714 achIfStack[iIfStack].fIncluded = FALSE; 715 else 716 achIfStack[iIfStack].fIncluded = TRUE; 717 } 718 achIfStack[iIfStack].fIf = FALSE; 719 } 720 else 721 /* 722 * #endif 723 */ 724 if (strncmp(&szBuffer[i], "endif", cchWord) == 0) 725 { /* Pop the if-stack. */ 726 if (iIfStack > 0) 727 iIfStack--; 728 else 729 fprintf(stderr, "%s(%d): If-Stack underflow!\n", pszFilename, iLine); 730 } 731 /* 732 * general if<something> and elseif<something> implementations 733 */ 734 else 735 if (strncmp(&szBuffer[i], "elseif", 6) == 0) 736 { 737 achIfStack[iIfStack].fSupported = FALSE; 738 achIfStack[iIfStack].fIncluded = TRUE; 739 } 740 else 741 if (strncmp(&szBuffer[i], "if", 2) == 0) 742 { 743 iIfStack++; 744 achIfStack[iIfStack].fIf = TRUE; 745 achIfStack[iIfStack].fSupported = FALSE; 746 achIfStack[iIfStack].fIncluded = TRUE; 747 } 748 /* The rest of them aren't implemented yet. 749 else if (strncmp(&szBuffer[i], "if") == 0) 750 { 751 } 752 */ 753 } 754 755 /* 756 * Comment checks. 757 * -Start at first non-blank. 758 * -Loop thru the line since we might have more than one 759 * comment statement on a single line. 760 */ 761 pszC = &szBuffer[i]; 762 while (pszC != NULL && *pszC != '\0') 763 { 764 if (fComment) 765 pszC = strstr(pszC, "*/"); /* look for end comment mark. */ 766 else 767 { 768 char *pszLC; 769 pszLC= strstr(pszC, "//"); /* look for single line comment mark. */ 770 pszC = strstr(pszC, "/*"); /* look for start comment mark */ 771 if (pszLC && pszLC < pszC) /* if there is an single line comment mark before the */ 772 break; /* muliline comment mark we'll ignore the multiline mark. */ 773 } 774 775 /* Comment mark found? */ 776 if (pszC != NULL) 777 { 778 fComment = !fComment; 779 pszC += 2; /* skip comment mark */ 780 781 /* debug */ 782 /* 783 if (fComment) 784 fprintf(stderr, "starts at line %d\n", iLine); 785 else 786 fprintf(stderr, "ends at line %d\n", iLine); 787 */ 788 } 789 } 790 } 791 else 792 break; 793 } /*while*/ 794 fputs("\n", phDep); 795 796 return 0; 797 } 798 799 800 /** 801 * Generates depend info on this file, and fwrites it to phDep. 802 * @returns 0 on success. 803 * !0 on error. 804 * @param phDep Pointer to file struct for outfile. 805 * @param pszFilename Pointer to source filename. 806 * @param phFile Pointer to source file handle. 807 * @param pOptions Pointer to options struct. 808 * @status completely implemented. 809 * @author knut st. osmundsen 810 */ 811 int langAsm(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 812 { 813 char szBuffer[4096]; /* max line length */ 814 int iLine; 815 816 817 /**********************************/ 818 /* print file name to depend file */ 819 /**********************************/ 820 if (pOptions->fObjRule && !fHeader) 821 { 822 if (pOptions->fNoObjectPath) 823 fprintf(phDep, "%s.%s:", fileNameNoExt(pszFilename, szBuffer), pOptions->pszObjectExt); 824 else 825 fprintf(phDep, "%s%s.%s:", 826 (*pOptions->pszObjectDir != '\0') ? 827 pOptions->pszObjectDir : filePathSlash(pszFilename, szBuffer), 828 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 829 pOptions->pszObjectExt); 830 831 if (pOptions->fSrcWhenObj) 832 fprintf(phDep, " \\\n%4s %s", "", pszFilename); 833 } 834 else 835 fprintf(phDep, "%s:", pszFilename); 836 837 838 /*******************/ 839 /* find dependants */ 840 /*******************/ 841 iLine = 0; 842 while (!feof(phFile)) /* line loop */ 843 { 844 if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL) 845 { 846 /* search for include */ 847 int cbLen; 848 int i = 0; 849 iLine++; 850 851 /* skip blank chars */ 852 cbLen = strlen(szBuffer); 853 while (i + 9 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t')) 854 i++; 855 856 /* is this an include? */ 857 if (strnicmp(&szBuffer[i], "include", 7) == 0 858 && (szBuffer[i + 7] == '\t' || szBuffer[i + 7] == ' ') 859 ) 860 { 861 char szFullname[CCHMAXPATH]; 862 char *psz; 863 int j; 864 865 /* skip to first no blank char */ 866 i += 7; 867 while (i < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t')) 868 i++; 869 870 /* comment check - if comment found, no filename was given. continue. */ 871 if (szBuffer[i] == ';') continue; 872 873 /* find end */ 874 j = 0; 875 while (i + j < cbLen 876 && j < CCHMAXPATH 877 && szBuffer[i+j] != ' ' && szBuffer[i+j] != '\t' && szBuffer[i+j] != '\n' 878 && szBuffer[i+j] != '\0' && szBuffer[i+j] != ';' && szBuffer[i+j] != '\r' 879 ) 880 j++; 881 882 /* copy filename */ 883 strncpy(szFullname, &szBuffer[i], j); 884 szFullname[j] = '\0'; /* ensure terminatition. */ 885 886 /* find include file! */ 887 psz = pathlistFindFile(pOptions->pszInclude, szFullname, szBuffer); 888 if (psz == NULL) 889 psz = pathlistFindFile(getenv("INCLUDE"), szFullname, szBuffer); 890 891 /* Did we find the include? */ 892 if (psz != NULL) 893 { 894 char szBuffer2[CCHMAXPATH]; 895 if (pOptions->fExcludeAll || 896 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL 897 ) 898 strcpy(szBuffer, szFullname); 899 fprintf(phDep, " \\\n%4.s %s", "", szBuffer); 900 } 901 else 902 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n", 903 pszFilename, iLine, szFullname); 904 } 905 } 906 else 907 break; 908 } /*while*/ 909 fputs("\n", phDep); 910 911 return 0; 912 } 913 914 915 /** 916 * Generates depend info on this Resource file, and writes it to phDep. 917 * @returns 0 on success. 918 * !0 on error. 919 * @param phDep Pointer to file struct for outfile. 920 * @param pszFilename Pointer to source filename. 921 * @param phFile Pointer to source file handle. 922 * @param pOptions Pointer to options struct. 923 * @status completely implemented. 924 * @author knut st. osmundsen 925 */ 926 int langRC(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 927 { 928 char szBuffer[4096]; /* max line length */ 929 int iLine; 930 931 /**********************************/ 932 /* print file name to depend file */ 933 /**********************************/ 934 if (pOptions->fObjRule && !fHeader) 935 { 936 if (pOptions->fNoObjectPath) 937 fprintf(phDep, "%s.%s:", fileNameNoExt(pszFilename, szBuffer), pOptions->pszRsrcExt); 938 else 939 fprintf(phDep, "%s%s.res:", 940 (*pOptions->pszObjectDir != '\0') ? 941 pOptions->pszObjectDir : filePathSlash(pszFilename, szBuffer), 942 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 943 pOptions->pszRsrcExt); 944 945 if (pOptions->fSrcWhenObj) 946 fprintf(phDep, " \\\n%4s %s", "", pszFilename); 947 } 948 else 949 fprintf(phDep, "%s:", pszFilename); 950 951 952 /*******************/ 953 /* find dependants */ 954 /*******************/ 521 955 iLine = 0; 522 956 while (!feof(phFile)) /* line loop */ … … 535 969 536 970 /* is this an include? */ 537 if (szBuffer[i] == '#' && strncmp(&szBuffer[i], "#include", 8) == 0) 971 if ( strncmp(&szBuffer[i], "#include", 8) == 0 972 || strncmp(&szBuffer[i], "RCINCLUDE", 9) == 0 973 || strncmp(&szBuffer[i], "DLGINCLUDE", 10) == 0 974 ) 538 975 { 539 976 char szFullname[CCHMAXPATH]; … … 593 1030 594 1031 /** 595 * Generates depend info on this file, and fwrites it to phDep.1032 * Generates depend info on this COBOL file, and writes it to phDep. 596 1033 * @returns 0 on success. 597 1034 * !0 on error. … … 603 1040 * @author knut st. osmundsen 604 1041 */ 605 int lang Asm(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions)1042 int langCOBOL(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 606 1043 { 607 1044 char szBuffer[4096]; /* max line length */ 608 1045 int iLine; 609 610 1046 611 1047 /**********************************/ … … 638 1074 if (fgets(szBuffer, sizeof(szBuffer), phFile) != NULL) 639 1075 { 640 /* search for include */1076 /* search for #include */ 641 1077 int cbLen; 642 1078 int i = 0; 1079 int i1, i2; 643 1080 iLine++; 1081 1082 /* check for comment mark (column 7) */ 1083 if (szBuffer[6] == '*') 1084 continue; 644 1085 645 1086 /* skip blank chars */ … … 649 1090 650 1091 /* is this an include? */ 651 if ( strnicmp(&szBuffer[i], "include", 7) == 0652 && (szBuffer[i + 7] == '\t' || szBuffer[i + 7] == ' ')1092 if ( (i1 = strnicmp(&szBuffer[i], "COPY", 4)) == 0 1093 || (i2 = strnicmpwords(&szBuffer[i], "EXEC SQL INCLUDE", 16)) == 0 653 1094 ) 654 1095 { … … 657 1098 int j; 658 1099 659 /* skip to first no blank char */ 660 i += 7; 661 while (i < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t')) 1100 /* skip statement */ 1101 i += 4; 1102 if (i1 != 0) 1103 { 1104 int y = 2; /* skip two words */ 1105 do 1106 { 1107 /* skip blanks */ 1108 while (szBuffer[i] == ' ' || szBuffer[i] == '\t') 1109 i++; 1110 /* skip word */ 1111 while (szBuffer[i] != ' ' && szBuffer[i] != '\t' 1112 && szBuffer[i] != '\0' && szBuffer[i] != '\n') 1113 i++; 1114 y--; 1115 } while (y > 0); 1116 } 1117 1118 /* check for blank */ 1119 if (szBuffer[i] != ' ' && szBuffer[i] != '\t') /* no copybook specified... */ 1120 continue; 1121 1122 /* skip blanks */ 1123 while (szBuffer[i] == ' ' || szBuffer[i] == '\t') 662 1124 i++; 663 1125 664 /* comment check - if comment found, no filename was given. continue. */ 665 if (szBuffer[i] == ';') continue; 1126 /* if invalid statement then continue with the next line! */ 1127 if (szBuffer[i] == '\0' || szBuffer[i] == '\n') 1128 continue; 666 1129 667 1130 /* find end */ 668 1131 j = 0; 669 while (i + j < cbLen 670 && j < CCHMAXPATH671 && szBuffer[i+j] != ' ' && szBuffer[i+j] != '\t' && szBuffer[i+j] != '\n'672 && szBuffer[i+j] != '\0' && szBuffer[i+j] != ' ;' && szBuffer[i+j] != '\r'1132 while (i + j < cbLen && j < CCHMAXPATH 1133 && szBuffer[i+j] != '.' 1134 && szBuffer[i+j] != ' ' && szBuffer[i+j] != '\t' 1135 && szBuffer[i+j] != '\0' && szBuffer[i+j] != '\n' 673 1136 ) 674 1137 j++; 1138 1139 /* if invalid statement then continue with the next line! */ 1140 if (szBuffer[i+j] != '.' && szBuffer[i+j] != ' ' && szBuffer[i] != '\t') 1141 continue; 675 1142 676 1143 /* copy filename */ … … 678 1145 szFullname[j] = '\0'; /* ensure terminatition. */ 679 1146 1147 /* add extention .cpy - hardcoded for the moment. */ 1148 strcat(szFullname, ".cpy"); 1149 680 1150 /* find include file! */ 681 1151 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) != NULL691 )692 strcpy(szBuffer, szFullname);693 fprintf(phDep, " \\\n%4.s %s", "", szBuffer);694 }695 else696 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",697 pszFilename, iLine, szFullname);698 }699 }700 else701 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. osmundsen719 */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 else733 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 else743 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) == 0766 || strncmp(&szBuffer[i], "RCINCLUDE", 9) == 0767 || strncmp(&szBuffer[i], "DLGINCLUDE", 10) == 0768 )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 1152 801 1153 /* did we find the include? */ … … 822 1174 } 823 1175 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. osmundsen835 */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 else849 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 else859 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)) == 0887 || (i2 = strnicmpwords(&szBuffer[i], "EXEC SQL INCLUDE", 16)) == 0888 )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 do900 {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 < CCHMAXPATH927 && 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) != NULL953 )954 strcpy(szBuffer, szFullname);955 fprintf(phDep, " \\\n%4.s %s", "", szBuffer);956 }957 else958 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n",959 pszFilename, iLine, szFullname);960 }961 }962 else963 break;964 } /*while*/965 fputs("\n", phDep);966 967 return 0;968 }969 970 1176 #define upcase(ch) \ 971 1177 (ch >= 'a' && ch <= 'z' ? ch - ('a' - 'A') : ch) … … 1203 1409 } 1204 1410 1411 1412 /** 1413 * Finds the first char after word. 1414 * @returns Pointer to the first char after word. 1415 * @param psz Where to start. 1416 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 1417 */ 1418 static char *findEndOfWord(char *psz) 1419 { 1420 1421 while (*psz != '\0' && 1422 ( 1423 (*psz >= 'A' && *psz <= 'Z') || (*psz >= 'a' && *psz <= 'z') 1424 || 1425 (*psz >= '0' && *psz <= '9') 1426 || 1427 *psz == '_' 1428 ) 1429 ) 1430 ++psz; 1431 return (char *)psz; 1432 } 1433 1434 #if 0 /* not used */ 1435 /** 1436 * Find the starting char of a word 1437 * @returns Pointer to first char in word. 1438 * @param psz Where to start. 1439 * @param pszStart Where to stop. 1440 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 1441 */ 1442 static char *findStartOfWord(const char *psz, const char *pszStart) 1443 { 1444 const char *pszR = psz; 1445 while (psz >= pszStart && 1446 ( 1447 (*psz >= 'A' && *psz <= 'Z') 1448 || (*psz >= 'a' && *psz <= 'z') 1449 || (*psz >= '0' && *psz <= '9') 1450 || *psz == '_' 1451 ) 1452 ) 1453 pszR = psz--; 1454 return (char*)pszR; 1455 } 1456 #endif 1457 1458 /* 1459 * Testin purpose. 1460 */ 1461 #include <os2.h> 1462
Note:
See TracChangeset
for help on using the changeset viewer.