Rev 11 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 11 | mjames | 1 | /** $Header: c:\\cygwin\\cvsroot/Vert03/cmdlib/cmdlog.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $ ** |
| 2 | mjames | 2 | |
| 3 | $Log: cmdlog.c,v $ |
||
| 4 | Revision 1.1.1.1 2003/11/04 23:34:56 mjames |
||
| 5 | Imported into local repositrory |
||
| 6 | |||
| 7 | Revision 1.14 2002/01/03 16:36:57 mjames |
||
| 8 | Method of accessing Vertical version changed to avoid |
||
| 9 | global variable |
||
| 10 | |||
| 11 | Also made DLL exportable function |
||
| 12 | |||
| 13 | Revision 1.13 2001/12/13 22:16:16 mjames |
||
| 14 | Using #ident with header to identify file |
||
| 15 | |||
| 16 | Revision 1.12 2001/11/19 10:41:52 mjames |
||
| 17 | Merged back DTC release |
||
| 18 | |||
| 19 | Revision 1.11.2.1 2001/11/16 15:09:42 mjames |
||
| 20 | Added log silent and log verbose commands, along with corresponding |
||
| 21 | low level calls. |
||
| 22 | |||
| 23 | Revision 1.11 2001/10/31 16:24:32 mjames |
||
| 24 | Changing the error message fprintf to use a format specifier instead of the |
||
| 25 | string itself. |
||
| 26 | |||
| 27 | Revision 1.10 2001/07/09 15:48:07 mjames |
||
| 28 | Placed the version string in an independent file to save time on building |
||
| 29 | all of the variants of Vertical |
||
| 30 | |||
| 31 | Revision 1.9 2001/07/09 15:35:18 mjames |
||
| 32 | Corrected argument counting bug in log lfile command |
||
| 33 | Used correct version string extracted from version.c |
||
| 34 | |||
| 35 | Revision 1.8 2001/06/19 05:24:57 mjames |
||
| 36 | Created a trap_fopen to overcome trying to write to read only files. |
||
| 37 | If this attempted in NT the file can be opened but not written to. |
||
| 38 | |||
| 39 | Revision 1.7 2001/06/06 12:10:25 mjames |
||
| 40 | Move from HPUX |
||
| 41 | |||
| 42 | Revision 1.6 2001/02/21 16:37:32 mjames |
||
| 43 | Provided a new method of defining port maps with VHDL which allows for short |
||
| 44 | cut definitions. |
||
| 45 | |||
| 46 | Cleaned up TCL/Tk interfacing issues |
||
| 47 | |||
| 48 | Revision 1.5 2001/02/01 21:41:44 mjames |
||
| 49 | Made the code begin to compile without TCL/TK |
||
| 50 | |||
| 51 | Revision 1.4 2001/01/26 21:50:10 mjames |
||
| 52 | Managed to get vertical non TCL to compile again |
||
| 53 | |||
| 54 | Conversion to argv, argc[] mode of operation continues |
||
| 55 | |||
| 56 | Revision 1.3 2001/01/04 21:26:54 mjames |
||
| 57 | Modifications to add in the TCL style |
||
| 58 | argument list to all of the functions |
||
| 59 | . |
||
| 60 | |||
| 61 | Revision 1.2 2001/01/02 07:53:51 mjames |
||
| 62 | Made changes to allow for interface with TCL/Tk |
||
| 63 | |||
| 64 | Revision 1.1.1.1 2000/10/19 21:58:35 mjames |
||
| 65 | Mike put it here |
||
| 66 | |||
| 67 | |||
| 68 | |||
| 69 | **********************************************************************************************************/ |
||
| 70 | |||
| 71 | |||
| 11 | mjames | 72 | |
| 73 | #include <stdio.h> |
||
| 74 | #include <string.h> |
||
| 75 | #include <stdlib.h> |
||
| 76 | #include <stdarg.h> |
||
| 77 | |||
| 78 | |||
| 79 | #include "vertcl_main.h" |
||
| 80 | #include "cmdparse.h" |
||
| 2 | mjames | 81 | #include "cmdexec.h" |
| 82 | #include "cmdutil.h" |
||
| 11 | mjames | 83 | |
| 2 | mjames | 84 | #include "expression.h" |
| 85 | #include "generic.h" |
||
| 11 | mjames | 86 | #include "database.h" |
| 2 | mjames | 87 | #include "printout.h" |
| 11 | mjames | 88 | #include "cmdlog.h" |
| 2 | mjames | 89 | #include "version.h" |
| 90 | |||
| 91 | static FILE *LogDisplay = NULL; |
||
| 11 | mjames | 92 | static FILE *LogError = NULL; |
| 93 | static FILE *LogFile = NULL; |
||
| 2 | mjames | 94 | |
| 95 | static int TransLevel = TRANSOFF; |
||
| 96 | /* added at TH request */ |
||
| 11 | mjames | 97 | static int LogDisableFlag = 0; |
| 2 | mjames | 98 | |
| 11 | mjames | 99 | #ident "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/cmdlib/cmdlog.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $" |
| 2 | mjames | 100 | |
| 11 | mjames | 101 | /***************************************** Setup error logging ***********************************************/ |
| 2 | mjames | 102 | |
| 11 | mjames | 103 | void InitErrorLog(void) { |
| 104 | LogDisplay = stdout; /* moved to satisfy GCC */ |
||
| 105 | LogError = trap_fopen("vertical.errs","w+"); |
||
| 106 | if (LogError) { |
||
| 107 | print_header(LogError,Vertical_Version); |
||
| 108 | fflush(LogError); |
||
| 109 | } |
||
| 110 | } |
||
| 2 | mjames | 111 | |
| 11 | mjames | 112 | /***************************************** Setup error logging ***********************************************/ |
| 2 | mjames | 113 | |
| 11 | mjames | 114 | void EndErrorLog(void) { |
| 115 | char str[1024]; |
||
| 116 | if (LogFile) |
||
| 117 | fclose(LogFile); |
||
| 118 | if (LogError) { |
||
| 119 | fflush(LogError); /* flush it then re-seek to top */ |
||
| 120 | fseek(LogError,0,SEEK_SET); |
||
| 121 | Log(LOG_GENERAL,"-- start ERROR LOG summary --\n\n"); |
||
| 122 | while(!feof(LogError)) { |
||
| 123 | fgets(str,1023,LogError); |
||
| 124 | str[1023]=0; |
||
| 125 | Log(LOG_GENERAL,str,stdout); |
||
| 126 | } |
||
| 127 | Log(LOG_GENERAL,"-- end ERROR LOG summary --\n\n"); |
||
| 128 | fclose(LogError); |
||
| 129 | } |
||
| 130 | } |
||
| 2 | mjames | 131 | |
| 132 | /****************************************************************************************/ |
||
| 133 | /* log a command into the console */ |
||
| 134 | |||
| 11 | mjames | 135 | void Log_Command(char * Format, ...) { |
| 136 | va_list ArgPtr; /* Get an argument pointer */ |
||
| 137 | char str[1024]; |
||
| 138 | /* silence logging */ |
||
| 139 | if (LogDisableFlag) |
||
| 140 | { |
||
| 141 | return; |
||
| 142 | } |
||
| 2 | mjames | 143 | |
| 11 | mjames | 144 | |
| 145 | va_start(ArgPtr, Format); /* Set pointer to 1st arg after the format string */ |
||
| 146 | vsprintf(str, Format, ArgPtr); /* write all the 'Messages' to the string */ |
||
| 147 | va_end(ArgPtr); |
||
| 2 | mjames | 148 | #if defined CMDLOG_TCL |
| 11 | mjames | 149 | if (Tcl_Mode==Tcl_GUI) |
| 150 | Et_EvalF(Tcl_interp,".con.t insert end \"\n%q\"",str); |
||
| 151 | else |
||
| 2 | mjames | 152 | #endif |
| 11 | mjames | 153 | printf("%s",str); |
| 154 | } |
||
| 2 | mjames | 155 | |
| 156 | |||
| 11 | mjames | 157 | /***************************************** Message handler ***********************************************/ |
| 2 | mjames | 158 | |
| 11 | mjames | 159 | __declspec (dllexport)void Log (EnumLogLevel LoggingLevel, char * Format, ...) |
| 2 | mjames | 160 | |
| 11 | mjames | 161 | { |
| 162 | va_list ArgPtr; /* Get an argument pointer */ |
||
| 163 | char str[1024]; |
||
| 164 | /* silence logging */ |
||
| 165 | if (LogDisableFlag) |
||
| 166 | { |
||
| 167 | return; |
||
| 168 | } |
||
| 2 | mjames | 169 | |
| 11 | mjames | 170 | |
| 171 | |||
| 172 | va_start(ArgPtr, Format); /* Set pointer to 1st arg after the format string */ |
||
| 173 | vsprintf(str, Format, ArgPtr); /* write all the 'Messages' to the string */ |
||
| 174 | va_end(ArgPtr); |
||
| 175 | |||
| 176 | if (LoggingLevel == LOG_ERROR) { |
||
| 177 | if (LogError != NULL) |
||
| 178 | fprintf (LogError ,"%s" , str); |
||
| 179 | } |
||
| 180 | /* stick it in the TCL console for now */ |
||
| 181 | if (LogDisplay != NULL) |
||
| 2 | mjames | 182 | #if defined CMDLOG_TCL |
| 11 | mjames | 183 | if (Tcl_Mode == Tcl_GUI) |
| 184 | Et_EvalF(Tcl_interp,".con.t insert end \"%q\"",str); |
||
| 185 | else |
||
| 2 | mjames | 186 | #endif |
| 11 | mjames | 187 | printf("%s",str); |
| 2 | mjames | 188 | |
| 11 | mjames | 189 | /* log everything to the file anyway */ |
| 2 | mjames | 190 | |
| 11 | mjames | 191 | if (TransLevel == TRANSON && LogFile != NULL) |
| 192 | fprintf (LogFile, str); |
||
| 2 | mjames | 193 | |
| 11 | mjames | 194 | } |
| 195 | |||
| 2 | mjames | 196 | /*********************************************************************************************************/ |
| 197 | |||
| 198 | int SetTrans (int x) |
||
| 199 | |||
| 11 | mjames | 200 | { |
| 2 | mjames | 201 | |
| 11 | mjames | 202 | switch (x) |
| 203 | { |
||
| 204 | case TRANSOFF : Log (LOG_GENERAL, "Transcript disabled\n"); TransLevel = TRANSOFF; break; |
||
| 205 | case TRANSON : TransLevel = TRANSON; Log (LOG_GENERAL, "Transcript enabled\n"); break; |
||
| 206 | case TRANSREAD : return (TransLevel); |
||
| 207 | default : return (UNKNOWNCMD); |
||
| 208 | } |
||
| 209 | return (OKCMD); |
||
| 210 | } |
||
| 211 | |||
| 2 | mjames | 212 | /*********************************************************************************************************/ |
| 11 | mjames | 213 | /* |
| 2 | mjames | 214 | @title |
| 215 | log transoff |
||
| 11 | mjames | 216 | @text |
| 2 | mjames | 217 | If this command is used then further logging will not be written |
| 11 | mjames | 218 | to the log file |
| 2 | mjames | 219 | @end |
| 220 | */ |
||
| 221 | |||
| 222 | int LogTrOff (ET_TCLARGS) |
||
| 11 | mjames | 223 | { SetTrans(TRANSOFF); return (OKCMD); } |
| 2 | mjames | 224 | |
| 11 | mjames | 225 | |
| 226 | /* |
||
| 2 | mjames | 227 | @title |
| 228 | log transon |
||
| 11 | mjames | 229 | @text |
| 2 | mjames | 230 | If this command is used then logging output will be written |
| 11 | mjames | 231 | to the log file |
| 2 | mjames | 232 | @end |
| 233 | */ |
||
| 234 | |||
| 235 | int LogTrOn (ET_TCLARGS) |
||
| 11 | mjames | 236 | { SetTrans(TRANSON); return (OKCMD); } |
| 2 | mjames | 237 | |
| 238 | /*********************************************************************************************************/ |
||
| 239 | |||
| 240 | int OpenLog (char *LogName) |
||
| 11 | mjames | 241 | { |
| 242 | SetTrans(TRANSON); |
||
| 243 | LogFile = fopen (LogName, "w"); |
||
| 244 | fprintf (LogFile, "#\n"); |
||
| 245 | fprintf (LogFile, "# Produced by VERTICAL version %s\n",Vertical_Version); |
||
| 246 | fprintf (LogFile, "#\n\n"); |
||
| 247 | return (OKCMD); |
||
| 248 | } |
||
| 2 | mjames | 249 | |
| 250 | /*********************************************************************************************************/ |
||
| 251 | |||
| 252 | int CloseLog (void) |
||
| 11 | mjames | 253 | { |
| 2 | mjames | 254 | |
| 11 | mjames | 255 | if (LogFile != NULL) |
| 256 | { |
||
| 257 | Log (LOG_GENERAL, "Close current log file\n"); |
||
| 258 | fclose (LogFile); |
||
| 259 | LogFile = NULL; |
||
| 260 | } |
||
| 261 | return (OKCMD); |
||
| 262 | } |
||
| 263 | |||
| 2 | mjames | 264 | /*********************************************************************************************************/ |
| 265 | |||
| 266 | int LogComm (ET_TCLARGS) |
||
| 11 | mjames | 267 | { |
| 268 | int i; |
||
| 2 | mjames | 269 | |
| 11 | mjames | 270 | if (argc >0) |
| 271 | { |
||
| 272 | Log (LOG_GENERAL, "# LOGGING COMMENT:"); |
||
| 273 | for (i=1; i<argc; i++) |
||
| 274 | Log (LOG_GENERAL, " %s", argv[i]); |
||
| 275 | Log (LOG_GENERAL, "\n"); |
||
| 276 | } |
||
| 277 | else |
||
| 278 | return (TCL_ERROR); |
||
| 279 | return (TCL_OK); |
||
| 280 | } |
||
| 2 | mjames | 281 | |
| 282 | /*********************************************************************************************************/ |
||
| 283 | /* |
||
| 284 | @title |
||
| 285 | log lfile <filename> |
||
| 286 | @text |
||
| 287 | All logged output will be written to the named file. |
||
| 288 | @end |
||
| 289 | */ |
||
| 290 | |||
| 291 | int LogLFile (ET_TCLARGS) |
||
| 11 | mjames | 292 | { |
| 2 | mjames | 293 | |
| 11 | mjames | 294 | if (argc > 0) |
| 295 | { |
||
| 296 | Log (LOG_GENERAL, "-- Set log filename: <%s>\n\n", argv[0]); |
||
| 297 | CloseLog(); |
||
| 298 | OpenLog (argv[0]); |
||
| 299 | return (TCL_OK); |
||
| 300 | } |
||
| 301 | else |
||
| 302 | return (TCL_ERROR); |
||
| 303 | } |
||
| 304 | |||
| 2 | mjames | 305 | /*********************************************************************************************************/ |
| 11 | mjames | 306 | /* enable / disable global silencing flag, one call works |
| 2 | mjames | 307 | as a command menu handler */ |
| 308 | |||
| 11 | mjames | 309 | void LogSilent(void) |
| 310 | { |
||
| 311 | LogDisableFlag =1; |
||
| 312 | } |
||
| 2 | mjames | 313 | |
| 11 | mjames | 314 | |
| 2 | mjames | 315 | /* |
| 316 | @title |
||
| 317 | log silent |
||
| 318 | @text |
||
| 319 | If this command is used, all further log messages are suppressed |
||
| 320 | @end |
||
| 321 | */ |
||
| 322 | |||
| 11 | mjames | 323 | int LogSilentHndl(ET_TCLARGS) |
| 324 | { |
||
| 325 | LogDisableFlag =1; |
||
| 326 | return 0; |
||
| 327 | } |
||
| 2 | mjames | 328 | |
| 329 | /*********************************************************************************************************/ |
||
| 11 | mjames | 330 | void LogVerbose(void) |
| 331 | { |
||
| 332 | LogDisableFlag = 0; |
||
| 333 | } |
||
| 2 | mjames | 334 | |
| 335 | /* |
||
| 336 | @title |
||
| 337 | log verbose |
||
| 338 | @text |
||
| 11 | mjames | 339 | If this command is used, all further log messages are enabled. |
| 2 | mjames | 340 | @end |
| 341 | */ |
||
| 342 | |||
| 11 | mjames | 343 | int LogVerboseHndl(ET_TCLARGS) |
| 344 | { |
||
| 345 | LogDisableFlag = 0; |
||
| 346 | return 0; |
||
| 347 | } |
||
| 2 | mjames | 348 | |
| 349 | |||
| 350 | |||
| 11 | mjames | 351 | /************************************* Logging command tokens ********************************************/ |
| 352 | |||
| 353 | CommandMenu LoggingMenu = |
||
| 354 | { |
||
| 355 | {"comm", 2, LogComm, NULL, "Add comment to log file",NULL,NULL}, |
||
| 356 | {"lfile", 2, LogLFile,NULL, "Open new log file","filename",NULL}, |
||
| 357 | {"troff", 4, LogTrOff,NULL, "Log file transcript on",NULL,NULL}, |
||
| 358 | {"tron", 4, LogTrOn, NULL, "Log file transcript off",NULL,NULL} , |
||
| 359 | {"silent",4, LogSilentHndl, NULL, "All log output off",NULL,NULL}, |
||
| 360 | {"verbose",4, LogVerboseHndl, NULL, "All log output resumed",NULL,NULL}, |
||
| 361 | {NULL , 0, NULL, NULL, NULL,NULL,NULL} , |
||
| 362 | }; |
||
| 363 | |||
| 2 | mjames | 364 | /*********************************************************************************************************/ |
| 11 | mjames | 365 | |
| 366 |