1 @comment %**start of header (This is for running Texinfo on a region.)
2 @setfilename rltech.info
3 @comment %**end of header (This is for running Texinfo on a region.)
7 This document describes the GNU Readline Library, a utility for aiding
8 in the consitency of user interface across discrete programs that need
9 to provide a command line interface.
11 Copyright (C) 1988 Free Software Foundation, Inc.
13 Permission is granted to make and distribute verbatim copies of
14 this manual provided the copyright notice and this permission notice
15 pare preserved on all copies.
18 Permission is granted to process this file through TeX and print the
19 results, provided the printed document carries copying permission
20 notice identical to this one except for the removal of this paragraph
21 (this paragraph not being relevant to the printed manual).
24 Permission is granted to copy and distribute modified versions of this
25 manual under the conditions for verbatim copying, provided that the entire
26 resulting derived work is distributed under the terms of a permission
27 notice identical to this one.
29 Permission is granted to copy and distribute translations of this manual
30 into another language, under the above conditions for modified versions,
31 except that this permission notice may be stated in a translation approved
35 @node Programming with GNU Readline
36 @chapter Programming with GNU Readline
38 This manual describes the interface between the GNU Readline Library and
39 user programs. If you are a programmer, and you wish to include the
40 features found in GNU Readline in your own programs, such as completion,
41 line editing, and interactive history manipulation, this documentation
45 * Default Behaviour:: Using the default behaviour of Readline.
46 * Custom Functions:: Adding your own functions to Readline.
47 * Custom Completers:: Supplanting or supplementing Readline's
51 @node Default Behaviour
52 @section Default Behaviour
54 Many programs provide a command line interface, such as @code{mail},
55 @code{ftp}, and @code{sh}. For such programs, the default behaviour of
56 Readline is sufficient. This section describes how to use Readline in
57 the simplest way possible, perhaps to replace calls in your code to
61 @cindex readline, function
62 The function @code{readline} prints a prompt and then reads and returns
63 a single line of text from the user. The line which @code{readline ()}
64 returns is allocated with @code{malloc ()}; you should @code{free ()}
65 the line when you are done with it. The declaration for @code{readline}
69 @code{char *readline (char *@var{prompt});}
74 @code{char *line = readline ("Enter a line: ");}
76 in order to read a line of text from the user.
78 The line which is returned has the final newline removed, so only the
79 text of the line remains.
81 If readline encounters an @code{EOF} while reading the line, and the
82 line is empty at that point, then @code{(char *)NULL} is returned.
83 Otherwise, the line is ended just as if a newline was typed.
85 If you want the user to be able to get at the line later, (with
86 @key{C-p} for example), you must call @code{add_history ()} to save the
87 line away in a @dfn{history} list of such lines.
90 @code{add_history (line)};
93 For full details on the GNU History Library, see the associated manual.
95 It is polite to avoid saving empty lines on the history list, since it
96 is rare than someone has a burning need to reuse a blank line. Here is
97 a function which usefully replaces the standard @code{gets ()} library
101 /* A static variable for holding the line. */
102 static char *line_read = (char *)NULL;
104 /* Read a string, and return a pointer to it. Returns NULL on EOF. */
108 /* If the buffer has already been allocated, return the memory
110 if (line_read != (char *)NULL)
113 line_read = (char *)NULL;
116 /* Get a line from the user. */
117 line_read = readline ("");
119 /* If the line has any text in it, save it on the history. */
120 if (line_read && *line_read)
121 add_history (line_read);
127 The above code gives the user the default behaviour of @key{TAB}
128 completion: completion on file names. If you do not want readline to
129 complete on filenames, you can change the binding of the @key{TAB} key
130 with @code{rl_bind_key ()}.
132 @findex rl_bind_key ()
134 @code{int rl_bind_key (int @var{key}, int (*@var{function})());}
137 @code{rl_bind_key ()} takes 2 arguments; @var{key} is the character that
138 you want to bind, and @var{function} is the address of the function to
139 run when @var{key} is pressed. Binding @key{TAB} to @code{rl_insert ()}
140 makes @key{TAB} just insert itself.
142 @code{rl_bind_key ()} returns non-zero if @var{key} is not a valid
143 ASCII character code (between 0 and 255).
146 @code{rl_bind_key ('\t', rl_insert);}
149 This code should be executed once at the start of your program; you
150 might write a function called @code{initialize_readline ()} which
151 performs this and other desired initializations, such as installing
152 custom completers, etc.
154 @node Custom Functions
155 @section Custom Functions
157 Readline provides a great many functions for manipulating the text of
158 the line. But it isn't possible to anticipate the needs of all
159 programs. This section describes the various functions and variables
160 defined in within the Readline library which allow a user program to add
161 customized functionality to Readline.
164 * The Function Type:: C declarations to make code readable.
165 * Function Naming:: How to give a function you write a name.
166 * Keymaps:: Making keymaps.
167 * Binding Keys:: Changing Keymaps.
168 * Function Writing:: Variables and calling conventions.
169 * Allowing Undoing:: How to make your functions undoable.
172 @node The Function Type
173 @subsection The Function Type
175 For the sake of readabilty, we declare a new type of object, called
176 @dfn{Function}. A @code{Function} is a C language function which
177 returns an @code{int}. The type declaration for @code{Function} is:
180 @code{typedef int Function ();}
182 The reason for declaring this new type is to make it easier to write
183 code describing pointers to C functions. Let us say we had a variable
184 called @var{func} which was a pointer to a function. Instead of the
185 classic C declaration
187 @code{int (*)()func;}
191 @code{Function *func;}
193 @node Function Naming
194 @subsection Naming a Function
196 The user can dynamically change the bindings of keys while using
197 Readline. This is done by representing the function with a descriptive
198 name. The user is able to type the descriptive name when referring to
199 the function. Thus, in an init file, one might find
202 Meta-Rubout: backward-kill-word
205 This binds the keystroke @key{Meta-Rubout} to the function
206 @emph{descriptively} named @code{backward-kill-word}. You, as the
207 programmer, should bind the functions you write to descriptive names as
208 well. Readline provides a function for doing that:
210 @defun rl_add_defun (char *name, Function *function, int key)
211 Add @var{name} to the list of named functions. Make @var{function} be
212 the function that gets called. If @var{key} is not -1, then bind it to
213 @var{function} using @code{rl_bind_key ()}.
216 Using this function alone is sufficient for most applications. It is
217 the recommended way to add a few functions to the default functions that
218 Readline has built in already. If you need to do more or different
219 things than adding a function to Readline, you may need to use the
220 underlying functions described below.
223 @subsection Selecting a Keymap
225 Key bindings take place on a @dfn{keymap}. The keymap is the
226 association between the keys that the user types and the functions that
227 get run. You can make your own keymaps, copy existing keymaps, and tell
228 Readline which keymap to use.
230 @defun {Keymap rl_make_bare_keymap} ()
231 Returns a new, empty keymap. The space for the keymap is allocated with
232 @code{malloc ()}; you should @code{free ()} it when you are done.
235 @defun {Keymap rl_copy_keymap} (Keymap map)
236 Return a new keymap which is a copy of @var{map}.
239 @defun {Keymap rl_make_keymap} ()
240 Return a new keymap with the printing characters bound to rl_insert,
241 the lowercase Meta characters bound to run their equivalents, and
242 the Meta digits bound to produce numeric arguments.
246 @subsection Binding Keys
248 You associate keys with functions through the keymap. Here are
249 functions for doing that.
251 @defun {int rl_bind_key} (int key, Function *function)
252 Binds @var{key} to @var{function} in the currently selected keymap.
253 Returns non-zero in the case of an invalid @var{key}.
256 @defun {int rl_bind_key_in_map} (int key, Function *function, Keymap map)
257 Bind @var{key} to @var{function} in @var{map}. Returns non-zero in the case
258 of an invalid @var{key}.
261 @defun {int rl_unbind_key} (int key)
262 Make @var{key} do nothing in the currently selected keymap.
263 Returns non-zero in case of error.
266 @defun {int rl_unbind_key_in_map} (int key, Keymap map)
267 Make @var{key} be bound to the null function in @var{map}.
268 Returns non-zero in case of error.
271 @defun rl_generic_bind (int type, char *keyseq, char *data, Keymap map)
272 Bind the key sequence represented by the string @var{keyseq} to the arbitrary
273 pointer @var{data}. @var{type} says what kind of data is pointed to by
274 @var{data}; right now this can be a function (@code{ISFUNC}), a macro
275 (@code{ISMACR}), or a keymap (@code{ISKMAP}). This makes new keymaps as
276 necessary. The initial place to do bindings is in @var{map}.
279 @node Function Writing
280 @subsection Writing a New Function
282 In order to write new functions for Readline, you need to know the
283 calling conventions for keyboard invoked functions, and the names of the
284 variables that describe the current state of the line gathered so far.
286 @defvar {char *rl_line_buffer}
287 This is the line gathered so far. You are welcome to modify the
288 contents of this, but see Undoing, below.
291 @defvar {int rl_point}
292 The offset of the current cursor position in @var{rl_line_buffer}.
296 The number of characters present in @code{rl_line_buffer}. When
297 @code{rl_point} is at the end of the line, then @code{rl_point} and
298 @code{rl_end} are equal.
301 The calling sequence for a command @code{foo} looks like
304 @code{foo (int count, int key)}
307 where @var{count} is the numeric argument (or 1 if defaulted) and
308 @var{key} is the key that invoked this function.
310 It is completely up to the function as to what should be done with the
311 numeric argument; some functions use it as a repeat count, other
312 functions as a flag, and some choose to ignore it. In general, if a
313 function uses the numeric argument as a repeat count, it should be able
314 to do something useful with a negative argument as well as a positive
315 argument. At the very least, it should be aware that it can be passed a
318 @node Allowing Undoing
319 @subsection Allowing Undoing
321 Supporting the undo command is a painless thing to do, and makes your
322 functions much more useful to the end user. It is certainly easy to try
323 something if you know you can undo it. I could use an undo function for
326 If your function simply inserts text once, or deletes text once, and it
327 calls @code{rl_insert_text ()} or @code{rl_delete_text ()} to do it, then
328 undoing is already done for you automatically, and you can safely skip
331 If you do multiple insertions or multiple deletions, or any combination
332 of these operations, you should group them together into one operation.
333 This can be done with @code{rl_begin_undo_group ()} and
334 @code{rl_end_undo_group ()}.
336 @defun rl_begin_undo_group ()
337 Begins saving undo information in a group construct. The undo
338 information usually comes from calls to @code{rl_insert_text ()} and
339 @code{rl_delete_text ()}, but they could be direct calls to
340 @code{rl_add_undo ()}.
343 @defun rl_end_undo_group ()
344 Closes the current undo group started with @code{rl_begin_undo_group
345 ()}. There should be exactly one call to @code{rl_end_undo_group ()}
346 for every call to @code{rl_begin_undo_group ()}.
349 Finally, if you neither insert nor delete text, but directly modify the
350 existing text (e.g. change its case), you call @code{rl_modifying ()}
351 once, just before you modify the text. You must supply the indices of
352 the text range that you are going to modify.
354 @defun rl_modifying (int start, int end)
355 Tell Readline to save the text between @var{start} and @var{end} as a
356 single undo unit. It is assumed that subsequent to this call you will
357 modify that range of text in some way.
360 @subsection An Example
362 Here is a function which changes lowercase characters to the uppercase
363 equivalents, and uppercase characters to the lowercase equivalents. If
364 this function was bound to @samp{M-c}, then typing @samp{M-c} would
365 change the case of the character under point. Typing @samp{10 M-c}
366 would change the case of the following 10 characters, leaving the cursor on
367 the last character changed.
370 /* Invert the case of the COUNT following characters. */
371 invert_case_line (count, key)
374 register int start, end;
386 /* Find the end of the range to modify. */
387 end = start + (count * direction);
389 /* Force it to be within range. */
405 /* Tell readline that we are modifying the line, so save the undo
407 rl_modifying (start, end);
409 for (; start != end; start += direction)
411 if (uppercase_p (rl_line_buffer[start]))
412 rl_line_buffer[start] = to_lower (rl_line_buffer[start]);
413 else if (lowercase_p (rl_line_buffer[start]))
414 rl_line_buffer[start] = to_upper (rl_line_buffer[start]);
416 /* Move point to on top of the last character changed. */
417 rl_point = end - direction;
421 @node Custom Completers
422 @section Custom Completers
424 Typically, a program that reads commands from the user has a way of
425 disambiguating commands and data. If your program is one of these, then
426 it can provide completion for either commands, or data, or both commands
427 and data. The following sections describe how your program and Readline
428 cooperate to provide this service to end users.
431 * How Completing Works:: The logic used to do completion.
432 * Completion Functions:: Functions provided by Readline.
433 * Completion Variables:: Variables which control completion.
434 * A Short Completion Example:: An example of writing completer subroutines.
437 @node How Completing Works
438 @subsection How Completing Works
440 In order to complete some text, the full list of possible completions
441 must be available. That is to say, it is not possible to accurately
442 expand a partial word without knowing what all of the possible words
443 that make sense in that context are. The GNU Readline library provides
444 the user interface to completion, and additionally, two of the most common
445 completion functions; filename and username. For completing other types
446 of text, you must write your own completion function. This section
447 describes exactly what those functions must do, and provides an example
450 There are three major functions used to perform completion:
454 The user-interface function @code{rl_complete ()}. This function is
455 called interactively with the same calling conventions as other
456 functions in readline intended for interactive use; i.e. @var{count},
457 and @var{invoking-key}. It isolates the word to be completed and calls
458 @code{completion_matches ()} to generate a list of possible completions.
459 It then either lists the possible completions or actually performs the
460 completion, depending on which behaviour is desired.
463 The internal function @code{completion_matches ()} uses your
464 @dfn{generator} function to generate the list of possible matches, and
465 then returns the array of these matches. You should place the address
466 of your generator function in @code{rl_completion_entry_function}.
469 The generator function is called repeatedly from
470 @code{completion_matches ()}, returning a string each time. The
471 arguments to the generator function are @var{text} and @var{state}.
472 @var{text} is the partial word to be completed. @var{state} is zero the
473 first time the function is called, and a positive non-zero integer for
474 each subsequent call. When the generator function returns @code{(char
475 *)NULL} this signals @code{completion_matches ()} that there are no more
480 @defun rl_complete (int ignore, int invoking_key)
481 Complete the word at or before point. You have supplied the function
482 that does the initial simple matching selection algorithm (see
483 @code{completion_matches ()}). The default is to do filename completion.
486 Note that @code{rl_complete ()} has the identical calling conventions as
487 any other key-invokable function; this is because by default it is bound
488 to the @samp{TAB} key.
490 @defvar {Function *rl_completion_entry_function}
491 This is a pointer to the generator function for @code{completion_matches
492 ()}. If the value of @code{rl_completion_entry_function} is
493 @code{(Function *)NULL} then the default filename generator function is
494 used, namely @code{filename_entry_function ()}.
497 @node Completion Functions
498 @subsection Completion Functions
500 Here is the complete list of callable completion functions present in
503 @defun rl_complete_internal (int what_to_do)
504 Complete the word at or before point. @var{what_to_do} says what to do
505 with the completion. A value of @samp{?} means list the possible
506 completions. @samp{TAB} means do standard completion. @samp{*} means
507 insert all of the possible completions.
510 @defun rl_complete (int ignore, int invoking_key)
511 Complete the word at or before point. You have supplied the function
512 that does the initial simple matching selection algorithm (see
513 @code{completion_matches ()}). The default is to do filename
514 completion. This just calls @code{rl_complete_internal ()} with an
515 argument of @samp{TAB}.
518 @defun rl_possible_completions ()
519 List the possible completions. See description of @code{rl_complete
520 ()}. This just calls @code{rl_complete_internal ()} with an argument of
524 @defun {char **completion_matches} (char *text, char *(*entry_function) ())
525 Returns an array of @code{(char *)} which is a list of completions for
526 @var{text}. If there are no completions, returns @code{(char **)NULL}.
527 The first entry in the returned array is the substitution for @var{text}.
528 The remaining entries are the possible completions. The array is
529 terminated with a @code{NULL} pointer.
531 @var{entry_function} is a function of two args, and returns a
532 @code{(char *)}. The first argument is @var{text}. The second is a
533 state argument; it is zero on the first call, and non-zero on subsequent
534 calls. It returns a @code{NULL} pointer to the caller when there are
538 @defun {char *filename_completion_function} (char *text, int state)
539 A generator function for filename completion in the general case. Note
540 that completion in the Bash shell is a little different because of all
541 the pathnames that must be followed when looking up the completion for a
545 @defun {char *username_completion_function} (char *text, int state)
546 A completion generator for usernames. @var{text} contains a partial
547 username preceded by a random character (usually @samp{~}).
550 @node Completion Variables
551 @subsection Completion Variables
553 @defvar {Function *rl_completion_entry_function}
554 A pointer to the generator function for @code{completion_matches ()}.
555 @code{NULL} means to use @code{filename_entry_function ()}, the default
559 @defvar {Function *rl_attempted_completion_function}
560 A pointer to an alternative function to create matches.
561 The function is called with @var{text}, @var{start}, and @var{end}.
562 @var{start} and @var{end} are indices in @code{rl_line_buffer} saying
563 what the boundaries of @var{text} are. If this function exists and
564 returns @code{NULL} then @code{rl_complete ()} will call the value of
565 @code{rl_completion_entry_function} to generate matches, otherwise the
566 array of strings returned will be used.
569 @defvar {int rl_completion_query_items}
570 Up to this many items will be displayed in response to a
571 possible-completions call. After that, we ask the user if she is sure
572 she wants to see them all. The default value is 100.
575 @defvar {char *rl_basic_word_break_characters}
576 The basic list of characters that signal a break between words for the
577 completer routine. The contents of this variable is what breaks words
578 in the Bash shell, i.e. " \t\n\"\\'`@@$><=;|&@{(".
581 @defvar {char *rl_completer_word_break_characters}
582 The list of characters that signal a break between words for
583 @code{rl_complete_internal ()}. The default list is the contents of
584 @code{rl_basic_word_break_characters}.
587 @defvar {char *rl_special_prefixes}
588 The list of characters that are word break characters, but should be
589 left in @var{text} when it is passed to the completion function.
590 Programs can use this to help determine what kind of completing to do.
593 @defvar {int rl_ignore_completion_duplicates}
594 If non-zero, then disallow duplicates in the matches. Default is 1.
597 @defvar {int rl_filename_completion_desired}
598 Non-zero means that the results of the matches are to be treated as
599 filenames. This is @emph{always} zero on entry, and can only be changed
600 within a completion entry generator function.
603 @defvar {Function *rl_ignore_some_completions_function}
604 This function, if defined, is called by the completer when real filename
605 completion is done, after all the matching names have been generated.
606 It is passed a @code{NULL} terminated array of @code{(char *)} known as
607 @var{matches} in the code. The 1st element (@code{matches[0]}) is the
608 maximal substring that is common to all matches. This function can
609 re-arrange the list of matches as required, but each deleted element of
610 the array must be @code{free()}'d.
613 @node A Short Completion Example
614 @subsection A Short Completion Example
616 Here is a small application demonstrating the use of the GNU Readline
617 library. It is called @code{fileman}, and the source code resides in
618 @file{readline/examples/fileman.c}. This sample application provides
619 completion of command names, line editing features, and access to the
624 /* fileman.c -- A tiny application which demonstrates how to use the
625 GNU Readline library. This application interactively allows users
626 to manipulate files and their modes. */
629 #include <readline/readline.h>
630 #include <readline/history.h>
631 #include <sys/types.h>
632 #include <sys/file.h>
633 #include <sys/stat.h>
634 #include <sys/errno.h>
636 /* The names of functions that actually do the manipulation. */
637 int com_list (), com_view (), com_rename (), com_stat (), com_pwd ();
638 int com_delete (), com_help (), com_cd (), com_quit ();
640 /* A structure which contains information on the commands this program
644 char *name; /* User printable name of the function. */
645 Function *func; /* Function to call to do the job. */
646 char *doc; /* Documentation for this function. */
649 COMMAND commands[] = @{
650 @{ "cd", com_cd, "Change to directory DIR" @},
651 @{ "delete", com_delete, "Delete FILE" @},
652 @{ "help", com_help, "Display this text" @},
653 @{ "?", com_help, "Synonym for `help'" @},
654 @{ "list", com_list, "List files in DIR" @},
655 @{ "ls", com_list, "Synonym for `list'" @},
656 @{ "pwd", com_pwd, "Print the current working directory" @},
657 @{ "quit", com_quit, "Quit using Fileman" @},
658 @{ "rename", com_rename, "Rename FILE to NEWNAME" @},
659 @{ "stat", com_stat, "Print out statistics on FILE" @},
660 @{ "view", com_view, "View the contents of FILE" @},
661 @{ (char *)NULL, (Function *)NULL, (char *)NULL @}
664 /* The name of this program, as taken from argv[0]. */
667 /* When non-zero, this global means the user is done using this program. */
676 initialize_readline (); /* Bind our completer. */
678 /* Loop reading and executing lines until the user quits. */
683 line = readline ("FileMan: ");
687 done = 1; /* Encountered EOF at top level. */
691 /* Remove leading and trailing whitespace from the line.
692 Then, if there is anything left, add it to the history list
709 /* Execute a command line. */
714 COMMAND *find_command (), *command;
717 /* Isolate the command word. */
719 while (line[i] && !whitespace (line[i]))
727 command = find_command (word);
731 fprintf (stderr, "%s: No such command for FileMan.\n", word);
735 /* Get argument to command, if any. */
736 while (whitespace (line[i]))
741 /* Call the function. */
742 (*(command->func)) (word);
745 /* Look up NAME as the name of a command, and return a pointer to that
746 command. Return a NULL pointer if NAME isn't a command name. */
753 for (i = 0; commands[i].name; i++)
754 if (strcmp (name, commands[i].name) == 0)
755 return (&commands[i]);
757 return ((COMMAND *)NULL);
760 /* Strip whitespace from the start and end of STRING. */
766 while (whitespace (string[i]))
770 strcpy (string, string + i);
772 i = strlen (string) - 1;
774 while (i > 0 && whitespace (string[i]))
780 /* **************************************************************** */
782 /* Interface to Readline Completion */
784 /* **************************************************************** */
786 /* Tell the GNU Readline library how to complete. We want to try to complete
787 on command names if this is the first word in the line, or on filenames
789 initialize_readline ()
791 char **fileman_completion ();
793 /* Allow conditional parsing of the ~/.inputrc file. */
794 rl_readline_name = "FileMan";
796 /* Tell the completer that we want a crack first. */
797 rl_attempted_completion_function = (Function *)fileman_completion;
800 /* Attempt to complete on the contents of TEXT. START and END show the
801 region of TEXT that contains the word to complete. We can use the
802 entire line in case we want to do some simple parsing. Return the
803 array of matches, or NULL if there aren't any. */
805 fileman_completion (text, start, end)
810 char *command_generator ();
812 matches = (char **)NULL;
814 /* If this word is at the start of the line, then it is a command
815 to complete. Otherwise it is the name of a file in the current
818 matches = completion_matches (text, command_generator);
823 /* Generator function for command completion. STATE lets us know whether
824 to start from scratch; without any state (i.e. STATE == 0), then we
825 start at the top of the list. */
827 command_generator (text, state)
831 static int list_index, len;
834 /* If this is a new word to complete, initialize now. This includes
835 saving the length of TEXT for efficiency, and initializing the index
843 /* Return the next name which partially matches from the command list. */
844 while (name = commands[list_index].name)
848 if (strncmp (name, text, len) == 0)
852 /* If no names matched, then return NULL. */
853 return ((char *)NULL);
856 /* **************************************************************** */
858 /* FileMan Commands */
860 /* **************************************************************** */
862 /* String to pass to system (). This is for the LIST, VIEW and RENAME
864 static char syscom[1024];
866 /* List the file(s) named in arg. */
873 sprintf (syscom, "ls -FClg %s", arg);
880 if (!valid_argument ("view", arg))
883 sprintf (syscom, "cat %s | more", arg);
890 too_dangerous ("rename");
898 if (!valid_argument ("stat", arg))
901 if (stat (arg, &finfo) == -1)
907 printf ("Statistics for `%s':\n", arg);
909 printf ("%s has %d link%s, and is %d bytes in length.\n", arg,
910 finfo.st_nlink, (finfo.st_nlink == 1) ? "" : "s", finfo.st_size);
911 printf (" Created on: %s", ctime (&finfo.st_ctime));
912 printf (" Last access at: %s", ctime (&finfo.st_atime));
913 printf ("Last modified at: %s", ctime (&finfo.st_mtime));
919 too_dangerous ("delete");
922 /* Print out help for ARG, or for all of the commands if ARG is
930 for (i = 0; commands[i].name; i++)
932 if (!*arg || (strcmp (arg, commands[i].name) == 0))
934 printf ("%s\t\t%s.\n", commands[i].name, commands[i].doc);
941 printf ("No commands match `%s'. Possibilties are:\n", arg);
943 for (i = 0; commands[i].name; i++)
945 /* Print in six columns. */
952 printf ("%s\t", commands[i].name);
961 /* Change to the directory ARG. */
965 if (chdir (arg) == -1)
971 /* Print out the current working directory. */
979 printf ("Current directory is %s\n", dir);
982 /* The user wishes to quit using this program. Just set DONE non-zero. */
989 /* Function which tells you that you can't do this. */
990 too_dangerous (caller)
994 "%s: Too dangerous for me to distribute. Write it yourself.\n",
998 /* Return non-zero if ARG is a valid argument for CALLER, else print
999 an error message and return zero. */
1001 valid_argument (caller, arg)
1006 fprintf (stderr, "%s: Argument required.\n", caller);