Subversion Repositories Vertical

Rev

Rev 2 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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.
  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.  
  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"
  92. #include "cmdexec.h"
  93. #include "cmdutil.h"
  94.  
  95. #include "expression.h"
  96. #include "generic.h"
  97. #include "database.h"
  98. #include "printout.h"
  99. #include "cmdlog.h"
  100. #include "version.h"
  101.  
  102. static FILE *LogDisplay = NULL;
  103. static FILE *LogError   = NULL;
  104. static FILE *LogFile    = NULL;
  105.  
  106. static int TransLevel = TRANSOFF;
  107. /* added at TH request */
  108. static int LogDisableFlag  = 0;
  109.  
  110. #ident "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/cmdlib/cmdlog.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $"
  111.  
  112. /***************************************** Setup error logging ***********************************************/
  113.  
  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.   }
  122.  
  123. /***************************************** Setup error logging ***********************************************/
  124.  
  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.   }
  142.  
  143. /****************************************************************************************/
  144. /* log a command into the console */
  145.  
  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.      }
  154.  
  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);  
  159. #if defined CMDLOG_TCL
  160.    if (Tcl_Mode==Tcl_GUI)
  161.      Et_EvalF(Tcl_interp,".con.t insert end \"\n%q\"",str);
  162.    else
  163. #endif
  164.      printf("%s",str);
  165.    }
  166.  
  167.  
  168. /***************************************** Message handler ***********************************************/
  169.  
  170. __declspec (dllexport)void Log (EnumLogLevel LoggingLevel, char * Format, ...)
  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.  
  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)
  193. #if defined CMDLOG_TCL
  194.    if (Tcl_Mode == Tcl_GUI)
  195.      Et_EvalF(Tcl_interp,".con.t insert end \"%q\"",str);
  196.    else
  197. #endif
  198.      printf("%s",str);
  199.  
  200.     /* log everything to the file anyway */
  201.  
  202.    if (TransLevel == TRANSON && LogFile    != NULL)
  203.       fprintf (LogFile,    str);
  204.  
  205.    }
  206.  
  207. /*********************************************************************************************************/
  208.  
  209. int SetTrans (int x)
  210.  
  211.    {
  212.  
  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.  
  223. /*********************************************************************************************************/
  224. /*
  225. @title
  226. log transoff
  227. @text
  228. If this command is used then further logging will not be written
  229. to the log file
  230. @end
  231. */
  232.  
  233. int LogTrOff (ET_TCLARGS)
  234.    { SetTrans(TRANSOFF); return (OKCMD); }
  235.  
  236.  
  237. /*
  238. @title
  239. log transon
  240. @text
  241. If this command is used then logging output will be written
  242. to the log file
  243. @end
  244. */
  245.  
  246. int LogTrOn (ET_TCLARGS)
  247.    { SetTrans(TRANSON); return (OKCMD); }
  248.  
  249. /*********************************************************************************************************/
  250.  
  251. int OpenLog (char *LogName)
  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.    }
  260.  
  261. /*********************************************************************************************************/
  262.  
  263. int CloseLog (void)
  264.    {
  265.  
  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.  
  275. /*********************************************************************************************************/
  276.  
  277. int LogComm (ET_TCLARGS)
  278.    {
  279.    int i;
  280.  
  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.    }
  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)
  303.    {
  304.  
  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.  
  316. /*********************************************************************************************************/
  317. /* enable / disable global silencing flag, one call works
  318.    as a command menu handler */
  319.  
  320. void LogSilent(void)
  321.   {
  322.   LogDisableFlag =1;
  323.   }
  324.  
  325.  
  326. /*
  327. @title
  328. log silent
  329. @text
  330. If this command is used, all further log messages are suppressed
  331. @end
  332. */
  333.  
  334. int LogSilentHndl(ET_TCLARGS)
  335.   {
  336.   LogDisableFlag =1;
  337.   return 0;
  338.   }
  339.  
  340. /*********************************************************************************************************/
  341. void LogVerbose(void)
  342.   {
  343.   LogDisableFlag = 0;
  344.   }
  345.  
  346. /*
  347. @title
  348. log verbose
  349. @text
  350. If this command is used, all further log messages are enabled.
  351. @end
  352. */
  353.  
  354. int LogVerboseHndl(ET_TCLARGS)
  355.   {
  356.   LogDisableFlag = 0;
  357.   return 0;
  358.   }
  359.  
  360.  
  361.  
  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.  
  375. /*********************************************************************************************************/
  376.  
  377.  
  378.