1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0023151: Add command line option to DRAWEXE to execute specified command

New command line option -c added to DRAWEXE: if it is given, the following arguments are considered as commands to be executed by DRAW after start.
When options -f or -c are used, DRAW exits after completion of the script unless option -i is given.
Option -l is removed as obsolete (not needed anymore due to appearance of option -v).
Option -h (or --help) is added, giving help on command options.
Reporting of unrecognized options added.
On Windows, when run in interactive mode, extended error reporting in case of DLL loading problems activated.
This commit is contained in:
abv 2012-05-11 14:29:52 +04:00 committed by bugmaster
parent f00435b08c
commit bf03eb83c7
6 changed files with 81 additions and 72 deletions

View File

@ -41,8 +41,6 @@
Standard_Boolean Draw_Interprete(char*); // Implement in draw.cxx
#define CLIENTWND 0 #define CLIENTWND 0
#define PROMPT "Command >> " #define PROMPT "Command >> "

View File

@ -54,6 +54,7 @@
#include <gp_Pnt2d.hxx> #include <gp_Pnt2d.hxx>
#include <Standard_Stream.hxx> #include <Standard_Stream.hxx>
#include <Standard_Version.hxx>
#include <Draw_Drawable3D.hxx> #include <Draw_Drawable3D.hxx>
#include <Draw_Interpretor.hxx> #include <Draw_Interpretor.hxx>
@ -67,9 +68,6 @@
#include <TCollection_AsciiString.hxx> #include <TCollection_AsciiString.hxx>
#include <Standard_ErrorHandler.hxx> #include <Standard_ErrorHandler.hxx>
extern Standard_Boolean Draw_ParseFailed; extern Standard_Boolean Draw_ParseFailed;
#ifndef WNT
extern Standard_Boolean Draw_LowWindows;
#endif
Standard_EXPORT Draw_Viewer dout; Standard_EXPORT Draw_Viewer dout;
Standard_EXPORT Draw_Interpretor theCommands; Standard_EXPORT Draw_Interpretor theCommands;
@ -92,11 +90,9 @@ static Standard_Boolean XLoop;
static Handle(Draw_ProgressIndicator) PInd = NULL; 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 // true if complete command
//#ifndef WNT
// ******************************************************************* // *******************************************************************
// read an init file // read an init file
// ******************************************************************* // *******************************************************************
@ -111,10 +107,9 @@ static void ReadInitFile (const TCollection_AsciiString& theFileName)
#ifdef WNT #ifdef WNT
if (!Draw_Batch) { if (!Draw_Batch) {
try { try {
OCC_CATCH_SIGNALS
aPath.ChangeAll ('\\', '/'); aPath.ChangeAll ('\\', '/');
sprintf(console_command, "source \"%s\"", aPath.ToCString()); sprintf(console_command, "source \"%.980s\"", aPath.ToCString());
console_semaphore = HAS_CONSOLE_COMMAND; console_semaphore = HAS_CONSOLE_COMMAND;
while (console_semaphore == HAS_CONSOLE_COMMAND) while (console_semaphore == HAS_CONSOLE_COMMAND)
Sleep(10); Sleep(10);
@ -133,7 +128,6 @@ static void ReadInitFile (const TCollection_AsciiString& theFileName)
} }
#endif #endif
} }
//#endif
//======================================================================= //=======================================================================
//function : //function :
@ -176,57 +170,79 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In
// analyze arguments // analyze arguments
// ***************************************************************** // *****************************************************************
Draw_Batch = Standard_False; Draw_Batch = Standard_False;
TCollection_AsciiString aRunFile; TCollection_AsciiString aRunFile, aCommand;
Standard_Integer i; Standard_Integer i;
Standard_Boolean isInteractiveForced = Standard_False; Standard_Boolean isInteractiveForced = Standard_False;
#ifndef WNT
for (i = 0; i < argc; i++) { #ifdef WNT
if (strcasecmp(argv[i],"-b") == 0) // On NT command line arguments are in the lpzline and not in argv
Draw_Batch = Standard_True; int argc = 0;
# ifndef __sgi const int MAXARGS = 1024;
else if (strcasecmp(argv[i],"-l") == 0) { const char* argv[MAXARGS];
Draw_LowWindows = Standard_True; 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], "-b") == 0)
else if (strcasecmp(argv[i],"-v") == 0) { Draw_Batch = Standard_True;
else if (strcasecmp (argv[i], "-v") == 0) {
// force virtual windows // force virtual windows
Draw_VirtualWindows = Standard_True; Draw_VirtualWindows = Standard_True;
} else if (strcasecmp(argv[i],"-i") == 0) { } else if (strcasecmp (argv[i], "-i") == 0) {
// force interactive // force interactive
Draw_VirtualWindows = Standard_False; Draw_VirtualWindows = Standard_False;
isInteractiveForced = Standard_True; 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; Draw_VirtualWindows = !isInteractiveForced;
if (++i < argc) { if (++i < argc) {
aRunFile = TCollection_AsciiString (argv[i]); aRunFile = TCollection_AsciiString (argv[i]);
} }
break; break;
} } else if (strcasecmp (argv[i], "-c") == 0) { // -c option should be LAST!
}
#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!
Draw_VirtualWindows = !isInteractiveForced; Draw_VirtualWindows = !isInteractiveForced;
p = strtok(NULL," \t"); if (++i < argc) {
if (p != NULL) { aCommand = TCollection_AsciiString (argv[i]);
aRunFile = TCollection_AsciiString (p); }
while (++i < argc) {
aCommand.AssignCat (" ");
aCommand.AssignCat (argv[i]);
} }
break; break;
} else {
cout << "Error: unsupported option " << argv[i] << endl;
} }
} }
#endif
// ***************************************************************** // *****************************************************************
// set signals // set signals
// ***************************************************************** // *****************************************************************
OSD::SetSignal(); 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 // 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) if (!Draw_Batch)
#ifdef WNT #ifdef WNT
Draw_Batch=!Init_Appli(hInst, hPrevInst, nShow, hWnd); Draw_Batch=!Init_Appli(hInst, hPrevInst, nShow, hWnd);
#else #else
Draw_Batch=!Init_Appli(); Draw_Batch=!Init_Appli();
#endif #endif
else else
cout << "batch mode" << endl; cout << "DRAW is running in batch mode" << endl;
XLoop = !Draw_Batch; XLoop = !Draw_Batch;
if (XLoop) { if (XLoop) {
@ -302,24 +318,27 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In
ReadInitFile (getenv ("DRAWDEFAULT")); ReadInitFile (getenv ("DRAWDEFAULT"));
} }
// pure batch // read commands from file
if (!aRunFile.IsEmpty()) { 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); 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 #ifndef WNT
return; return;
#else #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 #endif
} }
@ -328,7 +347,7 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In
// ***************************************************************** // *****************************************************************
if (XLoop) { if (XLoop) {
#ifdef WNT #ifdef WNT
Run_Appli(hWnd); Run_Appli(hWnd);
#else #else
Run_Appli(Draw_Interprete); Run_Appli(Draw_Interprete);
#endif #endif
@ -356,7 +375,7 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In
void (*Draw_BeforeCommand)() = NULL; void (*Draw_BeforeCommand)() = NULL;
void (*Draw_AfterCommand)(Standard_Integer) = 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; static Standard_Boolean first = Standard_True;

View File

@ -86,7 +86,7 @@ static char* ColorNames[MAXCOLOR] = {
static Standard_Boolean XLoop; static Standard_Boolean XLoop;
// extern Standard_IMPORT Standard_Boolean Draw_Interprete(char* command); //for C21 // 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 // true if complete command
// necessary for WNT in C21 only // necessary for WNT in C21 only

View File

@ -37,7 +37,7 @@
#include <Image_PixMap.hxx> #include <Image_PixMap.hxx>
extern Draw_Interpretor theCommands; extern Draw_Interpretor theCommands;
Standard_IMPORT Standard_Boolean Draw_VirtualWindows; extern Standard_Boolean Draw_VirtualWindows;
static Tcl_Interp *interp; /* Interpreter for this application. */ static Tcl_Interp *interp; /* Interpreter for this application. */
/* /*
@ -180,7 +180,6 @@ Display* Draw_WindowDisplay = NULL;
Standard_Integer Draw_WindowScreen = 0; Standard_Integer Draw_WindowScreen = 0;
Colormap Draw_WindowColorMap; Colormap Draw_WindowColorMap;
Standard_Boolean Draw_BlackBackGround = Standard_True; Standard_Boolean Draw_BlackBackGround = Standard_True;
Standard_Boolean Draw_LowWindows = Standard_False;
// Initialization of static variables of Draw_Window // Initialization of static variables of Draw_Window
@ -572,13 +571,6 @@ void Draw_Window::DisplayWindow()
{ {
return; return;
} }
else if (Draw_LowWindows)
{
// the window <win> will be displayed so that not to be hidden
// by any other window (on top)
XMapWindow(Draw_WindowDisplay, win);
XLowerWindow(Draw_WindowDisplay, win);
}
else else
{ {
XMapRaised(Draw_WindowDisplay, win); 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 ; Tcl_Channel outChannel, inChannel ;
Interprete = interprete; Interprete = interprete;
@ -2028,7 +2020,7 @@ Standard_Boolean Init_Appli(HINSTANCE hInst,
return Standard_True; return Standard_True;
} }
Standard_Boolean Draw_Interprete (char*); Standard_Boolean Draw_Interprete (const char*);
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
| readStdinThreadFunc | readStdinThreadFunc

View File

@ -169,7 +169,7 @@ class Draw_Window
// and return True if the command is complete // 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 // funtion : Init_Appli

View File

@ -31,7 +31,7 @@
#include <Draw_Window.hxx> #include <Draw_Window.hxx>
#include <CommandWindow.h> #include <CommandWindow.h>
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 Standard_Boolean Draw_IsConsoleSubsystem;
//extern "C" int compat_unlink(const char *fname); // Implemente dans TCL //extern "C" int compat_unlink(const char *fname); // Implemente dans TCL