51 #include <sys/types.h> 60 #include "rnr/rnrconfig.h" 127 m_sCmdHelpBrief =
"Print command help.";
128 m_sCmdHelpArgs =
"[<cmd> [object]]";
129 m_sCmdHelpDesc =
"Print list of commands or command long help. " 130 "If no arguments are " 131 "specified, then only the list of commands is printed. " 132 "If only the <cmd> argument is specified, and <cmd> is " 134 " verb object [qualifiers]\n" 135 "then a list of the command objects is printed. " 136 "Otherwise, the long help is printed for the given " 138 " <cmd> Root command name (verb).\n" 139 " <object> Sub-command name (object).";
154 TRY( ChkArgCnt(shell, argc) );
165 cmdNode = MatchHelp(shell, argc, argv, shell.
GetRootCmds());
168 if( cmdNode.
IsMap() )
171 PrintHelpSummaryList(shell, *cmdNode.
GetMap());
176 else if( cmdNode.
IsCmd() )
185 shell.
Error(
"help: Unknown command \"%s\".", argv[0]);
191 shell.
Error(
"help: Unknown command \"%s %s\".", argv[0], argv[1]);
214 const char *sContext)
216 size_t uCmdLen = strlen(m_sPubName);
217 const char *sSubContext;
220 if( strlen(sContext) < uCmdLen )
226 else if( strlen(sContext) == uCmdLen )
234 sSubContext = sContext+uCmdLen+1;
250 ShCmdMap::iterator iter;
252 for(iter=cmdMap.begin(); iter!=cmdMap.end(); iter++)
254 printf(
"%s ", iter->first);
268 ShCmdMap::iterator iter;
270 for(iter=cmdMap.begin(); iter!=cmdMap.end(); iter++)
272 printf(
"%15s - %s\n", iter->first, iter->second.GetMapBrief().c_str());
293 ShCmdMap::iterator iter1, iter2;
295 const char *sCmdName1, *sCmdName2;
305 n = strlen(sPattern);
308 for(iter1=cmdMap.begin(); iter1!=cmdMap.end(); iter1++)
310 sCmdName1 = iter1->first;
311 if( !strncmp(sPattern, sCmdName1, n) )
318 if( iter1 == cmdMap.end() )
324 for(iter2=cmdMap.begin(); iter2!=cmdMap.end(); iter2++)
331 sCmdName2 = iter2->first;
334 if( !strncmp(sPattern, sCmdName2, n) )
336 shell.
Error(
"help: %s: (Sub)Command not unique: Matches %s %s ...",
337 sPattern, sCmdName1, sCmdName2);
344 return iter1->second;
346 else if( (argc == 2) && iter1->second.IsMap() )
348 return MatchHelp(shell, argc-1, argv+1, *iter1->second.GetMap());
375 m_sCmdHelpBrief =
"Quit (exit) dynashell.";
411 m_sCmdHelpBrief =
"Exit (quit) dynashell.";
447 m_sCmdHelpBrief =
"Set the logging level.";
448 m_sCmdHelpArgs =
"<level>";
449 m_sCmdHelpDesc =
"Set the logging level.\n" 450 " <level> 0 | off | 1 | error | 2 | diag1 | ...";
464 TRY( ChkArgCnt(shell, argc) );
466 if( !strcmp(argv[0],
"off") )
470 else if( !strcmp(argv[0],
"error") )
474 else if( !strncmp(argv[0],
"diag", 3) )
476 TRY( ToInt(shell, argv[0]+4, &nLevel) );
481 TRY( ToInt(shell, argv[0], &nLevel) );
484 LOG_SET_THRESHOLD(nLevel);
506 const char *sContext)
509 static const char *logLevelSymTbl[] =
511 "off",
"error",
"diag1",
"diag2",
"diag3",
"diag4",
"diag5",
"diag6" 530 while( m_nTabIndex < arraysize(logLevelSymTbl) )
532 s = logLevelSymTbl[m_nTabIndex++];
534 if( !strncmp(s, sText, uTextLen) )
567 m_sCmdHelpBrief =
"Delay for a specified amount of time.";
568 m_sCmdHelpArgs =
"<sec>";
569 m_sCmdHelpDesc =
"Block waiting for <sec> seconds.\n" 570 " <sec> Floating-point wait period in seconds.";
583 struct timeval timeout;
585 TRY( ChkArgCnt(shell, argc) );
586 TRY( ToDouble(shell, argv[0], &fWait) );
588 timeout.tv_sec = (long)fWait;
589 timeout.tv_usec = (long)((fWait - (
double)timeout.tv_sec) * 1000000.0);
591 select(0, NULL, NULL, NULL, &timeout);
613 m_sCmdName =
"script";
614 m_sCmdHelpBrief =
"Run a dynamixel shell script.";
615 m_sCmdHelpArgs =
"<file>";
616 m_sCmdHelpDesc =
"Run a file containing dynamixel shell commands.\n" 617 " <file> Shell text file name.";
632 TRY( ChkArgCnt(shell, argc) );
634 sScriptFile = argv[0];
636 if( access(sScriptFile, F_OK|R_OK) != 0 )
638 shell.
Error(
"%s: %s.", sScriptFile, strerror(errno));
640 else if( (fp = fopen(sScriptFile,
"r")) == NULL )
642 shell.
Error(
"%s: %s.", sScriptFile, strerror(errno));
670 const char *sContext)
RoadNarrows Dynamixel Bus Communications Abstract Base Class Interface.
ShCmdMap * GetMap()
Get map object.
virtual char * TabCompletion(DynaShell &shell, const char *sText, size_t uTextLen, int nState, const char *sContext)
Command tab completion generator.
Dynamixel shell utilities.
DynaShellCmd * GetCmd()
Get command object.
void ScriptPush(const char *sScriptFile, FILE *fp)
Push new script on the stack.
void Exec(DynaShell &shell, int argc, char *argv[])
Exit shell.
void Exec(DynaShell &shell, int argc, char *argv[])
Wait the given number of seconds.
void Exec(DynaShell &shell, int argc, char *argv[])
Print help.
void Exec(DynaShell &shell, int argc, char *argv[])
Execute script.
char * CmdListGenerator(int nUid, const char *sText, size_t uTextLen, int nState, const char *sContext)
Command list generator function.
RoadNarrows Dynamixel Servo Chain Container Base Class Interface.
static const int FIRST
first state
void PrintHelpWordList(DynaShell &shell, ShCmdMap &cmdMap)
Print help list of words.
static char * dupstr(const string &str)
Duplicate string.
Dynamixel shell command abstract base class.
ShCmdNode & MatchHelp(DynaShell &shell, int argc, char *argv[], ShCmdMap &cmdMap)
Match command.
Dynamixel background thread class declarations.
map< const char *, ShCmdNode, ShCmdNodeKeyCmp > ShCmdMap
Shell command map type.
virtual char * TabCompletion(DynaShell &shell, const char *sText, size_t uTextLen, int nState, const char *sContext)
Command tab completion generator.
static int wc(const string &str)
Count the words in the string.
virtual void Ok()
Print standard ok success response.
void PrintHelpSummaryList(DynaShell &shell, ShCmdMap &cmdMap)
Print help summary list.
void Exec(DynaShell &shell, int argc, char *argv[])
NULL.
virtual void PrintHelp(int indent=0, int width=80)
Print command help with the description aligned at the given indentation.
bool IsMap()
Test if node type is map of commands.
void PublishShellCoreCommands(DynaShell &shell)
Publish shell core commands to shell.
RoadNarrows Dynamixel Archetype Servo Abstract Base Class.
int m_nTabIndex
tab completion: keyword index
#define TRY(boolexpr,...)
Try boolean expression.
void PublishCommand(const char *sParent, DynaShellCmd *pNewCmd)
Publish new command to shell.
RoadNarrows Dynamixel Top-Level Package Header File.
The dynashell Command Class Interface.
virtual char * TabCompletion(DynaShell &shell, const char *sText, size_t uTextLen, int nState, const char *sContext)
Command tab completion generator.
void Exec(DynaShell &shell, int argc, char *argv[])
Quit shell.
bool m_bRun
do [not] run shell
void Exec(DynaShell &shell, int argc, char *argv[])
Set diagnotics logging level.
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
static char * FileCompletionGenerator(const char *sText, int nState)
File name tab completion generator.
Shell command node class.
bool IsCmd()
Test if node type is shell command.
The simple dynashell declarations.