49 #include <sys/types.h> 61 #include <readline/readline.h> 62 #include <readline/history.h> 63 #endif // HAVE_READLINE 98 m_fnAppGen = fnAppGen;
115 m_fnAppGen = fnAppGen;
149 if( strName.length() > 0 )
151 m_sName = dupstr(strName.c_str());
155 m_sName = dupstr(
"none");
162 rl_readline_name = m_sName;
165 rl_attempted_completion_function = CompletionWrap;
166 #endif // HAVE_READLINE 179 m_sName = dupstr(sName);
183 m_sName = dupstr(
"none");
190 rl_readline_name = m_sName;
193 rl_attempted_completion_function = CompletionWrap;
194 #endif // HAVE_READLINE 205 if( m_sName != NULL )
232 entry.
m_nUid = m_nUidCounter;
233 m_vecGenerators.push_back(entry);
235 return m_nUidCounter++;
250 VecAppEntry::iterator iter;
252 for(iter = m_vecGenerators.begin();
253 iter != m_vecGenerators.begin();
256 if( iter->GetUid() == nUid )
258 m_vecGenerators.erase(iter);
283 static size_t BufSize = 4096;
288 bufLine =
new char[BufSize];
290 if( sPrompt && *sPrompt )
292 fprintf(stdout,
"%s", sPrompt);
296 if( fgets(bufLine, BufSize, fp) == NULL )
302 bufLine[BufSize-1] = 0;
304 if( (n > 0) && (bufLine[n-1] ==
'\n') )
324 HIST_ENTRY *pCurHist;
330 pCurHist = previous_history();
332 if( (pCurHist == NULL) || strcmp(pCurHist->line, str.c_str()) )
337 #endif // HAVE_READLINE 349 char *
t =
new char[strlen(s)+1];
367 for(i=0; i<t.length(); ++i)
369 if( !isspace((
int)t[i]) )
381 for(i=t.length()-1; i>0; --i)
383 if( !isspace((
int)t[i]) )
389 if( i != t.length()-1 )
391 t = t.substr(0, i+1);
411 for(left = s; isspace((
int)*left); left++) ;
418 right = left + strlen(left) - 1;
420 while( (right > left) && isspace((
int)*right) )
450 if( str.length() != 0 )
452 while( (pos = str.find(
" ")) != str.npos )
454 str = str.replace(pos, 2,
" ");
476 while( tokc < (
int)tokmax )
479 while( *s && isspace((
int)*s) )
494 while( *s && !isspace((
int)*s) )
526 while( *s && isspace((
int)*s) )
540 while( *s && !isspace((
int)*s) )
565 return ReadLineThis->Completion(sText, nStart, nEnd);
580 MatchGenerator(nStart);
582 return rl_completion_matches(sText, GeneratorWrap);
586 #endif // HAVE_READLINE 604 if( ReadLineThis->m_posMatched == ReadLineThis->m_vecGenerators.end() )
612 ReadLineThis->m_uTextLen = strlen(sText);
616 return ReadLineThis->m_posMatched->m_fnAppGen(
617 ReadLineThis->m_posMatched->GetUid(),
619 ReadLineThis->m_uTextLen,
621 ReadLineThis->m_strContext.c_str(),
622 ReadLineThis->m_posMatched->m_pAppArg);
633 m_posMatched = m_vecGenerators.end();
635 m_strContext.clear();
650 for(m_posMatched = m_vecGenerators.begin();
651 m_posMatched != m_vecGenerators.end();
657 if( m_posMatched->m_regex.Match(m_strContext) )
664 #endif // HAVE_READLINE char ** Completion(const char *sText, int nStart, int nEnd)
Command completion callback function.
int RegisterGenerator(const string strRegEx, ReadLineAppGenFunc_T fnAppGen, void *pAppArg)
Register application-specific tab-completion generator associated.
RegEx m_regex
applicatin matching regular expression
static string c14n(const string &str, size_t nLen)
Canonicalization of a string.
~ReadLineEntry()
Default destructor.
static char * fReadLine(FILE *fp, const char *sPrompt)
Read one input line from the given input stream.
ReadLineAppGenFunc_T m_fnAppGen
application-specific generator
static const int FIRST
first state
static char * dupstr(const string &str)
Duplicate string.
static int tokenize(char *s, char *tokv[], size_t tokmax)
Tokenize input.
static string strip(string &str)
Strip string of leading and trailing white space.
static char ** CompletionWrap(const char *sText, int nStart, int nEnd)
Command completion callback function wrapper.
static ReadLine * ReadLineThis
static pointer this single instance
virtual ~ReadLine()
Destructor.
char *(* ReadLineAppGenFunc_T)(int nUid, const char *sText, size_t uTextLen, int nState, const char *sContext, void *pAppArg)
Application-specific tab completion generator function type.
static int wc(const string &str)
Count the words in the string.
void AddToHistory(const char *sInput)
Add line to history.
ReadLine(const string &strName)
Initialization constructor.
ReadLineEntry()
Default constructor.
static const int NOT_REG
not registered return value
ReadLine class provides a c++ wrapper around the readline c library.
void MatchGenerator(int nEnd)
Find application-specific generator associated with the first characters in the readline buffer...
The Dynamixel Shell ReadLine Class.
void * m_pAppArg
application-specific argument
bool IsValid()
Check if entry is valid.
The Dynamixel Shell Regular Expression Class.
void UnregisterGenerator(int nUid)
Unregister application-specific generator associated with path.
static char * GeneratorWrap(const char *sText, int nState)
Generator wrapper.