Ignore:
Timestamp:
Feb 13, 2000, 12:54:30 AM (26 years ago)
Author:
bird
Message:

Corrections, DB optimizations, and some new features in StateUpd.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/database/StateUpd.cpp

    r2765 r2770  
    1 /* $Id: StateUpd.cpp,v 1.10 2000-02-12 17:55:02 bird Exp $
     1/* $Id: StateUpd.cpp,v 1.11 2000-02-12 23:54:29 bird Exp $
    22 *
    33 * StateUpd - Scans source files for API functions and imports data on them.
     
    1313#define INCL_DOSERRORS
    1414#define INCL_DOSMISC
     15#define INCL_DOSPROCESS
    1516#include <os2.h>
    1617#include <stdio.h>
     
    5455static void copy(char *psz, char *pszFrom, int iFrom, char *pszTo, int iTo, char **papszLines);
    5556static char *stristr(const char *pszStr, const char *pszSubStr);
     57static char *skipBackwards(const char *pszStopAt, const char *pszFrom, int &iLine, char **papszLines);
    5658
    5759
     
    7577    char          *pszUser     = "root";
    7678    char          *pszPasswd   = "";
    77     ULONG          ul1, ul2;
     79    ULONG          ul0, ul1, ul2;
     80
    7881    DosError(0x3);
     82    DosSetPriority(PRTYS_PROCESSTREE, PRTYC_REGULAR, 1, 0);
    7983
    8084    /* get dll name from directory */
     
    286290        /* write status to log */
    287291        ul2 = dbGetNumberOfUpdatedFunction(options.lDllRefcode);
    288         ul1 = dbCountFunctionInDll(options.lDllRefcode);
     292        ul1 = dbCountFunctionInDll(options.lDllRefcode, FALSE);
     293        ul0 = dbCountFunctionInDll(options.lDllRefcode, TRUE);
    289294        fprintf(phLog, "-------------------------------------------------\n");
    290295        fprintf(phLog, "-------- Functions which was not updated --------\n");
     
    292297        fprintf(phLog, "-------------------------------------------------\n");
    293298        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);
    295300        fprintf(phLog,"Number of successfully processed APIs: %4ld (%ld)\n", (long)(0x0000FFFF & ulRc), ul2);
    296301        fprintf(phLog,"Number of signals:                     %4ld\n", (long)(ulRc >> 16));
     
    303308
    304309        /* 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);
    306311        fprintf(stdout,"Number of successfully processed APIs: %4ld (%ld)\n", (long)(0x0000FFFF & ulRc), ul2);
    307312        fprintf(stdout,"Number of signals:                     %4ld\n", (long)(ulRc >> 16));
     
    744749    int     cArgs;
    745750    char *  apszArgs[30];
     751    int     iClass;
     752    char *  pszClass, *pszClassEnd;
    746753
    747754    /* 1.*/
     
    753760    {
    754761        fprintf(phSignal, "%d: oops! didn't find end of function!, %d\n", pszFilename, __LINE__);
    755         iRet = iP1;
     762        iRet = iP1+1;
    756763        return 0x00010000;
    757764    }
     
    764771    {
    765772        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 == ' ')
    769776    {
    770777        if (pszFn != papszLines[iFn])
     
    773780        {
    774781            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')
    779786    {
    780787        fprintf(phSignal, "%s: internal error!, %d\n", pszFilename, __LINE__);
    781         iRet = iP1;
     788        iRet = iP1+1;
    782789        return 0x00010000;
    783790    }
    784791    pszFnEnd = pszFn;
    785     pszFn = findStartOfWord(pszFn, papszLines[i]);
     792    pszFn = findStartOfWord(pszFn, papszLines[iFn]);
    786793
    787794    /* 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;
    810819
    811820    /* 3. */
     
    860869
    861870    /* 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))
    865876        {
    866877            fprintf(phSignal, "%s: Invalid ODINFUNCTION function too few parameters!\n", pszFilename);
    867878            return 0x00010000;
    868879        }
     880
    869881        /* return type */
    870         pFnDesc->pszReturnType = apszArgs[0];
     882        if (fProc)
     883            pFnDesc->pszReturnType = "void";
     884        else
     885            pFnDesc->pszReturnType = apszArgs[j++];
    871886
    872887        /* function name */
    873         pFnDesc->pszName = apszArgs[1];
     888        pFnDesc->pszName = apszArgs[j++];
    874889
    875890        /* arguments */
    876         j = 2;
    877891        pFnDesc->cParams = 0;
    878892        while (j+1 < cArgs)
     
    886900    else
    887901    {
    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);
    889914        *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);
    891926        pFnDesc->pszReturnType = *pszEnd == '\0' ? NULL : pszEnd;
    892927        pszEnd = strlen(pszEnd) + pszEnd + 1;
     
    898933        {   /* cdecl function is prefixed with an '_' */
    899934            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);
    904942        pFnDesc->pszName = pszEnd;
    905943        pszEnd = strlen(pszEnd) + pszEnd + 1;
     
    12441282        {
    12451283            pszP1 = strchr(papszLines[i], '(');
    1246             if (pszP1 != NULL && pszP1 > papszLines[i])
     1284            if (pszP1 != NULL && pszP1 >= papszLines[i])
    12471285            {
    12481286                int  cchFnName  = 0;
    12491287                char *pszFnName = pszP1 - 1;
    12501288
    1251                 while (pszFnName - cchFnName > papszLines[i] && pszFnName[cchFnName] == ' ')
     1289                while (pszFnName - cchFnName > papszLines[0] && pszFnName[cchFnName] == ' ')
    12521290                    cchFnName--, pszFnName--;
    12531291
    1254                 pszFnName = findStartOfWord(pszFnName, papszLines[i]);
     1292                pszFnName = findStartOfWord(pszFnName, papszLines[0]);
    12551293                cchFnName += pszP1 - pszFnName;
    12561294                if (cchFnName >= 0)
     
    12941332                                    return TRUE;
    12951333                                }
     1334                                /* FIXME: constructors with ':' afterwards are not supported !TODO! */
    12961335                            }
    12971336                        }
     
    15261565    char *psz = pszFile;
    15271566    char **papszLines = NULL;
    1528     int  cLines = 0;
     1567    int  cLines = 1;
    15291568
    15301569    while (*psz != '\0')
     
    15441583    if (papszLines != NULL)
    15451584    {
    1546         cLines = 0;
    1547         psz = pszFile;
     1585        cLines = 1;
     1586        papszLines[0] = psz = pszFile;
    15481587        while (*psz != '\0')
    15491588        {
     
    16281667}
    16291668
    1630 
     1669#if 0
    16311670static void copy(char *psz, int jFrom, int iFrom, int jTo, int iTo, char **papszLines)
    16321671{
     
    16391678    while (i < iTo || (i == iTo && j <= jTo))
    16401679    {
    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 */
    16431682            )
    16441683        {
     
    16781717}
    16791718
     1719#else
     1720static 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
    16801777
    16811778/**
     
    17141811}
    17151812
     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 */
     1827static 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.