Changeset 2742 for trunk/tools/database/StateUpd.cpp
- Timestamp:
- Feb 10, 2000, 11:10:40 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/database/StateUpd.cpp
r2004 r2742 1 /* $Id: StateUpd.cpp,v 1. 5 1999-12-06 23:52:42bird Exp $1 /* $Id: StateUpd.cpp,v 1.6 2000-02-10 22:10:38 bird Exp $ 2 2 * 3 3 * StateUpd - Scans source files for API functions and imports data on them. … … 12 12 #define INCL_DOSFILEMGR 13 13 #define INCL_DOSERRORS 14 #define INCL_DOSMISC 14 15 #include <os2.h> 15 16 #include <stdio.h> … … 41 42 static unsigned long analyseFnHdr(PFNDESC pFnDesc, char **papszLines, int i, const char *pszFilename, POPTIONS pOptions); 42 43 static unsigned long analyseFnDcl(PFNDESC pFnDesc, char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions); 44 static unsigned long analyseFnDcl2(PFNDESC pFnDesc, char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions); 43 45 static BOOL isFunction(char **papszLines, int i, POPTIONS pOptions); 44 46 static char *skipInsignificantChars(char **papszLines, int &i, char *psz); … … 71 73 char *pszUser = "root"; 72 74 char *pszPasswd = ""; 75 76 DosError(0x3); 73 77 74 78 /************************************************************************** … … 593 597 const char *pszFilename, POPTIONS pOptions) 594 598 { 595 static long lPrevFnDll = -1L; /* fix for duplicate dlls */ 596 FNFINDBUF FnFindBuf; 597 char *pszOS2; 598 char *pszP1; 599 int iP1; 600 char *pszP2; 601 int iP2; 602 char *psz; 603 unsigned long ulRc = 0x000000001; 604 int iFn = 0; 605 606 iRet = i+1; 599 static long lPrevFnDll = -1L; /* fix for duplicate dlls */ 600 unsigned long ulRc; 601 FNFINDBUF FnFindBuf; 602 long lFn = 0; 607 603 608 604 /* brief algorithm: 609 * 1. find function name and start and end parentese. (evt. return type.) 610 * 2. copy to szFnDclBuffer. 611 * 3. extract name, and do a database lookup on the name. 612 * 3b. if more that one match, write a signal. (TODO: a simple fix is done, but there are holes.) 613 * 4. analyse parameters. (evt. return type) 605 * 1. read function declaration using analyseFnDcl2. 606 * 2. apply name rules. 607 * 3. do a database lookup on the name. 608 * 3b. if more that one match, write a signal. (TODO: a simple fix is done, but there are holes.) 614 609 */ 615 610 611 /* 1. */ 612 ulRc = analyseFnDcl2(pFnDesc, papszLines, i, iRet, pszFilename, pOptions); 613 if (ulRc != 1) 614 return ulRc; 615 616 /* 2. */ 617 if (pOptions->fOS2 && strncmp(pFnDesc->pszName, "OS2", 3) == 0) 618 pFnDesc->pszName += 3; 619 else if (pOptions->fCOMCTL32 && strncmp(pFnDesc->pszName, "COMCTL32", 8) == 0) 620 pFnDesc->pszName += 8; 621 else if (pOptions->fVERSION && strncmp(pFnDesc->pszName, "VERSION", 7) == 0) 622 pFnDesc->pszName += 7; 623 else if (pOptions->fOld) 624 pFnDesc->pszName += 3; 625 626 /* 3. */ 627 if (!dbFindFunction(pFnDesc->pszName, &FnFindBuf)) 628 { 629 fprintf(phSignal, "%s, %s: error occured while reading from database, %s\n", 630 pszFilename, pFnDesc->pszName, dbGetLastErrorDesc()); 631 return 0x00010000; 632 } 633 634 if (FnFindBuf.cFns == 0) 635 { 636 fprintf(phLog, "%s was not an API\n", pFnDesc->pszName); 637 return 0; 638 } 639 else if (FnFindBuf.cFns > 1) 640 { /* 3b.*/ 641 while (lFn < (int)FnFindBuf.cFns && FnFindBuf.alDllRefCode[lFn] != lPrevFnDll) 642 lFn++; 643 if (lPrevFnDll == -1L && lFn >= (int)FnFindBuf.cFns) 644 { 645 fprintf(phSignal, "%s, %s: error - more than one function by the name '%s'\n", 646 pszFilename, pFnDesc->pszName, pFnDesc->pszName); 647 return 0x00010000; 648 } 649 } 650 pFnDesc->lRefCode = FnFindBuf.alRefCode[lFn]; 651 lPrevFnDll = FnFindBuf.alDllRefCode[lFn]; 652 653 return ulRc; 654 } 655 656 657 658 /** 659 * Analyses the function declaration. 660 * No DB lockup or special function type stuff, only ODINFUNCTION is processed. 661 * @returns high word = number of signals 662 * low word = number of APIs processed. (1 or 0). 663 * @param papszLines Array of lines in the file. 664 * @param i Index into papszLines. 665 * @param iRet Index into papszLines. Where to start searching again. 666 * @param pszFilename Filename used in the signal log. 667 * @param pOptions Pointer to options. 668 */ 669 static unsigned long analyseFnDcl2(PFNDESC pFnDesc, char **papszLines, int i, int &iRet, 670 const char *pszFilename, POPTIONS pOptions) 671 { 672 /** @sketch 673 * 1. find the '(' 674 * 2. find the word ahead of the '(', this is the function name. 675 * 3. find the closing ')' 676 * 4. copy the parameters, which is between the two '()' 677 * 5. format the parameters 678 */ 679 680 int iFn, iP1, iP2, j; 681 char * pszFn, *pszP1, *pszP2; 682 char * psz, *pszEnd; 683 int cArgs; 684 char * apszArgs[30]; 685 616 686 /* 1.*/ 617 if (!pOptions->fOld) 618 { /* new API naming convention */ 619 pszP1 = strchr(papszLines[i], '('); 620 iP1 = i; 621 pszOS2 = pszP1 - 1; 622 while (pszOS2 > papszLines[i] && *pszOS2 == ' ') 623 pszOS2--; 624 pszOS2 = findStartOfWord(pszOS2, papszLines[i]); 625 } 687 iP1 = i; 688 while (papszLines[iP1] != NULL 689 && (pszP1 = strchr(papszLines[iP1], '(')) == NULL) 690 iP1++; 691 if (papszLines[iP1] == NULL) 692 { 693 fprintf(phSignal, "%d: oops! didn't find end of function!, %d\n", pszFilename, __LINE__); 694 iRet = iP1; 695 return 0x00010000; 696 } 697 698 /* 2. */ 699 iFn = iP1; 700 if (papszLines[iFn] != pszP1) 701 pszFn = pszP1 - 1; 626 702 else 627 { /* old API naming convention */ 628 pszOS2 = strstr(papszLines[i], "OS2"); 629 iP1 = i; 630 pszP1 = findEndOfWord(pszOS2); 631 pszP1 = skipInsignificantChars(papszLines, iP1, pszP1); 632 } 703 { 704 pszFn = papszLines[--iFn]; 705 pszFn += strlen(pszFn); 706 } 707 while (iFn >= i && *pszFn == ' ') 708 { 709 if (pszFn != papszLines[iFn]) 710 pszFn--; 711 else 712 { 713 pszFn = papszLines[--iFn]; 714 pszFn += strlen(pszFn); 715 } 716 } 717 if (*pszFn == ' ' || *pszFn == '\0') 718 { 719 fprintf(phSignal, "%s: internal error!, %d\n", pszFilename, __LINE__); 720 iRet = iP1; 721 return 0x00010000; 722 } 723 pszFn = findStartOfWord(pszFn, papszLines[i]); 724 725 /* 3. */ 633 726 iP2 = iP1; 634 727 pszP2 = pszP1 + 1; … … 640 733 iRet = iP2 + 1; //assumes: only one function on a single line! 641 734 642 /* 2. */ 643 psz = &pFnDesc->szFnDclBuffer[0]; 644 /* copy name */ 645 if (pOptions->fOS2 && strncmp(pszOS2, "OS2", 3) == 0) 646 { 647 if (iP1 == i) 648 strncpy(psz, pszOS2+3, pszP1 - (pszOS2+3)); 649 else 650 strcpy(psz, pszOS2+3); 651 } 652 else if (pOptions->fCOMCTL32 && strncmp(pszOS2, "COMCTL32", 8) == 0) 653 { 654 if (iP1 == i) 655 strncpy(psz, pszOS2+8, pszP1 - (pszOS2+8)); 656 else 657 strcpy(psz, pszOS2+8); 658 } 659 else if (pOptions->fVERSION && strncmp(pszOS2, "VERSION", 7) == 0) 660 { 661 if (iP1 == i) 662 strncpy(psz, pszOS2+7, pszP1 - (pszOS2+7)); 663 else 664 strcpy(psz, pszOS2+7); 735 /* 4. */ 736 psz = pFnDesc->szFnDclBuffer; 737 copy(pFnDesc->szFnDclBuffer, pszP1, iP1, pszP2, iP2, papszLines); 738 pszEnd = psz + strlen(psz) + 1; 739 740 /* 5.*/ 741 cArgs = 0; 742 if (stricmp(psz, "(void)") != 0 && strcmp(psz, "()") != 0 && strcmp(psz, "( )")) 743 { 744 char *pszC; 745 pszC = trim(psz+1); 746 while (*pszC != '\0') 747 { 748 apszArgs[cArgs] = pszC; 749 while (*pszC != ',' && *pszC != ')' && *pszC != '\0') 750 pszC++; 751 *pszC = '\0'; 752 trim(apszArgs[cArgs++]); 753 754 /* next */ 755 pszC = trim(pszC + 1); 756 } 757 } 758 759 /* 6. */ 760 if (strnicmp(pszFn, "ODINFUNCTION", 12) == 0) 761 { 762 if (cArgs < 2) 763 { 764 fprintf(phSignal, "%s: Invalid ODINFUNCTION function too few parameters!\n", pszFilename); 765 return 0x00010000; 766 } 767 /* return type */ 768 pFnDesc->pszReturnType = apszArgs[0]; 769 770 /* function name */ 771 pFnDesc->pszName = apszArgs[1]; 772 773 /* arguments */ 774 j = 2; 775 pFnDesc->cParams = 0; 776 while (j+1 < cArgs) 777 { 778 pFnDesc->apszParamType[pFnDesc->cParams] = apszArgs[j]; 779 pFnDesc->apszParamName[pFnDesc->cParams] = apszArgs[j+1]; 780 pFnDesc->cParams++; 781 j += 2; 782 } 665 783 } 666 784 else 667 785 { 668 if (!pOptions->fOld) 669 { /* new API naming convention */ 670 if (iP1 == i) 671 strncpy(psz, pszOS2, pszP1 - pszOS2); 672 else 673 strcpy(psz, pszOS2); 674 } 675 else 676 { /* old API naming convention */ 677 if (iP1 == i) 678 strncpy(psz, pszOS2+3, pszP1 - (pszOS2+3)); 679 else 680 strcpy(psz, pszOS2+3); 681 } 682 } 683 trim(psz); 684 pFnDesc->pszName = psz; 685 psz += strlen(psz) + 1; 686 687 copy(psz, pszP1, iP1, pszP2, iP2, papszLines); 688 689 /* 3.*/ 690 if (!dbFindFunction(pFnDesc->pszName, &FnFindBuf)) 691 { 692 fprintf(phSignal, "%s, %s: error occured while reading from database, %s\n", 693 pszFilename, pFnDesc->pszName, dbGetLastErrorDesc()); 694 return 0x00010000; 695 } 696 697 if (FnFindBuf.cFns == 0) 698 { 699 fprintf(phLog, "%s was not an API\n", pFnDesc->pszName); 700 return 0; 701 } 702 else if (FnFindBuf.cFns > 1) 703 { /* 3b.*/ 704 while (iFn < (int)FnFindBuf.cFns && FnFindBuf.alDllRefCode[iFn] != lPrevFnDll) 705 iFn++; 706 if (lPrevFnDll == -1L && iFn >= (int)FnFindBuf.cFns) 707 { 708 fprintf(phSignal, "%s, %s: error - more than one function by the name '%s'\n", 709 pszFilename, pFnDesc->pszName, pFnDesc->pszName); 710 return 0x00010000; 711 } 712 } 713 pFnDesc->lRefCode = FnFindBuf.alRefCode[iFn]; 714 lPrevFnDll = FnFindBuf.alDllRefCode[iFn]; 715 716 /* 4.*/ 717 pFnDesc->cParams = 0; 718 if (stricmp(psz, "(void)") != 0 && strcmp(psz, "()") != 0 && strcmp(psz, "( )")) 719 { 720 psz++; /* skip '(' */ 721 while (*psz != '\0' && *psz != ')') 722 { 723 char *pszName; 724 char *pszEnd = psz; 725 726 while (*pszEnd != '\0' && *pszEnd != ',' && *pszEnd != ')') 727 pszEnd++; 728 729 /* fix - if pszEnd == '\0' then there is something wrong */ 730 if (*pszEnd == '\0') 731 { 732 fprintf(phLog, "internal error (not fatal): pszEnd = '\\0' when it shouldn't, %d\n", __LINE__); 733 break; 734 } 735 *pszEnd = '\0'; 736 737 /* paranoia test */ 738 if (pszEnd <= psz) 739 { 740 fprintf(phSignal, "%s: error - pszEnd <= psz\n", pszFilename); 741 return 0x00010000; 742 } 743 744 pszName = findStartOfWord(pszEnd - 1, psz); 745 if (pszName > psz) 746 { 747 pszName[-1] = '\0'; /* this is required to be space! */ 748 pFnDesc->apszParamType[pFnDesc->cParams] = trim(psz); 749 } 750 else 751 pFnDesc->apszParamType[pFnDesc->cParams] = ""; /* no parameter type (parameter is usualy a define) */ 752 pFnDesc->apszParamName[pFnDesc->cParams] = trim(pszName); 753 754 /* next */ 755 pFnDesc->cParams++; 756 psz = pszEnd + 1; 757 } 758 } 759 760 return ulRc; 786 /* function name */ 787 *pszEnd = '\0'; 788 strncat(pszEnd, pszFn, findEndOfWord(pszFn) - pszFn); 789 pFnDesc->pszName = pszEnd; 790 791 /* return type - not implemented TODO/FIXME! */ 792 pFnDesc->pszReturnType = NULL; 793 794 /* arguments */ 795 pFnDesc->cParams = cArgs; 796 for (j = 0; j < cArgs; j++) 797 { 798 pFnDesc->apszParamName[j] = findStartOfWord(apszArgs[j] + strlen(apszArgs[j]) - 1, 799 apszArgs[j]); 800 pFnDesc->apszParamName[j][-1] = '\0'; 801 pFnDesc->apszParamType[j] = trim(apszArgs[j]); 802 } 803 } 804 pOptions = pOptions; 805 return 0x00000001; 761 806 } 762 807 … … 1348 1393 { 1349 1394 char *pszR = psz; 1350 while (psz > pszStart &&1395 while (psz >= pszStart && 1351 1396 ( 1352 (*psz >= 'A' && *psz <= 'Z') || (*psz >= 'a' && *psz <= 'z') 1353 || 1354 (*psz >= '0' && *psz <= '9') 1355 || 1356 *psz == '_' 1357 ) 1397 (*psz >= 'A' && *psz <= 'Z') 1398 || (*psz >= 'a' && *psz <= 'z') 1399 || (*psz >= '0' && *psz <= '9') 1400 || *psz == '_' 1401 ) 1358 1402 ) 1359 1403 pszR = psz--; … … 1367 1411 if (psz == NULL) 1368 1412 return NULL; 1369 while (*psz == ' ' )1413 while (*psz == ' ' || *psz == '\t') 1370 1414 psz++; 1371 1415 i = strlen(psz) - 1; 1372 while (i >= 0 && psz[i] == ' ')1416 while (i >= 0 && (psz[i] == ' ' || *psz == '\t')) 1373 1417 i--; 1374 1418 psz[i+1] = '\0'; 1375 1419 return psz; 1376 1420 } 1421 1377 1422 1378 1423 /* copy: remove remarks, and unneeded spaces, ensuring no space after '(',
Note:
See TracChangeset
for help on using the changeset viewer.