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

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

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

  1 /**@(#)
  2 **/
  3 #include <stdio.h>
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/tv.h>
  8 #include  <tina/mtw.h>
  9 #include  <tina/tv_screen.h>
 10 #include <tina/Xmfuncs.h>
 11 
 12 static FILE *fp = NULL;
 13 static List *fplist=NULL; /* recursive macro list NAT 19/5/97 */
 14 static List *callback_list = NULL;
 15 static List *callback_list_end;
 16 static List *callfrom_list = NULL;
 17 static List *callfrom_list_end;
 18 
 19 /**
 20 a standard call back structure that can be invoked from
 21 the window system or from a command line, incorporating an automatic
 22 save to file mechanism
 23 **/
 24 
 25 /*
 26 void    tw_open_call_file(char *mode)
 27 {
 28     char    call_file[64];
 29 
 30     (void) string_append(call_file, tw_get_progname(), ".cls", NULL);
 31     if ((fp = fopen(call_file, mode)) == NULL)
 32         error("tw_open_call_file: cannot open file", non_fatal);
 33 }
 34 */
 35 /* function modified to allow recursive macros NAT 19/5/97 */
 36 void    tw_open_call_file(char *savefile, char *mode)
 37 {
 38     char    call_file[64];
 39     List   *ref_addtostart(), *link_rm_el();
 40  
 41     (void) string_append(call_file, savefile, ".cls", NULL);
 42     if (fp!=NULL) fplist = ref_addtostart(fplist,fp,NULL);
 43     if ((fp = fopen(call_file, mode)) == NULL)
 44     {
 45 /*
 46         fp = fplist->to;
 47 */
 48         fplist = link_rm_el(fplist);
 49         error("Cannot open calls file", non_fatal);
 50     }
 51 }
 52 
 53 void    tw_write_callfrom(Tw_callback * twc)
 54 {
 55     if (fp != NULL)
 56         (*twc->prnt) (fp, twc);
 57 }
 58 
 59 static void tw_register_callback(Tw_callback * twc)
 60 {
 61     List   *ref_addtoend(List *, void *, int);
 62 
 63     callback_list_end = ref_addtoend(callback_list_end, twc, NULL);
 64     if (callback_list == NULL)
 65         callback_list = callback_list_end;
 66 }
 67 
 68 void    tw_register_callfrom(Tw_callback * twc)
 69 {
 70     List   *ref_addtoend(List *, void *, int);
 71 
 72     callfrom_list_end = ref_addtoend(callfrom_list_end, twc, NULL);
 73     if (callfrom_list == NULL)
 74         callfrom_list = callfrom_list_end;
 75 }
 76 
 77 Tw_callback *tw_callback_make(char *name, Widget tool, Widget widget, void (*call) ( /* ??? */ ), void (*cmnd) ( /* ??? */ ), void (*prnt) ( /* ??? */ ), void (*func) ( /* ??? */ ), void *data1, void *data2)
 78 {
 79     Tw_callback *twc = ts_ralloc(Tw_callback);
 80 
 81     twc->name = name;
 82     twc->tool = tool;
 83     twc->widget = widget;
 84     twc->call = call;
 85     twc->cmnd = cmnd;
 86     twc->prnt = prnt;
 87     twc->func = func;
 88     twc->data1 = data1;
 89     twc->data2 = data2;
 90 
 91     tw_register_callback(twc);
 92     return (twc);
 93 }
 94 
 95 /* ARGSUSED quieten lint */
 96 void    tw_callback(Widget w, Tw_callback * twc, void *call_data)
 97 {
 98     Display *display = XtDisplay(twc->tool);
 99     Window  window = XtWindow(twc->tool);
100 
101     tw_set_wait_cursor(display, window);
102     tw_active_tool_data_set(display, window);
103 
104     if (twc->call != NULL)
105         (*twc->call) (twc, call_data);
106     tw_write_callfrom(twc);
107     tw_set_tina_cursor(display, window);
108 }
109 
110 void    tw_close_call_file(void)
111 {
112     List   *ptr;
113 
114     if (fp == NULL)
115         return;
116 
117     /** copy latest tool positions to callfile **/
118     for (ptr = callfrom_list; ptr != NULL; ptr = ptr->next)
119     {
120         Tw_callback *twc = (Tw_callback *) ptr->to;
121 
122         if (twc->prnt != NULL)
123             (*twc->prnt) (fp, twc);
124     }
125 
126     (void) fclose(fp);
127 /* modified to allow recursive generation of macros NAT 19/5/97 */
128     if (fplist !=NULL)
129     {
130        fp = fplist->to;
131        fplist = link_rm_el(fplist);
132     }
133     else
134 /* added to prevent continued file write attempts a.lacey@man.ac.uk 27.1.00 */
135        fp = NULL;
136 }
137 
138 tw_run_cmnd(char *name, char *args)
139 {
140     List   *ptr;
141     char   *str1,*str2;
142     int    fail = 0;
143 
144     for (ptr = callback_list; ptr != NULL; ptr = ptr->next)
145     {
146         Tw_callback *twc = (Tw_callback *) ptr->to;
147 
148         if (strcmp(twc->name, name) == 0 && twc->cmnd != NULL)
149         {
150             (*twc->cmnd) (twc, args);
151             fail =1;
152         }
153     }
154     for (ptr = callback_list; fail!=1 && ptr != NULL; ptr = ptr->next)
155     {
156         Tw_callback *twc = (Tw_callback *) ptr->to;
157 
158          str1 = strchr(twc->name,'.');
159          str2 = strchr(name,'.');
160          if ( str1 && str2 && strcmp(str1, str2) == 0 && twc->cmnd != NULL)
161               (*twc->cmnd) (twc, args);
162     }
163 }
164 
165 
166 /*
167 tw_read_call_file(void)
168 {
169     char    name[64], args[64], callback_file[64], *tw_get_progname(void);
170     FILE   *fp;
171 
172     (void) string_append(callback_file, tw_get_progname(), ".cls", NULL);
173     fp = fopen(callback_file, "r");
174 
175     if (fp == NULL)
176         return;
177 
178     while (freadline(fp, args) != EOF)
179     {
180         (void) sscanf(args, "%s", name);
181         tw_run_cmnd(name, args);
182     }
183 
184     (void) fclose(fp);
185 }
186 */
187 
188 tw_read_call_file(char *macrofile)
189 {
190     char    name[64], args[256], callback_file[64];
191     FILE   *fp;
192  
193     (void) string_append(callback_file, macrofile, ".cls", NULL);
194     fp = fopen(callback_file, "r");
195  
196     if (fp == NULL)
197         return;
198  
199     while (freadline(fp, args) != EOF)
200     {
201         (void) sscanf(args, "%s", name);
202         tw_run_cmnd(name, args);
203     }
204  
205     (void) fclose(fp);
206 }
207 
208 static void replace_spaces(char *str)
209 {
210     int     i;
211 
212     for (i = 0; str[i] != (char) NULL; i++)
213         if (str[i] == ' ')
214             str[i] = '_';
215 }
216 
217 char   *tw_extend_fullname(char *name, char *extension)
218 {
219     char   *fullname, *string_copy(char *);
220 
221     if (extension == (char *) NULL)
222     {
223         fullname = string_copy(name);
224         replace_spaces(fullname);
225     } else
226     {
227         fullname = string_alloc_append(name, ".", extension, NULL);
228         replace_spaces(fullname);
229     }
230     return (fullname);
231 }
232 

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