Changeset 2818 for trunk/tools/database/kHtmlPC.cpp
- Timestamp:
- Feb 18, 2000, 1:42:08 PM (26 years ago)
- 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:03bird Exp $ */1 /* $Id: kHtmlPC.cpp,v 1.3 2000-02-18 12:42:07 bird Exp $ */ 2 2 /* 3 3 * kHtmlPC - Special-purpose HTML/SQL preprocessor. … … 112 112 static void openLog(void); 113 113 static void closeLog(void); 114 static unsigned long processFile(const char *pszFilename /*, const POPTIONS pOptions*/);114 static unsigned long processFile(const char *pszFilenamem, const POPTIONS pOptions); 115 115 static unsigned long tagEndkSql(TAG_PARAMETER_LIST); 116 116 static unsigned long tagkSql(TAG_PARAMETER_LIST); 117 static unsigned long tagkTemplate(TAG_PARAMETER_LIST, FILE * &phFile );117 static unsigned long tagkTemplate(TAG_PARAMETER_LIST, FILE * &phFile, const POPTIONS pOptions); 118 118 static unsigned long tagkInclude(TAG_PARAMETER_LIST); 119 static unsigned long tagkGraph(TAG_PARAMETER_LIST );119 static unsigned long tagkGraph(TAG_PARAMETER_LIST, const POPTIONS pOptions); 120 120 static unsigned long tagkDefine(TAG_PARAMETER_LIST); 121 121 static unsigned long tagkUndef(TAG_PARAMETER_LIST); … … 155 155 char *pszUser = "root"; 156 156 char *pszPasswd = ""; 157 char szPathName[CCHMAXPATH]; 158 OPTIONS options = {"."}; 159 157 160 158 161 /* signal handler */ … … 167 170 * parse arguments. 168 171 * options: -h or -? help 172 * -b:<basepath> Basepath for output files. 169 173 * -d:<dbname> Database name 170 174 * -p:<passwd> Password … … 181 185 switch (argv[argi][1]) 182 186 { 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 183 207 case 'd': 184 208 case 'D': … … 186 210 pszDatabase = &argv[argi][3]; 187 211 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 } 189 216 break; 190 217 … … 205 232 pszPasswd = &argv[argi][3]; 206 233 else 207 fprintf(stderr, "warning: option '-p:' requires password.\n"); 234 { 235 fprintf(stderr, "error: option '-p:' requires password.\n"); 236 fFatal = TRUE; 237 } 208 238 break; 209 239 … … 213 243 pszUser = &argv[argi][3]; 214 244 else 245 { 215 246 fprintf(stderr, "error: option '-u:' requires userid.\n"); 247 fFatal = TRUE; 248 } 216 249 break; 217 250 … … 233 266 if (dbConnect(pszHost, pszUser, pszPasswd, pszDatabase)) 234 267 { 235 ulRc += processFile(argv[argi] /*, &options*/);268 ulRc += processFile(argv[argi], &options); 236 269 dbDisconnect(); 237 270 } … … 330 363 * @remark Big function! 331 364 */ 332 static unsigned long processFile(const char *pszFilename /*, const POPTIONS pOptions*/)365 static unsigned long processFile(const char *pszFilename, const POPTIONS pOptions) 333 366 { 334 367 unsigned long ulRc = 0; … … 454 487 ulRc2 = tagEndkSql(TAG_PARAMETERS); 455 488 else if (tag.isTag("!kTemplate")) /* !kTemplate */ 456 ulRc2 = tagkTemplate(TAG_PARAMETERS, phFile );489 ulRc2 = tagkTemplate(TAG_PARAMETERS, phFile, pOptions); 457 490 else if (tag.isTag("!kInclude")) /* !kInclude */ 458 491 ulRc2 = tagkInclude(TAG_PARAMETERS); 459 492 else if (tag.isTag("!kGraph")) /* !kGraph */ 460 ulRc2 = tagkGraph(TAG_PARAMETERS );493 ulRc2 = tagkGraph(TAG_PARAMETERS, pOptions); 461 494 else if (tag.isTag("!kDefine")) /* !kDefine */ 462 495 ulRc2 = tagkDefine(TAG_PARAMETERS); … … 714 747 * @returns low word: number of errors 715 748 * 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. 717 751 * @remark See TAG_PARAMETER_LIST for parameters. 718 752 * Use TAG_PARAMETERS when calling this function. 719 753 */ 720 static unsigned long tagkTemplate(TAG_PARAMETER_LIST, FILE * &phFile )754 static unsigned long tagkTemplate(TAG_PARAMETER_LIST, FILE * &phFile, const POPTIONS pOptions) 721 755 { 722 756 unsigned long ulRc = 0; … … 734 768 if (pszFilename != NULL) 735 769 { 770 char szFullFileName[CCHMAXPATH]; 736 771 if (phFile != NULL) 737 772 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 } 743 787 else 744 788 { 745 fprintf(phLog, "%s(%ld) : error: kTemplate - error opening output file '%s'.\n",746 pCurFile->getFilename(), pCurFile->getLineNumber()+1, p szFilename);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); 747 791 ulRc += 0x00000001; 748 792 } … … 799 843 * Use TAG_PARAMETERS when calling this function. 800 844 */ 801 static unsigned long tagkGraph(TAG_PARAMETER_LIST )845 static unsigned long tagkGraph(TAG_PARAMETER_LIST, const POPTIONS pOptions) 802 846 { 803 847 unsigned long ulRc = 0; … … 814 858 try 815 859 { 816 kGraph graph(tag );860 kGraph graph(tag, pOptions->pszBaseDir); 817 861 graph.showWarnings(phLog, pCurFile); 818 862 graph.save(); … … 2242 2286 /** 2243 2287 * Analyses the tag and executes SQL statements. 2244 * @param tag Tag. 2288 * @param tag Tag. 2289 * @param pszBaseDir Base output directory. 2245 2290 * @remark Throws kError::enmErrors 2246 2291 */ 2247 void kGraph::analyseTag(const kTag &tag ) throw(kError::enmErrors)2292 void kGraph::analyseTag(const kTag &tag, const char *pszBaseDir) throw(kError::enmErrors) 2248 2293 { 2249 2294 int cArgs, i; … … 2297 2342 { 2298 2343 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); 2300 2347 } 2301 2348 else if (stricmp(pszName, "title") == 0) … … 3125 3172 * @remark Throws kError::enmError on error. 3126 3173 */ 3127 kGraph::kGraph(const kTag &tag ) throw(kError::enmErrors)3174 kGraph::kGraph(const kTag &tag, const char *pszBaseDir) throw(kError::enmErrors) 3128 3175 : pGraph(NULL), enmTypeCd(unknown), enmSubTypeCd(normal), 3129 3176 pszFilename(NULL), pszTitle(NULL), pszTitleX(NULL), … … 3137 3184 try 3138 3185 { 3139 analyseTag(tag );3186 analyseTag(tag, pszBaseDir); 3140 3187 createBaseGraph(); 3141 3188 if (fLegend) … … 3163 3210 /** 3164 3211 * Saves the graph to the filename specified in the tag. 3212 * 2 3165 3213 * @returns Errorcode. 3166 3214 */
Note:
See TracChangeset
for help on using the changeset viewer.