Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-17 09:55:34

0001 /*  $NetBSD: histedit.h,v 1.62 2023/02/03 22:01:42 christos Exp $   */
0002 
0003 /*-
0004  * Copyright (c) 1992, 1993
0005  *  The Regents of the University of California.  All rights reserved.
0006  *
0007  * This code is derived from software contributed to Berkeley by
0008  * Christos Zoulas of Cornell University.
0009  *
0010  * Redistribution and use in source and binary forms, with or without
0011  * modification, are permitted provided that the following conditions
0012  * are met:
0013  * 1. Redistributions of source code must retain the above copyright
0014  *    notice, this list of conditions and the following disclaimer.
0015  * 2. Redistributions in binary form must reproduce the above copyright
0016  *    notice, this list of conditions and the following disclaimer in the
0017  *    documentation and/or other materials provided with the distribution.
0018  * 3. Neither the name of the University nor the names of its contributors
0019  *    may be used to endorse or promote products derived from this software
0020  *    without specific prior written permission.
0021  *
0022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
0023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0032  * SUCH DAMAGE.
0033  *
0034  *  @(#)histedit.h  8.2 (Berkeley) 1/3/94
0035  */
0036 
0037 /*
0038  * histedit.h: Line editor and history interface.
0039  */
0040 #ifndef _HISTEDIT_H_
0041 #define _HISTEDIT_H_
0042 
0043 #define LIBEDIT_MAJOR 2
0044 #define LIBEDIT_MINOR 11
0045 
0046 #include <sys/types.h>
0047 #include <stdio.h>
0048 
0049 #ifdef __cplusplus
0050 extern "C" {
0051 #endif
0052 
0053 /*
0054  * ==== Editing ====
0055  */
0056 
0057 typedef struct editline EditLine;
0058 
0059 /*
0060  * For user-defined function interface
0061  */
0062 typedef struct lineinfo {
0063     const char  *buffer;
0064     const char  *cursor;
0065     const char  *lastchar;
0066 } LineInfo;
0067 
0068 /*
0069  * EditLine editor function return codes.
0070  * For user-defined function interface
0071  */
0072 #define CC_NORM     0
0073 #define CC_NEWLINE  1
0074 #define CC_EOF      2
0075 #define CC_ARGHACK  3
0076 #define CC_REFRESH  4
0077 #define CC_CURSOR   5
0078 #define CC_ERROR    6
0079 #define CC_FATAL    7
0080 #define CC_REDISPLAY    8
0081 #define CC_REFRESH_BEEP 9
0082 
0083 /*
0084  * Initialization, cleanup, and resetting
0085  */
0086 EditLine    *el_init(const char *, FILE *, FILE *, FILE *);
0087 EditLine    *el_init_fd(const char *, FILE *, FILE *, FILE *,
0088     int, int, int);
0089 void         el_end(EditLine *);
0090 void         el_reset(EditLine *);
0091 
0092 /*
0093  * Get a line, a character or push a string back in the input queue
0094  */
0095 const char  *el_gets(EditLine *, int *);
0096 int      el_getc(EditLine *, char *);
0097 void         el_push(EditLine *, const char *);
0098 
0099 /*
0100  * Beep!
0101  */
0102 void         el_beep(EditLine *);
0103 
0104 /*
0105  * High level function internals control
0106  * Parses argc, argv array and executes builtin editline commands
0107  */
0108 int      el_parse(EditLine *, int, const char **);
0109 
0110 /*
0111  * Low level editline access functions
0112  */
0113 int      el_set(EditLine *, int, ...);
0114 int      el_get(EditLine *, int, ...);
0115 unsigned char   _el_fn_complete(EditLine *, int);
0116 unsigned char   _el_fn_sh_complete(EditLine *, int);
0117 
0118 /*
0119  * el_set/el_get parameters
0120  *
0121  * When using el_wset/el_wget (as opposed to el_set/el_get):
0122  *   Char is wchar_t, otherwise it is char.
0123  *   prompt_func is el_wpfunc_t, otherwise it is el_pfunc_t .
0124 
0125  * Prompt function prototypes are:
0126  *   typedef char    *(*el_pfunct_t)  (EditLine *);
0127  *   typedef wchar_t *(*el_wpfunct_t) (EditLine *);
0128  *
0129  * For operations that support set or set/get, the argument types listed are for
0130  * the "set" operation. For "get", each listed type must be a pointer.
0131  * E.g. EL_EDITMODE takes an int when set, but an int* when get.
0132  *
0133  * Operations that only support "get" have the correct argument types listed.
0134  */
0135 #define EL_PROMPT   0   /* , prompt_func);            set/get */
0136 #define EL_TERMINAL 1   /* , const char *);           set/get */
0137 #define EL_EDITOR   2   /* , const Char *);           set/get */
0138 #define EL_SIGNAL   3   /* , int);                set/get */
0139 #define EL_BIND     4   /* , const Char *, ..., NULL);        set     */
0140 #define EL_TELLTC   5   /* , const Char *, ..., NULL);        set     */
0141 #define EL_SETTC    6   /* , const Char *, ..., NULL);        set     */
0142 #define EL_ECHOTC   7   /* , const Char *, ..., NULL);        set     */
0143 #define EL_SETTY    8   /* , const Char *, ..., NULL);        set     */
0144 #define EL_ADDFN    9   /* , const Char *, const Char,        set     */
0145                 /*   el_func_t);                  */
0146 #define EL_HIST     10  /* , hist_fun_t, const void *);       set     */
0147 #define EL_EDITMODE 11  /* , int);                set/get */
0148 #define EL_RPROMPT  12  /* , prompt_func);            set/get */
0149 #define EL_GETCFN   13  /* , el_rfunc_t);             set/get */
0150 #define EL_CLIENTDATA   14  /* , void *);                 set/get */
0151 #define EL_UNBUFFERED   15  /* , int);                set/get */
0152 #define EL_PREP_TERM    16  /* , int);                set     */
0153 #define EL_GETTC    17  /* , const Char *, ..., NULL);        get */
0154 #define EL_GETFP    18  /* , int, FILE **);               get */
0155 #define EL_SETFP    19  /* , int, FILE *);            set     */
0156 #define EL_REFRESH  20  /* , void);               set     */
0157 #define EL_PROMPT_ESC   21  /* , prompt_func, Char);          set/get */
0158 #define EL_RPROMPT_ESC  22  /* , prompt_func, Char);          set/get */
0159 #define EL_RESIZE   23  /* , el_zfunc_t, void *);         set     */
0160 #define EL_ALIAS_TEXT   24  /* , el_afunc_t, void *);         set     */
0161 #define EL_SAFEREAD 25  /* , int);                set/get */
0162 
0163 #define EL_BUILTIN_GETCFN   (NULL)
0164 
0165 /*
0166  * Source named file or $PWD/.editrc or $HOME/.editrc
0167  */
0168 int     el_source(EditLine *, const char *);
0169 
0170 /*
0171  * Must be called when the terminal changes size; If EL_SIGNAL
0172  * is set this is done automatically otherwise it is the responsibility
0173  * of the application
0174  */
0175 void         el_resize(EditLine *);
0176 
0177 /*
0178  * User-defined function interface.
0179  */
0180 const LineInfo  *el_line(EditLine *);
0181 int      el_insertstr(EditLine *, const char *);
0182 void         el_deletestr(EditLine *, int);
0183 int      el_replacestr(EditLine *, const char *);
0184 int      el_deletestr1(EditLine *, int, int);
0185 
0186 /*
0187  * ==== History ====
0188  */
0189 
0190 typedef struct history History;
0191 
0192 typedef struct HistEvent {
0193     int      num;
0194     const char  *str;
0195 } HistEvent;
0196 
0197 /*
0198  * History access functions.
0199  */
0200 History *   history_init(void);
0201 void        history_end(History *);
0202 
0203 int     history(History *, HistEvent *, int, ...);
0204 
0205 #define H_FUNC       0  /* , UTSL       */
0206 #define H_SETSIZE    1  /* , const int);    */
0207 #define H_GETSIZE    2  /* , void);     */
0208 #define H_FIRST      3  /* , void);     */
0209 #define H_LAST       4  /* , void);     */
0210 #define H_PREV       5  /* , void);     */
0211 #define H_NEXT       6  /* , void);     */
0212 #define H_CURR       8  /* , const int);    */
0213 #define H_SET        7  /* , int);      */
0214 #define H_ADD        9  /* , const wchar_t *);  */
0215 #define H_ENTER     10  /* , const wchar_t *);  */
0216 #define H_APPEND    11  /* , const wchar_t *);  */
0217 #define H_END       12  /* , void);     */
0218 #define H_NEXT_STR  13  /* , const wchar_t *);  */
0219 #define H_PREV_STR  14  /* , const wchar_t *);  */
0220 #define H_NEXT_EVENT    15  /* , const int);    */
0221 #define H_PREV_EVENT    16  /* , const int);    */
0222 #define H_LOAD      17  /* , const char *); */
0223 #define H_SAVE      18  /* , const char *); */
0224 #define H_CLEAR     19  /* , void);     */
0225 #define H_SETUNIQUE 20  /* , int);      */
0226 #define H_GETUNIQUE 21  /* , void);     */
0227 #define H_DEL       22  /* , int);      */
0228 #define H_NEXT_EVDATA   23  /* , const int, histdata_t *);  */
0229 #define H_DELDATA   24  /* , int, histdata_t *);*/
0230 #define H_REPLACE   25  /* , const char *, histdata_t); */
0231 #define H_SAVE_FP   26  /* , FILE *);       */
0232 #define H_NSAVE_FP  27  /* , size_t, FILE *);   */
0233 
0234 
0235 
0236 /*
0237  * ==== Tokenization ====
0238  */
0239 
0240 typedef struct tokenizer Tokenizer;
0241 
0242 /*
0243  * String tokenization functions, using simplified sh(1) quoting rules
0244  */
0245 Tokenizer   *tok_init(const char *);
0246 void         tok_end(Tokenizer *);
0247 void         tok_reset(Tokenizer *);
0248 int      tok_line(Tokenizer *, const LineInfo *,
0249             int *, const char ***, int *, int *);
0250 int      tok_str(Tokenizer *, const char *,
0251             int *, const char ***);
0252 
0253 /*
0254  * Begin Wide Character Support
0255  */
0256 #include <wchar.h>
0257 #include <wctype.h>
0258 
0259 #ifndef HAVE_WCSDUP
0260 wchar_t * wcsdup(const wchar_t *str);
0261 #endif
0262 
0263 /*
0264  * ==== Editing ====
0265  */
0266 typedef struct lineinfow {
0267     const wchar_t   *buffer;
0268     const wchar_t   *cursor;
0269     const wchar_t   *lastchar;
0270 } LineInfoW;
0271 
0272 typedef int (*el_rfunc_t)(EditLine *, wchar_t *);
0273 
0274 const wchar_t   *el_wgets(EditLine *, int *);
0275 int      el_wgetc(EditLine *, wchar_t *);
0276 void         el_wpush(EditLine *, const wchar_t *);
0277 
0278 int      el_wparse(EditLine *, int, const wchar_t **);
0279 
0280 int      el_wset(EditLine *, int, ...);
0281 int      el_wget(EditLine *, int, ...);
0282 
0283 int      el_cursor(EditLine *, int);
0284 const LineInfoW *el_wline(EditLine *);
0285 int      el_winsertstr(EditLine *, const wchar_t *);
0286 #define          el_wdeletestr  el_deletestr
0287 int      el_wreplacestr(EditLine *, const wchar_t *);
0288 
0289 /*
0290  * ==== History ====
0291  */
0292 typedef struct histeventW {
0293     int      num;
0294     const wchar_t   *str;
0295 } HistEventW;
0296 
0297 typedef struct historyW HistoryW;
0298 
0299 HistoryW *  history_winit(void);
0300 void        history_wend(HistoryW *);
0301 
0302 int     history_w(HistoryW *, HistEventW *, int, ...);
0303 
0304 /*
0305  * ==== Tokenization ====
0306  */
0307 typedef struct tokenizerW TokenizerW;
0308 
0309 /* Wide character tokenizer support */
0310 TokenizerW  *tok_winit(const wchar_t *);
0311 void         tok_wend(TokenizerW *);
0312 void         tok_wreset(TokenizerW *);
0313 int      tok_wline(TokenizerW *, const LineInfoW *,
0314             int *, const wchar_t ***, int *, int *);
0315 int      tok_wstr(TokenizerW *, const wchar_t *,
0316             int *, const wchar_t ***);
0317 
0318 #ifdef __cplusplus
0319 }
0320 #endif
0321 
0322 #endif /* _HISTEDIT_H_ */