wtloop.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/
00002 /*
00003  * Copyright (C) 1986 - 1993   Thomas Williams, Colin Kelley
00004  *
00005  * Permission to use, copy, and distribute this software and its
00006  * documentation for any purpose with or without fee is hereby granted, 
00007  * provided that the above copyright notice appear in all copies and 
00008  * that both that copyright notice and this permission notice appear 
00009  * in supporting documentation.
00010  *
00011  * Permission to modify the software is granted, but not the right to
00012  * distribute the modified code.  Modifications are to be distributed 
00013  * as patches to released version.
00014  *  
00015  * This software is provided "as is" without express or implied warranty.
00016  *
00017  * AUTHORS
00018  *   Original Software:
00019  *     Thomas Williams,  Colin Kelley.
00020  *   Gnuplot 2.0 additions:
00021  *       Russell Lang, Dave Kotz, John Campbell.
00022  *   Gnuplot 3.0 additions:
00023  *       Gershon Elber and many others.
00024  *   
00025  * Modified for Scilab (1996) : Jean-Philippe Chancelier 
00026  * (2005) Allan CORNET
00027  *        
00028  */
00029 /*-----------------------------------------------------------------------------------*/
00030 #ifndef STRICT
00031   #define STRICT
00032 #endif
00033 
00034 #include <stdio.h>
00035 #include <setjmp.h>
00036 #include <signal.h>
00037 #ifdef XPG3_LOCALE
00038   #include <locale.h>
00039 #endif
00040 #include <signal.h>
00041 #include <string.h>
00042 #include <stdlib.h>
00043 #include <conio.h>
00044 #include "wresource.h"
00045 #include "wcommon.h"
00046 #include "stack-c.h" 
00047 #include "Os_specific.h" /* isanan */ 
00048 #include "Messages.h"
00049 #include "Warnings.h"
00050 #include "Errors.h"
00051 
00052 /*-----------------------------------------------------------------------------------*/
00053 extern int C2F(sciquit)(void );
00054 static void interrupt_setup ();
00055 extern void realmain(int nowin,int no_startup_flag,char *initial_script,int initial_script_type,int memory);
00056 /*-----------------------------------------------------------------------------------*/
00057 jmp_buf env;
00058 /*-----------------------------------------------------------------------------------*/
00059 /***********************************************
00060  * SIGINT is not used up to now 
00061  * CtrC are detected in readline or in ScilabXloop 
00062  * TextMessage1  while we are in a scilab window 
00063  * the function SignalCtrC set a flag 
00064  * for scilab 
00065  ***********************************************/
00066 void SignalCtrC (void)
00067 {
00068   int j = 2;
00070   C2F (sigbas) (&j);
00071 
00072 }
00073 /*-----------------------------------------------------------------------------------*/
00074 void inter (int an_int)
00075 {
00076   (void) signal (SIGINT, inter);
00077   (void) signal (SIGFPE, SIG_DFL);      /* turn off FPE trapping */
00078   (void) fflush (stdout);
00079   sciprint ("\n");
00080   longjmp (env, TRUE);          /* return to prompt  */
00081 }
00082 /*-----------------------------------------------------------------------------------*/
00083 /* Set up to catch interrupts */
00084 static void interrupt_setup (void)
00085 {
00086   (void) signal (SIGINT, inter);
00087 }
00088 /*-----------------------------------------------------------------------------------*/
00089 void sci_windows_main (int nowin, int *nos, char *path,int pathtype,int *lpath,int memory)
00090 {
00091   setbuf (stderr, (char *) NULL);
00092   if (!setjmp (env))
00093     {
00094       /* first time */
00095       interrupt_setup ();
00096     }
00097   else
00098     {
00099       /* come back here from int_error() */
00100       if (nowin != 1)
00101         SetCursor (LoadCursor ((HINSTANCE) NULL, IDC_ARROW));
00102     }
00103   /* take commands from stdin */
00104   realmain(nowin,*nos,path,pathtype,memory);
00105 
00106 }
00107 /*-----------------------------------------------------------------------------------*/
00108 void sci_clear_and_exit(int n) /* used with handlers */ 
00109 {
00110 #ifdef _DEBUG
00111   char Message[256];
00112   switch (n)
00113   {
00114           case SIGINT:
00115                   wsprintf(Message,MSG_ERROR59);
00116                   break;
00117           case SIGILL:
00118                   wsprintf(Message,MSG_ERROR60);
00119                   break;
00120           case SIGFPE:
00121                   wsprintf(Message,MSG_ERROR61);
00122                   break;
00123           case SIGSEGV:
00124                   wsprintf(Message,MSG_ERROR62);
00125                   break;
00126           case SIGTERM:
00127                   wsprintf(Message,MSG_ERROR63);
00128                   break;
00129           case SIGBREAK:
00130                   wsprintf(Message,MSG_ERROR64);
00131                   break;
00132           case SIGABRT:
00133                   wsprintf(Message,MSG_ERROR65);
00134                   break;
00135           default:
00136                   wsprintf(Message,MSG_ERROR66);
00137                   break;
00138   }
00139   MessageBox(NULL,Message,MSG_ERROR20,MB_ICONWARNING);
00140 #else
00141   /*MessageBox(NULL,MSG_WARNING30,MSG_WARNING22,MB_ICONWARNING);*/
00142 #endif
00143   C2F(sciquit)();
00144 }
00145 /*-----------------------------------------------------------------------------------*/
00146 /*-------------------------------------------------------
00147  * usr1 signal : used to transmit a Control C to 
00148  * scilab 
00149  *-------------------------------------------------------*/
00150 void sci_usr1_signal(int n) 
00151 {
00152   controlC_handler(n);
00153 }
00154 /*-----------------------------------------------------------------------------------*/
00155 /*-------------------------------------------------------
00156  * Ctrl-Z : stops the current computation 
00157  *          or the current interface call 
00158  *-------------------------------------------------------*/
00159 void  sci_sig_tstp(int n)
00160 {
00161   Scierror(999,MSG_ERROR67);
00162 }
00163 /*-----------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:03:55 2007 for Scilab [trunk] by  doxygen 1.5.1