home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / the25.zip / thesrc251.zip / trace.c < prev    next >
C/C++ Source or Header  |  1998-07-23  |  7KB  |  214 lines

  1. /***********************************************************************/
  2. /* TRACE.C - Debugging and tracing functions.                          */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1997 Mark Hessling
  7.  * 
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  * 
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  * 
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  * 
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  * 
  25.  * 
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed 
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                 Email:             M.Hessling@qut.edu.au
  33.  * PO Box 203                    Phone:                    +617 3802 0800
  34.  * Bellara                       http://www.gu.edu.au/gext/the/markh.html
  35.  * QLD 4507                      **** Maintainer PDCurses & REXX/SQL ****
  36.  * Australia                     ************* Author of THE ************
  37.  */
  38.  
  39. /*
  40. $Id: trace.c 2.1 1995/06/24 16:31:34 MH Rel MH $
  41. */
  42.  
  43. #ifdef HAVE_CONFIG_H
  44. # include <config.h>
  45. #endif
  46.  
  47. #include <stdlib.h>
  48. #include <stdio.h>
  49. #include <stdarg.h>
  50. #include <time.h>
  51.  
  52. #ifdef HAVE_PROTO
  53. void trace_initialise(void);
  54. void trace_function(char *);
  55. void trace_return(void);
  56. void trace_string(char *,...);
  57. void trace_constant(char *);
  58. #else
  59. void trace_initialise(/* void */);
  60. void trace_function(/* char* */);
  61. void trace_return(/* void */);
  62. void trace_string(/* char*,... */);
  63. void trace_constant(/* char * */);
  64. #endif
  65.  
  66. /*--------------------------- global data -----------------------------*/
  67. char trace_save_str[40];
  68. char trace_env[40];
  69. FILE *trace_fp;
  70. short trace_number=0,trace_level=(-1);
  71. /***********************************************************************/
  72. #ifdef HAVE_PROTO
  73. void trace_initialise(void)
  74. #else
  75. void trace_initialise()
  76. #endif
  77. /***********************************************************************/
  78. {
  79. /*------------------------- external data -----------------------------*/
  80. /*--------------------------- local data ------------------------------*/
  81.  char *trace_env_ptr=getenv("TRACE");
  82. /*--------------------------- processing ------------------------------*/
  83.  
  84.  trace_fp = NULL;
  85.  if (trace_env_ptr == NULL)
  86.     return;
  87.  strcpy(trace_env,trace_env_ptr);
  88.  trace_number = trace_level = 0;
  89.  strcpy(trace_save_str,"");
  90.  return;
  91. }
  92. /***********************************************************************/
  93. #ifdef HAVE_PROTO
  94. void trace_function(char *trace_str)
  95. #else
  96. void trace_function(trace_str)
  97. char *trace_str;
  98. #endif
  99. /***********************************************************************/
  100. {
  101. /*------------------------- external data -----------------------------*/
  102. /*--------------------------- local data ------------------------------*/
  103.  register int i;
  104.  time_t timer;
  105.  struct tm *tblock=NULL;
  106. /*--------------------------- processing ------------------------------*/
  107. #if 0
  108.  if (trace_level == (-1))
  109.     return;
  110.  if (strcmp(trace_str,trace_save_str) == 0)
  111.    {
  112.     trace_number++;
  113.     trace_level++;
  114.     return;
  115.    }
  116.  if (trace_number == 0)
  117.    {
  118.     trace_number = 1;
  119.     trace_level++;
  120.     return;
  121.    }
  122.  trace_fp = fopen(trace_env,"a");
  123.  for (i=0;i<trace_level;i++)
  124.      fprintf(trace_fp,"  ");
  125.  fprintf(trace_fp,"(%d)%-s",trace_level,trace_save_str);
  126.  for (i=0;i<60-(trace_level*2)-strlen(trace_save_str);i++)
  127.      fprintf(trace_fp," ");
  128.  fprintf(trace_fp,"%5d\n",trace_number);
  129.  fclose(trace_fp);
  130.  
  131.  trace_number = 1;
  132.  trace_level++;
  133.  strcpy(trace_save_str,trace_str);
  134.  return;
  135. #endif
  136.  if (trace_level == (-1))
  137.     return;
  138.  trace_level++;
  139.  trace_fp = fopen(trace_env,"a");
  140.  for (i=0;i<trace_level;i++)
  141.      fprintf(trace_fp,"  ");
  142.  fprintf(trace_fp,"(%d)%-s",trace_level,trace_str);
  143.  for (i=0;i<60-(trace_level*2)-strlen(trace_str);i++)
  144.      fprintf(trace_fp," ");
  145.  timer = time(NULL);
  146.  tblock = localtime(&timer);
  147.  fprintf(trace_fp,"%2d:%2d:%2d\n",tblock->tm_hour,tblock->tm_min,tblock->tm_sec);
  148.  fclose(trace_fp);
  149.  return;
  150. }
  151. /***********************************************************************/
  152. #ifdef HAVE_PROTO
  153. void trace_return(void)
  154. #else
  155. void trace_return()
  156. #endif
  157. /***********************************************************************/
  158. {
  159. /*------------------------- external data -----------------------------*/
  160. /*--------------------------- local data ------------------------------*/
  161. /*--------------------------- processing ------------------------------*/
  162.  if (trace_level == (-1))
  163.     return;
  164.  trace_level--;
  165.  if (trace_level < 0)
  166.     fprintf(trace_fp,"****** trace level below zero ********");
  167.  
  168.  return;
  169. }
  170. /***********************************************************************/
  171. #ifdef HAVE_PROTO
  172. void trace_string(char *fmt,...)
  173. #else
  174. void trace_string(fmt)
  175. char *fmt;
  176. #endif
  177. /***********************************************************************/
  178. {
  179. /*------------------------- external data -----------------------------*/
  180. /*--------------------------- local data ------------------------------*/
  181.  va_list args;
  182. /*--------------------------- processing ------------------------------*/
  183.  va_start(args,fmt);
  184.  trace_fp = fopen(trace_env,"a");
  185.  if (trace_fp == NULL)
  186.    {
  187.     va_end(args);
  188.     return;
  189.    }
  190.  vfprintf(trace_fp,fmt,args);
  191.  fclose(trace_fp);
  192.  va_end(args);
  193.  return;
  194. }
  195. /***********************************************************************/
  196. #ifdef HAVE_PROTO
  197. void trace_constant(char *str)
  198. #else
  199. void trace_constant(str)
  200. char *str;
  201. #endif
  202. /***********************************************************************/
  203. {
  204. /*------------------------- external data -----------------------------*/
  205. /*--------------------------- local data ------------------------------*/
  206. /*--------------------------- processing ------------------------------*/
  207.  trace_fp = fopen(trace_env,"a");
  208.  if (trace_fp == NULL)
  209.     return;
  210.  fprintf(trace_fp,"%s",str);
  211.  fclose(trace_fp);
  212.  return;
  213. }
  214.