-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdebug.h
91 lines (78 loc) · 2.25 KB
/
debug.h
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
/*
*
* ©K. D. Hedger. Tue 31 Jul 13:31:30 BST 2018 [email protected]
* This file (debug.h) is part of Projects.
* Projects 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 3 of the License, or
* at your option) any later version.
* Projects 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 Projects. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _DEBUG_H_
#define _DEBUG_H_
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <search.h>
#include <magic.h>
#include <stdarg.h>
#include <alloca.h>
#define MAXBUFFER 512
#define DEBUGFUNC(x,...) errLine=__LINE__,errFile=__FILE__,errFunc=__func__;debugFunc((const char*)x,__VA_ARGS__);
#define debugfunc DEBUGFUNC
#define MESSAGE(s) DEBUGFUNC("%s",s);
#define message MESSAGE
#define CHECKPOINT errLine=__LINE__,errFile=__FILE__,errFunc=__func__;
#define checkpoint CHECKPOINT
#define LASTCHECKPOINT(s) debugFunc("%s",s);
#define lastcheckpoint LASTCHECKPOINT
extern int errLine;
extern const char *errFile;
extern const char *errFunc;
static void debugFunc(const char *fmt, ...);
void debugFunc(const char *fmt, ...)
{
va_list ap;
char *buffer,*subbuffer;
buffer=(char*)alloca(MAXBUFFER);
subbuffer=(char*)alloca(MAXBUFFER);
buffer[0]=0;
subbuffer[0]=0;
va_start(ap, fmt);
while (*fmt)
{
subbuffer[0]=0;
if(fmt[0]=='%')
{
fmt++;
switch(*fmt)
{
case 's':
sprintf(subbuffer,"%s",va_arg(ap,char*));
break;
case 'i':
sprintf(subbuffer,"%i",va_arg(ap,int));
break;
default:
sprintf(subbuffer,"%c",fmt[0]);
break;
}
}
else
sprintf(subbuffer,"%c",fmt[0]);
strcat(buffer,subbuffer);
fmt++;
}
va_end(ap);
fprintf(stderr,"File: %s,Func: %s,Line: %i\n",errFile,errFunc,errLine);
fprintf(stderr,">>%s<<\n",buffer);
}
#endif