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