home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / cwin / c.exe / $INSTDIR / include / readline / history.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-12-15  |  9.9 KB  |  255 lines

  1. /* History.h -- the names of functions that you can call in history. */
  2. /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
  3.  
  4.    This file contains the GNU History Library (the Library), a set of
  5.    routines for managing the text of previously typed lines.
  6.  
  7.    The Library is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 2, or (at your option)
  10.    any later version.
  11.  
  12.    The Library is distributed in the hope that it will be useful, but
  13.    WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.    General Public License for more details.
  16.  
  17.    The GNU General Public License is often shipped with GNU software, and
  18.    is generally kept in a file called COPYING or LICENSE.  If you do not
  19.    have a copy of the license, write to the Free Software Foundation,
  20.    59 Temple Place, Suite 330, Boston, MA 02111 USA. */
  21.  
  22. #ifndef _HISTORY_H_
  23. #define _HISTORY_H_
  24.  
  25. #if __READLINE_EXPORT__
  26. # define READLINE_API __declspec (dllexport)
  27. #elif __READLINE_IMPORT__
  28. # define READLINE_API __declspec (dllimport)
  29. #else
  30. # define READLINE_API
  31. #endif
  32.  
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36.  
  37. #if defined READLINE_LIBRARY
  38. #  include "rlstdc.h"
  39. #  include "rltypedefs.h"
  40. #else
  41. #  include <readline/rlstdc.h>
  42. #  include <readline/rltypedefs.h>
  43. #endif
  44.  
  45. #ifdef __STDC__
  46. typedef void *histdata_t;
  47. #else
  48. typedef char *histdata_t;
  49. #endif
  50.  
  51. /* The structure used to store a history entry. */
  52. typedef struct _hist_entry {
  53.   char *line;
  54.   histdata_t data;
  55. } HIST_ENTRY;
  56.  
  57. /* A structure used to pass the current state of the history stuff around. */
  58. typedef struct _hist_state {
  59.   HIST_ENTRY **entries;        /* Pointer to the entries themselves. */
  60.   int offset;            /* The location pointer within this array. */
  61.   int length;            /* Number of elements within this array. */
  62.   int size;            /* Number of slots allocated to this array. */
  63.   int flags;
  64. } HISTORY_STATE;
  65.  
  66. /* Flag values for the `flags' member of HISTORY_STATE. */
  67. #define HS_STIFLED    0x01
  68.  
  69. /* Initialization and state management. */
  70.  
  71. /* Begin a session in which the history functions might be used.  This
  72.    just initializes the interactive variables. */
  73. READLINE_API extern void using_history __P((void));
  74.  
  75. /* Return the current HISTORY_STATE of the history. */
  76. READLINE_API extern HISTORY_STATE *history_get_history_state __P((void));
  77.  
  78. /* Set the state of the current history array to STATE. */
  79. READLINE_API extern void history_set_history_state __P((HISTORY_STATE *));
  80.  
  81. /* Manage the history list. */
  82.  
  83. /* Place STRING at the end of the history list.
  84.    The associated data field (if any) is set to NULL. */
  85. READLINE_API extern void add_history __P((const char *));
  86.  
  87. /* A reasonably useless function, only here for completeness.  WHICH
  88.    is the magic number that tells us which element to delete.  The
  89.    elements are numbered from 0. */
  90. READLINE_API extern HIST_ENTRY *remove_history __P((int));
  91.  
  92. /* Make the history entry at WHICH have LINE and DATA.  This returns
  93.    the old entry so you can dispose of the data.  In the case of an
  94.    invalid WHICH, a NULL pointer is returned. */
  95. READLINE_API extern HIST_ENTRY *replace_history_entry __P((int, const char *, histdata_t));
  96.  
  97. /* Clear the history list and start over. */
  98. READLINE_API extern void clear_history __P((void));
  99.  
  100. /* Stifle the history list, remembering only MAX number of entries. */
  101. READLINE_API extern void stifle_history __P((int));
  102.  
  103. /* Stop stifling the history.  This returns the previous amount the
  104.    history was stifled by.  The value is positive if the history was
  105.    stifled, negative if it wasn't. */
  106. READLINE_API extern int unstifle_history __P((void));
  107.  
  108. /* Return 1 if the history is stifled, 0 if it is not. */
  109. READLINE_API extern int history_is_stifled __P((void));
  110.  
  111. /* Information about the history list. */
  112.  
  113. /* Return a NULL terminated array of HIST_ENTRY which is the current input
  114.    history.  Element 0 of this list is the beginning of time.  If there
  115.    is no history, return NULL. */
  116. READLINE_API extern HIST_ENTRY **history_list __P((void));
  117.  
  118. /* Returns the number which says what history element we are now
  119.    looking at.  */
  120. READLINE_API extern int where_history __P((void));
  121.   
  122. /* Return the history entry at the current position, as determined by
  123.    history_offset.  If there is no entry there, return a NULL pointer. */
  124. READLINE_API extern HIST_ENTRY *current_history __P((void));
  125.  
  126. /* Return the history entry which is logically at OFFSET in the history
  127.    array.  OFFSET is relative to history_base. */
  128. READLINE_API extern HIST_ENTRY *history_get __P((int));
  129.  
  130. /* Return the number of bytes that the primary history entries are using.
  131.    This just adds up the lengths of the_history->lines. */
  132. READLINE_API extern int history_total_bytes __P((void));
  133.  
  134. /* Moving around the history list. */
  135.  
  136. /* Set the position in the history list to POS. */
  137. READLINE_API extern int history_set_pos __P((int));
  138.  
  139. /* Back up history_offset to the previous history entry, and return
  140.    a pointer to that entry.  If there is no previous entry, return
  141.    a NULL pointer. */
  142. READLINE_API extern HIST_ENTRY *previous_history __P((void));
  143.  
  144. /* Move history_offset forward to the next item in the input_history,
  145.    and return the a pointer to that entry.  If there is no next entry,
  146.    return a NULL pointer. */
  147. READLINE_API extern HIST_ENTRY *next_history __P((void));
  148.  
  149. /* Searching the history list. */
  150.  
  151. /* Search the history for STRING, starting at history_offset.
  152.    If DIRECTION < 0, then the search is through previous entries,
  153.    else through subsequent.  If the string is found, then
  154.    current_history () is the history entry, and the value of this function
  155.    is the offset in the line of that history entry that the string was
  156.    found in.  Otherwise, nothing is changed, and a -1 is returned. */
  157. READLINE_API extern int history_search __P((const char *, int));
  158.  
  159. /* Search the history for STRING, starting at history_offset.
  160.    The search is anchored: matching lines must begin with string.
  161.    DIRECTION is as in history_search(). */
  162. READLINE_API extern int history_search_prefix __P((const char *, int));
  163.  
  164. /* Search for STRING in the history list, starting at POS, an
  165.    absolute index into the list.  DIR, if negative, says to search
  166.    backwards from POS, else forwards.
  167.    Returns the absolute index of the history element where STRING
  168.    was found, or -1 otherwise. */
  169. READLINE_API extern int history_search_pos __P((const char *, int, int));
  170.  
  171. /* Managing the history file. */
  172.  
  173. /* Add the contents of FILENAME to the history list, a line at a time.
  174.    If FILENAME is NULL, then read from ~/.history.  Returns 0 if
  175.    successful, or errno if not. */
  176. READLINE_API extern int read_history __P((const char *));
  177.  
  178. /* Read a range of lines from FILENAME, adding them to the history list.
  179.    Start reading at the FROM'th line and end at the TO'th.  If FROM
  180.    is zero, start at the beginning.  If TO is less than FROM, read
  181.    until the end of the file.  If FILENAME is NULL, then read from
  182.    ~/.history.  Returns 0 if successful, or errno if not. */
  183. READLINE_API extern int read_history_range __P((const char *, int, int));
  184.  
  185. /* Write the current history to FILENAME.  If FILENAME is NULL,
  186.    then write the history list to ~/.history.  Values returned
  187.    are as in read_history ().  */
  188. READLINE_API extern int write_history __P((const char *));
  189.  
  190. /* Append NELEMENT entries to FILENAME.  The entries appended are from
  191.    the end of the list minus NELEMENTs up to the end of the list. */
  192. READLINE_API extern int append_history __P((int, const char *));
  193.  
  194. /* Truncate the history file, leaving only the last NLINES lines. */
  195. READLINE_API extern int history_truncate_file __P((const char *, int));
  196.  
  197. /* History expansion. */
  198.  
  199. /* Expand the string STRING, placing the result into OUTPUT, a pointer
  200.    to a string.  Returns:
  201.  
  202.    0) If no expansions took place (or, if the only change in
  203.       the text was the de-slashifying of the history expansion
  204.       character)
  205.    1) If expansions did take place
  206.   -1) If there was an error in expansion.
  207.    2) If the returned line should just be printed.
  208.  
  209.   If an error ocurred in expansion, then OUTPUT contains a descriptive
  210.   error message. */
  211. READLINE_API extern int history_expand __P((char *, char **));
  212.  
  213. /* Extract a string segment consisting of the FIRST through LAST
  214.    arguments present in STRING.  Arguments are broken up as in
  215.    the shell. */
  216. READLINE_API extern char *history_arg_extract __P((int, int, const char *));
  217.  
  218. /* Return the text of the history event beginning at the current
  219.    offset into STRING.  Pass STRING with *INDEX equal to the
  220.    history_expansion_char that begins this specification.
  221.    DELIMITING_QUOTE is a character that is allowed to end the string
  222.    specification for what to search for in addition to the normal
  223.    characters `:', ` ', `\t', `\n', and sometimes `?'. */
  224. READLINE_API extern char *get_history_event __P((const char *, int *, int));
  225.  
  226. /* Return an array of tokens, much as the shell might.  The tokens are
  227.    parsed out of STRING. */
  228. READLINE_API extern char **history_tokenize __P((const char *));
  229.  
  230. /* Exported history variables. */
  231. READLINE_API extern int history_base;
  232. READLINE_API extern int history_length;
  233. READLINE_API extern int history_max_entries;
  234. READLINE_API extern char history_expansion_char;
  235. READLINE_API extern char history_subst_char;
  236. READLINE_API extern char *history_word_delimiters;
  237. READLINE_API extern char history_comment_char;
  238. READLINE_API extern char *history_no_expand_chars;
  239. READLINE_API extern char *history_search_delimiter_chars;
  240. READLINE_API extern int history_quotes_inhibit_expansion;
  241.  
  242. /* Backwards compatibility */
  243. READLINE_API extern int max_input_history;
  244.  
  245. /* If set, this function is called to decide whether or not a particular
  246.    history expansion should be treated as a special case for the calling
  247.    application and not expanded. */
  248. READLINE_API extern rl_linebuf_func_t *history_inhibit_expansion_function;
  249.  
  250. #ifdef __cplusplus
  251. }
  252. #endif
  253.  
  254. #endif /* !_HISTORY_H_ */
  255.