Subversion Repositories Vertical

Rev

Rev 2 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 11
Line 1... Line 1...
1
/** $Header: c:\\cygwin\\cvsroot/Vert03/cmdlib/cmdlog.c,v 1.1.1.1 2003/11/04 23:34:56 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)
2
Exp $ ** Author: Kevin Ross (x6143) Philips Semiconductors Limited. Millbrook Industrial
3
                      Philips Semiconductors Limited.
3
Estate, Southampton, SO9 7BH. England.
4
                      Millbrook Industrial Estate, Southampton, SO9 7BH. England.
4
 
5
 
5
 
6
 
6
 
7
 
7
                Date: 12th May 1993
8
                Date: 12th May 1993
8
 
9
 
Line 76... Line 77...
76
 
77
 
77
 
78
 
78
 
79
 
79
**********************************************************************************************************/
80
**********************************************************************************************************/
80
 
81
 
81
#include "cmdlog.h"
-
 
82
 
82
 
-
 
83
 
-
 
84
#include <stdio.h>
-
 
85
#include <string.h>
-
 
86
#include <stdlib.h>
83
#include "cmdexec.h"
87
#include <stdarg.h>
-
 
88
 
-
 
89
 
-
 
90
#include "vertcl_main.h"
84
#include "cmdparse.h"
91
#include "cmdparse.h"
-
 
92
#include "cmdexec.h"
85
#include "cmdutil.h"
93
#include "cmdutil.h"
86
#include "database.h"
-
 
-
 
94
 
87
#include "expression.h"
95
#include "expression.h"
88
#include "generic.h"
96
#include "generic.h"
-
 
97
#include "database.h"
89
#include "printout.h"
98
#include "printout.h"
-
 
99
#include "cmdlog.h"
90
#include "version.h"
100
#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
 
101
 
98
static FILE *LogDisplay = NULL;
102
static FILE *LogDisplay = NULL;
99
static FILE *LogError = NULL;
103
static FILE *LogError   = NULL;
100
static FILE *LogFile = NULL;
104
static FILE *LogFile    = NULL;
101
 
105
 
102
static int TransLevel = TRANSOFF;
106
static int TransLevel = TRANSOFF;
103
/* added at TH request */
107
/* added at TH request */
104
static int LogDisableFlag = 0;
108
static int LogDisableFlag  = 0;
105
 
109
 
106
#ident                                                                                        \
-
 
107
    "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/cmdlib/cmdlog.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $"
110
#ident "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/cmdlib/cmdlog.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $"
108
 
111
 
109
/***************************************** Setup error logging
112
/***************************************** Setup error logging ***********************************************/
110
 * ***********************************************/
-
 
111
 
113
 
112
void InitErrorLog (void)
114
void InitErrorLog(void) {
113
{
-
 
114
        LogDisplay = stdout; /* moved to satisfy GCC */
115
  LogDisplay = stdout; /* moved to satisfy GCC */
115
        LogError = trap_fopen ("vertical.errs", "w+");
116
  LogError = trap_fopen("vertical.errs","w+");
116
        if (LogError)
117
  if (LogError) {
117
        {
-
 
118
                print_header (LogError, Vertical_Version);
118
    print_header(LogError,Vertical_Version);
119
                fflush (LogError);
119
    fflush(LogError);
120
        }
120
    }
121
}
121
  }
122
 
122
 
123
/***************************************** Setup error logging
123
/***************************************** Setup error logging ***********************************************/
124
 * ***********************************************/
-
 
125
 
124
 
126
void EndErrorLog (void)
125
void EndErrorLog(void) {
127
{
-
 
128
        char str[1024];
126
  char str[1024];
129
        if (LogFile)
127
  if (LogFile)
130
                fclose (LogFile);
128
    fclose(LogFile);
131
        if (LogError)
129
  if (LogError) {
132
        {
-
 
133
                fflush (LogError); /* flush it then re-seek to top */
130
    fflush(LogError); /* flush it then re-seek to top */
134
                fseek (LogError, 0, SEEK_SET);
131
    fseek(LogError,0,SEEK_SET);
135
                Log (LOG_GENERAL, "-- start ERROR LOG summary --\n\n");
132
    Log(LOG_GENERAL,"-- start ERROR LOG summary --\n\n");
136
                while (!feof (LogError))
133
    while(!feof(LogError)) {
137
                {
-
 
138
                        fgets (str, 1023, LogError);
134
      fgets(str,1023,LogError);
139
                        str[1023] = 0;
135
      str[1023]=0;
140
                        Log (LOG_GENERAL, str, stdout);
136
      Log(LOG_GENERAL,str,stdout);
141
                }
137
      }
142
                Log (LOG_GENERAL, "-- end ERROR LOG summary --\n\n");
138
    Log(LOG_GENERAL,"-- end ERROR LOG summary --\n\n");
143
                fclose (LogError);
139
    fclose(LogError);
144
        }
140
    }
145
}
141
  }
146
 
142
 
147
/****************************************************************************************/
143
/****************************************************************************************/
148
/* log a command into the console */
144
/* log a command into the console */
149
 
145
 
150
void Log_Command (char *Format, ...)
146
void Log_Command(char * Format, ...) {
151
{
-
 
152
        va_list ArgPtr; /* Get an argument pointer */
147
   va_list ArgPtr;                           /* Get an argument pointer */
153
        char str[1024];
148
   char str[1024];
154
        /* silence logging */
149
/* silence logging */
155
        if (LogDisableFlag)
150
   if (LogDisableFlag)
156
        {
151
     {
157
                return;
152
     return;
158
        }
153
     }
-
 
154
 
159
 
155
 
160
        va_start (ArgPtr, Format);      /* Set pointer to 1st arg after the format string */
156
   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 */
157
   vsprintf(str, Format, ArgPtr);            /* write all the 'Messages' to the string */
162
        va_end (ArgPtr);
158
   va_end(ArgPtr);  
163
#if defined CMDLOG_TCL
159
#if defined CMDLOG_TCL
164
        if (Tcl_Mode == Tcl_GUI)
160
   if (Tcl_Mode==Tcl_GUI)
165
                Et_EvalF (Tcl_interp, ".con.t insert end \"\n%q\"", str);
161
     Et_EvalF(Tcl_interp,".con.t insert end \"\n%q\"",str);
166
        else
162
   else
167
#endif
163
#endif
168
                printf ("%s", str);
164
     printf("%s",str);
-
 
165
   }
-
 
166
 
-
 
167
 
-
 
168
/***************************************** Message handler ***********************************************/
-
 
169
 
-
 
170
__declspec (dllexport)void Log (EnumLogLevel LoggingLevel, char * Format, ...)
169
}
171
 
-
 
172
   {
-
 
173
   va_list ArgPtr;                           /* Get an argument pointer */
-
 
174
   char str[1024];
-
 
175
/* silence logging */
-
 
176
   if (LogDisableFlag)
-
 
177
     {
-
 
178
     return;
-
 
179
     }
-
 
180
 
170
 
181
 
171
/***************************************** Message handler
-
 
172
 * ***********************************************/
-
 
173
 
182
 
174
__declspec(dllexport) void Log (EnumLogLevel LoggingLevel, char *Format, ...)
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);
175
 
186
 
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)
187
   if (LoggingLevel == LOG_ERROR) {
190
        {
-
 
191
                if (LogError != NULL)
188
     if (LogError   != NULL)
192
                        fprintf (LogError, "%s", str);
189
     fprintf (LogError ,"%s" , str);
193
        }
190
   }
194
        /* stick it in the TCL console for now */
191
   /* stick it in the TCL console for now */
195
        if (LogDisplay != NULL)
192
   if (LogDisplay != NULL)
196
#if defined CMDLOG_TCL
193
#if defined CMDLOG_TCL
197
                if (Tcl_Mode == Tcl_GUI)
194
   if (Tcl_Mode == Tcl_GUI)
198
                        Et_EvalF (Tcl_interp, ".con.t insert end \"%q\"", str);
195
     Et_EvalF(Tcl_interp,".con.t insert end \"%q\"",str);
199
                else
196
   else
200
#endif
197
#endif
201
                        printf ("%s", str);
198
     printf("%s",str);
202
 
199
 
203
        /* log everything to the file anyway */
200
    /* log everything to the file anyway */
204
 
201
 
205
        if (TransLevel == TRANSON && LogFile != NULL)
202
   if (TransLevel == TRANSON && LogFile    != NULL)
206
                fprintf (LogFile, str);
203
      fprintf (LogFile,    str);
207
}
204
 
-
 
205
   }
208
 
206
 
209
/*********************************************************************************************************/
207
/*********************************************************************************************************/
210
 
208
 
211
int SetTrans (int x)
209
int SetTrans (int x)
212
 
210
 
-
 
211
   {
213
{
212
 
214
        switch (x)
213
   switch (x)
215
        {
214
      {
216
        case TRANSOFF:
-
 
217
                Log (LOG_GENERAL, "Transcript disabled\n");
215
      case TRANSOFF  : Log (LOG_GENERAL, "Transcript disabled\n"); TransLevel = TRANSOFF; break;
218
                TransLevel = TRANSOFF;
-
 
219
                break;
-
 
220
        case TRANSON:
-
 
221
                TransLevel = TRANSON;
-
 
222
                Log (LOG_GENERAL, "Transcript enabled\n");
216
      case TRANSON   : TransLevel = TRANSON;  Log (LOG_GENERAL, "Transcript enabled\n");  break;
223
                break;
-
 
224
        case TRANSREAD:
-
 
225
                return (TransLevel);
217
      case TRANSREAD : return (TransLevel);
226
        default:
-
 
227
                return (UNKNOWNCMD);
218
      default        : return (UNKNOWNCMD);
228
        }
219
      }
229
        return (OKCMD);
220
   return (OKCMD);
230
}
221
   }
231
 
222
 
232
/*********************************************************************************************************/
223
/*********************************************************************************************************/
233
/*
224
/*
234
@title
225
@title
235
log transoff
226
log transoff
236
@text
227
@text
237
If this command is used then further logging will not be written
228
If this command is used then further logging will not be written
238
to the log file
229
to the log file
239
@end
230
@end
240
*/
231
*/
241
 
232
 
242
int LogTrOff (ET_TCLARGS)
233
int LogTrOff (ET_TCLARGS)
243
{
-
 
244
        SetTrans (TRANSOFF);
234
   { SetTrans(TRANSOFF); return (OKCMD); }
245
        return (OKCMD);
-
 
246
}
-
 
247
 
235
 
-
 
236
 
248
/*
237
/*
249
@title
238
@title
250
log transon
239
log transon
251
@text
240
@text
252
If this command is used then logging output will be written
241
If this command is used then logging output will be written
253
to the log file
242
to the log file
254
@end
243
@end
255
*/
244
*/
256
 
245
 
257
int LogTrOn (ET_TCLARGS)
246
int LogTrOn (ET_TCLARGS)
258
{
-
 
259
        SetTrans (TRANSON);
-
 
260
        return (OKCMD);
247
   { SetTrans(TRANSON); return (OKCMD); }
261
}
-
 
262
 
248
 
263
/*********************************************************************************************************/
249
/*********************************************************************************************************/
264
 
250
 
265
int OpenLog (char *LogName)
251
int OpenLog (char *LogName)
266
{
252
   {
267
        SetTrans (TRANSON);
253
   SetTrans(TRANSON);
268
        LogFile = fopen (LogName, "w");
254
   LogFile = fopen (LogName, "w");
269
        fprintf (LogFile, "#\n");
255
   fprintf (LogFile, "#\n");
270
        fprintf (LogFile, "# Produced by VERTICAL version %s\n", Vertical_Version);
256
   fprintf (LogFile, "# Produced by VERTICAL version %s\n",Vertical_Version);
271
        fprintf (LogFile, "#\n\n");
257
   fprintf (LogFile, "#\n\n");
272
        return (OKCMD);
258
   return (OKCMD);
273
}
259
   }
274
 
260
 
275
/*********************************************************************************************************/
261
/*********************************************************************************************************/
276
 
262
 
277
int CloseLog (void)
263
int CloseLog (void)
-
 
264
   {
278
{
265
 
279
        if (LogFile != NULL)
266
   if (LogFile != NULL)
280
        {
267
      {
281
                Log (LOG_GENERAL, "Close current log file\n");
268
      Log (LOG_GENERAL, "Close current log file\n");
282
                fclose (LogFile);
269
      fclose (LogFile);
283
                LogFile = NULL;
270
      LogFile = NULL;
284
        }
271
      }
285
        return (OKCMD);
272
   return (OKCMD);
286
}
273
   }
287
 
274
 
288
/*********************************************************************************************************/
275
/*********************************************************************************************************/
289
 
276
 
290
int LogComm (ET_TCLARGS)
277
int LogComm (ET_TCLARGS)
291
{
278
   {
292
        int i;
279
   int i;
293
 
280
 
294
        if (argc > 0)
281
   if (argc >0)
295
        {
282
      {
296
                Log (LOG_GENERAL, "# LOGGING COMMENT:");
283
      Log (LOG_GENERAL, "# LOGGING COMMENT:");
297
                for (i = 1; i < argc; i++)
284
      for (i=1; i<argc; i++)
298
                        Log (LOG_GENERAL, " %s", argv[i]);
285
         Log (LOG_GENERAL, " %s", argv[i]);
299
                Log (LOG_GENERAL, "\n");
286
      Log (LOG_GENERAL, "\n");
300
        }
287
      }
301
        else
288
   else
302
                return (TCL_ERROR);
289
      return (TCL_ERROR);
303
        return (TCL_OK);
290
   return (TCL_OK);
304
}
291
   }
305
 
292
 
306
/*********************************************************************************************************/
293
/*********************************************************************************************************/
307
/*
294
/*
308
@title
295
@title
309
log lfile <filename>
296
log lfile <filename>
Line 311... Line 298...
311
All logged output will be written to the named file.
298
All logged output will be written to the named file.
312
@end
299
@end
313
*/
300
*/
314
 
301
 
315
int LogLFile (ET_TCLARGS)
302
int LogLFile (ET_TCLARGS)
-
 
303
   {
316
{
304
 
317
        if (argc > 0)
305
   if (argc > 0)
318
        {
306
      {
319
                Log (LOG_GENERAL, "-- Set log filename: <%s>\n\n", argv[0]);
307
      Log (LOG_GENERAL, "-- Set log filename: <%s>\n\n", argv[0]);
320
                CloseLog ();
308
      CloseLog();
321
                OpenLog (argv[0]);
309
      OpenLog (argv[0]);
322
                return (TCL_OK);
310
      return (TCL_OK);
323
        }
311
      }
324
        else
312
   else
325
                return (TCL_ERROR);
313
      return (TCL_ERROR);
326
}
314
   }
327
 
315
 
328
/*********************************************************************************************************/
316
/*********************************************************************************************************/
329
/* enable / disable global silencing flag, one call works
317
/* enable / disable global silencing flag, one call works
330
   as a command menu handler */
318
   as a command menu handler */
331
 
319
 
332
void LogSilent (void)
320
void LogSilent(void)
333
{
321
  {
334
        LogDisableFlag = 1;
322
  LogDisableFlag =1;
-
 
323
  }
335
}
324
 
336
 
325
 
337
/*
326
/*
338
@title
327
@title
339
log silent
328
log silent
340
@text
329
@text
341
If this command is used, all further log messages are suppressed
330
If this command is used, all further log messages are suppressed
342
@end
331
@end
343
*/
332
*/
344
 
333
 
345
int LogSilentHndl (ET_TCLARGS)
334
int LogSilentHndl(ET_TCLARGS)
346
{
335
  {
347
        LogDisableFlag = 1;
336
  LogDisableFlag =1;
348
        return 0;
337
  return 0;
349
}
338
  }
350
 
339
 
351
/*********************************************************************************************************/
340
/*********************************************************************************************************/
352
void LogVerbose (void)
341
void LogVerbose(void)
353
{
342
  {
354
        LogDisableFlag = 0;
343
  LogDisableFlag = 0;
355
}
344
  }
356
 
345
 
357
/*
346
/*
358
@title
347
@title
359
log verbose
348
log verbose
360
@text
349
@text
361
If this command is used, all further log messages are enabled.
350
If this command is used, all further log messages are enabled.
362
@end
351
@end
363
*/
352
*/
364
 
353
 
365
int LogVerboseHndl (ET_TCLARGS)
354
int LogVerboseHndl(ET_TCLARGS)
366
{
355
  {
367
        LogDisableFlag = 0;
356
  LogDisableFlag = 0;
368
        return 0;
357
  return 0;
-
 
358
  }
-
 
359
 
369
}
360
 
370
 
361
 
371
/************************************* Logging command tokens
362
/************************************* Logging command tokens ********************************************/
372
 * ********************************************/
-
 
373
 
363
 
374
CommandMenu const LoggingMenu = {
364
   CommandMenu LoggingMenu =
-
 
365
      {
375
    {"comm", 2, LogComm, NULL, "Add comment to log file", NULL, NULL},
366
      {"comm",  2, LogComm, NULL, "Add comment to log file",NULL,NULL},
376
    {"lfile", 2, LogLFile, NULL, "Open new log file", "filename", NULL},
367
      {"lfile", 2, LogLFile,NULL, "Open new log file","filename",NULL},
377
    {"troff", 4, LogTrOff, NULL, "Log file transcript on", NULL, NULL},
368
      {"troff", 4, LogTrOff,NULL, "Log file transcript on",NULL,NULL},
378
    {"tron", 4, LogTrOn, NULL, "Log file transcript off", NULL, NULL},
369
      {"tron",  4, LogTrOn, NULL, "Log file transcript off",NULL,NULL} ,
379
    {"silent", 4, LogSilentHndl, NULL, "All log output off", NULL, NULL},
370
      {"silent",4, LogSilentHndl, NULL, "All log output off",NULL,NULL},
380
    {"verbose", 4, LogVerboseHndl, NULL, "All log output resumed", NULL, NULL},
371
      {"verbose",4, LogVerboseHndl, NULL, "All log output resumed",NULL,NULL},
381
    {NULL, 0, NULL, NULL, NULL, NULL, NULL},
372
      {NULL  ,  0, NULL,    NULL, NULL,NULL,NULL} ,
382
};
373
      };
383
 
374
 
384
/*********************************************************************************************************/
375
/*********************************************************************************************************/
-
 
376
 
-
 
377