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/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 */
Note: See TracChangeset for help on using the changeset viewer.