home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / progtool / c / gcc / gdb36p4b.zoo / readline / doc / history.info next >
Encoding:
GNU Info File  |  1993-10-05  |  17.5 KB  |  512 lines

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