appkit  1.5.1
RoadNarrows Robotics Application Kit
ReadLine.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Link: https://github.com/roadnarrows-robotics/rnr-sdk
6 //
7 // Library: librnr_appkit
8 //
9 // File: ReadLine.h
10 //
11 /*! \file
12  *
13  * \brief The thin ReadLine wrapper class interface.
14  *
15  * ReadLine provides a wrapper around the readline command-line C library.
16  *
17  * \note Define HAVE_READLINE to compile interface with the libreadline
18  * library.
19  *
20  * \author Robin Knight (robin.knight@roadnarrows.com)
21  *
22  * \par Copyright
23  * \h_copy 2011-2017. RoadNarrows LLC.\n
24  * http://www.roadnarrows.com\n
25  * All Rights Reserved
26  *
27  * \par Licence:
28  * MIT
29  */
30 /*
31  * @EulaBegin@
32  *
33  * Permission is hereby granted, without written agreement and without
34  * license or royalty fees, to use, copy, modify, and distribute this
35  * software and its documentation for any purpose, provided that
36  * (1) The above copyright notice and the following two paragraphs
37  * appear in all copies of the source code and (2) redistributions
38  * including binaries reproduces these notices in the supporting
39  * documentation. Substantial modifications to this software may be
40  * copyrighted by their authors and need not follow the licensing terms
41  * described here, provided that the new terms are clearly indicated in
42  * all files where they apply.
43  *
44  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
45  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
46  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
47  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
48  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
49  * THE POSSIBILITY OF SUCH DAMAGE.
50  *
51  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
52  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
53  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
54  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
55  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
56  *
57  * @EulaEnd@
58  */
59 ////////////////////////////////////////////////////////////////////////////////
60 
61 #ifndef _RNR_READ_LINE_H
62 #define _RNR_READ_LINE_H
63 
64 #include <sys/types.h>
65 #include <unistd.h>
66 #include <errno.h>
67 #include <string.h>
68 #include <stdlib.h>
69 #include <stdio.h>
70 #include <time.h>
71 
72 #include <iostream>
73 #include <string>
74 #include <vector>
75 
76 #ifdef HAVE_READLINE
77 #include <readline/readline.h>
78 #include <readline/history.h>
79 #endif // HAVE_READLINE
80 
81 
83 
84 /*!
85  * \brief RoadNarrows Robotics
86  */
87 namespace rnr
88 {
89  /*!
90  * \brief Commands
91  */
92  namespace cmd
93  {
94  static const char *RlTabEnd = ""; ///< no more matches value (empty string)
95 
96  // -------------------------------------------------------------------------
97  // Class ReadLine
98  // -------------------------------------------------------------------------
99 
100  /*!
101  * \brief ReadLine class provides a C++ wrapper around the readline C
102  * library.
103  *
104  * \par Features:
105  * \li line input processing
106  * \li tab completion
107  * \li history
108  *
109  * If libreadline is not available, then only simple line input processing
110  * is available.
111  */
112  class ReadLine
113  {
114  public:
115  static const int FIRST = 0; ///< first state
116 
117  /*!
118  * \brief ReadLine flag modifiers.
119  */
120  enum RlFlags
121  {
122  FlagTabNoMods = 0x0000, ///< no TAB modifiers
123  FlagTabNoDefault = 0x0001, ///< no default TAB completion match
124  FlagTabNoFilename = 0x0002, ///< no filename TAB completion attempt
125  FlagTabNoSpace = 0x0004 ///< no space(' ') after TAB completion
126  };
127 
128  /*!
129  * \brief Application-specific TAB completion generator function type.
130  *
131  * The generator is called multiple times on a TAB completion event.
132  * The call is made through the readline library rl_completion_matches()
133  * C function. On the first call, nState equals ReadLine::FIRST. This
134  * allows for any necessary initaliazation of (static) application
135  * specific state variables. On subsequent calls, nState \h_gt 0.
136  *
137  * For each matched candidate, a malloc'd string must be returned. The
138  * readline library automatically frees the memory allocation after use.
139  *
140  * When all candidates are exhausted, return NULL to signal no more
141  * matches to the readline library calling function.
142  *
143  * ReadLine Support Methods:
144  * - ReadLine::dupstr() - string allocation.
145  * - ReadLine::tokenize() - simple, whitespace token generator.
146  * - ReadLine::wc() count whitespace separated words.
147  *
148  * \param pAppArg Generator function argument.
149  * \param strText Partial text string to complete.
150  * \param nState Generator state. If FIRST(0), initialize any
151  * state statics.
152  * \param strContext Generator context (i.e. stripped input buffer).
153  *
154  * \return
155  * If a first/next match is made, return allocated completed match.\n
156  * Otherwise return NULL.
157  */
158  typedef char *(*AppGenFunc)(void *pAppArg,
159  const std::string &strText,
160  int nState,
161  const std::string &strContext);
162 
163  /*!
164  * \brief Alternative application-specific TAB completion generator
165  * function type.
166  *
167  * This is a somewhat more powerful TAB completion function that remains
168  * entirely in C++. The calling function is ReadLine::completion()
169  * which, in turn, is called by the readline library through the
170  * set rl_attempted_completion_function variable.
171  *
172  * The generator is called multiple times on a TAB completion event.
173  * On the first call, nIndex is equal to 0. Subsequent calls, nIndex is
174  * incremented by one. The function may safely use this index to sequence
175  * through any application-specific data.
176  *
177  * Return Values:
178  * -# match: Any non-empty, non-whitespace string.
179  * -# empty: An empty string "" terminates TAB completion generation.
180  * RlTabEnd is equivalent to the empty string.
181  *
182  * Tab Modifier Flags:
183  * - FlagTabNoDefault:
184  * If this flag is set at index 0 and a match is returned, then
185  * a "no default" readline library value will be set. Otherwise the
186  * this first match is the default.
187  * - FlagTabNoFilename:
188  * If this flag is set at the end of TAB completion (an empty string
189  * is returned), then readline library default filename completion
190  * action is disabled. (See rl_attempted_completion_over.)
191  * The readline library default action is only invoked if no strings
192  * are generated.
193  *
194  * Flags only apply to the current TAB completion event and are reset
195  * to defaults there after.
196  *
197  * ReadLine Support Methods: \ref See AppGenFunc.
198  *
199  * \param pAppArg Generator function argument.
200  * \param strText Partial text string to complete.
201  * \param nIndex Match candidate index starting from 0.
202  * \param strContext Generator context (i.e. input buffer).
203  * \param nStart Starting index in context of text.
204  * \param nEnd Ending index in context of the position
205  * immediately after the end of text. If nStart
206  * equals nEnd, then empty text.
207  * \param [out] uFlags TAB completion modifier flags.
208  *
209  * \return Match or empty string.
210  */
211  typedef const std::string (*AltAppGenFunc)(void *pAppArg,
212  const std::string &strText,
213  int nIndex,
214  const std::string &strContext,
215  int nStart,
216  int nEnd,
217  unsigned &uFlags);
218 
219  /*!
220  * \brief Default initialization constructor.
221  *
222  * \param strName Name of readline. Used to allow for conditional
223  * parsing of the ~/.inputrc file.
224  * \param strPrompt Command line primary prompt string. Prompting occurs
225  * only in interactive mode.
226  * \param bUseRlLib Use the readline library. Note that readline must
227  * be available and the input is interactive. Otherwise
228  * a simple command-line interface will be used.
229  */
230  ReadLine(const std::string strName = "",
231  const std::string strPrompt = "> ",
232  bool bUseRlLib = true);
233 
234  /*!
235  * \brief Destructor.
236  */
237  virtual ~ReadLine();
238 
239  /*!
240  * \brief Register application-specific tab-completion generator.
241  *
242  * The registered function will be called through the readline library
243  * rl_completion_matches() C function.
244  *
245  * \param fnAppGen Application-specific generator function.
246  * \param pAppArg Optional application argument generator function.
247  */
248  void registerGenerator(AppGenFunc fnAppGen, void *pAppArg);
249 
250  /*!
251  * \brief Register alternate application-specific tab-completion
252  * generator.
253  *
254  * The registered function will be called through the
255  * ReadLine::completion C++ method.
256  *
257  * \param fnAltAppGen Alt application-specific generator function.
258  * \param pAppArg Optional application argument generator function.
259  */
260  void registerAltGenerator(AltAppGenFunc fnAltAppGen, void *pAppArg);
261 
262  /*!
263  * \brief Unregister application-specific generator associated with path.
264  */
265  void unregisterGenerator();
266 
267  /*!
268  * \brief Interactively read a line of input from standard input (stdin).
269  *
270  * The readline library function readline() will be called iff:
271  * - The readline library is available (HAVE_READLINE).
272  * - The application enabled the ReadLine instance to use the readline.
273  * - library (bUseRlLib).
274  * - The input stdin is interactive (i.e. bound to a terminal or tty).
275  *
276  * Otherwise, ireadLine() is used.
277  *
278  * The readline() library call enables TAB completion, line editing, and
279  * history recording/recall.
280  *
281  * If in interactive mode, the user will be prompted with the current
282  * prompt string. Any prompt is written to standard output (stdout).
283  *
284  * \return
285  * Returns the string of the line read, stripped of leading and trailing
286  * whitespace. If the string is empty, then one of:
287  * - The line was all whitespace.
288  * - EOF was reached. Use \ref isEoF() to test this condition.
289  * - A file read error occurred. Use \ref isFError() to test this
290  * conition.
291  */
292  std::string &rlreadLine();
293 
294  /*!
295  * \brief Interactively read a line of input from standard input (stdin).
296  *
297  * The readline library is not used.
298  *
299  * If in interactive mode, the user will be prompted with the currently
300  * set prompt string. Any prompt is written to standard output (stdout).
301  *
302  * \note The \ref rlreadLine() call is the preferred method since it
303  * automatically determines the best underlining function/method to call.
304  *
305  * \return
306  * Returns the string of the line read, stripped of leading and trailing
307  * whitespace. If the string is empty, then one of:
308  * - The line was all whitespace.
309  * - EOF was reached. Use \ref isEoF() to test this condition.
310  * - A file read error occurred. Use \ref isFError() to test this
311  * conition.
312  */
313  std::string &ireadLine()
314  {
315  return ireadLine(stdin);
316  }
317 
318  /*!
319  * \brief Interactively read a line of input from an input stream.
320  *
321  * The readline library is not used.
322  *
323  * If in interactive mode, the user will be prompted with the currently
324  * set prompt string. Any prompt is written to standard output (stdout).
325  *
326  * \param fp Input file stream pointer.
327  *
328  * \return
329  * Returns the string of the line read, stripped of leading and trailing
330  * whitespace. If the string is empty, then one of:
331  * - The line was all whitespace.
332  * - EOF was reached. Use \ref isEoF() to test this condition.
333  * - A file read error occurred. Use \ref isFError() to test this
334  * conition.
335  */
336  std::string &ireadLine(FILE *fp);
337 
338  /*!
339  * \brief Read one input line from the given input stream.
340  *
341  * The input stream may be attached to a terminal, pipe, or file. No
342  * prompting will occur.
343  *
344  * \param fp Input file stream pointer.
345  *
346  * \return
347  * Returns the string of the line read, stripped of leading and trailing
348  * whitespace. If the string is empty, then one of:
349  * - The line was all whitespace.
350  * - EOF was reached. Use \ref isEoF() to test this condition.
351  * - A file read error occurred. Use \ref isFError() to test this
352  * conition.
353  */
354  std::string &freadLine(FILE *fp);
355 
356  /*
357  * \brief Add input to readline history.
358  *
359  * The line is added if the line is not empty and does not match the last
360  * command.
361  *
362  * \param strLine Input line to add.
363  */
364  void addToHistory(const std::string &strLine);
365 
366  /*!
367  * \brief Get this instance of readline name.
368  */
369  const std::string &getName() const
370  {
371  return m_strName;
372  }
373 
374  /*!
375  * \brief Test if have readline library.
376  *
377  * \return Returns true or false.
378  */
379  bool haveRlLib() const
380  {
381 #ifdef HAVE_READLINE
382  return true;
383 #else // !HAVE_READLINE
384  return false;
385 #endif // HAVE_READLINE
386  }
387 
388  /*!
389  * \brief Test if the readline library is enabled.
390  *
391  * \return Returns true or false.
392  */
393  bool useRlLib() const
394  {
395  return m_bUseRlLib;
396  }
397 
398  /*!
399  * \brief Test if input file pointer is interactive.
400  *
401  * A file input stream is interactive if it is bound to a terminal or
402  * tty.
403  *
404  * \return Returns true or false.
405  */
406  bool isInteractive(FILE *fp);
407 
408  /*!
409  * \brief Set the prompt string.
410  *
411  * \param strPrompt New prompt string.
412  */
413  void setPrompt(const std::string &strPrompt)
414  {
415  m_strPrompt = strPrompt;
416  }
417 
418  /*!
419  * \brief Get the current prompt string.
420  *
421  * \return String.
422  */
423  const std::string &getPrompt() const
424  {
425  return m_strPrompt;
426  }
427 
428  /*!
429  * \brief Get last read line.
430  *
431  * \return String.
432  */
433  const std::string &getLastRead() const
434  {
435  return m_strLine;
436  }
437 
438  /*!
439  * \brief Get the line number of the last read line.
440  *
441  * \return Line number.
442  */
443  size_t getLineNum() const
444  {
445  return m_uLineNum;
446  }
447 
448  /*!
449  * \brief Set the current line number.
450  *
451  * \param Line number.
452  */
453  void setLineNum(const size_t uLineNum)
454  {
455  m_uLineNum = uLineNum;
456  }
457 
458  /*!
459  * \brief Reset the line number to zero.
460  */
462  {
463  m_uLineNum = 0;
464  }
465 
466  /*!
467  * \brief Test if the last read operation resulted in an end-of-file
468  * condition.
469  *
470  * \return Returns true or false.
471  */
472  bool isEoF() const
473  {
474  return m_bEoF;
475  }
476 
477  /*!
478  * \brief Test if the last read operation resulted in an I/O error
479  * condition.
480  *
481  * \return Returns true or false.
482  */
483  bool isFError() const
484  {
485  return m_bFError;
486  }
487 
488  /*!
489  * \brief Get the most recently set error string.
490  *
491  * \return Error string.
492  */
493  const std::string &getErrorStr() const;
494 
495 
496  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
497  // Built-In Tab Completion Generators
498  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
499 
500  /*!
501  * \brief Filename TAB completion generator.
502  *
503  * A completion generator for filenames.
504  *
505  * \param sText Partial text string to complete.
506  * \param nState Generator state. If FIRST,then initialize any statics.
507  *
508  * \return
509  * If a first/next match is made, return allocated completed match.\n
510  * Otherwise return NULL.
511  */
512  static char *filenameCompletionGenerator(const char *sText, int nState)
513  {
514  #ifdef HAVE_READLINE
515  return rl_filename_completion_function(sText, nState);
516  #else // !HAVE_READLINE
517  return NULL;
518  #endif // HAVE_READLINE
519  }
520 
521  /*!
522  * \brief Username TAB completion generator.
523  *
524  * A completion generator for usernames.
525  *
526  * \param sText Partial text string to complete.
527  * \param nState Generator state. If FIRST,then initialize any statics.
528  *
529  * \return
530  * If a first/next match is made, return allocated completed match.\n
531  * Otherwise return NULL.
532  */
533  static char *usernameCompletionGenerator(const char *sText, int nState)
534  {
535  #ifdef HAVE_READLINE
536  return rl_username_completion_function(sText, nState);
537  #else // !HAVE_READLINE
538  return NULL;
539  #endif // HAVE_READLINE
540  }
541 
542 
543  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
544  // Utilities
545  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
546 
547  /*!
548  * \brief Duplicate string.
549  *
550  * The readline library requires allocated char*'s.
551  *
552  * \param str String to dup.
553  *
554  * \return Duplicated, allocated char*.
555  */
556  static char *dupstr(const std::string &str)
557  {
558  return ReadLine::dupstr(str.c_str());
559  }
560 
561  /*!
562  * \brief Duplicate string.
563  *
564  * The readline library requires allocated char*'s.
565  *
566  * \param s Null-terminated string to dup.
567  *
568  * \return Duplicated, allocated char *.
569  */
570  static char *dupstr(const char *s);
571 
572  /*!
573  * \brief Tokenize the given string.
574  *
575  * Tokens are contiguous non-whitespace character sequences, separated by
576  * either the start-of-string, whitespace, or the end-of-string.
577  *
578  * \param [in] str Input string to generate tokens.
579  * \param [out] tokens Vector of tokens.
580  *
581  * \return Number of tokens.
582  */
583  static size_t tokenize(const std::string &str, str::StringVec &tokens);
584 
585  /*!
586  * \brief In-place string tokenizer.
587  *
588  * Tokens are contiguous non-whitespace character sequences, separated by
589  * either the start-of-string, whitespace, or the end-of-string.
590  *
591  * The '\0' character is inserted at the end of each detected word in s.
592  * No memory allocation is used.
593  *
594  * \param [in,out] s Input/output null-terminated string to tokenize.
595  * \param [out] tokv Array of tokens (pointer to locations in s).
596  * \param [in] tokmax Maximum number of tokens.
597  *
598  * \return Number of tokens.
599  */
600  size_t tokenize(char *s, char *tokv[], size_t tokmax);
601 
602  /*!
603  * \brief Count the words in the string.
604  *
605  * \param str String to count.
606  *
607  * \return Number of words.
608  */
609  static int wc(const std::string &str)
610  {
611  return ReadLine::wc(str.c_str());
612  }
613 
614  /*!
615  * \brief Count the words in the string.
616  *
617  * \param s Null-terminated string to count.
618  *
619  * \return Number of words.
620  */
621  static int wc(const char *s);
622 
623  protected:
624  static ReadLine *ThisObj; ///< static pointer to this single instance
625 
626  std::string m_strName; ///< readline name
627  std::string m_strPrompt; ///< prompt string
628  bool m_bUseRlLib; ///< [do not] use readline library
629  std::string m_strLine; ///< last read line
630  size_t m_uLineNum; ///< line number
631  bool m_bEoF; ///< last file op end of file condition
632  bool m_bFError; ///< last file op file error condition
633  std::string m_strError; ///< error string
634  AppGenFunc m_fnAppGen; ///< application-specific generator
635  AltAppGenFunc m_fnAltAppGen;///< alternate app-specific generator
636  void *m_pAppArg; ///< application-specific argument
637 
638  /*!
639  * \brief Command completion callback function wrapper.
640  *
641  * Wraps method ReadLine::completion().
642  *
643  * \param sText Text string to complete as a command.
644  * \param nStart Start index of text string in line.
645  * \param nEnd End index of text string in line.
646  *
647  * \return Array of matches, NULL if none.
648  */
649  static char **completionWrapper(const char *sText, int nStart, int nEnd);
650 
651  /*!
652  * \brief Command completion callback function.
653  *
654  * Attempt to complete on the contents of text. The start and end bound
655  * the region of rl_line_buffer that contains the word to complete. Text
656  * is the word to complete. We can use the entire contents of
657  * rl_line_buffer to provide context.
658  *
659  * \param sText Text string to complete as a command.
660  * \param nStart Start index of text string in line.
661  * \param nEnd End index of text string in line.
662  *
663  * \return Array of matches, NULL if none.
664  */
665  char **completion(const char *sText, int nStart, int nEnd);
666 
667  /*!
668  * \brief Command completion callback function.
669  *
670  * If an alternative application-specific generator is registered, this
671  * method is used to provide the requisite C++ interface.
672  *
673  * Attempt to complete on the contents of text. The start and end bound
674  * the region of rl_line_buffer that contains the word to complete. Text
675  * is the word to complete. We can use the entire contents of
676  * rl_line_buffer to provide context.
677  *
678  * This method also provides the indexing for the registered generator.
679  *
680  * \param sText Text string to complete as a command.
681  * \param nStart Start index of text string in line.
682  * \param nEnd End index of text string in line.
683  *
684  * \return Array of matches, NULL if none.
685  */
686  char **altCompletion(const std::string strText, int nStart, int nEnd);
687 
688  /*!
689  * \brief Generator wrapper.
690  *
691  * Calls the registered application-specific generator.
692  *
693  * \param sText Partial text string to complete.
694  * \param nState Generator state. If FIRST,then initialize any statics.
695  *
696  * \return
697  * If a first/next match is made, return allocated completed match.\n
698  * Otherwise return NULL.
699  */
700  static char *generatorWrapper(const char *sText, int nState);
701 
702  /*!
703  * \brief Set stream status for the last read operation.
704  *
705  * \param fp Input file pointer.
706  */
707  void setStreamStatus(FILE *fp);
708 
709  /*!
710  * \brief Clear stream status prior to next read operation.
711  */
712  void clearStreamStatus();
713  };
714 
715  } // namespace cmd
716 } // namespace rnr
717 
718 
719 #endif // _RNR_READ_LINE_H
bool m_bFError
last file op file error condition
Definition: ReadLine.h:632
std::string m_strError
error string
Definition: ReadLine.h:633
void setLineNum(const size_t uLineNum)
Set the current line number.
Definition: ReadLine.h:453
std::string m_strName
readline name
Definition: ReadLine.h:626
no filename TAB completion attempt
Definition: ReadLine.h:124
RlFlags
ReadLine flag modifiers.
Definition: ReadLine.h:120
std::vector< std::string > StringVec
Useful types.
Definition: StringTheory.h:83
std::string & rlreadLine()
Interactively read a line of input from standard input (stdin).
Definition: ReadLine.cxx:174
static char ** completionWrapper(const char *sText, int nStart, int nEnd)
Command completion callback function wrapper.
Definition: ReadLine.cxx:471
size_t getLineNum() const
Get the line number of the last read line.
Definition: ReadLine.h:443
void clearStreamStatus()
Clear stream status prior to next read operation.
Definition: ReadLine.cxx:349
AppGenFunc m_fnAppGen
application-specific generator
Definition: ReadLine.h:634
char *(* AppGenFunc)(void *pAppArg, const std::string &strText, int nState, const std::string &strContext)
Application-specific TAB completion generator function type.
Definition: ReadLine.h:158
void registerAltGenerator(AltAppGenFunc fnAltAppGen, void *pAppArg)
Register alternate application-specific tab-completion generator.
Definition: ReadLine.cxx:155
const std::string & getLastRead() const
Get last read line.
Definition: ReadLine.h:433
std::string m_strPrompt
prompt string
Definition: ReadLine.h:627
bool m_bUseRlLib
[do not] use readline library
Definition: ReadLine.h:628
no space(&#39; &#39;) after TAB completion
Definition: ReadLine.h:125
bool haveRlLib() const
Test if have readline library.
Definition: ReadLine.h:379
Of string spaces and their strangian operators.
const std::string & getPrompt() const
Get the current prompt string.
Definition: ReadLine.h:423
static int wc(const std::string &str)
Count the words in the string.
Definition: ReadLine.h:609
bool m_bEoF
last file op end of file condition
Definition: ReadLine.h:631
char ** altCompletion(const std::string strText, int nStart, int nEnd)
Command completion callback function.
Definition: ReadLine.cxx:493
static size_t tokenize(const std::string &str, str::StringVec &tokens)
Tokenize the given string.
static const int FIRST
first state
Definition: ReadLine.h:115
void * m_pAppArg
application-specific argument
Definition: ReadLine.h:636
void setStreamStatus(FILE *fp)
Set stream status for the last read operation.
Definition: ReadLine.cxx:327
std::string & freadLine(FILE *fp)
Read one input line from the given input stream.
Definition: ReadLine.cxx:239
static char * generatorWrapper(const char *sText, int nState)
Generator wrapper.
Definition: ReadLine.cxx:574
bool isInteractive(FILE *fp)
Test if input file pointer is interactive.
Definition: ReadLine.cxx:317
virtual ~ReadLine()
Destructor.
Definition: ReadLine.cxx:143
void resetLineNum()
Reset the line number to zero.
Definition: ReadLine.h:461
char ** completion(const char *sText, int nStart, int nEnd)
Command completion callback function.
Definition: ReadLine.cxx:476
const std::string & getName() const
Get this instance of readline name.
Definition: ReadLine.h:369
size_t m_uLineNum
line number
Definition: ReadLine.h:630
bool useRlLib() const
Test if the readline library is enabled.
Definition: ReadLine.h:393
ReadLine class provides a C++ wrapper around the readline C library.
Definition: ReadLine.h:112
bool isFError() const
Test if the last read operation resulted in an I/O error condition.
Definition: ReadLine.h:483
const std::string(* AltAppGenFunc)(void *pAppArg, const std::string &strText, int nIndex, const std::string &strContext, int nStart, int nEnd, unsigned &uFlags)
Alternative application-specific TAB completion generator function type.
Definition: ReadLine.h:211
static const char * RlTabEnd
no more matches value (empty string)
Definition: ReadLine.h:94
static char * usernameCompletionGenerator(const char *sText, int nState)
Username TAB completion generator.
Definition: ReadLine.h:533
no default TAB completion match
Definition: ReadLine.h:123
ReadLine(const std::string strName="", const std::string strPrompt="> ", bool bUseRlLib=true)
Default initialization constructor.
Definition: ReadLine.cxx:111
void registerGenerator(AppGenFunc fnAppGen, void *pAppArg)
Register application-specific tab-completion generator.
Definition: ReadLine.cxx:148
AltAppGenFunc m_fnAltAppGen
alternate app-specific generator
Definition: ReadLine.h:635
void setPrompt(const std::string &strPrompt)
Set the prompt string.
Definition: ReadLine.h:413
std::string & ireadLine()
Interactively read a line of input from standard input (stdin).
Definition: ReadLine.h:313
static ReadLine * ThisObj
static pointer to this single instance
Definition: ReadLine.h:624
static char * dupstr(const std::string &str)
Duplicate string.
Definition: ReadLine.h:556
bool isEoF() const
Test if the last read operation resulted in an end-of-file condition.
Definition: ReadLine.h:472
void unregisterGenerator()
Unregister application-specific generator associated with path.
Definition: ReadLine.cxx:162
RoadNarrows Robotics.
Definition: Camera.h:74
static char * filenameCompletionGenerator(const char *sText, int nState)
Filename TAB completion generator.
Definition: ReadLine.h:512
std::string m_strLine
last read line
Definition: ReadLine.h:629
const std::string & getErrorStr() const
Get the most recently set error string.
Definition: ReadLine.cxx:322