histedit.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* $NetBSD: histedit.h,v 1.19 2002/03/18 16:00:54 christos Exp $ */
  2. /*-
  3. * Copyright (c) 1992, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * Christos Zoulas of Cornell University.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. All advertising materials mentioning features or use of this software
  18. * must display the following acknowledgement:
  19. * This product includes software developed by the University of
  20. * California, Berkeley and its contributors.
  21. * 4. Neither the name of the University nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35. * SUCH DAMAGE.
  36. *
  37. * @(#)histedit.h 8.2 (Berkeley) 1/3/94
  38. */
  39. /*
  40. * histedit.h: Line editor and history interface.
  41. */
  42. #ifndef _HISTEDIT_H_
  43. #define _HISTEDIT_H_
  44. #define LIBEDIT_MAJOR 2
  45. #define LIBEDIT_MINOR 6
  46. #include <sys/types.h>
  47. #include <stdio.h>
  48. /*
  49. * ==== Editing ====
  50. */
  51. typedef struct editline EditLine;
  52. /*
  53. * For user-defined function interface
  54. */
  55. typedef struct lineinfo {
  56. char *buffer;
  57. char *cursor;
  58. char *lastchar;
  59. } LineInfo;
  60. /*
  61. * EditLine editor function return codes.
  62. * For user-defined function interface
  63. */
  64. #define CC_NORM 0
  65. #define CC_NEWLINE 1
  66. #define CC_EOF 2
  67. #define CC_ARGHACK 3
  68. #define CC_REFRESH 4
  69. #define CC_CURSOR 5
  70. #define CC_ERROR 6
  71. #define CC_FATAL 7
  72. #define CC_REDISPLAY 8
  73. #define CC_REFRESH_BEEP 9
  74. /*
  75. * Initialization, cleanup, and resetting
  76. */
  77. EditLine *el_init(const char *, FILE *, FILE *, FILE *);
  78. void el_reset(EditLine *);
  79. void el_end(EditLine *);
  80. /*
  81. * Get a line, a character or push a string back in the input queue
  82. */
  83. const char *el_gets(EditLine *, int *);
  84. int el_getc(EditLine *, char *);
  85. void el_push(EditLine *, char *);
  86. /*
  87. * Beep!
  88. */
  89. void el_beep(EditLine *);
  90. /*
  91. * High level function internals control
  92. * Parses argc, argv array and executes builtin editline commands
  93. */
  94. int el_parse(EditLine *, int, const char **);
  95. /*
  96. * Low level editline access functions
  97. */
  98. int el_set(EditLine *, int, ...);
  99. int el_get(EditLine *, int, void *);
  100. /*
  101. * el_set/el_get parameters
  102. */
  103. #define EL_PROMPT 0 /* , el_pfunc_t); */
  104. #define EL_TERMINAL 1 /* , const char *); */
  105. #define EL_EDITOR 2 /* , const char *); */
  106. #define EL_SIGNAL 3 /* , int); */
  107. #define EL_BIND 4 /* , const char *, ..., NULL); */
  108. #define EL_TELLTC 5 /* , const char *, ..., NULL); */
  109. #define EL_SETTC 6 /* , const char *, ..., NULL); */
  110. #define EL_ECHOTC 7 /* , const char *, ..., NULL); */
  111. #define EL_SETTY 8 /* , const char *, ..., NULL); */
  112. #define EL_ADDFN 9 /* , const char *, const char * */
  113. /* , el_func_t); */
  114. #define EL_HIST 10 /* , hist_fun_t, const char *); */
  115. #define EL_EDITMODE 11 /* , int); */
  116. #define EL_RPROMPT 12 /* , el_pfunc_t); */
  117. #define EL_GETCFN 13 /* , el_rfunc_t); */
  118. #define EL_CLIENTDATA 14 /* , void *); */
  119. #define EL_BUILTIN_GETCFN (NULL)
  120. /*
  121. * Source named file or $PWD/.editrc or $HOME/.editrc
  122. */
  123. int el_source(EditLine *, const char *);
  124. /*
  125. * Must be called when the terminal changes size; If EL_SIGNAL
  126. * is set this is done automatically otherwise it is the responsibility
  127. * of the application
  128. */
  129. void el_resize(EditLine *);
  130. /*
  131. * User-defined function interface.
  132. */
  133. const LineInfo *el_line(EditLine *);
  134. int el_insertstr(EditLine *, const char *);
  135. void el_deletestr(EditLine *, int);
  136. /*
  137. * ==== History ====
  138. */
  139. typedef struct history History;
  140. typedef struct HistEvent {
  141. int num;
  142. const char *str;
  143. } HistEvent;
  144. /*
  145. * History access functions.
  146. */
  147. History * history_init(void);
  148. void history_end(History *);
  149. int history(History *, HistEvent *, int, ...);
  150. #define H_FUNC 0 /* , UTSL */
  151. #define H_SETSIZE 1 /* , const int); */
  152. #define H_GETSIZE 2 /* , void); */
  153. #define H_FIRST 3 /* , void); */
  154. #define H_LAST 4 /* , void); */
  155. #define H_PREV 5 /* , void); */
  156. #define H_NEXT 6 /* , void); */
  157. #define H_CURR 8 /* , const int); */
  158. #define H_SET 7 /* , void); */
  159. #define H_ADD 9 /* , const char *); */
  160. #define H_ENTER 10 /* , const char *); */
  161. #define H_APPEND 11 /* , const char *); */
  162. #define H_END 12 /* , void); */
  163. #define H_NEXT_STR 13 /* , const char *); */
  164. #define H_PREV_STR 14 /* , const char *); */
  165. #define H_NEXT_EVENT 15 /* , const int); */
  166. #define H_PREV_EVENT 16 /* , const int); */
  167. #define H_LOAD 17 /* , const char *); */
  168. #define H_SAVE 18 /* , const char *); */
  169. #define H_CLEAR 19 /* , void); */
  170. #endif /* _HISTEDIT_H_ */