Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / yagle / xyagle / XMT_panel.c
1 /*------------------------------------------------------------\
2 | |
3 | Tool : XYAG XMT |
4 | |
5 | File : Yag Panel.c |
6 | |
7 | Author : Picault Stephane |
8 | Lester Anthony |
9 | |
10 \------------------------------------------------------------*/
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <setjmp.h>
16
17 #include <Xm/Xm.h>
18 #include <Xm/FileSB.h>
19 #include <Xm/SelectioB.h>
20 #include <Xm/PushBG.h>
21 #include <Xm/Text.h>
22
23 #include <fcntl.h>
24 #include <unistd.h>
25 #include <errno.h>
26 #include <sys/wait.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29
30 #include BEH_H
31 #include BHL_H
32 #include MUT_H
33 #include MLO_H
34 #include LOG_H
35 #include CGV_H
36 #include BVL_H
37 #include BEF_H
38
39 #include XSB_H
40 #include XYA_H
41 #include XMX_H
42 #include XTB_H
43 #include XMT_H
44 #include INF_H
45 #include YAG_H
46
47 #include "XMT_panel.h"
48
49 #include XMV_H
50 #include XME_H
51
52 #include "XME_panel.h"
53 #include "XME_beh.h"
54 #include "XMF_file.h"
55 #include "XMV_view.h"
56 #include "XYA_cgvfig.h"
57
58 extern xyagzoom *XyagHeadZoom;
59
60 static void (*XyagOldExitHandler) () = NULL;
61 int xya_pfd[2];
62 int xya_out[2];
63
64 extern int XYADEBUG;
65
66 sigjmp_buf XyagMyEnv ;
67 sigjmp_buf *XyagJmpEnv = NULL ;
68 void XyagSetJmpEnv(sigjmp_buf *buf)
69 {
70 XyagJmpEnv = buf;
71 }
72
73 /*------------------------------------------------------------\
74 | XyagInitFileErr |
75 \------------------------------------------------------------*/
76 void XyagInitFileErr()
77 {
78 char *str ;
79
80 if (XYADEBUG) return;
81 if (XyagCallbackFileQuitFonction != NULL) return;
82
83 if (pipe( xya_pfd ) != -1)
84 {
85 close(2);
86 dup2( xya_pfd[1],2 );
87 close( xya_pfd[1] );
88 }
89
90 if (pipe( xya_out ) != -1)
91 {
92 close(1);
93 dup2( xya_out[1],1 );
94 close( xya_out[1] );
95 }
96
97 }
98
99 /*------------------------------------------------------------\
100 | XyagGetWarningMess |
101 \------------------------------------------------------------*/
102 void XyagGetWarningMess( )
103 {
104 char buffer[4096];
105 int i = 0;
106 char *pt ;
107
108 if (XYADEBUG) return;
109 if (XyagCallbackFileQuitFonction != NULL) {
110 XyagGetWarningFunction ();
111 return;
112 }
113
114 fprintf(stderr,"\n") ;
115 fflush( stderr );
116 i = read(xya_pfd[0],buffer,4096) ;
117 buffer[i] = '\0' ;
118
119 if(i == -1)
120 return ;
121
122 pt = buffer ;
123
124 while((isspace((int)*pt) != 0) && (*pt != '\0'))
125 pt++ ;
126
127 if(strlen(pt) == 0)
128 return ;
129
130 XyagWarningMessage( XyagMainWindow, pt );
131 }
132
133
134
135 /*------------------------------------------------------------\
136 | XyagExit |
137 \------------------------------------------------------------*/
138 void XyagExit(x)
139 int x ;
140 {
141 MBK_EXIT_KILL = 'N' ;
142 EXIT(x);
143 }
144
145 /*------------------------------------------------------------\
146 | XyagFirePasqua |
147 \------------------------------------------------------------*/
148 void XyagFirePasqua()
149 {
150 char c;
151 int nb = 1;
152
153 if(XyagCallbackFileQuitFonction != NULL) {
154 XyagSetJmpEnv (NULL);
155 XyagFirePasquaFunction ();
156 return;
157 }
158 /*-------------------*/
159 /* Clean up the pipe */
160 /*-------------------*/
161 while ((nb != -1) && (nb != 0))
162 {
163 XyagSetBlock( xya_pfd[0], False );
164 nb = read(xya_pfd[0], &c, 1);
165 }
166
167 nb = 1;
168 while ((nb != -1) && (nb != 0))
169 {
170 XyagSetBlock( xya_out[0], False );
171 nb = read(xya_out[0], &c, 1);
172 }
173
174 signal(SIGTERM, XyagOldExitHandler);
175 }
176
177
178
179 /*------------------------------------------------------------\
180 | XyagFatalAppError |
181 \------------------------------------------------------------*/
182 void XyagFatalAppError( message )
183 char *message;
184 {
185 //XtasDestroyAllFig() ;
186 XyagFirePasqua();
187 XyagErrorMessage( XyagMainWindow, message );
188 siglongjmp(XyagMyEnv, 1);
189 }
190
191 /*------------------------------------------------------------\
192 | XyagGetStdoutMess |
193 \------------------------------------------------------------*/
194 void XyagGetStdoutMess()
195 {
196 static char buffer[4096];
197 static int i = 0;
198
199 fflush( stderr );
200 i = read(xya_pfd[0],buffer,4096) ;
201 buffer[i] = '\0' ;
202
203 if(strlen(buffer) == 0)
204 return ;
205
206 if(i == -1)
207 strcpy(buffer,"Fatal Error Occuring While Reading File") ;
208
209 XyagFatalAppError(buffer) ;
210 }
211
212
213
214
215
216 /*------------------------------------------------------------\
217 | XyagSetBlock |
218 \------------------------------------------------------------*/
219 void XyagSetBlock( fd, on )
220 int fd, on;
221 {
222 static int blockf, nonblockf;
223 static int first = True;
224 int flags;
225
226 if ( first == True )
227 {
228 first = False;
229 if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
230 {
231 fprintf(stderr,"ERREUR FCNTL\n");fflush(stderr);
232
233 }
234 blockf = flags & ~O_NDELAY;
235 blockf = flags & ~O_NONBLOCK;
236 nonblockf = flags | O_NDELAY;
237 nonblockf = flags | O_NONBLOCK;
238 }
239
240 if (fcntl(fd, F_SETFL, on ? blockf : nonblockf ) == -1)
241 {
242 fprintf(stderr,"ERREUR FCNTL\n");fflush(stderr);
243 }
244 }
245
246 /*------------------------------------------------------------\
247 | XyagPasqua |
248 \------------------------------------------------------------*/
249 void XyagPasqua()
250 {
251 /*---------------------------------*/
252 /* Catch all stdout messages !!! */
253 /*---------------------------------*/
254 if(XyagCallbackFileQuitFonction != NULL) {
255 XyagPasquaFunction ();
256 return;
257 }
258 XyagSetBlock( 2, False );
259 XyagSetBlock( 1, False );
260 XyagOldExitHandler = signal( SIGTERM, XyagGetStdoutMess );
261 }
262
263 void updatebacklist(cgvfig_list *cgvf)
264 {
265 chain_list *cl=OPEN_STACK, *ch;
266 if (OPEN_STACK==NULL) return;
267 if (cl->DATA==cgvf)
268 {
269 OPEN_STACK=OPEN_STACK->NEXT; cl->NEXT=NULL;
270 freechain(cl);
271 XyagDelConnect();
272 XyagDelSelect();
273 XyagDelZoom();
274 return;
275 }
276 while (cl->NEXT!=NULL && cl->NEXT->DATA!=cgvf)
277 {
278 cl=cl->NEXT;
279 }
280 if (cl->NEXT!=NULL)
281 {
282 void *sel, *con, *zoom;
283 con=XyagHeadConnect;
284 sel=XyagHeadSelect;
285 zoom=XyagHeadZoom;
286
287 XyagHeadConnect=cgvf->data0;
288 XyagHeadSelect=cgvf->data1;
289 XyagHeadZoom=cgvf->data_ZOOM;
290
291 XyagDelConnect();
292 XyagDelSelect();
293 XyagDelZoom();
294
295 ch=cl->NEXT;cl->NEXT=ch->NEXT; ch->NEXT=NULL;
296 freechain(ch);
297
298 XyagHeadConnect=con;
299 XyagHeadSelect=sel;
300 XyagHeadZoom=zoom;
301 }
302 // else printf("not found??!!\n");
303 }
304