Home | History | Annotate | Line # | Download | only in libedit
histedit.h revision 1.52
      1  1.52  christos /*	$NetBSD: histedit.h,v 1.52 2014/05/11 01:05:17 christos 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.38  christos #define	LIBEDIT_MINOR 11
     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.27  christos #ifdef __cplusplus
     50  1.27  christos extern "C" {
     51  1.27  christos #endif
     52  1.27  christos 
     53   1.1       cgd /*
     54   1.1       cgd  * ==== Editing ====
     55   1.1       cgd  */
     56  1.25     lukem 
     57   1.1       cgd typedef struct editline EditLine;
     58   1.1       cgd 
     59   1.1       cgd /*
     60   1.1       cgd  * For user-defined function interface
     61   1.1       cgd  */
     62   1.1       cgd typedef struct lineinfo {
     63  1.16     lukem 	const char	*buffer;
     64  1.16     lukem 	const char	*cursor;
     65  1.16     lukem 	const char	*lastchar;
     66   1.1       cgd } LineInfo;
     67   1.1       cgd 
     68   1.1       cgd /*
     69   1.1       cgd  * EditLine editor function return codes.
     70   1.1       cgd  * For user-defined function interface
     71   1.1       cgd  */
     72   1.1       cgd #define	CC_NORM		0
     73   1.1       cgd #define	CC_NEWLINE	1
     74   1.1       cgd #define	CC_EOF		2
     75  1.16     lukem #define	CC_ARGHACK	3
     76  1.16     lukem #define	CC_REFRESH	4
     77   1.1       cgd #define	CC_CURSOR	5
     78   1.1       cgd #define	CC_ERROR	6
     79  1.16     lukem #define	CC_FATAL	7
     80  1.16     lukem #define	CC_REDISPLAY	8
     81  1.16     lukem #define	CC_REFRESH_BEEP	9
     82   1.1       cgd 
     83   1.1       cgd /*
     84   1.1       cgd  * Initialization, cleanup, and resetting
     85   1.1       cgd  */
     86  1.16     lukem EditLine	*el_init(const char *, FILE *, FILE *, FILE *);
     87  1.50  christos EditLine	*el_init_fd(const char *, FILE *, FILE *, FILE *,
     88  1.50  christos     int, int, int);
     89  1.25     lukem void		 el_end(EditLine *);
     90  1.16     lukem void		 el_reset(EditLine *);
     91   1.1       cgd 
     92   1.1       cgd /*
     93   1.1       cgd  * Get a line, a character or push a string back in the input queue
     94   1.1       cgd  */
     95  1.16     lukem const char	*el_gets(EditLine *, int *);
     96  1.16     lukem int		 el_getc(EditLine *, char *);
     97  1.35  christos void		 el_push(EditLine *, const char *);
     98   1.1       cgd 
     99   1.1       cgd /*
    100   1.7  christos  * Beep!
    101   1.7  christos  */
    102  1.16     lukem void		 el_beep(EditLine *);
    103   1.7  christos 
    104   1.7  christos /*
    105   1.1       cgd  * High level function internals control
    106   1.1       cgd  * Parses argc, argv array and executes builtin editline commands
    107   1.1       cgd  */
    108  1.19  christos int		 el_parse(EditLine *, int, const char **);
    109   1.1       cgd 
    110   1.1       cgd /*
    111  1.10     lukem  * Low level editline access functions
    112   1.1       cgd  */
    113  1.16     lukem int		 el_set(EditLine *, int, ...);
    114  1.29  christos int		 el_get(EditLine *, int, ...);
    115  1.26       dsl unsigned char	_el_fn_complete(EditLine *, int);
    116   1.1       cgd 
    117   1.1       cgd /*
    118   1.1       cgd  * el_set/el_get parameters
    119  1.42  christos  *
    120  1.45  christos  * When using el_wset/el_wget (as opposed to el_set/el_get):
    121  1.45  christos  *   Char is wchar_t, otherwise it is char.
    122  1.45  christos  *   prompt_func is el_wpfunc_t, otherwise it is el_pfunc_t .
    123  1.45  christos 
    124  1.45  christos  * Prompt function prototypes are:
    125  1.45  christos  *   typedef char    *(*el_pfunct_t)  (EditLine *);
    126  1.45  christos  *   typedef wchar_t *(*el_wpfunct_t) (EditLine *);
    127  1.42  christos  *
    128  1.42  christos  * For operations that support set or set/get, the argument types listed are for
    129  1.42  christos  * the "set" operation. For "get", each listed type must be a pointer.
    130  1.42  christos  * E.g. EL_EDITMODE takes an int when set, but an int* when get.
    131  1.42  christos  *
    132  1.42  christos  * Operations that only support "get" have the correct argument types listed.
    133  1.42  christos  */
    134  1.45  christos #define	EL_PROMPT	0	/* , prompt_func);		      set/get */
    135  1.42  christos #define	EL_TERMINAL	1	/* , const char *);		      set/get */
    136  1.45  christos #define	EL_EDITOR	2	/* , const Char *);		      set/get */
    137  1.42  christos #define	EL_SIGNAL	3	/* , int);			      set/get */
    138  1.45  christos #define	EL_BIND		4	/* , const Char *, ..., NULL);	      set     */
    139  1.45  christos #define	EL_TELLTC	5	/* , const Char *, ..., NULL);	      set     */
    140  1.45  christos #define	EL_SETTC	6	/* , const Char *, ..., NULL);	      set     */
    141  1.45  christos #define	EL_ECHOTC	7	/* , const Char *, ..., NULL);        set     */
    142  1.45  christos #define	EL_SETTY	8	/* , const Char *, ..., NULL);        set     */
    143  1.45  christos #define	EL_ADDFN	9	/* , const Char *, const Char,        set     */
    144  1.45  christos 				/*   el_func_t);		 	      */
    145  1.48  christos #define	EL_HIST		10	/* , hist_fun_t, const void *);	      set     */
    146  1.42  christos #define	EL_EDITMODE	11	/* , int);			      set/get */
    147  1.44  christos #define	EL_RPROMPT	12	/* , prompt_func);		      set/get */
    148  1.42  christos #define	EL_GETCFN	13	/* , el_rfunc_t);		      set/get */
    149  1.42  christos #define	EL_CLIENTDATA	14	/* , void *);			      set/get */
    150  1.42  christos #define	EL_UNBUFFERED	15	/* , int);			      set/get */
    151  1.42  christos #define	EL_PREP_TERM	16	/* , int);			      set     */
    152  1.45  christos #define	EL_GETTC	17	/* , const Char *, ..., NULL);		  get */
    153  1.42  christos #define	EL_GETFP	18	/* , int, FILE **);		          get */
    154  1.42  christos #define	EL_SETFP	19	/* , int, FILE *);		      set     */
    155  1.42  christos #define	EL_REFRESH	20	/* , void);			      set     */
    156  1.45  christos #define	EL_PROMPT_ESC	21	/* , prompt_func, Char);	      set/get */
    157  1.45  christos #define	EL_RPROMPT_ESC	22	/* , prompt_func, Char);	      set/get */
    158  1.47  christos #define	EL_RESIZE	23	/* , el_zfunc_t, void *);	      set     */
    159  1.17  christos 
    160  1.32  christos #define	EL_BUILTIN_GETCFN	(NULL)
    161   1.1       cgd 
    162   1.1       cgd /*
    163   1.1       cgd  * Source named file or $PWD/.editrc or $HOME/.editrc
    164   1.1       cgd  */
    165  1.16     lukem int		el_source(EditLine *, const char *);
    166   1.1       cgd 
    167   1.1       cgd /*
    168   1.1       cgd  * Must be called when the terminal changes size; If EL_SIGNAL
    169   1.1       cgd  * is set this is done automatically otherwise it is the responsibility
    170   1.1       cgd  * of the application
    171   1.1       cgd  */
    172  1.16     lukem void		 el_resize(EditLine *);
    173   1.1       cgd 
    174   1.1       cgd /*
    175   1.1       cgd  * User-defined function interface.
    176   1.1       cgd  */
    177  1.16     lukem const LineInfo	*el_line(EditLine *);
    178  1.16     lukem int		 el_insertstr(EditLine *, const char *);
    179  1.16     lukem void		 el_deletestr(EditLine *, int);
    180   1.1       cgd 
    181  1.25     lukem 
    182   1.1       cgd /*
    183   1.1       cgd  * ==== History ====
    184   1.1       cgd  */
    185   1.1       cgd 
    186   1.1       cgd typedef struct history History;
    187   1.1       cgd 
    188   1.1       cgd typedef struct HistEvent {
    189  1.16     lukem 	int		 num;
    190  1.16     lukem 	const char	*str;
    191   1.1       cgd } HistEvent;
    192   1.1       cgd 
    193   1.1       cgd /*
    194   1.1       cgd  * History access functions.
    195   1.1       cgd  */
    196  1.16     lukem History *	history_init(void);
    197  1.16     lukem void		history_end(History *);
    198   1.1       cgd 
    199  1.16     lukem int		history(History *, HistEvent *, int, ...);
    200   1.1       cgd 
    201  1.16     lukem #define	H_FUNC		 0	/* , UTSL		*/
    202  1.16     lukem #define	H_SETSIZE	 1	/* , const int);	*/
    203  1.16     lukem #define	H_GETSIZE	 2	/* , void);		*/
    204  1.16     lukem #define	H_FIRST		 3	/* , void);		*/
    205  1.16     lukem #define	H_LAST		 4	/* , void);		*/
    206  1.16     lukem #define	H_PREV		 5	/* , void);		*/
    207  1.16     lukem #define	H_NEXT		 6	/* , void);		*/
    208  1.16     lukem #define	H_CURR		 8	/* , const int);	*/
    209  1.20  christos #define	H_SET		 7	/* , int);		*/
    210  1.42  christos #define	H_ADD		 9	/* , const wchar_t *);	*/
    211  1.42  christos #define	H_ENTER		10	/* , const wchar_t *);	*/
    212  1.42  christos #define	H_APPEND	11	/* , const wchar_t *);	*/
    213  1.16     lukem #define	H_END		12	/* , void);		*/
    214  1.42  christos #define	H_NEXT_STR	13	/* , const wchar_t *);	*/
    215  1.42  christos #define	H_PREV_STR	14	/* , const wchar_t *);	*/
    216  1.16     lukem #define	H_NEXT_EVENT	15	/* , const int);	*/
    217  1.16     lukem #define	H_PREV_EVENT	16	/* , const int);	*/
    218  1.16     lukem #define	H_LOAD		17	/* , const char *);	*/
    219  1.16     lukem #define	H_SAVE		18	/* , const char *);	*/
    220  1.16     lukem #define	H_CLEAR		19	/* , void);		*/
    221  1.21  christos #define	H_SETUNIQUE	20	/* , int);		*/
    222  1.21  christos #define	H_GETUNIQUE	21	/* , void);		*/
    223  1.28  christos #define	H_DEL		22	/* , int);		*/
    224  1.41  christos #define	H_NEXT_EVDATA	23	/* , const int, histdata_t *);	*/
    225  1.41  christos #define	H_DELDATA	24	/* , int, histdata_t *);*/
    226  1.41  christos #define	H_REPLACE	25	/* , const char *, histdata_t);	*/
    227  1.52  christos #define	H_SAVE_FP	26	/* , FILE *);		*/
    228  1.41  christos 
    229  1.25     lukem 
    230  1.25     lukem 
    231  1.25     lukem /*
    232  1.25     lukem  * ==== Tokenization ====
    233  1.25     lukem  */
    234  1.25     lukem 
    235  1.25     lukem typedef struct tokenizer Tokenizer;
    236  1.25     lukem 
    237  1.25     lukem /*
    238  1.25     lukem  * String tokenization functions, using simplified sh(1) quoting rules
    239  1.25     lukem  */
    240  1.25     lukem Tokenizer	*tok_init(const char *);
    241  1.25     lukem void		 tok_end(Tokenizer *);
    242  1.25     lukem void		 tok_reset(Tokenizer *);
    243  1.25     lukem int		 tok_line(Tokenizer *, const LineInfo *,
    244  1.25     lukem 		    int *, const char ***, int *, int *);
    245  1.25     lukem int		 tok_str(Tokenizer *, const char *,
    246  1.25     lukem 		    int *, const char ***);
    247   1.1       cgd 
    248  1.42  christos /*
    249  1.42  christos  * Begin Wide Character Support
    250  1.42  christos  */
    251  1.42  christos #ifdef __linux__
    252  1.42  christos /* Apparently we need _GNU_SOURCE defined to get access to wcsdup on Linux */
    253  1.46  christos #ifndef _GNU_SOURCE
    254  1.42  christos #define _GNU_SOURCE
    255  1.42  christos #endif
    256  1.46  christos #endif
    257  1.42  christos 
    258  1.42  christos #include <wchar.h>
    259  1.42  christos #include <wctype.h>
    260  1.42  christos 
    261  1.42  christos /*
    262  1.42  christos  * Wide character versions
    263  1.42  christos  */
    264  1.42  christos 
    265  1.42  christos /*
    266  1.42  christos  * ==== Editing ====
    267  1.42  christos  */
    268  1.42  christos typedef struct lineinfow {
    269  1.42  christos 	const wchar_t	*buffer;
    270  1.42  christos 	const wchar_t	*cursor;
    271  1.42  christos 	const wchar_t	*lastchar;
    272  1.42  christos } LineInfoW;
    273  1.42  christos 
    274  1.42  christos const wchar_t	*el_wgets(EditLine *, int *);
    275  1.42  christos int		 el_wgetc(EditLine *, wchar_t *);
    276  1.42  christos void		 el_wpush(EditLine *, const wchar_t *);
    277  1.42  christos 
    278  1.42  christos int		 el_wparse(EditLine *, int, const wchar_t **);
    279  1.42  christos 
    280  1.42  christos int		 el_wset(EditLine *, int, ...);
    281  1.42  christos int		 el_wget(EditLine *, int, ...);
    282  1.42  christos 
    283  1.51  christos int		 el_cursor(EditLine *, int);
    284  1.42  christos const LineInfoW	*el_wline(EditLine *);
    285  1.42  christos int		 el_winsertstr(EditLine *, const wchar_t *);
    286  1.42  christos #define          el_wdeletestr  el_deletestr
    287  1.42  christos 
    288  1.42  christos /*
    289  1.42  christos  * ==== History ====
    290  1.42  christos  */
    291  1.45  christos typedef struct histeventW {
    292  1.42  christos 	int		 num;
    293  1.42  christos 	const wchar_t	*str;
    294  1.42  christos } HistEventW;
    295  1.42  christos 
    296  1.45  christos typedef struct historyW HistoryW;
    297  1.42  christos 
    298  1.43  christos HistoryW *	history_winit(void);
    299  1.43  christos void		history_wend(HistoryW *);
    300  1.42  christos 
    301  1.45  christos int		history_w(HistoryW *, HistEventW *, int, ...);
    302  1.42  christos 
    303  1.42  christos /*
    304  1.42  christos  * ==== Tokenization ====
    305  1.42  christos  */
    306  1.45  christos typedef struct tokenizerW TokenizerW;
    307  1.42  christos 
    308  1.42  christos /* Wide character tokenizer support */
    309  1.42  christos TokenizerW	*tok_winit(const wchar_t *);
    310  1.42  christos void		 tok_wend(TokenizerW *);
    311  1.42  christos void		 tok_wreset(TokenizerW *);
    312  1.42  christos int		 tok_wline(TokenizerW *, const LineInfoW *,
    313  1.42  christos 		    int *, const wchar_t ***, int *, int *);
    314  1.42  christos int		 tok_wstr(TokenizerW *, const wchar_t *,
    315  1.42  christos 		    int *, const wchar_t ***);
    316  1.42  christos 
    317  1.27  christos #ifdef __cplusplus
    318  1.27  christos }
    319  1.27  christos #endif
    320  1.27  christos 
    321  1.11    kleink #endif /* _HISTEDIT_H_ */
    322