File: wtloop.c

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (301 lines) | stat: -rw-r--r-- 8,671 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*-----------------------------------------------------------------------------------*/
/*
 * Copyright (C) 1986 - 1993   Thomas Williams, Colin Kelley
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for any purpose with or without fee is hereby granted, 
 * provided that the above copyright notice appear in all copies and 
 * that both that copyright notice and this permission notice appear 
 * in supporting documentation.
 *
 * Permission to modify the software is granted, but not the right to
 * distribute the modified code.  Modifications are to be distributed 
 * as patches to released version.
 *  
 * This software is provided "as is" without express or implied warranty.
 *
 * AUTHORS
 *   Original Software:
 *     Thomas Williams,  Colin Kelley.
 *   Gnuplot 2.0 additions:
 *       Russell Lang, Dave Kotz, John Campbell.
 *   Gnuplot 3.0 additions:
 *       Gershon Elber and many others.
 *   
 * Modified for Scilab (1996) : Jean-Philippe Chancelier 
 * (2005) Allan CORNET
 *        
 */
/*-----------------------------------------------------------------------------------*/
#ifndef STRICT
  #define STRICT
#endif

#include <stdio.h>
#include <setjmp.h>
#include <signal.h>
#ifdef XPG3_LOCALE
  #include <locale.h>
#endif
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>

//#include "plot.h"
#include "wresource.h"
#include "wcommon.h"
#include "../os_specific/Os_specific.h" 
#include "../stack-c.h" 

#include "Messages.h"
#include "Warnings.h"
#include "Errors.h"


/*-----------------------------------------------------------------------------------*/
extern int C2F (stimer) (void);
extern void C2F (settmpdir) (void);
extern void C2F (tmpdirc) (void);
extern void C2F (getenvc) (int *ierr, char *var, char *buf, int *buflen, int *iflag);
extern char *get_sci_data_strings (int n);
extern int C2F(sciquit)(void );
extern int C2F(scirun)(char * startup, int lstartup);
extern int C2F(inisci)(int *,int *,int *);
extern int IsNoInteractiveWindow(void);
extern BOOL IsWindowInterface(void);
extern char *GetExceptionString(DWORD ExceptionCode);
static void interrupt_setup ();
static void realmain(int nos,char *initial_script,int initial_script_type,int lpath,int memory);
static int sci_exit(int n) ;
/*-----------------------------------------------------------------------------------*/
static int  no_startup_flag=0;
jmp_buf env;
extern char input_line[];
/*-----------------------------------------------------------------------------------*/
/***********************************************
 * SIGINT is not used up to now 
 * CtrC are detected in readline or in jpc_Xloop 
 * TextMessage1  while we are in a scilab window 
 * the function SignalCtrC set a flag 
 * for scilab 
 ***********************************************/
void SignalCtrC (void)
{
  int j = 2;
/**  SIGINT; **/
  C2F (sigbas) (&j);

}
/*-----------------------------------------------------------------------------------*/
void inter (int an_int)
{
  (void) signal (SIGINT, inter);
  (void) signal (SIGFPE, SIG_DFL);	/* turn off FPE trapping */
  (void) fflush (stdout);
  sciprint ("\n");
  longjmp (env, TRUE);		/* return to prompt  */
}
/*-----------------------------------------------------------------------------------*/
/* Set up to catch interrupts */
static void interrupt_setup (void)
{
  (void) signal (SIGINT, inter);
}
/*-----------------------------------------------------------------------------------*/
void sci_windows_main (int nowin, int *nos, char *path,int pathtype,int *lpath,int memory)
{
#ifdef XPG3_LOCALE
  (void) setlocale (LC_CTYPE, "");
#endif
  setbuf (stderr, (char *) NULL);
  if (!setjmp (env))
    {
      /* first time */
      interrupt_setup ();
    }
  else
    {
      /* come back here from int_error() */
      if (nowin != 1)
	SetCursor (LoadCursor ((HINSTANCE) NULL, IDC_ARROW));
    }
  /* take commands from stdin */
	realmain (*nos, path,pathtype,*lpath,memory);
}
/*-----------------------------------------------------------------------------------*/
void sci_clear_and_exit(int n) /* used with handlers */ 
{
#ifdef _DEBUG
  char Message[256];
  switch (n)
  {
	  case SIGINT:
		  wsprintf(Message,MSG_ERROR59);
		  break;
	  case SIGILL:
		  wsprintf(Message,MSG_ERROR60);
		  break;
	  case SIGFPE:
		  wsprintf(Message,MSG_ERROR61);
		  break;
	  case SIGSEGV:
		  wsprintf(Message,MSG_ERROR62);
		  break;
	  case SIGTERM:
		  wsprintf(Message,MSG_ERROR63);
		  break;
	  case SIGBREAK:
		  wsprintf(Message,MSG_ERROR64);
		  break;
	  case SIGABRT:
		  wsprintf(Message,MSG_ERROR65);
		  break;
	  default:
		  wsprintf(Message,MSG_ERROR66);
		  break;
  }
  MessageBox(NULL,Message,MSG_ERROR20,MB_ICONWARNING);
#else
  MessageBox(NULL,MSG_WARNING30,MSG_WARNING22,MB_ICONWARNING);
#endif
  WinExit();
  C2F(sciquit)();
}
/*-----------------------------------------------------------------------------------*/
static void realmain(int nos,char *initial_script,int initial_script_type,int lpath,int memory)
{
	int ierr;
	static int ini=-1;
	char startup[256];
	/* create temp directory */
	C2F(settmpdir)();

	/* signals */
	signal(SIGINT,sci_clear_and_exit);
	signal(SIGILL,sci_clear_and_exit);
	signal(SIGFPE,sci_clear_and_exit);
	signal(SIGSEGV,sci_clear_and_exit);
	signal(SIGTERM,sci_clear_and_exit);
	signal(SIGBREAK,sci_clear_and_exit);
	signal(SIGABRT,sci_clear_and_exit);

	/*  prepare startup script  */
	if ( nos != 1 ) 
	{
		/* execute a startup */
		no_startup_flag = 0;
		if ( initial_script != NULL ) 
		{
			switch ( initial_script_type ) 
			{
				case 0 : 
					sprintf(startup,"%s;exec('%s',-1)",get_sci_data_strings(1),initial_script);
				break;
				case 1 : 
					sprintf(startup,"%s;%s;",get_sci_data_strings(1),initial_script);
				break;
			}
		}
		else sprintf(startup,"%s;",get_sci_data_strings(1));
	}
	else 
	{
		/* No startup but maybe an initial script  */
		no_startup_flag = 1;
		if ( initial_script != NULL ) 
			switch ( initial_script_type ) 
			{
				case 0 : 
					sprintf(startup,"exec('%s',-1)",initial_script);
				break;
				case 1 : 
					sprintf(startup,"%s;",initial_script);
				break;
			}
		else  sprintf(startup," ");
	}

	/* initialize scilab interp  */
	C2F(inisci)(&ini, &memory, &ierr);
	if (ierr > 0) sci_exit(1) ;

	/* execute the initial script and enter scilab */ 
	#ifndef _DEBUG
		_try
			{
				C2F(scirun)(startup,strlen(startup));
			}
		_except (EXCEPTION_EXECUTE_HANDLER) 
			{
				Rerun:
					{
						char *ExceptionString=GetExceptionString(GetExceptionCode());
						sciprint("Warning !!!\nScilab has found a critical error (%s).\nScilab may become unstable.\n",ExceptionString);
						if (ExceptionString) {FREE(ExceptionString);ExceptionString=NULL;}
					}
				_try
					{
						C2F(scirun)("",strlen(""));
}
						_except (EXCEPTION_EXECUTE_HANDLER) 
						{
							goto Rerun;
						}

					}
	#else
		C2F(scirun)(startup,strlen(startup));
	#endif

	/* cleaning */ /* Allan CORNET 18/01/2004 */
	WinExit();
	C2F(sciquit)(); 
	C2F(tmpdirc)();
}
/*-----------------------------------------------------------------------------------*/
/*-------------------------------------------------------
 * Exit function called by some 
 * X11 functions 
 * call sciquit which call clear_exit
 *-------------------------------------------------------*/
int C2F(sciquit)()            /* used at Fortran level */
{
  int status = 0;
  /* fprintf(stderr,"I Quit Scilab through sciquit\n"); */
  if ( no_startup_flag == 0) 
    {
      char *quit_script =  get_sci_data_strings(5);
      C2F(scirun)(quit_script,strlen(quit_script));
    }
  return sci_exit(status) ;
} 
/*-----------------------------------------------------------------------------------*/
int sci_exit(int n) 
{
  /* fprintf(stderr,"I Quit Scilab through sci_exit\n");*/
  /** clean tmpfiles **/
  C2F(tmpdirc)();
  /* really exit */
  exit(n);
  return(0);
}
/*-----------------------------------------------------------------------------------*/
/*-------------------------------------------------------
 * usr1 signal : used to transmit a Control C to 
 * scilab 
 *-------------------------------------------------------*/
void sci_usr1_signal(int n) 
{
  controlC_handler(n);
}
/*-----------------------------------------------------------------------------------*/
/*-------------------------------------------------------
 * Ctrl-Z : stops the current computation 
 *          or the current interface call 
 *-------------------------------------------------------*/
void  sci_sig_tstp(int n)
{
  Scierror(999,MSG_ERROR67);
}
/*-----------------------------------------------------------------------------------*/