histedit.h revision 84325
1/* $FreeBSD: head/include/histedit.h 84325 2001-10-01 21:06:25Z obrien $ */ 2/* $NetBSD: histedit.h,v 1.15 2000/02/28 17:41:05 chopps Exp $ */ 3 4/*- 5 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Christos Zoulas of Cornell University. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)histedit.h 8.2 (Berkeley) 1/3/94 40 */ 41 42/* 43 * histedit.h: Line editor and history interface. 44 */ 45#ifndef _h_editline 46#define _h_editline 47 48#include <sys/types.h> 49#include <stdio.h> 50 51/* 52 * ==== Editing ==== 53 */ 54typedef struct editline EditLine; 55 56/* 57 * For user-defined function interface 58 */ 59typedef struct lineinfo { 60 const char *buffer; 61 const char *cursor; 62 const char *lastchar; 63} LineInfo; 64 65 66/* 67 * EditLine editor function return codes. 68 * For user-defined function interface 69 */ 70#define CC_NORM 0 71#define CC_NEWLINE 1 72#define CC_EOF 2 73#define CC_ARGHACK 3 74#define CC_REFRESH 4 75#define CC_CURSOR 5 76#define CC_ERROR 6 77#define CC_FATAL 7 78#define CC_REDISPLAY 8 79#define CC_REFRESH_BEEP 9 80 81/* 82 * Initialization, cleanup, and resetting 83 */ 84EditLine *el_init __P((const char *, FILE *, FILE *, FILE *)); 85void el_reset __P((EditLine *)); 86void el_end __P((EditLine *)); 87 88 89/* 90 * Get a line, a character or push a string back in the input queue 91 */ 92const char *el_gets __P((EditLine *, int *)); 93int el_getc __P((EditLine *, char *)); 94void el_push __P((EditLine *, const char *)); 95 96/* 97 * Beep! 98 */ 99void el_beep(EditLine *); 100 101/* 102 * High level function internals control 103 * Parses argc, argv array and executes builtin editline commands 104 */ 105int el_parse __P((EditLine *, int, char **)); 106 107/* 108 * Low level editline access function 109 */ 110int el_set __P((EditLine *, int, ...)); 111int el_get __P((EditLine *, int, void *)); 112 113/* 114 * el_set/el_get parameters 115 */ 116#define EL_PROMPT 0 /* , el_pfunc_t); */ 117#define EL_TERMINAL 1 /* , const char *); */ 118#define EL_EDITOR 2 /* , const char *); */ 119#define EL_SIGNAL 3 /* , int); */ 120#define EL_BIND 4 /* , const char *, ..., NULL); */ 121#define EL_TELLTC 5 /* , const char *, ..., NULL); */ 122#define EL_SETTC 6 /* , const char *, ..., NULL); */ 123#define EL_ECHOTC 7 /* , const char *, ..., NULL); */ 124#define EL_SETTY 8 /* , const char *, ..., NULL); */ 125#define EL_ADDFN 9 /* , const char *, const char * */ 126 /* , el_func_t); */ 127#define EL_HIST 10 /* , hist_fun_t, const char *); */ 128#define EL_EDITMODE 11 /* , int); */ 129#define EL_RPROMPT 12 /* , el_pfunc_t); */ 130 131/* 132 * Source named file or $PWD/.editrc or $HOME/.editrc 133 */ 134int el_source __P((EditLine *, const char *)); 135 136/* 137 * Must be called when the terminal changes size; If EL_SIGNAL 138 * is set this is done automatically otherwise it is the responsibility 139 * of the application 140 */ 141void el_resize __P((EditLine *)); 142 143 144/* 145 * User-defined function interface. 146 */ 147const LineInfo *el_line __P((EditLine *)); 148int el_insertstr __P((EditLine *, const char *)); 149void el_deletestr __P((EditLine *, int)); 150 151/* 152 * ==== History ==== 153 */ 154 155typedef struct history History; 156 157typedef struct HistEvent { 158 int num; 159 const char *str; 160} HistEvent; 161 162/* 163 * History access functions. 164 */ 165History * history_init __P((void)); 166void history_end __P((History *)); 167 168int history __P((History *, HistEvent *, int, ...)); 169 170#define H_FUNC 0 /* , UTSL */ 171#define H_SETSIZE 1 /* , const int); */ 172#define H_EVENT 1 /* , const int); */ 173#define H_GETSIZE 2 /* , void); */ 174#define H_FIRST 3 /* , void); */ 175#define H_LAST 4 /* , void); */ 176#define H_PREV 5 /* , void); */ 177#define H_NEXT 6 /* , void); */ 178#define H_CURR 8 /* , const int); */ 179#define H_SET 7 /* , void); */ 180#define H_ADD 9 /* , const char *); */ 181#define H_ENTER 10 /* , const char *); */ 182#define H_APPEND 11 /* , const char *); */ 183#define H_END 12 /* , void); */ 184#define H_NEXT_STR 13 /* , const char *); */ 185#define H_PREV_STR 14 /* , const char *); */ 186#define H_NEXT_EVENT 15 /* , const int); */ 187#define H_PREV_EVENT 16 /* , const int); */ 188#define H_LOAD 17 /* , const char *); */ 189#define H_SAVE 18 /* , const char *); */ 190#define H_CLEAR 19 /* , void); */ 191 192#endif /* _h_editline */ 193