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