histedit.h revision 1841
11841Swollman/*- 21841Swollman * Copyright (c) 1992, 1993 31841Swollman * The Regents of the University of California. All rights reserved. 41841Swollman * 51841Swollman * This code is derived from software contributed to Berkeley by 61841Swollman * Christos Zoulas of Cornell University. 71841Swollman * 81841Swollman * Redistribution and use in source and binary forms, with or without 91841Swollman * modification, are permitted provided that the following conditions 101841Swollman * are met: 111841Swollman * 1. Redistributions of source code must retain the above copyright 121841Swollman * notice, this list of conditions and the following disclaimer. 131841Swollman * 2. Redistributions in binary form must reproduce the above copyright 141841Swollman * notice, this list of conditions and the following disclaimer in the 151841Swollman * documentation and/or other materials provided with the distribution. 161841Swollman * 3. All advertising materials mentioning features or use of this software 171841Swollman * must display the following acknowledgement: 181841Swollman * This product includes software developed by the University of 191841Swollman * California, Berkeley and its contributors. 201841Swollman * 4. Neither the name of the University nor the names of its contributors 211841Swollman * may be used to endorse or promote products derived from this software 221841Swollman * without specific prior written permission. 231841Swollman * 241841Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251841Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261841Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271841Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281841Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291841Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301841Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311841Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321841Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331841Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341841Swollman * SUCH DAMAGE. 351841Swollman * 361841Swollman * @(#)histedit.h 8.2 (Berkeley) 1/3/94 371841Swollman */ 381841Swollman 391841Swollman/* 401841Swollman * histedit.h: Line editor and history interface. 411841Swollman */ 421841Swollman#ifndef _h_editline 431841Swollman#define _h_editline 441841Swollman 451841Swollman#include <sys/types.h> 461841Swollman#include <stdio.h> 471841Swollman 481841Swollman/* 491841Swollman * ==== Editing ==== 501841Swollman */ 511841Swollmantypedef struct editline EditLine; 521841Swollman 531841Swollman/* 541841Swollman * For user-defined function interface 551841Swollman */ 561841Swollmantypedef struct lineinfo { 571841Swollman __const char *buffer; 581841Swollman __const char *cursor; 591841Swollman __const char *lastchar; 601841Swollman} LineInfo; 611841Swollman 621841Swollman 631841Swollman/* 641841Swollman * EditLine editor function return codes. 651841Swollman * For user-defined function interface 661841Swollman */ 671841Swollman#define CC_NORM 0 681841Swollman#define CC_NEWLINE 1 691841Swollman#define CC_EOF 2 701841Swollman#define CC_ARGHACK 3 711841Swollman#define CC_REFRESH 4 721841Swollman#define CC_CURSOR 5 731841Swollman#define CC_ERROR 6 741841Swollman#define CC_FATAL 7 751841Swollman 761841Swollman/* 771841Swollman * Initialization, cleanup, and resetting 781841Swollman */ 791841SwollmanEditLine *el_init __P((const char *, FILE *, FILE *)); 801841Swollmanvoid el_reset __P((EditLine *)); 811841Swollmanvoid el_end __P((EditLine *)); 821841Swollman 831841Swollman 841841Swollman/* 851841Swollman * Get a line, a character or push a string back in the input queue 861841Swollman */ 871841Swollman__const char *el_gets __P((EditLine *, int *)); 881841Swollmanint el_getc __P((EditLine *, char *)); 891841Swollmanvoid el_push __P((EditLine *, const char *)); 901841Swollman 911841Swollman/* 921841Swollman * High level function internals control 931841Swollman * Parses argc, argv array and executes builtin editline commands 941841Swollman */ 951841Swollmanint el_parse __P((EditLine *, int, char **)); 961841Swollman 971841Swollman/* 981841Swollman * Low level editline access function 991841Swollman */ 1001841Swollmanint el_set __P((EditLine *, int, ...)); 1011841Swollman 1021841Swollman/* 1031841Swollman * el_set/el_get parameters 1041841Swollman */ 1051841Swollman#define EL_PROMPT 0 /* , el_pfunc_t); */ 1061841Swollman#define EL_TERMINAL 1 /* , const char *); */ 1071841Swollman#define EL_EDITOR 2 /* , const char *); */ 1081841Swollman#define EL_SIGNAL 3 /* , int); */ 1091841Swollman#define EL_BIND 4 /* , const char *, ..., NULL); */ 1101841Swollman#define EL_TELLTC 5 /* , const char *, ..., NULL); */ 1111841Swollman#define EL_SETTC 6 /* , const char *, ..., NULL); */ 1121841Swollman#define EL_ECHOTC 7 /* , const char *, ..., NULL); */ 1131841Swollman#define EL_SETTY 8 /* , const char *, ..., NULL); */ 1141841Swollman#define EL_ADDFN 9 /* , const char *, const char * */ 1151841Swollman /* , el_func_t); */ 1161841Swollman#define EL_HIST 10 /* , hist_fun_t, const char *); */ 1171841Swollman 1181841Swollman/* 1191841Swollman * Source named file or $PWD/.editrc or $HOME/.editrc 1201841Swollman */ 1211841Swollmanint el_source __P((EditLine *, const char *)); 1221841Swollman 1231841Swollman/* 1241841Swollman * Must be called when the terminal changes size; If EL_SIGNAL 1251841Swollman * is set this is done automatically otherwise it is the responsibility 1261841Swollman * of the application 1271841Swollman */ 1281841Swollmanvoid el_resize __P((EditLine *)); 1291841Swollman 1301841Swollman 1311841Swollman/* 1321841Swollman * User-defined function interface. 1331841Swollman */ 1341841Swollman__const LineInfo *el_line __P((EditLine *)); 1351841Swollmanint el_insertstr __P((EditLine *, char *)); 1361841Swollmanvoid el_deletestr __P((EditLine *, int)); 1371841Swollman 1381841Swollman/* 1391841Swollman * ==== History ==== 1401841Swollman */ 1411841Swollman 1421841Swollmantypedef struct history History; 1431841Swollman 1441841Swollmantypedef struct HistEvent { 1451841Swollman int num; 1461841Swollman __const char *str; 1471841Swollman} HistEvent; 1481841Swollman 1491841Swollman/* 1501841Swollman * History access functions. 1511841Swollman */ 1521841SwollmanHistory * history_init __P((void)); 1531841Swollmanvoid history_end __P((History *)); 1541841Swollman 1551841Swollman__const HistEvent * history __P((History *, int, ...)); 1561841Swollman 1571841Swollman#define H_FUNC 0 /* , UTSL */ 1581841Swollman#define H_EVENT 1 /* , const int); */ 1591841Swollman#define H_FIRST 2 /* , void); */ 1601841Swollman#define H_LAST 3 /* , void); */ 1611841Swollman#define H_PREV 4 /* , void); */ 1621841Swollman#define H_NEXT 5 /* , void); */ 1631841Swollman#define H_CURR 6 /* , void); */ 1641841Swollman#define H_ADD 7 /* , const char*); */ 1651841Swollman#define H_ENTER 8 /* , const char*); */ 1661841Swollman#define H_END 9 /* , void); */ 1671841Swollman#define H_NEXT_STR 10 /* , const char*); */ 1681841Swollman#define H_PREV_STR 11 /* , const char*); */ 1691841Swollman#define H_NEXT_EVENT 12 /* , const int); */ 1701841Swollman#define H_PREV_EVENT 13 /* , const int); */ 1711841Swollman 1721841Swollman#endif /* _h_editline */ 173