14 #ifndef __CMD_Manager_H__
15 #define __CMD_Manager_H__
45 class cmd_FalseCallback;
58 #define CMD_STATUS_VARIABLE "status"
70 void aboutToDelete()
override final;
90 void sendInput(
const char *input,
bool create_block =
true);
96 void sendMultiLineInput(
const char *input,
97 bool create_block =
true);
100 void execute(
const char *cmd,
bool add_to_history =
false,
101 std::ostream *out=0, std::ostream *err=0,
102 bool do_alias_expansion =
true,
103 bool create_block =
true);
109 void sendInputNoLock(
111 bool create_block =
true);
112 void sendMultiLineInputNoLock(
114 bool create_block =
true);
117 bool add_to_history =
false,
118 std::ostream *out = 0,
119 std::ostream *err = 0,
120 bool do_alias_expansion =
true,
121 bool create_block =
true);
126 void completeCommand(
const char *prefix,
130 void matchCommands(
const char *prefix,
134 void installCommand(
const char *
name,
const char *options,
140 bool uninstallCommand(
const char *
name);
146 bool markCommandForFalseIfStatements(
const char *
name,
156 {
return myPostCmdCallbackData; }
161 void setCommandEchoCallback(
166 {
return myCommandEchoCallbackData; }
169 void commandDump(std::ostream &os,
const char *
pattern=0,
170 const char *prefix=0)
const;
174 void commandHelp(std::ostream &os,
const char *cmd,
175 bool full_match_only =
false)
const;
177 void saveAliases(std::ostream &os);
178 void saveVariables(std::ostream &os,
bool level0_locals);
184 int prev = myHistoryCapture;
185 myHistoryCapture = onOff;
193 return mySourceStack(mySourceStack.entries()-1);
197 void pushOutputStreams(std::ostream &out, std::ostream &err);
198 void popOutputStreams();
201 void unsetVariable(
const char *
name);
203 void resetVariables();
206 void setVariable(
const char *
name,
const char *
value,
207 int local,
int uplevel=0);
210 bool hasVariable(
const char *
name)
const;
213 {
return getVariableValueByName(name, value); }
216 {
return getVariableValueByName(name, value); }
219 {
return getVariableValueByName(name, value); }
222 {
return getVariableValueByName(name, value); }
225 {
return getVariableValueByName(name, value); }
227 bool hasEnv(
const char *
name)
const;
231 int clearDirtyVariables();
235 int isVariableNameOk(
const char *
name);
239 bool setMotName(
const char *
path,
bool dovarchange);
241 void setJob(
const char *
path);
246 std::ostream &
getError(
int printMessage = 1);
250 std::ostream *setStandardOut(std::ostream &os);
251 std::ostream *setStandardErr(std::ostream &os);
254 void streamDeleted(std::ostream &os);
256 void setPrompt(
const char *prompt);
260 level = myPromptStack.entries()-1;
261 return myPromptStack(
level);
263 void pushPrompt(
const char *prompt);
266 int isLoopCommand(
const char *str);
268 int evaluateCondition(
const char *expr);
269 int evaluateCondition(
int argc,
const char *argv[]);
274 static void saveProtectedString(std::ostream &os,
const char *
s);
275 static void expandControlSequences(
UT_String &str);
283 static void buildQuotedCommandLineStringForBinaryData(
285 static void retrieveBinaryDataFromInsideCommand(
289 void dumpHistory(std::ostream &os)
const;
295 const char *getHistoryCommand(
int n)
const;
297 unsigned int getHistoryCount()
const;
305 void setAlias(
const char *
name,
const char *
value);
307 void destroyAlias(
const char *
name);
309 void destroyAliases();
315 void allowEnvironmentToOverwriteVariable(
316 const char *
name,
bool onoff);
319 bool isEnvironmentAllowedToOverwriteVariable(
324 { myIsLoadingGlobalVariables = onoff; }
327 {
return myIsLoadingGlobalVariables; }
333 { myVariableChangeNotifier = notifier; }
336 {
return myVariableChangeNotifier; }
338 void saveCommandString(std::ostream &os,
const UT_String &str);
342 int &fstart,
int &fend,
int &finc,
343 char oframe =
'f',
char ofinc =
'i');
351 myLoopNestLevel += dir;
352 if (!myLoopNestLevel)
358 CMD_Loop *buildLoop(
const char *text);
362 void setVerbose(
int on_off);
363 int getVerbose()
const;
366 { myCommandEchoFlag = on_off; }
369 void setIORedirection(
int on_off);
370 int getIORedirection()
const;
373 const char *getOptions(
const char *cmdName);
378 return findCommand(name, 1) >= 0;
386 void setSafeMode(
int safe_mode);
387 int isInSafeMode()
const;
388 void setBrowserMode(
int browser_mode);
389 int isInBrowserMode()
const;
394 { myStatusCode = status_code; }
397 {
return myStatusCode; }
408 bool openPort(
int port,
bool safe,
bool quiet,
410 const char *execute, pid_t *pid,
411 bool separateerrors,
bool suppress =
true,
412 const char *ip_mask = 0,
414 child_exited_callback = 0,
415 bool detach_console_for_execute=
false,
416 bool drain_queue_when_waiting_for_exec=
true);
417 bool openPort(
int port,
bool safe,
bool quiet,
418 bool wait, std::ostream &error_output,
419 const char *execute, pid_t *pid,
420 bool separateerrors,
bool suppress =
true,
421 const char *ip_mask = 0,
423 child_exited_callback = 0,
424 bool detach_console_for_execute=
false,
425 bool drain_queue_when_waiting_for_exec=
true);
426 bool openPort(
int port,
bool safe,
bool quiet,
428 const char *
const*execute_argv, pid_t *pid,
429 bool separateerrors,
bool suppress =
true,
430 const char *ip_mask = 0,
432 child_exited_callback = 0,
433 bool detach_console_for_execute=
false,
434 bool drain_queue_when_waiting_for_exec=
true);
435 bool openPort(
int port,
bool safe,
bool quiet,
436 bool wait, std::ostream &error_output,
437 const char *
const*execute_argv, pid_t *pid,
438 bool separateerrors,
bool suppress =
true,
439 const char *ip_mask = 0,
441 child_exited_callback = 0,
442 bool detach_console_for_execute=
false,
443 bool drain_queue_when_waiting_for_exec=
true);
447 void closePort(
int port);
448 void closeAutoPort();
450 bool beginChannelBlock();
451 bool endChannelBlock();
466 static int getHScriptPort();
475 static void setUpdatePythonEnvironmentVariables(
bool b);
476 static bool getUpdatePythonEnvironmentVariables();
480 int &timeDepend,
int thread)
override;
483 void destroyContents();
485 template <
typename T>
bool
486 getVariableValueByName(
const char *
name,
T &
value);
488 friend class cmd_SendInput;
489 friend class cmd_SendMultiLineInput;
490 friend class cmd_Execute;
492 void internalSendInput(
const char *input,
493 bool run_pushed_source=
false);
501 bool openPort(
int port,
bool safe,
bool quiet,
503 std::ostream *error_output,
504 const char *
const*execute_argv, pid_t *pid,
505 bool separateerrors,
bool suppress,
508 child_exited_callback,
509 bool detach_console_for_execute,
510 bool drain_queue_when_waiting_for_exec=
true);
514 void internalExecute(
const char *str);
515 void runCommand(
char *str);
517 int findCommand(
const char *
name,
int exact = 0);
519 void installBaseCommands();
520 void addPortExtension();
522 void installBuiltInVariables();
523 void installObsoleteCommands();
525 void setReadVariables(
const char *str);
526 void breakAllSources();
527 void updateNoAliasVariable();
528 void pushStandardOut(std::ostream *os);
529 void popStandardOut();
530 void pushStandardErr(std::ostream *os);
531 void popStandardErr();
532 void updateStatusVariable();
539 bool setHipVars(
const char *hipfile,
550 int myReadVariablesLocal;
556 bool myIsLoadingGlobalVariables;
561 unsigned myCommandCount;
568 int myExecuteCommandStack;
570 unsigned myAliasExpand:1,
582 void *myPostCmdCallbackData;
586 void *myCommandEchoCallbackData;
591 bool myCommandEchoFlag;
597 static bool theUpdatePythonEnvironmentVariables;
600 static int theChannelBlockCount;
634 template <typename
T>
bool
641 for (i = mySourceStack.entries()-1; i >= 0; i--)
643 src = mySourceStack(i);
void setStatusCode(int status_code)
void(* CMD_PostCmdCallback)(void *userdata)
int getStatusCode() const
Returns non-zero if the last command failed.
CMD_VariableTable * getGlobalVariables()
void bumpLoopNestLevel(int dir)
bool getVariable(const char *name, fpreal32 &value)
Returns the value of the named variable as a float.
GT_API const UT_StringHolder filename
virtual bool getVariableString(const char *name, UT_String &value, int &time_depend, int thread)
void * getCommandEchoCallbackData() const
Return the userdata set in setCommandEchoCallback().
static bool getContextExists()
#define SYS_VISIBILITY_EXPORT
bool getVariable(const char *name, int32 &value)
Returns the value of the named variable as an int.
virtual bool getChRefLabelForUI(const CH_ChannelRef &r, UT_String &ret) const
void setCommandEcho(bool on_off)
void(* CMD_CommandEchoCallback)(const char *echo_line, void *userdata)
GLsizei const GLchar *const * path
bool getVariable(const char *name, int64 &value)
Returns the value of the named variable as an int.
bool getVariable(const char *name, UT_String &value)
Returns the value of the named variable.
int getContinueLevel() const
UT_Array< CMD_Source * > CMD_SourceStack
virtual void setContext()
void * getPostCmdCallbackData() const
Return the userdata set in setPostCmdCallback().
**But if you need a result
void(* CMD_Callback)(CMD_Args &args)
SYS_VISIBILITY_EXPORT void CMDextendLibrary(CMD_Manager *theManager)
int getLoopNestLevel() const
virtual bool getChRefAlias(const CH_ChannelRef &r, UT_String &ret) const
unsigned getCommandsRun() const
Return the number of commands run. It's possible for this to overflow.
static CMD_Manager * getContext()
retrieves the global CMD_Manager
void setIsLoadingGlobalVariables(bool onoff)
CMD_VariableChangeNotifier * getVariableChangeNotifier() const
Returns a variable change notification center object.
bool getVariable(const char *name, fpreal64 &value)
Returns the value of the named variable as a fpreal64.
static bool getUpdatePythonEnvironmentVariables()
void setContinueLevel(int level)
CMD_AliasTable * getAliases()
bool getCommandEcho() const
int setHistoryCapture(int onOff)
bool isLoadingGlobalVariables()
Are we loading global variables from the hip file?
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
int isCommandDefined(const char *name)
Returns true if the command is defined.
CMD_AutoDisableUpdatePythonEnv()
bool getVariable(const char *name, UT_String &value)
GLuint const GLchar * name
GLboolean GLboolean GLboolean b
int getBreakLevel() const
GLenum GLenum GLsizei void * table
void(* ChildExitedCallback)(FS_ServerSocketListener &, void *callback_data, bool listener_forced_to_close)
UT_Array< char * > CMD_PromptStack
CMD_Manager * CMDgetManager()
const UT_StringHolder & appName() const
Return the name of the application.
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
~CMD_AutoDisableUpdatePythonEnv()
void bumpBreakLevel(int dir)
static void setUpdatePythonEnvironmentVariables(bool b)
**If you just want to fire and args
GLdouble GLdouble GLdouble top
const char * getPrompt(int level=-1) const
CMD_VariableTable * getLocalVariables()
UT_StringArray JOINTS hip
void setVariableChangeNotifier(CMD_VariableChangeNotifier *notifier)
Register a variable change notification center object.
UT_ValArray< CMD_Command * > CMD_CommandList
virtual bool getChRefNodePath(const CH_ChannelRef &r, UT_String &ret) const