Changeset 5921 for trunk/tools
- Timestamp:
- Jun 7, 2001, 2:35:42 AM (24 years ago)
- Location:
- trunk/tools/fastdep
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/fastdep/avl.c
r4653 r5921 1 /* $Id: avl.c,v 1. 3 2000-11-21 04:35:36bird Exp $1 /* $Id: avl.c,v 1.4 2001-06-07 00:35:41 bird Exp $ 2 2 * 3 3 * AVL-Tree (lookalike) implementation. … … 186 186 assert(AVLStack.cEntries < AVL_MAX_HEIGHT); 187 187 AVLStack.aEntries[AVLStack.cEntries++] = ppDeleteNode; 188 #ifndef AVL_CMP 188 189 if (AVL_E(pDeleteNode->Key, Key)) 189 190 break; … … 193 194 else 194 195 ppDeleteNode = &pDeleteNode->pRight; 196 #else 197 { 198 int register iDiff; 199 if ((iDiff = AVL_CMP(pDeleteNode->Key, Key)) == 0) 200 break; 201 202 if (iDiff > 0) 203 ppDeleteNode = &pDeleteNode->pLeft; 204 else 205 ppDeleteNode = &pDeleteNode->pRight; 206 } 207 #endif 195 208 } 196 209 … … 245 258 PAVLNODECORE AVLGet(PPAVLNODECORE ppTree, AVLKEY Key) 246 259 { 247 register PAVLNODECORE pNode = *ppTree; 260 #ifndef AVL_CMP 261 register PAVLNODECORE pNode = *ppTree; 248 262 249 263 while (pNode != NULL && AVL_NE(pNode->Key, Key)) … … 255 269 } 256 270 271 #else 272 273 register int iDiff; 274 register PAVLNODECORE pNode = *ppTree; 275 276 while (pNode != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0) 277 { 278 if (iDiff > 0) 279 pNode = pNode->pLeft; 280 else 281 pNode = pNode->pRight; 282 } 283 284 #endif 285 257 286 return pNode; 258 287 } 259 260 288 261 289 … … 273 301 PAVLNODECORE AVLGetWithParent(PPAVLNODECORE ppTree, PPAVLNODECORE ppParent, AVLKEY Key) 274 302 { 275 register PAVLNODECORE pNode = *ppTree; 276 register PAVLNODECORE pParent = NULL; 303 #ifndef AVL_CMP 304 305 register PAVLNODECORE pNode = *ppTree; 306 register PAVLNODECORE pParent = NULL; 277 307 278 308 while (pNode != NULL && AVL_NE(pNode->Key, Key)) … … 284 314 pNode = pNode->pRight; 285 315 } 316 317 #else 318 319 register PAVLNODECORE pNode = *ppTree; 320 register PAVLNODECORE pParent = NULL; 321 register int iDiff; 322 323 while (pNode != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0) 324 { 325 pParent = pNode; 326 if (iDiff > 0) 327 pNode = pNode->pLeft; 328 else 329 pNode = pNode->pRight; 330 } 331 332 #endif 286 333 287 334 *ppParent = pParent; … … 314 361 PPAVLNODECORE ppNode = ppTree; 315 362 PAVLNODECORE pNode; 363 #ifdef AVL_CMP 364 int iDiff; 365 #endif 316 366 317 367 AVLStack.cEntries = 0; 318 368 369 #ifndef AVL_CMP 319 370 while ((pNode = *ppNode) != NULL && AVL_NE(pNode->Key, Key)) 371 #else 372 while ((pNode = *ppNode) != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0) 373 #endif 320 374 { 321 375 assert(AVLStack.cEntries < AVL_MAX_HEIGHT); 322 376 AVLStack.aEntries[AVLStack.cEntries++] = ppNode; 377 #ifndef AVL_CMP 323 378 if (AVL_G(pNode->Key, Key)) 379 #else 380 if (iDiff > 0) 381 #endif 324 382 ppNode = &pNode->pLeft; 325 383 else … … 349 407 { 350 408 pCurNode = *AVLStack.aEntries[AVLStack.cEntries]; 409 #ifndef AVL_CMP 351 410 if (AVL_L(pCurNode->Key, Key) && (*ppLeft == NULL || AVL_G(pCurNode->Key, (*ppLeft)->Key))) 352 411 *ppLeft = pCurNode; 353 412 else if (AVL_G(pCurNode->Key, Key) && (*ppRight == NULL || AVL_L(pCurNode->Key, (*ppRight)->Key))) 354 413 *ppRight = pCurNode; 414 #else 415 if ((iDiff = AVL_CMP(pCurNode->Key, Key)) < 0 && (*ppLeft == NULL || AVL_G(pCurNode->Key, (*ppLeft)->Key))) 416 *ppLeft = pCurNode; 417 else if (iDiff > 0 && (*ppRight == NULL || AVL_L(pCurNode->Key, (*ppRight)->Key))) 418 *ppRight = pCurNode; 419 #endif 355 420 } 356 421 } … … 583 648 PAVLNODECORE AVLGetBestFit(PPAVLNODECORE ppTree, AVLKEY Key, int fAbove) 584 649 { 650 #ifdef AVL_CMP 651 register int iDiff; 652 #endif 585 653 register PAVLNODECORE pNode = *ppTree; 586 654 PAVLNODECORE pNodeLast = NULL; … … 588 656 if (fAbove) 589 657 { /* pNode->Key >= Key */ 658 #ifndef AVL_CMP 590 659 while (pNode != NULL && AVL_NE(pNode->Key, Key)) 591 { 660 #else 661 while (pNode != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0) 662 #endif 663 { 664 #ifndef AVL_CMP 592 665 if (AVL_G(pNode->Key, Key)) 666 #else 667 if (iDiff > 0) 668 #endif 593 669 { 594 670 pNodeLast = pNode; … … 601 677 else 602 678 { /* pNode->Key <= Key */ 679 #ifndef AVL_CMP 603 680 while (pNode != NULL && AVL_NE(pNode->Key, Key)) 604 { 681 #else 682 while (pNode != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0) 683 #endif 684 { 685 #ifndef AVL_CMP 605 686 if (AVL_L(pNode->Key, Key)) 687 #else 688 if (iDiff < 0) 689 #endif 606 690 { 607 691 pNodeLast = pNode; -
trunk/tools/fastdep/avl.h
r3132 r5921 1 /* $Id: avl.h,v 1. 2 2000-03-16 23:51:25bird Exp $1 /* $Id: avl.h,v 1.3 2001-06-07 00:35:42 bird Exp $ 2 2 * 3 3 * AVL-Tree (lookalike) declaration. … … 38 38 #define AVL_E(key1, key2) (strcmp(key1, key2) == 0) 39 39 #define AVL_NE(key1, key2) (strcmp(key1, key2) != 0) 40 40 #define AVL_CMP(key1, key2) strcmp(key1, key2) 41 41 42 42 /** -
trunk/tools/fastdep/fastdep.c
r5317 r5921 1 /* $Id: fastdep.c,v 1.2 6 2001-03-14 20:17:52 bird Exp $1 /* $Id: fastdep.c,v 1.27 2001-06-07 00:35:42 bird Exp $ 2 2 * 3 3 * Fast dependents. (Fast = Quick and Dirty!) … … 21 21 * If you're compiling this under a UNICODE system this may perhaps change, 22 22 * but I doubd that fastdep will work at all under a UNICODE system. ;-) 23 */ 23 */ 24 24 #if defined(UNICODE) && !defined(__WIN32OS2__) 25 25 #define CBNEWLINE (2) … … 43 43 #include <stdlib.h> 44 44 #include <direct.h> 45 #include <assert.h> 45 46 46 47 #include "avl.h" … … 119 120 BOOL fCacheSearchDirs; /* cache entire search dirs. */ 120 121 const char * pszExcludeFiles; /* List of excluded files. */ 121 const char * pszSuperDependency; /* name for super dependency */ 122 const char * pszSuperDependency; /* Name for super dependency rule. */ 123 BOOL fForceScan; /* Force scan of all files. */ 124 FDATE fDepDate; /* The date which files are to be search from. */ 122 125 } OPTIONS, *POPTIONS; 123 126 … … 127 130 */ 128 131 typedef int ( _FNLANG) (const char *pszFilename, const char *pszNormFilename, 129 void *pvFile, BOOL fHeader, POPTIONS pOptions);132 FDATE FileDate, BOOL fHeader); 130 133 typedef _FNLANG *PFNLANG; 131 134 … … 150 153 typedef struct _DepRule 151 154 { 152 AVLNODECORE avlCore; 153 char * pszRule; /* Pointer to rule name */ 154 int cDeps; /* Entries in the dependant array. */ 155 char ** papszDep; /* Pointer to an array of pointers to dependants. */ 155 AVLNODECORE avlCore; 156 char * pszRule; /* Pointer to rule name */ 157 int cDeps; /* Entries in the dependant array. */ 158 char ** papszDep; /* Pointer to an array of pointers to dependants. */ 159 BOOL fUpdated; /* If we have updated this entry during current run. */ 156 160 } DEPRULE, *PDEPRULE; 157 161 … … 168 172 *******************************************************************************/ 169 173 static void syntax(void); 170 static int makeDependent(const char *pszFilename, POPTIONS pOptions);171 172 int langC_CPP(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);173 int langAsm(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);174 int langRC(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);175 int langCOBOL(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions);174 static int makeDependent(const char *pszFilename, FDATE FileDate); 175 176 static int langC_CPP(const char *pszFilename, const char *pszNormFilename, FDATE FileDate, BOOL fHeader); 177 static int langAsm( const char *pszFilename, const char *pszNormFilename, FDATE FileDate, BOOL fHeader); 178 static int langRC( const char *pszFilename, const char *pszNormFilename, FDATE FileDate, BOOL fHeader); 179 static int langCOBOL(const char *pszFilename, const char *pszNormFilename, FDATE FileDate, BOOL fHeader); 176 180 177 181 … … 196 200 197 201 /* pathlist operations */ 198 static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer , POPTIONS pOptions);199 static BOOL pathlistFindFile2(const char *pszPathList, const char *pszFilename , POPTIONS pOptions);202 static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer); 203 static BOOL pathlistFindFile2(const char *pszPathList, const char *pszFilename); 200 204 201 205 /* word operations */ … … 212 216 INLINE char *trimR(char *psz); 213 217 218 /* preprocessors */ 219 static char *PreProcessLine(char *pszOut, const char *pszIn); 220 214 221 /* textbuffer */ 215 222 static void *textbufferCreate(const char *pszFilename); … … 219 226 220 227 /* depend workers */ 221 static BOOL depReadFile(const char *pszFilename , POPTIONS pOptions);222 static BOOL depWriteFile(const char *pszFilename , POPTIONS pOptions);228 static BOOL depReadFile(const char *pszFilename); 229 static BOOL depWriteFile(const char *pszFilename); 223 230 static void depRemoveAll(void); 224 static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt );231 static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, FDATE FileDate); 225 232 static BOOL depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic); 226 #if 0 /* not used */227 static BOOL depCleanFile(const char *pszFilename);228 #endif229 233 static BOOL depCheckCyclic(PDEPRULE pdepRule, const char *pszDep); 230 234 … … 303 307 } 304 308 }; 309 310 311 static char szObjectDir[CCHMAXPATH]; 312 static char szObjectExt[64] = "obj"; 313 static char szRsrcExt[64] = "res"; 314 static char szInclude[32768] = ";"; 315 static char szExclude[32768] = ";"; 316 static char szExcludeFiles[65536] = ""; 317 318 OPTIONS options = 319 { 320 szInclude, /* pszInclude */ 321 szExclude, /* pszExclude */ 322 FALSE, /* fExcludeAll */ 323 szObjectExt, /* pszObjectExt */ 324 szObjectDir, /* pszObjectDir */ 325 FALSE, /* fObjectDir */ 326 szRsrcExt, /* pszRsrcExt */ 327 TRUE, /* fObjRule */ 328 FALSE, /* fNoObjectPath */ 329 TRUE, /* fSrcWhenObj */ 330 FALSE, /* fAppend */ 331 TRUE, /* fCheckCyclic */ 332 TRUE, /* fCacheSearchDirs */ 333 szExcludeFiles, /* pszExcludeFiles */ 334 NULL, /* pszSuperDependency */ 335 FALSE, /* fForceScan */ 336 {1,1,1} /* fDepDate */ 337 }; 338 305 339 306 340 … … 329 363 const char *pszDepFile = pszDefaultDepFile; 330 364 char achBuffer[4096]; 331 332 static char szObjectDir[CCHMAXPATH];333 static char szObjectExt[64] = "obj";334 static char szRsrcExt[64] = "res";335 static char szInclude[32768] = ";";336 static char szExclude[32768] = ";";337 static char szExcludeFiles[65536] = "";338 339 OPTIONS options =340 {341 szInclude, /* pszInclude */342 szExclude, /* pszExclude */343 FALSE, /* fExcludeAll */344 szObjectExt, /* pszObjectExt */345 szObjectDir, /* pszObjectDir */346 FALSE, /* fObjectDir */347 szRsrcExt, /* pszRsrcExt */348 TRUE, /* fObjRule */349 FALSE, /* fNoObjectPath */350 TRUE, /* fSrcWhenObj */351 FALSE, /* fAppend */352 TRUE, /* fCheckCyclic */353 TRUE, /* fCacheSearchDirs */354 szExcludeFiles, /* pszExcludeFiles */355 NULL /* pszSuperDependency */356 };357 365 358 366 szObjectDir[0] = '\0'; … … 438 446 if (pdepTree != NULL && pszOld != pszDepFile) 439 447 { 440 if (!depWriteFile(pszOld , &options))448 if (!depWriteFile(pszOld)) 441 449 fprintf(stderr, "error: failed to write (flush) dependencies.\n"); 442 450 depRemoveAll(); … … 501 509 break; 502 510 511 case 'f': 512 case 'F': /* force scan of all files. */ 513 options.fForceScan = argv[argi][2] != '-'; 514 break; 515 503 516 case 'I': /* optional include path. This has precedence over the INCLUDE environment variable. */ 504 517 case 'i': … … 745 758 746 759 /* 747 * If append option is specified we'll have to read the existing dep file 748 * before starting adding new dependencies. 760 * If append option is or if the forcescan option isn't is 761 * we'll have to read the existing dep file before starting 762 * adding new dependencies. 749 763 */ 750 if (pdepTree == NULL && options.fAppend)751 depReadFile(pszDepFile , &options);764 if (pdepTree == NULL && (options.fAppend || !options.fForceScan)) 765 depReadFile(pszDepFile); 752 766 753 767 /* … … 802 816 * Analyse the file. 803 817 */ 804 rc -= makeDependent(&szSource[0], &options);818 rc -= makeDependent(&szSource[0], pfindbuf3->fdateLastWrite); 805 819 } 806 820 … … 817 831 818 832 /* Write the depend file! */ 819 if (!depWriteFile(pszDepFile , &options))833 if (!depWriteFile(pszDepFile)) 820 834 fprintf(stderr, "error: failed to write dependencies file!\n"); 821 835 #if 0 … … 832 846 * @author knut st. osmundsen 833 847 */ 834 staticvoid syntax(void)848 void syntax(void) 835 849 { 836 850 printf( 837 "FastDep v0. 32\n"851 "FastDep v0.40\n" 838 852 "Dependency scanner. Creates a makefile readable depend file.\n" 839 853 " - was quick and dirty, now it's just quick -\n" 840 854 "\n" 841 "Syntax: FastDep [-a<[+]|->] [-ca] [-cy<[+]|->] [-d <outputfn>]\n" 842 " [-e <excludepath>] [-eall<[+]|->] [-i <include>] [-n<[+]|->]\n" 843 " [-o <objdir>] [-obr<[+]|->] [-x <f1[;f2]>] [-r <rsrcext>]\n" 844 " <files> [more options [more files [...]]]\n" 855 "Syntax: FastDep [options] <files> [more options [more files [...]]]\n" 845 856 " or\n" 846 857 " FastDep [options] @<parameterfile>\n" 847 858 "\n" 848 " -a<[+]|-> Append to the output file. Default: Overwrite.\n" 859 "Options:\n" 860 " -a<[+]|-> Append to the output file. Default: Overwrite.\n" 849 861 " -ca Force search directory caching.\n" 850 862 " Default: cache if more that 25 files are to be searched.\n" 851 863 " (more than 25 in the first file expression.)\n" 852 " -cy<[+]|-> Check for cylic dependencies. Default: -cy-\n"853 " -d <outputfn> Output filename. Default: %s\n"864 " -cy<[+]|-> Check for cylic dependencies. Default: -cy-\n" 865 " -d <outputfn> Output filename. Default: %s\n" 854 866 " -e excludepath Exclude paths. If a filename is found in any\n" 855 867 " of these paths only the filename is used, not\n" … … 860 872 " was found in.\n" 861 873 " Default: eall-\n" 874 " -f<[+]|-> Force scanning of all files. If disabled we'll only scan\n" 875 " files which are younger or up to one month older than the\n" 876 " dependancy file (if it exists). Default: disabled\n" 862 877 " -i <include> Additional include paths. INCLUDE is searched after this.\n" 863 878 " -n<[+]|-> No path for object files in the rules.\n" … … 867 882 " -obr<[+]|-> -obr+: Object rule.\n" 868 883 " -obr-: No object rule, rule for source filename is generated.\n" 869 " -obj[ ]<objext> Object extention. Default: obj\n"884 " -obj[ ]<objext> Object extention. Default: obj\n" 870 885 " -s[ ][name] Insert super-dependency on top of tree.\n" 871 886 " If not specified name defaults to 'alltargets'.\n" 872 887 " Default: disabled\n" 873 " -r[ ]<rsrcext> Resource binary extention. Default: res\n"888 " -r[ ]<rsrcext> Resource binary extention. Default: res\n" 874 889 " -x[ ]<f1[;f2]> Files to exclude. Only exact filenames.\n" 875 890 " <files> Files to scan. Wildchars are allowed.\n" … … 886 901 * and written to file later. 887 902 * @returns 888 * @param pszFilenamePointer to source filename. Correct case is assumed!889 * @param pOptions Pointer to options struct.890 * @status 891 * @author 892 */ 893 static int makeDependent(const char *pszFilename, POPTIONS pOptions)903 * @param pszFilename Pointer to source filename. Correct case is assumed! 904 * @param FileDate File date. 905 * @status completely implemented. 906 * @author knut st. osmundsen 907 */ 908 int makeDependent(const char *pszFilename, FDATE FileDate) 894 909 { 895 910 int rc = -1; 896 void * pvFile; 897 898 pvFile = textbufferCreate(pszFilename); 899 if (pvFile != NULL) 900 { 901 char szExt[CCHMAXPATH]; 902 PCONFIGENTRY pCfg = &aConfig[0]; 903 BOOL fHeader; 904 905 /* 906 * Find which filetype this is... 907 */ 908 fileExt(pszFilename, szExt); 909 while (pCfg->papszExts != NULL) 911 912 char szExt[CCHMAXPATH]; 913 PCONFIGENTRY pCfg = &aConfig[0]; 914 BOOL fHeader; 915 916 /* 917 * Find which filetype this is... 918 */ 919 fileExt(pszFilename, szExt); 920 while (pCfg->papszExts != NULL) 921 { 922 const char **ppsz = pCfg->papszExts; 923 while (*ppsz != NULL && stricmp(*ppsz, szExt) != 0) 924 ppsz++; 925 if (*ppsz != NULL) 910 926 { 911 const char **ppsz = pCfg->papszExts; 912 while (*ppsz != NULL && stricmp(*ppsz, szExt) != 0) 913 ppsz++; 914 if (*ppsz != NULL) 915 { 916 fHeader = &pCfg->papszExts[pCfg->iFirstHdr] <= ppsz; 917 break; 918 } 919 pCfg++; 927 fHeader = &pCfg->papszExts[pCfg->iFirstHdr] <= ppsz; 928 break; 920 929 } 921 922 /* Found? */ 923 if (pCfg->papszExts != NULL) 924 { 925 char szNormFile[CCHMAXPATH]; 926 fileNormalize2(pszFilename, szNormFile); 927 rc = (*pCfg->pfn)(pszFilename, &szNormFile[0], pvFile, fHeader, pOptions); 928 } 929 else 930 { 931 if (*fileName(pszFilename, szExt) != '.') /* these are 'hidden' files, like .cvsignore, let's ignore them. */ 932 fprintf(stderr, "warning: '%s' has an unknown file type.\n", pszFilename); 933 rc = 0; 934 } 935 936 textbufferDestroy(pvFile); 930 pCfg++; 931 } 932 933 /* Found? */ 934 if (pCfg->papszExts != NULL) 935 { 936 char szNormFile[CCHMAXPATH]; 937 fileNormalize2(pszFilename, szNormFile); 938 rc = (*pCfg->pfn)(pszFilename, &szNormFile[0], FileDate, fHeader); 937 939 } 938 940 else 939 fprintf(stderr, "failed to open '%s'\n", pszFilename); 941 { 942 if (*fileName(pszFilename, szExt) != '.') /* these are 'hidden' files, like .cvsignore, let's ignore them. */ 943 fprintf(stderr, "warning: '%s' has an unknown file type.\n", pszFilename); 944 rc = 0; 945 } 946 940 947 941 948 return rc; … … 946 953 * Generates depend info on this C or C++ file, these are stored internally 947 954 * and written to file later. 948 * @returns 0 on success. 949 * !0 on error. 950 * @param pszFilename Pointer to source filename. Correct case is assumed! 951 * @param pszNormFilename Pointer to normalized source filename. 952 * @param pvFile Pointer to file textbuffer. 953 * @param pOptions Pointer to options struct. 954 * @status completely implemented. 955 * @author knut st. osmundsen 956 */ 957 int langC_CPP(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions) 958 { 955 * @returns 0 on success. 956 * !0 on error. 957 * @param pszFilename Pointer to source filename. Correct case is assumed! 958 * @param pszNormFilename Pointer to normalized source filename. 959 * @parma FileDate Date of the source file. 960 * @parma fHeader True if header file is being scanned. 961 * @status completely implemented. 962 * @author knut st. osmundsen 963 */ 964 int langC_CPP(const char *pszFilename, const char *pszNormFilename, 965 FDATE FileDate, BOOL fHeader) 966 { 967 void * pvFile; /* Text buffer pointer. */ 959 968 void * pvRule; /* Handle to the current rule. */ 960 969 char szBuffer[4096]; /* Max line length is 4096... should not be a problem. */ … … 980 989 /* Add the depend rule */ 981 990 /**********************************/ 982 if ( pOptions->fObjRule && !fHeader)983 { 984 if ( pOptions->fNoObjectPath)985 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszObjectExt);991 if (options.fObjRule && !fHeader) 992 { 993 if (options.fNoObjectPath) 994 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, FileDate); 986 995 else 987 pvRule = depAddRule( pOptions->fObjectDir ?988 pOptions->pszObjectDir :996 pvRule = depAddRule(options.fObjectDir ? 997 options.pszObjectDir : 989 998 filePathSlash(pszFilename, szBuffer), 990 999 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 991 pOptions->pszObjectExt); 992 993 if (pOptions->fSrcWhenObj && pvRule) 1000 options.pszObjectExt, 1001 FileDate); 1002 1003 if (options.fSrcWhenObj && pvRule) 994 1004 depAddDepend(pvRule, 995 pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?1005 options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 996 1006 fileName(pszFilename, szBuffer) : pszNormFilename, 997 pOptions->fCheckCyclic);1007 options.fCheckCyclic); 998 1008 } 999 1009 else 1000 pvRule = depAddRule( pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?1001 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL );1010 pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1011 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, FileDate); 1002 1012 1003 1013 /* duplicate rule? */ 1004 1014 if (pvRule == NULL) 1005 1015 return 0; 1016 1017 1018 /********************/ 1019 /* Make file buffer */ 1020 /********************/ 1021 pvFile = textbufferCreate(pszFilename); 1022 if (!pvFile) 1023 { 1024 fprintf(stderr, "failed to open '%s'\n", pszFilename); 1025 return -1; 1026 } 1006 1027 1007 1028 … … 1094 1115 1095 1116 /* find include file! */ 1096 psz = pathlistFindFile( pOptions->pszInclude, szFullname, szBuffer, pOptions);1117 psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer); 1097 1118 if (psz == NULL) 1098 psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer , pOptions);1119 psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer); 1099 1120 1100 1121 /* did we find the include? */ 1101 1122 if (psz != NULL) 1102 1123 { 1103 if ( pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))1104 depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);1124 if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer)) 1125 depAddDepend(pvRule, szFullname, options.fCheckCyclic); 1105 1126 else 1106 depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic);1127 depAddDepend(pvRule, szBuffer, options.fCheckCyclic); 1107 1128 } 1108 1129 else … … 1219 1240 } /*while*/ 1220 1241 1242 textbufferDestroy(pvFile); 1243 1221 1244 return 0; 1222 1245 } … … 1226 1249 * Generates depend info on this file, these are stored internally 1227 1250 * and written to file later. 1228 * @returns 0 on success. 1229 * !0 on error. 1230 * @param pszFilename Pointer to source filename. Correct case is assumed! 1231 * @param pszNormFilename Pointer to normalized source filename. 1232 * @param pvFile Pointer to file textbuffer. 1233 * @param pOptions Pointer to options struct. 1234 * @status completely implemented. 1235 * @author knut st. osmundsen 1236 */ 1237 int langAsm(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions) 1238 { 1251 * @returns 0 on success. 1252 * !0 on error. 1253 * @param pszFilename Pointer to source filename. Correct case is assumed! 1254 * @param pszNormFilename Pointer to normalized source filename. 1255 * @parma FileDate Date of the source file. 1256 * @parma fHeader True if header file is being scanned. 1257 * @status completely implemented. 1258 * @author knut st. osmundsen 1259 */ 1260 int langAsm(const char *pszFilename, const char *pszNormFilename, 1261 FDATE FileDate, BOOL fHeader) 1262 { 1263 void * pvFile; /* Text buffer pointer. */ 1239 1264 void * pvRule; /* Handle to the current rule. */ 1240 1265 char szBuffer[4096]; /* Temporary buffer (max line lenght size...) */ … … 1246 1271 /* Add the depend rule */ 1247 1272 /**********************************/ 1248 if ( pOptions->fObjRule && !fHeader)1249 { 1250 if ( pOptions->fNoObjectPath)1251 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszObjectExt);1273 if (options.fObjRule && !fHeader) 1274 { 1275 if (options.fNoObjectPath) 1276 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, FileDate); 1252 1277 else 1253 pvRule = depAddRule( pOptions->fObjectDir ?1254 pOptions->pszObjectDir :1278 pvRule = depAddRule(options.fObjectDir ? 1279 options.pszObjectDir : 1255 1280 filePathSlash(pszFilename, szBuffer), 1256 1281 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 1257 pOptions->pszObjectExt); 1258 1259 if (pOptions->fSrcWhenObj && pvRule) 1282 options.pszObjectExt, 1283 FileDate); 1284 1285 if (options.fSrcWhenObj && pvRule) 1260 1286 depAddDepend(pvRule, 1261 pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?1287 options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1262 1288 fileName(pszFilename, szBuffer) : pszNormFilename, 1263 pOptions->fCheckCyclic);1289 options.fCheckCyclic); 1264 1290 } 1265 1291 else 1266 pvRule = depAddRule( pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?1267 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL );1292 pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1293 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, FileDate); 1268 1294 1269 1295 /* duplicate rule? */ 1270 1296 if (pvRule == NULL) 1271 1297 return 0; 1298 1299 1300 /********************/ 1301 /* Make file buffer */ 1302 /********************/ 1303 pvFile = textbufferCreate(pszFilename); 1304 if (!pvFile) 1305 { 1306 fprintf(stderr, "failed to open '%s'\n", pszFilename); 1307 return -1; 1308 } 1272 1309 1273 1310 … … 1320 1357 1321 1358 /* find include file! */ 1322 psz = pathlistFindFile( pOptions->pszInclude, szFullname, szBuffer, pOptions);1359 psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer); 1323 1360 if (psz == NULL) 1324 psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer , pOptions);1361 psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer); 1325 1362 1326 1363 /* Did we find the include? */ 1327 1364 if (psz != NULL) 1328 1365 { 1329 if ( pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))1330 depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);1366 if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer)) 1367 depAddDepend(pvRule, szFullname, options.fCheckCyclic); 1331 1368 else 1332 depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic);1369 depAddDepend(pvRule, szBuffer, options.fCheckCyclic); 1333 1370 } 1334 1371 else … … 1337 1374 } 1338 1375 } /*while*/ 1376 1377 textbufferDestroy(pvFile); 1339 1378 1340 1379 return 0; … … 1349 1388 * @param pszFilename Pointer to source filename. Correct case is assumed! 1350 1389 * @param pszNormFilename Pointer to normalized source filename. 1351 * @par am pvFile Pointer to file textbuffer.1352 * @par am pOptions Pointer to options struct.1390 * @parma FileDate Date of the source file. 1391 * @parma fHeader True if header file is being scanned. 1353 1392 * @status completely implemented. 1354 1393 * @author knut st. osmundsen 1355 1394 */ 1356 int langRC(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions) 1357 { 1395 #if 0 1396 int langRC(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader) 1397 { 1398 void * pvFile; /* Text buffer pointer. */ 1358 1399 void * pvRule; /* Handle to the current rule. */ 1359 1400 char szBuffer[4096]; /* Temporary buffer (max line lenght size...) */ … … 1365 1406 /* Add the depend rule */ 1366 1407 /**********************************/ 1367 if ( pOptions->fObjRule && !fHeader)1368 { 1369 if ( pOptions->fNoObjectPath)1370 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszRsrcExt);1408 if (options.fObjRule && !fHeader) 1409 { 1410 if (options.fNoObjectPath) 1411 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, FileDate); 1371 1412 else 1372 pvRule = depAddRule( pOptions->fObjectDir ?1373 pOptions->pszObjectDir :1413 pvRule = depAddRule(options.fObjectDir ? 1414 options.pszObjectDir : 1374 1415 filePathSlash(pszFilename, szBuffer), 1375 1416 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 1376 pOptions->pszRsrcExt); 1377 1378 if (pOptions->fSrcWhenObj && pvRule) 1417 options.pszRsrcExt, 1418 FileDate); 1419 1420 if (options.fSrcWhenObj && pvRule) 1379 1421 depAddDepend(pvRule, 1380 pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?1422 options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1381 1423 fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), 1382 pOptions->fCheckCyclic);1424 options.fCheckCyclic); 1383 1425 } 1384 1426 else 1385 pvRule = depAddRule(pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ? 1386 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL); 1427 pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1428 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, 1429 FileDate); 1387 1430 1388 1431 /* duplicate rule? */ 1389 1432 if (pvRule == NULL) 1390 1433 return 0; 1434 1435 1436 /********************/ 1437 /* Make file buffer */ 1438 /********************/ 1439 pvFile = textbufferCreate(pszFilename); 1440 if (!pvFile) 1441 { 1442 fprintf(stderr, "failed to open '%s'\n", pszFilename); 1443 return -1; 1444 } 1391 1445 1392 1446 … … 1411 1465 i1 = 1; 1412 1466 if ( strncmp(&szBuffer[i], "#include", 8) == 0 1413 || (i1 = strn cmp(&szBuffer[i], "RCINCLUDE", 9)) == 01414 || strn cmp(&szBuffer[i], "DLGINCLUDE", 10) == 01467 || (i1 = strnicmp(&szBuffer[i], "RCINCLUDE", 9)) == 0 1468 || strnicmp(&szBuffer[i], "DLGINCLUDE", 10) == 0 1415 1469 ) 1416 1470 { … … 1468 1522 1469 1523 /* find include file! */ 1470 psz = pathlistFindFile( pOptions->pszInclude, szFullname, szBuffer, pOptions);1524 psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer); 1471 1525 if (psz == NULL) 1472 psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer , pOptions);1526 psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer); 1473 1527 1474 1528 /* did we find the include? */ 1475 1529 if (psz != NULL) 1476 1530 { 1477 if ( pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))1478 depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);1531 if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer)) 1532 depAddDepend(pvRule, szFullname, options.fCheckCyclic); 1479 1533 else 1480 depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic);1534 depAddDepend(pvRule, szBuffer, options.fCheckCyclic); 1481 1535 } 1482 1536 else 1483 1537 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n", 1484 1538 pszFilename, iLine, szFullname); 1539 } } /*while*/ 1540 1541 textbufferDestroy(pvFile); 1542 return 0; 1543 } 1544 #else 1545 int langRC(const char *pszFilename, const char *pszNormFilename, 1546 FDATE FileDate, BOOL fHeader) 1547 { 1548 void * pvFile; /* Text buffer pointer. */ 1549 void * pvRule; /* Handle to the current rule. */ 1550 char szBuffer[4096]; /* Max line length is 4096... should not be a problem. */ 1551 int iLine; /* Linenumber. */ 1552 void * pv = NULL; /* An index used by textbufferGetNextLine. */ 1553 BOOL fComment; /* TRUE when within a multiline comment. */ 1554 /* FALSE when not within a multiline comment. */ 1555 int iIfStack; /* StackPointer. */ 1556 struct IfStackEntry 1557 { 1558 int fIncluded : 1; /* TRUE: include this code; 1559 * FALSE: excluded */ 1560 int fIf : 1; /* TRUE: #if part of the expression. 1561 * FALSE: #else part of the expression. */ 1562 int fSupported : 1; /* TRUE: supported if/else statement 1563 * FALSE: unsupported all else[<something>] are ignored 1564 * All code is included. 1565 */ 1566 } achIfStack[256]; 1567 1568 1569 /**********************************/ 1570 /* Add the depend rule */ 1571 /**********************************/ 1572 if (options.fObjRule && !fHeader) 1573 { 1574 if (options.fNoObjectPath) 1575 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszRsrcExt, FileDate); 1576 else 1577 pvRule = depAddRule(options.fObjectDir ? 1578 options.pszObjectDir : 1579 filePathSlash(pszFilename, szBuffer), 1580 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 1581 options.pszRsrcExt, 1582 FileDate); 1583 1584 if (options.fSrcWhenObj && pvRule) 1585 depAddDepend(pvRule, 1586 options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1587 fileName(pszFilename, szBuffer) : pszNormFilename, 1588 options.fCheckCyclic); 1589 } 1590 else 1591 pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1592 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, FileDate); 1593 1594 /* duplicate rule? */ 1595 if (pvRule == NULL) 1596 return 0; 1597 1598 1599 /********************/ 1600 /* Make file buffer */ 1601 /********************/ 1602 pvFile = textbufferCreate(pszFilename); 1603 if (!pvFile) 1604 { 1605 fprintf(stderr, "failed to open '%s'\n", pszFilename); 1606 return -1; 1607 } 1608 1609 1610 /*******************/ 1611 /* find dependants */ 1612 /*******************/ 1613 /* Initiate the IF-stack, comment state and line number. */ 1614 iIfStack = 0; 1615 achIfStack[iIfStack].fIf = TRUE; 1616 achIfStack[iIfStack].fIncluded = TRUE; 1617 achIfStack[iIfStack].fSupported = TRUE; 1618 fComment = FALSE; 1619 iLine = 0; 1620 while (textbufferGetNextLine(pvFile, &pv, szBuffer, sizeof(szBuffer)) != NULL) /* line loop */ 1621 { 1622 register char * pszC; 1623 char szFullname[CCHMAXPATH]; 1624 int cbLen; 1625 int i1 = 1; 1626 int i = 0; 1627 iLine++; 1628 1629 /* skip blank chars */ 1630 cbLen = strlen(szBuffer); 1631 while (i + 2 < cbLen && (szBuffer[i] == ' ' || szBuffer[i] == '\t')) 1632 i++; 1633 1634 /* preprocessor statement? */ 1635 if (!fComment && szBuffer[i] == '#') 1636 { 1637 /* 1638 * Preprocessor checks 1639 * We known that we have a preprocessor statment (starting with an '#' * at szBuffer[i]). 1640 * Depending on the word afterwards we'll take some different actions. 1641 * So we'll start of by extracting that word and make a string swich on it. 1642 * Note that there might be some blanks between the hash and the word. 1643 */ 1644 int cchWord; 1645 char * pszEndWord; 1646 char * pszArgument; 1647 i++; /* skip hash ('#') */ 1648 while (szBuffer[i] == '\t' || szBuffer[i] == ' ') /* skip blanks */ 1649 i++; 1650 pszArgument = pszEndWord = findEndOfWord(&szBuffer[i]); 1651 cchWord = pszEndWord - &szBuffer[i]; 1652 1653 /* 1654 * Find the argument by skipping the blanks. 1655 */ 1656 while (*pszArgument == '\t' || *pszArgument == ' ') /* skip blanks */ 1657 pszArgument++; 1658 1659 /* 1660 * string switch. 1661 */ 1662 if (strncmp(&szBuffer[i], "include", cchWord) == 0) 1663 { 1664 /* 1665 * #include 1666 * 1667 * Are we in a state where this file is to be included? 1668 */ 1669 if (achIfStack[iIfStack].fIncluded) 1670 { 1671 char *psz; 1672 BOOL f = FALSE; 1673 int j; 1674 1675 /* extract info between "" or <> */ 1676 while (i < cbLen && !(f = (szBuffer[i] == '"' || szBuffer[i] == '<'))) 1677 i++; 1678 i++; /* skip '"' or '<' */ 1679 1680 /* if invalid statement then continue with the next line! */ 1681 if (!f) continue; 1682 1683 /* find end */ 1684 j = f = 0; 1685 while (i + j < cbLen && j < CCHMAXPATH && 1686 !(f = (szBuffer[i+j] == '"' || szBuffer[i+j] == '>'))) 1687 j++; 1688 1689 /* if invalid statement then continue with the next line! */ 1690 if (!f) continue; 1691 1692 /* copy filename */ 1693 strncpy(szFullname, &szBuffer[i], j); 1694 szFullname[j] = '\0'; /* ensure terminatition. */ 1695 strlwr(szFullname); 1696 1697 /* find include file! */ 1698 psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer); 1699 if (psz == NULL) 1700 psz = pathlistFindFile(pszIncludeEnv, szFullname, szBuffer); 1701 1702 /* did we find the include? */ 1703 if (psz != NULL) 1704 { 1705 if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer)) 1706 depAddDepend(pvRule, szFullname, options.fCheckCyclic); 1707 else 1708 depAddDepend(pvRule, szBuffer, options.fCheckCyclic); 1709 } 1710 else 1711 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n", 1712 pszFilename, iLine, szFullname); 1713 } 1714 } 1715 else 1716 /* 1717 * #if 1718 */ 1719 if (strncmp(&szBuffer[i], "if", cchWord) == 0) 1720 { /* #if 0 and #if <1-9> are supported */ 1721 pszEndWord = findEndOfWord(pszArgument); 1722 iIfStack++; 1723 if ((pszEndWord - pszArgument) == 1 1724 && *pszArgument >= '0' && *pszArgument <= '9') 1725 { 1726 if (*pszArgument != '0') 1727 achIfStack[iIfStack].fIncluded = TRUE; 1728 else 1729 achIfStack[iIfStack].fIncluded = FALSE; 1730 } 1731 else 1732 achIfStack[iIfStack].fSupported = FALSE; 1733 achIfStack[iIfStack].fIncluded = TRUE; 1734 achIfStack[iIfStack].fIf = TRUE; 1735 } 1736 else 1737 /* 1738 * #else 1739 */ 1740 if (strncmp(&szBuffer[i], "else", cchWord) == 0) 1741 { 1742 if (achIfStack[iIfStack].fSupported) 1743 { 1744 if (achIfStack[iIfStack].fIncluded) /* ARG!! this'll prevent warning */ 1745 achIfStack[iIfStack].fIncluded = FALSE; 1746 else 1747 achIfStack[iIfStack].fIncluded = TRUE; 1748 } 1749 achIfStack[iIfStack].fIf = FALSE; 1750 } 1751 else 1752 /* 1753 * #endif 1754 */ 1755 if (strncmp(&szBuffer[i], "endif", cchWord) == 0) 1756 { /* Pop the if-stack. */ 1757 if (iIfStack > 0) 1758 iIfStack--; 1759 else 1760 fprintf(stderr, "%s(%d): If-Stack underflow!\n", pszFilename, iLine); 1761 } 1762 /* 1763 * general if<something> and elseif<something> implementations 1764 */ 1765 else 1766 if (strncmp(&szBuffer[i], "elseif", 6) == 0) 1767 { 1768 achIfStack[iIfStack].fSupported = FALSE; 1769 achIfStack[iIfStack].fIncluded = TRUE; 1770 } 1771 else 1772 if (strncmp(&szBuffer[i], "if", 2) == 0) 1773 { 1774 iIfStack++; 1775 achIfStack[iIfStack].fIf = TRUE; 1776 achIfStack[iIfStack].fSupported = FALSE; 1777 achIfStack[iIfStack].fIncluded = TRUE; 1778 } 1779 /* The rest of them aren't implemented yet. 1780 else if (strncmp(&szBuffer[i], "if") == 0) 1781 { 1782 } 1783 */ 1784 } else 1785 /* 1786 * Check for resource compiler directives. 1787 */ 1788 if ( !fComment 1789 && !strchr(&szBuffer[i], ',') 1790 && ( !strnicmp(&szBuffer[i], "ICON", 4) 1791 || !strnicmp(&szBuffer[i], "FONT", 4) 1792 || !strnicmp(&szBuffer[i], "BITMAP", 6) 1793 || !strnicmp(&szBuffer[i], "POINTER", 7) 1794 || !strnicmp(&szBuffer[i], "RESOURCE", 8) 1795 || !(i1 = strnicmp(&szBuffer[i], "RCINCLUDE", 9)) 1796 /*|| !strnicmp(&szBuffer[i], "DLGINCLUDE", 10) - only used by the dlgeditor */ 1797 || !strnicmp(&szBuffer[i], "DEFAULTICON", 11) 1798 ) 1799 ) 1800 { 1801 /* 1802 * RESOURCE 123 1 ["]filename.ext["] 1803 */ 1804 char szLine[1024]; 1805 char * pszFilename; 1806 char chQuote = ' '; 1807 1808 PreProcessLine(szLine, &szBuffer[i]); 1809 1810 pszFilename = &szLine[strlen(szLine)-1]; 1811 if (*pszFilename == '\"' || *pszFilename == '\'') 1812 { 1813 chQuote = *pszFilename; 1814 *pszFilename-- = '\0'; 1815 } 1816 while (*pszFilename != chQuote) 1817 pszFilename--; 1818 *pszFilename++ = '\0'; /* We now have extracted the filename - pszFilename. */ 1819 strlwr(pszFilename); 1820 1821 /* Add filename to the dependencies. */ 1822 if (i1) 1823 depAddDepend(pvRule, pszFilename, options.fCheckCyclic); 1824 else 1825 { 1826 char *psz; 1827 /* find include file! */ 1828 psz = pathlistFindFile(options.pszInclude, pszFilename, szFullname); 1829 if (psz == NULL) 1830 psz = pathlistFindFile(pszIncludeEnv, pszFilename, szFullname); 1831 1832 /* did we find the include? */ 1833 if (psz != NULL) 1834 { 1835 if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szFullname)) 1836 depAddDepend(pvRule, pszFilename, options.fCheckCyclic); 1837 else 1838 depAddDepend(pvRule, szFullname, options.fCheckCyclic); 1839 } 1840 else 1841 fprintf(stderr, "%s(%d): warning include file '%s' not found!\n", 1842 pszFilename, iLine, pszFilename); 1843 } 1844 } 1845 1846 1847 /* 1848 * Comment checks. 1849 * -Start at first non-blank. 1850 * -Loop thru the line since we might have more than one 1851 * comment statement on a single line. 1852 */ 1853 pszC = &szBuffer[i]; 1854 while (pszC != NULL && *pszC != '\0') 1855 { 1856 if (fComment) 1857 pszC = strstr(pszC, "*/"); /* look for end comment mark. */ 1858 else 1859 { 1860 char *pszLC; 1861 pszLC= strstr(pszC, "//"); /* look for single line comment mark. */ 1862 pszC = strstr(pszC, "/*"); /* look for start comment mark */ 1863 if (pszLC && pszLC < pszC) /* if there is an single line comment mark before the */ 1864 break; /* muliline comment mark we'll ignore the multiline mark. */ 1865 } 1866 1867 /* Comment mark found? */ 1868 if (pszC != NULL) 1869 { 1870 fComment = !fComment; 1871 pszC += 2; /* skip comment mark */ 1872 1873 /* debug */ 1874 /* 1875 if (fComment) 1876 fprintf(stderr, "starts at line %d\n", iLine); 1877 else 1878 fprintf(stderr, "ends at line %d\n", iLine); 1879 */ 1880 } 1485 1881 } 1486 1882 } /*while*/ 1487 1883 1884 textbufferDestroy(pvFile); 1885 1488 1886 return 0; 1489 1887 } 1888 #endif 1490 1889 1491 1890 … … 1493 1892 * Generates depend info on this COBOL file, these are stored internally 1494 1893 * and written to file later. 1495 * @returns 0 on success. 1496 * !0 on error. 1497 * @param pszFilename Pointer to source filename. Correct case is assumed! 1498 * @param pszNormFilename Pointer to normalized source filename. 1499 * @param pvFile Pointer to file textbuffer. 1500 * @param pOptions Pointer to options struct. 1501 * @status completely implemented. 1502 * @author knut st. osmundsen 1503 */ 1504 int langCOBOL(const char *pszFilename, const char *pszNormFilename, void *pvFile, BOOL fHeader, POPTIONS pOptions) 1505 { 1894 * @returns 0 on success. 1895 * !0 on error. 1896 * @param pszFilename Pointer to source filename. Correct case is assumed! 1897 * @param pszNormFilename Pointer to normalized source filename. 1898 * @parma FileDate Date of the source file. 1899 * @parma fHeader True if header file is being scanned. 1900 * @status completely implemented. 1901 * @author knut st. osmundsen 1902 */ 1903 int langCOBOL(const char *pszFilename, const char *pszNormFilename, 1904 FDATE FileDate, BOOL fHeader) 1905 { 1906 void * pvFile; /* Text buffer pointer. */ 1506 1907 void * pvRule; /* Handle to the current rule. */ 1507 1908 char szBuffer[4096]; /* Temporary buffer (max line lenght size...) */ … … 1513 1914 /* Add the depend rule */ 1514 1915 /**********************************/ 1515 if ( pOptions->fObjRule && !fHeader)1516 { 1517 if ( pOptions->fNoObjectPath)1518 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszObjectExt);1916 if (options.fObjRule && !fHeader) 1917 { 1918 if (options.fNoObjectPath) 1919 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, options.pszObjectExt, FileDate); 1519 1920 else 1520 pvRule = depAddRule( pOptions->fObjectDir ?1521 pOptions->pszObjectDir :1921 pvRule = depAddRule(options.fObjectDir ? 1922 options.pszObjectDir : 1522 1923 filePathSlash(pszFilename, szBuffer), 1523 1924 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 1524 pOptions->pszObjectExt); 1525 1526 if (pOptions->fSrcWhenObj && pvRule) 1925 options.pszObjectExt, 1926 FileDate); 1927 1928 if (options.fSrcWhenObj && pvRule) 1527 1929 depAddDepend(pvRule, 1528 pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?1529 fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer),1530 pOptions->fCheckCyclic);1930 options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) 1931 ? fileName(pszFilename, szBuffer) : fileNormalize2(pszFilename, szBuffer), 1932 options.fCheckCyclic); 1531 1933 } 1532 1934 else 1533 pvRule = depAddRule( pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, pszNormFilename, pOptions) ?1534 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL );1935 pvRule = depAddRule(options.fExcludeAll || pathlistFindFile2(options.pszExclude, pszNormFilename) ? 1936 fileName(pszFilename, szBuffer) : pszNormFilename, NULL, NULL, FileDate); 1535 1937 1536 1938 /* duplicate rule? */ 1537 1939 if (pvRule == NULL) 1538 1940 return 0; 1941 1942 1943 /********************/ 1944 /* Make file buffer */ 1945 /********************/ 1946 pvFile = textbufferCreate(pszFilename); 1947 if (!pvFile) 1948 { 1949 fprintf(stderr, "failed to open '%s'\n", pszFilename); 1950 return -1; 1951 } 1539 1952 1540 1953 … … 1621 2034 1622 2035 /* find include file! */ 1623 psz = pathlistFindFile( pOptions->pszInclude, szFullname, szBuffer, pOptions);2036 psz = pathlistFindFile(options.pszInclude, szFullname, szBuffer); 1624 2037 1625 2038 /* did we find the include? */ 1626 2039 if (psz != NULL) 1627 2040 { 1628 if ( pOptions->fExcludeAll || pathlistFindFile2(pOptions->pszExclude, szBuffer, pOptions))1629 depAddDepend(pvRule, szFullname, pOptions->fCheckCyclic);2041 if (options.fExcludeAll || pathlistFindFile2(options.pszExclude, szBuffer)) 2042 depAddDepend(pvRule, szFullname, options.fCheckCyclic); 1630 2043 else 1631 depAddDepend(pvRule, szBuffer, pOptions->fCheckCyclic);2044 depAddDepend(pvRule, szBuffer, options.fCheckCyclic); 1632 2045 } 1633 2046 else … … 1636 2049 } 1637 2050 } /*while*/ 2051 2052 textbufferDestroy(pvFile); 1638 2053 1639 2054 return 0; … … 1651 2066 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 1652 2067 */ 1653 staticint strnicmpwords(const char *pszS1, const char *pszS2, int cch)2068 int strnicmpwords(const char *pszS1, const char *pszS2, int cch) 1654 2069 { 1655 2070 do … … 1821 2236 * @author knut st. osmundsen 1822 2237 */ 1823 staticchar *filePathSlash(const char *pszFilename, char *pszBuffer)2238 char *filePathSlash(const char *pszFilename, char *pszBuffer) 1824 2239 { 1825 2240 char *psz = strrchr(pszFilename, '\\'); … … 1849 2264 * @author knut st. osmundsen 1850 2265 */ 1851 staticchar *filePathSlash2(const char *pszFilename, char *pszBuffer)2266 char *filePathSlash2(const char *pszFilename, char *pszBuffer) 1852 2267 { 1853 2268 char *psz = strrchr(pszFilename, '\\'); … … 1952 2367 * @param pszFilename Name of the file which is to be added. (with path!) 1953 2368 */ 1954 staticBOOL filecacheAddFile(const char *pszFilename)2369 BOOL filecacheAddFile(const char *pszFilename) 1955 2370 { 1956 2371 PFCACHEENTRY pfcNew; … … 1982 2397 * @param pszDir Name of the path which is to be added. (with slash!) 1983 2398 */ 1984 staticBOOL filecacheAddDir(const char *pszDir)2399 BOOL filecacheAddDir(const char *pszDir) 1985 2400 { 1986 2401 PFCACHEENTRY pfcNew; … … 2087 2502 * @parma pszFilename Filename to find. 2088 2503 * @parma pszBuffer Ouput Buffer. 2089 * @param pOptions Pointer to options struct.2090 2504 * @status completely implemented. 2091 2505 * @author knut st. osmundsen 2092 2506 */ 2093 static char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer, POPTIONS pOptions)2507 char *pathlistFindFile(const char *pszPathList, const char *pszFilename, char *pszBuffer) 2094 2508 { 2095 2509 const char *psz = pszPathList; … … 2135 2549 * add the directory to the cache and search it. 2136 2550 */ 2137 if ( pOptions->fCacheSearchDirs && filecacheAddDir(szDir))2551 if (options.fCacheSearchDirs && filecacheAddDir(szDir)) 2138 2552 { 2139 2553 if (filecacheFind(pszBuffer)) … … 2176 2590 * @param pszPathList Path list to search for filename. 2177 2591 * @parma pszFilename Filename to find. The filename should be normalized! 2178 * @param pOptions Pointer to options struct.2179 2592 * @status completely implemented. 2180 2593 * @author knut st. osmundsen 2181 2594 */ 2182 static BOOL pathlistFindFile2(const char *pszPathList, const char *pszFilename, POPTIONS pOptions)2595 BOOL pathlistFindFile2(const char *pszPathList, const char *pszFilename) 2183 2596 { 2184 2597 const char *psz = pszPathList; … … 2238 2651 } 2239 2652 2240 pOptions = pOptions;2241 2653 return FALSE; 2242 2654 } … … 2249 2661 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 2250 2662 */ 2251 staticchar *findEndOfWord(char *psz)2663 char *findEndOfWord(char *psz) 2252 2664 { 2253 2665 … … 2273 2685 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 2274 2686 */ 2275 staticchar *findStartOfWord(const char *psz, const char *pszStart)2687 char *findStartOfWord(const char *psz, const char *pszStart) 2276 2688 { 2277 2689 const char *pszR = psz; … … 2294 2706 * @param phFile File handle. 2295 2707 */ 2296 s tatic signed long fsize(FILE *phFile)2708 signed long fsize(FILE *phFile) 2297 2709 { 2298 2710 int ipos; … … 2356 2768 2357 2769 /** 2770 * C/C++ preprocess a single line. Assumes that we're not starting 2771 * with at comment. 2772 * @returns Pointer to output buffer. 2773 * @param pszOut Ouput (preprocessed) string. 2774 * @param pszIn Input string. 2775 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 2776 */ 2777 char *PreProcessLine(char *pszOut, const char *pszIn) 2778 { 2779 char * psz = pszOut; 2780 BOOL fComment = FALSE; 2781 BOOL fQuote = FALSE; 2782 2783 /* 2784 * Loop thru the string. 2785 */ 2786 while (*pszIn != '\0') 2787 { 2788 if (fQuote) 2789 { 2790 *psz++ = *pszIn; 2791 if (*pszIn == '\\') 2792 { 2793 *psz++ = *++pszIn; 2794 pszIn++; 2795 } 2796 else if (*pszIn++ == '"') 2797 fQuote = FALSE; 2798 } 2799 else if (fComment) 2800 { 2801 if (*pszIn == '*' && pszIn[1] == '/') 2802 { 2803 fComment = FALSE; 2804 pszIn += 2; 2805 } 2806 else 2807 pszIn++; 2808 } 2809 else 2810 { 2811 if ( (*pszIn == '/' && pszIn[1] == '/') 2812 || *pszIn == '\0') 2813 { /* End of line. */ 2814 break; 2815 } 2816 2817 if (*pszIn == '/' && pszIn[1] == '*') 2818 { /* Start comment */ 2819 fComment = TRUE; 2820 pszIn += 2; 2821 } 2822 else 2823 *psz++ = *pszIn++; 2824 } 2825 } 2826 2827 /* 2828 * Trim right. 2829 */ 2830 psz--; 2831 while (psz >= pszOut && *psz == ' ' && *psz == '\t') 2832 psz--; 2833 psz[1] = '\0'; 2834 2835 return pszOut; 2836 } 2837 2838 2839 /** 2358 2840 * Creates a memory buffer for a text file. 2359 2841 * @returns Pointer to file memoryblock. NULL on error. … … 2362 2844 * time (DosRead + DosOpen) - about 70% of the execution time! 2363 2845 */ 2364 staticvoid *textbufferCreate(const char *pszFilename)2846 void *textbufferCreate(const char *pszFilename) 2365 2847 { 2366 2848 void *pvFile = NULL; … … 2396 2878 * @param pvBuffer Buffer handle. 2397 2879 */ 2398 staticvoid textbufferDestroy(void *pvBuffer)2880 void textbufferDestroy(void *pvBuffer) 2399 2881 { 2400 2882 free(pvBuffer); … … 2409 2891 * NULL is passed in to get the first line. 2410 2892 */ 2411 staticchar *textbufferNextLine(void *pvBuffer, register char *psz)2893 char *textbufferNextLine(void *pvBuffer, register char *psz) 2412 2894 { 2413 2895 register char ch; … … 2443 2925 * @remark '\n' and '\r' are removed! 2444 2926 */ 2445 staticchar *textbufferGetNextLine(void *pvBuffer, void **ppv, char *pszLineBuffer, int cchLineBuffer)2927 char *textbufferGetNextLine(void *pvBuffer, void **ppv, char *pszLineBuffer, int cchLineBuffer) 2446 2928 { 2447 2929 char * pszLine = pszLineBuffer; … … 2482 2964 /** 2483 2965 * Appends a depend file to the internal file. 2484 */ 2485 static BOOL depReadFile(const char *pszFilename, POPTIONS pOptions) 2486 { 2487 void *pvFile; 2488 char *pszNext; 2489 BOOL fMoreDeps = FALSE; 2490 void *pvRule = NULL; 2966 * This will update the date in the option struct. 2967 */ 2968 BOOL depReadFile(const char *pszFilename) 2969 { 2970 FILESTATUS3 fst3; 2971 void * pvFile; 2972 char * pszNext; 2973 BOOL fMoreDeps = FALSE; 2974 void * pvRule = NULL; 2975 2491 2976 2492 2977 /* read depend file */ … … 2494 2979 if (pvFile == NULL) 2495 2980 return FALSE; 2981 2982 /* get the filedate and subtract one month from it. */ 2983 if (!DosQueryPathInfo(pszFilename, FIL_STANDARD, &fst3, sizeof(fst3))) 2984 { 2985 if (fst3.fdateLastWrite.month <= 1) 2986 { 2987 if (fst3.fdateLastWrite.year != 0) 2988 { 2989 fst3.fdateLastWrite.month = 12; 2990 fst3.fdateLastWrite.year--; 2991 } 2992 } 2993 else 2994 fst3.fdateLastWrite.month--; 2995 options.fDepDate = fst3.fdateLastWrite; 2996 } 2496 2997 2497 2998 /* parse the original depend file */ … … 2542 3043 ) 2543 3044 { 3045 static FDATE FileDate = {0,0,0}; 2544 3046 psz[i] = '\0'; 2545 pvRule = depAddRule(trimR(psz), NULL, NULL); 3047 pvRule = depAddRule(trimR(psz), NULL, NULL, FileDate); 3048 ((PDEPRULE)pvRule)->fUpdated = FALSE; 2546 3049 psz += i + 1; 2547 3050 cch -= i + 1; … … 2569 3072 psz = trim(psz); 2570 3073 if (*psz != '\0') 2571 depAddDepend(pvRule, psz, pOptions->fCheckCyclic);3074 depAddDepend(pvRule, psz, options.fCheckCyclic); 2572 3075 } 2573 3076 } … … 2585 3088 * @params pszFilename Pointer to name of the output file. 2586 3089 */ 2587 static BOOL depWriteFile(const char *pszFilename, POPTIONS options)3090 BOOL depWriteFile(const char *pszFilename) 2588 3091 { 2589 3092 FILE *phFile; … … 2601 3104 * "super" dependency, enter this scope. 2602 3105 */ 2603 if (options ->pszSuperDependency != NULL)3106 if (options.pszSuperDependency != NULL) 2604 3107 { 2605 3108 iBuffer = sprintf(szBuffer, 2606 3109 "%s:", 2607 options ->pszSuperDependency);3110 options.pszSuperDependency); 2608 3111 2609 3112 pdep = (PDEPRULE)(void*)AVLBeginEnumTree((PPAVLNODECORE)(void*)&pdepTree, &EnumData, TRUE); … … 2704 3207 * Removes all nodes in the tree of dependencies. (pdepTree) 2705 3208 */ 2706 staticvoid depRemoveAll(void)3209 void depRemoveAll(void) 2707 3210 { 2708 3211 AVLENUMDATA EnumData; … … 2739 3242 * NULL if pszRulePath or pszRulePath and pszName contains the entire rule. 2740 3243 */ 2741 static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt)3244 void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt, FDATE FileDate) 2742 3245 { 2743 3246 char szRule[CCHMAXPATH*2]; … … 2776 3279 pNew->papszDep = NULL; 2777 3280 pNew->avlCore.Key = pNew->pszRule; 2778 2779 /* Insert rule */ 3281 pNew->fUpdated = TRUE; 3282 3283 /* Insert the rule */ 2780 3284 if (!AVLInsert((PPAVLNODECORE)(void*)&pdepTree, &pNew->avlCore)) 2781 { /* rule existed - return NULL */ 3285 { /* 3286 * The rule existed. 3287 * If it's allready touched (updated) during this session 3288 * there is nothing to be done. 3289 * If not force scan and it's newer than depfile-1month then 3290 * we'll use the information we've got. 3291 * Reuse the node in the tree. 3292 */ 3293 PDEPRULE pOld = (PDEPRULE)(void*)AVLGet((PPAVLNODECORE)(void*)&pdepTree, pNew->avlCore.Key); 3294 assert(pOld); 2782 3295 free(pNew); 2783 return NULL; 3296 if (pOld->fUpdated) 3297 return NULL; 3298 3299 pOld->fUpdated = TRUE; 3300 if (!options.fForceScan && *(PUSHORT)(void*)&FileDate < *(PUSHORT)(void*)&options.fDepDate) 3301 return NULL; 3302 3303 if (pOld->papszDep) 3304 { 3305 free(pOld->papszDep); 3306 pOld->papszDep = NULL; 3307 } 3308 pOld->cDeps = 0; 3309 3310 return pOld; 2784 3311 } 2785 3312 … … 2797 3324 * @param fCheckCyclic When set we'll check that we're not creating an cyclic dependency. 2798 3325 */ 2799 staticBOOL depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic)3326 BOOL depAddDepend(void *pvRule, const char *pszDep, BOOL fCheckCyclic) 2800 3327 { 2801 3328 PDEPRULE pdep = (PDEPRULE)pvRule; … … 2843 3370 * @param pszDep Depend name. 2844 3371 */ 2845 staticBOOL depCheckCyclic(PDEPRULE pdepRule, const char *pszDep)3372 BOOL depCheckCyclic(PDEPRULE pdepRule, const char *pszDep) 2846 3373 { 2847 3374 #define DEPTH 32 … … 2900 3427 * Testing purpose. 2901 3428 */ 3429 2902 3430 #if !defined(OS2FAKE) 2903 3431 #include <os2.h> … … 2906 3434 #include "olemann.h" 2907 3435 #endif 2908 2909 2910 2911
Note:
See TracChangeset
for help on using the changeset viewer.