1 /****************************************************************************/
3 /* Chaine de CAO & VLSI Alliance */
5 /* Produit : XTAS Version 5 */
6 /* Fichier : xtas_unix.c */
8 /* (c) copyright 1991-1998 Laboratoire LIP6 equipe ASIM */
9 /* Tous droits reserves */
10 /* Support : e-mail alliance-support@asim.lip6.fr */
12 /* Author(s) : Lionel PROTZENKO Date : 01/08/1997 */
14 /* Modified by : Date : ../../.... */
15 /* Modified by : Date : ../../.... */
16 /* Modified by : Date : ../../.... */
18 /*--------------------------------------------------------------------------*/
21 /*--------------------------------------------------------------------------*/
23 /*--------------------------------------------------------------------------*/
25 /*--------------------------------------------------------------------------*/
31 static void (*XtasOldExitHandler
) () = NULL
;
32 char XTAS_DEBUG_MODE
= 'N' ;
34 /*---------------------------------------------------------------------------*/
36 /* FUNCTION : XtasSetBlock */
38 /* IN ARGS : .fd : The file descriptor. */
39 /* .on : Indicator of a blocking read or not. */
41 /* OUT ARGS : ( void ) */
45 /*---------------------------------------------------------------------------*/
46 void XtasSetBlock( fd
, on
)
49 static int blockf
, nonblockf
;
50 static int first
= True
;
56 if ((flags
= fcntl(fd
, F_GETFL
, 0)) == -1)
58 fprintf(stderr
,"ERREUR FCNTL\n");fflush(stderr
);
61 blockf
= flags
& ~O_NDELAY
;
62 blockf
= flags
& ~O_NONBLOCK
;
63 nonblockf
= flags
| O_NDELAY
;
64 nonblockf
= flags
| O_NONBLOCK
;
67 if (fcntl(fd
, F_SETFL
, on
? blockf
: nonblockf
) == -1)
69 fprintf(stderr
,"ERREUR FCNTL\n");fflush(stderr
);
73 /*---------------------------------------------------------------------------*/
75 /* FUNCTION : XtasInitFileErr */
77 /* IN ARGS : ( none ) */
79 /* OUT ARGS : ( void ) */
81 /* OBJECT : Catch stderr */
83 /*---------------------------------------------------------------------------*/
84 void XtasInitFileErr()
88 str
= getenv("XTAS_DEBUG_MODE") ;
91 XTAS_DEBUG_MODE
= (strcmp(str
,"yes") == 0 ) ? 'Y' : 'N' ;
94 if (pipe( tas_pfd
) != -1)
101 if (pipe( tas_out
) != -1)
104 dup2( tas_out
[1],1 );
108 if(XTAS_DEBUG_MODE
== 'N')
110 signal( SIGBUS
, XtasFatalSysError
);
111 signal( SIGSEGV
, XtasFatalSysError
);
115 /*---------------------------------------------------------------------------*/
117 /* FUNCTION : XtasGetStdoutMess */
119 /* IN ARGS : ( none ) */
121 /* OUT ARGS : ( void ) */
123 /* OBJECT : Catch messages of stdout from the pipe. */
125 /*---------------------------------------------------------------------------*/
126 void XtasGetStdoutMess()
128 static char buffer
[4096];
132 i
= read(tas_pfd
[0],buffer
,4095) ;
135 strcpy(buffer
,"Fatal Error Occuring While Reading File") ;
139 if(strlen(buffer
) == 0)
142 XtasFatalAppError(buffer
) ;
145 /*---------------------------------------------------------------------------*/
147 /* FUNCTION : XtasPasqua */
149 /* IN ARGS : ( none ) */
151 /* OUT ARGS : ( void ) */
153 /* OBJECT : Activates the stdout watching. */
155 /*---------------------------------------------------------------------------*/
158 /*---------------------------------*/
159 /* Catch all stdout messages !!! */
160 /*---------------------------------*/
161 XtasSetBlock( 2, False
);
162 XtasSetBlock( 1, False
);
163 XtasOldExitHandler
= signal( SIGTERM
, XtasGetStdoutMess
);
164 XtasClearAllStream (); /* avoid warnings from Motif */
167 /*---------------------------------------------------------------------------*/
169 /* FUNCTION : XtasFirePasqua */
171 /* IN ARGS : ( none ) */
173 /* OUT ARGS : ( void ) */
175 /* OBJECT : Deactivates the stdout watching. */
177 /*---------------------------------------------------------------------------*/
178 void XtasFirePasqua()
183 XtasSetLabelString( XtasDeskMessageField
, XTAS_NULINFO
);
185 /*-------------------*/
186 /* Clean up the pipe */
187 /*-------------------*/
188 while ((nb
!= -1) && (nb
!= 0))
190 XtasSetBlock( tas_pfd
[0], False
);
191 nb
= read(tas_pfd
[0], &c
, 1);
195 while ((nb
!= -1) && (nb
!= 0))
197 XtasSetBlock( tas_out
[0], False
);
198 nb
= read(tas_out
[0], &c
, 1);
201 signal(SIGTERM
, XtasOldExitHandler
);
204 /*---------------------------------------------------------------------------*/
206 /* FUNCTION : XtasFatalSysError */
208 /* IN ARGS : ( none ) */
210 /* OUT ARGS : ( void ) */
212 /* OBJECT : Treatment of System Fatal Errors. */
214 /*---------------------------------------------------------------------------*/
215 void XtasFatalSysError()
217 XtasDestroyAllFig() ;
220 XalDrawMessage( XtasErrorWidget
, XTAS_FSYSERR
);
221 XtCloseDisplay( XtDisplay( XtasTopLevel
) );
226 /*---------------------------------------------------------------------------*/
228 /* FUNCTION : XtasExit */
230 /* IN ARGS : ( none ) */
232 /* OUT ARGS : ( void ) */
234 /* OBJECT : Treatment of exit */
236 /*---------------------------------------------------------------------------*/
240 MBK_EXIT_KILL
= 'N' ;
241 XyagExitErrorMessage(x
);
245 /*---------------------------------------------------------------------------*/
247 /* FUNCTION : XtasFatalAppError */
249 /* IN ARGS : .message : The message to be drawn to the user. */
251 /* OUT ARGS : ( void ) */
253 /* OBJECT : Treatment of Application's Fatal Errors. */
255 /*---------------------------------------------------------------------------*/
256 void XtasFatalAppError( message
)
259 XtasDestroyAllFig() ;
260 XtasDestroyStbInProgress();
263 if ( XtasErrorWidget
)
265 XtasSetLabelString( XtasDeskMessageField
, XTAS_FAPPERR
);
266 XalForceUpdate( XtasDeskMessageField
);
267 XalDrawMessage( XtasErrorWidget
, message
);
270 if (XyagJmpEnv
!= NULL
)
271 siglongjmp(*XyagJmpEnv
, 1);
273 siglongjmp(XtasMyEnv
, 1);
276 /*---------------------------------------------------------------------------*/
278 /* FUNCTION : XtasGetWarningMess */
280 /* IN ARGS : .message : The message to be drawn to the user. */
282 /* OUT ARGS : ( void ) */
284 /* OBJECT : Treatment of Application's Warning */
286 /*---------------------------------------------------------------------------*/
287 void XtasGetWarningMess( )
293 fprintf(stderr
,"\n") ;
295 i
= read(tas_pfd
[0],buffer
,4095) ;
305 while((isspace((int)*pt
) != 0) && (*pt
!= '\0'))
311 if ( XtasWarningWidget
)
313 XalForceUpdate( XtasDeskMessageField
);
314 XalDrawMessage( XtasWarningWidget
, pt
);
318 /*---------------------------------------------------------------------------*/
320 /* FUNCTION : XtasGetOutMess */
322 /* IN ARGS : .message : The message to be drawn to the user. */
324 /* OUT ARGS : ( void ) */
326 /* OBJECT : Treatment of Application's Warning */
328 /*---------------------------------------------------------------------------*/
329 void XtasGetOutMess( )
335 fprintf(stdout
,"\n") ;
337 i
= read(tas_out
[0],buffer
,65534) ;
346 //while((isspace((int)*pt) != 0) && (*pt != '\0'))
352 if ( XtasTraceWidget
)
354 XalForceUpdate( XtasDeskMessageField
);
355 XalDrawMessage( XtasTraceWidget
, pt
);
358 /*---------------------------------------------------------------------------*/
360 /* FUNCTION : XtasClearAllStream */
362 /*---------------------------------------------------------------------------*/
363 void XtasClearAllStream( )
367 fprintf(stdout
,"\n") ;
369 read(tas_out
[0],buffer
,65536) ;
370 fprintf(stderr
,"\n") ;
372 read(tas_pfd
[0],buffer
,65536) ;