/[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.10 - (show annotations) (download) (as text)
Tue Aug 24 08:25:52 1999 UTC (20 years ago) by guppy
Branch: MAIN
Changes since 1.9: +1 -0 lines
File MIME type: text/x-chdr
blah

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23