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