~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/TCLwidgets/tw_check.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2   tw_check.c
  3 */
  4 
  5 #include <stdio.h>
  6 #include <tina/sys.h>
  7 #include <tcl.h>
  8 #include "tclWt.h"
  9 #include "tclWtPro.h"
 10 
 11 
 12 
 13 static void check_call(Tw_callback * twc)
 14 {
 15         int value = *((int *)twc->data1);
 16 
 17         (*twc->func) (value);
 18 }
 19 
 20 
 21 static char *ttcl_writetrace_check(ClientData cdata, Tcl_Interp * interp,
 22                                                                                                                                          char *name1, char *name2, int flags)
 23 {
 24         List *twlist = (List *) cdata;
 25         Tw_callback *twc = (Tw_callback *) (twlist->to);
 26         int set;
 27         char *tclvalue, *butname;
 28 
 29         if (!name2 || !twlist)
 30                 return ("choice update failed");
 31 
 32         tclvalue = Tcl_GetVar2(interp, name1, name2, flags);
 33 
 34         /*
 35                  would be nice to know the previously value but turning 'off'
 36                  will have to do
 37         */
 38         if (Tcl_GetBoolean(interp, tclvalue, &set) != TCL_OK)
 39         {
 40                 Tcl_SetVar2(interp, name1, name2, "off", flags);
 41                 return ("positive boolean argument required, element turned off");
 42         }
 43 
 44         if ((twc = (Tw_callback *) (twlist->to)) != NULL)
 45         {
 46                 butname = (char *) (twc->data2);
 47                 while (!butname && !strcmp(name2, butname))
 48                 {
 49                         butname = NULL;
 50                         if ((twlist = twlist->next) != NULL)
 51                                 if ((twc = (Tw_callback *) (twlist->to)) != NULL)
 52                                         butname = (char *) (twc->data2);
 53                 }
 54         }
 55 
 56         if (!twc || !butname)
 57                 return ("element unknown");
 58 
 59         check_call(twc);
 60 
 61         return NULL;
 62 }
 63 
 64 
 65 static void check_cmnd(Tw_callback * twc, char *args)
 66 {
 67         int value;
 68 
 69         (void) sscanf(args, "%*s %d", &value);
 70         twc->data1 = (void *) value;
 71         (*twc->func) (value);
 72 
 73 }
 74 
 75 static void check_prnt(FILE * fp, Tw_callback * twc)
 76 {
 77         int value = (int) twc->data1;
 78 
 79         (void) fprintf(fp, "%s %d %d\n", twc->name, value);
 80 }
 81 
 82 
 83 void *tw_check(char *name, ...)
 84 {
 85         Tcl_Interp *interp;
 86         Tw_callback *twc;
 87         List *twlist = NULL;
 88         va_list ap;
 89         void (*func) ();
 90         int *vparam, value, i;
 91         char *string_alloc_append(), *string_copy();
 92         char *tclname, *butname, *element;
 93         char *fullname = tw_extend_fullname(tw_get_toolname(), name);
 94 
 95         if ((interp = ttcl_get_interp()) == NULL)
 96                 return;
 97 
 98         tclname = ttcl_mkshellname(fullname, TTCLCHECK);
 99 
100         va_start(ap, name);
101         func = (void (*)()) va_arg(ap, void *);
102         value = va_arg(ap, int);
103 
104         for (i = 1; (butname = va_arg(ap, char *)) != NULL; i++)
105         {
106                 vparam = (int *) ralloc(sizeof(int));
107                 *vparam = i;
108                 twc = tw_callback_make(fullname, NULL, check_call, check_cmnd,
109                                                                                                          check_prnt, func, (void *) vparam,
110                                                                                                          string_copy(butname));
111                 twlist = ref_addtostart(twlist, twc, 0);
112                 element = string_alloc_append(tclname, "(", butname, ")", NULL);
113                 if (i & value)
114                         Tcl_SetVar(interp, element, "on", 0);
115                 else
116                         Tcl_SetVar(interp, element, "off", 0);
117                 rfree(element);
118         }
119 
120         twlist = list_reverse(twlist);
121         va_end(ap);
122 
123         Tcl_TraceVar(interp, tclname, TCL_TRACE_WRITES, ttcl_writetrace_check,
124                                                          (ClientData) twlist);
125         rfree(tclname);
126 
127         (*func) (value);
128 
129         return (twlist);
130 }
131 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.