realmain.c File Reference

#include "realmain.h"
#include "MALLOC.h"
#include "sciprint.h"
#include "xscion.h"
#include "getarg.h"
#include "inffic.h"
#include "scirun.h"
#include "sciquit.h"

Include dependency graph for realmain.c:

Go to the source code of this file.

Defines

#define BSIZE   128
#define PATH_MAX   1024

Functions

void C2F() settmpdir (void)
void sci_clear_and_exit (int n)
int C2F() inisci (int *, int *, int *)
void sci_usr1_signal (int n)
int IsNoInteractiveWindow (void)
void InitXsession (void)
void main_sci (int argc, char **argv, char *startup, int lstartup, int memory)
static void strip_blank (char *source)
void realmain (int nowin, int no_startup_flag_l, char *initial_script, int initial_script_type, int memory)
void Set_no_startup_flag (int start)
int Get_no_startup_flag (void)
char ** create_argv (int *argc)

Variables

static int no_startup_flag = 0


Define Documentation

#define BSIZE   128

Definition at line 34 of file realmain.c.

Referenced by create_argv().

#define PATH_MAX   1024

Definition at line 36 of file realmain.c.

Referenced by DoChangeDir(), InitCheckBIN(), InitCheckCOS(), InitCheckCOSF(), InitCheckDEM(), InitCheckGRAPH(), InitCheckGRAPHB(), InitCheckSAV(), InitCheckSCE(), InitCheckSCI(), InitCheckTST(), IsDirectory(), ok_prep(), realmain(), SetDir(), SetSci(), settmpdir(), XmuCvtStringToCursor(), and XmuLocatePixmapFile().


Function Documentation

char** create_argv ( int argc  ) 

Definition at line 176 of file realmain.c.

References BSIZE, buf, C2F, i, malloc(), NULL, scigetarg(), sciiargc(), and strip_blank().

00177 {
00178   int i;
00179   char **argv;
00180   *argc = C2F(sciiargc)() + 1;
00181   if ( ( argv = malloc((*argc)*sizeof(char *))) == NULL) return NULL;
00182   for ( i=0 ; i < *argc ; i++) 
00183     {
00184       char buf[BSIZE];
00185       C2F(scigetarg)(&i,buf,BSIZE);
00186       buf[BSIZE-1]='\0';
00187       strip_blank(buf);
00188       argv[i] = malloc((strlen(buf)+1)*sizeof(char));
00189       if ( argv[i] == NULL) return NULL;
00190       strcpy(argv[i],buf);
00191     }
00192   return argv;
00193 }

Here is the call graph for this function:

int Get_no_startup_flag ( void   ) 

Definition at line 170 of file realmain.c.

References no_startup_flag.

Referenced by TerminateCorePart1().

00171 {
00172         return no_startup_flag;
00173 }

Here is the caller graph for this function:

int C2F() inisci ( int ,
int ,
int  
)

void InitXsession ( void   ) 

Definition at line 615 of file x_main.c.

References app_flush(), DisplayInit(), and dpy.

Referenced by realmain().

00616 { 
00617         static Display *dpy = (Display *) NULL;
00618         static  Widget toplevel1;
00619         int i=0;
00620         
00621         DisplayInit("",&dpy,&toplevel1);
00622         for (i=0;i<1000;i++) app_flush(); /* force to empty X event loop */
00623         XSync(dpy,0);
00624 }

Here is the call graph for this function:

Here is the caller graph for this function:

int IsNoInteractiveWindow ( void   ) 

Definition at line 610 of file x_main.c.

References nointeractive.

Referenced by realmain().

00611 {
00612         return nointeractive;
00613 }

Here is the caller graph for this function:

void main_sci ( int  argc,
char **  argv,
char *  startup,
int  lstartup,
int  memory 
)

Definition at line 396 of file x_main.c.

Referenced by C2F(), and realmain().

00397 {
00398   XtermWidget CreateSubWindows();
00399   register TScreen *screen;
00400   register int  pty;
00401   int Xsocket;
00402   /* Init the Toolkit. */
00403   realToplevel = toplevel = 
00404     XtAppInitialize(&app_con, "Xscilab", 
00405                     optionDescList, XtNumber(optionDescList), 
00406                     &argc, argv, fallback_resources, 
00407                     (ArgList) 0,(Cardinal) 0);                               
00408   XtGetApplicationResources(toplevel, (XtPointer) &resource,
00409                             application_resources,
00410                             XtNumber(application_resources), 
00411                             (ArgList) 0,(Cardinal) 0);
00419   XtAppAddActions(app_con, actionProcs, XtNumber(actionProcs));
00420   toplevel =   initColors(realToplevel);
00421    /* SetXsciOn();  */ /*Already done in realmain */
00422   xterm_name = resource.xterm_name;
00423   if (strcmp(xterm_name, "-") == 0) xterm_name = "xterm";
00424   XtSetValues (toplevel, ourTopLevelShellArgs,
00425                (Cardinal)  number_ourTopLevelShellArgs);
00426   /* Parse the rest of the command line 
00427    * the arguments parsed by XtAppInitialize must be the last ones 
00428    * and here we can check that arguments belong to options 
00429    * this is to be updated 
00430    */
00431   /* 
00432   for (argc--, argv++ ; argc > 0 ; argc--, argv++) 
00433     {
00434       if(**argv != '-') Syntax (*argv);
00435       switch(argv[0][1]) {
00436       case 'h':
00437         Help ();      break;
00438         / * NOTREACHED * /
00439       default:
00440         Syntax (*argv);
00441       }
00442     }
00443   */
00444   XawSimpleMenuAddGlobalActions (app_con);
00445   XtRegisterGrabAction (HandlePopupMenu, True,
00446                         (ButtonPressMask|ButtonReleaseMask),
00447                         GrabModeAsync, GrabModeAsync);
00448   term = CreateSubWindows(toplevel);
00449   screen = &term->screen;
00450   if (screen->savelines < 0) screen->savelines = 0;
00451   term->flags = 0;
00452   if (!screen->jumpscroll) {
00453     term->flags |= SMOOTHSCROLL;
00454     update_jumpscroll();
00455   }
00456   if (term->misc.reverseWrap) {
00457     term->flags |= REVERSEWRAP;
00458     update_reversewrap();
00459   }
00460   if (term->misc.autoWrap) {
00461     term->flags |= WRAPAROUND;
00462     update_autowrap();
00463   }
00464   if (term->misc.re_verse) {
00465     term->flags |= REVERSE_VIDEO;
00466     update_reversevideo();
00467   }
00468   
00469   term->initflags = term->flags;
00470   
00471   if (term->misc.appcursorDefault) {
00472     term->keyboard.flags |= CURSOR_APL;
00473     update_appcursor();
00474   }
00475   
00476   if (term->misc.appkeypadDefault) {
00477     term->keyboard.flags |= KYPD_APL;
00478     update_appkeypad();
00479   }
00480   
00481   /* open a terminal for client */
00482   screen->arrow = make_colored_cursor (XC_left_ptr, 
00483                                        screen->mousecolor,
00484                                        screen->mousecolorback);
00485   /* avoid double MapWindow requests */
00486   XtSetMappedWhenManaged( XtParent(term), False );
00487   wm_delete_window = XInternAtom(XtDisplay(realToplevel),"WM_DELETE_WINDOW",False);
00488   VTInit1(realToplevel);
00489   Xsocket = ConnectionNumber(screen->display);
00490   pty = screen->respond;
00491   pty_mask = 1 << pty;
00492   X_mask = 1 << Xsocket;
00493   Select_mask = pty_mask | X_mask;
00494   max_plus1 = (pty < Xsocket) ? (1 + Xsocket) : (1 + pty); 
00495   XSetErrorHandler((XErrorHandler)xerror);
00496   XSetIOErrorHandler((XIOErrorHandler)xioerror);
00497   /* initialize xterm and run scilab  */
00498   VTRun(startup,lstartup,memory);
00499 
00500 }

Here is the caller graph for this function:

void realmain ( int  nowin,
int  no_startup_flag_l,
char *  initial_script,
int  initial_script_type,
int  memory 
)

Definition at line 39 of file realmain.c.

References C2F, create_argv(), ExceptionMessage(), FREE, get_sci_data_strings(), ierr, inisci(), InitXsession(), IsNoInteractiveWindow(), main_sci(), MALLOC, NULL, PATH_MAX, sci_clear_and_exit(), sci_exit(), sci_usr1_signal(), sciquit(), scirun(), Set_no_startup_flag(), settmpdir(), SetXsciOn(), SIGHUP, and SIGQUIT.

00040 {
00041   static int ini=-1;
00042   int ierr=0;
00043   char *startup=(char*)MALLOC(sizeof(char)*PATH_MAX+1);
00044           //[256];
00045 
00046   Set_no_startup_flag(no_startup_flag_l);
00047 
00048   /* create temp directory */
00049   C2F(settmpdir)();
00050   /* signals */
00051   #ifdef ENABLESIG
00052   signal(SIGINT,sci_clear_and_exit);
00053   #ifdef SIGBUS
00054   signal(SIGBUS,sci_clear_and_exit);
00055   #endif
00056   signal(SIGSEGV,sci_clear_and_exit);
00057   #if SIGQUIT
00058   signal(SIGQUIT,sci_clear_and_exit);
00059   #endif
00060   #ifdef SIGHUP
00061   signal(SIGHUP,sci_clear_and_exit);
00062   #endif
00063   #ifdef SIGUSR1
00064   signal(SIGUSR1,sci_usr1_signal);
00065   #endif
00066 
00067   #ifdef _MSC_VER
00068   signal(SIGILL,sci_clear_and_exit);
00069   signal(SIGFPE,sci_clear_and_exit);
00070   signal(SIGTERM,sci_clear_and_exit);
00071   signal(SIGBREAK,sci_clear_and_exit);
00072   signal(SIGABRT,sci_clear_and_exit);
00073   #endif
00074   #endif
00075 
00076   /*  prepare startup script  */
00077 
00078   if ( no_startup_flag_l == 0) 
00079   {
00080         /* execute a startup */
00081     if ( initial_script != NULL ) switch ( initial_script_type ) 
00082         {
00083                 case 0 : 
00084                         sprintf(startup,"%s;exec('%s',-1)",get_sci_data_strings(1),initial_script);
00085                 break;
00086                 case 1 : 
00087                         sprintf(startup,"%s;%s;",get_sci_data_strings(1),initial_script);
00088                 break;
00089         }
00090     else sprintf(startup,"%s;",get_sci_data_strings(1));
00091   }
00092   else 
00093   {
00094         /* No startup but maybe an initial script  */
00095     if ( initial_script != NULL ) switch ( initial_script_type ) 
00096         {
00097             case 0 : 
00098               sprintf(startup,"exec('%s',-1)",initial_script); break;
00099             case 1 : 
00100               sprintf(startup,"%s;",initial_script);   break;
00101         }
00102     else sprintf(startup," ");
00103   }
00104 
00105   #ifndef _MSC_VER
00106   if ( nowin == 0 ) 
00107     {
00108       int argc=0;
00109       char **argv=NULL;
00110 
00111       argv = create_argv(&argc);
00112 
00113       /* we are in window mode */
00114       SetXsciOn();
00115       main_sci(argc,argv,startup,strlen(startup),memory);
00116     }
00117   else 
00118     {
00119         if (! IsNoInteractiveWindow() )
00120         {
00121                 InitXsession();
00122         }
00123       /* initialize scilab interp  */
00124       C2F(inisci)(&ini, &memory, &ierr);
00125       if (ierr > 0) sci_exit(1) ;
00126       /* execute the initial script and enter scilab */ 
00127       C2F(scirun)(startup,strlen(startup));
00128     }
00129   #else
00130         /* initialize scilab interp  */
00131         C2F(inisci)(&ini, &memory, &ierr);
00132         if (ierr > 0) sci_exit(1) ;
00133 
00134         /* execute the initial script and enter scilab */ 
00135         #ifndef _DEBUG
00136         _try
00137         {
00138                 C2F(scirun)(startup,strlen(startup));
00139         }
00140         _except (EXCEPTION_EXECUTE_HANDLER) 
00141         {
00142                 Rerun:
00143                 {
00144                         ExceptionMessage(GetExceptionCode(),NULL);
00145                 }
00146                 _try
00147                 {
00148                         C2F(scirun)("",strlen(""));
00149                 }
00150                 _except (EXCEPTION_EXECUTE_HANDLER) 
00151                 {
00152                         goto Rerun;
00153                 }
00154 
00155         }
00156         #else
00157                 C2F(scirun)(startup,strlen(startup));
00158         #endif
00159   #endif
00160   FREE(startup);
00161   /* cleaning */
00162   C2F(sciquit)();
00163 }

Here is the call graph for this function:

void sci_clear_and_exit ( int  n  ) 

Definition at line 534 of file x_main.c.

References C2F, and sciquit().

Referenced by Cleanup(), DeleteWindow(), Do_Kill(), realmain(), test_quit(), VTRealize(), and xioerror().

00535 {
00536    C2F(sciquit)();
00537 }

Here is the call graph for this function:

Here is the caller graph for this function:

void sci_usr1_signal ( int  n  ) 

usr1 signal : used to transmit a Control C to scilab

Definition at line 544 of file x_main.c.

References controlC_handler().

Referenced by realmain().

00545 {
00546    controlC_handler(n);
00547 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Set_no_startup_flag ( int  start  ) 

Definition at line 165 of file realmain.c.

References no_startup_flag.

Referenced by realmain().

00166 {
00167         no_startup_flag=start;
00168 }

Here is the caller graph for this function:

void C2F() settmpdir ( void   ) 

creates a tmp dir for a scilab session and fixes the TMPDIR env variable

Definition at line 38 of file tmpdir.c.

References buf, CreateDir(), FALSE, first, getpid(), NULL, PATH_MAX, putenv, and tmp_dir.

00039 {
00040 #ifdef _MSC_VER
00041         #define PATH_MAX 1024
00042         char TmpDirDefault[PATH_MAX];
00043 #endif
00044   static int first =0;
00045   if ( first == 0 ) 
00046     {
00047       first++;
00048 #ifdef _MSC_VER 
00049           if (!GetTempPath(PATH_MAX,TmpDirDefault))
00050           {
00051                   MessageBox(NULL,"Don''t find Windows temporary directory","Error",MB_ICONERROR);
00052                   exit(1);
00053           }
00054           else
00055           {
00056                   sprintf(tmp_dir,"%sSCI_TMP_%d_",TmpDirDefault,(int) _getpid());
00057           }
00058 
00059           if ( CreateDirectory(tmp_dir,NULL)==FALSE)
00060       {
00061                 DWORD attribs=GetFileAttributes (tmp_dir); 
00062 
00063                 if (attribs & FILE_ATTRIBUTE_DIRECTORY)
00064                 {
00065                   // Repertoire existant
00066                 }
00067                 else
00068                 {
00069                   #ifdef _DEBUG
00070                   char MsgErr[1024];
00071                   wsprintf(MsgErr,"Impossible to create : %s",tmp_dir);
00072                   MessageBox(NULL,MsgErr,"Error",MB_ICONERROR);
00073                   exit(1);
00074                   #else
00075                   GetTempPath(PATH_MAX,TmpDirDefault);
00076                   sprintf(tmp_dir,"%s",TmpDirDefault);
00077                   tmp_dir[strlen(tmp_dir)-1]='\0'; /* Remove last \ */
00078                   #endif
00079                 }
00080   }
00081 #else 
00082   sprintf(tmp_dir,"/tmp/SD_%d_",(int) getpid());
00083   CreateDir(tmp_dir) ;
00084 #endif 
00085   sprintf(buf,"TMPDIR=%s",tmp_dir);
00086   putenv(buf);
00087     }
00088 }

Here is the call graph for this function:

static void strip_blank ( char *  source  )  [static]

Definition at line 196 of file realmain.c.

References p.

Referenced by create_argv().

00197 {
00198   char *p;
00199   p = source;
00200   /* look for end of string */
00201   while(*p != '\0') p++;
00202   while(p != source)
00203   {
00204     p--;
00205     if(*p != ' ') break;
00206     *p = '\0';
00207   }
00208 }

Here is the caller graph for this function:


Variable Documentation

int no_startup_flag = 0 [static]

Definition at line 32 of file realmain.c.

Referenced by Get_no_startup_flag(), and Set_no_startup_flag().


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