-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquattro_debug.c
85 lines (75 loc) · 2.07 KB
/
quattro_debug.c
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
//@+leo-ver=4-thin
//@+node:leonardoce.20090629082550.141:@thin quattro_debug.c
//@@language c
//@@tabwidth -4
//@+others
//@+node:leonardoce.20090629082550.142:safeStrdup
#include "quattro_debug.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *safeStrdup(const char *orig) {
if(orig==NULL) {
return NULL;
} else {
return strdup(orig);
}
}
//@-node:leonardoce.20090629082550.142:safeStrdup
//@+node:leonardoce.20090629082550.143:safeFree
void safeFree(void *orig) {
if(orig!=NULL) {
free(orig);
}
}
//@-node:leonardoce.20090629082550.143:safeFree
//@+node:leonardoce.20090629082550.144:ForthDebugInfo_New
ForthDebugInfo *ForthDebugInfo_New(const char *fileName, const char *wordName, int row, int col, int diType) {
ForthDebugInfo *self=(ForthDebugInfo *)malloc(sizeof(ForthDebugInfo));
self->fileName=safeStrdup(fileName);
self->wordName=safeStrdup(wordName);
self->row=row;
self->col=col;
self->infoType=diType;
return(self);
}
//@-node:leonardoce.20090629082550.144:ForthDebugInfo_New
//@+node:leonardoce.20090629082550.145:ForthDebugInfo_Delete
void ForthDebugInfo_Delete(ForthDebugInfo *self) {
safeFree(self->fileName);
safeFree(self->wordName);
safeFree(self);
}
//@-node:leonardoce.20090629082550.145:ForthDebugInfo_Delete
//@+node:leonardoce.20090629082550.146:ForthDebugInfo_Dump
void ForthDebugInfo_Dump(ForthDebugInfo *self) {
printf("<debuginfo ");
switch(self->infoType) {
case DI_ENTER:
printf("type=\"ENTER\" ");
break;
case DI_EXIT:
printf("type=\"EXIT\" ");
break;
case DI_DOES:
printf("type=\"DOES\" ");
break;
case DI_TRACE:
printf("type=\"TRACE\" ");
break;
default:
printf("type=\"UNKNOWN\" ");
break;
}
if(self->fileName!=NULL) {
printf("fileName=\"%s\" ", self->fileName);
}
if(self->wordName!=NULL) {
printf("wordName=\"%s\" ", self->wordName);
}
printf("row=\"%i\" col=\"%i\"/>", self->row, self->col);
}
//@-node:leonardoce.20090629082550.146:ForthDebugInfo_Dump
//@-others
//@-node:leonardoce.20090629082550.141:@thin quattro_debug.c
//@-leo