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

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

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

  1 #include <stdio.h>
  2 #include <string.h>
  3 #include <math.h>
  4 #include <tina/sys.h>
  5 #include <tcl.h>
  6 #include "tclWt.h"
  7 #include "tclWtPro.h"
  8 
  9 
 10 static FILE *fp = NULL;
 11 static List *fplist = NULL;
 12 static List *callback_list = NULL;
 13 static List *callback_list_end;
 14 static List *callfrom_list = NULL;
 15 static List *callfrom_list_end;
 16 
 17 
 18 void tw_open_call_file(char *savefile, char *mode)
 19 {
 20         char call_file[64];
 21         List *ref_addtostart(), *link_rm_el();
 22 
 23         (void) string_append(call_file, savefile, ".cls", NULL);
 24         if (fp != NULL)
 25                 fplist = ref_addtostart(fplist, fp, NULL);
 26         if ((fp = fopen(call_file, mode)) == NULL)
 27         {
 28                 fp = fplist->to;
 29                 fplist = link_rm_el(fplist);
 30                 error("Cannot open calls file", non_fatal);
 31         }
 32 }
 33 
 34 void tw_write_callfrom(Tw_callback * twc)
 35 {
 36         if (fp != NULL)
 37                 (*twc->prnt) (fp, twc);
 38 }
 39 
 40 static void tw_register_callback(Tw_callback * twc)
 41 {
 42         List *ref_addtoend();
 43 
 44         callback_list_end = ref_addtoend(callback_list_end, twc, NULL);
 45         if (callback_list == NULL)
 46                 callback_list = callback_list_end;
 47 }
 48 
 49 void tw_register_callfrom(Tw_callback * twc)
 50 {
 51         List *ref_addtoend();
 52 
 53         callfrom_list_end = ref_addtoend(callfrom_list_end, twc, NULL);
 54         if (callfrom_list == NULL)
 55                 callfrom_list = callfrom_list_end;
 56 }
 57 
 58 Tw_callback *tw_callback_make(char *name, Window window,
 59                                                                                                                         void (*call) ( /* ??? */ ),
 60                                                                                                                         void (*cmnd) ( /* ??? */ ),
 61                                                                                                                         void (*prnt) ( /* ??? */ ),
 62                                                                                                                         void (*func) ( /* ??? */ ), void *data1,
 63                                                                                                                         void *data2)
 64 {
 65         Tw_callback *twc = ts_ralloc(Tw_callback);
 66 
 67         twc->name = name;
 68         twc->window = window;
 69         twc->call = call;
 70         twc->cmnd = cmnd;
 71         twc->prnt = prnt;
 72         twc->func = func;
 73         twc->data1 = data1;
 74         twc->data2 = data2;
 75 
 76         tw_register_callback(twc);
 77         return (twc);
 78 }
 79 
 80 static void tw_callback(Tw_callback * twc)
 81 {
 82         if (twc->call != NULL)
 83                 (*twc->call) (twc);
 84         if (tw_save())
 85                 tw_write_callfrom(twc);
 86 }
 87 
 88 
 89 
 90 void tw_close_call_file(void)
 91 {
 92         List *ptr, *link_rm_el();
 93 
 94         if (fp == NULL)
 95                 return;
 96 
 97         for (ptr = callfrom_list; ptr != NULL; ptr = ptr->next)
 98         {
 99                 Tw_callback *twc = (Tw_callback *) ptr->to;
100                 if (twc->prnt != NULL)
101                         (*twc->prnt) (fp, twc);
102         }
103 
104         (void) fclose(fp);
105 
106         if (fplist != NULL)
107         {
108                 fp = fplist->to;
109                 fplist = link_rm_el(fplist);
110         } else
111                 fp = NULL;
112 }
113 
114 tw_run_cmnd(char *name, char *args)
115 {
116         List *ptr;
117         char *str1, *str2;
118         int fail = 0;
119 
120         for (ptr = callback_list; ptr != NULL; ptr = ptr->next)
121         {
122                 Tw_callback *twc = (Tw_callback *) ptr->to;
123 
124                 if (strcmp(twc->name, name) == 0 && twc->cmnd != NULL)
125                 {
126                         (*twc->cmnd) (twc, args);
127                         fail = 1;
128                 }
129         }
130         for (ptr = callback_list; fail != 1 && ptr != NULL; ptr = ptr->next)
131         {
132                 Tw_callback *twc = (Tw_callback *) ptr->to;
133 
134                 str1 = strchr(twc->name, '.');
135                 str2 = strchr(name, '.');
136                 if (str1 && str2 && strcmp(str1, str2) == 0 && twc->cmnd != NULL)
137                         (*twc->cmnd) (twc, args);
138         }
139 }
140 
141 tw_read_call_file(char *macrofile)
142 {
143         char name[64], args[256], callback_file[64];
144         FILE *fp;
145 
146         (void) string_append(callback_file, macrofile, ".cls", NULL);
147         fp = fopen(callback_file, "r");
148 
149         if (fp == NULL)
150         {
151                 format("macro file not found\n");
152                 return;
153         }
154 
155         while (freadline(fp, args) != EOF)
156         {
157                 (void) sscanf(args, "%s", name);
158                 tw_run_cmnd(name, args);
159         }
160 
161         (void) fclose(fp);
162         fp = NULL;
163 }
164 
165 static void replace_spaces(char *str)
166 {
167         int i;
168 
169         for (i = 0; i < strlen(str); i++)
170                 if (str[i] == ' ')
171                         str[i] = '_';
172 }
173 
174 char *tw_extend_fullname(char *name, char *extension)
175 {
176         char *fullname, *string_copy(), *string_alloc_append();
177 
178         if (extension == NULL)
179         {
180                 fullname = string_copy(name);
181                 replace_spaces(fullname);
182         } else
183         {
184                 fullname = string_alloc_append(name, ".", extension, NULL);
185                 replace_spaces(fullname);
186         }
187         return (fullname);
188 }
189 

~ [ 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.