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

Linux Cross Reference
Tina5/tina-tools/tinatool/wdgts/xm/wdgtsXm_tw_command.c

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

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/wdgts/xm/wdgtsXm_tw_command.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: wdgtsXm_tw_command.c,v 1.3 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "wdgtsXm_tw_command.h"
 49 
 50 #if HAVE_CONFIG_H
 51 #   include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #include <string.h>
 56 
 57 #include <tina/sys/sysDef.h>
 58 #include <tina/sys/sysPro.h>
 59 #include <tina/sys/sysLst_list.h>
 60 
 61 #include <tinatool/wdgts/xm/wdgts_XmDef.h>
 62 #include <tinatool/gphx/x11/gphxX11_tw_cursor.h>
 63 #include <tinatool/wdgts/xm/wdgtsXm_tw_tool.h>
 64 #include <tinatool/gphx/x11/gphxX11_tw_cursor.h>
 65 
 66 static FILE *fp = NULL;
 67 static List *fplist=NULL; /* recursive macro list NAT 19/5/97 */
 68 static List *callback_list = NULL;
 69 static List *callback_list_end;
 70 static List *callfrom_list = NULL;
 71 static List *callfrom_list_end;
 72 
 73 /**
 74 a standard call back structure that can be invoked from
 75 the window system or from a command line, incorporating an automatic
 76 save to file mechanism
 77 **/
 78 
 79 /*
 80 void    tw_open_call_file(char *mode)
 81 {
 82     char    call_file[64];
 83 
 84     (void) string_append(call_file, tw_get_progname(), ".cls", NULL);
 85     if ((fp = fopen(call_file, mode)) == NULL)
 86         error("tw_open_call_file: cannot open file", non_fatal);
 87 }
 88 */
 89 /* function modified to allow recursive macros NAT 19/5/97 */
 90 void    tw_open_call_file(char *savefile, char *mode)
 91 {
 92     char    call_file[64];
 93     List   *ref_addtostart(), *link_rm_el();
 94  
 95     (void) string_append(call_file, savefile, ".cls", NULL);
 96     if (fp!=NULL) fplist = ref_addtostart(fplist,fp,0);
 97     if ((fp = fopen(call_file, mode)) == NULL)
 98     {
 99 /*
100         fp = fplist->to;
101 */
102         fplist = link_rm_el(fplist);
103         error("Cannot open calls file", non_fatal);
104     }
105 }
106 
107 void    tw_write_callfrom(Tw_callback * twc)
108 {
109     if (fp != NULL)
110         (*twc->prnt) (fp, twc);
111 }
112 
113 static void tw_register_callback(Tw_callback * twc)
114 {
115     List   *ref_addtoend(List *, void *, int);
116 
117     callback_list_end = ref_addtoend(callback_list_end, twc, 0);
118     if (callback_list == NULL)
119         callback_list = callback_list_end;
120 }
121 
122 void    tw_register_callfrom(Tw_callback * twc)
123 {
124     List   *ref_addtoend(List *, void *, int);
125 
126     callfrom_list_end = ref_addtoend(callfrom_list_end, twc, 0);
127     if (callfrom_list == NULL)
128         callfrom_list = callfrom_list_end;
129 }
130 
131 Tw_callback *tw_callback_make(char *name, Widget tool, Widget widget, void (*call) ( /* ??? */ ), void (*cmnd) ( /* ??? */ ), void (*prnt) ( /* ??? */ ), void (*func) ( /* ??? */ ), void *data1, void *data2)
132 {
133     Tw_callback *twc = ts_ralloc(Tw_callback);
134 
135     twc->name = name;
136     twc->tool = tool;
137     twc->widget = widget;
138     twc->call = call;
139     twc->cmnd = cmnd;
140     twc->prnt = prnt;
141     twc->func = func;
142     twc->data1 = data1;
143     twc->data2 = data2;
144 
145     tw_register_callback(twc);
146     return (twc);
147 }
148 
149 /* ARGSUSED quieten lint */
150 void    tw_callback(Widget w, Tw_callback * twc, void *call_data)
151 {
152     Display *display = XtDisplay(twc->tool);
153     Window  window = XtWindow(twc->tool);
154 
155     tw_set_wait_cursor(display, window);
156     tw_active_tool_data_set(display, window);
157 
158     if (twc->call != NULL)
159         (*twc->call) (twc, call_data);
160     tw_write_callfrom(twc);
161     tw_set_tina_cursor(display, window);
162 }
163 
164 void    tw_close_call_file(void)
165 {
166     List   *ptr;
167 
168     if (fp == NULL)
169         return;
170 
171     /** copy latest tool positions to callfile **/
172     for (ptr = callfrom_list; ptr != NULL; ptr = ptr->next)
173     {
174         Tw_callback *twc = (Tw_callback *) ptr->to;
175 
176         if (twc->prnt != NULL)
177             (*twc->prnt) (fp, twc);
178     }
179 
180     (void) fclose(fp);
181 /* modified to allow recursive generation of macros NAT 19/5/97 */
182     if (fplist !=NULL)
183     {
184        fp = fplist->to;
185        fplist = link_rm_el(fplist);
186     }
187     else
188 /* added to prevent continued file write attempts a.lacey@man.ac.uk 27.1.00 */
189        fp = NULL;
190 }
191 
192 void tw_run_cmnd(char *name, char *args)
193 {
194     List   *ptr;
195     char   *str1,*str2;
196     int    fail = 0;
197 
198     for (ptr = callback_list; ptr != NULL; ptr = ptr->next)
199     {
200         Tw_callback *twc = (Tw_callback *) ptr->to;
201 
202         if (strcmp(twc->name, name) == 0 && twc->cmnd != NULL)
203         {
204             (*twc->cmnd) (twc, args);
205             fail =1;
206         }
207     }
208     for (ptr = callback_list; fail!=1 && ptr != NULL; ptr = ptr->next)
209     {
210         Tw_callback *twc = (Tw_callback *) ptr->to;
211 
212          str1 = strchr(twc->name,'.');
213          str2 = strchr(name,'.');
214          if ( str1 && str2 && strcmp(str1, str2) == 0 && twc->cmnd != NULL)
215               (*twc->cmnd) (twc, args);
216     }
217 }
218 
219 
220 /*
221 tw_read_call_file(void)
222 {
223     char    name[64], args[64], callback_file[64], *tw_get_progname(void);
224     FILE   *fp;
225 
226     (void) string_append(callback_file, tw_get_progname(), ".cls", NULL);
227     fp = fopen(callback_file, "r");
228 
229     if (fp == NULL)
230         return;
231 
232     while (freadline(fp, args) != EOF)
233     {
234         (void) sscanf(args, "%s", name);
235         tw_run_cmnd(name, args);
236     }
237 
238     (void) fclose(fp);
239 }
240 */
241 
242 void tw_read_call_file(char *macrofile)
243 {
244     char    name[64], args[256], callback_file[64];
245     FILE   *fp;
246  
247     (void) string_append(callback_file, macrofile, ".cls", NULL);
248     fp = fopen(callback_file, "r");
249  
250     if (fp == NULL)
251         return;
252  
253     while (freadline(fp, args) != EOF)
254     {
255         (void) sscanf(args, "%s", name);
256         tw_run_cmnd(name, args);
257     }
258  
259     (void) fclose(fp);
260 }
261 
262 static void replace_spaces(char *str)
263 {
264     int     i;
265 
266     for (i = 0; str[i] != (char) NULL; i++)
267         if (str[i] == ' ')
268             str[i] = '_';
269 }
270 
271 char   *tw_extend_fullname(char *name, char *extension)
272 {
273     char   *fullname, *string_copy(char *);
274 
275     if (extension == (char *) NULL)
276     {
277         fullname = string_copy(name);
278         replace_spaces(fullname);
279     } else
280     {
281         fullname = string_alloc_append(name, ".", extension, NULL);
282         replace_spaces(fullname);
283     }
284     return (fullname);
285 }
286 

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