Ignore:
Timestamp:
Feb 11, 2000, 7:35:55 PM (26 years ago)
Author:
bird
Message:

Odin32 DB.

File:
1 edited

Legend:

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

    r2748 r2759  
    1 /* $Id: StateUpd.cpp,v 1.7 2000-02-10 23:37:52 bird Exp $
     1/* $Id: StateUpd.cpp,v 1.8 2000-02-11 18:35:54 bird Exp $
    22 *
    33 * StateUpd - Scans source files for API functions and imports data on them.
     
    4444static unsigned long analyseFnDcl2(PFNDESC pFnDesc, char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions);
    4545static BOOL  isFunction(char **papszLines, int i, POPTIONS pOptions);
     46static long _System dbNotUpdatedCallBack(const char *pszValue, const char *pszFieldName, void *pvUser);
    4647static char *skipInsignificantChars(char **papszLines, int &i, char *psz);
    4748static char *readFileIntoMemory(const char *pszFilename);
     
    6667    BOOL           fFatal = FALSE;
    6768    unsigned long  ulRc = 0;
    68     OPTIONS        options = {TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE};
     69    char           szDLLName[64];
     70    OPTIONS        options = {TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, &szDLLName[0], -1};
    6971    unsigned long  ulRc2;
    7072    char          *pszErrorDesc = NULL;
     
    7375    char          *pszUser     = "root";
    7476    char          *pszPasswd   = "";
    75 
     77    ULONG          ul1, ul2;
    7678    DosError(0x3);
     79
     80    /* get dll name from directory */
     81    ul1 = ul2 = 0;
     82    DosQueryCurrentDisk(&ul1, &ul2);
     83    ul2 = sizeof(szDLLName);
     84    DosQueryCurrentDir(ul1, &szDLLName[0], &ul2);
     85    if (ul2 != 0)
     86    {
     87        if (szDLLName[ul2-1] == '\\' || szDLLName[ul2-1] == '/')
     88            szDLLName[--ul2] = '\0';
     89        ul1 = ul2;
     90        while (ul1 != 0 && szDLLName[ul1-1] != '\\' && szDLLName[ul1-1] != '/')
     91            ul1--;
     92        if (ul1 != 0)
     93            options.pszDLLName = &szDLLName[ul1];
     94    }
     95    else
     96        szDLLName[0] = '\0';
     97
    7798
    7899    /**************************************************************************
     
    87108    *           -COMCTL32<[+]|-> Removes 'COMCTL32'-prefix from function name.
    88109    *           -VERSION<[+]|->  Removes 'VERSION'-prefix from function name.
     110    *           -Dll:<dllname>   Name of the dll being processed.
    89111    *           -d:<dbname>      Database name
    90112    *           -p:<passwd>      Password
     
    101123                case 'd':
    102124                case 'D':
    103                     if (argv[argi][2] == ':')
    104                         pszDatabase = &argv[argi][3];
     125                    if (strnicmp(argv[argi], "dll:", 4) == 0 )
     126                        options.pszDLLName = &argv[argi][5];
    105127                    else
    106                         fprintf(stderr, "warning: option '-d:' requires database name.\n");
     128                    {
     129                        if (argv[argi][2] == ':')
     130                            pszDatabase = &argv[argi][3];
     131                        else
     132                            fprintf(stderr, "warning: option '-d:' requires database name.\n");
     133                    }
    107134                    break;
    108135
     
    217244        if (!options.fIntegrityOnly)
    218245        {
     246            /* find dll */
     247            options.lDllRefcode = dbGetDll(options.pszDLLName);
     248            fprintf(phLog, "DLL: refcode=%d, name=%s\n", options.lDllRefcode, options.pszDLLName);
     249
    219250            /* processing */
    220251            if (argv[argi] == NULL || *argv[argi] == '\0')
     
    253284        }
    254285
     286        /* write status to log */
     287        fprintf(phLog, "-------------------------------------------------\n");
     288        fprintf(phLog, "-------- Functions which was not updated --------\n");
     289        dbGetNotUpdatedFunction(options.lDllRefcode, dbNotUpdatedCallBack);
     290        fprintf(phLog, "-------------------------------------------------\n");
     291        fprintf(phLog, "-------------------------------------------------\n\n");
     292        ul1 = dbCountFunctionInDll(options.lDllRefcode);
     293        fprintf(phLog,"Number of function in this DLL:        %4ld\n", ul1);
     294        fprintf(phLog,"Number of successfully processed APIs: %4ld\n", (long)(0x0000FFFF & ulRc));
     295        fprintf(phLog,"Number of signals:                     %4ld\n", (long)(ulRc >> 16));
     296
    255297        /* close the logs */
    256298        closeLogs();
     
    260302
    261303        /* warn if error during processing. */
     304        fprintf(stdout,"Number of function in this DLL:        %4ld\n", ul1);
    262305        fprintf(stdout,"Number of successfully processed APIs: %4ld\n", (long)(0x0000FFFF & ulRc));
    263306        fprintf(stdout,"Number of signals:                     %4ld\n", (long)(ulRc >> 16));
     
    568611
    569612        /* 3.*/
    570         fprintf(phLog, "Name:      '%s'  (refcode=%ld)\n", FnDesc.pszName, FnDesc.lRefCode);
     613        fprintf(phLog, "Name:      '%s'  (refcodes=", FnDesc.pszName);
     614        for (j = 0; j < FnDesc.cRefCodes; j++)
     615            fprintf(phLog, j > 0 ? ", %ld" : "%ld", FnDesc.alRefCode[j]);
     616        fprintf(phLog, ")\n");
    571617        fprintf(phLog, "  Returns: '%s'\n", FnDesc.pszReturnType != NULL ? FnDesc.pszReturnType : "<missing>");
    572618        fprintf(phLog, "  cParams: %2d\n", FnDesc.cParams);
     
    640686    }
    641687
    642     if (FnFindBuf.cFns == 0)
    643     {
     688    pFnDesc->cRefCodes = 0;
     689    if (FnFindBuf.cFns != 0)
     690    {
     691        if (pOptions->lDllRefcode < 0)
     692        {
     693            if (FnFindBuf.cFns > 1)
     694            {
     695                fprintf(phSignal, "%s: unknown dll and more than two occurences of this function!\n", pszFilename);
     696                return 0x00010000;
     697            }
     698            pOptions->lDllRefcode = FnFindBuf.alDllRefCode[0];
     699            fprintf(phLog, "DllRef = %d\n", pOptions->lDllRefcode);
     700        }
     701
     702        for (lFn = 0; lFn < FnFindBuf.cFns; lFn++)
     703        {
     704            if (FnFindBuf.alDllRefCode[lFn] == pOptions->lDllRefcode)
     705                pFnDesc->alRefCode[pFnDesc->cRefCodes++] = FnFindBuf.alRefCode[lFn];
     706        }
     707
     708        if (pFnDesc->cRefCodes == 0)
     709            fprintf(phLog, "%s was not an API in this dll(%d)!\n", pFnDesc->pszName, pOptions->lDllRefcode);
     710    }
     711    else
    644712        fprintf(phLog, "%s was not an API\n", pFnDesc->pszName);
    645         return 0;
    646     }
    647     else if (FnFindBuf.cFns > 1)
    648     {   /* 3b.*/
    649         while (lFn < (int)FnFindBuf.cFns && FnFindBuf.alDllRefCode[lFn] != lPrevFnDll)
    650             lFn++;
    651         if (lPrevFnDll == -1L && lFn >= (int)FnFindBuf.cFns)
    652         {
    653             fprintf(phSignal, "%s, %s: error - more than one function by the name '%s'\n",
    654                     pszFilename, pFnDesc->pszName, pFnDesc->pszName);
    655             return 0x00010000;
    656         }
    657     }
    658     pFnDesc->lRefCode = FnFindBuf.alRefCode[lFn];
    659     lPrevFnDll = FnFindBuf.alDllRefCode[lFn];
    660 
     713
     714    ulRc = pFnDesc->cRefCodes;
    661715    return ulRc;
    662716}
     
    681735     * 1. find the '('
    682736     * 2. find the word ahead of the '(', this is the function name.
     737     * 2a. class test.
    683738     * 3. find the closing ')'
    684739     * 4. copy the parameters, which is between the two '()'
     
    687742
    688743    int     iFn, iP1, iP2, j;
    689     char *  pszFn, *pszP1, *pszP2;
     744    char *  pszFn, *pszFnEnd, *pszP1, *pszP2;
    690745    char *  psz, *pszEnd;
    691746    int     cArgs;
     
    729784        return 0x00010000;
    730785    }
     786    pszFnEnd = pszFn;
    731787    pszFn = findStartOfWord(pszFn, papszLines[i]);
     788
     789    /* 2a. */
     790    psz = pszFn;
     791    while (psz >= papszLines[i] && *psz == ' ')
     792        psz--;
     793    if (psz > papszLines[i] && *psz == ':')
     794    {
     795        while (psz >= papszLines[i] && *psz == ' ')
     796            psz--;
     797        if (psz > papszLines[i] && *psz == ':')
     798        {
     799            while (psz >= papszLines[i] && *psz == ' ')
     800                psz--;
     801            if (psz > papszLines[i])
     802                pszFn = findStartOfWord(psz, papszLines[i]);
     803            else
     804                fprintf(phLog, "%.*s: class name is not at same line as the ::\n", pszFnEnd - psz-1, psz+1);
     805        }
     806        else
     807        {
     808            fprintf(phLog, "%.*s: invalid class '::'\n", pszFnEnd - psz, psz);
     809            return 0;
     810        }
     811    }
    732812
    733813    /* 3. */
     
    792872    else
    793873    {
     874        /* return type - not implemented TODO/FIXME! */
     875        *pszEnd = '\0';
     876        copy(pszEnd, papszLines[i], i, pszFn-1, iFn, papszLines);
     877        pFnDesc->pszReturnType = *pszEnd == '\0' ? NULL : pszEnd;
     878        pszEnd = strlen(pszEnd) + pszEnd + 1;
     879
    794880        /* function name */
    795881        *pszEnd = '\0';
    796         strncat(pszEnd, pszFn, findEndOfWord(pszFn) - pszFn);
     882        if (pFnDesc->pszReturnType != NULL
     883            && stristr(pFnDesc->pszReturnType, "cdecl") != NULL)
     884        {   /* cdecl function is prefixed with an '_' */
     885            strcpy(pszEnd, "_");
     886            strncat(pszEnd+1, pszFn, pszFnEnd - pszFn+1);
     887        }
     888        else
     889            strncat(pszEnd, pszFn, pszFnEnd - pszFn+1);
     890
    797891        pFnDesc->pszName = pszEnd;
    798 
    799         /* return type - not implemented TODO/FIXME! */
    800         pFnDesc->pszReturnType = NULL;
    801892
    802893        /* arguments */
     
    12271318
    12281319
     1320
     1321/**
     1322 * Callback function for the dbGetNotUpdatedFunction routine.
     1323 *
     1324 */
     1325static long _System dbNotUpdatedCallBack(const char *pszValue, const char *pszFieldName, void *pvUser)
     1326{
     1327    if (stricmp(pszFieldName, "name") == 0)
     1328        fprintf(phLog, "%s ", pszValue);
     1329    else if (stricmp(pszFieldName, "updated") == 0)
     1330        fprintf(phLog, "update=%s ", pszValue);
     1331    else if (stricmp(pszFieldName, "intname") == 0)
     1332        fprintf(phLog, "(%s)\n", pszValue);
     1333
     1334    pvUser = pvUser;
     1335    return 0;
     1336}
     1337
     1338
    12291339/**
    12301340 * Skips insignificant chars (spaces, new-lines and comments)
Note: See TracChangeset for help on using the changeset viewer.