Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/source/debug.c
1069 views
1
/*
2
* debug.c -- controll the values of x_debug.
3
*
4
* Written by Jeremy Nelson
5
* Copyright 1997 EPIC Software Labs
6
* See the COPYRIGHT file for more information
7
*/
8
9
#include "irc.h"
10
static char cvsrevision[] = "$Id: debug.c 3 2008-02-25 09:49:14Z keaston $";
11
CVS_REVISION(debug_c)
12
#include "struct.h"
13
14
#include "ircaux.h"
15
#include "output.h"
16
#include "misc.h"
17
#include "window.h"
18
#include "hook.h"
19
#include "lastlog.h"
20
#include "cset.h"
21
#include "screen.h"
22
#include "input.h"
23
#include "status.h"
24
#include "vars.h"
25
#define MAIN_SOURCE
26
#include "modval.h"
27
28
unsigned long x_debug = 0;
29
unsigned long internal_debug = 0;
30
unsigned long alias_debug = 0;
31
unsigned int debug_count = 1;
32
int in_debug_yell = 0;
33
34
struct debug_opts
35
{
36
char *command;
37
int flag;
38
};
39
40
static struct debug_opts opts[] =
41
{
42
{ "LOCAL_VARS", DEBUG_LOCAL_VARS },
43
{ "CTCPS", DEBUG_CTCPS },
44
{ "DCC_SEARCH", DEBUG_DCC_SEARCH },
45
{ "OUTBOUND", DEBUG_OUTBOUND },
46
{ "INBOUND", DEBUG_INBOUND },
47
{ "DCC_XMIT", DEBUG_DCC_XMIT },
48
{ "WAITS", DEBUG_WAITS },
49
{ "MEMORY", DEBUG_MEMORY },
50
{ "SERVER_CONNECT", DEBUG_SERVER_CONNECT },
51
{ "CRASH", DEBUG_CRASH },
52
{ "COLOR", DEBUG_COLOR },
53
{ "NOTIFY", DEBUG_NOTIFY },
54
{ "REGEX", DEBUG_REGEX },
55
{ "REGEX_DEBUG", DEBUG_REGEX_DEBUG },
56
{ "BROKEN_CLOCK", DEBUG_BROKEN_CLOCK },
57
{ "UNKNOWN", DEBUG_UNKNOWN },
58
{ "DEBUG", DEBUG_DEBUGGER },
59
{ "NEW_MATH", DEBUG_NEW_MATH },
60
{ "NEW_MATH_DEBUG", DEBUG_NEW_MATH_DEBUG },
61
{ "AUTOKEY", DEBUG_AUTOKEY },
62
{ "STRUCTURES", DEBUG_STRUCTURES },
63
{ "ALL", DEBUG_ALL },
64
{ NULL, 0 },
65
};
66
67
68
69
BUILT_IN_COMMAND(xdebugcmd)
70
{
71
int cnt;
72
int remove = 0;
73
char *this_arg;
74
75
if (!args || !*args)
76
{
77
char buffer[540];
78
char *q;
79
int i = 0;
80
81
buffer[0] = 0;
82
strmcat(buffer, "[-][+][option(s)] ", 511);
83
q = &buffer[strlen(buffer)];
84
for (i = 0; opts[i].command; i++)
85
{
86
if (q)
87
strmcat(q, ", ", 511);
88
strmcat(q, opts[i].command, 511);
89
}
90
return;
91
}
92
93
while (args && *args)
94
{
95
this_arg = upper(next_arg(args, &args));
96
if (*this_arg == '-')
97
remove = 1, this_arg++;
98
else if (*this_arg == '+')
99
this_arg++;
100
101
for (cnt = 0; opts[cnt].command; cnt++)
102
{
103
if (!strncmp(this_arg, opts[cnt].command, strlen(this_arg)))
104
{
105
if (remove)
106
x_debug &= ~opts[cnt].flag;
107
else
108
x_debug |= opts[cnt].flag;
109
break;
110
}
111
}
112
if (!opts[cnt].command)
113
say("Unrecognized XDEBUG option '%s'", this_arg);
114
}
115
}
116
117
void debugyell(const char *format, ...)
118
{
119
const char *save_from;
120
unsigned long save_level;
121
unsigned long old_alias_debug = alias_debug;
122
alias_debug = 0;
123
save_display_target(&save_from, &save_level);
124
set_display_target(NULL, LOG_DEBUG);
125
if (format)
126
{
127
char debugbuf[BIG_BUFFER_SIZE+1];
128
va_list args;
129
va_start (args, format);
130
*debugbuf = 0;
131
vsnprintf(debugbuf, BIG_BUFFER_SIZE, format, args);
132
va_end(args);
133
in_debug_yell = 1;
134
if (*debugbuf && do_hook(DEBUG_LIST, "%s", debugbuf))
135
put_echo(debugbuf);
136
in_debug_yell = 0;
137
}
138
alias_debug = old_alias_debug;
139
reset_display_target();
140
restore_display_target(save_from, save_level);
141
}
142
143
int parse_debug(char *value, int nvalue, char **rv)
144
{
145
char *str1, *str2;
146
char *copy;
147
char *nv = NULL;
148
149
if (rv)
150
*rv = NULL;
151
152
if (!value)
153
return 0;
154
155
copy = alloca(strlen(value) + 1);
156
strcpy(copy, value);
157
158
while ((str1 = new_next_arg(copy, &copy)))
159
{
160
while (*str1 && (str2 = next_in_comma_list(str1, &str1)))
161
{
162
if (!my_strnicmp(str2, "ALL", 3))
163
nvalue = (0x7F - (DEBUG_TCL));
164
else if (!my_strnicmp(str2, "-ALL", 4))
165
nvalue = 0;
166
else if (!my_strnicmp(str2, "COMMANDS", 4))
167
nvalue |= DEBUG_COMMANDS;
168
else if (!my_strnicmp(str2, "-COMMANDS", 4))
169
nvalue &= ~(DEBUG_COMMANDS);
170
else if (!my_strnicmp(str2, "EXPANSIONS", 4))
171
nvalue |= DEBUG_EXPANSIONS;
172
else if (!my_strnicmp(str2, "-EXPANSIONS", 4))
173
nvalue &= ~(DEBUG_EXPANSIONS);
174
else if (!my_strnicmp(str2, "TCL", 3))
175
nvalue |= DEBUG_TCL;
176
else if (!my_strnicmp(str2, "-TCL", 3))
177
nvalue &= ~(DEBUG_TCL);
178
else if (!my_strnicmp(str2, "ALIAS", 3))
179
nvalue |= DEBUG_CMDALIAS;
180
else if (!my_strnicmp(str2, "-ALIAS", 3))
181
nvalue &= ~(DEBUG_CMDALIAS);
182
else if (!my_strnicmp(str2, "HOOK", 3))
183
nvalue |= DEBUG_HOOK;
184
else if (!my_strnicmp(str2, "-HOOK", 3))
185
nvalue &= ~(DEBUG_HOOK);
186
else if (!my_strnicmp(str2, "VARIABLES", 3))
187
nvalue |= DEBUG_VARIABLE;
188
else if (!my_strnicmp(str2, "-VARIABLES", 3))
189
nvalue &= ~(DEBUG_VARIABLE);
190
else if (!my_strnicmp(str2, "FUNCTIONS", 3))
191
nvalue |= DEBUG_FUNC;
192
else if (!my_strnicmp(str2, "-FUNCTIONS", 3))
193
nvalue &= ~(DEBUG_FUNC);
194
else if (!my_strnicmp(str2, "STRUCTURES", 3))
195
nvalue |= DEBUG_STRUCTURES;
196
else if (!my_strnicmp(str2, "-STRUCTURES", 3))
197
nvalue &= ~(DEBUG_STRUCTURES);
198
}
199
}
200
if (rv)
201
{
202
if (nvalue & DEBUG_COMMANDS)
203
m_s3cat(&nv, comma, "COMMANDS");
204
if (nvalue & DEBUG_EXPANSIONS)
205
m_s3cat(&nv, comma, "EXPANSIONS");
206
if (nvalue & DEBUG_TCL)
207
m_s3cat(&nv, comma, "TCL");
208
if (nvalue & DEBUG_CMDALIAS)
209
m_s3cat(&nv, comma, "ALIAS");
210
if (nvalue & DEBUG_HOOK)
211
m_s3cat(&nv, comma, "HOOK");
212
if (nvalue & DEBUG_VARIABLE)
213
m_s3cat(&nv, comma, "VARIABLES");
214
if (nvalue & DEBUG_FUNC)
215
m_s3cat(&nv, comma, "FUNCTIONS");
216
if (nvalue & DEBUG_STRUCTURES)
217
m_s3cat(&nv, comma, "STRUCTURES");
218
*rv = nv;
219
}
220
return nvalue;
221
}
222
223
void debug_window(Window *win, char *value, int unused)
224
{
225
Window *old_win = win;
226
char *nv = NULL;
227
228
internal_debug = parse_debug(value, internal_debug, &nv);
229
set_string_var(DEBUG_VAR, nv);
230
231
if (internal_debug)
232
{
233
Window *tmp = NULL;
234
if (!get_window_by_name("debug") && (tmp = new_window(win->screen)))
235
{
236
malloc_strcpy(&tmp->name, "debug");
237
tmp->double_status = 0;
238
hide_window(tmp);
239
tmp->window_level = LOG_DEBUG;
240
tmp->absolute_size = 1;
241
tmp->skip = 1;
242
debugging_window = tmp;
243
set_wset_string_var(tmp->wset, STATUS_FORMAT1_WSET, DEFAULT_FORMAT_DEBUG_FSET);
244
build_status(tmp, NULL, 0);
245
update_all_windows();
246
set_input_prompt(win, get_string_var(INPUT_PROMPT_VAR), 0);
247
cursor_to_input();
248
set_screens_current_window(old_win->screen, old_win);
249
}
250
}
251
else
252
{
253
if ((old_win = get_window_by_name("debug")))
254
{
255
delete_window(old_win);
256
debugging_window = NULL;
257
update_all_windows();
258
set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0);
259
cursor_to_input();
260
}
261
}
262
new_free(&nv);
263
}
264
265