Changeset 6663 for trunk/tools/database


Ignore:
Timestamp:
Sep 6, 2001, 5:07:32 AM (24 years ago)
Author:
bird
Message:

Design note improovments.

Location:
trunk/tools/database
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/database/CreateTables.sql

    r3916 r6663  
    1 -- $Id: CreateTables.sql,v 1.17 2000-08-02 01:22:34 bird Exp $
     1-- $Id: CreateTables.sql,v 1.18 2001-09-06 03:07:31 bird Exp $
    22--
    33-- Create all tables.
     
    103103
    104104--
    105 -- This table holds design notes (per dll).
     105-- This table holds design notes (per module).
     106--
     107-- seqnbrnote is a unique number used to order the
     108--            sections within a design note.
     109-- level      is the nesting level of the section.
     110--            0 is the top section in the note.
    106111--
    107112CREATE TABLE designnote (
    108     refcode     INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
     113    refcode     INTEGER NOT NULL AUTO_INCREMENT,
    109114    dll         TINYINT NOT NULL,
    110115    file        INTEGER NOT NULL,
    111     seqnbrfile  SMALLINT NOT NULL,
     116    line        INTEGER  NOT NULL DEFAULT -1,
     117    seqnbrnote  SMALLINT NOT NULL,
     118    level       TINYINT NOT NULL,
    112119    seqnbr      INTEGER NOT NULL,
    113     line        INTEGER  NOT NULL DEFAULT -1,
    114     title       TEXT,
     120    name        TEXT,
    115121    note        TEXT    NOT NULL,
    116     UNIQUE      u1(refcode),
    117     INDEX       u2(file, seqnbrfile, seqnbr, dll)
     122    PRIMARY KEY(refcode, seqnbrnote),
     123    UNIQUE      u1(refcode, seqnbrnote),
     124    UNIQUE      u2(refcode, seqnbrnote, level),
     125    UNIQUE      u3(dll, seqnbr, level, seqnbrnote, refcode),
     126    INDEX       i1(file, refcode)
    118127);
    119128
  • trunk/tools/database/StateUpd.cpp

    r6660 r6663  
    1 /* $Id: StateUpd.cpp,v 1.35 2001-09-05 23:14:12 bird Exp $
     1/* $Id: StateUpd.cpp,v 1.36 2001-09-06 03:07:31 bird Exp $
    22 *
    33 * StateUpd - Scans source files for API functions and imports data on them.
     
    6565inline char *trim(char *psz);
    6666inline char *trimR(char *psz);
     67static char *trimHtml(char *psz);
    6768inline char *skip(const char *psz);
    6869static void  copy(char *psz, char *pszFrom, int iFrom, char *pszTo, int iTo, char **papszLines);
     
    827828    unsigned long   ulRc = 0;
    828829    char            szBuffer[0x10000];
    829     char *          psz;
     830    char *          pszTitle;
    830831
    831832    /*
     
    835836     *
    836837     */
    837     psz = stristr(papszLines[i], "@design");
    838     if (psz != NULL && (psz[7] == '\0' || psz[7] == ' '))
    839     {
     838    pszTitle = stristr(papszLines[i], "@design");
     839    if (pszTitle != NULL && (pszTitle[7] == '\0' || pszTitle[7] == ' '))
     840    {
     841        char *          psz;
    840842        signed long     lSeqNbr;
    841 
    842         psz = findEndOfWord(psz+1)+1;
    843         lSeqNbr = atol(psz);
     843        signed long     lSeqNbrNote;
     844        signed long     lRefCode;
     845        long            alSeqNbrs[1024];
     846        long            lLevel;
     847
     848        memset(alSeqNbrs, 0, sizeof(alSeqNbrs));
     849
     850        /*
     851         * Get title and seqnbr. Then copy the entire stuff to the buffer.
     852         */
     853        pszTitle = findEndOfWord(pszTitle+1)+1;
     854        lSeqNbr = atol(pszTitle);
    844855        if (lSeqNbr != 0)
    845             psz = findEndOfWord(psz);
    846         psz = trim(psz);
    847         if (psz != NULL && strstr(psz, "*/") != NULL)
     856            pszTitle = findEndOfWord(pszTitle);
     857        pszTitle = trim(pszTitle);
     858        if (pszTitle != NULL && strstr(pszTitle, "*/") != NULL)
    848859        {
    849860            szBuffer[0] = '\0';
    850             *strstr(psz, "*/") = '\0';
     861            *strstr(pszTitle, "*/") = '\0';
    851862        }
    852863        else
    853864            copyComment(&szBuffer[0], 0, i+1, papszLines, TRUE, TRUE);
    854 
    855         /* Update database */
    856         if (!dbAddDesignNote(pOptions->lDllRefcode, pOptions->lFileRefcode, psz, &szBuffer[0], lSeqNbr, pOptions->lSeqFile++, i + 1))
    857         {
    858             ulRc = 0x00010000;
    859             fprintf(phSignal, "%s(%d): Failed to add designnote. %s\n", dbGetLastErrorDesc());
    860         }
     865        pszTitle = trim(pszTitle);
     866
     867        /*
     868         * Add design note section by section.
     869         */
     870        psz = &szBuffer[0];
     871        lLevel = 0;
     872        lSeqNbrNote = 0;
     873        do
     874        {
     875            char *  pszEnd;
     876            long    lNextLevel = -1;
     877
     878            /*
     879             * Parse out title and section/squence number if not lLevel 0.
     880             * (psz = "@sub...")
     881             */
     882            if (lLevel > 0)
     883            {
     884                pszTitle = findEndOfWord(psz+1);
     885                lSeqNbr = atol(pszTitle);
     886                if (lSeqNbr != 0)
     887                {
     888                    pszTitle = findEndOfWord(pszTitle);
     889                    alSeqNbrs[lLevel] = lSeqNbr;
     890                }
     891                else
     892                    lSeqNbr = ++alSeqNbrs[lLevel];
     893
     894                pszTitle = trim(pszTitle);
     895                if (pszTitle != NULL && (psz = strstr(pszTitle, "\n")) != NULL)
     896                    *psz++ = '\0';
     897                else
     898                    psz = "";
     899            }
     900
     901
     902            /*
     903             * Find end of this section.
     904             * (pszEnd will point at @sub or '\0'.)
     905             */
     906            pszEnd = psz;
     907            do
     908            {
     909                while (*pszEnd == '\n' || *pszEnd == ' ' || *pszEnd == '\t' || *pszEnd == '\r')
     910                    ++pszEnd;
     911                if (!strnicmp(pszEnd, "@sub", 4) && !strnicmp(findEndOfWord(pszEnd + 1) - 7, "section", 7))
     912                {
     913                    lNextLevel = 1;
     914                    while (!strnicmp(pszEnd + 1 + lNextLevel * 3, "sub", 3))
     915                        lNextLevel++;
     916                    break;
     917                }
     918            } while ((pszEnd = strchr(pszEnd, '\n')) != NULL);
     919            if (!pszEnd)
     920                pszEnd = psz + strlen(psz);
     921            else
     922                pszEnd[-1] = '\0';
     923
     924            /*
     925             * Strip end and start of section.
     926             */
     927            psz = trimHtml(psz);
     928            pszTitle = trimHtml(pszTitle);
     929
     930            /*
     931             * Add the note.
     932             */
     933            if (!dbAddDesignNote(pOptions->lDllRefcode, pOptions->lFileRefcode,
     934                                 pszTitle, psz,
     935                                 lLevel, lSeqNbr, lSeqNbrNote++, i + 1, lLevel > 0, &lRefCode))
     936            {
     937                ulRc += 0x00010000;
     938                fprintf(phSignal, "%s(%d): Failed to add designnote. %s\n", pszFilename, i, dbGetLastErrorDesc());
     939            }
     940
     941            /*
     942             * Next.
     943             */
     944            psz = pszEnd;
     945            if (lLevel < lNextLevel)
     946                memset(&alSeqNbrs[lLevel+1], 0, (lNextLevel - lLevel) * sizeof(alSeqNbrs[0]));
     947            lLevel = lNextLevel;
     948
     949        } while (*psz);
     950
    861951
    862952        /* Skip to line after comment end. */
     
    24572547}
    24582548
     2549/**
     2550 * Trims string. <BR>, <P>, '@', '\t', '\n' and '\t' is trimmed from both ends of the string.
     2551 * @returns Pointer to string.
     2552 * @param   psz     String to trim.
     2553 */
     2554char *trimHtml(char *psz)
     2555{
     2556    if (!psz)
     2557        return NULL;
     2558
     2559    char *pszEnd = psz + strlen(psz) - 1;
     2560
     2561    while (pszEnd > psz)
     2562    {
     2563        if (*pszEnd == '@' || *pszEnd == ' ' || *pszEnd == '\t' || *pszEnd == '\n' || *pszEnd == '\r')
     2564            pszEnd--;
     2565        else if (!strnicmp(pszEnd - 3, "<BR>", 4))
     2566            pszEnd -= 4;
     2567        else if (!strnicmp(pszEnd - 2, "<P>", 3))
     2568            pszEnd -= 3;
     2569        else
     2570            break;
     2571    }
     2572    *++pszEnd = '\0';
     2573
     2574    while (psz < pszEnd)
     2575    {
     2576        if (*psz == '@' || *psz == ' ' || *psz == '\t' || *psz == '\n' || *psz == '\r')
     2577            psz++;
     2578        else if (!strnicmp(psz, "<BR>", 4))
     2579            psz += 4;
     2580        else if (!strnicmp(psz, "<P>", 3))
     2581            psz += 3;
     2582        else
     2583            break;
     2584    }
     2585
     2586    return psz;
     2587}
     2588
    24592589
    24602590/**
  • trunk/tools/database/db.cpp

    r6651 r6663  
    1 /* $Id: db.cpp,v 1.24 2001-09-05 13:59:03 bird Exp $ *
     1/* $Id: db.cpp,v 1.25 2001-09-06 03:07:32 bird Exp $ *
    22 *
    33 * DB - contains all database routines.
     
    11721172 * @param       pszTitle        Design note title.
    11731173 * @param       pszText         Design note text.
     1174 * @param       lLevel          Level of the note section. 0 is the design note it self.
    11741175 * @param       lSeqNbr         Sequence number (in dll). If 0 the use next available number.
    1175  * @param       lSeqNbrFile     Sequence number in file.
     1176 * @param       lSeqNbrNote     Sequence number in note.
    11761177 * @param       lLine           Line number (1 - based!).
     1178 * @param       fSubSection     TRUE if subsection FALSE if design note.
     1179 *                              if TRUE *plRefCode will hold the reference id of the note.
     1180 *                              if FALSE *plRefCode will receive the reference id of the note being created.
     1181 * @param       plRefCode       Pointer to reference id of the design note. see fSubSection for more info.
    11771182 */
    11781183BOOL            _System dbAddDesignNote(signed long lDll,
     
    11801185                                        const char *pszTitle,
    11811186                                        const char *pszText,
     1187                                        signed long lLevel,
    11821188                                        signed long lSeqNbr,
    1183                                         signed long lSeqNbrFile,
    1184                                         signed long lLine)
    1185 {
     1189                                        signed long lSeqNbrNote,
     1190                                        signed long lLine,
     1191                                        BOOL        fSubSection,
     1192                                        signed long *plRefCode)
     1193{
     1194    int         rc;
    11861195    char        szQuery[0x10200];
    11871196    MYSQL_RES * pres;
     
    11891198
    11901199    assert(lDll >= 0 && lFile >= 0);
    1191     assert(lSeqNbrFile >= 0);
     1200    assert(lSeqNbrNote >= 0);
    11921201
    11931202    /*
    11941203     * If no lSqlNbr the make one.
    11951204     */
    1196     if (lSeqNbr == 0)
    1197     {
    1198         sprintf(&szQuery[0], "SELECT MAX(seqnbr) + 1 FROM designnote WHERE dll = %ld", lDll);
     1205    if (lSeqNbr == 0 && !fSubSection)
     1206    {
     1207        sprintf(&szQuery[0], "SELECT MAX(seqnbr) + 1 FROM designnote WHERE dll = %ld AND level = 0", lDll);
    11991208        if (mysql_query(pmysql, &szQuery[0]) >= 0)
    12001209        {
     
    12031212            {
    12041213                MYSQL_ROW parow = mysql_fetch_row(pres);
    1205                 if (parow != NULL)
     1214                if (parow != NULL && parow[0])
    12061215                    lSeqNbr = getvalue(0, parow);
    12071216                else
     
    12171226
    12181227    /*
    1219      * Create update query.
     1228     * Create insert query.
    12201229     */
    1221     sprintf(&szQuery[0], "INSERT INTO designnote(dll, file, seqnbrfile, seqnbr, line, title, note) "
    1222                          "VALUES (%ld, %ld, %ld, %ld, %ld, ",
    1223             lDll, lFile, lSeqNbrFile, lSeqNbr, lLine);
     1230    if (!fSubSection)
     1231        sprintf(&szQuery[0], "INSERT INTO designnote(dll, file, level, seqnbrnote, seqnbr, line, name, note) "
     1232                             "VALUES (%ld, %ld, %ld, %ld, %ld, %ld, ",
     1233                lDll, lFile, lLevel, lSeqNbrNote, lSeqNbr, lLine);
     1234    else
     1235        sprintf(&szQuery[0], "INSERT INTO designnote(refcode, dll, file, level, seqnbrnote, seqnbr, line, name, note) "
     1236                             "VALUES (%ld, %ld, %ld, %ld, %ld, %ld, %ld, ",
     1237                *plRefCode, lDll, lFile, lLevel, lSeqNbrNote, lSeqNbr, lLine);
     1238
    12241239    if (pszTitle != NULL && *pszTitle != '\0')
    12251240        sqlstrcat(&szQuery[0], NULL, pszTitle);
     
    12281243    sqlstrcat(&szQuery[0], ", ", pszText == NULL ? "" : pszText, ")");
    12291244
    1230     return mysql_query(pmysql, &szQuery[0]) >= 0;
     1245    if (mysql_query(pmysql, &szQuery[0]) >= 0)
     1246    {
     1247        if (!fSubSection)
     1248            *plRefCode = mysql_insert_id(pmysql);
     1249        return TRUE;
     1250    }
     1251    return FALSE;
    12311252}
    12321253
  • trunk/tools/database/db.h

    r3917 r6663  
    1 /* $Id: db.h,v 1.13 2000-08-02 02:18:05 bird Exp $ */
     1/* $Id: db.h,v 1.14 2001-09-06 03:07:32 bird Exp $ */
    22/*
    33 * DB - contains all database routines
     
    140140                                             const char *pszTitle,
    141141                                             const char *pszText,
     142                                             signed long lLevel,
    142143                                             signed long lSeqNbr,
    143                                              signed long lSeqNbrFile,
    144                                              signed long lLine);
     144                                             signed long lSeqNbrNote,
     145                                             signed long lLine,
     146                                             BOOL        fSubSection,
     147                                             signed long *plRefCode);
    145148    unsigned long    _System dbCreateHistory(char *pszError);
    146149    unsigned long    _System dbCheckIntegrity(char *pszError);
Note: See TracChangeset for help on using the changeset viewer.