Changeset 3838 for trunk/tools/database/StateUpd.cpp
- Timestamp:
- Jul 18, 2000, 9:16:01 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/database/StateUpd.cpp
r3115 r3838 1 /* $Id: StateUpd.cpp,v 1.2 2 2000-03-14 16:33:20bird Exp $1 /* $Id: StateUpd.cpp,v 1.23 2000-07-18 07:15:58 bird Exp $ 2 2 * 3 3 * StateUpd - Scans source files for API functions and imports data on them. … … 47 47 static unsigned long processDir(const char *pszDirOrFile, POPTIONS pOptions); 48 48 static unsigned long processFile(const char *pszFilename, POPTIONS pOptions); 49 static unsigned long processModuleHeader(char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions); 50 static unsigned long processDesignNote(char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions); 49 51 static unsigned long processAPI(char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions); 50 52 static unsigned long analyseFnHdr(PFNDESC pFnDesc, char **papszLines, int i, const char *pszFilename, POPTIONS pOptions); … … 54 56 static char *CommonCopyTextUntilNextTag(char *pszTarget, BOOL fHTML, int iStart, int iEnd, char **papszLines, const char *pszStart = NULL); 55 57 static BOOL isFunction(char **papszLines, int i, POPTIONS pOptions); 58 static BOOL isDesignNote(char **papszLines, int i, POPTIONS pOptions); 56 59 static long _System dbNotUpdatedCallBack(const char *pszValue, const char *pszFieldName, void *pvUser); 57 60 static char *skipInsignificantChars(char **papszLines, int &i, char *psz); … … 63 66 inline char *trimR(char *psz); 64 67 inline char *skip(const char *psz); 68 static void copy(char *psz, char *pszFrom, int iFrom, char *pszTo, int iTo, char **papszLines); 65 69 static void copy(char *psz, int jFrom, int iFrom, int jTo, int iTo, char **papszLines); 66 static void copy(char *psz, char *pszFrom, int iFrom, char *pszTo, int iTo, char **papszLines); 70 static void copyComment(char *psz, char *pszFrom, int iFrom, char **papszLines, BOOL fStrip); 71 static void copyComment(char *psz, int jFrom, int iFrom, char **papszLines, BOOL fStrip); 67 72 static char *stristr(const char *pszStr, const char *pszSubStr); 68 73 static char *skipBackwards(const char *pszStopAt, const char *pszFrom, int &iLine, char **papszLines); … … 92 97 93 98 DosError(0x3); 94 DosSetPriority(PRTYS_PROCESSTREE, PRTYC_REGULAR, 1, 0);99 /*DosSetPriority(PRTYS_PROCESSTREE, PRTYC_REGULAR, 1, 0);*/ 95 100 96 101 /* get dll name from directory */ … … 264 269 options.lDllRefcode = dbGetDll(options.pszDLLName); 265 270 fprintf(phLog, "DLL: refcode=%d, name=%s\n", options.lDllRefcode, options.pszDLLName); 266 267 /* processing */ 268 if (argv[argi] == NULL || *argv[argi] == '\0') 269 ulRc = processDir(".", &options); 270 else 271 while (argv[argi] != NULL) 272 { 273 ulRc += processDir(argv[argi], &options); 274 argi++; 275 } 276 277 /* create new history rows */ 278 pszErrorDesc = (char*)malloc(1048768); assert(pszErrorDesc != NULL); 279 *pszErrorDesc = '\0'; 280 ulRc2 = dbCreateHistory(pszErrorDesc); 281 if (ulRc2 != 0) 282 { 283 fprintf(phSignal, "-,-: errors which occurred while creating history:\n\t%s\n", pszErrorDesc); 284 ulRc += ulRc2 << 16; 285 } 286 free(pszErrorDesc); 287 288 /* check db integrity */ 289 if (options.fIntegrityAfter) 290 { 271 if (options.lDllRefcode >= 0) 272 { 273 /* processing */ 274 if (argv[argi] == NULL || *argv[argi] == '\0') 275 ulRc = processDir(".", &options); 276 else 277 while (argv[argi] != NULL) 278 { 279 ulRc += processDir(argv[argi], &options); 280 argi++; 281 } 282 283 /* create new history rows */ 291 284 pszErrorDesc = (char*)malloc(1048768); assert(pszErrorDesc != NULL); 292 285 *pszErrorDesc = '\0'; 293 ulRc2 = dbC heckIntegrity(pszErrorDesc);286 ulRc2 = dbCreateHistory(pszErrorDesc); 294 287 if (ulRc2 != 0) 295 288 { 296 fprintf(phSignal, "-,-: integrity errors:\n\t%s\n", pszErrorDesc);289 fprintf(phSignal, "-,-: errors which occurred while creating history:\n\t%s\n", pszErrorDesc); 297 290 ulRc += ulRc2 << 16; 298 291 } 299 292 free(pszErrorDesc); 293 294 /* check db integrity */ 295 if (options.fIntegrityAfter) 296 { 297 pszErrorDesc = (char*)malloc(1048768); assert(pszErrorDesc != NULL); 298 *pszErrorDesc = '\0'; 299 ulRc2 = dbCheckIntegrity(pszErrorDesc); 300 if (ulRc2 != 0) 301 { 302 fprintf(phSignal, "-,-: integrity errors:\n\t%s\n", pszErrorDesc); 303 ulRc += ulRc2 << 16; 304 } 305 free(pszErrorDesc); 306 } 307 } 308 else 309 { /* failed to find dll - concidered nearly fatal. */ 310 fprintf(phSignal, "-,-: failed to find dll (%s)!\n\t%s\n", 311 options.pszDLLName ? options.pszDLLName : "<NULL>"); 312 ulRc++; 300 313 } 301 314 } … … 361 374 " -Old Use old API style. default: disabled\n" 362 375 " -OS2 Ignore 'OS2'-prefix on APIs. default: disabled\n" 363 " -Dll:<dllname> Name of the dll. default: dirname\n"376 " -Dll:<dllname> Name of the dll. default: currentdirname\n" 364 377 " -h:<hostname> Database server hostname. default: localhost\n" 365 378 " -u:<username> Username on the server. default: root\n" … … 541 554 * 2. create line array. 542 555 * (3. simple preprocessing - TODO) 543 * 4. scan thru the line array, looking for APIs. 544 * 4b. when API is found, process it. 556 * 4. process module header. 557 * 5. scan thru the line array, looking for APIs and designnotes. 558 * 5b. when API is found, process it. 559 * 5c. when designnote found, process it. 545 560 */ 546 561 static unsigned long processFile(const char *pszFilename, POPTIONS pOptions) … … 561 576 if (papszLines != NULL) 562 577 { 578 unsigned long ulRc; 563 579 int i = 0; 564 580 565 581 /* 3. - TODO */ 566 582 567 /* 4.*/ 568 while (papszLines[i] != NULL) 569 { 570 if (isFunction(papszLines, i, pOptions)) 583 /* 4. */ 584 ulRc = processModuleHeader(papszLines, i, i, pszFilename, pOptions); 585 cSignals += ulRc >> 16; 586 if (ulRc & 0x0000ffff) 587 { 588 /* 4b. 589 * Remove Design notes. 590 */ 591 pOptions->lSeqFile = 0; 592 if (!dbRemoveDesignNotes(pOptions->lFileRefcode)) 571 593 { 572 unsigned long ulRc; 573 ulRc = processAPI(papszLines, i, i, pszFilename, pOptions); 574 cAPIs += 0x0000ffff & ulRc; 575 cSignals += ulRc >> 16; 594 fprintf(phSignal, "%s: failed to remove design notes. %s\n", 595 pszFilename, dbGetLastErrorDesc()); 596 cSignals++; 576 597 } 577 else 578 i++; 598 599 600 /* 5.*/ 601 while (papszLines[i] != NULL) 602 { 603 if (isFunction(papszLines, i, pOptions)) 604 { 605 ulRc = processAPI(papszLines, i, i, pszFilename, pOptions); 606 cAPIs += 0x0000ffff & ulRc; 607 cSignals += ulRc >> 16; 608 } 609 else 610 { 611 if (isDesignNote(papszLines, i, pOptions)) 612 { 613 ulRc = processDesignNote(papszLines, i, i, pszFilename, pOptions); 614 cSignals += ulRc >> 16; 615 } 616 i++; 617 } 618 } 579 619 } 580 620 … … 598 638 return (unsigned long)((cSignals << 16) | cAPIs); 599 639 } 640 641 642 /** 643 * Processes an module header and other file information. 644 * @returns high word = number of signals. 645 * low word = Success indicator (TRUE / FALSE). 646 * @param papszLines Array of lines in the file. 647 * @param i Index into papszLines. 648 * @param iRet Index into papszLines. Where to resume search. 649 * @param pszFilename Filename. 650 * @param pOptions Pointer to options. lFileRefcode is set on successful return. 651 * @sketch Extract module information if any.... 652 */ 653 static unsigned long processModuleHeader(char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions) 654 { 655 char szDescription[10240]; /* File description buffer. */ 656 char szId[128]; /* CVS Id keyword buffer. */ 657 char * psz, *psz2; 658 const char * pszDBFilename; 659 char * pszLastDateTime; 660 char * pszRevision; 661 char * pszAuthor; 662 signed long lLastAuthor; 663 664 /* 665 * Find the DB filename (skip path!) 666 */ 667 pszDBFilename = strrchr(pszFilename, '\\'); 668 psz = strrchr(pszFilename, '/'); 669 if (psz > pszDBFilename) 670 pszDBFilename = psz; 671 psz = strrchr(pszFilename, ':'); 672 if (psz > pszDBFilename) 673 pszDBFilename = psz; 674 if (pszDBFilename == NULL) 675 pszDBFilename = pszFilename; 676 else 677 pszDBFilename++; 678 679 /* 680 * The module header is either on single comment or two comments. 681 * The first line should be a "$Id" CVS keyword. (by convention). 682 * Then the module description follows. So, we'll try find the $Id 683 * keyword first. 684 */ 685 iRet = i; 686 while (i < iRet + 10 && (psz = strstr(papszLines[i], "$Id"": ")) == NULL) 687 i++; 688 if (psz != NULL) 689 { /* found $Id: */ 690 psz2 = strchr(psz+3, '$'); 691 strncpy(&szId[0], psz, psz2 - psz); 692 szId[psz2 - psz] = '\0'; 693 iRet = i; 694 695 /* parse it! */ 696 psz = strstr(szId+4, ",v "); 697 if (psz == NULL) 698 { 699 fprintf(phSignal, "%s, module header: $Id keyword is incorrect (or the parsing code is broken).\n", pszFilename); 700 return 0x00010000; 701 } 702 pszRevision = trim(psz + 3); 703 psz = strchr(pszRevision, ' '); 704 *psz++ = '\0'; 705 trimR(pszRevision); 706 707 pszLastDateTime = trim(psz); 708 psz = strchr(strchr(pszLastDateTime, ' ') + 1, ' '); 709 *psz++ = '\0'; 710 pszLastDateTime[4] = pszLastDateTime[7] = '-'; 711 trimR(pszLastDateTime); 712 713 pszAuthor = trim(psz); 714 psz = strchr(pszAuthor, ' '); 715 *psz = '\0'; 716 lLastAuthor = dbFindAuthor(pszAuthor, NULL); 717 718 /* 719 * Is there more stuff here, in this comment? 720 * Skip to end of the current comment and copy the contents to szDescription. 721 * if szDescription suddenly contains nothing. 722 */ 723 psz = &szDescription[0]; 724 copyComment(psz, psz2+1, i, papszLines, TRUE); 725 while (*psz == '\n' && *psz == ' ') 726 psz++; 727 if (*psz == '\0') 728 { /* 729 * No description in the first comment. (The one with $Id.) 730 * Is there a comment following the first one? 731 */ 732 while (papszLines[i] != NULL && strstr(papszLines[i++], "*/") == NULL) 733 i = i; 734 while (papszLines[i] != NULL) 735 { 736 psz2 = papszLines[i]; 737 while (*psz2 == ' ') 738 psz2++; 739 if (*psz2 != '\0') 740 break; 741 i++; 742 } 743 if (psz2 != NULL && strncmp(psz2, "/*", 2) == 0) 744 { 745 psz = &szDescription[0]; 746 copyComment(psz, psz2+1, i, papszLines, TRUE); 747 while (*psz == '\n' && *psz == ' ') 748 psz++; 749 if (psz == '\0') 750 szDescription[0] = '\0'; 751 752 /* Skip to line after comment end. */ 753 while (papszLines[i] != NULL && strstr(papszLines[i++], "*/") == NULL) 754 i = i; 755 } 756 } 757 else 758 { 759 /* Skip to line after comment end. */ 760 while (papszLines[i] != NULL && strstr(papszLines[i++], "*/") == NULL) 761 i = i; 762 } 763 iRet = i; 764 765 /* 766 * Information is collected. 767 * Insert or update the database. 768 */ 769 if (dbInsertUpdateFile((unsigned short)pOptions->lDllRefcode, pszDBFilename, 770 &szDescription[0], pszLastDateTime, lLastAuthor, pszRevision)) 771 { 772 /* 773 * Get file refcode. 774 */ 775 pOptions->lFileRefcode = dbFindFile(pOptions->lDllRefcode, pszDBFilename); 776 if (pOptions->lFileRefcode <= 0) 777 { 778 fprintf(phSignal, "%s, module header: failed to find file in DB. %s\n", 779 pszDBFilename, dbGetLastErrorDesc()); 780 return 0x00010000; 781 } 782 } 783 else 784 { 785 fprintf(phSignal, "%s, module header: failed to insert/update file. %s\n", 786 pszDBFilename, dbGetLastErrorDesc()); 787 return 0x00010000; 788 } 789 } 790 else 791 { 792 fprintf(phSignal, "%s, module header: $Id keyword is missing.\n", pszFilename); 793 return 0x00010000; 794 } 795 796 return TRUE; 797 } 798 799 800 /** 801 * Processes an API function. 802 * @returns high word = number of signals 803 * low word = Success indicator (TRUE/FALSE). 804 * @param papszLines Array of lines in the file. 805 * @param i Index into papszLines. 806 * @param iRet Index into papszLines. Where to resume search. 807 * @param pszFilename Filename used in the signal log. 808 * @param pOptions Pointer to options. 809 */ 810 static unsigned long processDesignNote(char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions) 811 { 812 unsigned long ulRc; 813 char szBuffer[0x10000]; 814 char * psz; 815 816 /* 817 * Find and parse the @designnote tag/keyword. 818 * syntax: @designnote [seqnbr] <title> 819 * <text> 820 * 821 */ 822 psz = stristr(papszLines[i], "@designnote "); 823 if (psz != NULL) 824 { 825 signed long lSeqNbr; 826 827 psz = findEndOfWord(psz+1)+1; 828 lSeqNbr = atol(psz); 829 if (lSeqNbr != 0) 830 psz = findEndOfWord(psz); 831 psz = trim(psz); 832 if (psz != NULL && strstr(psz, "*/") != NULL) 833 { 834 szBuffer[0] = '\0'; 835 *strstr(psz, "*/") = '\0'; 836 } 837 else 838 copyComment(&szBuffer[0], 0, i+1, papszLines, TRUE); 839 840 /* Update database */ 841 if (!dbAddDesignNote(pOptions->lDllRefcode, pOptions->lFileRefcode, psz, &szBuffer[0], lSeqNbr, pOptions->lSeqFile++)) 842 { 843 ulRc = 0x00010000; 844 fprintf(phSignal, "%s(%d): Failed to add designnote. %s\n", dbGetLastErrorDesc()); 845 } 846 847 /* Skip to line after comment end. */ 848 while (papszLines[i] != NULL && strstr(papszLines[i++], "*/") == NULL) 849 i = i; 850 iRet = i; 851 } 852 else 853 { 854 fprintf(phSignal, "%s(%d): internal error @designnote \n", pszFilename, i); 855 ulRc = 0x00010000; 856 } 857 858 return ulRc; 859 } 860 861 600 862 601 863 … … 1808 2070 1809 2071 2072 /** 2073 * Checks if there may be a design note starting at the current line. 2074 * @returns TRUE if design note found, else FALSE. 2075 * @param papszLines Array of lines in the file. 2076 * @param i Index into papszLines. 2077 * @param pOptions Pointer to options. 2078 */ 2079 static BOOL isDesignNote(char **papszLines, int i, POPTIONS pOptions) 2080 { 2081 char *psz = papszLines[i]; 2082 2083 if (psz == NULL) 2084 return FALSE; 2085 2086 // look for /**@designnote " 2087 while (*psz == ' ') 2088 psz++; 2089 if (strncmp(psz, "/**", 3) == 0) 2090 { 2091 psz++; 2092 while (*psz == '*' || *psz == ' ') 2093 psz++; 2094 return strnicmp(psz, "@designnote ", 12) == 0; 2095 } 2096 pOptions = pOptions; 2097 return FALSE; 2098 } 2099 2100 2101 1810 2102 1811 2103 /** … … 2237 2529 2238 2530 2531 /* copyComment: Wrapper for the other copyComment function. 2532 * 2533 */ 2534 static void copyComment(char *psz, char *pszFrom, int iFrom, char **papszLines, BOOL fStrip) 2535 { 2536 copyComment(psz, pszFrom - papszLines[iFrom], iFrom, papszLines, fStrip); 2537 } 2538 2539 2540 2541 2542 /** 2543 * Copies a set of lines to a buffer (psz) stopping at the first end comment. 2544 * (If a start comment occurs it is concidered an error.) 2545 * Stars begining lines are removed. 2546 * @param psz Target buffer. 2547 * @param jFrom Starting position, index into line iFrom. 2548 * @param iFrom Starting position, index into papszLines. 2549 * @param papszLines Array of lines. 2550 * @param fStrip Strip blank lines at start and end + LICENCE notice (at end). 2551 * @status completely implemented. 2552 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 2553 */ 2554 static void copyComment(char *psz, int jFrom, int iFrom, char **papszLines, BOOL fStrip) 2555 { 2556 char * pszStartBuffer = psz; /* Start of the target buffer. */ 2557 char * pszStart = psz; /* Start of current line. */ 2558 int fFirst = TRUE; /* True while we're still processing the start of the line. */ 2559 int i, j; /* Indexes into papszLines. */ 2560 2561 i = iFrom; 2562 j = jFrom; 2563 while (papszLines[i] != NULL && !(papszLines[i][j] == '*' && papszLines[i][j+1] == '/')) 2564 { 2565 if (papszLines[i][j] != '\0') 2566 { 2567 /* Skip or copy the char ? */ 2568 if (fFirst && papszLines[i][j] == ' ') 2569 j++; 2570 else if (fFirst && papszLines[i][j] == '*') 2571 j += papszLines[i][j+1] == ' ' ? (fFirst = FALSE) + 2 : 1; /* bad habbit...*/ 2572 else 2573 { /* Copy it */ 2574 *psz++ = papszLines[i][j++]; 2575 fFirst = FALSE; 2576 } 2577 } 2578 else 2579 { /* End of line: 2580 * Check if empty line. If so truncate it. 2581 * Add new line char if not empty first line... 2582 */ 2583 j = 0; /* use this as an index from line start on the copied line. */ 2584 while (pszStart + j < psz && pszStart[j] == ' ') 2585 j++; 2586 if (pszStart + j == psz) 2587 psz = pszStart; 2588 if (psz > pszStartBuffer || !fStrip) 2589 *psz++ = '\n'; 2590 2591 /* next */ 2592 i++; 2593 j = 0; 2594 fFirst = TRUE; 2595 pszStart = psz; 2596 } 2597 } 2598 *psz = '\0'; 2599 2600 /* 2601 * Strip end + license. 2602 */ 2603 if (fStrip) 2604 { 2605 while (psz >= pszStartBuffer && (*psz == ' ' || *psz == '\n' || *psz == '\0')) 2606 *psz-- = '\0'; 2607 2608 if (psz - 20 > pszStartBuffer && strstr(psz - 20, "LICENSE.TXT") != NULL) 2609 { 2610 while (psz >= pszStartBuffer && *psz != '\n') 2611 *psz-- = '\0'; 2612 } 2613 2614 while (psz >= pszStartBuffer && (*psz == ' ' || *psz == '\n' || *psz == '\0')) 2615 *psz-- = '\0'; 2616 } 2617 } 2618 2619 2239 2620 /** 2240 2621 * Upcases a char.
Note:
See TracChangeset
for help on using the changeset viewer.