histedit.h revision 170511
1139804Simp/*- 293835Stmm * Copyright (c) 1992, 1993 393835Stmm * The Regents of the University of California. All rights reserved. 493835Stmm * 593835Stmm * This code is derived from software contributed to Berkeley by 693835Stmm * Christos Zoulas of Cornell University. 793835Stmm * 893835Stmm * Redistribution and use in source and binary forms, with or without 993835Stmm * modification, are permitted provided that the following conditions 1093835Stmm * are met: 1193835Stmm * 1. Redistributions of source code must retain the above copyright 1293835Stmm * notice, this list of conditions and the following disclaimer. 1393835Stmm * 2. Redistributions in binary form must reproduce the above copyright 1493835Stmm * notice, this list of conditions and the following disclaimer in the 1593835Stmm * documentation and/or other materials provided with the distribution. 1693835Stmm * 3. Neither the name of the University nor the names of its contributors 1793835Stmm * may be used to endorse or promote products derived from this software 1893835Stmm * without specific prior written permission. 1993835Stmm * 2093835Stmm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2193835Stmm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2293835Stmm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2393835Stmm * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2493835Stmm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2593835Stmm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2693835Stmm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2793835Stmm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2893835Stmm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2993835Stmm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3093835Stmm * SUCH DAMAGE. 3193835Stmm * 3293835Stmm * @(#)histedit.h 8.2 (Berkeley) 1/3/94 3393835Stmm * $NetBSD: histedit.h,v 1.31 2006/12/15 22:13:33 christos Exp $ 3493835Stmm * $FreeBSD: head/include/histedit.h 170511 2007-06-10 19:06:09Z stefanf $ 3593835Stmm */ 3693835Stmm 3793835Stmm/* 3893835Stmm * histedit.h: Line editor and history interface. 3993835Stmm */ 4093835Stmm#ifndef _HISTEDIT_H_ 4193835Stmm#define _HISTEDIT_H_ 4293835Stmm 4393835Stmm#include <sys/types.h> 4493835Stmm#include <stdio.h> 4593835Stmm 4693835Stmm__BEGIN_DECLS 4793835Stmm 4893835Stmm/* 4993835Stmm * ==== Editing ==== 5093835Stmm */ 5193835Stmm 5293835Stmmtypedef struct editline EditLine; 5393835Stmm 5493835Stmm/* 55116182Sobrien * For user-defined function interface 56116182Sobrien */ 57116182Sobrientypedef struct lineinfo { 58116182Sobrien const char *buffer; 5993835Stmm const char *cursor; 6093835Stmm const char *lastchar; 6193835Stmm} LineInfo; 6293835Stmm 6393835Stmm/* 6493835Stmm * EditLine editor function return codes. 6593835Stmm * For user-defined function interface 6693835Stmm */ 67101484Stmm#define CC_NORM 0 68101484Stmm#define CC_NEWLINE 1 69101484Stmm#define CC_EOF 2 7093835Stmm#define CC_ARGHACK 3 7193835Stmm#define CC_REFRESH 4 7293835Stmm#define CC_CURSOR 5 7393835Stmm#define CC_ERROR 6 7493835Stmm#define CC_FATAL 7 7593835Stmm#define CC_REDISPLAY 8 7693835Stmm#define CC_REFRESH_BEEP 9 7793835Stmm 7893835Stmm/* 7993835Stmm * Initialization, cleanup, and resetting 8093835Stmm */ 8193835StmmEditLine *el_init(const char *, FILE *, FILE *, FILE *); 8293835Stmmvoid el_end(EditLine *); 8393835Stmmvoid el_reset(EditLine *); 8493835Stmm 8593835Stmm/* 8693835Stmm * Get a line, a character or push a string back in the input queue 8793835Stmm */ 8893835Stmmconst char *el_gets(EditLine *, int *); 8993835Stmmint el_getc(EditLine *, char *); 9093835Stmmvoid el_push(EditLine *, char *); 9193835Stmm 9293835Stmm/* 9393835Stmm * Beep! 9493835Stmm */ 9593835Stmmvoid el_beep(EditLine *); 9693835Stmm 97101484Stmm/* 9893835Stmm * High level function internals control 9993835Stmm * Parses argc, argv array and executes builtin editline commands 100101484Stmm */ 10193835Stmmint el_parse(EditLine *, int, const char **); 10293835Stmm 103101484Stmm/* 10493835Stmm * Low level editline access functions 10593835Stmm */ 10693835Stmmint el_set(EditLine *, int, ...); 10793835Stmmint el_get(EditLine *, int, ...); 10893835Stmm#if 0 10993835Stmmunsigned char _el_fn_complete(EditLine *, int); 11093835Stmm#endif 11193835Stmm 11293835Stmm/* 11393835Stmm * el_set/el_get parameters 11493835Stmm */ 11593835Stmm#define EL_PROMPT 0 /* , el_pfunc_t); */ 11693835Stmm#define EL_TERMINAL 1 /* , const char *); */ 11793835Stmm#define EL_EDITOR 2 /* , const char *); */ 11893835Stmm#define EL_SIGNAL 3 /* , int); */ 11993835Stmm#define EL_BIND 4 /* , const char *, ..., NULL); */ 12093835Stmm#define EL_TELLTC 5 /* , const char *, ..., NULL); */ 12193835Stmm#define EL_SETTC 6 /* , const char *, ..., NULL); */ 12293835Stmm#define EL_ECHOTC 7 /* , const char *, ..., NULL); */ 12393835Stmm#define EL_SETTY 8 /* , const char *, ..., NULL); */ 12493835Stmm#define EL_ADDFN 9 /* , const char *, const char * */ 12593835Stmm /* , el_func_t); */ 12693835Stmm#define EL_HIST 10 /* , hist_fun_t, const char *); */ 12793835Stmm#define EL_EDITMODE 11 /* , int); */ 12893835Stmm#define EL_RPROMPT 12 /* , el_pfunc_t); */ 12993835Stmm#define EL_GETCFN 13 /* , el_rfunc_t); */ 13093835Stmm#define EL_CLIENTDATA 14 /* , void *); */ 13193835Stmm#define EL_UNBUFFERED 15 /* , int); */ 13293835Stmm#define EL_PREP_TERM 16 /* , int); */ 13393835Stmm#define EL_GETTC 17 /* , const char *, ..., NULL); */ 13493835Stmm#define EL_GETFP 18 /* , int, FILE **) */ 13593835Stmm#define EL_SETFP 19 /* , int, FILE *) */ 13693835Stmm 13793835Stmm#define EL_BUILTIN_GETCFN (NULL) 13893835Stmm 13993835Stmm/* 14093835Stmm * Source named file or $PWD/.editrc or $HOME/.editrc 14193835Stmm */ 14293835Stmmint el_source(EditLine *, const char *); 14393835Stmm 14493835Stmm/* 14593835Stmm * Must be called when the terminal changes size; If EL_SIGNAL 14693835Stmm * is set this is done automatically otherwise it is the responsibility 14793835Stmm * of the application 14893835Stmm */ 14993835Stmmvoid el_resize(EditLine *); 15093835Stmm 15193835Stmm 15293835Stmm/* 15393835Stmm * Set user private data. 15493835Stmm */ 15593835Stmmvoid el_data_set __P((EditLine *, void *)); 15693835Stmmvoid * el_data_get __P((EditLine *)); 15793835Stmm 15893835Stmm/* 15993835Stmm * User-defined function interface. 16093835Stmm */ 16193835Stmmconst LineInfo *el_line(EditLine *); 16293835Stmmint el_insertstr(EditLine *, const char *); 16393835Stmmvoid el_deletestr(EditLine *, int); 16493835Stmm 16593835Stmm 16693835Stmm/* 16793835Stmm * ==== History ==== 16893835Stmm */ 16993835Stmm 17093835Stmmtypedef struct history History; 17193835Stmm 17293835Stmmtypedef struct HistEvent { 17393835Stmm int num; 17493835Stmm const char *str; 17593835Stmm} HistEvent; 17693835Stmm 17793835Stmm/* 17893835Stmm * History access functions. 17993835Stmm */ 18093835StmmHistory * history_init(void); 18193835Stmmvoid history_end(History *); 18293835Stmm 18393835Stmmint history(History *, HistEvent *, int, ...); 18493835Stmm 18593835Stmm#define H_FUNC 0 /* , UTSL */ 18693835Stmm#define H_SETSIZE 1 /* , const int); */ 18793835Stmm#define H_EVENT 1 /* , const int); */ 18893835Stmm#define H_GETSIZE 2 /* , void); */ 18993835Stmm#define H_FIRST 3 /* , void); */ 19093835Stmm#define H_LAST 4 /* , void); */ 19193835Stmm#define H_PREV 5 /* , void); */ 19293835Stmm#define H_NEXT 6 /* , void); */ 19393835Stmm#define H_CURR 8 /* , const int); */ 19493835Stmm#define H_SET 7 /* , int); */ 19593835Stmm#define H_ADD 9 /* , const char *); */ 19693835Stmm#define H_ENTER 10 /* , const char *); */ 19793835Stmm#define H_APPEND 11 /* , const char *); */ 19893835Stmm#define H_END 12 /* , void); */ 19993835Stmm#define H_NEXT_STR 13 /* , const char *); */ 20093835Stmm#define H_PREV_STR 14 /* , const char *); */ 20193835Stmm#define H_NEXT_EVENT 15 /* , const int); */ 20293835Stmm#define H_PREV_EVENT 16 /* , const int); */ 20393835Stmm#define H_LOAD 17 /* , const char *); */ 20493835Stmm#define H_SAVE 18 /* , const char *); */ 20593835Stmm#define H_CLEAR 19 /* , void); */ 20693835Stmm#define H_SETUNIQUE 20 /* , int); */ 20793835Stmm#define H_GETUNIQUE 21 /* , void); */ 20893835Stmm#define H_DEL 22 /* , int); */ 20993835Stmm 21093835Stmm 21193835Stmm/* 21293835Stmm * ==== Tokenization ==== 21393835Stmm */ 21493835Stmm 21593835Stmmtypedef struct tokenizer Tokenizer; 21693835Stmm 21793835Stmm/* 21893835Stmm * String tokenization functions, using simplified sh(1) quoting rules 21993835Stmm */ 22093835StmmTokenizer *tok_init(const char *); 22193835Stmmvoid tok_end(Tokenizer *); 22293835Stmmvoid tok_reset(Tokenizer *); 22393835Stmmint tok_line(Tokenizer *, const LineInfo *, 22493835Stmm int *, const char ***, int *, int *); 22593835Stmmint tok_str(Tokenizer *, const char *, 22693835Stmm int *, const char ***); 22793835Stmm 22893835Stmm__END_DECLS 22993835Stmm 23093835Stmm#endif /* _HISTEDIT_H_ */ 23193835Stmm