Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:30:02

0001 /*  $NetBSD: histedit.h,v 1.57 2017/09/01 10:19:10 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 
0117 /*
0118  * el_set/el_get parameters
0119  *
0120  * When using el_wset/el_wget (as opposed to el_set/el_get):
0121  *   Char is wchar_t, otherwise it is char.
0122  *   prompt_func is el_wpfunc_t, otherwise it is el_pfunc_t .
0123 
0124  * Prompt function prototypes are:
0125  *   typedef char    *(*el_pfunct_t)  (EditLine *);
0126  *   typedef wchar_t *(*el_wpfunct_t) (EditLine *);
0127  *
0128  * For operations that support set or set/get, the argument types listed are for
0129  * the "set" operation. For "get", each listed type must be a pointer.
0130  * E.g. EL_EDITMODE takes an int when set, but an int* when get.
0131  *
0132  * Operations that only support "get" have the correct argument types listed.
0133  */
0134 #define EL_PROMPT   0   /* , prompt_func);            set/get */
0135 #define EL_TERMINAL 1   /* , const char *);           set/get */
0136 #define EL_EDITOR   2   /* , const Char *);           set/get */
0137 #define EL_SIGNAL   3   /* , int);                set/get */
0138 #define EL_BIND     4   /* , const Char *, ..., NULL);        set     */
0139 #define EL_TELLTC   5   /* , const Char *, ..., NULL);        set     */
0140 #define EL_SETTC    6   /* , const Char *, ..., NULL);        set     */
0141 #define EL_ECHOTC   7   /* , const Char *, ..., NULL);        set     */
0142 #define EL_SETTY    8   /* , const Char *, ..., NULL);        set     */
0143 #define EL_ADDFN    9   /* , const Char *, const Char,        set     */
0144                 /*   el_func_t);                  */
0145 #define EL_HIST     10  /* , hist_fun_t, const void *);       set     */
0146 #define EL_EDITMODE 11  /* , int);                set/get */
0147 #define EL_RPROMPT  12  /* , prompt_func);            set/get */
0148 #define EL_GETCFN   13  /* , el_rfunc_t);             set/get */
0149 #define EL_CLIENTDATA   14  /* , void *);                 set/get */
0150 #define EL_UNBUFFERED   15  /* , int);                set/get */
0151 #define EL_PREP_TERM    16  /* , int);                set     */
0152 #define EL_GETTC    17  /* , const Char *, ..., NULL);        get */
0153 #define EL_GETFP    18  /* , int, FILE **);               get */
0154 #define EL_SETFP    19  /* , int, FILE *);            set     */
0155 #define EL_REFRESH  20  /* , void);               set     */
0156 #define EL_PROMPT_ESC   21  /* , prompt_func, Char);          set/get */
0157 #define EL_RPROMPT_ESC  22  /* , prompt_func, Char);          set/get */
0158 #define EL_RESIZE   23  /* , el_zfunc_t, void *);         set     */
0159 #define EL_ALIAS_TEXT   24  /* , el_afunc_t, void *);         set     */
0160 
0161 #define EL_BUILTIN_GETCFN   (NULL)
0162 
0163 /*
0164  * Source named file or $PWD/.editrc or $HOME/.editrc
0165  */
0166 int     el_source(EditLine *, const char *);
0167 
0168 /*
0169  * Must be called when the terminal changes size; If EL_SIGNAL
0170  * is set this is done automatically otherwise it is the responsibility
0171  * of the application
0172  */
0173 void         el_resize(EditLine *);
0174 
0175 /*
0176  * User-defined function interface.
0177  */
0178 const LineInfo  *el_line(EditLine *);
0179 int      el_insertstr(EditLine *, const char *);
0180 void         el_deletestr(EditLine *, int);
0181 
0182 
0183 /*
0184  * ==== History ====
0185  */
0186 
0187 typedef struct history History;
0188 
0189 typedef struct HistEvent {
0190     int      num;
0191     const char  *str;
0192 } HistEvent;
0193 
0194 /*
0195  * History access functions.
0196  */
0197 History *   history_init(void);
0198 void        history_end(History *);
0199 
0200 int     history(History *, HistEvent *, int, ...);
0201 
0202 #define H_FUNC       0  /* , UTSL       */
0203 #define H_SETSIZE    1  /* , const int);    */
0204 #define H_GETSIZE    2  /* , void);     */
0205 #define H_FIRST      3  /* , void);     */
0206 #define H_LAST       4  /* , void);     */
0207 #define H_PREV       5  /* , void);     */
0208 #define H_NEXT       6  /* , void);     */
0209 #define H_CURR       8  /* , const int);    */
0210 #define H_SET        7  /* , int);      */
0211 #define H_ADD        9  /* , const wchar_t *);  */
0212 #define H_ENTER     10  /* , const wchar_t *);  */
0213 #define H_APPEND    11  /* , const wchar_t *);  */
0214 #define H_END       12  /* , void);     */
0215 #define H_NEXT_STR  13  /* , const wchar_t *);  */
0216 #define H_PREV_STR  14  /* , const wchar_t *);  */
0217 #define H_NEXT_EVENT    15  /* , const int);    */
0218 #define H_PREV_EVENT    16  /* , const int);    */
0219 #define H_LOAD      17  /* , const char *); */
0220 #define H_SAVE      18  /* , const char *); */
0221 #define H_CLEAR     19  /* , void);     */
0222 #define H_SETUNIQUE 20  /* , int);      */
0223 #define H_GETUNIQUE 21  /* , void);     */
0224 #define H_DEL       22  /* , int);      */
0225 #define H_NEXT_EVDATA   23  /* , const int, histdata_t *);  */
0226 #define H_DELDATA   24  /* , int, histdata_t *);*/
0227 #define H_REPLACE   25  /* , const char *, histdata_t); */
0228 #define H_SAVE_FP   26  /* , FILE *);       */
0229 #define H_NSAVE_FP  27  /* , size_t, FILE *);   */
0230 
0231 
0232 
0233 /*
0234  * ==== Tokenization ====
0235  */
0236 
0237 typedef struct tokenizer Tokenizer;
0238 
0239 /*
0240  * String tokenization functions, using simplified sh(1) quoting rules
0241  */
0242 Tokenizer   *tok_init(const char *);
0243 void         tok_end(Tokenizer *);
0244 void         tok_reset(Tokenizer *);
0245 int      tok_line(Tokenizer *, const LineInfo *,
0246             int *, const char ***, int *, int *);
0247 int      tok_str(Tokenizer *, const char *,
0248             int *, const char ***);
0249 
0250 /*
0251  * Begin Wide Character Support
0252  */
0253 #include <wchar.h>
0254 #include <wctype.h>
0255 
0256 /*
0257  * ==== Editing ====
0258  */
0259 typedef struct lineinfow {
0260     const wchar_t   *buffer;
0261     const wchar_t   *cursor;
0262     const wchar_t   *lastchar;
0263 } LineInfoW;
0264 
0265 typedef int (*el_rfunc_t)(EditLine *, wchar_t *);
0266 
0267 const wchar_t   *el_wgets(EditLine *, int *);
0268 int      el_wgetc(EditLine *, wchar_t *);
0269 void         el_wpush(EditLine *, const wchar_t *);
0270 
0271 int      el_wparse(EditLine *, int, const wchar_t **);
0272 
0273 int      el_wset(EditLine *, int, ...);
0274 int      el_wget(EditLine *, int, ...);
0275 
0276 int      el_cursor(EditLine *, int);
0277 const LineInfoW *el_wline(EditLine *);
0278 int      el_winsertstr(EditLine *, const wchar_t *);
0279 #define          el_wdeletestr  el_deletestr
0280 
0281 /*
0282  * ==== History ====
0283  */
0284 typedef struct histeventW {
0285     int      num;
0286     const wchar_t   *str;
0287 } HistEventW;
0288 
0289 typedef struct historyW HistoryW;
0290 
0291 HistoryW *  history_winit(void);
0292 void        history_wend(HistoryW *);
0293 
0294 int     history_w(HistoryW *, HistEventW *, int, ...);
0295 
0296 /*
0297  * ==== Tokenization ====
0298  */
0299 typedef struct tokenizerW TokenizerW;
0300 
0301 /* Wide character tokenizer support */
0302 TokenizerW  *tok_winit(const wchar_t *);
0303 void         tok_wend(TokenizerW *);
0304 void         tok_wreset(TokenizerW *);
0305 int      tok_wline(TokenizerW *, const LineInfoW *,
0306             int *, const wchar_t ***, int *, int *);
0307 int      tok_wstr(TokenizerW *, const wchar_t *,
0308             int *, const wchar_t ***);
0309 
0310 #ifdef __cplusplus
0311 }
0312 #endif
0313 
0314 #endif /* _HISTEDIT_H_ */