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

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

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

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

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