/[cvs]/eggdrop1.4/src/tcl.c
ViewVC logotype

Contents of /eggdrop1.4/src/tcl.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (show annotations) (download) (as text)
Thu Aug 26 08:30:21 1999 UTC (20 years, 1 month ago) by guppy
Branch: MAIN
Changes since 1.10: +2 -0 lines
File MIME type: text/x-chdr
quiet-save patch

1 /*
2 * tcl.c -- handles:
3 * the code for every command eggdrop adds to Tcl
4 * Tcl initialization
5 * getting and setting Tcl/eggdrop variables
6 *
7 * dprintf'ized, 4feb1996
8 */
9 /*
10 * This file is part of the eggdrop source code
11 * copyright (c) 1997 Robey Pointer
12 * and is distributed according to the GNU general public license.
13 * For full details, read the top of 'main.c' or the file called
14 * COPYING that was distributed with this code.
15 */
16
17 #include "main.h"
18
19 /* used for read/write to internal strings */
20 typedef struct {
21 char *str; /* pointer to actual string in eggdrop */
22 int max; /* max length (negative: read-only var when protect is on) */
23 /* (0: read-only ALWAYS) */
24 int flags; /* 1 = directory */
25 } strinfo;
26
27 typedef struct {
28 int *var;
29 int ro;
30 } intinfo;
31
32 int protect_readonly = 0; /* turn on/off readonly protection */
33 char whois_fields[121] = ""; /* fields to display in a .whois */
34 Tcl_Interp *interp; /* eggdrop always uses the same interpreter */
35
36 extern int backgrd, flood_telnet_thr, flood_telnet_time;
37 extern int shtime, share_greet, require_p, keep_all_logs;
38 extern int use_stderr, allow_new_telnets, stealth_telnets, use_telnet_banner;
39 extern int default_flags, conmask, switch_logfiles_at, connect_timeout;
40 extern int firewallport, reserved_port, notify_users_at;
41 extern int flood_thr, ignore_time;
42 extern char origbotname[], botuser[], motdfile[], admin[], userfile[],
43 firewall[], helpdir[], notify_new[], hostname[], myip[], moddir[],
44 tempdir[], owner[], network[], botnetnick[], bannerfile[];
45 extern int die_on_sighup, die_on_sigterm, max_logs, max_logsize, enable_simul;
46 extern int dcc_total, debug_output, identtimeout, protect_telnet;
47 extern int egg_numver, share_unlinks, dcc_sanitycheck, sort_users;
48 extern struct dcc_t *dcc;
49 extern char egg_version[];
50 extern tcl_timer_t *timer, *utimer;
51 extern time_t online_since;
52 extern log_t *logs;
53 extern int tands;
54 extern int resolve_timeout;
55 extern char natip[];
56 extern int default_uflags; /* drummer */
57
58 /* confvar patch by aaronwl */
59 extern char configfile[];
60 int dcc_flood_thr = 3;
61 int debug_tcl = 0;
62 int use_silence = 0;
63 int use_invites = 0; /* Jason/drummer */
64 int use_exempts = 0; /* Jason/drummer */
65 int force_expire = 0; /* Rufus */
66 int remote_boots = 2;
67 int allow_dk_cmds = 1;
68 int must_be_owner = 1;
69 int max_dcc = 20; /* needs at least 4 or 5 just to get started
70 * 20 should be enough */
71 int min_dcc_port = 1024; /* dcc-portrange, min port - dw/guppy */
72 int max_dcc_port = 65535; /* dcc-portrange, max port - dw/guppy */
73 int quick_logs = 0; /* quick write logs?
74 * flush em every min instead of every 5 */
75 int par_telnet_flood = 1; /* trigger telnet flood for +f ppl? - dw */
76 int quiet_save = 0; /* quiet-save patch by Lucas */
77
78 /* prototypes for tcl */
79 Tcl_Interp *Tcl_CreateInterp();
80 int strtot = 0;
81
82 int expmem_tcl()
83 {
84 int i, tot = 0;
85
86 context;
87 for (i = 0; i < max_logs; i++)
88 if (logs[i].filename != NULL) {
89 tot += strlen(logs[i].filename) + 1;
90 tot += strlen(logs[i].chname) + 1;
91 }
92 return tot + strtot;
93 }
94
95 /***********************************************************************/
96
97 /* logfile [<modes> <channel> <filename>] */
98 static int tcl_logfile STDVAR
99 {
100 int i;
101 char s[151];
102
103 BADARGS(1, 4, " ?logModes channel logFile?");
104 if (argc == 1) {
105 /* they just want a list of the logfiles and modes */
106 for (i = 0; i < max_logs; i++)
107 if (logs[i].filename != NULL) {
108 strcpy(s, masktype(logs[i].mask));
109 strcat(s, " ");
110 strcat(s, logs[i].chname);
111 strcat(s, " ");
112 strcat(s, logs[i].filename);
113 Tcl_AppendElement(interp, s);
114 }
115 return TCL_OK;
116 }
117 BADARGS(4, 4, " ?logModes channel logFile?");
118 for (i = 0; i < max_logs; i++)
119 if ((logs[i].filename != NULL) && (!strcmp(logs[i].filename, argv[3]))) {
120 logs[i].mask = logmodes(argv[1]);
121 nfree(logs[i].chname);
122 logs[i].chname = NULL;
123 if (!logs[i].mask) {
124 /* ending logfile */
125 nfree(logs[i].filename);
126 logs[i].filename = NULL;
127 if (logs[i].f != NULL) {
128 fclose(logs[i].f);
129 logs[i].f = NULL;
130 }
131 } else {
132 logs[i].chname = (char *) nmalloc(strlen(argv[2]) + 1);
133 strcpy(logs[i].chname, argv[2]);
134 }
135 Tcl_AppendResult(interp, argv[3], NULL);
136 return TCL_OK;
137 }
138 for (i = 0; i < max_logs; i++)
139 if (logs[i].filename == NULL) {
140 logs[i].mask = logmodes(argv[1]);
141 logs[i].filename = (char *) nmalloc(strlen(argv[3]) + 1);
142 strcpy(logs[i].filename, argv[3]);
143 logs[i].chname = (char *) nmalloc(strlen(argv[2]) + 1);
144 strcpy(logs[i].chname, argv[2]);
145 Tcl_AppendResult(interp, argv[3], NULL);
146 return TCL_OK;
147 }
148 Tcl_AppendResult(interp, "reached max # of logfiles", NULL);
149 return TCL_ERROR;
150 }
151
152 int findidx(int z)
153 {
154 int j;
155
156 for (j = 0; j < dcc_total; j++)
157 if ((dcc[j].sock == z) && (dcc[j].type->flags & DCT_VALIDIDX))
158 return j;
159 return -1;
160 }
161
162 static void botnet_change(char *new)
163 {
164 if (strcasecmp(botnetnick, new) != 0) {
165 /* trying to change bot's nickname */
166 if (tands > 0) {
167 putlog(LOG_MISC, "*", "* Tried to change my botnet nick, but I'm still linked to a botnet.");
168 putlog(LOG_MISC, "*", "* (Unlink and try again.)");
169 return;
170 } else {
171 if (botnetnick[0])
172 putlog(LOG_MISC, "*", "* IDENTITY CHANGE: %s -> %s", botnetnick, new);
173 strcpy(botnetnick, new);
174 }
175 }
176 }
177
178 /**********************************************************************/
179
180 int init_dcc_max(), init_misc();
181
182 /* used for read/write to integer couplets */
183 typedef struct {
184 int *left; /* left side of couplet */
185 int *right; /* right side */
186 } coupletinfo;
187
188 /* read/write integer couplets (int1:int2) */
189 static char *tcl_eggcouplet(ClientData cdata, Tcl_Interp * irp, char *name1,
190 char *name2, int flags)
191 {
192 char *s, s1[41];
193 coupletinfo *cp = (coupletinfo *) cdata;
194
195 if (flags & (TCL_TRACE_READS | TCL_TRACE_UNSETS)) {
196 sprintf(s1, "%d:%d", *(cp->left), *(cp->right));
197 Tcl_SetVar2(interp, name1, name2, s1, TCL_GLOBAL_ONLY);
198 if (flags & TCL_TRACE_UNSETS)
199 Tcl_TraceVar(interp, name1,
200 TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
201 tcl_eggcouplet, cdata);
202 } else { /* writes */
203 s = Tcl_GetVar2(interp, name1, name2, TCL_GLOBAL_ONLY);
204 if (s != NULL) {
205 int nr1, nr2;
206
207 if (strlen(s) > 40)
208 s[40] = 0;
209 sscanf(s, "%d%*c%d", &nr1, &nr2);
210 *(cp->left) = nr1;
211 *(cp->right) = nr2;
212 }
213 }
214 return NULL;
215 }
216
217 /* read/write normal integer */
218 static char *tcl_eggint(ClientData cdata, Tcl_Interp * irp, char *name1,
219 char *name2, int flags)
220 {
221 char *s, s1[40];
222 long l;
223 intinfo *ii = (intinfo *) cdata;
224
225 if (flags & (TCL_TRACE_READS | TCL_TRACE_UNSETS)) {
226 /* special cases */
227 if ((int *) ii->var == &conmask)
228 strcpy(s1, masktype(conmask));
229 else if ((int *) ii->var == &default_flags) {
230 struct flag_record fr =
231 {FR_GLOBAL, 0, 0, 0, 0, 0};
232 fr.global = default_flags;
233 fr.udef_global = default_uflags;
234 build_flags(s1, &fr, 0);
235 } else
236 sprintf(s1, "%d", *(int *) ii->var);
237 Tcl_SetVar2(interp, name1, name2, s1, TCL_GLOBAL_ONLY);
238 if (flags & TCL_TRACE_UNSETS)
239 Tcl_TraceVar(interp, name1,
240 TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
241 tcl_eggint, cdata);
242 return NULL;
243 } else { /* writes */
244 s = Tcl_GetVar2(interp, name1, name2, TCL_GLOBAL_ONLY);
245 if (s != NULL) {
246 if ((int *) ii->var == &conmask) {
247 if (s[0])
248 conmask = logmodes(s);
249 else
250 conmask = LOG_MODES | LOG_MISC | LOG_CMDS;
251 } else if ((int *) ii->var == &default_flags) {
252 struct flag_record fr =
253 {FR_GLOBAL, 0, 0, 0, 0, 0};
254
255 break_down_flags(s, &fr, 0);
256 default_flags = sanity_check(fr.global); /* drummer */
257 default_uflags = fr.udef_global;
258 } else if ((ii->ro == 2) || ((ii->ro == 1) && protect_readonly)) {
259 return "read-only variable";
260 } else {
261 if (Tcl_ExprLong(interp, s, &l) == TCL_ERROR)
262 return interp->result;
263 if ((int *) ii->var == &max_dcc) {
264 if (l < max_dcc)
265 return "you can't DECREASE max-dcc";
266 max_dcc = l;
267 init_dcc_max();
268 } else if ((int *) ii->var == &max_logs) {
269 if (l < max_logs)
270 return "you can't DECREASE max-logs";
271 max_logs = l;
272 init_misc();
273 } else
274 *(ii->var) = (int) l;
275 }
276 }
277 return NULL;
278 }
279 }
280
281 /* read/write normal string variable */
282 static char *tcl_eggstr(ClientData cdata, Tcl_Interp * irp, char *name1,
283 char *name2, int flags)
284 {
285 char *s;
286 strinfo *st = (strinfo *) cdata;
287
288 if (flags & (TCL_TRACE_READS | TCL_TRACE_UNSETS)) {
289 if ((st->str == firewall) && (firewall[0])) {
290 char s1[161];
291
292 sprintf(s1, "%s:%d", firewall, firewallport);
293 Tcl_SetVar2(interp, name1, name2, s1, TCL_GLOBAL_ONLY);
294 } else
295 Tcl_SetVar2(interp, name1, name2, st->str, TCL_GLOBAL_ONLY);
296 if (flags & TCL_TRACE_UNSETS) {
297 Tcl_TraceVar(interp, name1, TCL_TRACE_READS | TCL_TRACE_WRITES |
298 TCL_TRACE_UNSETS, tcl_eggstr, cdata);
299 if ((st->max <= 0) && (protect_readonly || (st->max == 0)))
300 return "read-only variable"; /* it won't return the error... */
301 }
302 return NULL;
303 } else { /* writes */
304 if ((st->max <= 0) && (protect_readonly || (st->max == 0))) {
305 Tcl_SetVar2(interp, name1, name2, st->str, TCL_GLOBAL_ONLY);
306 return "read-only variable";
307 }
308 s = Tcl_GetVar2(interp, name1, name2, TCL_GLOBAL_ONLY);
309 if (s != NULL) {
310 if (strlen(s) > abs(st->max))
311 s[abs(st->max)] = 0;
312 if (st->str == botnetnick)
313 botnet_change(s);
314 else if (st->str == firewall) {
315 splitc(firewall, s, ':');
316 if (!firewall[0])
317 strcpy(firewall, s);
318 else
319 firewallport = atoi(s);
320 } else
321 strcpy(st->str, s);
322 if ((st->flags) && (s[0])) {
323 if (st->str[strlen(st->str) - 1] != '/')
324 strcat(st->str, "/");
325 }
326 }
327 return NULL;
328 }
329 }
330
331 /* add/remove tcl commands */
332 void add_tcl_commands(tcl_cmds * tab)
333 {
334 int i;
335
336 for (i = 0; tab[i].name; i++)
337 Tcl_CreateCommand(interp, tab[i].name, tab[i].func, NULL, NULL);
338 }
339
340 void rem_tcl_commands(tcl_cmds * tab)
341 {
342 int i;
343
344 for (i = 0; tab[i].name; i++)
345 Tcl_DeleteCommand(interp, tab[i].name);
346 }
347
348 static tcl_strings def_tcl_strings[] =
349 {
350 {"botnet-nick", botnetnick, HANDLEN, 0},
351 {"userfile", userfile, 120, STR_PROTECT},
352 {"motd", motdfile, 120, STR_PROTECT},
353 {"admin", admin, 120, 0},
354 {"help-path", helpdir, 120, STR_DIR | STR_PROTECT},
355 {"temp-path", tempdir, 120, STR_DIR | STR_PROTECT},
356 #ifndef STATIC
357 {"mod-path", moddir, 120, STR_DIR | STR_PROTECT},
358 #endif
359 {"notify-newusers", notify_new, 120, 0},
360 {"owner", owner, 120, STR_PROTECT},
361 {"my-hostname", hostname, 120, 0},
362 {"my-ip", myip, 120, 0},
363 {"network", network, 40, 0},
364 {"whois-fields", whois_fields, 120, 0},
365 {"nat-ip", natip, 120, 0},
366 {"username", botuser, 10, 0},
367 {"version", egg_version, 0, 0},
368 {"firewall", firewall, 120, 0},
369 /* confvar patch by aaronwl */
370 {"config", configfile, 0, 0},
371 {"telnet-banner", bannerfile, 120, STR_PROTECT},
372 {0, 0, 0, 0}
373 };
374
375 /* ints */
376
377 static tcl_ints def_tcl_ints[] =
378 {
379 {"ignore-time", &ignore_time, 0},
380 {"dcc-flood-thr", &dcc_flood_thr, 0},
381 {"hourly-updates", &notify_users_at, 0},
382 {"switch-logfiles-at", &switch_logfiles_at, 0},
383 {"connect-timeout", &connect_timeout, 0},
384 {"reserved-port", &reserved_port, 0},
385 /* booleans (really just ints) */
386 {"require-p", &require_p, 0},
387 {"keep-all-logs", &keep_all_logs, 0},
388 {"open-telnets", &allow_new_telnets, 0},
389 {"stealth-telnets", &stealth_telnets, 0},
390 {"use-telnet-banner", &use_telnet_banner, 0},
391 {"uptime", (int *) &online_since, 2},
392 {"console", &conmask, 0},
393 {"default-flags", &default_flags, 0},
394 /* moved from eggdrop.h */
395 {"numversion", &egg_numver, 2},
396 {"debug-tcl", &debug_tcl, 1},
397 {"die-on-sighup", &die_on_sighup, 1},
398 {"die-on-sigterm", &die_on_sigterm, 1},
399 {"remote-boots", &remote_boots, 1},
400 {"max-dcc", &max_dcc, 0},
401 {"max-logs", &max_logs, 0},
402 {"max-logsize", &max_logsize, 0},
403 {"quick-logs", &quick_logs, 0},
404 {"enable-simul", &enable_simul, 1},
405 {"debug-output", &debug_output, 1},
406 {"protect-telnet", &protect_telnet, 0},
407 {"dcc-sanitycheck", &dcc_sanitycheck, 0},
408 {"sort-users", &sort_users, 0},
409 {"ident-timeout", &identtimeout, 0},
410 {"share-unlinks", &share_unlinks, 0},
411 {"log-time", &shtime, 0},
412 {"allow-dk-cmds", &allow_dk_cmds, 0},
413 {"resolve-timeout", &resolve_timeout, 0},
414 {"must-be-owner", &must_be_owner, 1},
415 {"use-silence", &use_silence, 0}, /* arthur2 */
416 {"paranoid-telnet-flood", &par_telnet_flood, 0},
417 {"use-exempts", &use_exempts, 0}, /* Jason/drummer */
418 {"use-invites", &use_invites, 0}, /* Jason/drummer */
419 {"quiet-save", &quiet_save, 0}, /* Lucas */
420 {"force-expire", &force_expire, 0}, /* Rufus */
421 {0, 0, 0} /* arthur2 */
422 };
423
424 static tcl_coups def_tcl_coups[] =
425 {
426 {"telnet-flood", &flood_telnet_thr, &flood_telnet_time},
427 {"dcc-portrange", &min_dcc_port, &max_dcc_port}, /* dw */
428 {0, 0, 0}
429 };
430
431 /* set up Tcl variables that will hook into eggdrop internal vars via */
432 /* trace callbacks */
433 static void init_traces()
434 {
435 add_tcl_coups(def_tcl_coups);
436 add_tcl_strings(def_tcl_strings);
437 add_tcl_ints(def_tcl_ints);
438 }
439
440 void kill_tcl()
441 {
442 context;
443 rem_tcl_coups(def_tcl_coups);
444 rem_tcl_strings(def_tcl_strings);
445 rem_tcl_ints(def_tcl_ints);
446 kill_bind();
447 Tcl_DeleteInterp(interp);
448 }
449
450 extern tcl_cmds tcluser_cmds[], tcldcc_cmds[], tclmisc_cmds[];
451
452 /* not going through Tcl's crazy main() system (what on earth was he
453 * smoking?!) so we gotta initialize the Tcl interpreter */
454 void init_tcl()
455 {
456 char pver[25];
457
458 /* initialize the interpreter */
459 context;
460 interp = Tcl_CreateInterp();
461 Tcl_Init(interp);
462 init_bind();
463 init_traces();
464 /* add new commands */
465 /* isnt this much neater :) */
466 add_tcl_commands(tcluser_cmds);
467 add_tcl_commands(tcldcc_cmds);
468 add_tcl_commands(tclmisc_cmds);
469
470 #define Q(A,B) Tcl_CreateCommand(interp,A,B,NULL,NULL)
471 Q("logfile", tcl_logfile);
472 sscanf(egg_version, "%s", pver);
473 Tcl_PkgProvide(interp, "eggdrop", pver);
474 }
475
476 /**********************************************************************/
477
478 void do_tcl(char *whatzit, char *script)
479 {
480 int code;
481 FILE *f = 0;
482
483 if (debug_tcl) {
484 f = fopen("DEBUG.TCL", "a");
485 if (f != NULL)
486 fprintf(f, "eval: %s\n", script);
487 }
488 set_tcl_vars();
489 context;
490 code = Tcl_Eval(interp, script);
491 if (debug_tcl && (f != NULL)) {
492 fprintf(f, "done eval, result=%d\n", code);
493 fclose(f);
494 }
495 if (code != TCL_OK) {
496 putlog(LOG_MISC, "*", "Tcl error in script for '%s':", whatzit);
497 putlog(LOG_MISC, "*", "%s", interp->result);
498 }
499 }
500
501 /* read and interpret the configfile given */
502 /* return 1 if everything was okay */
503 int readtclprog(char *fname)
504 {
505 int code;
506 FILE *f;
507
508 set_tcl_vars();
509 f = fopen(fname, "r");
510 if (f == NULL)
511 return 0;
512 fclose(f);
513 if (debug_tcl) {
514 f = fopen("DEBUG.TCL", "a");
515 if (f != NULL) {
516 fprintf(f, "Sourcing file %s ...\n", fname);
517 fclose(f);
518 }
519 }
520 code = Tcl_EvalFile(interp, fname);
521 if (code != TCL_OK) {
522 if (use_stderr) {
523 dprintf(DP_STDERR, "Tcl error in file '%s':\n", fname);
524 dprintf(DP_STDERR, "%s\n",
525 Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY));
526 } else {
527 putlog(LOG_MISC, "*", "Tcl error in file '%s':", fname);
528 putlog(LOG_MISC, "*", "%s\n",
529 Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY));
530 }
531 /* try to go on anyway (shrug) */
532 /* no dont it's to risky now */
533 return 0;
534 }
535 /* refresh internal variables */
536 return 1;
537 }
538
539 void add_tcl_strings(tcl_strings * list)
540 {
541 int i;
542 strinfo *st;
543
544 for (i = 0; list[i].name; i++) {
545 if (list[i].length > 0) {
546 char *p = Tcl_GetVar(interp, list[i].name, TCL_GLOBAL_ONLY);
547
548 if (p != NULL) {
549 strncpy(list[i].buf, p, list[i].length);
550 list[i].buf[list[i].length] = 0;
551 if (list[i].flags & STR_DIR) {
552 int x = strlen(list[i].buf);
553
554 if ((x > 0) && (x < (list[i].length - 1)) &&
555 (list[i].buf[x - 1] != '/')) {
556 list[i].buf[x++] = '/';
557 list[i].buf[x] = 0;
558 }
559 }
560 }
561 }
562 st = (strinfo *) nmalloc(sizeof(strinfo));
563 strtot += sizeof(strinfo);
564 st->max = list[i].length - (list[i].flags & STR_DIR);
565 if (list[i].flags & STR_PROTECT)
566 st->max = -st->max;
567 st->str = list[i].buf;
568 st->flags = (list[i].flags & STR_DIR);
569 Tcl_TraceVar(interp, list[i].name, TCL_TRACE_READS | TCL_TRACE_WRITES |
570 TCL_TRACE_UNSETS, tcl_eggstr, (ClientData) st);
571 }
572 }
573
574 void rem_tcl_strings(tcl_strings * list)
575 {
576 int i;
577 strinfo *st;
578
579 for (i = 0; list[i].name; i++) {
580 st = (strinfo *) Tcl_VarTraceInfo(interp, list[i].name,
581 TCL_TRACE_READS |
582 TCL_TRACE_WRITES |
583 TCL_TRACE_UNSETS,
584 tcl_eggstr, NULL);
585 Tcl_UntraceVar(interp, list[i].name,
586 TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
587 tcl_eggstr, st);
588 if (st != NULL) {
589 strtot -= sizeof(strinfo);
590 nfree(st);
591 }
592 }
593 }
594
595 void add_tcl_ints(tcl_ints * list)
596 {
597 int i;
598 intinfo *ii;
599
600 for (i = 0; list[i].name; i++) {
601 char *p = Tcl_GetVar(interp, list[i].name, TCL_GLOBAL_ONLY);
602
603 if (p != NULL)
604 *(list[i].val) = atoi(p);
605 ii = nmalloc(sizeof(intinfo));
606 strtot += sizeof(intinfo);
607 ii->var = list[i].val;
608 ii->ro = list[i].readonly;
609 Tcl_TraceVar(interp, list[i].name,
610 TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
611 tcl_eggint, (ClientData) ii);
612 }
613
614 }
615
616 void rem_tcl_ints(tcl_ints * list)
617 {
618 int i;
619 intinfo *ii;
620
621 for (i = 0; list[i].name; i++) {
622 ii = (intinfo *) Tcl_VarTraceInfo(interp, list[i].name,
623 TCL_TRACE_READS |
624 TCL_TRACE_WRITES |
625 TCL_TRACE_UNSETS,
626 tcl_eggint, NULL);
627 Tcl_UntraceVar(interp, list[i].name,
628 TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
629 tcl_eggint, (ClientData) ii);
630 if (ii) {
631 strtot -= sizeof(intinfo);
632 nfree(ii);
633 }
634 }
635 }
636
637 /* allocate couplet space for tracing couplets */
638 void add_tcl_coups(tcl_coups * list)
639 {
640 coupletinfo *cp;
641 int i;
642
643 for (i = 0; list[i].name; i++) {
644 cp = (coupletinfo *) nmalloc(sizeof(coupletinfo));
645 strtot += sizeof(coupletinfo);
646 cp->left = list[i].lptr;
647 cp->right = list[i].rptr;
648 Tcl_TraceVar(interp, list[i].name,
649 TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
650 tcl_eggcouplet, (ClientData) cp);
651 }
652 }
653
654 void rem_tcl_coups(tcl_coups * list)
655 {
656 coupletinfo *cp;
657 int i;
658
659 for (i = 0; list[i].name; i++) {
660 cp = (coupletinfo *) Tcl_VarTraceInfo(interp, list[i].name,
661 TCL_TRACE_READS |
662 TCL_TRACE_WRITES |
663 TCL_TRACE_UNSETS,
664 tcl_eggcouplet, NULL);
665 strtot -= sizeof(coupletinfo);
666 Tcl_UntraceVar(interp, list[i].name,
667 TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
668 tcl_eggcouplet, (ClientData) cp);
669 nfree(cp);
670 }
671 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23