Changeset 3123 for trunk/tools
- Timestamp:
- Mar 16, 2000, 4:27:08 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/fastdep/fastdep.c
r3122 r3123 1 /* $Id: fastdep.c,v 1. 7 2000-03-15 17:14:16bird Exp $1 /* $Id: fastdep.c,v 1.8 2000-03-16 15:27:08 bird Exp $ 2 2 * 3 3 * Fast dependents. (Fast = Quick and Dirty!) … … 86 86 * Language specific analysis functions type. 87 87 */ 88 typedef int ( _FNLANG) ( FILE *phDep,const char *pszFilename, FILE *phFile,88 typedef int ( _FNLANG) (const char *pszFilename, FILE *phFile, 89 89 BOOL fHeader, POPTIONS pOptions); 90 90 typedef _FNLANG *PFNLANG; … … 121 121 *******************************************************************************/ 122 122 static void syntax(void); 123 static int makeDependent( FILE *phDep,const char *pszFilename, POPTIONS pOptions);124 125 int langC_CPP( FILE *phDep,const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions);126 int langAsm( FILE *phDep,const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions);127 int langRC( FILE *phDep,const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions);128 int langCOBOL( FILE *phDep,const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions);123 static int makeDependent(const char *pszFilename, POPTIONS pOptions); 124 125 int langC_CPP(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions); 126 int langAsm(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions); 127 int langRC(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions); 128 int langCOBOL(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions); 129 129 130 130 … … 163 163 static BOOL depReadFile(const char *pszFilename); 164 164 static BOOL depWriteFile(const char *pszFilename); 165 static void *depAddRule(const char *pszRule); 165 static void depRemoveAll(void); 166 static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt); 166 167 static BOOL depAddDepend(void *pvRule, const char *pszDep); 167 168 … … 231 232 int main(int argc, char **argv) 232 233 { 233 FILE *phDep = NULL;234 234 int rc = 0; 235 235 int argi = 1; … … 279 279 case 'D': 280 280 case 'd': /* "-d <filename>" */ 281 { 282 const char *pszOld = pszDepFile; 281 283 if (argv[argi][2] != '\0') 282 284 pszDepFile = &argv[argi][2]; … … 291 293 } 292 294 } 293 if (phDep != NULL) 295 296 /* if dependencies are generated we'll flush them to the old filename */ 297 if (pdepList != NULL && pszOld != pszDepFile) 294 298 { 295 fclose(phDep); 296 phDep = NULL; 299 if (!depWriteFile(pszOld)) 300 fprintf(stderr, "error: failed to write (flush) dependencies.\n"); 301 depRemoveAll(); 297 302 } 298 303 break; 304 } 299 305 300 306 case 'E': /* list of paths. If a file is found in one of these directories the */ … … 416 422 417 423 /* 418 * Open output file.419 */420 if (phDep == NULL)421 {422 phDep = fopen(pszDepFile, options.fAppend ? "a" : "w");423 if (phDep == NULL)424 {425 fprintf(stderr, "error opening outputfile '%s'.\n", pszDepFile);426 return 1;427 }428 }429 430 /*431 424 * Search for the files specified. 432 425 */ … … 454 447 * Analyse the file. 455 448 */ 456 rc -= makeDependent( phDep,&szSource[0], &options);449 rc -= makeDependent(&szSource[0], &options); 457 450 458 451 /* next file */ … … 465 458 } 466 459 467 /* Close the dep file! */ 468 if (phDep != NULL) 469 fclose(phDep); 470 471 /* clean it! */ 472 #if 0 473 depCleanFile(pszDepFile); 474 #endif 460 /* Write the depend file! */ 461 if (!depWriteFile(pszDepFile)) 462 fprintf(stderr, "error: failed to write dependencies file!\n"); 475 463 476 464 return rc; … … 519 507 520 508 /** 521 * Generates depend info on this file, and fwrites it to phDep. 509 * Generates depend info on this file, these are stored internally 510 * and written to file later. 522 511 * @returns 523 * @param phDep Pointer to file struct for outfile.524 512 * @param pszFilename Pointer to source filename. 525 513 * @param pOptions Pointer to options struct. … … 527 515 * @author knut st. osmundsen 528 516 */ 529 static int makeDependent( FILE *phDep,const char *pszFilename, POPTIONS pOptions)517 static int makeDependent(const char *pszFilename, POPTIONS pOptions) 530 518 { 531 519 int rc = -1; … … 558 546 /* Found? */ 559 547 if (pCfg->papszExts != NULL) 560 rc = (*pCfg->pfn)(p hDep, pszFilename, phFile, fHeader, pOptions);548 rc = (*pCfg->pfn)(pszFilename, phFile, fHeader, pOptions); 561 549 else 562 550 { … … 566 554 } 567 555 568 fputs("\n", phDep);569 556 fclose(phFile); 570 557 } … … 577 564 578 565 /** 579 * Generates depend info on this C or C++ file, and writes it to phDep. 566 * Generates depend info on this C or C++ file, these are stored internally 567 * and written to file later. 580 568 * @returns 0 on success. 581 569 * !0 on error. 582 * @param phDep Pointer to file struct for outfile.583 570 * @param pszFilename Pointer to source filename. 584 571 * @param phFile Pointer to source file handle. … … 587 574 * @author knut st. osmundsen 588 575 */ 589 int langC_CPP(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 590 { 576 int langC_CPP(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 577 { 578 void * pvRule; /* Handle to the current rule. */ 591 579 int iLine; /* Linenumber. */ 592 580 char szBuffer[4096]; /* Max line length is 4096... should not be a problem. */ … … 608 596 609 597 /**********************************/ 610 /* print file name to depend file*/598 /* Add the depend rule */ 611 599 /**********************************/ 612 600 if (pOptions->fObjRule && !fHeader) 613 601 { 614 602 if (pOptions->fNoObjectPath) 615 fprintf(phDep, "%s.%s:", fileNameNoExt(pszFilename, szBuffer), pOptions->pszObjectExt);603 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszObjectExt); 616 604 else 617 fprintf(phDep, "%s%s.%s:", 618 pOptions->fObjectDir ? 619 pOptions->pszObjectDir : filePathSlash(pszFilename, szBuffer), 620 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 621 pOptions->pszObjectExt); 622 623 if (pOptions->fSrcWhenObj) 624 fprintf(phDep, " \\\n%4s %s", "", 625 pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename 626 ); 605 pvRule = depAddRule(pOptions->fObjectDir ? 606 pOptions->pszObjectDir : 607 filePathSlash(pszFilename, szBuffer), 608 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 609 pOptions->pszObjectExt); 610 611 if (pOptions->fSrcWhenObj && pvRule) 612 depAddDepend(pvRule, pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename); 627 613 } 628 614 else 629 fprintf(phDep, "%s:", pszFilename); 615 pvRule = depAddRule(pszFilename, NULL, NULL); 616 617 /* duplicate rule? */ 618 if (pvRule == NULL) 619 return 0; 630 620 631 621 … … 726 716 if (psz != NULL) 727 717 { 728 char szBuffer2[CCHMAXPATH];718 char szBuffer2[CCHMAXPATH]; 729 719 if (pOptions->fExcludeAll || 730 720 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL 731 721 ) 732 strcpy(szBuffer, szFullname); 733 fprintf(phDep, " \\\n%4.s %s", "", szBuffer); 722 depAddDepend(pvRule, szFullname); 723 else 724 depAddDepend(pvRule, szBuffer); 734 725 } 735 726 else … … 848 839 break; 849 840 } /*while*/ 850 fputs("\n", phDep);851 841 852 842 return 0; … … 855 845 856 846 /** 857 * Generates depend info on this file, and fwrites it to phDep. 847 * Generates depend info on this file, these are stored internally 848 * and written to file later. 858 849 * @returns 0 on success. 859 850 * !0 on error. 860 * @param phDep Pointer to file struct for outfile.861 851 * @param pszFilename Pointer to source filename. 862 852 * @param phFile Pointer to source file handle. … … 865 855 * @author knut st. osmundsen 866 856 */ 867 int langAsm(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 868 { 869 char szBuffer[4096]; /* max line length */ 870 int iLine; 857 int langAsm(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 858 { 859 void * pvRule; /* Handle to the current rule. */ 860 char szBuffer[4096]; /* Temporary buffer (max line lenght size...) */ 861 int iLine; /* current line number */ 871 862 872 863 873 864 /**********************************/ 874 /* print file name to depend file*/865 /* Add the depend rule */ 875 866 /**********************************/ 876 867 if (pOptions->fObjRule && !fHeader) 877 868 { 878 869 if (pOptions->fNoObjectPath) 879 fprintf(phDep, "%s.%s:", fileNameNoExt(pszFilename, szBuffer), pOptions->pszObjectExt);870 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszObjectExt); 880 871 else 881 fprintf(phDep, "%s%s.%s:", 882 pOptions->fObjectDir ? 883 pOptions->pszObjectDir : filePathSlash(pszFilename, szBuffer), 884 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 885 pOptions->pszObjectExt); 886 887 if (pOptions->fSrcWhenObj) 888 fprintf(phDep, " \\\n%4s %s", "", 889 pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename 890 ); 872 pvRule = depAddRule(pOptions->fObjectDir ? 873 pOptions->pszObjectDir : 874 filePathSlash(pszFilename, szBuffer), 875 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 876 pOptions->pszObjectExt); 877 878 if (pOptions->fSrcWhenObj && pvRule) 879 depAddDepend(pvRule, pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename); 891 880 } 892 881 else 893 fprintf(phDep, "%s:", pszFilename); 882 pvRule = depAddRule(pszFilename, NULL, NULL); 883 884 /* duplicate rule? */ 885 if (pvRule == NULL) 886 return 0; 894 887 895 888 … … 954 947 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL 955 948 ) 956 strcpy(szBuffer, szFullname); 957 fprintf(phDep, " \\\n%4.s %s", "", szBuffer); 949 depAddDepend(pvRule, szFullname); 950 else 951 depAddDepend(pvRule, szBuffer); 958 952 } 959 953 else … … 965 959 break; 966 960 } /*while*/ 967 fputs("\n", phDep);968 961 969 962 return 0; … … 972 965 973 966 /** 974 * Generates depend info on this Resource file, and writes it to phDep. 967 * Generates depend info on this Resource file, these are stored internally 968 * and written to file later. 975 969 * @returns 0 on success. 976 970 * !0 on error. 977 * @param phDep Pointer to file struct for outfile.978 971 * @param pszFilename Pointer to source filename. 979 972 * @param phFile Pointer to source file handle. … … 982 975 * @author knut st. osmundsen 983 976 */ 984 int langRC(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 985 { 986 char szBuffer[4096]; /* max line length */ 987 int iLine; 977 int langRC(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 978 { 979 void * pvRule; /* Handle to the current rule. */ 980 char szBuffer[4096]; /* Temporary buffer (max line lenght size...) */ 981 int iLine; /* current line number */ 982 988 983 989 984 /**********************************/ 990 /* print file name to depend file*/985 /* Add the depend rule */ 991 986 /**********************************/ 992 987 if (pOptions->fObjRule && !fHeader) 993 988 { 994 989 if (pOptions->fNoObjectPath) 995 fprintf(phDep, "%s.%s:", fileNameNoExt(pszFilename, szBuffer), pOptions->pszRsrcExt);990 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszRsrcExt); 996 991 else 997 fprintf(phDep, "%s%s.res:", 998 pOptions->fObjectDir ? 999 pOptions->pszObjectDir : filePathSlash(pszFilename, szBuffer), 1000 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 1001 pOptions->pszRsrcExt); 1002 1003 if (pOptions->fSrcWhenObj) 1004 fprintf(phDep, " \\\n%4s %s", "", 1005 pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename 1006 ); 992 pvRule = depAddRule(pOptions->fObjectDir ? 993 pOptions->pszObjectDir : 994 filePathSlash(pszFilename, szBuffer), 995 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 996 pOptions->pszRsrcExt); 997 998 if (pOptions->fSrcWhenObj && pvRule) 999 depAddDepend(pvRule, pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename); 1007 1000 } 1008 1001 else 1009 fprintf(phDep, "%s:", pszFilename); 1002 pvRule = depAddRule(pszFilename, NULL, NULL); 1003 1004 /* duplicate rule? */ 1005 if (pvRule == NULL) 1006 return 0; 1010 1007 1011 1008 … … 1072 1069 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL 1073 1070 ) 1074 strcpy(szBuffer, szFullname); 1075 fprintf(phDep, " \\\n%4.s %s", "", szBuffer); 1071 depAddDepend(pvRule, szFullname); 1072 else 1073 depAddDepend(pvRule, szBuffer); 1076 1074 } 1077 1075 else … … 1083 1081 break; 1084 1082 } /*while*/ 1085 fputs("\n", phDep);1086 1083 1087 1084 return 0; … … 1090 1087 1091 1088 /** 1092 * Generates depend info on this COBOL file, and writes it to phDep. 1089 * Generates depend info on this COBOL file, these are stored internally 1090 * and written to file later. 1093 1091 * @returns 0 on success. 1094 1092 * !0 on error. 1095 * @param phDep Pointer to file struct for outfile.1096 1093 * @param pszFilename Pointer to source filename. 1097 1094 * @param phFile Pointer to source file handle. … … 1100 1097 * @author knut st. osmundsen 1101 1098 */ 1102 int langCOBOL(FILE *phDep, const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 1103 { 1104 char szBuffer[4096]; /* max line length */ 1105 int iLine; 1099 int langCOBOL(const char *pszFilename, FILE *phFile, BOOL fHeader, POPTIONS pOptions) 1100 { 1101 void * pvRule; /* Handle to the current rule. */ 1102 char szBuffer[4096]; /* Temporary buffer (max line lenght size...) */ 1103 int iLine; /* current line number */ 1104 1106 1105 1107 1106 /**********************************/ 1108 /* print file name to depend file*/1107 /* Add the depend rule */ 1109 1108 /**********************************/ 1110 1109 if (pOptions->fObjRule && !fHeader) 1111 1110 { 1112 1111 if (pOptions->fNoObjectPath) 1113 fprintf(phDep, "%s.%s:", fileNameNoExt(pszFilename, szBuffer), pOptions->pszObjectExt);1112 pvRule = depAddRule(fileNameNoExt(pszFilename, szBuffer), NULL, pOptions->pszObjectExt); 1114 1113 else 1115 fprintf(phDep, "%s%s.%s:", 1116 pOptions->fObjectDir ? 1117 pOptions->pszObjectDir : filePathSlash(pszFilename, szBuffer), 1118 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 1119 pOptions->pszObjectExt); 1120 1121 if (pOptions->fSrcWhenObj) 1122 fprintf(phDep, " \\\n%4s %s", "", 1123 pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename 1124 ); 1114 pvRule = depAddRule(pOptions->fObjectDir ? 1115 pOptions->pszObjectDir : 1116 filePathSlash(pszFilename, szBuffer), 1117 fileNameNoExt(pszFilename, szBuffer + CCHMAXPATH), 1118 pOptions->pszObjectExt); 1119 1120 if (pOptions->fSrcWhenObj && pvRule) 1121 depAddDepend(pvRule, pOptions->fExcludeAll ? fileName(pszFilename, szBuffer) : pszFilename); 1125 1122 } 1126 1123 else 1127 fprintf(phDep, "%s:", pszFilename); 1124 pvRule = depAddRule(pszFilename, NULL, NULL); 1125 1126 /* duplicate rule? */ 1127 if (pvRule == NULL) 1128 return 0; 1128 1129 1129 1130 … … 1220 1221 pathlistFindFile(pOptions->pszExclude, szFullname, szBuffer2) != NULL 1221 1222 ) 1222 strcpy(szBuffer, szFullname); 1223 fprintf(phDep, " \\\n%4.s %s", "", szBuffer); 1223 depAddDepend(pvRule, szFullname); 1224 else 1225 depAddDepend(pvRule, szBuffer); 1224 1226 } 1225 1227 else … … 1231 1233 break; 1232 1234 } /*while*/ 1233 fputs("\n", phDep);1234 1235 1235 1236 return 0; … … 1707 1708 if (!fMoreDeps && *psz != ' ' && *psz != '\t' && *psz != '\0') 1708 1709 { 1710 i = 0; 1709 1711 while (psz[i] != '\0') 1710 1712 { … … 1723 1725 { /* new rule! */ 1724 1726 psz[i] = '\0'; 1725 pvRule = depAddRule(trimR(psz) );1727 pvRule = depAddRule(trimR(psz), NULL, NULL); 1726 1728 psz += i + 1; 1727 1729 cch -= i + 1; … … 1740 1742 else 1741 1743 fMoreDeps = FALSE; 1742 psz = trim(psz); 1743 if (*psz != '\0') 1744 depAddDepend(pvRule, psz); 1744 1745 /* if not duplicate rule */ 1746 if (pvRule != NULL) 1747 { 1748 psz = trim(psz); 1749 if (*psz != '\0') 1750 depAddDepend(pvRule, psz); 1751 } 1745 1752 } 1746 1753 } /* while */ … … 1763 1770 if (phFile != NULL) 1764 1771 { 1772 char szBuffer[4096]; 1773 int iBuffer = 0; 1765 1774 PDEPRULE pdep = pdepList; 1775 1766 1776 while (pdep != NULL) 1767 1777 { 1768 1769 fprintf(phFile, "%s:", pdep->pszRule); 1778 /* Write rule. Flush the buffer first if necessary. */ 1779 if (iBuffer + 2 >= sizeof(szBuffer)) 1780 { 1781 fwrite(szBuffer, iBuffer, 1, phFile); 1782 iBuffer = 0; 1783 } 1784 iBuffer += sprintf(szBuffer + iBuffer, "%s:", pdep->pszRule); 1785 1786 /* write rule dependants. */ 1770 1787 if (pdep->papszDep != NULL) 1771 1788 { … … 1773 1790 while (*ppsz != NULL) 1774 1791 { 1775 fprintf(phFile, " \\\n %s", *ppsz); 1792 /* flush buffer? */ 1793 if (iBuffer + strlen(*ppsz) + 20 >= sizeof(szBuffer)) 1794 { 1795 fwrite(szBuffer, iBuffer, 1, phFile); 1796 iBuffer = 0; 1797 } 1798 iBuffer += sprintf(szBuffer + iBuffer, " \\\n %s", *ppsz); 1776 1799 1777 1800 /* next dependant */ … … 1779 1802 } 1780 1803 } 1781 fputs("\n\n", phFile); 1804 1805 /* Add two new lines. Flush buffer first if necessary. */ 1806 if (iBuffer + 2 >= sizeof(szBuffer)) 1807 { 1808 fwrite(szBuffer, iBuffer, 1, phFile); 1809 iBuffer = 0; 1810 } 1811 strcpy(szBuffer + iBuffer, "\n\n"); 1812 iBuffer += 2; 1782 1813 1783 1814 /* next rule */ … … 1785 1816 } 1786 1817 1818 /* flush buffer. */ 1819 fwrite(szBuffer, iBuffer, 1, phFile); 1820 1787 1821 fclose(phFile); 1788 1822 return TRUE; … … 1792 1826 } 1793 1827 1828 1829 /** 1830 * Removes all entries in the list of dependencies. (pdepList) 1831 */ 1832 static void depRemoveAll(void) 1833 { 1834 while (pdepList != NULL) 1835 { 1836 register PDEPRULE pdepToBeFree = pdepList; 1837 /* next */ 1838 pdepList = pdepToBeFree->pNext; 1839 1840 /* free this */ 1841 if (pdepToBeFree->papszDep != NULL) 1842 { 1843 char ** ppsz = pdepToBeFree->papszDep; 1844 while (*ppsz != NULL) 1845 free(*ppsz++); 1846 free(pdepToBeFree->papszDep); 1847 } 1848 free(pdepToBeFree); 1849 } 1850 } 1851 1852 1794 1853 /** 1795 1854 * Adds a rule to the list of dependant rules. 1796 1855 * @returns Rule handle. NULL if rule exists/error. 1797 * @param pszRule Pointer to rule text. Empty strings are banned! 1798 * 1799 */ 1800 static void *depAddRule(const char *pszRule) 1801 { 1856 * @param pszRulePath Pointer to rule text. Empty strings are banned! 1857 * This string might only contain the path of the rule. (with '\\') 1858 * @param pszName Name of the rule. 1859 * NULL if pszRulePath contains the entire rule. 1860 * @param pszExt Extention (without '.') 1861 * NULL if pszRulePath or pszRulePath and pszName contains the entire rule. 1862 */ 1863 static void *depAddRule(const char *pszRulePath, const char *pszName, const char *pszExt) 1864 { 1865 char szRule[CCHMAXPATH*2]; 1802 1866 PDEPRULE pdepPrev = NULL; 1803 1867 PDEPRULE pdep = pdepList; 1804 1868 PDEPRULE pNew; 1869 int cch; 1870 1871 /* make rulename */ 1872 strcpy(szRule, pszRulePath); 1873 cch = strlen(szRule); 1874 if (pszName != NULL) 1875 { 1876 strcpy(szRule + cch, pszName); 1877 cch += strlen(szRule + cch); 1878 } 1879 if (pszExt != NULL) 1880 { 1881 strcat(szRule + cch++, "."); 1882 strcat(szRule + cch, pszExt); 1883 cch += strlen(szRule + cch); 1884 } 1805 1885 1806 1886 /* find location */ 1807 while (pdep != NULL && 1808 stricmp(pdep->pszRule, pszRule) < 0 1809 ) 1810 { 1811 pdep = pdepPrev; 1887 while (pdep != NULL && stricmp(pdep->pszRule, szRule) < 0) 1888 { 1889 pdepPrev = pdep; 1812 1890 pdep = pdep->pNext; 1813 1891 } 1814 1892 1815 1893 /* check if matching rule name */ 1816 if (pdep != NULL && stricmp(pdep->pszRule, pszRule) == 0)1894 if (pdep != NULL && stricmp(pdep->pszRule, szRule) == 0) 1817 1895 return NULL; 1818 1896 1819 /* allocate a new rule structure and fill in data */ 1820 pNew = malloc(sizeof(DEPRULE)); 1897 /* 1898 * Allocate a new rule structure and fill in data 1899 * Note. One block for both the DEPRULE and the pszRule string. 1900 */ 1901 pNew = malloc(sizeof(DEPRULE) + cch + 1); 1821 1902 if (pNew == NULL) 1822 1903 return NULL; 1823 pNew->pszRule = malloc(strlen(pszRule) + 1); 1824 if (pNew->pszRule == NULL) 1825 { 1826 free(pNew); 1827 return NULL; 1828 } 1829 strcpy(pNew->pszRule, pszRule); 1904 pNew->pszRule = (char*)(void*)(pNew + 1); 1905 strcpy(pNew->pszRule, szRule); 1830 1906 pNew->cDeps = 0; 1831 1907 pNew->papszDep = NULL; … … 1854 1930 1855 1931 /* allocate more array space */ 1856 if (pdep->cDeps == 0 || ( pdep->cDeps + 2) % 32== 0)1857 { 1858 pdep->papszDep = realloc(pdep->papszDep, 32 * sizeof(char*));1932 if (pdep->cDeps == 0 || ((pdep->cDeps + 2) % 32) == 0) 1933 { 1934 pdep->papszDep = realloc(pdep->papszDep, sizeof(char*) * (pdep->cDeps + 32)); 1859 1935 if (pdep->papszDep == NULL) 1860 1936 {
Note:
See TracChangeset
for help on using the changeset viewer.