1313981Spfg/* $NetBSD: histedit.h,v 1.55 2016/02/17 19:47:49 christos Exp $ */ 2276881Sbapt 31841Swollman/*- 41841Swollman * Copyright (c) 1992, 1993 51841Swollman * The Regents of the University of California. All rights reserved. 61841Swollman * 71841Swollman * This code is derived from software contributed to Berkeley by 81841Swollman * Christos Zoulas of Cornell University. 91841Swollman * 101841Swollman * Redistribution and use in source and binary forms, with or without 111841Swollman * modification, are permitted provided that the following conditions 121841Swollman * are met: 131841Swollman * 1. Redistributions of source code must retain the above copyright 141841Swollman * notice, this list of conditions and the following disclaimer. 151841Swollman * 2. Redistributions in binary form must reproduce the above copyright 161841Swollman * notice, this list of conditions and the following disclaimer in the 171841Swollman * documentation and/or other materials provided with the distribution. 18148834Sstefanf * 3. Neither the name of the University nor the names of its contributors 191841Swollman * may be used to endorse or promote products derived from this software 201841Swollman * without specific prior written permission. 211841Swollman * 221841Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231841Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241841Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251841Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261841Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271841Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281841Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291841Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301841Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311841Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321841Swollman * SUCH DAMAGE. 331841Swollman * 341841Swollman * @(#)histedit.h 8.2 (Berkeley) 1/3/94 3584326Sobrien * $FreeBSD: stable/11/lib/libedit/histedit.h 313981 2017-02-20 03:33:59Z pfg $ 361841Swollman */ 371841Swollman 381841Swollman/* 391841Swollman * histedit.h: Line editor and history interface. 401841Swollman */ 4184326Sobrien#ifndef _HISTEDIT_H_ 4284326Sobrien#define _HISTEDIT_H_ 431841Swollman 44276881Sbapt#define LIBEDIT_MAJOR 2 45276881Sbapt#define LIBEDIT_MINOR 11 46276881Sbapt 471841Swollman#include <sys/types.h> 481841Swollman#include <stdio.h> 491841Swollman 50220370Sobrien#ifdef __cplusplus 51220370Sobrienextern "C" { 52220370Sobrien#endif 53117556Simp 541841Swollman/* 551841Swollman * ==== Editing ==== 561841Swollman */ 57148834Sstefanf 581841Swollmantypedef struct editline EditLine; 591841Swollman 601841Swollman/* 611841Swollman * For user-defined function interface 621841Swollman */ 631841Swollmantypedef struct lineinfo { 6484326Sobrien const char *buffer; 6584326Sobrien const char *cursor; 6684326Sobrien const char *lastchar; 671841Swollman} LineInfo; 681841Swollman 691841Swollman/* 701841Swollman * EditLine editor function return codes. 711841Swollman * For user-defined function interface 721841Swollman */ 731841Swollman#define CC_NORM 0 741841Swollman#define CC_NEWLINE 1 751841Swollman#define CC_EOF 2 7684326Sobrien#define CC_ARGHACK 3 7784326Sobrien#define CC_REFRESH 4 781841Swollman#define CC_CURSOR 5 791841Swollman#define CC_ERROR 6 8084326Sobrien#define CC_FATAL 7 8184326Sobrien#define CC_REDISPLAY 8 8284325Sobrien#define CC_REFRESH_BEEP 9 831841Swollman 841841Swollman/* 851841Swollman * Initialization, cleanup, and resetting 861841Swollman */ 8784326SobrienEditLine *el_init(const char *, FILE *, FILE *, FILE *); 88276881SbaptEditLine *el_init_fd(const char *, FILE *, FILE *, FILE *, 89276881Sbapt int, int, int); 90148834Sstefanfvoid el_end(EditLine *); 9184326Sobrienvoid el_reset(EditLine *); 921841Swollman 931841Swollman/* 941841Swollman * Get a line, a character or push a string back in the input queue 951841Swollman */ 9684326Sobrienconst char *el_gets(EditLine *, int *); 9784326Sobrienint el_getc(EditLine *, char *); 98220370Sobrienvoid el_push(EditLine *, const char *); 991841Swollman 1001841Swollman/* 10184325Sobrien * Beep! 10284325Sobrien */ 10384325Sobrienvoid el_beep(EditLine *); 10484325Sobrien 10584325Sobrien/* 1061841Swollman * High level function internals control 1071841Swollman * Parses argc, argv array and executes builtin editline commands 1081841Swollman */ 109148834Sstefanfint el_parse(EditLine *, int, const char **); 1101841Swollman 1111841Swollman/* 11284326Sobrien * Low level editline access functions 1131841Swollman */ 11484326Sobrienint el_set(EditLine *, int, ...); 115170511Sstefanfint el_get(EditLine *, int, ...); 116148834Sstefanfunsigned char _el_fn_complete(EditLine *, int); 117209219Sjillesunsigned char _el_fn_sh_complete(EditLine *, int); 1181841Swollman 1191841Swollman/* 1201841Swollman * el_set/el_get parameters 121276881Sbapt * 122276881Sbapt * When using el_wset/el_wget (as opposed to el_set/el_get): 123276881Sbapt * Char is wchar_t, otherwise it is char. 124276881Sbapt * prompt_func is el_wpfunc_t, otherwise it is el_pfunc_t . 125276881Sbapt 126276881Sbapt * Prompt function prototypes are: 127276881Sbapt * typedef char *(*el_pfunct_t) (EditLine *); 128276881Sbapt * typedef wchar_t *(*el_wpfunct_t) (EditLine *); 129276881Sbapt * 130276881Sbapt * For operations that support set or set/get, the argument types listed are for 131276881Sbapt * the "set" operation. For "get", each listed type must be a pointer. 132276881Sbapt * E.g. EL_EDITMODE takes an int when set, but an int* when get. 133313981Spfg * 134276881Sbapt * Operations that only support "get" have the correct argument types listed. 1351841Swollman */ 136276881Sbapt#define EL_PROMPT 0 /* , prompt_func); set/get */ 137276881Sbapt#define EL_TERMINAL 1 /* , const char *); set/get */ 138276881Sbapt#define EL_EDITOR 2 /* , const Char *); set/get */ 139276881Sbapt#define EL_SIGNAL 3 /* , int); set/get */ 140276881Sbapt#define EL_BIND 4 /* , const Char *, ..., NULL); set */ 141276881Sbapt#define EL_TELLTC 5 /* , const Char *, ..., NULL); set */ 142276881Sbapt#define EL_SETTC 6 /* , const Char *, ..., NULL); set */ 143276881Sbapt#define EL_ECHOTC 7 /* , const Char *, ..., NULL); set */ 144276881Sbapt#define EL_SETTY 8 /* , const Char *, ..., NULL); set */ 145276881Sbapt#define EL_ADDFN 9 /* , const Char *, const Char, set */ 146313981Spfg /* el_func_t); */ 147276881Sbapt#define EL_HIST 10 /* , hist_fun_t, const void *); set */ 148276881Sbapt#define EL_EDITMODE 11 /* , int); set/get */ 149276881Sbapt#define EL_RPROMPT 12 /* , prompt_func); set/get */ 150276881Sbapt#define EL_GETCFN 13 /* , el_rfunc_t); set/get */ 151276881Sbapt#define EL_CLIENTDATA 14 /* , void *); set/get */ 152276881Sbapt#define EL_UNBUFFERED 15 /* , int); set/get */ 153276881Sbapt#define EL_PREP_TERM 16 /* , int); set */ 154276881Sbapt#define EL_GETTC 17 /* , const Char *, ..., NULL); get */ 155276881Sbapt#define EL_GETFP 18 /* , int, FILE **); get */ 156276881Sbapt#define EL_SETFP 19 /* , int, FILE *); set */ 157220370Sobrien#define EL_REFRESH 20 /* , void); set */ 158220370Sobrien#define EL_PROMPT_ESC 21 /* , prompt_func, Char); set/get */ 159220370Sobrien#define EL_RPROMPT_ESC 22 /* , prompt_func, Char); set/get */ 160220370Sobrien#define EL_RESIZE 23 /* , el_zfunc_t, void *); set */ 161276881Sbapt#define EL_ALIAS_TEXT 24 /* , el_afunc_t, void *); set */ 1621841Swollman 163170547Sstefanf#define EL_BUILTIN_GETCFN (NULL) 164148834Sstefanf 1651841Swollman/* 1661841Swollman * Source named file or $PWD/.editrc or $HOME/.editrc 1671841Swollman */ 16884326Sobrienint el_source(EditLine *, const char *); 1691841Swollman 1701841Swollman/* 1711841Swollman * Must be called when the terminal changes size; If EL_SIGNAL 1721841Swollman * is set this is done automatically otherwise it is the responsibility 1731841Swollman * of the application 1741841Swollman */ 17584326Sobrienvoid el_resize(EditLine *); 1761841Swollman 1771841Swollman/* 1781841Swollman * User-defined function interface. 1791841Swollman */ 18084326Sobrienconst LineInfo *el_line(EditLine *); 18184326Sobrienint el_insertstr(EditLine *, const char *); 18284326Sobrienvoid el_deletestr(EditLine *, int); 1831841Swollman 184148834Sstefanf 1851841Swollman/* 1861841Swollman * ==== History ==== 1871841Swollman */ 1881841Swollman 1891841Swollmantypedef struct history History; 1901841Swollman 1911841Swollmantypedef struct HistEvent { 19284326Sobrien int num; 19384326Sobrien const char *str; 1941841Swollman} HistEvent; 1951841Swollman 1961841Swollman/* 1971841Swollman * History access functions. 1981841Swollman */ 19984326SobrienHistory * history_init(void); 20084326Sobrienvoid history_end(History *); 2011841Swollman 20284326Sobrienint history(History *, HistEvent *, int, ...); 2031841Swollman 20484326Sobrien#define H_FUNC 0 /* , UTSL */ 20584325Sobrien#define H_SETSIZE 1 /* , const int); */ 20684325Sobrien#define H_GETSIZE 2 /* , void); */ 20784325Sobrien#define H_FIRST 3 /* , void); */ 20884325Sobrien#define H_LAST 4 /* , void); */ 20984325Sobrien#define H_PREV 5 /* , void); */ 21084325Sobrien#define H_NEXT 6 /* , void); */ 21184325Sobrien#define H_CURR 8 /* , const int); */ 212148834Sstefanf#define H_SET 7 /* , int); */ 213276881Sbapt#define H_ADD 9 /* , const wchar_t *); */ 214276881Sbapt#define H_ENTER 10 /* , const wchar_t *); */ 215276881Sbapt#define H_APPEND 11 /* , const wchar_t *); */ 21684325Sobrien#define H_END 12 /* , void); */ 217276881Sbapt#define H_NEXT_STR 13 /* , const wchar_t *); */ 218276881Sbapt#define H_PREV_STR 14 /* , const wchar_t *); */ 21984325Sobrien#define H_NEXT_EVENT 15 /* , const int); */ 22084325Sobrien#define H_PREV_EVENT 16 /* , const int); */ 22184325Sobrien#define H_LOAD 17 /* , const char *); */ 22284325Sobrien#define H_SAVE 18 /* , const char *); */ 22384325Sobrien#define H_CLEAR 19 /* , void); */ 224148834Sstefanf#define H_SETUNIQUE 20 /* , int); */ 225148834Sstefanf#define H_GETUNIQUE 21 /* , void); */ 226148834Sstefanf#define H_DEL 22 /* , int); */ 227220370Sobrien#define H_NEXT_EVDATA 23 /* , const int, histdata_t *); */ 228220370Sobrien#define H_DELDATA 24 /* , int, histdata_t *);*/ 229220370Sobrien#define H_REPLACE 25 /* , const char *, histdata_t); */ 230276881Sbapt#define H_SAVE_FP 26 /* , FILE *); */ 2311841Swollman 232148834Sstefanf 233276881Sbapt 234148834Sstefanf/* 235148834Sstefanf * ==== Tokenization ==== 236148834Sstefanf */ 237148834Sstefanf 238148834Sstefanftypedef struct tokenizer Tokenizer; 239148834Sstefanf 240148834Sstefanf/* 241148834Sstefanf * String tokenization functions, using simplified sh(1) quoting rules 242148834Sstefanf */ 243148834SstefanfTokenizer *tok_init(const char *); 244148834Sstefanfvoid tok_end(Tokenizer *); 245148834Sstefanfvoid tok_reset(Tokenizer *); 246148834Sstefanfint tok_line(Tokenizer *, const LineInfo *, 247148834Sstefanf int *, const char ***, int *, int *); 248148834Sstefanfint tok_str(Tokenizer *, const char *, 249148834Sstefanf int *, const char ***); 250148834Sstefanf 251276881Sbapt/* 252276881Sbapt * Begin Wide Character Support 253276881Sbapt */ 254276881Sbapt#include <wchar.h> 255276881Sbapt#include <wctype.h> 256276881Sbapt 257276881Sbapt/* 258276881Sbapt * ==== Editing ==== 259276881Sbapt */ 260276881Sbapttypedef struct lineinfow { 261276881Sbapt const wchar_t *buffer; 262276881Sbapt const wchar_t *cursor; 263276881Sbapt const wchar_t *lastchar; 264276881Sbapt} LineInfoW; 265276881Sbapt 266276881Sbaptconst wchar_t *el_wgets(EditLine *, int *); 267276881Sbaptint el_wgetc(EditLine *, wchar_t *); 268276881Sbaptvoid el_wpush(EditLine *, const wchar_t *); 269276881Sbapt 270276881Sbaptint el_wparse(EditLine *, int, const wchar_t **); 271276881Sbapt 272276881Sbaptint el_wset(EditLine *, int, ...); 273276881Sbaptint el_wget(EditLine *, int, ...); 274276881Sbapt 275276881Sbaptint el_cursor(EditLine *, int); 276276881Sbaptconst LineInfoW *el_wline(EditLine *); 277276881Sbaptint el_winsertstr(EditLine *, const wchar_t *); 278276881Sbapt#define el_wdeletestr el_deletestr 279276881Sbapt 280276881Sbapt/* 281276881Sbapt * ==== History ==== 282276881Sbapt */ 283276881Sbapttypedef struct histeventW { 284276881Sbapt int num; 285276881Sbapt const wchar_t *str; 286276881Sbapt} HistEventW; 287276881Sbapt 288276881Sbapttypedef struct historyW HistoryW; 289276881Sbapt 290276881SbaptHistoryW * history_winit(void); 291276881Sbaptvoid history_wend(HistoryW *); 292276881Sbapt 293276881Sbaptint history_w(HistoryW *, HistEventW *, int, ...); 294276881Sbapt 295276881Sbapt/* 296276881Sbapt * ==== Tokenization ==== 297276881Sbapt */ 298276881Sbapttypedef struct tokenizerW TokenizerW; 299276881Sbapt 300276881Sbapt/* Wide character tokenizer support */ 301276881SbaptTokenizerW *tok_winit(const wchar_t *); 302276881Sbaptvoid tok_wend(TokenizerW *); 303276881Sbaptvoid tok_wreset(TokenizerW *); 304276881Sbaptint tok_wline(TokenizerW *, const LineInfoW *, 305276881Sbapt int *, const wchar_t ***, int *, int *); 306276881Sbaptint tok_wstr(TokenizerW *, const wchar_t *, 307276881Sbapt int *, const wchar_t ***); 308276881Sbapt 309220370Sobrien#ifdef __cplusplus 310220370Sobrien} 311220370Sobrien#endif 312117556Simp 31384326Sobrien#endif /* _HISTEDIT_H_ */ 314