Changeset 2818 for trunk/tools/database


Ignore:
Timestamp:
Feb 18, 2000, 1:42:08 PM (26 years ago)
Author:
bird
Message:

Read more of the function header into the database.
Stateupd is changed to do this and the database is expanded with new fields.
The sample is partly updated.

Location:
trunk/tools/database
Files:
7 edited

Legend:

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

    r2789 r2818  
    1 -- $Id: CreateTables.sql,v 1.6 2000-02-15 13:31:06 bird Exp $
     1-- $Id: CreateTables.sql,v 1.7 2000-02-18 12:42:05 bird Exp $
    22--
    33-- Create all tables.
     
    3737    return   VARCHAR(64),
    3838    updated  TINYINT  NOT NULL DEFAULT 0,
     39    description TEXT,
     40    remark      TEXT,
     41    returndesc  TEXT,
     42    sketch      TEXT,
     43    equiv       TEXT,
     44    time        TEXT,
    3945    UNIQUE i1(refcode, aliasfn),
    4046    UNIQUE i1a(dll, aliasfn, refcode),
     
    112118    name     VARCHAR(64) NOT NULL,
    113119    type     VARCHAR(64) NOT NULL,
    114     description VARCHAR(128),
    115     INDEX  i1(function, name(10)),
     120    description TEXT,
     121    INDEX  i1(function, name),
    116122    UNIQUE u1(function, name)
    117123);
  • trunk/tools/database/StateUpd.cpp

    r2791 r2818  
    1 /* $Id: StateUpd.cpp,v 1.18 2000-02-15 13:37:52 bird Exp $
     1/* $Id: StateUpd.cpp,v 1.19 2000-02-18 12:42:06 bird Exp $
    22 *
    33 * StateUpd - Scans source files for API functions and imports data on them.
     
    1515#define INCL_DOSPROCESS
    1616#include <os2.h>
     17#include <malloc.h>
    1718#include <stdio.h>
    1819#include <string.h>
    19 #include <malloc.h>
     20#include <stdlib.h>
    2021#include <assert.h>
    2122
     
    3031static FILE  *phLog = NULL;
    3132static FILE  *phSignal = NULL;
     33
     34static const char *pszCommonKeywords[] =
     35{
     36    "* Author",     "* Status",     "* Remark",     "* Result",
     37    "* Variable",   "* Parameters", "* Purpose",    NULL
     38};
    3239
    3340
     
    4451static unsigned long analyseFnDcl(PFNDESC pFnDesc, char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions);
    4552static unsigned long analyseFnDcl2(PFNDESC pFnDesc, char **papszLines, int i, int &iRet, const char *pszFilename, POPTIONS pOptions);
     53static char *SDSCopyTextUntilNextTag(char *pszTarget, BOOL fHTML, int iStart, int iEnd, char **papszLines, const char *pszStart = NULL);
     54static char *CommonCopyTextUntilNextTag(char *pszTarget, BOOL fHTML, int iStart, int iEnd, char **papszLines, const char *pszStart = NULL);
    4655static BOOL  isFunction(char **papszLines, int i, POPTIONS pOptions);
    4756static long _System dbNotUpdatedCallBack(const char *pszValue, const char *pszFieldName, void *pvUser);
     
    4958static char *readFileIntoMemory(const char *pszFilename);
    5059static char **createLineArray(char *pszFile);
    51 static char *findEndOfWord(char *psz);
    52 static char *findStartOfWord(char *psz, const char *pszStart);
    53 static char *trim(char *psz);
    54 static void copy(char *psz, int jFrom, int iFrom, int jTo, int iTo, char **papszLines);
    55 static void copy(char *psz, char *pszFrom, int iFrom, char *pszTo, int iTo, char **papszLines);
     60static char *findEndOfWord(const char *psz);
     61static char *findStartOfWord(const char *psz, const char *pszStart);
     62inline char *trim(char *psz);
     63inline char *trimR(char *psz);
     64inline char *skip(const char *psz);
     65static void  copy(char *psz, int jFrom, int iFrom, int jTo, int iTo, char **papszLines);
     66static void  copy(char *psz, char *pszFrom, int iFrom, char *pszTo, int iTo, char **papszLines);
    5667static char *stristr(const char *pszStr, const char *pszSubStr);
    5768static char *skipBackwards(const char *pszStopAt, const char *pszFrom, int &iLine, char **papszLines);
     69static int   findStrLine(const char *psz, int iStart, int iEnd, char **papszLines);
    5870
    5971
     
    637649        fprintf(phLog, "  cParams: %2d\n", FnDesc.cParams);
    638650        for (j = 0; j < FnDesc.cParams; j++)
    639             fprintf(phLog, "  Param %2d: type '%s' %*s name '%s'\n", j, FnDesc.apszParamType[j],
    640                     (int)(15 - strlen(FnDesc.apszParamType[j])), "", FnDesc.apszParamName[j]);
     651            fprintf(phLog, "  Param %2d: type '%s' %*s name '%s' description: %s\n", j, FnDesc.apszParamType[j],
     652                    max((int)(15 - strlen(FnDesc.apszParamType[j])), 0), "", FnDesc.apszParamName[j],
     653                    FnDesc.apszParamDesc[j] != NULL ?  FnDesc.apszParamDesc[j] : "(null)");
    641654        fprintf(phLog, "  Status:   %ld - '%s'\n", FnDesc.lStatus, FnDesc.pszStatus != NULL ? FnDesc.pszStatus : "<missing>");
    642655        fprintf(phLog, "  cAuthors: %2d\n", FnDesc.cAuthors);
    643656        for (j = 0; j < FnDesc.cAuthors; j++)
    644657            fprintf(phLog, "  Author %d: '%s'  (refcode=%ld)\n", j, FnDesc.apszAuthor[j], FnDesc.alAuthorRefCode[j]);
     658
     659        fprintf(phLog, "  Description: %s\n", FnDesc.pszDescription != NULL ? FnDesc.pszDescription : "(null)");
     660        fprintf(phLog, "  Remark:      %s\n", FnDesc.pszRemark != NULL ? FnDesc.pszRemark : "(null)");
     661        fprintf(phLog, "  Return Desc: %s\n", FnDesc.pszReturnDesc != NULL ? FnDesc.pszReturnDesc : "(null)");
     662        fprintf(phLog, "  Sketch:      %s\n", FnDesc.pszSketch != NULL ? FnDesc.pszSketch : "(null)");
     663        fprintf(phLog, "  Equiv:       %s\n", FnDesc.pszEquiv != NULL ? FnDesc.pszEquiv : "(null)");
     664        fprintf(phLog, "  Time:        %s\n", FnDesc.pszTime != NULL ? FnDesc.pszTime : "(null)");
     665        fprintf(phLog, "------------\n");
    645666
    646667        /* 4.*/
     
    10681089 * @param     pszFilename  Filename used in the signal log.
    10691090 * @param     pOptions     Pointer to options.
    1070  * @sketch    1. Search backwards (start at i-1) for a comment or code.
     1091 * @sketch    0. initiate pFnDesc struct
     1092 *            1. Search backwards (start at i-1) for a comment or code.
    10711093 *            2. If comment: (else fail)
    10721094 *                2a. find start and end of comment.
     
    10881110    int   fSDS = 0;
    10891111    char *psz, *pszB;
    1090     char *pszAuthor = NULL;
     1112    char *pszAuthors = NULL;
    10911113    unsigned long ulRc = 0x00000001;
    10921114
     
    10961118        return 0;
    10971119
    1098     /* 1. + 2a.*/
     1120    /*
     1121     * 0. initiate pFnDesc struct
     1122     */
     1123    for (j = 0; j < pFnDesc->cParams; j++)
     1124        pFnDesc->apszParamDesc[j] = NULL;
     1125    pFnDesc->cAuthors = 0;
     1126    pFnDesc->pszDescription = pFnDesc->pszRemark = pFnDesc->pszReturnDesc = NULL;
     1127    pFnDesc->pszSketch = pFnDesc->pszEquiv = pFnDesc->pszTime = pFnDesc->pszStatus = NULL;
     1128    pFnDesc->lStatus = 99; /* unknown */
     1129
     1130    /*
     1131     * 1. + 2a.
     1132     */
    10991133    iEnd = i-1; /* find end */
    11001134    j = strlen(papszLines[iEnd]);
     
    11341168    jStart = j;
    11351169
    1136     /* 2b.*/
     1170    /*
     1171     * 2b.
     1172     */
    11371173    if (strncmp(&papszLines[iStart][jStart], "/**", 3) != 0) /* checks that there are more than one star at start of comment */
    11381174        return 0;
    11391175
    1140     iName = iStart; /* Odin32 common */
    1141     while (iName <= iEnd &&
    1142            stristr(papszLines[iName], "* Name") == NULL)
    1143         iName++;
    1144     iStatus = iStart;
    1145     while (iStatus <= iEnd &&
    1146            stristr(papszLines[iStatus], "* Status") == NULL)
    1147         iStatus++;
    1148     iAuthor = iStart;
    1149     while (iAuthor <= iEnd &&
    1150            stristr(papszLines[iAuthor], "* Author") == NULL)
    1151         iAuthor++;
    1152 
    1153     if (!(iName <= iEnd || iStatus <= iEnd || iAuthor <= iEnd)) /* if not found try SDS */
    1154     {
    1155         iStatus = iStart;
    1156         while (iStatus <= iEnd &&
    1157                stristr(papszLines[iStatus], "@status") == NULL)
    1158             iStatus++;
    1159         iAuthor = iStart;
    1160         while (iAuthor <= iEnd &&
    1161                stristr(papszLines[iAuthor], "@author") == NULL)
    1162             iAuthor++;
     1176    /* Odin32 common? */
     1177    iName   = findStrLine("* Name", iStart, iEnd, papszLines);
     1178    iStatus = findStrLine("* Status", iStart, iEnd, papszLines);
     1179    iAuthor = findStrLine("* Author", iStart, iEnd, papszLines);
     1180
     1181    if (!(iName <= iEnd || iStatus <= iEnd || iAuthor <= iEnd))
     1182    {
     1183        /* SDS ? */
     1184        iStatus = findStrLine("@status", iStart, iEnd, papszLines);
     1185        iAuthor = findStrLine("@author", iStart, iEnd, papszLines);
     1186        iName   = iEnd + 1;
     1187
    11631188        if (!(iStatus <= iEnd || iAuthor <= iEnd))
    11641189            return 0;
    1165         fSDS = 1;
    1166     }
    1167 
    1168     /* 2c.*/
    1169     if (iName <= iEnd && strstr(papszLines[iName], pFnDesc->pszName) == NULL)
    1170         fprintf(phLog, "Warning: a matching function name is not found in the name Field\n");
     1190        fSDS = TRUE;
     1191    }
     1192    else
     1193    {
     1194        /* 2c.*/
     1195        if (iName <= iEnd && strstr(papszLines[iName], pFnDesc->pszName) == NULL)
     1196            fprintf(phLog, "Warning: a matching function name is not found in the name Field\n");
     1197    }
    11711198
    11721199    /* 2d.*/
    11731200    pszB = &pFnDesc->szFnHdrBuffer[0];
    11741201    if (!fSDS)
    1175     {   /* Odin32 common */
    1176         if (iStatus <= iEnd) /* Status */
    1177         {
    1178             psz = stristr(papszLines[iStatus], "* Status") + sizeof("* Status") - 1;
    1179             while (*psz != '\0' && (*psz == ' ' || *psz == ':'))
    1180                 psz++;
    1181             strcpy(pszB, psz);
    1182             trim(pszB);
    1183             if (*pszB != '\0' && pszB[strlen(pszB)-1] == '*') /* just in case some have an right hand '*' column */
    1184             {
    1185                 pszB[strlen(pszB)-1] = '\0';
    1186                 trim(pszB);
    1187             }
    1188             pFnDesc->pszStatus = pszB;
    1189             pszB += strlen(pszB) + 1;
    1190         }
    1191 
    1192         if (iAuthor <= iEnd) /* Author(s) */
    1193         {
    1194             pszAuthor = pszB;
    1195             psz = stristr(papszLines[iAuthor], "* Author") + sizeof("* Author") - 1;
    1196             do
    1197             {
    1198                 while (*psz != '\0' && (*psz == ' ' || *psz == ':'))
    1199                     psz++;
    1200                 strcpy(pszB, psz);
    1201                 trim(pszB);
    1202                 if (*pszB != '\0' && pszB[strlen(pszB)-1] == '*') /* just in case some have an right hand '*' column */
     1202    {
     1203        /*
     1204         * Odin32 common styled header
     1205         */
     1206
     1207        /* Author(s) */
     1208        pszAuthors              = CommonCopyTextUntilNextTag(pszB, FALSE, iAuthor, iEnd, papszLines);
     1209        pszB += strlen(pszB) + 1;
     1210
     1211        /* Status */
     1212        pFnDesc->pszStatus      = CommonCopyTextUntilNextTag(pszB, FALSE, iStatus, iEnd, papszLines);
     1213        pszB += strlen(pszB) + 1;
     1214
     1215        /* Remark */
     1216        i = findStrLine("* Remark", iStart, iEnd, papszLines);
     1217        pFnDesc->pszRemark      = CommonCopyTextUntilNextTag(pszB, TRUE, i, iEnd, papszLines);
     1218        pszB += strlen(pszB) + 1;
     1219
     1220        /* Description */
     1221        i = findStrLine("* Purpose", iStart, iEnd, papszLines);
     1222        pFnDesc->pszDescription = CommonCopyTextUntilNextTag(pszB, TRUE, i, iEnd, papszLines);
     1223        pszB += strlen(pszB) + 1;
     1224
     1225        /* Return(result) description */
     1226        i = findStrLine("* Result", iStart, iEnd, papszLines);
     1227        pFnDesc->pszReturnDesc  = CommonCopyTextUntilNextTag(pszB, TRUE, i, iEnd, papszLines);
     1228        pszB += strlen(pszB) + 1;
     1229
     1230        /* FIXME parameters */
     1231
     1232    }
     1233    else
     1234    {
     1235        /*
     1236         * SDS styled header
     1237         */
     1238
     1239        /* author */
     1240        pszAuthors              = SDSCopyTextUntilNextTag(pszB, FALSE, iAuthor, iEnd, papszLines);
     1241        pszB += strlen(pszB) + 1;
     1242
     1243        /* status */
     1244        pFnDesc->pszReturnDesc  = SDSCopyTextUntilNextTag(pszB, FALSE, iStatus, iEnd, papszLines);
     1245        pszB += strlen(pszB) + 1;
     1246
     1247        /* remark */
     1248        i = findStrLine("@remark", iStart, iEnd, papszLines);
     1249        pFnDesc->pszRemark      = SDSCopyTextUntilNextTag(pszB, TRUE, i, iEnd, papszLines);
     1250        pszB += strlen(pszB) + 1;
     1251
     1252        /* description */
     1253        i = findStrLine("@desc",   iStart, iEnd, papszLines);
     1254        pFnDesc->pszDescription = SDSCopyTextUntilNextTag(pszB, TRUE, i > iEnd ? iStart : i, iEnd, papszLines);
     1255        pszB += strlen(pszB) + 1;
     1256
     1257        /* sketch */
     1258        i = findStrLine("@sketch", iStart, iEnd, papszLines);
     1259        pFnDesc->pszSketch      = SDSCopyTextUntilNextTag(pszB, TRUE, i, iEnd, papszLines);
     1260        pszB += strlen(pszB) + 1;
     1261
     1262        /* return description */
     1263        i = findStrLine("@return", iStart, iEnd, papszLines);
     1264        pFnDesc->pszReturnDesc  = SDSCopyTextUntilNextTag(pszB, TRUE, i, iEnd, papszLines);
     1265        pszB += strlen(pszB) + 1;
     1266
     1267        /* time */
     1268        i = findStrLine("@time", iStart, iEnd, papszLines);
     1269        pFnDesc->pszReturnDesc  = SDSCopyTextUntilNextTag(pszB, TRUE, i, iEnd, papszLines);
     1270        pszB += strlen(pszB) + 1;
     1271
     1272        /* equiv */
     1273        i = findStrLine("@equiv", iStart, iEnd, papszLines);
     1274        pFnDesc->pszReturnDesc  = SDSCopyTextUntilNextTag(pszB, TRUE, i, iEnd, papszLines);
     1275        pszB += strlen(pszB) + 1;
     1276
     1277        /* Set parameter descriptions to NULL */
     1278        for (i = 0; i < pFnDesc->cParams; i++)
     1279            pFnDesc->apszParamDesc[i] = NULL;
     1280
     1281        /*
     1282         * parameters, new @param for each parameter!
     1283         */
     1284        do
     1285        {
     1286            char *pszParam;
     1287
     1288            /* find first */
     1289            i = findStrLine("@param", iStart, iEnd, papszLines);
     1290            if (i >= iEnd)
     1291                break;
     1292
     1293            /* Get parameter name - first word */
     1294            pszParam = SDSCopyTextUntilNextTag(pszB, TRUE, i, iEnd, papszLines);
     1295            if (pszParam != NULL)
     1296            {
     1297                /* first word in psz is the parameter name! */
     1298                psz = findEndOfWord(pszParam);
     1299                *psz++ = '\0';
     1300
     1301                /* find parameter */
     1302                for (j = 0; j < pFnDesc->cParams; j++)
     1303                    if (strcmp(pFnDesc->apszParamName[j], pszParam) != 0)
     1304                        break;
     1305                if (j < pFnDesc->cParams)
    12031306                {
    1204                     pszB[strlen(pszB)-1] = '\0';
    1205                     trim(pszB);
     1307                    /* find end of parameter name */
     1308                    psz = findEndOfWord(strstr(papszLines[i], pszParam));
     1309                    /* copy from end of parameter name */
     1310                    pFnDesc->apszParamDesc[j] = SDSCopyTextUntilNextTag(pszB, TRUE, i, iEnd, papszLines, psz);
     1311                    pszB += strlen(pszB) + 1;
    12061312                }
    1207                 if (*pszB != '\0' && pszB[strlen(pszB)-1] != ',')
    1208                     strcat(pszB, ",");
    1209                 pszB += strlen(pszB);
    1210 
    1211                 /* next */
    1212                 psz = papszLines[++iAuthor] + 1;
    1213                 j = 0;
    1214                 while (*psz == ' ' && j++ < 5) psz++;
    1215                 if (*psz == '*')
    1216                     psz++;
    1217             } while (iAuthor < iEnd && *psz == ' ');
    1218             pszB++;
    1219         }
    1220     }
    1221     else
    1222     {   /* SDS */
    1223         if (iStatus <= iEnd)
    1224         {
    1225             psz = stristr(papszLines[iStatus], "@status") + sizeof("@status");
    1226             while (*psz == ' ')
    1227                 psz++;
    1228             strcpy(pszB, psz);
    1229             trim(pszB);
    1230             pszB += strlen(pszB) + 1;
    1231         }
    1232 
    1233         if (iAuthor <= iEnd)
    1234         {
    1235             pszAuthor = pszB;
    1236             psz = stristr(papszLines[iAuthor], "@author") + sizeof("@author");
    1237             do
    1238             {
    1239                 while (*psz == ' ')
    1240                     psz++;
    1241                 strcpy(pszB, psz);
    1242                 trim(pszB);
    1243                 if (*pszB != '\0' && pszB[strlen(pszB)-1] != ',')
    1244                     strcat(pszB, ",");
    1245                 pszB += strlen(pszB) + 1;
    1246 
    1247                 /* next */
    1248                 psz = papszLines[++iAuthor] + 1;
    1249                 j = 0;
    1250                 while (*psz == ' ' && j++ < 5) psz++;
    1251                 if (*psz == '*')
    1252                     psz++;
    1253             } while (iAuthor <= iEnd && (*psz == ' ' || *psz == '@'));
    1254             pszB++;
    1255         }
    1256     }
    1257 
    1258     /* Status - refcodes are hardcoded here! */
     1313                else
     1314                {   /* signal that parameter name wasn't found! */
     1315                    fprintf(phSignal, "%s, %s: '%s' is not a valid parameter.\n",
     1316                            pszFilename, pFnDesc->pszName, pszParam);
     1317                    ulRc += 0x00010000;
     1318                }
     1319            }
     1320        } while (i > iEnd);
     1321    }
     1322
     1323    /*
     1324     * Status - refcodes are hardcoded here!
     1325     */
    12591326    if (pFnDesc->pszStatus != NULL && *pFnDesc->pszStatus != '\0')
    12601327    {
     
    12891356    }
    12901357
    1291     /* Author */
    1292     if (pszAuthor)
     1358    /*
     1359     * Author
     1360     */
     1361    if (pszAuthors != NULL)
    12931362    {   /* author1, author2, author3 */
    12941363        j = 0;
    1295         psz = trim(pszAuthor);
     1364        psz = trim(pszAuthors);
    12961365        pFnDesc->cAuthors = 0;
    12971366        while (*psz != '\0' && pFnDesc->cAuthors < (int)(sizeof(pFnDesc->apszAuthor) / sizeof(pFnDesc->apszAuthor[0])))
     
    12991368            char *pszBr1 = strchr(psz, '[');
    13001369            char *pszBr2 = strchr(psz, ']');
    1301             char *pszComma;
     1370            char *pszEmail = NULL;
     1371            char *pszNext;
    13021372
    13031373            /* remove '[text]' text - this is usualy used for time/date */
     
    13071377
    13081378            /* terminate string */
    1309             pszComma = strchr(psz, ',');
    1310             if (pszComma != NULL)
    1311             {
    1312                 pszAuthor = pszComma + 1;
    1313                 *pszComma = '\0';
     1379            pszNext = strchr(psz, ',');
     1380            if (pszNext == NULL)
     1381                pszNext = strchr(psz, '\n');
     1382            if (pszNext != NULL)
     1383                *pszNext = '\0';
     1384
     1385            /* check for (email) test */
     1386            pszBr1 = strchr(psz, '(');
     1387            pszBr2 = strchr(psz, ')');
     1388            if (pszBr1 != NULL || pszBr2 != NULL)
     1389            {
     1390                if (pszBr1 != NULL)
     1391                    *pszBr1++ = '\0';
     1392                if (pszBr2 != NULL)
     1393                    *pszBr2++ = '\0';
     1394
     1395                if (pszBr1 != NULL && pszBr1 < pszBr2)
     1396                    pszEmail = trim(pszBr1 + 1);
    13141397            }
    13151398
    13161399            pFnDesc->apszAuthor[pFnDesc->cAuthors]      = trim(psz);
    13171400            pFnDesc->alAuthorRefCode[pFnDesc->cAuthors] =
    1318                 dbFindAuthor(pFnDesc->apszAuthor[pFnDesc->cAuthors]);
     1401                dbFindAuthor(pFnDesc->apszAuthor[pFnDesc->cAuthors], pszEmail);
    13191402
    13201403            if (pFnDesc->alAuthorRefCode[pFnDesc->cAuthors] == -1)
     
    13271410            /* next */
    13281411            pFnDesc->cAuthors++;
    1329             psz = trim(pszAuthor);
     1412            psz = pszNext ? skip(pszNext + 1) : "";
    13301413        }
    13311414    }
     
    13331416    return ulRc;
    13341417}
     1418
     1419
     1420
     1421/**
     1422 * Copies a piece of tag/keyword text into an buffer. SDS.
     1423 * @returns   Pointer to buffer. If iStart > iEnd NULL is returned.
     1424 * @param     pszTarget  Pointer to buffer.
     1425 * @param     fHTML      Add HTML tags like <br> or not
     1426 * @param     iStart     Index of start line.
     1427 * @param     iEnd       Index of last line.
     1428 * @param     apszLines  Array lines.
     1429 * @param     pszStart   Pointer to char to start at (into papszLines[iStart] of course!)
     1430 * @status    completely impelmented.
     1431 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     1432 * @remark    Addes some HTML tags.
     1433 */
     1434static char *SDSCopyTextUntilNextTag(char *pszTarget, BOOL fHTML, int iStart, int iEnd, char **papszLines, const char *pszStart)
     1435{
     1436    char *pszRet = pszTarget;
     1437
     1438    if (iStart <= iEnd)
     1439    {
     1440        int         iStartColumn;
     1441        const char *psz = pszStart != NULL ? pszStart : papszLines[iStart];
     1442
     1443        /*
     1444         * skip dummy chars.
     1445         */
     1446        while (iStart <= iEnd && (*psz == ' ' || *psz == '/' || *psz == '*' || *psz == '\0' ))
     1447        {
     1448            if (*psz == '\0')
     1449                psz = papszLines[++iStart];
     1450            else
     1451                psz++;
     1452        }
     1453
     1454        /* Anything left of the area to copy? */
     1455        if (iStart <= iEnd)
     1456        {
     1457            /*
     1458             * if we stand at a tag, skip over the tag
     1459             */
     1460            if (*psz == '@')
     1461                psz = skip(findEndOfWord(psz+1));
     1462
     1463            /*
     1464             * save start columen
     1465             */
     1466            iStartColumn = psz - papszLines[iStart];
     1467
     1468            /*
     1469             * Copy loop.
     1470             */
     1471            do
     1472            {
     1473                int i;
     1474                for (i = psz - papszLines[iStart]; i < iStartColumn; i++)
     1475                    *pszTarget++ = ' '; /* FIXME HTML and indenting... */
     1476
     1477                strcpy(pszTarget, psz);
     1478                trimR(pszTarget);
     1479                pszTarget += strlen(pszTarget);
     1480                if (fHTML)
     1481                    strcpy(pszTarget, "<BR>\n");
     1482                else
     1483                    strcpy(pszTarget, "\n");
     1484                pszTarget += strlen(pszTarget);
     1485
     1486                /* Next */
     1487                psz = skip(papszLines[++iStart]);
     1488                if (iStart <= iEnd)
     1489                {
     1490                    while (psz != NULL && *psz == '*')
     1491                        ++psz;
     1492                    psz = skip(psz);
     1493                    /* end test comment */
     1494                    if (psz > papszLines[iStart] && psz[-1] == '*' && *psz == '/')
     1495                        break;
     1496                }
     1497            } while (iStart <= iEnd && *psz != '@');
     1498
     1499            /*
     1500             * remove empty lines at end.
     1501             */
     1502            if (fHTML)
     1503            {
     1504                pszTarget--;
     1505                while (pszTarget >= pszRet && (*pszTarget == '\n' || *pszTarget == ' '))
     1506                {
     1507                    if (*pszTarget == '\n')
     1508                        pszTarget -= 4;
     1509                    *pszTarget-- = '\0';
     1510                }
     1511            }
     1512            else
     1513            {
     1514                pszTarget--;
     1515                while (pszTarget >= pszRet && (*pszTarget == '\n' || *pszTarget == ' '))
     1516                    *pszTarget-- = '\0';
     1517            }
     1518        }
     1519        else
     1520            pszTarget = '\0';
     1521    }
     1522    else
     1523        pszRet = NULL;
     1524
     1525    return pszRet != NULL && *pszRet == '\0' ?  NULL : pszRet;
     1526}
     1527
     1528
     1529
     1530/**
     1531 * Copies a piece of tag/keyword text into an buffer. SDS.
     1532 * @returns   Pointer to buffer. If iStart > iEnd NULL is returned.
     1533 * @param     pszTarget  Pointer to buffer.
     1534 * @param     fHTML      Add HTML tags like <br> or not
     1535 * @param     iStart     Index of start line.
     1536 * @param     iEnd       Index of last line.
     1537 * @param     apszLines  Array lines.
     1538 * @param     pszStart   Pointer to char to start at (into papszLines[iStart] of course!)
     1539 * @status    completely impelmented.
     1540 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     1541 * @remark    Addes some HTML tags.
     1542 */
     1543static char *CommonCopyTextUntilNextTag(char *pszTarget, BOOL fHTML, int iStart, int iEnd, char **papszLines, const char *pszStart)
     1544{
     1545    char *pszRet = pszTarget;
     1546
     1547    if (iStart <= iEnd)
     1548    {
     1549        /* known keywords */
     1550        int         iStartColumn;
     1551        int         i;
     1552        const char *psz = pszStart != NULL ? pszStart : papszLines[iStart];
     1553
     1554        /*
     1555         * Skip evt. keyword
     1556         */
     1557        psz = skip(psz);
     1558        for (i = 0; pszCommonKeywords[i] != NULL; i++)
     1559            if (strnicmp(pszCommonKeywords[i], psz, strlen(pszCommonKeywords[i])) == 0)
     1560            {
     1561                psz = skip(psz + strlen(pszCommonKeywords[i]));
     1562                psz = skip(*psz == ':' ? psz + 1 : psz);
     1563                break;
     1564            }
     1565
     1566        /*
     1567         * save start columen
     1568         */
     1569        iStartColumn = psz - papszLines[iStart];
     1570
     1571        /*
     1572         * copy loop
     1573         */
     1574        do
     1575        {
     1576            /*
     1577             * Skip '*'s at start of the line.
     1578             */
     1579            while (*psz == '*')
     1580                psz++;
     1581
     1582            /* end comment check */
     1583            if (psz > papszLines[iStart] && psz[-1] == '*' && *psz == '/')
     1584                break;
     1585            psz = skip(psz);
     1586
     1587            /*
     1588             * Indent up to iStartColumn
     1589             */
     1590            for (i = psz - papszLines[iStart]; i < iStartColumn; i++)
     1591                *pszTarget++ = ' '; /* FIXME HTML and indenting... */
     1592
     1593            /*
     1594             * Copy the rest of the line and add HTML break.
     1595             */
     1596            strcpy(pszTarget, psz);
     1597            trimR(pszTarget);
     1598            pszTarget += strlen(pszTarget);
     1599            if (fHTML)
     1600                strcpy(pszTarget, "<BR>\n");
     1601            else
     1602                strcpy(pszTarget, "\n");
     1603            pszTarget += strlen(pszTarget);
     1604
     1605            /*
     1606             * Next
     1607             */
     1608            psz = skip(papszLines[++iStart]);
     1609
     1610            /*
     1611             * Check for keyword
     1612             */
     1613            if (iStart <= iEnd)
     1614            {
     1615                psz = skip(psz);
     1616                for (i = 0; pszCommonKeywords[i] != NULL; i++)
     1617                    if (strnicmp(pszCommonKeywords[i], psz, strlen(pszCommonKeywords[i])) == 0)
     1618                        break;
     1619                if (pszCommonKeywords[i] != NULL)
     1620                    break;
     1621            }
     1622        } while (iStart < iEnd);
     1623
     1624        /*
     1625         * remove empty lines at end.
     1626         */
     1627        if (fHTML)
     1628        {
     1629            pszTarget--;
     1630            while (pszTarget >= pszRet && (*pszTarget == '\n' || *pszTarget == ' '))
     1631            {
     1632                if (*pszTarget == '\n')
     1633                    pszTarget -= 4;
     1634                *pszTarget-- = '\0';
     1635            }
     1636        }
     1637        else
     1638        {
     1639            pszTarget--;
     1640            while (pszTarget >= pszRet && (*pszTarget == '\n' || *pszTarget == ' '))
     1641                *pszTarget-- = '\0';
     1642        }
     1643    }
     1644    else
     1645        pszRet = NULL;
     1646
     1647    return pszRet != NULL && *pszRet == '\0' ?  NULL : pszRet;
     1648}
     1649
    13351650
    13361651
     
    16992014
    17002015/** first char after word */
    1701 static char *findEndOfWord(char *psz)
     2016static char *findEndOfWord(const char *psz)
    17022017{
    17032018
     
    17122027          )
    17132028        ++psz;
    1714     return psz;
     2029    return (char *)psz;
    17152030}
    17162031
    17172032
    17182033/** starting char of word */
    1719 static char *findStartOfWord(char *psz, const char *pszStart)
    1720 {
    1721     char *pszR = psz;
     2034static char *findStartOfWord(const char *psz, const char *pszStart)
     2035{
     2036    const char *pszR = psz;
    17222037    while (psz >= pszStart &&
    17232038            (
     
    17292044          )
    17302045        pszR = psz--;
    1731     return pszR;
     2046    return (char*)pszR;
    17322047}
    17332048
     
    17402055 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    17412056 */
    1742 static char *trim(char *psz)
     2057inline char *trim(char *psz)
    17432058{
    17442059    int i;
     
    17522067    psz[i+1] = '\0';
    17532068    return psz;
     2069}
     2070
     2071
     2072/**
     2073 * Right trims a string, ie. removing spaces (and tabs) from the end of the string.
     2074 * @returns   Pointer to the string passed in.
     2075 * @param     psz   Pointer to the string which is to be right trimmed.
     2076 * @status    completely implmented.
     2077 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     2078 */
     2079inline char *trimR(char *psz)
     2080{
     2081    int i;
     2082    if (psz == NULL)
     2083        return NULL;
     2084    i = strlen(psz) - 1;
     2085    while (i >= 0 && (psz[i] == ' ' || *psz == '\t'))
     2086        i--;
     2087    psz[i+1] = '\0';
     2088    return psz;
     2089}
     2090
     2091
     2092/**
     2093 * skips blanks until first non-blank.
     2094 * @returns   Pointer to first not space or tab char in the string.
     2095 * @param     psz   Pointer to the string.
     2096 * @status    completely implmented.
     2097 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     2098 */
     2099inline char *skip(const char *psz)
     2100{
     2101    if (psz == NULL)
     2102        return NULL;
     2103
     2104    while (*psz == ' ' || *psz == '\t')
     2105        psz++;
     2106    return (char*)psz;
    17542107}
    17552108
     
    19922345}
    19932346
     2347
     2348/**
     2349 * Finds a string in a range of pages.
     2350 * @returns   Index of the line (into ppaszLines).
     2351 * @param     psz         String to search for.
     2352 * @param     iStart      Start line.
     2353 * @param     iEnd        Line to stop at
     2354 * @param     papszLines  Array of lines to search within.
     2355 * @status    completely implemented.
     2356 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     2357 */
     2358static int findStrLine(const char *psz, int iStart, int iEnd, char **papszLines)
     2359{
     2360    while (iStart <= iEnd &&
     2361           stristr(papszLines[iStart], psz) == NULL)
     2362        iStart++;
     2363    return iStart;
     2364}
     2365
     2366
     2367
     2368
  • trunk/tools/database/db.cpp

    r2776 r2818  
    1 /* $Id: db.cpp,v 1.10 2000-02-14 17:18:31 bird Exp $ *
     1/* $Id: db.cpp,v 1.11 2000-02-18 12:42:06 bird Exp $ *
    22 *
    33 * DB - contains all database routines.
     
    8080static unsigned long CheckAuthorError(char * &pszError, const char *pszFieldName, const char *pszFieldValue, const char *pszQuery);
    8181static unsigned long logDbError(char * &pszError, const char *pszQuery);
     82static char *sqlstrcat(char *pszQuery, const char *pszBefore, const char *pszStr, const char *pszAfter = NULL);
     83
    8284#ifndef DLL
    8385    extern "C" void      dbHandler(int sig);
     
    297299    int  rc;
    298300    long lFunction = -1;
    299     char szQuery[256];
     301    char szQuery[512];
    300302    MYSQL_RES *pres;
    301303
     
    596598 *                       This doesn't have to be the name. Initials, alias and email
    597599 *                       is also searched.
    598  */
    599 signed long _System dbFindAuthor(const char *pszAuthor)
     600 * @param     pszEmail   Email address. Might be NULL!
     601 */
     602signed long _System dbFindAuthor(const char *pszAuthor, const char *pszEmail)
    600603{
    601604    signed long refcode = -1;
    602605    MYSQL_RES *pres;
    603     char szQuery[256];
    604 
     606    char szQuery[512];
     607
     608    /*
     609     * parameter validations
     610     */
     611    if (pszAuthor == NULL || strlen(pszAuthor) > 64)
     612        return -1;
     613    if (pszEmail != NULL && strlen(pszEmail) > 64)
     614    {
     615        fprintf(stderr, "email too long!");
     616        return -1;
     617    }
     618
     619    /*
     620     * Query
     621     */
    605622    sprintf(&szQuery[0],
    606623            "SELECT refcode FROM author "
     
    610627            "      email    = '%s'",
    611628            pszAuthor, pszAuthor, pszAuthor, pszAuthor);
     629
     630    if (pszEmail != NULL)
     631        sprintf(&szQuery[strlen(&szQuery[0])], " OR email = '%s'", pszEmail);
     632
    612633    if (mysql_query(pmysql, &szQuery[0]) >= 0)
    613634    {
     
    702723    MYSQL_RES *     pres;
    703724    MYSQL_ROW       row;
    704     char            szQuery[512];
    705     char *          pszQuery = &szQuery[0];
     725    char *          pszQuery2 = (char*)malloc(65500);
     726    char *          pszQuery = pszQuery2;
    706727    long            lCurrentState;
    707728    int             i,k,rc;
    708729    unsigned long   ulRc = 0;
    709730
     731    /* check if malloc have failed allocating memory for us. */
     732    if (pszQuery2 == NULL)
     733    {
     734        strcpy(pszError, "internal dbUpdateFunction error - malloc failed!\n");
     735        return 1;
     736    }
     737
     738
     739    /*
     740     * Loop thru all functions in the array of refocodes.
     741     */
    710742    for (k = 0; k < pFnDesc->cRefCodes; k++)
    711743    {
     
    717749        sprintf(pszQuery, "UPDATE function SET updated = updated + 1 WHERE refcode = %ld",
    718750                pFnDesc->alRefCode[k]);
    719         rc = mysql_queryu1(pmysql, &szQuery[0]);
     751        rc = mysql_queryu1(pmysql, pszQuery2);
    720752
    721753
     
    724756         */
    725757        lCurrentState = dbGetFunctionState(pFnDesc->alRefCode[k]);
    726         if (lCurrentState == -1)
     758        if (lCurrentState == -1 && dbGetLastErrorDesc() != NULL && strlen(dbGetLastErrorDesc()) != 0)
    727759        {
    728760            strcpy(pszError, dbGetLastErrorDesc());
     761            free(pszQuery2);
    729762            return 1;
    730763        }
     
    736769        strcpy(pszQuery, "UPDATE function SET ");
    737770        pszQuery += strlen(pszQuery);
    738         if (pFnDesc->lStatus != 99 || lCurrentState == 0)
    739         {
    740             sprintf(pszQuery, "state = %ld ", pFnDesc->lStatus);
     771
     772        /* Status */
     773        if (lCurrentState != pFnDesc->lStatus
     774            && pFnDesc->lStatus != 0
     775            && (lCurrentState == 0 || pFnDesc->lStatus != 99))
     776        {
     777            sprintf(pszQuery, "state = %ld", pFnDesc->lStatus);
    741778            f = TRUE;
    742779        }
    743780        pszQuery += strlen(pszQuery);
    744781
     782        /* return type */
    745783        if (pFnDesc->pszReturnType != NULL)
    746784        {
    747785            if (f)  strcat(pszQuery, ", ");
    748             sprintf(pszQuery + strlen(pszQuery),  "return = '%s' ", pFnDesc->pszReturnType);
    749             pszQuery += strlen(pszQuery);
     786            pszQuery = sqlstrcat(pszQuery, "return = ",  pFnDesc->pszReturnType);
    750787            f = TRUE;
    751788        }
    752789
     790        /* Description */
     791        if (pFnDesc->pszDescription != NULL)
     792        {
     793            if (f)  strcat(pszQuery, ", ");
     794            pszQuery = sqlstrcat(pszQuery, "description  = ", pFnDesc->pszDescription);
     795            f = TRUE;
     796        }
     797
     798        /* Remark */
     799        if (pFnDesc->pszRemark != NULL)
     800        {
     801            if (f)  strcat(pszQuery, ", ");
     802            pszQuery = sqlstrcat(pszQuery,  "remark = ", pFnDesc->pszRemark);
     803            f = TRUE;
     804        }
     805
     806        /* Description */
     807        if (pFnDesc->pszReturnDesc != NULL)
     808        {
     809            if (f)  strcat(pszQuery, ", ");
     810            pszQuery = sqlstrcat(pszQuery,  "returndesc = ", pFnDesc->pszReturnDesc);
     811            f = TRUE;
     812        }
     813
     814        /* Sketch */
     815        if (pFnDesc->pszSketch != NULL)
     816        {
     817            if (f)  strcat(pszQuery, ", ");
     818            pszQuery = sqlstrcat(pszQuery,  "sketch = ", pFnDesc->pszSketch);
     819            f = TRUE;
     820        }
     821
     822        /* Equiv */
     823        if (pFnDesc->pszEquiv != NULL)
     824        {
     825            if (f)  strcat(pszQuery, ", ");
     826            pszQuery = sqlstrcat(pszQuery,  "equiv = ", pFnDesc->pszEquiv);
     827            f = TRUE;
     828        }
     829
     830        /* Equiv */
     831        if (pFnDesc->pszTime != NULL)
     832        {
     833            if (f)  strcat(pszQuery, ", ");
     834            pszQuery = sqlstrcat(pszQuery,  "time = ", pFnDesc->pszTime);
     835            f = TRUE;
     836        }
     837
     838        /* Execute update query? */
    753839        if (f)
    754840        {
    755             sprintf(pszQuery + strlen(pszQuery), "WHERE refcode = %ld", pFnDesc->alRefCode[k]);
    756             rc = mysql_queryu2(pmysql, &szQuery[0]);
     841            sprintf(pszQuery + strlen(pszQuery), " WHERE refcode = %ld", pFnDesc->alRefCode[k]);
     842            rc = mysql_queryu2(pmysql, pszQuery2);
    757843            if (rc < 0)
    758844            {
    759845                sprintf(pszError, "Updating functiontable failed with error: %s - (sql=%s) ",
    760                         dbGetLastErrorDesc(), &szQuery[0]);
     846                        dbGetLastErrorDesc(), pszQuery2);
    761847                pszError += strlen(pszError) - 1;
    762848                ulRc++;
     
    765851
    766852
     853
    767854        /*
    768855         * Parameters
    769856         */
    770         pszQuery = &szQuery[0];
     857        pszQuery = pszQuery2;
    771858        sprintf(pszQuery, "SELECT count(*) FROM parameter WHERE function = %ld", pFnDesc->alRefCode[k]);
    772859        rc = mysql_queryu3(pmysql, pszQuery);
     
    782869                    for (i = 0; i < pFnDesc->cParams; i++)
    783870                    {
    784                         sprintf(pszQuery, "UPDATE parameter SET type = '%s', name = '%s' "
    785                                 "WHERE function = (%ld) AND sequencenbr = (%ld)",
     871                        sprintf(pszQuery, "UPDATE parameter SET type = '%s', name = '%s'",
    786872                                pFnDesc->apszParamType[i] != NULL ? pFnDesc->apszParamType[i] : "",
    787                                 pFnDesc->apszParamName[i] != NULL ? pFnDesc->apszParamName[i] : "",
    788                                 pFnDesc->alRefCode[k], i
    789                                 );
     873                                pFnDesc->apszParamName[i] != NULL ? pFnDesc->apszParamName[i] : "");
     874                        if (pFnDesc->apszParamDesc[i] != NULL)
     875                            sqlstrcat(pszQuery, ", description = ", pFnDesc->apszParamDesc[i]);
     876                        sprintf(pszQuery + strlen(pszQuery), " WHERE function = (%ld) AND sequencenbr = (%ld)",
     877                                pFnDesc->alRefCode[k], i);
    790878                        rc = mysql_queryu4(pmysql, pszQuery);
    791879                        if (rc < 0)
     
    820908                    for (i = 0; i < pFnDesc->cParams; i++)
    821909                    {
    822                         sprintf(pszQuery, "INSERT INTO parameter(function, sequencenbr, type, name) "
    823                                 "VALUES (%ld, %d, '%s', '%s')",
     910                        sprintf(pszQuery, "INSERT INTO parameter(function, sequencenbr, type, name, description) "
     911                                "VALUES (%ld, %d, '%s', '%s'",
    824912                                pFnDesc->alRefCode[k], i,
    825913                                pFnDesc->apszParamType[i] != NULL ? pFnDesc->apszParamType[i] : "",
    826914                                pFnDesc->apszParamName[i] != NULL ? pFnDesc->apszParamName[i] : ""
    827915                                );
    828                         rc = mysql_queryu6(pmysql, pszQuery);
     916                        if (pFnDesc->apszParamDesc[i] != NULL)
     917                            sqlstrcat(pszQuery, ", ", pFnDesc->apszParamDesc[i]);
     918                        else
     919                            strcat(pszQuery, ", NULL)");
     920
     921                        rc = mysql_queryu6(pmysql, pszQuery2);
    829922                        if (rc < 0)
    830923                        {
     
    896989
    897990    lDll = lDll;
     991    free(pszQuery2);
    898992    return ulRc;
    899993}
     
    15481642    mysql_free_result(pres);
    15491643    return (signed long)rc;
     1644}
     1645
     1646
     1647/**
     1648 *
     1649 * @returns   Pointer to end of the string.
     1650 * @param     pszQuery   Outputbuffer
     1651 * @param     pszBefore  Text before string, might be NULL.
     1652 * @param     pszStr     String (NOT NULL)
     1653 * @param     pszAfter   Text after, might be NULL.
     1654 * @status    completely implemented
     1655 * @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     1656 */
     1657static char *sqlstrcat(char *pszQuery, const char *pszBefore, const char *pszStr, const char *pszAfter)
     1658{
     1659    register char ch;
     1660
     1661    pszQuery += strlen(pszQuery);
     1662
     1663    /*
     1664     * String before
     1665     */
     1666    if (pszBefore != NULL)
     1667    {
     1668        strcpy(pszQuery, pszBefore);
     1669        pszQuery += strlen(pszQuery);
     1670    }
     1671
     1672    /*
     1673     * THE String
     1674     */
     1675    *pszQuery++ = '\'';
     1676    while ((ch = *pszStr++) != '\0')
     1677    {
     1678        if (ch == '\'')
     1679            *pszQuery++ = '\\';
     1680        *pszQuery++ = ch;
     1681    }
     1682    *pszQuery++ = '\'';
     1683
     1684    /*
     1685     * String after
     1686     */
     1687    if (pszAfter != NULL)
     1688    {
     1689        strcpy(pszQuery, pszAfter);
     1690        pszQuery += strlen(pszQuery);
     1691    }
     1692    else
     1693        *pszQuery = '\0';
     1694
     1695
     1696    return pszQuery;
    15501697}
    15511698
  • trunk/tools/database/db.h

    r2770 r2818  
    1 /* $Id: db.h,v 1.6 2000-02-12 23:54:29 bird Exp $ */
     1/* $Id: db.h,v 1.7 2000-02-18 12:42:07 bird Exp $ */
    22/*
    33 * DB - contains all database routines
     
    3232        /* buffers */
    3333        char  szFnDclBuffer[2048];
    34         char  szFnHdrBuffer[2048];
     34        char  szFnHdrBuffer[10240];
    3535
    3636        /* function name and type */
     
    4545        char *apszParamType[30];
    4646        char *apszParamName[30];
     47        char *apszParamDesc[30];
    4748
    4849        /* authors */
     
    5051        char *apszAuthor[NBR_AUTHORS];
    5152        long  alAuthorRefCode[NBR_AUTHORS];
     53
     54        /* other description fields */
     55        char *pszDescription;
     56        char *pszRemark;
     57        char *pszReturnDesc;
     58        char *pszSketch;
     59        char *pszEquiv;
     60        char *pszTime;
    5261
    5362        /* status */
     
    93102                                           PFNFINDBUF pFnFindBuf,
    94103                                           signed long lDll);
    95     signed long     _System dbFindAuthor(const char *pszAuthor);
     104    signed long     _System dbFindAuthor(const char *pszAuthor, const char *pszEmail);
    96105    signed long     _System dbGetFunctionState(signed long lRefCode);
    97106    unsigned long   _System dbUpdateFunction(PFNDESC pFnDesc,
  • trunk/tools/database/kHtmlPC.cpp

    r2765 r2818  
    1 /* $Id: kHtmlPC.cpp,v 1.2 2000-02-12 17:55:03 bird Exp $ */
     1/* $Id: kHtmlPC.cpp,v 1.3 2000-02-18 12:42:07 bird Exp $ */
    22/*
    33 * kHtmlPC - Special-purpose HTML/SQL preprocessor.
     
    112112static void          openLog(void);
    113113static void          closeLog(void);
    114 static unsigned long processFile(const char *pszFilename/*, const POPTIONS pOptions*/);
     114static unsigned long processFile(const char *pszFilenamem, const POPTIONS pOptions);
    115115static unsigned long tagEndkSql(TAG_PARAMETER_LIST);
    116116static unsigned long tagkSql(TAG_PARAMETER_LIST);
    117 static unsigned long tagkTemplate(TAG_PARAMETER_LIST, FILE * &phFile);
     117static unsigned long tagkTemplate(TAG_PARAMETER_LIST, FILE * &phFile, const POPTIONS pOptions);
    118118static unsigned long tagkInclude(TAG_PARAMETER_LIST);
    119 static unsigned long tagkGraph(TAG_PARAMETER_LIST);
     119static unsigned long tagkGraph(TAG_PARAMETER_LIST, const POPTIONS pOptions);
    120120static unsigned long tagkDefine(TAG_PARAMETER_LIST);
    121121static unsigned long tagkUndef(TAG_PARAMETER_LIST);
     
    155155    char           *pszUser     = "root";
    156156    char           *pszPasswd   = "";
     157    char            szPathName[CCHMAXPATH];
     158    OPTIONS         options = {"."};
     159
    157160
    158161    /* signal handler */
     
    167170    * parse arguments.
    168171    * options:  -h or -?     help
     172    *           -b:<basepath> Basepath for output files.
    169173    *           -d:<dbname>   Database name
    170174    *           -p:<passwd>   Password
     
    181185            switch (argv[argi][1])
    182186            {
     187                case 'b':
     188                case 'B':
     189                    printf("%s\n", argv[argi]);
     190                    if (argv[argi][2] == ':')
     191                    {
     192                        if (_fullpath(&szPathName[0], &argv[argi][3], sizeof(szPathName)) != NULL)
     193                            options.pszBaseDir = &szPathName[0];
     194                        else
     195                        {
     196                            fprintf(stderr, "error: basepath '%s' don't exists\n", &argv[argi][3]);
     197                            fFatal = TRUE;
     198                        }
     199                    }
     200                    else
     201                    {
     202                        fprintf(stderr, "error: option '-b:' requires a directory name.\n");
     203                        fFatal = TRUE;
     204                    }
     205                    break;
     206
    183207                case 'd':
    184208                case 'D':
     
    186210                        pszDatabase = &argv[argi][3];
    187211                    else
    188                         fprintf(stderr, "warning: option '-d:' requires database name.\n");
     212                    {
     213                        fprintf(stderr, "error: option '-d:' requires database name.\n");
     214                        fFatal = TRUE;
     215                    }
    189216                    break;
    190217
     
    205232                        pszPasswd = &argv[argi][3];
    206233                    else
    207                         fprintf(stderr, "warning: option '-p:' requires password.\n");
     234                    {
     235                        fprintf(stderr, "error: option '-p:' requires password.\n");
     236                        fFatal = TRUE;
     237                    }
    208238                    break;
    209239
     
    213243                        pszUser = &argv[argi][3];
    214244                    else
     245                    {
    215246                        fprintf(stderr, "error: option '-u:' requires userid.\n");
     247                        fFatal = TRUE;
     248                    }
    216249                    break;
    217250
     
    233266            if (dbConnect(pszHost, pszUser, pszPasswd, pszDatabase))
    234267            {
    235                 ulRc += processFile(argv[argi]/*, &options*/);
     268                ulRc += processFile(argv[argi], &options);
    236269                dbDisconnect();
    237270            }
     
    330363 * @remark    Big function!
    331364 */
    332 static unsigned long processFile(const char *pszFilename/*, const POPTIONS pOptions*/)
     365static unsigned long processFile(const char *pszFilename, const POPTIONS pOptions)
    333366{
    334367    unsigned long                      ulRc = 0;
     
    454487                            ulRc2 = tagEndkSql(TAG_PARAMETERS);
    455488                        else if (tag.isTag("!kTemplate"))               /* !kTemplate   */
    456                             ulRc2 = tagkTemplate(TAG_PARAMETERS, phFile);
     489                            ulRc2 = tagkTemplate(TAG_PARAMETERS, phFile, pOptions);
    457490                        else if (tag.isTag("!kInclude"))                /* !kInclude    */
    458491                            ulRc2 = tagkInclude(TAG_PARAMETERS);
    459492                        else if (tag.isTag("!kGraph"))                  /* !kGraph      */
    460                             ulRc2 = tagkGraph(TAG_PARAMETERS);
     493                            ulRc2 = tagkGraph(TAG_PARAMETERS, pOptions);
    461494                        else if (tag.isTag("!kDefine"))                 /* !kDefine     */
    462495                            ulRc2 = tagkDefine(TAG_PARAMETERS);
     
    714747 * @returns   low  word: number of errors
    715748 *            high word: number of warnings
    716  * @param     phFile  Reference to current output file.
     749 * @param     phFile    Reference to current output file.
     750 * @param     pOptions  Pointer to the options struct.
    717751 * @remark    See TAG_PARAMETER_LIST for parameters.
    718752 *            Use TAG_PARAMETERS when calling this function.
    719753 */
    720 static unsigned long tagkTemplate(TAG_PARAMETER_LIST, FILE * &phFile)
     754static unsigned long tagkTemplate(TAG_PARAMETER_LIST, FILE * &phFile, const POPTIONS pOptions)
    721755{
    722756    unsigned long    ulRc = 0;
     
    734768    if (pszFilename != NULL)
    735769    {
     770        char  szFullFileName[CCHMAXPATH];
    736771        if (phFile != NULL)
    737772            fclose(phFile);
    738 
    739         phFile = fopen(pszFilename, "wb");
    740         if (phFile != NULL)
    741             fprintf(phLog, "%s(%ld) : info: new output file, '%s'.\n",
    742                     pCurFile->getFilename(), pCurFile->getLineNumber()+1, pszFilename);
     773        if (strlen(pszFilename) + strlen(pOptions->pszBaseDir) + 1 + 1 < sizeof(szFullFileName))
     774        {
     775            sprintf(&szFullFileName[0], "%s\\%s", pOptions->pszBaseDir, pszFilename);
     776            phFile = fopen(&szFullFileName[0], "wb");
     777            if (phFile != NULL)
     778                fprintf(phLog, "%s(%ld) : info: new output file, '%s'.\n",
     779                        pCurFile->getFilename(), pCurFile->getLineNumber()+1, &szFullFileName[0]);
     780            else
     781            {
     782                fprintf(phLog, "%s(%ld) : error: kTemplate - error opening output file '%s'.\n",
     783                        pCurFile->getFilename(), pCurFile->getLineNumber()+1, &szFullFileName[0]);
     784                ulRc += 0x00000001;
     785            }
     786        }
    743787        else
    744788        {
    745             fprintf(phLog, "%s(%ld) : error: kTemplate - error opening output file '%s'.\n",
    746                     pCurFile->getFilename(), pCurFile->getLineNumber()+1, pszFilename);
     789            fprintf(phLog, "%s(%ld) : error: kTemplate - filename and base dir is too long! '%s\\%s'.\n",
     790                    pCurFile->getFilename(), pCurFile->getLineNumber()+1, pOptions->pszBaseDir, pszFilename);
    747791            ulRc += 0x00000001;
    748792        }
     
    799843 *            Use TAG_PARAMETERS when calling this function.
    800844 */
    801 static unsigned long tagkGraph(TAG_PARAMETER_LIST)
     845static unsigned long tagkGraph(TAG_PARAMETER_LIST, const POPTIONS pOptions)
    802846{
    803847    unsigned long ulRc = 0;
     
    814858    try
    815859    {
    816         kGraph graph(tag);
     860        kGraph graph(tag, pOptions->pszBaseDir);
    817861        graph.showWarnings(phLog, pCurFile);
    818862        graph.save();
     
    22422286/**
    22432287 * Analyses the tag and executes SQL statements.
    2244  * @param     tag  Tag.
     2288 * @param     tag         Tag.
     2289 * @param     pszBaseDir  Base output directory.
    22452290 * @remark    Throws kError::enmErrors
    22462291 */
    2247 void  kGraph::analyseTag(const kTag &tag) throw(kError::enmErrors)
     2292void  kGraph::analyseTag(const kTag &tag, const char *pszBaseDir) throw(kError::enmErrors)
    22482293{
    22492294    int cArgs,    i;
     
    22972342        {
    22982343            if (pszValue == NULL || strlen(pszValue) == 0) throw(kError::error_filename_param_is_missing_value);
    2299             pszFilename = dupeString(pszValue);
     2344            pszFilename = new char[strlen(pszValue) + 2 + strlen(pszBaseDir)];
     2345            if (pszFilename == NULL) throw(kError::error_filename_param_is_missing_value);
     2346            sprintf(pszFilename, "%s\\%s", pszBaseDir, pszValue);
    23002347        }
    23012348        else if (stricmp(pszName, "title") == 0)
     
    31253172 * @remark    Throws kError::enmError on error.
    31263173 */
    3127 kGraph::kGraph(const kTag &tag) throw(kError::enmErrors)
     3174kGraph::kGraph(const kTag &tag, const char *pszBaseDir) throw(kError::enmErrors)
    31283175    : pGraph(NULL), enmTypeCd(unknown), enmSubTypeCd(normal),
    31293176    pszFilename(NULL), pszTitle(NULL), pszTitleX(NULL),
     
    31373184    try
    31383185    {
    3139         analyseTag(tag);
     3186        analyseTag(tag, pszBaseDir);
    31403187        createBaseGraph();
    31413188        if (fLegend)
     
    31633210/**
    31643211 * Saves the graph to the filename specified in the tag.
     3212 * 2
    31653213 * @returns   Errorcode.
    31663214 */
  • trunk/tools/database/kHtmlPC.h

    r830 r2818  
    1 /* $Id: kHtmlPC.h,v 1.1 1999-09-05 02:53:06 bird Exp $ */
     1/* $Id: kHtmlPC.h,v 1.2 2000-02-18 12:42:08 bird Exp $ */
    22/*
    33 * kHtmlPC - Special-purpose HTML/SQL preprocessor.
     
    1717    typedef struct _options
    1818    {
    19         BOOL fDummy;
     19        char *pszBaseDir;
    2020    } OPTIONS, *POPTIONS;
    2121
     
    428428
    429429            /**@cat internal function */
    430             void    analyseTag(const kTag &tag)     throw(kError::enmErrors);
     430            void    analyseTag(const kTag &tag, const char *pszBaseDir)     throw(kError::enmErrors);
    431431            void    fetchData(const char *pszSql)   throw(kError::enmErrors);
    432432            kGraphDataSet *findOrCreateDataSet(const char *pszLegend) throw(kError::enmErrors);
     
    450450
    451451        public:
    452             kGraph(const kTag &tag) throw(kError::enmErrors);
     452            kGraph(const kTag &tag, const char *pszBaseDir) throw(kError::enmErrors);
    453453            ~kGraph(void);
    454454
  • trunk/tools/database/sample.kSqlHtml

    r2765 r2818  
    1 <!-- $Id: sample.kSqlHtml,v 1.2 2000-02-12 17:55:04 bird Exp $
     1<!-- $Id: sample.kSqlHtml,v 1.3 2000-02-18 12:42:08 bird Exp $
    22  --
    33  -- kSqlHTML Template Sample.
     
    186186<BODY>
    187187<H1>Details on APIs in $(dllname)</H1>
     188<P>
     189<IMAGE SRC="odin32Dll$(dllname).gif">
     190</P>
    188191<TABLE BORDER=1 BORDERCOLOR="#000000" CELLPADDING=4 CELLSPACING=0>
    189192    <THEAD>
    190         <TR VALIGN=TOP> <TH>Ordinal</TH> <TH>API name</TH> <TH>State</TH> </TR>
     193        <TR VALIGN=TOP> <TH>Ordinal</TH> <TH>API name</TH> <TH>Author(s)</TH> <TH>State</TH> </TR>
    191194    </THEAD>
    192195    <TBODY>
    193196        <!kSql sql="SELECT ordinal,
    194197                           function.name AS functionname,
    195                            state.name AS statename
     198                           state.name AS statename,
     199                           function.refcode AS fnrefcode
    196200                       FROM function, state
    197201                       WHERE state.refcode = state
    198                              AND dll = $(dllrefcode)"
     202                             AND dll = $(dllrefcode)
     203                       ORDER BY function.name"
    199204        ><TR>
    200205            <TD><P ALIGN=RIGHT>$(ordinal)<P></TD>
    201206            <TD><P ALIGN=LEFT>$(functionname)<P></TD>
     207            <TD><!kSql sql="SELECT name AS authorname
     208                            FROM fnauthor fna, author a
     209                            WHERE function = $(fnrefcode) AND fna.author = a.refcode"
     210           ><P ALIGN=RIGHT>$(authorname)<P><!/kSql>
     211            </TD>
    202212            <TD><P ALIGN=LEFT>$(statename)<P></TD>
    203213        </TR><!/kSql>
Note: See TracChangeset for help on using the changeset viewer.