histedit.h revision 276881
117680Spst/* $NetBSD: histedit.h,v 1.53 2014/06/18 18:12:28 christos Exp $ */ 239300Sfenner 317680Spst/*- 417680Spst * Copyright (c) 1992, 1993 517680Spst * The Regents of the University of California. All rights reserved. 617680Spst * 717680Spst * This code is derived from software contributed to Berkeley by 817680Spst * Christos Zoulas of Cornell University. 917680Spst * 1017680Spst * Redistribution and use in source and binary forms, with or without 1117680Spst * modification, are permitted provided that the following conditions 1217680Spst * are met: 1317680Spst * 1. Redistributions of source code must retain the above copyright 1417680Spst * notice, this list of conditions and the following disclaimer. 1517680Spst * 2. Redistributions in binary form must reproduce the above copyright 1617680Spst * notice, this list of conditions and the following disclaimer in the 1717680Spst * documentation and/or other materials provided with the distribution. 1817680Spst * 3. Neither the name of the University nor the names of its contributors 1917680Spst * may be used to endorse or promote products derived from this software 2056896Sfenner * without specific prior written permission. 2156896Sfenner * 2217680Spst * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2317680Spst * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2417680Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2526183Sfenner * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2675118Sfenner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2717680Spst * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2817680Spst * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2956896Sfenner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3056896Sfenner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3156896Sfenner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3256896Sfenner * SUCH DAMAGE. 3317680Spst * 3417680Spst * @(#)histedit.h 8.2 (Berkeley) 1/3/94 3517680Spst * $FreeBSD: head/lib/libedit/histedit.h 276881 2015-01-09 07:40:56Z bapt $ 3617680Spst */ 3717680Spst 3839300Sfenner/* 3939300Sfenner * histedit.h: Line editor and history interface. 4039300Sfenner */ 4117680Spst#ifndef _HISTEDIT_H_ 4217680Spst#define _HISTEDIT_H_ 4317680Spst 4417680Spst#define LIBEDIT_MAJOR 2 4517680Spst#define LIBEDIT_MINOR 11 4675118Sfenner 4717680Spst#include <sys/types.h> 4817680Spst#include <stdio.h> 4917680Spst 5017680Spst#ifdef __cplusplus 5117680Spstextern "C" { 5275118Sfenner#endif 5375118Sfenner 5475118Sfenner/* 5575118Sfenner * ==== Editing ==== 5675118Sfenner */ 5775118Sfenner 5875118Sfennertypedef struct editline EditLine; 5975118Sfenner 6075118Sfenner/* 6175118Sfenner * For user-defined function interface 6275118Sfenner */ 6375118Sfennertypedef struct lineinfo { 6475118Sfenner const char *buffer; 6575118Sfenner const char *cursor; 6619001Spst const char *lastchar; 6717680Spst} LineInfo; 6817680Spst 6917680Spst/* 7075118Sfenner * EditLine editor function return codes. 7175118Sfenner * For user-defined function interface 7275118Sfenner */ 7317680Spst#define CC_NORM 0 7417680Spst#define CC_NEWLINE 1 7517680Spst#define CC_EOF 2 7675118Sfenner#define CC_ARGHACK 3 7775118Sfenner#define CC_REFRESH 4 7817680Spst#define CC_CURSOR 5 7917680Spst#define CC_ERROR 6 8017680Spst#define CC_FATAL 7 8117680Spst#define CC_REDISPLAY 8 8217680Spst#define CC_REFRESH_BEEP 9 8317680Spst 8417680Spst/* 8575118Sfenner * Initialization, cleanup, and resetting 8675118Sfenner */ 8775118SfennerEditLine *el_init(const char *, FILE *, FILE *, FILE *); 8817680SpstEditLine *el_init_fd(const char *, FILE *, FILE *, FILE *, 8917680Spst int, int, int); 9017680Spstvoid el_end(EditLine *); 9117680Spstvoid el_reset(EditLine *); 9217680Spst 9317680Spst/* 9417680Spst * Get a line, a character or push a string back in the input queue 9575118Sfenner */ 9675118Sfennerconst char *el_gets(EditLine *, int *); 9775118Sfennerint el_getc(EditLine *, char *); 9875118Sfennervoid el_push(EditLine *, const char *); 9975118Sfenner 10075118Sfenner/* 10117680Spst * Beep! 10217680Spst */ 10317680Spstvoid el_beep(EditLine *); 10426183Sfenner 10526183Sfenner/* 10626183Sfenner * High level function internals control 10717680Spst * Parses argc, argv array and executes builtin editline commands 10817680Spst */ 10917680Spstint el_parse(EditLine *, int, const char **); 11017680Spst 11117680Spst/* 11217680Spst * Low level editline access functions 11326183Sfenner */ 11426183Sfennerint el_set(EditLine *, int, ...); 11526183Sfennerint el_get(EditLine *, int, ...); 11626183Sfennerunsigned char _el_fn_complete(EditLine *, int); 11717680Spstunsigned char _el_fn_sh_complete(EditLine *, int); 11817680Spst 11917680Spst/* 12017680Spst * el_set/el_get parameters 12117680Spst * 12275118Sfenner * When using el_wset/el_wget (as opposed to el_set/el_get): 12317680Spst * Char is wchar_t, otherwise it is char. 12417680Spst * prompt_func is el_wpfunc_t, otherwise it is el_pfunc_t . 12517680Spst 12617680Spst * Prompt function prototypes are: 12717680Spst * typedef char *(*el_pfunct_t) (EditLine *); 12817680Spst * typedef wchar_t *(*el_wpfunct_t) (EditLine *); 12917680Spst * 13075118Sfenner * For operations that support set or set/get, the argument types listed are for 13175118Sfenner * the "set" operation. For "get", each listed type must be a pointer. 13217680Spst * E.g. EL_EDITMODE takes an int when set, but an int* when get. 13317680Spst * 13417680Spst * Operations that only support "get" have the correct argument types listed. 13517680Spst */ 13617680Spst#define EL_PROMPT 0 /* , prompt_func); set/get */ 13717680Spst#define EL_TERMINAL 1 /* , const char *); set/get */ 13817680Spst#define EL_EDITOR 2 /* , const Char *); set/get */ 13917680Spst#define EL_SIGNAL 3 /* , int); set/get */ 14017680Spst#define EL_BIND 4 /* , const Char *, ..., NULL); set */ 14117680Spst#define EL_TELLTC 5 /* , const Char *, ..., NULL); set */ 14217680Spst#define EL_SETTC 6 /* , const Char *, ..., NULL); set */ 14317680Spst#define EL_ECHOTC 7 /* , const Char *, ..., NULL); set */ 14417680Spst#define EL_SETTY 8 /* , const Char *, ..., NULL); set */ 14517680Spst#define EL_ADDFN 9 /* , const Char *, const Char, set */ 14617680Spst /* el_func_t); */ 14717680Spst#define EL_HIST 10 /* , hist_fun_t, const void *); set */ 14817680Spst#define EL_EDITMODE 11 /* , int); set/get */ 14926183Sfenner#define EL_RPROMPT 12 /* , prompt_func); set/get */ 15075118Sfenner#define EL_GETCFN 13 /* , el_rfunc_t); set/get */ 15175118Sfenner#define EL_CLIENTDATA 14 /* , void *); set/get */ 15217680Spst#define EL_UNBUFFERED 15 /* , int); set/get */ 15326183Sfenner#define EL_PREP_TERM 16 /* , int); set */ 15417680Spst#define EL_GETTC 17 /* , const Char *, ..., NULL); get */ 15517680Spst#define EL_GETFP 18 /* , int, FILE **); get */ 15617680Spst#define EL_SETFP 19 /* , int, FILE *); set */ 15717680Spst#define EL_REFRESH 20 /* , void); set */ 15826183Sfenner#define EL_PROMPT_ESC 21 /* , prompt_func, Char); set/get */ 15926183Sfenner#define EL_RPROMPT_ESC 22 /* , prompt_func, Char); set/get */ 16017680Spst#define EL_RESIZE 23 /* , el_zfunc_t, void *); set */ 16117680Spst#define EL_ALIAS_TEXT 24 /* , el_afunc_t, void *); set */ 16217680Spst 16317680Spst#define EL_BUILTIN_GETCFN (NULL) 16417680Spst 16517680Spst/* 16626183Sfenner * Source named file or $PWD/.editrc or $HOME/.editrc 16717680Spst */ 16826183Sfennerint el_source(EditLine *, const char *); 16917680Spst 17017680Spst/* 17117680Spst * Must be called when the terminal changes size; If EL_SIGNAL 17217680Spst * is set this is done automatically otherwise it is the responsibility 17317680Spst * of the application 17417680Spst */ 17517680Spstvoid el_resize(EditLine *); 17626183Sfenner 17717680Spst/* 17817680Spst * User-defined function interface. 17917680Spst */ 18026183Sfennerconst LineInfo *el_line(EditLine *); 18117680Spstint el_insertstr(EditLine *, const char *); 18226183Sfennervoid el_deletestr(EditLine *, int); 18326183Sfenner 18417680Spst 18575118Sfenner/* 18617680Spst * ==== History ==== 18717680Spst */ 18817680Spst 18917680Spsttypedef struct history History; 19017680Spst 19117680Spsttypedef struct HistEvent { 19217680Spst int num; 19317680Spst const char *str; 19417680Spst} HistEvent; 19517680Spst 19626183Sfenner/* 19717680Spst * History access functions. 19817680Spst */ 19926183SfennerHistory * history_init(void); 20026183Sfennervoid history_end(History *); 20126183Sfenner 20226183Sfennerint history(History *, HistEvent *, int, ...); 20326183Sfenner 20426183Sfenner#define H_FUNC 0 /* , UTSL */ 20526183Sfenner#define H_SETSIZE 1 /* , const int); */ 20626183Sfenner#define H_GETSIZE 2 /* , void); */ 20726183Sfenner#define H_FIRST 3 /* , void); */ 20826183Sfenner#define H_LAST 4 /* , void); */ 20926183Sfenner#define H_PREV 5 /* , void); */ 21017680Spst#define H_NEXT 6 /* , void); */ 21117680Spst#define H_CURR 8 /* , const int); */ 21217680Spst#define H_SET 7 /* , int); */ 21317680Spst#define H_ADD 9 /* , const wchar_t *); */ 21426183Sfenner#define H_ENTER 10 /* , const wchar_t *); */ 21526183Sfenner#define H_APPEND 11 /* , const wchar_t *); */ 21617680Spst#define H_END 12 /* , void); */ 21717680Spst#define H_NEXT_STR 13 /* , const wchar_t *); */ 21826183Sfenner#define H_PREV_STR 14 /* , const wchar_t *); */ 21926183Sfenner#define H_NEXT_EVENT 15 /* , const int); */ 22026183Sfenner#define H_PREV_EVENT 16 /* , const int); */ 22126183Sfenner#define H_LOAD 17 /* , const char *); */ 22275118Sfenner#define H_SAVE 18 /* , const char *); */ 22326183Sfenner#define H_CLEAR 19 /* , void); */ 22426183Sfenner#define H_SETUNIQUE 20 /* , int); */ 22526183Sfenner#define H_GETUNIQUE 21 /* , void); */ 22626183Sfenner#define H_DEL 22 /* , int); */ 22726183Sfenner#define H_NEXT_EVDATA 23 /* , const int, histdata_t *); */ 22826183Sfenner#define H_DELDATA 24 /* , int, histdata_t *);*/ 22926183Sfenner#define H_REPLACE 25 /* , const char *, histdata_t); */ 23026183Sfenner#define H_SAVE_FP 26 /* , FILE *); */ 23126183Sfenner 23217680Spst 23317680Spst 23426183Sfenner/* 23517680Spst * ==== Tokenization ==== 23617680Spst */ 23717680Spst 23826183Sfennertypedef struct tokenizer Tokenizer; 23975118Sfenner 24026183Sfenner/* 24126183Sfenner * String tokenization functions, using simplified sh(1) quoting rules 24226183Sfenner */ 24326183SfennerTokenizer *tok_init(const char *); 24426183Sfennervoid tok_end(Tokenizer *); 24526183Sfennervoid tok_reset(Tokenizer *); 24626183Sfennerint tok_line(Tokenizer *, const LineInfo *, 24726183Sfenner int *, const char ***, int *, int *); 24826183Sfennerint tok_str(Tokenizer *, const char *, 24926183Sfenner int *, const char ***); 25017680Spst 25117680Spst/* 25217680Spst * Begin Wide Character Support 25317680Spst */ 25417680Spst#ifdef __linux__ 25526183Sfenner/* Apparently we need _GNU_SOURCE defined to get access to wcsdup on Linux */ 25626183Sfenner#ifndef _GNU_SOURCE 25775118Sfenner#define _GNU_SOURCE 25817680Spst#endif 25917680Spst#endif 26017680Spst 26126183Sfenner#include <wchar.h> 26275118Sfenner#include <wctype.h> 26317680Spst 26417680Spst/* 26517680Spst * Wide character versions 26617680Spst */ 26726183Sfenner 26875118Sfenner/* 26917680Spst * ==== Editing ==== 27017680Spst */ 27117680Spsttypedef struct lineinfow { 27217680Spst const wchar_t *buffer; 27317680Spst const wchar_t *cursor; 27417680Spst const wchar_t *lastchar; 27517680Spst} LineInfoW; 27617680Spst 27717680Spstconst wchar_t *el_wgets(EditLine *, int *); 27817680Spstint el_wgetc(EditLine *, wchar_t *); 27926183Sfennervoid el_wpush(EditLine *, const wchar_t *); 28017680Spst 28126183Sfennerint el_wparse(EditLine *, int, const wchar_t **); 28217680Spst 28317680Spstint el_wset(EditLine *, int, ...); 28417680Spstint el_wget(EditLine *, int, ...); 28517680Spst 28617680Spstint el_cursor(EditLine *, int); 28726183Sfennerconst LineInfoW *el_wline(EditLine *); 28826183Sfennerint el_winsertstr(EditLine *, const wchar_t *); 28926183Sfenner#define el_wdeletestr el_deletestr 29026183Sfenner 29117680Spst/* 29217680Spst * ==== History ==== 29317680Spst */ 29417680Spsttypedef struct histeventW { 29575118Sfenner int num; 29675118Sfenner const wchar_t *str; 29775118Sfenner} HistEventW; 29875118Sfenner 29975118Sfennertypedef struct historyW HistoryW; 30075118Sfenner 30175118SfennerHistoryW * history_winit(void); 30275118Sfennervoid history_wend(HistoryW *); 30375118Sfenner 30475118Sfennerint history_w(HistoryW *, HistEventW *, int, ...); 30575118Sfenner 30675118Sfenner/* 30775118Sfenner * ==== Tokenization ==== 30875118Sfenner */ 30975118Sfennertypedef struct tokenizerW TokenizerW; 31075118Sfenner 31175118Sfenner/* Wide character tokenizer support */ 31275118SfennerTokenizerW *tok_winit(const wchar_t *); 31375118Sfennervoid tok_wend(TokenizerW *); 31475118Sfennervoid tok_wreset(TokenizerW *); 31575118Sfennerint tok_wline(TokenizerW *, const LineInfoW *, 31675118Sfenner int *, const wchar_t ***, int *, int *); 31775118Sfennerint tok_wstr(TokenizerW *, const wchar_t *, 31875118Sfenner int *, const wchar_t ***); 31975118Sfenner 32075118Sfenner#ifdef __cplusplus 32175118Sfenner} 32275118Sfenner#endif 32375118Sfenner 32475118Sfenner#endif /* _HISTEDIT_H_ */ 32575118Sfenner