File: trace.c

package info (click to toggle)
the 2.5-0.2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 3,116 kB
  • ctags: 3,020
  • sloc: ansic: 46,212; sh: 1,525; makefile: 395
file content (211 lines) | stat: -rw-r--r-- 6,543 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/***********************************************************************/
/* TRACE.C - Debugging and tracing functions.                          */
/***********************************************************************/
/*
 * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
 * Copyright (C) 1991-1997 Mark Hessling
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to:
 * 
 *    The Free Software Foundation, Inc.
 *    675 Mass Ave,
 *    Cambridge, MA 02139 USA.
 * 
 * 
 * If you make modifications to this software that you feel increases
 * it usefulness for the rest of the community, please email the
 * changes, enhancements, bug fixes as well as any and all ideas to me.
 * This software is going to be maintained and enhanced as deemed 
 * necessary by the community.
 *
 * Mark Hessling                 Email:             M.Hessling@qut.edu.au
 * PO Box 203                    Phone:                    +617 3802 0800
 * Bellara                       http://www.gu.edu.au/gext/the/markh.html
 * QLD 4507                      **** Maintainer PDCurses & REXX/SQL ****
 * Australia                     ************* Author of THE ************
 */

/*
$Id: trace.c 2.1 1995/06/24 16:31:34 MH Rel MH $
*/

#include <config.h>

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <time.h>

#ifdef HAVE_PROTO
void trace_initialise(void);
void trace_function(char *);
void trace_return(void);
void trace_string(char *,...);
void trace_constant(char *);
#else
void trace_initialise(/* void */);
void trace_function(/* char* */);
void trace_return(/* void */);
void trace_string(/* char*,... */);
void trace_constant(/* char * */);
#endif

/*--------------------------- global data -----------------------------*/
char trace_save_str[40];
char trace_env[40];
FILE *trace_fp;
short trace_number=0,trace_level=(-1);
/***********************************************************************/
#ifdef HAVE_PROTO
void trace_initialise(void)
#else
void trace_initialise()
#endif
/***********************************************************************/
{
/*------------------------- external data -----------------------------*/
/*--------------------------- local data ------------------------------*/
 char *trace_env_ptr=getenv("TRACE");
/*--------------------------- processing ------------------------------*/

 trace_fp = NULL;
 if (trace_env_ptr == NULL)
    return;
 strcpy(trace_env,trace_env_ptr);
 trace_number = trace_level = 0;
 strcpy(trace_save_str,"");
 return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
void trace_function(char *trace_str)
#else
void trace_function(trace_str)
char *trace_str;
#endif
/***********************************************************************/
{
/*------------------------- external data -----------------------------*/
/*--------------------------- local data ------------------------------*/
 register int i;
 time_t timer;
 struct tm *tblock=NULL;
/*--------------------------- processing ------------------------------*/
#if 0
 if (trace_level == (-1))
    return;
 if (strcmp(trace_str,trace_save_str) == 0)
   {
    trace_number++;
    trace_level++;
    return;
   }
 if (trace_number == 0)
   {
    trace_number = 1;
    trace_level++;
    return;
   }
 trace_fp = fopen(trace_env,"a");
 for (i=0;i<trace_level;i++)
     fprintf(trace_fp,"  ");
 fprintf(trace_fp,"(%d)%-s",trace_level,trace_save_str);
 for (i=0;i<60-(trace_level*2)-strlen(trace_save_str);i++)
     fprintf(trace_fp," ");
 fprintf(trace_fp,"%5d\n",trace_number);
 fclose(trace_fp);

 trace_number = 1;
 trace_level++;
 strcpy(trace_save_str,trace_str);
 return;
#endif
 if (trace_level == (-1))
    return;
 trace_level++;
 trace_fp = fopen(trace_env,"a");
 for (i=0;i<trace_level;i++)
     fprintf(trace_fp,"  ");
 fprintf(trace_fp,"(%d)%-s",trace_level,trace_str);
 for (i=0;i<60-(trace_level*2)-strlen(trace_str);i++)
     fprintf(trace_fp," ");
 timer = time(NULL);
 tblock = localtime(&timer);
 fprintf(trace_fp,"%2d:%2d:%2d\n",tblock->tm_hour,tblock->tm_min,tblock->tm_sec);
 fclose(trace_fp);
 return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
void trace_return(void)
#else
void trace_return()
#endif
/***********************************************************************/
{
/*------------------------- external data -----------------------------*/
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
 if (trace_level == (-1))
    return;
 trace_level--;
 if (trace_level < 0)
    fprintf(trace_fp,"****** trace level below zero ********");

 return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
void trace_string(char *fmt,...)
#else
void trace_string(fmt)
char *fmt;
#endif
/***********************************************************************/
{
/*------------------------- external data -----------------------------*/
/*--------------------------- local data ------------------------------*/
 va_list args;
/*--------------------------- processing ------------------------------*/
 va_start(args,fmt);
 trace_fp = fopen(trace_env,"a");
 if (trace_fp == NULL)
   {
    va_end(args);
    return;
   }
 vfprintf(trace_fp,fmt,args);
 fclose(trace_fp);
 va_end(args);
 return;
}
/***********************************************************************/
#ifdef HAVE_PROTO
void trace_constant(char *str)
#else
void trace_constant(str)
char *str;
#endif
/***********************************************************************/
{
/*------------------------- external data -----------------------------*/
/*--------------------------- local data ------------------------------*/
/*--------------------------- processing ------------------------------*/
 trace_fp = fopen(trace_env,"a");
 if (trace_fp == NULL)
    return;
 fprintf(trace_fp,"%s",str);
 fclose(trace_fp);
 return;
}