home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Atari / Gnu / gdb36p4b.zoo / readline / doc / history.info (.txt) next >
GNU Info File  |  1993-10-05  |  18KB  |  378 lines

  1. This is Info file history.info, produced by Makeinfo-1.55 from the
  2. input file hist.texinfo.
  3.    This document describes the GNU History library, a programming tool
  4. that provides a consistent user interface for recalling lines of
  5. previously typed input.
  6.    Copyright (C) 1988, 1991 Free Software Foundation, Inc.
  7.    Permission is granted to make and distribute verbatim copies of this
  8. manual provided the copyright notice and this permission notice pare
  9. preserved on all copies.
  10.    Permission is granted to copy and distribute modified versions of
  11. this manual under the conditions for verbatim copying, provided that
  12. the entire resulting derived work is distributed under the terms of a
  13. permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that this permission notice may be stated in a
  17. translation approved by the Foundation.
  18. File: history.info,  Node: Top,  Next: Using History Interactively,  Prev: (DIR),  Up: (DIR)
  19. GNU History Library
  20. *******************
  21.    This document describes the GNU History library, a programming tool
  22. that provides a consistent user interface for recalling lines of
  23. previously typed input.
  24. * Menu:
  25. * Using History Interactively::      GNU History User's Manual.
  26. * Programming with GNU History::  GNU History Programmer's Manual.
  27. * Concept Index::          Index of concepts described in this manual.
  28. * Function and Variable Index::      Index of externally visible functions
  29.                   and variables.
  30. File: history.info,  Node: Using History Interactively,  Next: Programming with GNU History,  Prev: Top,  Up: Top
  31. Using History Interactively
  32. ***************************
  33.    This chapter describes how to use the GNU History Library
  34. interactively, from a user's standpoint.  It should be considered a
  35. user's guide.  For information on using the GNU History Library in your
  36. own programs, *note Programming with GNU History::..
  37. * Menu:
  38. * History Interaction::        What it feels like using History as a user.
  39. File: history.info,  Node: History Interaction,  Up: Using History Interactively
  40. History Interaction
  41. ===================
  42.    The History library provides a history expansion feature that is
  43. similar to the history expansion in Csh.  The following text describes
  44. the sytax that you use to manipulate the history information.
  45.    History expansion takes place in two parts.  The first is to
  46. determine which line from the previous history should be used during
  47. substitution.  The second is to select portions of that line for
  48. inclusion into the current one.  The line selected from the previous
  49. history is called the "event", and the portions of that line that are
  50. acted upon are called "words".  The line is broken into words in the
  51. same fashion that the Bash shell does, so that several English (or
  52. Unix) words surrounded by quotes are considered as one word.
  53. * Menu:
  54. * Event Designators::    How to specify which history line to use.
  55. * Word Designators::    Specifying which words are of interest.
  56. * Modifiers::        Modifying the results of susbstitution.
  57. File: history.info,  Node: Event Designators,  Next: Word Designators,  Up: History Interaction
  58. Event Designators
  59. -----------------
  60.    An event designator is a reference to a command line entry in the
  61. history list.
  62.      Start a history subsititution, except when followed by a space,
  63.      tab, or the end of the line... = or (.
  64.      Refer to the previous command.  This is a synonym for `!-1'.
  65.      Refer to command line N.
  66. `!-n'
  67.      Refer to the command line N lines back.
  68. `!string'
  69.      Refer to the most recent command starting with STRING.
  70. `!?string'[`?']
  71.      Refer to the most recent command containing STRING.
  72. File: history.info,  Node: Word Designators,  Next: Modifiers,  Prev: Event Designators,  Up: History Interaction
  73. Word Designators
  74. ----------------
  75.    A : separates the event specification from the word designator.  It
  76. can be omitted if the word designator begins with a ^, $, * or %.
  77. Words are numbered from the beginning of the line, with the first word
  78. being denoted by a 0 (zero).
  79. `0 (zero)'
  80.      The zero'th word.  For many applications, this is the command word.
  81.      The N'th word.
  82.      The first argument.  that is, word 1.
  83.      The last argument.
  84.      The word matched by the most recent `?string?' search.
  85. `x-y'
  86.      A range of words; `-Y' Abbreviates `0-Y'.
  87.      All of the words, excepting the zero'th.  This is a synonym for
  88.      `1-$'.  It is not an error to use * if there is just one word in
  89.      the event.  The empty string is returned in that case.
  90. File: history.info,  Node: Modifiers,  Prev: Word Designators,  Up: History Interaction
  91. Modifiers
  92. ---------
  93.    After the optional word designator, you can add a sequence of one or
  94. more of the following modifiers, each preceded by a :.
  95.      The entire command line typed so far.  This means the current
  96.      command, not the previous command, so it really isn't a word
  97.      designator, and doesn't belong in this section.
  98.      Remove a trailing pathname component, leaving only the head.
  99.      Remove a trailing suffix of the form `.'SUFFIX, leaving the
  100.      basename.
  101.      Remove all but the suffix.
  102.      Remove all leading  pathname  components, leaving the tail.
  103.      Print the new command but do not execute it.
  104. File: history.info,  Node: Programming with GNU History,  Next: Concept Index,  Prev: Using History Interactively,  Up: Top
  105. Programming with GNU History
  106. ****************************
  107.    This chapter describes how to interface the GNU History Library with
  108. programs that you write.  It should be considered a technical guide.
  109. For information on the interactive use of GNU History, *note Using
  110. History Interactively::..
  111. * Menu:
  112. * Introduction to History::    What is the GNU History library for?
  113. * History Storage::        How information is stored.
  114. * History Functions::        Functions that you can use.
  115. * History Variables::        Variables that control behaviour.
  116. * History Programming Example::    Example of using the GNU History Library.
  117. File: history.info,  Node: Introduction to History,  Next: History Storage,  Up: Programming with GNU History
  118. Introduction to History
  119. =======================
  120.    Many programs read input from the user a line at a time.  The GNU
  121. history library is able to keep track of those lines, associate
  122. arbitrary data with each line, and utilize information from previous
  123. lines in making up new ones.
  124.    The programmer using the History library has available to him
  125. functions for remembering lines on a history stack, associating
  126. arbitrary data with a line, removing lines from the stack, searching
  127. through the stack for a line containing an arbitrary text string, and
  128. referencing any line on the stack directly.  In addition, a history
  129. "expansion" function is available which provides for a consistent user
  130. interface across many different programs.
  131.    The end-user using programs written with the History library has the
  132. benifit of a consistent user interface, with a set of well-known
  133. commands for manipulating the text of previous lines and using that text
  134. in new commands.  The basic history manipulation commands are similar to
  135. the history substitution used by `Csh'.
  136.    If the programmer desires, he can use the Readline library, which
  137. includes some history manipulation by default, and has the added
  138. advantage of Emacs style command line editing.
  139. File: history.info,  Node: History Storage,  Next: History Functions,  Prev: Introduction to History,  Up: Programming with GNU History
  140. History Storage
  141. ===============
  142.      typedef struct _hist_entry {
  143.        char *line;
  144.        char *data;
  145.      } HIST_ENTRY;
  146. File: history.info,  Node: History Functions,  Next: History Variables,  Prev: History Storage,  Up: Programming with GNU History
  147. History Functions
  148. =================
  149.    This section describes the calling sequence for the various functions
  150. present in GNU History.
  151.  - Function: void using_history ()
  152.      Begin a session in which the history functions might be used.  This
  153.      just initializes the interactive variables.
  154.  - Function: void add_history (CHAR *STRING)
  155.      Place STRING at the end of the history list.  The associated data
  156.      field (if any) is set to `NULL'.
  157.  - Function: int where_history ()
  158.      Returns the number which says what history element we are now
  159.      looking at.
  160.  - Function: int history_set_pos (INT POS)
  161.      Set the position in the history list to POS.
  162.  - Function: int history_search_pos (CHAR *STRING, INT DIRECTION, INT
  163.           POS)
  164.      Search for STRING in the history list, starting at POS, an
  165.      absolute index into the list.  DIRECTION, if negative, says to
  166.      search backwards from POS, else forwards.  Returns the absolute
  167.      index of the history element where STRING was found, or -1
  168.      otherwise.
  169.  - Function: HIST_ENTRY *remove_history ();
  170.      Remove history element WHICH from the history.  The removed
  171.      element is returned to you so you can free the line, data, and
  172.      containing structure.
  173.  - Function: void stifle_history (INT MAX)
  174.      Stifle the history list, remembering only MAX number of entries.
  175.  - Function: int unstifle_history ();
  176.      Stop stifling the history.  This returns the previous amount the
  177.      history was stifled by.  The value is positive if the history was
  178.      stifled, negative if it wasn't.
  179.  - Function: int read_history (CHAR *FILENAME)
  180.      Add the contents of FILENAME to the history list, a line at a
  181.      time.  If FILENAME is `NULL', then read from `~/.history'.
  182.      Returns 0 if successful, or errno if not.
  183.  - Function: int read_history_range (CHAR *FILENAME, INT FROM, INT TO)
  184.      Read a range of lines from FILENAME, adding them to the history
  185.      list.  Start reading at the FROM'th line and end at the TO'th.  If
  186.      FROM is zero, start at the beginning.  If TO is less than FROM,
  187.      then read until the end of the file.  If FILENAME is `NULL', then
  188.      read from `~/.history'.  Returns 0 if successful, or `errno' if
  189.      not.
  190.  - Function: int write_history (CHAR *FILENAME)
  191.      Append the current history to FILENAME.  If FILENAME is `NULL',
  192.      then append the history list to `~/.history'.  Values returned are
  193.      as in `read_history ()'.
  194.  - Function: int append_history (INT NELEMENTS, CHAR *FILENAME)
  195.      Append NELEMENT entries to FILENAME.  The entries appended are
  196.      from the end of the list minus NELEMENTS up to the end of the list.
  197.  - Function: HIST_ENTRY *replace_history_entry ()
  198.      Make the history entry at WHICH have LINE and DATA.  This returns
  199.      the old entry so you can dispose of the data.  In the case of an
  200.      invalid WHICH, a `NULL' pointer is returned.
  201.  - Function: HIST_ENTRY *current_history ()
  202.      Return the history entry at the current position, as determined by
  203.      `history_offset'.  If there is no entry there, return a `NULL'
  204.      pointer.
  205.  - Function: HIST_ENTRY *previous_history ()
  206.      Back up HISTORY_OFFSET to the previous history entry, and return a
  207.      pointer to that entry.  If there is no previous entry, return a
  208.      `NULL' pointer.
  209.  - Function: HIST_ENTRY *next_history ()
  210.      Move `history_offset' forward to the next history entry, and return
  211.      the a pointer to that entry.  If there is no next entry, return a
  212.      `NULL' pointer.
  213.  - Function: HIST_ENTRY **history_list ()
  214.      Return a `NULL' terminated array of `HIST_ENTRY' which is the
  215.      current input history.  Element 0 of this list is the beginning of
  216.      time.  If there is no history, return `NULL'.
  217.  - Function: int history_search (CHAR *STRING, INT DIRECTION)
  218.      Search the history for STRING, starting at `history_offset'.  If
  219.      DIRECTION < 0, then the search is through previous entries, else
  220.      through subsequent.  If STRING is found, then `current_history ()'
  221.      is the history entry, and the value of this function is the offset
  222.      in the line of that history entry that the STRING was found in.
  223.      Otherwise, nothing is changed, and a -1 is returned.
  224.  - Function: int history_expand (CHAR *STRING, CHAR **OUTPUT)
  225.      Expand STRING, placing the result into OUTPUT, a pointer to a
  226.      string.  Returns:
  227.     `0'
  228.           If no expansions took place (or, if the only change in the
  229.           text was the de-slashifying of the history expansion
  230.           character),
  231.     `1'
  232.           if expansions did take place, or
  233.     `-1'
  234.           if there was an error in expansion.
  235.      If an error ocurred in expansion, then OUTPUT contains a
  236.      descriptive error message.
  237.  - Function: char *history_arg_extract (INT FIRST, INT LAST, CHAR
  238.           *STRING)
  239.      Extract a string segment consisting of the FIRST through LAST
  240.      arguments present in STRING.  Arguments are broken up as in the
  241.      GNU Bash shell.
  242.  - Function: int history_total_bytes ();
  243.      Return the number of bytes that the primary history entries are
  244.      using.  This just adds up the lengths of `the_history->lines'.
  245. File: history.info,  Node: History Variables,  Next: History Programming Example,  Prev: History Functions,  Up: Programming with GNU History
  246. History Variables
  247. =================
  248.    This section describes the variables in GNU History that are
  249. externally visible.
  250.  - Variable: int history_base
  251.      For convenience only.  You set this when interpreting history
  252.      commands.  It is the logical offset of the first history element.
  253. File: history.info,  Node: History Programming Example,  Prev: History Variables,  Up: Programming with GNU History
  254. History Programming Example
  255. ===========================
  256.    The following snippet of code demonstrates simple use of the GNU
  257. History Library.
  258.      main ()
  259.      {
  260.        char line[1024], *t;
  261.        int done = 0;
  262.      
  263.        line[0] = 0;
  264.      
  265.        while (!done)
  266.          {
  267.            fprintf (stdout, "history%% ");
  268.            t = gets (line);
  269.      
  270.            if (!t)
  271.              strcpy (line, "quit");
  272.      
  273.            if (line[0])
  274.              {
  275.                char *expansion;
  276.                int result;
  277.      
  278.                using_history ();
  279.      
  280.                result = history_expand (line, &expansion);
  281.                strcpy (line, expansion);
  282.                free (expansion);
  283.                if (result)
  284.                  fprintf (stderr, "%s\n", line);
  285.      
  286.                if (result < 0)
  287.                  continue;
  288.      
  289.                add_history (line);
  290.              }
  291.      
  292.            if (strcmp (line, "quit") == 0) done = 1;
  293.            if (strcmp (line, "save") == 0) write_history (0);
  294.            if (strcmp (line, "read") == 0) read_history (0);
  295.            if (strcmp (line, "list") == 0)
  296.              {
  297.                register HIST_ENTRY **the_list = history_list ();
  298.                register int i;
  299.      
  300.                if (the_list)
  301.                  for (i = 0; the_list[i]; i++)
  302.                    fprintf (stdout, "%d: %s\n",
  303.                       i + history_base, the_list[i]->line);
  304.              }
  305.            if (strncmp (line, "delete", strlen ("delete")) == 0)
  306.              {
  307.                int which;
  308.                if ((sscanf (line + strlen ("delete"), "%d", &which)) == 1)
  309.                  {
  310.                    HIST_ENTRY *entry = remove_history (which);
  311.                    if (!entry)
  312.                      fprintf (stderr, "No such entry %d\n", which);
  313.                    else
  314.                      {
  315.                        free (entry->line);
  316.                        free (entry);
  317.                      }
  318.                  }
  319.                else
  320.                  {
  321.                    fprintf (stderr, "non-numeric arg given to `delete'\n");
  322.                  }
  323.              }
  324.          }
  325.      }
  326. File: history.info,  Node: Concept Index,  Next: Function and Variable Index,  Prev: Programming with GNU History,  Up: Top
  327. Concept Index
  328. *************
  329. * Menu:
  330. * event designators:                    Event Designators.
  331. * expansion:                            History Interaction.
  332. File: history.info,  Node: Function and Variable Index,  Prev: Concept Index,  Up: Top
  333. Function and Variable Index
  334. ***************************
  335. * Menu:
  336. * char *history_arg_extract:            History Functions.
  337. * HIST_ENTRY **history_list:            History Functions.
  338. * HIST_ENTRY *current_history:          History Functions.
  339. * HIST_ENTRY *next_history:             History Functions.
  340. * HIST_ENTRY *previous_history:         History Functions.
  341. * HIST_ENTRY *remove_history:           History Functions.
  342. * HIST_ENTRY *replace_history_entry:    History Functions.
  343. * int append_history:                   History Functions.
  344. * int history_base:                     History Variables.
  345. * int history_expand:                   History Functions.
  346. * int history_search:                   History Functions.
  347. * int history_search_pos:               History Functions.
  348. * int history_set_pos:                  History Functions.
  349. * int history_total_bytes:              History Functions.
  350. * int read_history:                     History Functions.
  351. * int read_history_range:               History Functions.
  352. * int unstifle_history:                 History Functions.
  353. * int where_history:                    History Functions.
  354. * int write_history:                    History Functions.
  355. * void add_history:                     History Functions.
  356. * void stifle_history:                  History Functions.
  357. * void using_history:                   History Functions.
  358. Tag Table:
  359. Node: Top
  360. Node: Using History Interactively
  361. Node: History Interaction
  362. Node: Event Designators
  363. Node: Word Designators
  364. Node: Modifiers
  365. Node: Programming with GNU History
  366. Node: Introduction to History
  367. Node: History Storage
  368. Node: History Functions
  369. Node: History Variables
  370. 13045
  371. Node: History Programming Example
  372. 13481
  373. Node: Concept Index
  374. 15726
  375. Node: Function and Variable Index
  376. 16012
  377. End Tag Table
  378.