x_main.c File Reference

#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 "machine.h"
#include "math.h"
#include "version.h"
#include "realmain.h"
#include "scimem.h"
#include "getarg.h"
#include "DestroyObjects.h"
#include "periScreen.h"
#include "All-extern-x.h"
#include "All-extern.h"
#include <sys/resource.h>
#include <sys/param.h>
#include <unistd.h>
#include <stdlib.h>
#include "Xscilab.ad.h"

Include dependency graph for x_main.c:

Go to the source code of this file.

Data Structures

struct  _resource
struct  _color
struct  _options

Defines

#define MIN_STACKSIZE   180000
#define offset(field)   XtOffsetOf(struct _resource, field)
#define ADDTOPLEVEL(NAME)

Functions

void controlC_handler (int n)
void sci_clear_and_exit (int)
char * strindex (register char *s1, register char *s2)
void do_hangup (void)
void do_kill (Widget gw, caddr_t closure, caddr_t data)
void sci_usr1_signal (int n)
char ** create_argv (int *argc)
void settexmacs (void)
void SetWITH_GUI (BOOL)
int IsNoInteractiveWindow (void)
void sci_sig_tstp (int n)
int IsConsoleMode (void)
void InitXsession (void)
void C2F() mainscic (void)
void DeleteWindow (Widget w, XEvent *event, String *params, Cardinal *num_params)
void KeyboardMapping (Widget w, XEvent *event, String *params, Cardinal *num_params)
int Xscilab (Display **dpy, Widget *topwid)
Widget initColors (Widget realToplevel_w)
void main_sci (int argc, char **argv, char *startup, int lstartup, int memory)
int GetBytesAvailable (int fd)
int kill_process_group (int pid, int sig)
static void Syntax (char *badOption)

Variables

char * ProgramName
int sci_show_banner = 1
static int no_window = 0
static int nointeractive = 0
Boolean sunFunctionKeys = False
static struct _resource resource
XtResource application_resources []
XtResource app_colors []
static char * fallback_resources []
static XrmOptionDescRec optionDescList []
static struct _options options []
WidgetClass xtermWidgetClass
Arg ourTopLevelShellArgs []
int number_ourTopLevelShellArgs = 2
XtAppContext app_con
Widget toplevel = (Widget) NULL
Widget realToplevel = (Widget) NULL
static XtActionsRec actionProcs []
Atom wm_delete_window


Define Documentation

#define ADDTOPLEVEL ( NAME   ) 

Value:

toplevel_w = XtCreateManagedWidget(NAME,formWidgetClass, \
                                         realToplevel_w,(ArgList)0 ,(Cardinal)0);
initColors: To allow resources to be specified separately for color and mono displays, we add a dummy Form widget below realToplevel in appropriate circumstances.

Definition at line 329 of file x_main.c.

Referenced by initColors().

#define MIN_STACKSIZE   180000

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

Definition at line 114 of file x_main.c.

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

Definition at line 197 of file x_main.c.


Function Documentation

void controlC_handler ( int  n  ) 

TODO : comment

Parameters:
sig 

Definition at line 8 of file csignal.c.

References C2F, j, and sigbas().

Referenced by callinterf(), csignal(), and sci_usr1_signal().

00009 {
00010   int j = SIGINT;
00011   C2F(sigbas)(&j);
00012 }

Here is the call graph for this function:

Here is the caller graph for this function:

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:

void DeleteWindow ( Widget  w,
XEvent *  event,
String *  params,
Cardinal *  num_params 
)

DeleteWindow(): Action proc to implement ICCCM delete_window.

Definition at line 280 of file x_main.c.

References sci_clear_and_exit().

00285 {
00286  sci_clear_and_exit(0); 
00287 }

Here is the call graph for this function:

void do_hangup ( void   ) 

void do_kill ( Widget  gw,
caddr_t  closure,
caddr_t  data 
)

Definition at line 305 of file x_menu.c.

References handle_send_signal().

00308 {
00309     handle_send_signal (gw, SIGKILL);
00310 }

Here is the call graph for this function:

int GetBytesAvailable ( int  fd  ) 

Definition at line 519 of file x_main.c.

Referenced by Bell(), and Xputchar().

00521 {
00522 #ifdef FIONREAD
00523     static long arg;
00524     ioctl (fd, FIONREAD, (char *) &arg);
00525     return (int) arg;
00526 #else
00527     struct pollfd pollfds[1];
00528     pollfds[0].fd = fd;
00529     pollfds[0].events = POLLIN;
00530     return poll (pollfds, 1, 0);
00531 #endif
00532 }

Here is the caller graph for this function:

Widget initColors ( Widget  realToplevel_w  ) 

Definition at line 335 of file x_main.c.

References ADDTOPLEVEL, C2F, resource, setcolordef(), visual, _resource::visualType, and xscion().

Referenced by AddNewWin(), main_sci(), and ShellFormCreate().

00337 {
00338   int i;
00339   Widget toplevel_w ;
00340   Screen *Xscreen;
00341   Visual *visual;
00342   /* The default is no extra widget (ie. mono) */
00343   toplevel_w = realToplevel_w;
00344   Xscreen = XtScreen(realToplevel_w);
00345   C2F(xscion)(&i);/* is it a scilab -nw */
00346   if ( i != 0 ) 
00347     {
00348       /* If we are using a scilab -nw 
00349        *  resource.visualType == NULL
00350        *
00351        * See if the user has specified a type */
00352       if (strcmp(resource.visualType,"mono") == 0) {
00353         /* Ton van Overbeek patch 22/08/00 */
00354         return toplevel_w;
00355       } else if (strcmp(resource.visualType,"color") == 0) {
00356         ADDTOPLEVEL("color");
00357         /* Ton van Overbeek patch 22/08/00 */
00358         return toplevel_w;
00359       } else if (strcmp(resource.visualType,"gray") == 0) {
00360         ADDTOPLEVEL("gray");
00361         /* Ton van Overbeek patch 22/08/00 */
00362         return toplevel_w;
00363       }
00364     }
00365   /* Otherwise we try to figure it out */
00366   if ((visual=XDefaultVisualOfScreen(Xscreen)) == NULL) {
00367     fprintf(stderr,"Scilab: can't get info about visual!\n");
00368     return toplevel_w;
00369   }
00370   if (visual->map_entries > 2) {
00371     switch (visual->class) {
00372     case StaticColor:
00373     case PseudoColor:
00374     case TrueColor:
00375     case DirectColor:
00376       ADDTOPLEVEL("color");
00377       setcolordef(1) ;
00378       break;
00379     case StaticGray:
00380     case GrayScale:
00381       ADDTOPLEVEL("gray");
00382       setcolordef(0) ;
00383       break;
00384     default:
00385       setcolordef(0) ;
00386       toplevel_w = realToplevel_w;
00387     }
00388   } else {
00389       setcolordef(0) ;
00390       toplevel_w = realToplevel_w;
00391   }
00392   /* Ton van Overbeek patch 22/08/00 */
00393   return toplevel_w;
00394 }

Here is the call graph for this function:

Here is the caller graph for this function:

void InitXsession ( void   ) 

int IsConsoleMode ( void   ) 

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)

Definition at line 132 of file WinConsole.c.

00133 {
00134         return (int)(!WindowMode);
00135 }

int IsNoInteractiveWindow ( void   ) 

Definition at line 609 of file winmain.c.

References nointeractive.

00610 {
00611         return nointeractive;
00612 }

void KeyboardMapping ( Widget  w,
XEvent *  event,
String *  params,
Cardinal *  num_params 
)

Definition at line 289 of file x_main.c.

00294 {
00295     switch (event->type) {
00296        case MappingNotify:
00297           XRefreshKeyboardMapping(&event->xmapping);
00298           break;
00299     }
00300 }

int kill_process_group ( int  pid,
int  sig 
)

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

Definition at line 564 of file x_main.c.

Referenced by Cleanup(), and handle_send_signal().

00567 {
00568     return kill (-pid, sig);
00569 }

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.

References _Misc::appcursorDefault, _Misc::appkeypadDefault, TScreen::arrow, _Misc::autoWrap, CreateSubWindows(), CURSOR_APL, TScreen::display, _XtermWidgetRec::flags, TKeyboard::flags, HandlePopupMenu(), initColors(), _XtermWidgetRec::initflags, TScreen::jumpscroll, _XtermWidgetRec::keyboard, KYPD_APL, make_colored_cursor(), max_plus1, _XtermWidgetRec::misc, TScreen::mousecolor, TScreen::mousecolorback, pty_mask, _Misc::re_verse, resource, TScreen::respond, REVERSE_VIDEO, _Misc::reverseWrap, REVERSEWRAP, TScreen::savelines, _XtermWidgetRec::screen, Select_mask, SMOOTHSCROLL, term, update_appcursor, update_appkeypad, update_autowrap, update_jumpscroll, update_reversevideo, update_reversewrap, VTInit1(), VTRun(), WRAPAROUND, X_mask, XawSimpleMenuAddGlobalActions(), xerror(), xioerror(), Xsocket, and xterm_name.

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 call graph for this function:

void C2F() mainscic ( void   ) 

void sci_clear_and_exit ( int   ) 

Definition at line 108 of file wtloop.c.

References C2F, Message(), MSG_ERROR20, MSG_ERROR59, MSG_ERROR60, MSG_ERROR61, MSG_ERROR62, MSG_ERROR63, MSG_ERROR64, MSG_ERROR65, MSG_ERROR66, NULL, and sciquit().

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 }

Here is the call graph for this function:

void sci_sig_tstp ( int  n  ) 

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

Definition at line 159 of file wtloop.c.

References MSG_ERROR67.

00160 {
00161   Scierror(999,MSG_ERROR67);
00162 }

void sci_usr1_signal ( int  n  ) 

usr1 signal : used to transmit a Control C to scilab

Definition at line 150 of file wtloop.c.

References controlC_handler().

00151 {
00152   controlC_handler(n);
00153 }

Here is the call graph for this function:

void settexmacs ( void   ) 

Definition at line 24 of file texmacs.c.

References texmacs_mode.

Referenced by Console_Main().

00024                   {
00025   texmacs_mode=1;
00026 }

Here is the caller graph for this function:

void SetWITH_GUI ( BOOL   ) 

Definition at line 292 of file inisci-c.c.

References FALSE, TRUE, and WITH_GUI.

00293 {
00294         if ( (ON == FALSE) || (ON == TRUE) ) WITH_GUI=ON;
00295 }

char* strindex ( register char *  s1,
register char *  s2 
)

Referenced by getString().

Here is the caller graph for this function:

static void Syntax ( char *  badOption  )  [static]

Syntax

Definition at line 575 of file x_main.c.

References len, _options::opt, options, and ProgramName.

00576 {
00577   struct _options *opt;
00578   int col;
00579 
00580   fprintf (stderr, "%s:  bad command line option \"%s\"\r\n\n",
00581            ProgramName, badOption);
00582 
00583   fprintf (stderr, "usage:  %s", ProgramName);
00584   col = 8 + strlen(ProgramName);
00585   for (opt = options; opt->opt; opt++) {
00586     int len = 3 + strlen(opt->opt);      /* space [ string ] */
00587     if (col + len > 79) {
00588       fprintf (stderr, "\r\n   ");  /* 3 spaces */
00589       col = 3;
00590     }
00591     fprintf (stderr, " [%s]", opt->opt);
00592     col += len;
00593   }
00594 
00595   fprintf (stderr, "\r\n\nType %s -help for a full description.\r\n\n",
00596            ProgramName);
00597   exit (1);
00598 }

int Xscilab ( Display **  dpy,
Widget *  topwid 
)

used by scilab to know the dpy and toplevel

Definition at line 312 of file x_main.c.

Referenced by DisplayInit().

00315 {
00316   *topwid=toplevel;
00317   if ( toplevel != (Widget) NULL) *dpy=XtDisplay(toplevel);
00318   return(1);
00319 }

Here is the caller graph for this function:


Variable Documentation

XtActionsRec actionProcs[] [static]

Initial value:

 {
  {"DeleteWindow", DeleteWindow},
  {"SGDeleteWindow", SGDeleteWindow},
  {"KeyboardMapping", KeyboardMapping}
}

Definition at line 302 of file x_main.c.

XtResource app_colors[]

Initial value:

 {
  {"xscilab.color*Command.background", "Xscilab*Command.Background", 
     XtRString, sizeof(String),
     XtOffsetOf(struct _color, c1), NULL,NULL}
}
colors;

Definition at line 226 of file x_main.c.

XtAppContext app_con

Definition at line 272 of file x_main.c.

XtResource application_resources[]

Initial value:

 {
    {"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, SCI_VERSION_STRING},
    {XtNiconName, XtCIconName, XtRString, sizeof(char *),
        offset(icon_name), XtRString, SCI_VERSION_STRING},
    {"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)"" }
}

Definition at line 199 of file x_main.c.

char* fallback_resources[] [static]

Initial value:

 {

    NULL
}

Definition at line 232 of file x_main.c.

int no_window = 0 [static]

Definition at line 116 of file x_main.c.

Referenced by IsConsoleMode().

int nointeractive = 0 [static]

Definition at line 117 of file x_main.c.

int number_ourTopLevelShellArgs = 2

Definition at line 270 of file x_main.c.

XrmOptionDescRec optionDescList[] [static]

Initial value:

 {
{"-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"},
}

Definition at line 240 of file x_main.c.

Referenced by DisplayInit().

struct _options options[] [static]

Arg ourTopLevelShellArgs[]

Initial value:

 {
  { XtNallowShellResize, (XtArgVal) TRUE },     
  { XtNinput, (XtArgVal) TRUE },
}

Definition at line 266 of file x_main.c.

char* ProgramName

Definition at line 94 of file x_main.c.

Referenced by set_character_class(), and Syntax().

Widget realToplevel = (Widget) NULL

Definition at line 274 of file x_main.c.

Referenced by set_scilab_icon().

struct _resource resource [static]

Referenced by initColors(), and main_sci().

int sci_show_banner = 1

Definition at line 115 of file x_main.c.

Referenced by banier(), Console_Main(), and Windows_Main().

Boolean sunFunctionKeys = False

Definition at line 180 of file x_main.c.

Referenced by Input().

Widget toplevel = (Widget) NULL

Definition at line 273 of file x_main.c.

Atom wm_delete_window

Definition at line 321 of file x_main.c.

WidgetClass xtermWidgetClass

Definition at line 505 of file x_charproc.c.


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