StdAir Logo  1.00.0
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
readline_autocomp.hpp File Reference
#include <string>
#include <iosfwd>
#include <cstdio>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include <readline/readline.h>
#include <readline/history.h>

Go to the source code of this file.


struct  COMMAND


typedef int(* pt2Func )(char *)


char * getwd ()
char * xmalloc (size_t)
int com_list (char *)
int com_view (char *)
int com_rename (char *)
int com_stat (char *)
int com_pwd (char *)
int com_delete (char *)
int com_help (char *)
int com_cd (char *)
int com_quit (char *)
char * stripwhite (char *iString)
COMMANDfind_command (char *iString)
char * dupstr (char *iString)
int execute_line (char *line)
char * command_generator (char *text, int state)
char ** fileman_completion (char *text, int start, int end)
void initialize_readline ()
void too_dangerous (char *caller)
int valid_argument (char *caller, char *arg)


COMMAND commands []
int done
static char syscom [1024]

Typedef Documentation

typedef int(* pt2Func)(char *)

Definition at line 35 of file readline_autocomp.hpp.

Function Documentation

char* getwd ( )

readline_autocomp.hpp – A tiny application which demonstrates how to use the GNU Readline library. This application interactively allows users to manipulate files and their modes.

Referenced by com_pwd().

char* xmalloc ( size_t  )

Referenced by dupstr().

void com_list ( char *  arg)

List the file(s) named in arg.

Definition at line 264 of file readline_autocomp.hpp.

int com_view ( char *  arg)

Definition at line 274 of file readline_autocomp.hpp.

References valid_argument().

int com_rename ( char *  arg)

Definition at line 284 of file readline_autocomp.hpp.

References too_dangerous().

int com_stat ( char *  arg)

Definition at line 289 of file readline_autocomp.hpp.

References valid_argument().

int com_pwd ( char *  ignore)

Definition at line 367 of file readline_autocomp.hpp.

References getwd().

Referenced by com_cd().

int com_delete ( char *  arg)

Definition at line 315 of file readline_autocomp.hpp.

References too_dangerous().

int com_help ( char *  arg)

Print out help for ARG, or for all of the commands if ARG is not present.

Definition at line 324 of file readline_autocomp.hpp.

References COMMAND::name.

int com_cd ( char *  arg)

Definition at line 356 of file readline_autocomp.hpp.

References com_pwd().

int com_quit ( char *  arg)

Definition at line 381 of file readline_autocomp.hpp.

char * stripwhite ( char *  string)

Strip whitespace from the start and end of STRING. Return a pointer into STRING.

Definition at line 152 of file readline_autocomp.hpp.

COMMAND * find_command ( char *  name)

Look up NAME as the name of a command, and return a pointer to that command. Return a NULL pointer if NAME isn't a command name.

Definition at line 136 of file readline_autocomp.hpp.

References COMMAND::name.

Referenced by execute_line().

char* dupstr ( char *  iString)

Duplicate a string

Definition at line 85 of file readline_autocomp.hpp.

References xmalloc().

Referenced by command_generator().

int execute_line ( char *  line)

Execute a command line.

Definition at line 94 of file readline_autocomp.hpp.

References find_command(), and COMMAND::func.

char * command_generator ( char *  text,
int  state 

Generator function for command completion. STATE lets us know whether to start from scratch; without any state (i.e. STATE == 0), then we start at the top of the list.

Definition at line 222 of file readline_autocomp.hpp.

References dupstr().

Referenced by fileman_completion().

char ** fileman_completion ( char *  text,
int  start,
int  end 

Attempt to complete on the contents of TEXT. START and END bound the region of rl_line_buffer that contains the word to complete. TEXT is the word to complete. We can use the entire contents of rl_line_buffer in case we want to do some simple parsing. Return the array of matches, or NULL if there aren't any.

Definition at line 200 of file readline_autocomp.hpp.

References command_generator().

Referenced by initialize_readline().

void initialize_readline ( )

Tell the GNU Readline library how to complete. We want to try to complete on command names if this is the first word in the line, or on filenames if not.

Definition at line 185 of file readline_autocomp.hpp.

References fileman_completion().

void too_dangerous ( char *  caller)

Definition at line 387 of file readline_autocomp.hpp.

Referenced by com_delete(), and com_rename().

int valid_argument ( char *  caller,
char *  arg 

Definition at line 395 of file readline_autocomp.hpp.

Referenced by com_stat(), and com_view().

Variable Documentation

COMMAND commands[]
Initial value:
{ "cd", (*com_cd)(), "Change to directory DIR" },
{ "delete", com_delete, "Delete FILE" },
{ "help", com_help, "Display this text" },
{ "?", com_help, "Synonym for `help'" },
{ "list", com_list, "List files in DIR" },
{ "ls", com_list, "Synonym for `list'" },
{ "pwd", com_pwd, "Print the current working directory" },
{ "quit", com_quit, "Quit using airinv" },
{ "rename", com_rename, "Rename FILE to NEWNAME" },
{ "stat", com_stat, "Print out statistics on FILE" },
{ "view", com_view, "View the contents of FILE" },
{ (char*) NULL, (pt2Func) NULL, (char*) NULL }

Definition at line 58 of file readline_autocomp.hpp.

int done

When non-zero, this global means the user is done using this program.

Definition at line 80 of file readline_autocomp.hpp.

char syscom[1024]

String to pass to system(). This is for the LIST, VIEW and RENAME commands.

Definition at line 259 of file readline_autocomp.hpp.