diff --git a/src/Draw/CommandWindow.cxx b/src/Draw/CommandWindow.cxx index 8cc1a39a8a..2de0fbc69c 100755 --- a/src/Draw/CommandWindow.cxx +++ b/src/Draw/CommandWindow.cxx @@ -41,8 +41,6 @@ -Standard_Boolean Draw_Interprete(char*); // Implement in draw.cxx - #define CLIENTWND 0 #define PROMPT "Command >> " diff --git a/src/Draw/Draw.cxx b/src/Draw/Draw.cxx index 9a0f82e35f..d5e3ff70ef 100755 --- a/src/Draw/Draw.cxx +++ b/src/Draw/Draw.cxx @@ -54,6 +54,7 @@ #include #include +#include #include #include @@ -67,9 +68,6 @@ #include #include extern Standard_Boolean Draw_ParseFailed; -#ifndef WNT -extern Standard_Boolean Draw_LowWindows; -#endif Standard_EXPORT Draw_Viewer dout; Standard_EXPORT Draw_Interpretor theCommands; @@ -92,11 +90,9 @@ static Standard_Boolean XLoop; static Handle(Draw_ProgressIndicator) PInd = NULL; -Standard_EXPORT Standard_Boolean Draw_Interprete(char* command); +Standard_EXPORT Standard_Boolean Draw_Interprete(const char* command); // true if complete command -//#ifndef WNT - // ******************************************************************* // read an init file // ******************************************************************* @@ -111,10 +107,9 @@ static void ReadInitFile (const TCollection_AsciiString& theFileName) #ifdef WNT if (!Draw_Batch) { try { - OCC_CATCH_SIGNALS aPath.ChangeAll ('\\', '/'); - sprintf(console_command, "source \"%s\"", aPath.ToCString()); + sprintf(console_command, "source \"%.980s\"", aPath.ToCString()); console_semaphore = HAS_CONSOLE_COMMAND; while (console_semaphore == HAS_CONSOLE_COMMAND) Sleep(10); @@ -133,7 +128,6 @@ static void ReadInitFile (const TCollection_AsciiString& theFileName) } #endif } -//#endif //======================================================================= //function : @@ -176,57 +170,79 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In // analyze arguments // ***************************************************************** Draw_Batch = Standard_False; - TCollection_AsciiString aRunFile; + TCollection_AsciiString aRunFile, aCommand; Standard_Integer i; Standard_Boolean isInteractiveForced = Standard_False; -#ifndef WNT - for (i = 0; i < argc; i++) { - if (strcasecmp(argv[i],"-b") == 0) - Draw_Batch = Standard_True; -# ifndef __sgi - else if (strcasecmp(argv[i],"-l") == 0) { - Draw_LowWindows = Standard_True; + +#ifdef WNT + // On NT command line arguments are in the lpzline and not in argv + int argc = 0; + const int MAXARGS = 1024; + const char* argv[MAXARGS]; + for (const char* p = strtok(lpszLine, " \t"); p != NULL; p = strtok(NULL, " \t")) { + argv[argc++] = p; + } +#endif + + // parse command line + for (i = 1; i < argc; i++) { + if (strcasecmp (argv[i], "-h") == 0 || strcasecmp (argv[i], "--help") == 0) + { + cout << "Open CASCADE " << OCC_VERSION_STRING_EXT << " DRAW Test Harness" << endl << endl; + cout << "Options: " << endl; + cout << " -b: batch mode (no GUI, no viewers)" << endl; + cout << " -v: no GUI, use virtual (off-screen) windows for viewers" << endl; + cout << " -i: interactive mode" << endl; + cout << " -f file: execute script from file" << endl; + cout << " -c command args...: execute command (with optional arguments)" << endl << endl; + cout << "Options -b, -v, and -i are mutually exclusive." << endl; + cout << "If -c or -f are given, -v is default; otherwise default is -i." << endl; + cout << "Options -c and -f are alternatives and should be at the end " << endl; + cout << "of the command line. " << endl; + cout << "Option -c can accept set of commands separated by ';'." << endl; + return; } -# endif - else if (strcasecmp(argv[i],"-v") == 0) { + else if (strcasecmp (argv[i], "-b") == 0) + Draw_Batch = Standard_True; + else if (strcasecmp (argv[i], "-v") == 0) { // force virtual windows Draw_VirtualWindows = Standard_True; - } else if (strcasecmp(argv[i],"-i") == 0) { + } else if (strcasecmp (argv[i], "-i") == 0) { // force interactive Draw_VirtualWindows = Standard_False; isInteractiveForced = Standard_True; - } else if (strcasecmp(argv[i],"-f") == 0) { // -f option should be LAST! + } else if (strcasecmp (argv[i], "-f") == 0) { // -f option should be LAST! Draw_VirtualWindows = !isInteractiveForced; if (++i < argc) { aRunFile = TCollection_AsciiString (argv[i]); } break; - } - } -#else - // On NT command line arguments are in the lpzline and not in argv - for (char* p = strtok(lpszLine, " \t"); p != NULL; p = strtok(NULL, " \t")) { - if (strcasecmp(p, "-v") == 0) { - Draw_VirtualWindows = Standard_True; - } else if (strcasecmp(p, "-i") == 0) { - // force interactive - Draw_VirtualWindows = Standard_False; - isInteractiveForced = Standard_True; - } else if (strcasecmp(p, "-f") == 0) { // -f option should be LAST! + } else if (strcasecmp (argv[i], "-c") == 0) { // -c option should be LAST! Draw_VirtualWindows = !isInteractiveForced; - p = strtok(NULL," \t"); - if (p != NULL) { - aRunFile = TCollection_AsciiString (p); + if (++i < argc) { + aCommand = TCollection_AsciiString (argv[i]); + } + while (++i < argc) { + aCommand.AssignCat (" "); + aCommand.AssignCat (argv[i]); } break; + } else { + cout << "Error: unsupported option " << argv[i] << endl; } } -#endif + // ***************************************************************** // set signals // ***************************************************************** OSD::SetSignal(); +#ifdef _WIN32 + // in interactive mode, force Windows to report dll loading problems interactively + if ( ! Draw_VirtualWindows && ! Draw_Batch ) + ::SetErrorMode (0); +#endif + // ***************************************************************** // init X window and create display // ***************************************************************** @@ -236,12 +252,12 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In if (!Draw_Batch) #ifdef WNT - Draw_Batch=!Init_Appli(hInst, hPrevInst, nShow, hWnd); + Draw_Batch=!Init_Appli(hInst, hPrevInst, nShow, hWnd); #else Draw_Batch=!Init_Appli(); #endif else - cout << "batch mode" << endl; + cout << "DRAW is running in batch mode" << endl; XLoop = !Draw_Batch; if (XLoop) { @@ -302,24 +318,27 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In ReadInitFile (getenv ("DRAWDEFAULT")); } - // pure batch + // read commands from file if (!aRunFile.IsEmpty()) { - // do not map raise the windows, so test programs are discrete -#ifndef WNT - Draw_LowWindows = Standard_True; -#endif - // comme on ne peut pas photographier les fenetres trop discretes sur sgi - // on se met en vedette !! (pmn 20/02/97) -#ifdef __sgi - Draw_LowWindows = Standard_False; -#endif - ReadInitFile (aRunFile); - // provide a clean exit, this is usefull for some analysis tools + // provide a clean exit, this is useful for some analysis tools + if ( ! isInteractiveForced ) #ifndef WNT - return; + return; #else - ExitProcess(0); + ExitProcess(0); +#endif + } + + // execute command from command line + if (!aCommand.IsEmpty()) { + Draw_Interprete (aCommand.ToCString()); + // provide a clean exit, this is useful for some analysis tools + if ( ! isInteractiveForced ) +#ifndef WNT + return; +#else + ExitProcess(0); #endif } @@ -328,7 +347,7 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In // ***************************************************************** if (XLoop) { #ifdef WNT - Run_Appli(hWnd); + Run_Appli(hWnd); #else Run_Appli(Draw_Interprete); #endif @@ -356,7 +375,7 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In void (*Draw_BeforeCommand)() = NULL; void (*Draw_AfterCommand)(Standard_Integer) = NULL; -Standard_Boolean Draw_Interprete(char* com) +Standard_Boolean Draw_Interprete(const char* com) { static Standard_Boolean first = Standard_True; diff --git a/src/Draw/Draw_Main.cxx b/src/Draw/Draw_Main.cxx index 6682dbae02..bf281a7eaf 100755 --- a/src/Draw/Draw_Main.cxx +++ b/src/Draw/Draw_Main.cxx @@ -86,7 +86,7 @@ static char* ColorNames[MAXCOLOR] = { static Standard_Boolean XLoop; // extern Standard_IMPORT Standard_Boolean Draw_Interprete(char* command); //for C21 -Standard_IMPORT Standard_Boolean Draw_Interprete(char* command); //for C30 +Standard_IMPORT Standard_Boolean Draw_Interprete(const char* command); //for C30 // true if complete command // necessary for WNT in C21 only diff --git a/src/Draw/Draw_Window.cxx b/src/Draw/Draw_Window.cxx index e48bf9c350..0a7c0d0060 100755 --- a/src/Draw/Draw_Window.cxx +++ b/src/Draw/Draw_Window.cxx @@ -37,7 +37,7 @@ #include extern Draw_Interpretor theCommands; -Standard_IMPORT Standard_Boolean Draw_VirtualWindows; +extern Standard_Boolean Draw_VirtualWindows; static Tcl_Interp *interp; /* Interpreter for this application. */ /* @@ -180,7 +180,6 @@ Display* Draw_WindowDisplay = NULL; Standard_Integer Draw_WindowScreen = 0; Colormap Draw_WindowColorMap; Standard_Boolean Draw_BlackBackGround = Standard_True; -Standard_Boolean Draw_LowWindows = Standard_False; // Initialization of static variables of Draw_Window @@ -572,13 +571,6 @@ void Draw_Window::DisplayWindow() { return; } - else if (Draw_LowWindows) - { - // the window will be displayed so that not to be hidden - // by any other window (on top) - XMapWindow(Draw_WindowDisplay, win); - XLowerWindow(Draw_WindowDisplay, win); - } else { XMapRaised(Draw_WindowDisplay, win); @@ -954,9 +946,9 @@ static void ProcessEvents(ClientData,int) //====================================================== -static Standard_Boolean(*Interprete) (char*); +static Standard_Boolean(*Interprete) (const char*); -void Run_Appli(Standard_Boolean (*interprete) (char*)) +void Run_Appli(Standard_Boolean (*interprete) (const char*)) { Tcl_Channel outChannel, inChannel ; Interprete = interprete; @@ -2028,7 +2020,7 @@ Standard_Boolean Init_Appli(HINSTANCE hInst, return Standard_True; } -Standard_Boolean Draw_Interprete (char*); +Standard_Boolean Draw_Interprete (const char*); /*--------------------------------------------------------*\ | readStdinThreadFunc diff --git a/src/Draw/Draw_Window.hxx b/src/Draw/Draw_Window.hxx index 36f2e5c791..0278343588 100755 --- a/src/Draw/Draw_Window.hxx +++ b/src/Draw/Draw_Window.hxx @@ -169,7 +169,7 @@ class Draw_Window // and return True if the command is complete //====================================================== -void Run_Appli(Standard_Boolean (*inteprete) (char*)); +void Run_Appli(Standard_Boolean (*inteprete) (const char*)); //====================================================== // funtion : Init_Appli diff --git a/src/Draw/MainWindow.cxx b/src/Draw/MainWindow.cxx index edb2a9b3c6..d2f8153267 100755 --- a/src/Draw/MainWindow.cxx +++ b/src/Draw/MainWindow.cxx @@ -31,7 +31,7 @@ #include #include -Standard_Boolean Draw_Interprete(char* command); // Implemented in Draw.cxx +Standard_Boolean Draw_Interprete(const char* command); // Implemented in Draw.cxx extern Standard_Boolean Draw_IsConsoleSubsystem; //extern "C" int compat_unlink(const char *fname); // Implemente dans TCL