Changeset 2770 for trunk/tools/database/StateUpd.cpp
- Timestamp:
- Feb 13, 2000, 12:54:30 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/database/StateUpd.cpp
r2765 r2770 1 /* $Id: StateUpd.cpp,v 1.1 0 2000-02-12 17:55:02bird Exp $1 /* $Id: StateUpd.cpp,v 1.11 2000-02-12 23:54:29 bird Exp $ 2 2 * 3 3 * StateUpd - Scans source files for API functions and imports data on them. … … 13 13 #define INCL_DOSERRORS 14 14 #define INCL_DOSMISC 15 #define INCL_DOSPROCESS 15 16 #include <os2.h> 16 17 #include <stdio.h> … … 54 55 static void copy(char *psz, char *pszFrom, int iFrom, char *pszTo, int iTo, char **papszLines); 55 56 static char *stristr(const char *pszStr, const char *pszSubStr); 57 static char *skipBackwards(const char *pszStopAt, const char *pszFrom, int &iLine, char **papszLines); 56 58 57 59 … … 75 77 char *pszUser = "root"; 76 78 char *pszPasswd = ""; 77 ULONG ul1, ul2; 79 ULONG ul0, ul1, ul2; 80 78 81 DosError(0x3); 82 DosSetPriority(PRTYS_PROCESSTREE, PRTYC_REGULAR, 1, 0); 79 83 80 84 /* get dll name from directory */ … … 286 290 /* write status to log */ 287 291 ul2 = dbGetNumberOfUpdatedFunction(options.lDllRefcode); 288 ul1 = dbCountFunctionInDll(options.lDllRefcode); 292 ul1 = dbCountFunctionInDll(options.lDllRefcode, FALSE); 293 ul0 = dbCountFunctionInDll(options.lDllRefcode, TRUE); 289 294 fprintf(phLog, "-------------------------------------------------\n"); 290 295 fprintf(phLog, "-------- Functions which was not updated --------\n"); … … 292 297 fprintf(phLog, "-------------------------------------------------\n"); 293 298 fprintf(phLog, "-------------------------------------------------\n\n"); 294 fprintf(phLog,"Number of function in this DLL: %4ld \n", ul1);299 fprintf(phLog,"Number of function in this DLL: %4ld (%ld)\n", ul1, ul0); 295 300 fprintf(phLog,"Number of successfully processed APIs: %4ld (%ld)\n", (long)(0x0000FFFF & ulRc), ul2); 296 301 fprintf(phLog,"Number of signals: %4ld\n", (long)(ulRc >> 16)); … … 303 308 304 309 /* warn if error during processing. */ 305 fprintf(stdout,"Number of function in this DLL: %4ld \n", ul1);310 fprintf(stdout,"Number of function in this DLL: %4ld (%ld)\n", ul1, ul0); 306 311 fprintf(stdout,"Number of successfully processed APIs: %4ld (%ld)\n", (long)(0x0000FFFF & ulRc), ul2); 307 312 fprintf(stdout,"Number of signals: %4ld\n", (long)(ulRc >> 16)); … … 744 749 int cArgs; 745 750 char * apszArgs[30]; 751 int iClass; 752 char * pszClass, *pszClassEnd; 746 753 747 754 /* 1.*/ … … 753 760 { 754 761 fprintf(phSignal, "%d: oops! didn't find end of function!, %d\n", pszFilename, __LINE__); 755 iRet = iP1 ;762 iRet = iP1+1; 756 763 return 0x00010000; 757 764 } … … 764 771 { 765 772 pszFn = papszLines[--iFn]; 766 pszFn += strlen(pszFn) ;767 } 768 while (iFn >= i&& *pszFn == ' ')773 pszFn += strlen(pszFn) - (*pszFn != '\0'); 774 } 775 while (iFn >= 0 && *pszFn == ' ') 769 776 { 770 777 if (pszFn != papszLines[iFn]) … … 773 780 { 774 781 pszFn = papszLines[--iFn]; 775 pszFn += strlen(pszFn) ;776 } 777 } 778 if ( *pszFn == ' ' || *pszFn == '\0')782 pszFn += strlen(pszFn) - (*pszFn != '\0'); 783 } 784 } 785 if (iFn < 0 || *pszFn == ' ' || *pszFn == '\0') 779 786 { 780 787 fprintf(phSignal, "%s: internal error!, %d\n", pszFilename, __LINE__); 781 iRet = iP1 ;788 iRet = iP1+1; 782 789 return 0x00010000; 783 790 } 784 791 pszFnEnd = pszFn; 785 pszFn = findStartOfWord(pszFn, papszLines[i ]);792 pszFn = findStartOfWord(pszFn, papszLines[iFn]); 786 793 787 794 /* 2a. */ 788 psz = pszFn; 789 while (psz >= papszLines[i] && *psz == ' ') 790 psz--; 791 if (psz > papszLines[i] && *psz == ':') 792 { 793 while (psz >= papszLines[i] && *psz == ' ') 794 psz--; 795 if (psz > papszLines[i] && *psz == ':') 796 { 797 while (psz >= papszLines[i] && *psz == ' ') 798 psz--; 799 if (psz > papszLines[i]) 800 pszFn = findStartOfWord(psz, papszLines[i]); 801 else 802 fprintf(phLog, "%.*s: class name is not at same line as the ::\n", pszFnEnd - psz-1, psz+1); 803 } 804 else 805 { 806 fprintf(phLog, "%.*s: invalid class '::'\n", pszFnEnd - psz, psz); 807 return 0; 808 } 809 } 795 /* operators are not supported (BOOL kTime::operator > (const kTime &time) const) */ 796 if (pszFn > papszLines[iFn]) 797 { 798 pszClassEnd = pszFn - 1; 799 iClass = iFn; 800 } 801 else 802 { 803 pszClassEnd = pszFn - 1; 804 iClass = iFn - 1; 805 } 806 c = 2; 807 while (iClass >= 0 && c >= 0) 808 { 809 if (*pszClassEnd == ':') 810 c--; 811 else if (*pszClassEnd != ' ') 812 break; 813 pszClassEnd--; 814 } 815 if (*pszClassEnd != ' ' && c == 0) 816 pszClass = findStartOfWord(pszClassEnd, papszLines[iClass]); 817 else 818 pszClass = pszClassEnd = NULL; 810 819 811 820 /* 3. */ … … 860 869 861 870 /* 6. */ 862 if (strnicmp(pszFn, "ODINFUNCTION", 12) == 0) 863 { 864 if (cArgs < 2) 871 if (strnicmp(pszFn, "ODINFUNCTION", 12) == 0 || strnicmp(pszFn, "ODINPROCEDURE", 13) == 0) 872 { 873 BOOL fProc = strnicmp(pszFn, "ODINPROCEDURE", 13) == 0; 874 j = 0; 875 if (cArgs < (fProc ? 1 : 2)) 865 876 { 866 877 fprintf(phSignal, "%s: Invalid ODINFUNCTION function too few parameters!\n", pszFilename); 867 878 return 0x00010000; 868 879 } 880 869 881 /* return type */ 870 pFnDesc->pszReturnType = apszArgs[0]; 882 if (fProc) 883 pFnDesc->pszReturnType = "void"; 884 else 885 pFnDesc->pszReturnType = apszArgs[j++]; 871 886 872 887 /* function name */ 873 pFnDesc->pszName = apszArgs[ 1];888 pFnDesc->pszName = apszArgs[j++]; 874 889 875 890 /* arguments */ 876 j = 2;877 891 pFnDesc->cParams = 0; 878 892 while (j+1 < cArgs) … … 886 900 else 887 901 { 888 /* return type - not implemented TODO/FIXME! */ 902 /* return type */ 903 int iReturn = pszClass != NULL ? iClass : iFn; 904 char * pszReturn = pszClass != NULL ? pszClass : pszFn; 905 906 if (pszReturn != papszLines[iReturn]) 907 pszReturn--; 908 else 909 { 910 pszReturn = papszLines[--iReturn]; 911 pszReturn += strlen(pszReturn) - (*pszReturn != '\0'); 912 } 913 pszReturn = skipBackwards("{};-+#:\"\'", pszReturn, iReturn, papszLines); 889 914 *pszEnd = '\0'; 890 copy(pszEnd, papszLines[i], i, pszFn-1, iFn, papszLines); 915 copy(pszEnd, pszReturn, iReturn, pszFn-1, iFn, papszLines); 916 if (strlen(pszEnd) > 1024) 917 { 918 fprintf(phSignal,"Fatal error! return statement is too larget. len=%d", strlen(pszEnd)); 919 fprintf(phLog, "Fatal error! return statement is too larget. len=%d", strlen(pszEnd)); 920 fprintf(stderr, "Fatal error! return statement is too larget. len=%d", strlen(pszEnd)); 921 fflush(phLog); 922 fflush(phSignal); 923 fflush(stderr); 924 } 925 pszEnd = trim(pszEnd); 891 926 pFnDesc->pszReturnType = *pszEnd == '\0' ? NULL : pszEnd; 892 927 pszEnd = strlen(pszEnd) + pszEnd + 1; … … 898 933 { /* cdecl function is prefixed with an '_' */ 899 934 strcpy(pszEnd, "_"); 900 strncat(pszEnd + 1, pszFn, pszFnEnd - pszFn+1); 901 } 902 else 903 strncat(pszEnd, pszFn, pszFnEnd - pszFn+1); 935 } 936 if (pszClass != NULL) 937 { 938 strncat(pszEnd,pszClass, pszClassEnd - pszClass + 1); 939 strcat(pszEnd, "::"); 940 } 941 strncat(pszEnd, pszFn, pszFnEnd - pszFn + 1); 904 942 pFnDesc->pszName = pszEnd; 905 943 pszEnd = strlen(pszEnd) + pszEnd + 1; … … 1244 1282 { 1245 1283 pszP1 = strchr(papszLines[i], '('); 1246 if (pszP1 != NULL && pszP1 > papszLines[i])1284 if (pszP1 != NULL && pszP1 >= papszLines[i]) 1247 1285 { 1248 1286 int cchFnName = 0; 1249 1287 char *pszFnName = pszP1 - 1; 1250 1288 1251 while (pszFnName - cchFnName > papszLines[ i] && pszFnName[cchFnName] == ' ')1289 while (pszFnName - cchFnName > papszLines[0] && pszFnName[cchFnName] == ' ') 1252 1290 cchFnName--, pszFnName--; 1253 1291 1254 pszFnName = findStartOfWord(pszFnName, papszLines[ i]);1292 pszFnName = findStartOfWord(pszFnName, papszLines[0]); 1255 1293 cchFnName += pszP1 - pszFnName; 1256 1294 if (cchFnName >= 0) … … 1294 1332 return TRUE; 1295 1333 } 1334 /* FIXME: constructors with ':' afterwards are not supported !TODO! */ 1296 1335 } 1297 1336 } … … 1526 1565 char *psz = pszFile; 1527 1566 char **papszLines = NULL; 1528 int cLines = 0;1567 int cLines = 1; 1529 1568 1530 1569 while (*psz != '\0') … … 1544 1583 if (papszLines != NULL) 1545 1584 { 1546 cLines = 0;1547 p sz = pszFile;1585 cLines = 1; 1586 papszLines[0] = psz = pszFile; 1548 1587 while (*psz != '\0') 1549 1588 { … … 1628 1667 } 1629 1668 1630 1669 #if 0 1631 1670 static void copy(char *psz, int jFrom, int iFrom, int jTo, int iTo, char **papszLines) 1632 1671 { … … 1639 1678 while (i < iTo || (i == iTo && j <= jTo)) 1640 1679 { 1641 if (papszLines[i][j] != '\0' &&1642 !(papszLines[i][j] == '/' && papszLines[i][j+1] == '/') /* '//' coments */1680 if (papszLines[i][j] != '\0' 1681 && !(papszLines[i][j] == '/' && papszLines[i][j+1] == '/') /* '//' coments */ 1643 1682 ) 1644 1683 { … … 1678 1717 } 1679 1718 1719 #else 1720 static void copy(char *psz, int jFrom, int iFrom, int jTo, int iTo, char **papszLines) 1721 { 1722 char chPrev = '\n'; 1723 int i, j; 1724 int fComment = FALSE; 1725 int fFirst = TRUE; 1726 1727 i = iFrom; 1728 j = jFrom; 1729 while (i < iTo || (i == iTo && j <= jTo)) 1730 { 1731 if (papszLines[i][j] != '\0' 1732 && !(papszLines[i][j] == '/' && papszLines[i][j+1] == '/') /* '//' coments */ 1733 && !(!fComment && fFirst && papszLines[i][j] == '#') 1734 ) 1735 { 1736 fFirst = papszLines[i][j] == ' '; 1737 1738 /* copy char ? */ 1739 if (!fComment) 1740 { 1741 fComment = papszLines[i][j] == '/' && papszLines[i][j+1] == '*'; 1742 1743 if (!fComment && !(chPrev == ' ' && papszLines[i][j] == ' ') /* only one space char */ 1744 && !(chPrev == '(' && papszLines[i][j] == ' ') /* no space after '(' */ 1745 ) 1746 { 1747 if (chPrev == ' ' && (papszLines[i][j] == ',' || papszLines[i][j] == ')')) 1748 psz[-1] = papszLines[i][j]; /* no space before ',' and ')' */ 1749 else 1750 { 1751 chPrev = *psz++ = papszLines[i][j]; 1752 if (chPrev == '*') /* ensure ' ' after '*' */ 1753 chPrev = *psz++ = ' '; 1754 } 1755 } 1756 1757 } 1758 else 1759 if ((fComment = papszLines[i][j] != '*' || papszLines[i][j+1] != '/') == FALSE) 1760 j++; 1761 j++; 1762 } 1763 else 1764 { 1765 /* next */ 1766 j = 0; 1767 fFirst = TRUE; 1768 i++; 1769 if (chPrev != ' ' && chPrev != '(') 1770 chPrev = *psz++ = ' '; 1771 } 1772 } 1773 *psz = '\0'; 1774 } 1775 #endif 1776 1680 1777 1681 1778 /** … … 1714 1811 } 1715 1812 1813 1814 1815 /** 1816 * Skips backwards until one of the chars in pszStopAt or star of file is reached. 1817 * @returns Pointer to end. 1818 * @param pszStopAt Array of chars which we should stop at. 1819 * @param pszFrom Start pointer. 1820 * @param iLine Reference to index to array of lines. input: start line, output: result line. 1821 * @param papszLines Array lines. 1822 * @sketch 1823 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 1824 * @remark Comments are skipped. 1825 * No tests for strings ("...asdf"). 1826 */ 1827 static char *skipBackwards(const char *pszStopAt, const char *pszFrom, int &iLine, char **papszLines) 1828 { 1829 BOOL fComment = FALSE; 1830 int i = iLine; 1831 const char *psz = pszFrom; 1832 1833 while (i >= 0) 1834 { 1835 /* check for stop char */ 1836 const char *psz1 = pszStopAt; 1837 while (*psz1 != '\0') 1838 if (*psz1++ == *psz) 1839 break; 1840 if (*psz1 != '\0') 1841 break; 1842 1843 /* comment check */ 1844 if (!fComment && psz > papszLines[i] && *psz == '/' && psz[-1] == '*') 1845 fComment = TRUE; 1846 else if (fComment && *psz == '/' && psz[1] == '*') 1847 fComment = FALSE; 1848 1849 /* ok position to return? */ 1850 if (!fComment) 1851 { 1852 iLine = i; 1853 pszFrom = psz; 1854 } 1855 1856 /* prev */ 1857 if (psz > papszLines[i]) 1858 psz--; 1859 else 1860 { /* try find line comment */ 1861 do 1862 { 1863 char *pszStart = papszLines[--i]; 1864 while (*pszStart == ' ') 1865 pszStart++; 1866 if (*pszStart != '\0' && *pszStart != '#' 1867 && !(*pszStart == '/' && pszStart[1] == '/')) 1868 { /* find '//' */ 1869 pszStart = strstr(pszStart, "//"); 1870 if (pszStart != NULL) 1871 psz = pszStart-1; 1872 else 1873 psz = papszLines[i] + strlen(papszLines[i]) - 1; 1874 break; 1875 } 1876 } while (i > 0); 1877 } 1878 } 1879 1880 return (char*)pszFrom; 1881 } 1882
Note:
See TracChangeset
for help on using the changeset viewer.