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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.