00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef STRICT
00030 #define STRICT
00031 #endif
00032
00033 #include "winmain.h"
00034 #include "WinConsole.h"
00035 #include "wtext.h"
00036 #include "Messages.h"
00037 #include "Warnings.h"
00038 #include "Errors.h"
00039 #include "GraphWindows.h"
00040 #include "MenuWindows.h"
00041
00042 #include "win_mem_alloc.h"
00043
00044 #define stricmp _stricmp
00045 #define strnicmp _strnicmp
00046
00047 BOOL ScilabIsStarting=TRUE;
00048 int sci_show_banner=1;
00049
00050 extern void PrintFile(char *filename);
00051 extern void ChangeCursorWhenScilabIsReady(void);
00052 extern TW InitTWStruct(void);
00053 extern void CreateSplashscreen(void);
00054 extern void settexmacs(void);
00055 extern void MessageBoxNewGraphicMode(void);
00056 extern int ExitScilab(void);
00057 extern void SetWITH_GUI(BOOL ON);
00058 extern BOOL GetWITH_GUI(void);
00059 extern void disp_scilab_version(void);
00060
00061 static LPSTR my_argv[MAXCMDTOKENS];
00062
00063 int Console_Main(int argc, char **argv)
00064 {
00065 int nowin = 0, argcount = 0, lpath = 0, pathtype=0;
00066 char *path = NULL;
00067 char *ScilabDirectory=NULL;
00068 int i=0;
00069
00070 my_argc = -1;
00071
00072 ForbiddenToUseScilab();
00073
00074 SetWindowMode(FALSE);
00075 ScilabIsStarting=TRUE;
00076
00077 for (i=0;i<argc;i++)
00078 {
00079 my_argv[i] = argv[i];
00080 }
00081 my_argc =argc;
00082
00083 ScilabDirectory=GetScilabDirectory(FALSE);
00084
00085 if (ScilabDirectory == NULL)
00086 {
00087 MessageBox (NULL, MSG_ERROR20 ,MSG_ERROR38, MB_ICONSTOP | MB_OK);
00088 exit(1);
00089 }
00090
00091 InitszGraphMenuName(ScilabDirectory);
00092
00093 if (ScilabDirectory){FREE(ScilabDirectory);ScilabDirectory=NULL;}
00094
00095
00096 InitCommonControls ();
00097
00098 textwin=InitTWStruct();
00099
00100 textwin.hInstance = GetModuleHandle(MSG_SCIMSG9);
00101 textwin.hPrevInstance = 0;
00102 textwin.nCmdShow = 1;
00103 textwin.Title = MSG_SCIMSG21;
00104 textwin.lpmw = &menuwin;
00105 textwin.ScreenSize.x = 120;
00106 textwin.ScreenSize.y = 80;
00107 textwin.KeyBufSize = 2048;
00108 textwin.CursorFlag = 1;
00109
00110 menuwin=InitMWStruct();
00111 menuwin.szMenuName = GetszMenuName();
00112
00113 graphwin=InitGWStruct();
00114 graphwin.hInstance = GetModuleHandle(MSG_SCIMSG9);
00115 graphwin.hPrevInstance = 0;
00116 graphwin.Title = MSG_SCIMSG23 ;
00117 graphwin.szMenuName = GetszGraphMenuName();
00118 graphwin.lptw = &textwin;
00119 argcount = my_argc;
00120 while (argcount > 0)
00121 {
00122 argcount--;
00123 if (stricmp (my_argv[argcount], "-NW") == 0) nowin = 1;
00124 else if (stricmp (my_argv[argcount], "-NS") == 0) startupf = 1;
00125 else if ( stricmp(my_argv[argcount],"-NB") == 0) { sci_show_banner = 0; }
00126 else if (stricmp (my_argv[argcount], "-NWNI") == 0)
00127 {
00128 nowin = 1;
00129 nointeractive = 1;
00130 }
00131 else if (stricmp (my_argv[argcount], "-F") == 0 && argcount + 1 < my_argc)
00132 {
00133 path = my_argv[argcount + 1];
00134 lpath = strlen (my_argv[argcount + 1]);
00135 }
00136 else if (stricmp (my_argv[argcount], "-E") == 0 && argcount + 1 < my_argc)
00137 {
00138 path = my_argv[argcount + 1];
00139 lpath = strlen (my_argv[argcount + 1]);
00140 pathtype=1;
00141 }
00142 else if ( stricmp(my_argv[argcount],"-MEM") == 0 && argcount + 1 < my_argc)
00143 {
00144 memory = Max(atoi( my_argv[argcount + 1]),MIN_STACKSIZE );
00145 }
00146 else if ( stricmp(my_argv[argcount],"-TEXMACS") == 0 )
00147 {
00148 settexmacs();
00149 }
00150 else if ( stricmp(my_argv[argcount],"-NOGUI") == 0 )
00151 {
00152 nowin = 1;
00153 nointeractive = 1;
00154 SetWITH_GUI(FALSE);
00155 }
00156 else if ( (stricmp (my_argv[argcount],"-VERSION")==0) ||
00157 (stricmp (my_argv[argcount],"-VER")==0) )
00158 {
00159 disp_scilab_version();
00160 exit(1);
00161 }
00162 else if ( (stricmp (my_argv[argcount],"-H")==0) ||
00163 (stricmp (my_argv[argcount],"-?")==0) ||
00164 (stricmp (my_argv[argcount],"-HELP")==0) )
00165 {
00166 printf(MSG_SCIMSG24B);
00167 printf(MSG_SCIMSG122);
00168 printf(MSG_SCIMSG123);
00169 printf(MSG_SCIMSG124);
00170 printf(MSG_SCIMSG125);
00171 printf(MSG_SCIMSG126);
00172 printf(MSG_SCIMSG127);
00173 printf(MSG_SCIMSG128);
00174 printf(MSG_SCIMSG129);
00175 printf(MSG_SCIMSG130);
00176 printf(MSG_SCIMSG131);
00177 printf(MSG_SCIMSG132);
00178 printf(MSG_SCIMSG133);
00179 printf(MSG_SCIMSG134);
00180 printf(MSG_SCIMSG135);
00181
00182 printf("\n");
00183 exit(1);
00184 }
00185 }
00186
00187 hdllInstance = GetModuleHandle(MSG_SCIMSG9);
00188
00189 if (nowin == 1)
00190 {
00191 SaveConsoleColors();
00192 if (nointeractive!=1)
00193 {
00194 RenameConsole();
00195 UpdateConsoleColors();
00196 }
00197
00198 sci_windows_main (nowin, &startupf,path,pathtype, &lpath,memory);
00199
00200 }
00201 else
00202 {
00203 MessageBox(NULL,MSG_ERROR79,MSG_ERROR20,MB_ICONWARNING);
00204 }
00205
00206 ExitScilab();
00207
00208 return 0;
00209 }
00210
00211 int WINAPI Windows_Main (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
00212 {
00213 int i=0;
00214 BOOL ShortCircuitExec=FALSE;
00215 BOOL LaunchAFile=FALSE;
00216 BOOL ShowMessageBoxInfo=TRUE;
00217 char FileName[MAX_PATH];
00218 int nowin = 0, argcount = 0, lpath = 0, pathtype=0;
00219 char *path = NULL;
00220 char *ScilabDirectory=NULL;
00221
00222 HANDLE hOut = NULL;
00223
00224 char *pFullCmdLine=NULL;
00225 char *pFullCmdLineTmp=NULL;
00226 char *pPathCmdLine=NULL;
00227
00228 ForbiddenToUseScilab();
00229
00230 SetWindowMode(TRUE);
00231 ScilabIsStarting=TRUE;
00232
00233 strcpy(FileName,"Empty");
00234
00235 ScilabDirectory=GetScilabDirectory(FALSE);
00236
00237 if (ScilabDirectory == NULL)
00238 {
00239 MessageBox (NULL,MSG_ERROR20 , MSG_ERROR38, MB_ICONSTOP | MB_OK);
00240 exit(1);
00241 }
00242 InitszMenuName(ScilabDirectory);
00243 InitszGraphMenuName(ScilabDirectory);
00244
00245 if (ScilabDirectory){FREE(ScilabDirectory);ScilabDirectory=NULL;}
00246
00247
00248 InitCommonControls ();
00249
00250 textwin=InitTWStruct();
00251
00252 textwin.hInstance = hInstance;
00253 textwin.hPrevInstance = hPrevInstance;
00254 textwin.nCmdShow = iCmdShow;
00255 textwin.Title = MSG_SCIMSG21;
00256 textwin.lpmw = &menuwin;
00257 textwin.ScreenSize.x = 120;
00258 textwin.ScreenSize.y = 80;
00259 textwin.KeyBufSize = 4096;
00260 textwin.CursorFlag = 1;
00261
00262 menuwin=InitMWStruct();
00263 menuwin.szMenuName = GetszMenuName();
00264
00265 graphwin=InitGWStruct();
00266 graphwin.hInstance = hInstance;
00267 graphwin.hPrevInstance = hPrevInstance;
00268 graphwin.Title = MSG_SCIMSG23;
00269 graphwin.szMenuName = GetszGraphMenuName();
00270 graphwin.lptw = &textwin;
00271
00272 pFullCmdLineTmp=GetCommandLine();
00273 {
00274 char LineCommand[MAX_PATH];
00275 char LineCommandBis[MAX_PATH];
00276 char ShortPath[MAX_PATH];
00277 char *pPathCmdLine=NULL;
00278 char PathCmdLineCopy[1024];
00279 char StrWscilexToSearch[MAX_PATH];
00280
00281 sprintf(StrWscilexToSearch,"%s\" ",WSCILEX);
00282
00283 strcpy(LineCommand,pFullCmdLineTmp);
00284 LineCommand[strlen(LineCommand)]='\0';
00285 strcpy(LineCommandBis,pFullCmdLineTmp);
00286 LineCommandBis[strlen(LineCommandBis)]='\0';
00287
00288 pPathCmdLine=stristr(LineCommand,StrWscilexToSearch);
00289
00290 if ( (pPathCmdLine != NULL) && ( (strlen(pPathCmdLine)-strlen(StrWscilexToSearch)-1) > 0) )
00291 {
00292 char LINE[1024];
00293
00294 strcpy(PathCmdLineCopy,pPathCmdLine);
00295 if ( PathCmdLineCopy[strlen(StrWscilexToSearch)-2] == '\"' ) PathCmdLineCopy[strlen(StrWscilexToSearch)-2] = ' ';
00296 strncpy(LINE,&LineCommandBis[1],strlen(LineCommandBis)-strlen(PathCmdLineCopy)-1);
00297 LINE[strlen(LineCommandBis)-strlen(PathCmdLineCopy)-1]='\0';
00298
00299 GetShortPathName(LINE,ShortPath,MAX_PATH);
00300 strcat(ShortPath,PathCmdLineCopy);
00301
00302 pFullCmdLine=(char*)MALLOC(sizeof(char)*(strlen(ShortPath)+1));
00303 strcpy(pFullCmdLine,ShortPath);
00304 }
00305 else
00306 {
00307 pFullCmdLine=(char*)MALLOC(sizeof(char)*(strlen(LineCommandBis)+1));
00308 strcpy(pFullCmdLine,LineCommandBis);
00309 }
00310
00311 }
00312
00313 my_argv[++my_argc] = strtok (pFullCmdLine, " ");
00314 while (my_argv[my_argc] != NULL)
00315 {
00316 my_argv[++my_argc] = strtok(NULL, " ");
00317 }
00318
00319 for (i=1;i<my_argc;i++)
00320 {
00321 if ( stricmp (my_argv[i], "-NB") == 0 )
00322 {
00323 ShowMessageBoxInfo=FALSE;
00324 }
00325 }
00326
00327 if (ShowMessageBoxInfo)
00328 {
00329
00330 MessageBoxNewGraphicMode();
00331 }
00332
00333 for (i=1;i<my_argc;i++)
00334 {
00335 if ( (stricmp (my_argv[i], "-NW") == 0) || (stricmp (my_argv[i], "-NWI") == 0) || (stricmp (my_argv[i], "-TEXMACS") == 0) || (stricmp (my_argv[i], "-NOGUI") == 0) )
00336 {
00337 MessageBox(NULL,"Not with Windows Console","Error",MB_ICONINFORMATION);
00338 exit(1);
00339 }
00340
00341 if ( (stricmp (my_argv[i], "-VERSION") == 0) ||
00342 (stricmp (my_argv[i], "-VER") == 0) )
00343 {
00344 disp_scilab_version();
00345 exit(1);
00346 }
00347
00348 if ( (stricmp (my_argv[i], "-H") == 0) ||
00349 (stricmp (my_argv[i], "-?") == 0) ||
00350 (stricmp (my_argv[i], "-HELP") == 0) )
00351 {
00352 char Msg[2048];
00353 strcpy(Msg,MSG_SCIMSG24);
00354 strcat(Msg,MSG_SCIMSG122);
00355 strcat(Msg,MSG_SCIMSG123);
00356 strcat(Msg,MSG_SCIMSG124);
00357 strcat(Msg,MSG_SCIMSG125);
00358 strcat(Msg,MSG_SCIMSG126);
00359 strcat(Msg,MSG_SCIMSG127);
00360 strcat(Msg,MSG_SCIMSG128);
00361 strcat(Msg,MSG_SCIMSG129);
00362 strcat(Msg,MSG_SCIMSG130);
00363 strcat(Msg,MSG_SCIMSG131);
00364 strcat(Msg,MSG_SCIMSG132);
00365 strcat(Msg,MSG_SCIMSG133);
00366 strcat(Msg,MSG_SCIMSG134);
00367 strcat(Msg,MSG_SCIMSG135);
00368
00369 MessageBox(NULL,Msg,MSG_SCIMSG30,MB_ICONINFORMATION);
00370 exit(1);
00371 }
00372 }
00373 argcount = my_argc;
00374
00375 if (argcount > 2)
00376 {
00377 if ( (stricmp (my_argv[1], "-X") == 0) ||
00378 (stricmp (my_argv[1], "-O") == 0) ||
00379 (stricmp (my_argv[1], "-P") == 0) )
00380 {
00381 char *Commande=NULL;
00382 int CodeAction=-1;
00383 int j=0;
00384
00385 LaunchAFile=TRUE;
00386
00387 strcpy(FileName,my_argv[2]);
00388 for (j=3;j<argcount;j++)
00389 {
00390 strcat(FileName," ");
00391 strcat(FileName,my_argv[j]);
00392 }
00393 if (stricmp (my_argv[1], "-O") == 0) CodeAction=0;
00394 if (stricmp (my_argv[1], "-X") == 0) CodeAction=1;
00395 if (stricmp (my_argv[1], "-P") == 0) CodeAction=2;
00396
00397 Commande=(char*)MALLOC(MAX_PATH*sizeof(char));
00398 strcpy(Commande,"empty");
00399 CommandByFileExtension(FileName,CodeAction,Commande);
00400
00401 if (
00402 ( ( IsAScicosFile(FileName)== TRUE ) && (CodeAction==1) ) ||
00403 ( ( IsAGraphFile(FileName)== TRUE ) && (CodeAction==1) )
00404 )
00405 {
00406 my_argc=-1;
00407 my_argv[++my_argc]=Commande;
00408 argcount = my_argc;
00409 ShortCircuitExec=TRUE;
00410 }
00411 else
00412 {
00413 my_argc=-1;
00414 my_argv[++my_argc] = strtok (Commande, " ");
00415 while (my_argv[my_argc] != NULL)
00416 {
00417 my_argv[++my_argc] = strtok(NULL, " ");
00418 }
00419 argcount = my_argc;
00420 }
00421 }
00422 }
00423
00424 if ( ShortCircuitExec == TRUE)
00425 {
00426 char PathWScilex[MAX_PATH];
00427 int lenPathWScilex=0;
00428 GetModuleFileName ((HINSTANCE)GetModuleHandle(NULL), PathWScilex, MAX_PATH);
00429 lenPathWScilex=strlen(PathWScilex);
00430 path = my_argv[argcount]+lenPathWScilex+3;
00431 lpath = strlen (my_argv[argcount]+lenPathWScilex+3);
00432 pathtype=1;
00433 LaunchAFile=TRUE;
00434 }
00435 else
00436 while (argcount > 0)
00437 {
00438 char ArgTmp[MAX_PATH];
00439
00440 argcount--;
00441 strcpy(ArgTmp,my_argv[argcount]);
00442
00443 if (stricmp (ArgTmp, "-NS") == 0) startupf = 1;
00444 else if ( stricmp(ArgTmp,"-NB") == 0) { sci_show_banner = 0; }
00445 else if (stricmp (ArgTmp, "-F") == 0 && argcount + 1 < my_argc)
00446 {
00447 path = my_argv[argcount + 1];
00448 lpath = strlen (my_argv[argcount + 1]);
00449 }
00450 else if (stricmp (ArgTmp, "-E") == 0 && argcount + 1 < my_argc)
00451 {
00452 path = my_argv[argcount + 1];
00453 lpath = strlen (my_argv[argcount + 1]);
00454 pathtype=1;
00455 }
00456 else if ( stricmp(ArgTmp,"-MEM") == 0 && argcount + 1 < my_argc)
00457 {
00458 memory = Max(atoi( my_argv[argcount + 1]),MIN_STACKSIZE );
00459 }
00460 }
00461 hdllInstance = hInstance;
00462
00463
00464 if ( (sci_show_banner) && (LaunchAFile == FALSE) )CreateSplashscreen();
00465
00466 CreateScilabConsole(sci_show_banner);
00467
00468 if (TextInit (&textwin)) exit (1);
00469
00470 textwin.hIcon = LoadIcon (hInstance, "texticon");
00471 SetClassLong (textwin.hWndParent, GCL_HICON, (DWORD) textwin.hIcon);
00472 SetXsciOn ();
00473
00474 ShowWindow (textwin.hWndParent, SW_SHOWNORMAL);
00475 ForceToActiveWindowParent();
00476 HideScilex();
00477
00478 if (LaunchAFile) ChangeCursorWhenScilabIsReady();
00479
00480
00481 sci_windows_main (nowin, &startupf, path,pathtype, &lpath,memory);
00482
00483 CloseScilabConsole();
00484
00485 ExitScilab();
00486
00487
00488 return 0;
00489 }
00490
00491 void InitWindowGraphDll(void)
00492
00493
00494
00495
00496 {
00497 if ( GetWITH_GUI() )
00498 {
00499 char *ScilabDirectory=NULL;
00500
00501 HINSTANCE hdllInstanceTmp=NULL;
00502 char *p1 = (char*)getenv ("SCI");
00503 hdllInstanceTmp=(HINSTANCE)GetModuleHandle(MSG_SCIMSG11);
00504
00505 if (hdllInstanceTmp==NULL)
00506 {
00507 MessageBox(NULL,MSG_ERROR39,MSG_ERROR20,MB_ICONWARNING|MB_OK);
00508 exit(1);
00509 }
00510
00511 ForbiddenToUseScilab();
00512
00513 hdllInstance=hdllInstanceTmp;
00514 ScilabDirectory=GetScilabDirectory(FALSE);
00515
00516 if (ScilabDirectory == NULL)
00517 {
00518 MessageBox (NULL, MSG_ERROR20, MSG_ERROR38, MB_ICONSTOP | MB_OK);
00519 exit(1);
00520 }
00521
00522 InitszGraphMenuName(ScilabDirectory);
00523 if (ScilabDirectory){FREE(ScilabDirectory);ScilabDirectory=NULL;}
00524
00525 InitCommonControls ();
00526
00527 graphwin=InitGWStruct();
00528 graphwin.hInstance = hdllInstance;
00529 graphwin.hPrevInstance = NULL;
00530 graphwin.Title = MSG_SCIMSG23;
00531 graphwin.szMenuName = GetszGraphMenuName();
00532 graphwin.lptw = &textwin;
00533 }
00534 }
00535
00536
00537 void add_sci_argv(char *p)
00538 {
00539 if (*p) my_argv[++my_argc]=p;
00540 }
00541
00542
00543 int sci_iargc()
00544 {
00545 return my_argc -1 ;
00546 }
00547
00548 int sci_getarg(int *n,char *s,long int ls)
00549 {
00550 register char *t;
00551 register int i;
00552
00553 if(*n>=0 && *n <= my_argc)
00554 t = my_argv[*n];
00555 else
00556 t = "";
00557
00558 for(i = 0; i < ls && *t!='\0' ; ++i)
00559 *s++ = *t++;
00560 for( ; i<ls ; ++i)
00561 *s++ = ' ';
00562 return 0;
00563 }
00564
00565 int InteractiveMode ()
00566 {
00567 return nointeractive;
00568 }
00569
00570 int C2F(showlogo) ()
00571 {
00572 return show_logo;
00573 }
00574
00575 void Kill_Scilex(void)
00576 {
00577 HANDLE hProcess;
00578
00579
00580 hProcess=OpenProcess(PROCESS_TERMINATE,FALSE,GetCurrentProcessId());
00581 if (hProcess)
00582 {
00583
00584
00585 TerminateProcess(hProcess,0);
00586 }
00587 else MessageBox(NULL,MSG_WARNING20,MSG_WARNING21,MB_ICONWARNING);
00588 }
00589
00590 BOOL ForbiddenToUseScilab(void)
00591 {
00592 BOOL bOK=FALSE;
00593 HDC hdc=GetDC(NULL);
00594 int BitsByPixel = GetDeviceCaps(hdc, BITSPIXEL);
00595
00596 ReleaseDC (NULL, hdc);
00597
00598 if ( BitsByPixel < 8 )
00599 {
00600 MessageBox(NULL,MSG_WARNING22,MSG_ERROR42,MB_ICONSTOP);
00601 exit(1);
00602 return bOK;
00603 }
00604
00605 bOK=TRUE;
00606 return bOK;
00607 }
00608
00609 int IsNoInteractiveWindow(void)
00610 {
00611 return nointeractive;
00612 }
00613
00614
00615 char *stristr(const char *psz,const char *tofind)
00616 {
00617 const char *ptr = psz;
00618 const char *ptr2;
00619
00620 while(1)
00621 {
00622 ptr = strchr(psz,toupper(*tofind));
00623 ptr2 = strchr(psz,tolower(*tofind));
00624 if (!ptr)
00625 {
00626 ptr = ptr2;
00627 }
00628 if (!ptr)
00629 {
00630 break;
00631 }
00632 if (ptr2 && (ptr2 < ptr))
00633 {
00634 ptr = ptr2;
00635 }
00636 if (!strnicmp(ptr,tofind,strlen(tofind)))
00637 {
00638 return (char *) ptr;
00639 }
00640 psz = ptr+1;
00641 }
00642 return 0;
00643 }
00644