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