Subversion Repositories Vertical

Rev

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