6 #ifndef __AIRINV_READLINE_AUTOCOMP_HPP
7 #define __AIRINV_READLINE_AUTOCOMP_HPP
13 #include <sys/types.h>
16 #include <sys/errno.h>
18 #include <readline/readline.h>
19 #include <readline/history.h>
59 {
"cd", (*com_cd)(),
"Change to directory DIR" },
61 {
"help",
com_help,
"Display this text" },
62 {
"?",
com_help,
"Synonym for `help'" },
63 {
"list",
com_list,
"List files in DIR" },
64 {
"ls",
com_list,
"Synonym for `list'" },
65 {
"pwd",
com_pwd,
"Print the current working directory" },
66 {
"quit",
com_quit,
"Quit using airinv" },
67 {
"rename",
com_rename,
"Rename FILE to NEWNAME" },
68 {
"stat",
com_stat,
"Print out statistics on FILE" },
69 {
"view",
com_view,
"View the contents of FILE" },
70 { (
char*) NULL, (
pt2Func) NULL, (
char*) NULL }
86 char* r =
xmalloc (std::strlen (iString) + 1);
101 while (line[i] && whitespace (line[i])) {
106 while (line[i] && !whitespace (line[i])) {
117 std::cerr << word <<
": No such command for airinv." << std::endl;
122 while (whitespace (line[i])) {
129 return (*(command->
func)) (word);
139 for (i = 0; commands[i].
name; i++) {
140 if (strcmp (name, commands[i].name) == 0) {
141 return (&commands[i]);
153 register char *s, *t;
155 for (s =
string; whitespace (*s); s++) {
162 t = s + strlen (s) - 1;
163 while (t > s && whitespace (*t)) {
187 rl_readline_name =
"airinv";
203 matches = (
char**) NULL;
223 static int list_index, len;
237 while (name = commands[list_index].name) {
240 if (strncmp (name, text, len) == 0) {
269 std::ostringstream oStr;
270 oStr <<
"ls -FClg " << arg;
271 return system (oStr.c_str());
279 std::ostringstream oStr;
280 oStr <<
"more " << arg;
281 return system (syscom);
296 if (stat (arg, &finfo) == -1) {
301 std::cout <<
"Statistics for `" << arg <<
"':" << std::endl;
303 const std::string lPluralEnd1 = (finfo.st_nlink == 1) ?
"" :
"s";
304 const std::string lPluralEnd2 = (finfo.st_size == 1) ?
"" :
"s";
305 std::cout << arg <<
" has "
306 << finfo.st_nlink <<
" link" << lPluralEnd1 <<
", and is "
307 << finfo.st_size <<
" byte" << lPluralEnd2 <<
" in length."
309 std::cout <<
" Inode Last Change at: " << ctime (&finfo.st_ctime) << std::endl;
310 std::cout <<
" Last access at: " << ctime (&finfo.st_atime) << std::endl;
311 std::cout <<
" Last modified at: " << ctime (&finfo.st_mtime) << std::endl;
328 for (i = 0; commands[i].
name; i++) {
329 if (!*arg || (strcmp (arg, commands[i].name) == 0)) {
330 printf (
"%s\t\t%s.\n", commands[i].name, commands[i].doc);
336 printf (
"No commands match `%s'. Possibilties are:\n", arg);
338 for (i = 0; commands[i].
name; i++) {
345 printf (
"%s\t", commands[i].name);
357 if (chdir (arg) == -1) {
372 printf (
"Error getting pwd: %s\n", dir);
376 printf (
"Current directory is %s\n", dir);
389 "%s: Too dangerous for me to distribute. Write it yourself.\n",
397 fprintf (stderr,
"%s: Argument required.\n", caller);
404 #endif // _AIRINV_READLINE_AUTOCOMP_HPP
COMMAND * find_command(char *iString)
int execute_line(char *line)
int valid_argument(char *caller, char *arg)
void initialize_readline()
char ** fileman_completion(char *text, int start, int end)
char * dupstr(char *iString)
char * command_generator(char *text, int state)
void too_dangerous(char *caller)
char * stripwhite(char *iString)