/** $Header: c:\\cygwin\\cvsroot/Vert03/cmdlib/cmdlog.c,v 1.1.1.1 2003/11/04 23:34:56 mjames
Exp $ ** Author: Kevin Ross (x6143) Philips Semiconductors Limited. Millbrook Industrial
Estate, Southampton, SO9 7BH. England.
Date: 12th May 1993
Comment: This program serves the 'LOGGING' menu for the SFC3 evaluation software
$Log: cmdlog.c,v $
Revision 1.1.1.1 2003/11/04 23:34:56 mjames
Imported into local repositrory
Revision 1.14 2002/01/03 16:36:57 mjames
Method of accessing Vertical version changed to avoid
global variable
Also made DLL exportable function
Revision 1.13 2001/12/13 22:16:16 mjames
Using #ident with header to identify file
Revision 1.12 2001/11/19 10:41:52 mjames
Merged back DTC release
Revision 1.11.2.1 2001/11/16 15:09:42 mjames
Added log silent and log verbose commands, along with corresponding
low level calls.
Revision 1.11 2001/10/31 16:24:32 mjames
Changing the error message fprintf to use a format specifier instead of the
string itself.
Revision 1.10 2001/07/09 15:48:07 mjames
Placed the version string in an independent file to save time on building
all of the variants of Vertical
Revision 1.9 2001/07/09 15:35:18 mjames
Corrected argument counting bug in log lfile command
Used correct version string extracted from version.c
Revision 1.8 2001/06/19 05:24:57 mjames
Created a trap_fopen to overcome trying to write to read only files.
If this attempted in NT the file can be opened but not written to.
Revision 1.7 2001/06/06 12:10:25 mjames
Move from HPUX
Revision 1.6 2001/02/21 16:37:32 mjames
Provided a new method of defining port maps with VHDL which allows for short
cut definitions.
Cleaned up TCL/Tk interfacing issues
Revision 1.5 2001/02/01 21:41:44 mjames
Made the code begin to compile without TCL/TK
Revision 1.4 2001/01/26 21:50:10 mjames
Managed to get vertical non TCL to compile again
Conversion to argv, argc[] mode of operation continues
Revision 1.3 2001/01/04 21:26:54 mjames
Modifications to add in the TCL style
argument list to all of the functions
.
Revision 1.2 2001/01/02 07:53:51 mjames
Made changes to allow for interface with TCL/Tk
Revision 1.1.1.1 2000/10/19 21:58:35 mjames
Mike put it here
**********************************************************************************************************/
#include "cmdlog.h"
#include "cmdexec.h"
#include "cmdparse.h"
#include "cmdutil.h"
#include "database.h"
#include "expression.h"
#include "generic.h"
#include "printout.h"
#include "version.h"
#include "vertcl_main.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static FILE *LogDisplay = NULL;
static FILE *LogError = NULL;
static FILE *LogFile = NULL;
static int TransLevel = TRANSOFF;
/* added at TH request */
static int LogDisableFlag = 0;
#ident \
"@(#)$Header: c:\\cygwin\\cvsroot/Vert03/cmdlib/cmdlog.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $"
/***************************************** Setup error logging
* ***********************************************/
void InitErrorLog (void)
{
LogDisplay = stdout; /* moved to satisfy GCC */
LogError = trap_fopen ("vertical.errs", "w+");
if (LogError)
{
print_header (LogError, Vertical_Version);
}
}
/***************************************** Setup error logging
* ***********************************************/
void EndErrorLog (void)
{
char str[1024];
if (LogFile)
if (LogError)
{
fflush (LogError
); /* flush it then re-seek to top */
fseek (LogError
, 0, SEEK_SET
);
Log (LOG_GENERAL, "-- start ERROR LOG summary --\n\n");
{
fgets (str
, 1023, LogError
);
str[1023] = 0;
Log (LOG_GENERAL, str, stdout);
}
Log (LOG_GENERAL, "-- end ERROR LOG summary --\n\n");
}
}
/****************************************************************************************/
/* log a command into the console */
void Log_Command (char *Format, ...)
{
va_list ArgPtr; /* Get an argument pointer */
char str[1024];
/* silence logging */
if (LogDisableFlag)
{
return;
}
va_start (ArgPtr
, Format
); /* Set pointer to 1st arg after the format string */
vsprintf (str
, Format
, ArgPtr
); /* write all the 'Messages' to the string */
#if defined CMDLOG_TCL
if (Tcl_Mode == Tcl_GUI)
Et_EvalF (Tcl_interp, ".con.t insert end \"\n%q\"", str);
else
#endif
}
/***************************************** Message handler
* ***********************************************/
__declspec(dllexport) void Log (EnumLogLevel LoggingLevel, char *Format, ...)
{
va_list ArgPtr; /* Get an argument pointer */
char str[1024];
/* silence logging */
if (LogDisableFlag)
{
return;
}
va_start (ArgPtr
, Format
); /* Set pointer to 1st arg after the format string */
vsprintf (str
, Format
, ArgPtr
); /* write all the 'Messages' to the string */
if (LoggingLevel == LOG_ERROR)
{
if (LogError != NULL)
}
/* stick it in the TCL console for now */
if (LogDisplay != NULL)
#if defined CMDLOG_TCL
if (Tcl_Mode == Tcl_GUI)
Et_EvalF (Tcl_interp, ".con.t insert end \"%q\"", str);
else
#endif
/* log everything to the file anyway */
if (TransLevel == TRANSON && LogFile != NULL)
}
/*********************************************************************************************************/
int SetTrans (int x)
{
switch (x)
{
case TRANSOFF:
Log (LOG_GENERAL, "Transcript disabled\n");
TransLevel = TRANSOFF;
break;
case TRANSON:
TransLevel = TRANSON;
Log (LOG_GENERAL, "Transcript enabled\n");
break;
case TRANSREAD:
return (TransLevel);
default:
return (UNKNOWNCMD);
}
return (OKCMD);
}
/*********************************************************************************************************/
/*
@title
log transoff
@text
If this command is used then further logging will not be written
to the log file
@end
*/
int LogTrOff (ET_TCLARGS)
{
SetTrans (TRANSOFF);
return (OKCMD);
}
/*
@title
log transon
@text
If this command is used then logging output will be written
to the log file
@end
*/
int LogTrOn (ET_TCLARGS)
{
SetTrans (TRANSON);
return (OKCMD);
}
/*********************************************************************************************************/
int OpenLog (char *LogName)
{
SetTrans (TRANSON);
LogFile
= fopen (LogName
, "w");
fprintf (LogFile
, "# Produced by VERTICAL version %s\n", Vertical_Version
);
return (OKCMD);
}
/*********************************************************************************************************/
int CloseLog (void)
{
if (LogFile != NULL)
{
Log (LOG_GENERAL, "Close current log file\n");
LogFile = NULL;
}
return (OKCMD);
}
/*********************************************************************************************************/
int LogComm (ET_TCLARGS)
{
int i;
if (argc > 0)
{
Log (LOG_GENERAL, "# LOGGING COMMENT:");
for (i = 1; i < argc; i++)
Log (LOG_GENERAL, " %s", argv[i]);
Log (LOG_GENERAL, "\n");
}
else
return (TCL_ERROR);
return (TCL_OK);
}
/*********************************************************************************************************/
/*
@title
log lfile <filename>
@text
All logged output will be written to the named file.
@end
*/
int LogLFile (ET_TCLARGS)
{
if (argc > 0)
{
Log (LOG_GENERAL, "-- Set log filename: <%s>\n\n", argv[0]);
CloseLog ();
OpenLog (argv[0]);
return (TCL_OK);
}
else
return (TCL_ERROR);
}
/*********************************************************************************************************/
/* enable / disable global silencing flag, one call works
as a command menu handler */
void LogSilent (void)
{
LogDisableFlag = 1;
}
/*
@title
log silent
@text
If this command is used, all further log messages are suppressed
@end
*/
int LogSilentHndl (ET_TCLARGS)
{
LogDisableFlag = 1;
return 0;
}
/*********************************************************************************************************/
void LogVerbose (void)
{
LogDisableFlag = 0;
}
/*
@title
log verbose
@text
If this command is used, all further log messages are enabled.
@end
*/
int LogVerboseHndl (ET_TCLARGS)
{
LogDisableFlag = 0;
return 0;
}
/************************************* Logging command tokens
* ********************************************/
CommandMenu const LoggingMenu = {
{"comm", 2, LogComm, NULL, "Add comment to log file", NULL, NULL},
{"lfile", 2, LogLFile, NULL, "Open new log file", "filename", NULL},
{"troff", 4, LogTrOff, NULL, "Log file transcript on", NULL, NULL},
{"tron", 4, LogTrOn, NULL, "Log file transcript off", NULL, NULL},
{"silent", 4, LogSilentHndl, NULL, "All log output off", NULL, NULL},
{"verbose", 4, LogVerboseHndl, NULL, "All log output resumed", NULL, NULL},
{NULL, 0, NULL, NULL, NULL, NULL, NULL},
};
/*********************************************************************************************************/