File: x_main.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 (789 lines) | stat: -rw-r--r-- 19,922 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
/*---------------------------------------------------------- 
 * Real main function for Scilab on X11 platform 
 *----------------------------------------------------------*/
/* main.c */

#include <pwd.h>
#include <ctype.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>

#include "x_ptyxP.h"
#include "x_data.h"
#include "x_error.h"
#include "x_menu.h"
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xaw3d/Form.h>
#include <X11/Xos.h>
#include <X11/cursorfont.h>
#include <X11/Xaw3d/SimpleMenu.h>

#include "../version.h"
#include "../machine.h"
#include "../graphics/Math.h"

#include "../graphics/DestroyObjects.h"

extern void  controlC_handler(int n);

#include "All-extern-x.h"
#include "All-extern.h"

#ifdef USE_TERMIOS
#include <termios.h>
/* this hacked termios support only works on SYSV */
#define USE_SYSV_TERMIO
#define termio termios
#undef TCGETA
#define TCGETA TCGETS
#undef TCSETA
#define TCSETA TCSETS
#else /* USE_TERMIOS */
#ifdef SYSV
#include <sys/termio.h>
#endif /* SYSV */
#endif /* USE_TERMIOS else */

#ifndef SYSV				/* BSD systems */
/* #include <sgtty.h> */
#include <sys/resource.h>
#endif	/* !SYSV */

#include <stdio.h>
#include <errno.h>

#include <sys/param.h>	/* for NOFILE */

#ifdef  PUCC_PTYD
#include <local/openpty.h>
int	Ptyfd;
#endif /* PUCC_PTYD */

#ifndef X_NOT_POSIX
#include <unistd.h>
#else
extern long lseek();
#ifdef USG
extern unsigned sleep();
#else
extern void sleep();
#endif
#endif

#ifndef X_NOT_STDC_ENV
#include <stdlib.h>
#else
extern char *malloc();
extern char *calloc();
extern char *realloc();
extern char *getenv();
extern void exit();
#endif

char *ProgramName;

#ifdef WITH_TK
/*  extern void initTCLTK(void);
  extern void flushTKEvents(void); */
#endif


extern void sci_clear_and_exit (int);
extern int C2F(nofpex) (void);
extern int C2F(scigetarg) (int *,char *,long int l);
extern int C2F(sciiargc) (void);
extern void C2F(settmpdir) (void);
extern char *get_sci_data_strings (int n);
extern void C2F(tmpdirc)();
extern char *strindex ();
extern void do_hangup();
extern void do_kill();
extern void sci_usr1_signal(int n) ;

static void Syntax  __PARAMS((char *badOption));  
static void strip_blank  __PARAMS((char *source));  
static void Syntax  (char *badOption);  
static char ** create_argv(int *argc);
static void strip_blank(char *source);

extern sciPointObj *pfiguremdl; /* F.Leray 18.11.04 : used to be destroyed with sciquit */
extern sciPointObj *paxesmdl;   /* F.Leray 18.11.04 : used to be destroyed with sciquit */

/*---------------------------------------------------------- 
 * mainsci.f directly call this function 
 * thus this is the real main for scilab 
 * Copyright Inria/Enpc 
 *----------------------------------------------------------*/

#define MIN_STACKSIZE 180000

static int  no_startup_flag=0;
static int  memory = MIN_STACKSIZE;
static int  no_window = 0;
static char * initial_script = NULL;
static int  initial_script_type = 0; /* 0 means filename 1 means code */
extern void settexmacs();

int  sci_show_banner=1;

void C2F(realmain)()
{
  int ierr, argc,i;
  static int ini=-1;
  char startup[256];
  char **argv, *display = NULL;
  
  #if (defined __GNUC__  )
		putenv ("COMPILER=gcc");
	#else
		putenv ("COMPILER=cc or another");
	#endif

  /* floating point exceptions */
  C2F(nofpex)(); 
  /* create argv */
  if (( argv = create_argv(&argc))== NULL) 
    exit(1);
  ProgramName = argv[0];
  /* scanning options */
  for ( i=0 ; i < argc ; i++) 
    {
      if ( strcmp(argv[i],"-nw") == 0) 
	{ no_window = 1; } 
      if ( strcmp(argv[i],"-nwni") == 0) 
	{ no_window = 1; } 
      else if ( strcmp(argv[i],"-display") == 0) 
	{ 
	  char dpy[128];
	  sprintf(dpy,"DISPLAY=%s",display);
	  putenv(dpy);
	} 
      else if ( strcmp(argv[i],"-nb") == 0) { sci_show_banner = 0; }
      else if ( strcmp(argv[i],"-ns") == 0)  { no_startup_flag = 1;}
      else if ( strcmp(argv[i],"-mem") == 0) { i++;memory = Max(atoi(argv[i]),MIN_STACKSIZE );} 
      else if ( strcmp(argv[i],"-f") == 0) { initial_script = argv[++i];} 
      else if ( strcmp(argv[i],"-e") == 0) 
	{
	  initial_script = argv[++i];
	  initial_script_type = 1;
	} 
      else if ( strcmp(argv[i],"--texmacs") == 0)  { no_window = 1;settexmacs();}

    }
  /* create temp directory */
  C2F(settmpdir)();
  /* signals */
  signal(SIGINT,sci_clear_and_exit);
  signal(SIGBUS,sci_clear_and_exit);
  signal(SIGSEGV,sci_clear_and_exit);
  signal(SIGQUIT,sci_clear_and_exit);
  signal(SIGHUP,sci_clear_and_exit);
  signal(SIGUSR1,sci_usr1_signal);
  /*  prepare startup script  */

  if ( no_startup_flag == 0) 
    {
      /* execute a startup */
      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  */
      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," ");
    }
    
 #ifdef WITH_TK
   /*initTCLTK();
   flushTKEvents();*/
 #endif
  

  if ( no_window == 0 ) 
    {
      /* we are in window mode */
      SetXsciOn();
    }

  if ( no_window == 0 ) 
    {
      /* enters window mode first then 
       * call inisci and scirun 
       */
      main_sci(argc,argv,startup,strlen(startup),memory);
    }
  else 
    {
      /* initialize scilab interp  */
      C2F(inisci)(&ini, &memory, &ierr);
      if (ierr > 0) sci_exit(1) ;
      /* execute the initial script and enter scilab */ 
      C2F(scirun)(startup,strlen(startup));
    }
  /* cleaning */
  C2F(sciquit)();
  return ;
}


Boolean   sunFunctionKeys = False;

static struct _resource {
    char *xterm_name;
    char *icon_geometry;
    char *title;
    char *icon_name;
    char *term_name;
    char *tty_modes;
    Boolean noWindow;
    Boolean noStartup;
    Boolean useInsertMode;
    String visualType;
} resource;

/* used by VT (charproc.c) */

#define offset(field)	XtOffsetOf(struct _resource, field)

XtResource application_resources[] = {
    {"noWindow", "NoWindow", XtRBoolean, sizeof(Boolean),
	offset(noWindow), XtRString, "false"},
    {"noStartup", "NoStartup",XtRBoolean, sizeof(Boolean),
	offset(noStartup), XtRString, "false"},
    {"termName", "TermName", XtRString, sizeof(char *),
	offset(term_name), XtRString, (caddr_t) NULL},
    {"name", "Name", XtRString, sizeof(char *),
	offset(xterm_name), XtRString, "xterm"},
    {"iconGeometry", "IconGeometry", XtRString, sizeof(char *),
	offset(icon_geometry), XtRString, (caddr_t) NULL},
    {XtNtitle, XtCTitle, XtRString, sizeof(char *),
	offset(title), XtRString, VERSION},
    {XtNiconName, XtCIconName, XtRString, sizeof(char *),
	offset(icon_name), XtRString, VERSION},
    {"ttyModes", "TtyModes", XtRString, sizeof(char *),
	offset(tty_modes), XtRString, (caddr_t) NULL},
    {"useInsertMode", "UseInsertMode", XtRBoolean, sizeof (Boolean),
        offset(useInsertMode), XtRString, "false"},
    {"visualType", "VisualType", XtRString, sizeof(String),
	offset(visualType), XtRImmediate, (XtPointer)"" }
};

struct _color {
  char *c1;
}; /**  colors; **/

XtResource app_colors[] = {
  {"xscilab.color*Command.background", "Xscilab*Command.Background", 
     XtRString, sizeof(String),
     XtOffsetOf(struct _color, c1), NULL,NULL}
};

static char *fallback_resources[] = {
#include "Xscilab.ad.h"
    NULL
};

/* Command line options table.  Only resources are entered here...there is a
   pass over the remaining options after XrmParseCommand is let loose. */

static XrmOptionDescRec optionDescList[] = {
{"-geometry",	"*vtsci.geometry",XrmoptionSepArg,	(caddr_t) NULL},
{"-tm",		"*ttyModes",  XrmoptionSepArg,	(caddr_t) NULL},
{"-tn",		"*termName",  XrmoptionSepArg,	(caddr_t) NULL},
{"-nw",		"*noWindow",  XrmoptionNoArg,	(caddr_t) "on"},
{"-nwni",		"*noWindow",  XrmoptionNoArg,	(caddr_t) "on"},
{"-ns",		"*noStartup", XrmoptionNoArg,	(caddr_t) "on"},
};

static struct _options {
  char *opt;
  char *desc;
} options[] = {
  { "-help",                 "print out this message" },
  { "-ns",                   "no startup mode " },
  { "-nw",                   "no window mode " },
  { "-nwni",                 "no window mode also" },
  { "-display displayname",  "X server to contact" },
  { "-name string",          "client instance, icon, and title strings" },
  { "-xrm resourcestring",   "additional resource specifications" },
  { "-tm string",            "terminal mode keywords and characters" },
  { NULL, NULL }
};

extern WidgetClass xtermWidgetClass;

Arg ourTopLevelShellArgs[] = {
  { XtNallowShellResize, (XtArgVal) TRUE },	
  { XtNinput, (XtArgVal) TRUE },
};
int number_ourTopLevelShellArgs = 2;
	
XtAppContext app_con;
Widget toplevel = (Widget) NULL;
Widget realToplevel = (Widget) NULL;

/*
 * DeleteWindow(): Action proc to implement ICCCM delete_window.
 */

void
DeleteWindow(w, event, params, num_params)
    Widget w;
    XEvent *event;
    String *params;
    Cardinal *num_params;
{
 sci_clear_and_exit(0); 
}


void
KeyboardMapping(w, event, params, num_params)
    Widget w;
    XEvent *event;
    String *params;
    Cardinal *num_params;
{
    switch (event->type) {
       case MappingNotify:
	  XRefreshKeyboardMapping(&event->xmapping);
	  break;
    }
}

/** extern void  SGDeleteWindow(); **/

static XtActionsRec actionProcs[] = {
  {"DeleteWindow", DeleteWindow},
  {"SGDeleteWindow", SGDeleteWindow},
  {"KeyboardMapping", KeyboardMapping}
};


/* used by scilab to know the dpy and toplevel */

int Xscilab(dpy,topwid)
     Display **dpy;
     Widget *topwid;
{
  *topwid=toplevel;
  if ( toplevel != (Widget) NULL) *dpy=XtDisplay(toplevel);
  return(1);
}

Atom wm_delete_window;

/*
 * initColors: To allow resources to be specified separately for color
 *	and mono displays, we add a dummy Form widget below realToplevel
 *	in appropriate circumstances.
 */

#define ADDTOPLEVEL(NAME) \
	toplevel_w = XtCreateManagedWidget(NAME,formWidgetClass, \
					 realToplevel_w,(ArgList)0 ,(Cardinal)0);

static int screencolor = 1 ; /* default screen color status */

/* return the current screencolor */

void getcolordef(screenc)
     integer *screenc;
{
  *screenc= screencolor;
}

void setcolordef(screenc)
     int screenc;
{
  screencolor = screenc;
}


Widget initColors(realToplevel_w)
     Widget realToplevel_w;
{
  int i;
  Widget toplevel_w ;
  Screen *Xscreen;
  Visual *visual;
  /* The default is no extra widget (ie. mono) */
  toplevel_w = realToplevel_w;
  Xscreen = XtScreen(realToplevel_w);
  C2F(xscion)(&i);/* is it a scilab -nw */
  if ( i != 0 ) 
    {
      /* If we are using a scilab -nw 
       *  resource.visualType == NULL
       *
       * See if the user has specified a type */
      if (strcmp(resource.visualType,"mono") == 0) {
	/* Ton van Overbeek patch 22/08/00 */
	return toplevel_w;
      } else if (strcmp(resource.visualType,"color") == 0) {
	ADDTOPLEVEL("color");
	/* Ton van Overbeek patch 22/08/00 */
	return toplevel_w;
      } else if (strcmp(resource.visualType,"gray") == 0) {
	ADDTOPLEVEL("gray");
	/* Ton van Overbeek patch 22/08/00 */
	return toplevel_w;
      }
    }
  /* Otherwise we try to figure it out */
  if ((visual=XDefaultVisualOfScreen(Xscreen)) == NULL) {
    fprintf(stderr,"Scilab: can't get info about visual!\n");
    return toplevel_w;
  }
  if (visual->map_entries > 2) {
    switch (visual->class) {
    case StaticColor:
    case PseudoColor:
    case TrueColor:
    case DirectColor:
      ADDTOPLEVEL("color");
      screencolor = 1;
      break;
    case StaticGray:
    case GrayScale:
      ADDTOPLEVEL("gray");
      screencolor = 0;
      break;
    default:
      screencolor = 0;
      toplevel_w = realToplevel_w;
    }
  } else {
      screencolor = 0;
      toplevel_w = realToplevel_w;
  }
  /* Ton van Overbeek patch 22/08/00 */
  return toplevel_w;
}

void main_sci (int argc,char ** argv, char *startup, int lstartup,int memory)
{
  XtermWidget CreateSubWindows();
  register TScreen *screen;
  register int  pty;
  int Xsocket;
  /* Init the Toolkit. */
  realToplevel = toplevel = 
    XtAppInitialize(&app_con, "Xscilab", 
		    optionDescList, XtNumber(optionDescList), 
		    &argc, argv, fallback_resources, 
		    (ArgList) 0,(Cardinal) 0);				     
  XtGetApplicationResources(toplevel, (XtPointer) &resource,
			    application_resources,
			    XtNumber(application_resources), 
			    (ArgList) 0,(Cardinal) 0);
  /** 
  XtGetApplicationResources(toplevel, (XtPointer) &colors, 
			    app_colors,
			    XtNumber(app_colors), 
			    (ArgList) 0,(Cardinal) 0);
  printf("Color: %s\n",colors.c1);
  **/
  XtAppAddActions(app_con, actionProcs, XtNumber(actionProcs));
  toplevel =   initColors(realToplevel);
   /* SetXsciOn();  */ /*Already done in realmain */
  xterm_name = resource.xterm_name;
  if (strcmp(xterm_name, "-") == 0) xterm_name = "xterm";
  XtSetValues (toplevel, ourTopLevelShellArgs,
	       (Cardinal)  number_ourTopLevelShellArgs);
  /* Parse the rest of the command line 
   * the arguments parsed by XtAppInitialize must be the last ones 
   * and here we can check that arguments belong to options 
   * this is to be updated 
   */
  /* 
  for (argc--, argv++ ; argc > 0 ; argc--, argv++) 
    {
      if(**argv != '-') Syntax (*argv);
      switch(argv[0][1]) {
      case 'h':
	Help ();      break;
	/ * NOTREACHED * /
      default:
	Syntax (*argv);
      }
    }
  */
  XawSimpleMenuAddGlobalActions (app_con);
  XtRegisterGrabAction (HandlePopupMenu, True,
			(ButtonPressMask|ButtonReleaseMask),
			GrabModeAsync, GrabModeAsync);
  term = CreateSubWindows(toplevel);
  screen = &term->screen;
  if (screen->savelines < 0) screen->savelines = 0;
  term->flags = 0;
  if (!screen->jumpscroll) {
    term->flags |= SMOOTHSCROLL;
    update_jumpscroll();
  }
  if (term->misc.reverseWrap) {
    term->flags |= REVERSEWRAP;
    update_reversewrap();
  }
  if (term->misc.autoWrap) {
    term->flags |= WRAPAROUND;
    update_autowrap();
  }
  if (term->misc.re_verse) {
    term->flags |= REVERSE_VIDEO;
    update_reversevideo();
  }
  
  term->initflags = term->flags;
  
  if (term->misc.appcursorDefault) {
    term->keyboard.flags |= CURSOR_APL;
    update_appcursor();
  }
  
  if (term->misc.appkeypadDefault) {
    term->keyboard.flags |= KYPD_APL;
    update_appkeypad();
  }
  
  /* open a terminal for client */
  screen->arrow = make_colored_cursor (XC_left_ptr, 
				       screen->mousecolor,
				       screen->mousecolorback);
  /* avoid double MapWindow requests */
  XtSetMappedWhenManaged( XtParent(term), False );
  wm_delete_window = XInternAtom(XtDisplay(realToplevel),"WM_DELETE_WINDOW",False);
  VTInit1(realToplevel);
  Xsocket = ConnectionNumber(screen->display);
  pty = screen->respond;
  pty_mask = 1 << pty;
  X_mask = 1 << Xsocket;
  Select_mask = pty_mask | X_mask;
  max_plus1 = (pty < Xsocket) ? (1 + Xsocket) : (1 + pty); 
  XSetErrorHandler((XErrorHandler)xerror);
  XSetIOErrorHandler((XIOErrorHandler)xioerror);
  /* initialize xterm and run scilab  */
  VTRun(startup,lstartup,memory);

}



#ifdef sun 
#ifndef SYSV
#include <sys/ieeefp.h>
clear_ieee_warnings()
{
  char *mode, **out, *in;
  ieee_flags("clearall","exeption","all", &out);
}
#endif 
#endif 

/* following include needed for solaris */
#if defined(solaris) && defined(__STDC__) 
#include <stropts.h>
#include <poll.h>
#endif

int GetBytesAvailable (fd)
    int fd;
{
#ifdef FIONREAD
    static long arg;
    ioctl (fd, FIONREAD, (char *) &arg);
    return (int) arg;
#else
    struct pollfd pollfds[1];
    pollfds[0].fd = fd;
    pollfds[0].events = POLLIN;
    return poll (pollfds, 1, 0);
#endif
}

/* utility */

#define BSIZE 128 

static char ** create_argv(int *argc)
{
  int i;
  char **argv;
  *argc = C2F(sciiargc)() + 1;
  if ( ( argv = malloc((*argc)*sizeof(char *))) == NULL) return NULL;
  for ( i=0 ; i < *argc ; i++) 
    {
      char buf[BSIZE];
      C2F(scigetarg)(&i,buf,BSIZE);
      buf[BSIZE-1]='\0';
      strip_blank(buf);
      argv[i] = malloc((strlen(buf)+1)*sizeof(char));
      if ( argv[i] == NULL) return NULL;
      strcpy(argv[i],buf);
      /* fprintf(stderr,"arg[%d] %s\n",i,argv[i]);*/
    }
  return argv;
}

/* utility */

static void strip_blank(char *source)
{
  char *p;
  p = source;
  /* look for end of string */
  while(*p != '\0') p++;
  while(p != source) {
    p--;
    if(*p != ' ') break;
    *p = '\0';
  }
}

/*-------------------------------------------------------
 * Exit function called by some 
 * X11 functions 
 * call sciquit which call clear_exit
 *-------------------------------------------------------*/

int C2F(sciquit)(void)            /* used at Fortran level */
{
  int status = 0;
  /* fprintf(stderr,"I Quit Scilab through sciquit\n"); */

 /* F.Leray : graphic objects models (for axe and figure) can now be deleted */
  DestroyAllGraphicsSons(pfiguremdl); paxesmdl = (sciPointObj *) NULL;
  DestroyFigure(pfiguremdl); pfiguremdl = (sciPointObj *) NULL;
  
  if ( no_startup_flag == 0) 
    {
      char *quit_script =  get_sci_data_strings(5);
      C2F(scirun)(quit_script,strlen(quit_script));
    }
  sci_exit(status) ;
  return 0;
} 

void sci_clear_and_exit(int n) /* used with handlers */ 
{
  /* fprintf(stderr,"I Quit Scilab through sci_clear_and_exit\n"); */
  C2F(sciquit)();
}

int sci_exit(int n) 
{
  /* fprintf(stderr,"I Quit Scilab through sci_exit\n");*/
  /** clean tmpfiles **/
  C2F(tmpdirc)();
  /** clean ieee **/
#ifdef sun 
#ifndef SYSV
#include <sys/ieeefp.h>
  {
    char *mode, **out, *in;
    ieee_flags("clearall","exeption","all", &out);
  }
#endif 
#endif 
  /* really exit */
  exit(n);
  return(0);
}

/*-------------------------------------------------------
 * usr1 signal : used to transmit a Control C to 
 * scilab 
 *-------------------------------------------------------*/

void sci_usr1_signal(int n) 
{
  /* fprintf(stderr," usr1 signal "); */
  controlC_handler(n);
}

/*-------------------------------------------------------
 * Ctrl-Z : stops the current computation 
 *          or the current interface call 
 *-------------------------------------------------------*/

void  sci_sig_tstp(int n)
{
  Scierror(999,"SIGSTP: aborting current computation\r\n");
}

/*-------------------------------------------------------
 * Utility function to try to hide system differences from
 * everybody who used to call killpg() 
 *-------------------------------------------------------*/

int kill_process_group(pid, sig)
    int pid;
    int sig;
{
    return kill (-pid, sig);
}

/*-------------------------------------------------------
 * Syntax 
 *-------------------------------------------------------*/

static void Syntax (badOption)
    char *badOption;
{
  struct _options *opt;
  int col;

  fprintf (stderr, "%s:  bad command line option \"%s\"\r\n\n",
	   ProgramName, badOption);

  fprintf (stderr, "usage:  %s", ProgramName);
  col = 8 + strlen(ProgramName);
  for (opt = options; opt->opt; opt++) {
    int len = 3 + strlen(opt->opt);	 /* space [ string ] */
    if (col + len > 79) {
      fprintf (stderr, "\r\n   ");  /* 3 spaces */
      col = 3;
    }
    fprintf (stderr, " [%s]", opt->opt);
    col += len;
  }

  fprintf (stderr, "\r\n\nType %s -help for a full description.\r\n\n",
	   ProgramName);
  exit (1);
}

/* V.C 04/2004 */
/* Function used to know if we are in window mode (returned value is 1) */
/* or in console mode (returned value is 0) */
int IsConsoleMode(void)
{
  return no_window;
}