2023-03-07 20:43:04 -08:00
|
|
|
/* $OpenBSD: el.c,v 1.38 2023/03/08 04:43:05 guenther Exp $ */
|
2011-07-06 22:40:42 -07:00
|
|
|
/* $NetBSD: el.c,v 1.61 2011/01/27 23:11:40 christos Exp $ */
|
1997-01-15 21:18:27 -08:00
|
|
|
|
1995-10-18 01:37:01 -07:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Christos Zoulas of Cornell University.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-06-02 13:18:29 -07:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1995-10-18 01:37:01 -07:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
#include "config.h"
|
1995-10-18 01:37:01 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* el.c: EditLine interface functions
|
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
2010-06-29 17:05:35 -07:00
|
|
|
#include <ctype.h>
|
2016-04-09 12:31:55 -07:00
|
|
|
#include <langinfo.h>
|
2015-01-16 08:48:51 -08:00
|
|
|
#include <limits.h>
|
2016-04-09 12:31:55 -07:00
|
|
|
#include <locale.h>
|
2016-03-20 16:48:27 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-02-01 16:43:12 -08:00
|
|
|
|
1995-10-18 01:37:01 -07:00
|
|
|
#include "el.h"
|
Cleanup of private header inclusion:
1. Do not include private headers from "chared.h", "hist.h", "prompt.h",
"refresh.h", "search.h", "sig.h", "terminal.h", "tty.h".
The only private header having to include other private headers is "el.h".
2. Do not include "common.h", "parse.h", "help.h" from "el.h",
and do not include "emacs.h" and "vi.h" from "chared.h",
include them directly where needed.
3. Do include "fcns.h" from "el.h" because el_func_t is needed for "map.h".
4. Do not include private headers again that are already included by "el.h".
5. Include private headers after standard headers.
OK czarkoff@
2016-03-20 15:57:59 -07:00
|
|
|
#include "parse.h"
|
2016-05-20 08:30:17 -07:00
|
|
|
#include "read.h"
|
1995-10-18 01:37:01 -07:00
|
|
|
|
|
|
|
/* el_init():
|
|
|
|
* Initialize editline and set default parameters.
|
|
|
|
*/
|
2016-04-11 14:17:29 -07:00
|
|
|
EditLine *
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
|
1995-10-18 01:37:01 -07:00
|
|
|
{
|
2017-04-12 11:24:37 -07:00
|
|
|
EditLine *el = (EditLine *) calloc(1, sizeof(EditLine));
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
|
|
|
if (el == NULL)
|
2016-01-30 04:22:20 -08:00
|
|
|
return NULL;
|
1995-10-18 01:37:01 -07:00
|
|
|
|
2010-06-29 17:05:35 -07:00
|
|
|
el->el_infile = fin;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el->el_outfile = fout;
|
|
|
|
el->el_errfile = ferr;
|
2010-06-29 17:05:35 -07:00
|
|
|
|
|
|
|
el->el_infd = fileno(fin);
|
2011-07-06 22:40:42 -07:00
|
|
|
el->el_outfd = fileno(fout);
|
|
|
|
el->el_errfd = fileno(ferr);
|
2010-06-29 17:05:35 -07:00
|
|
|
|
2016-04-11 12:54:53 -07:00
|
|
|
el->el_prog = wcsdup(ct_decode_string(prog, &el->el_scratch));
|
2010-06-29 17:05:35 -07:00
|
|
|
if (el->el_prog == NULL) {
|
2014-10-16 23:07:50 -07:00
|
|
|
free(el);
|
2003-11-25 12:12:38 -08:00
|
|
|
return NULL;
|
|
|
|
}
|
1995-10-18 01:37:01 -07:00
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
/*
|
|
|
|
* Initialize all the modules. Order is important!!!
|
|
|
|
*/
|
|
|
|
el->el_flags = 0;
|
2010-06-29 17:05:35 -07:00
|
|
|
if (setlocale(LC_CTYPE, NULL) != NULL){
|
|
|
|
if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
|
|
|
|
el->el_flags |= CHARSET_IS_UTF8;
|
|
|
|
}
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
2016-01-29 16:06:39 -08:00
|
|
|
if (terminal_init(el) == -1) {
|
2014-10-16 23:07:50 -07:00
|
|
|
free(el->el_prog);
|
|
|
|
free(el);
|
1995-10-18 01:37:01 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-29 11:32:33 -08:00
|
|
|
(void) keymacro_init(el);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
(void) map_init(el);
|
|
|
|
if (tty_init(el) == -1)
|
|
|
|
el->el_flags |= NO_TTY;
|
|
|
|
(void) ch_init(el);
|
|
|
|
(void) search_init(el);
|
|
|
|
(void) hist_init(el);
|
|
|
|
(void) prompt_init(el);
|
|
|
|
(void) sig_init(el);
|
2016-05-20 08:30:17 -07:00
|
|
|
if (read_init(el) == -1) {
|
|
|
|
el_end(el);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-30 04:22:20 -08:00
|
|
|
return el;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
}
|
1995-10-18 01:37:01 -07:00
|
|
|
|
|
|
|
|
|
|
|
/* el_end():
|
|
|
|
* Clean up.
|
|
|
|
*/
|
2016-04-11 14:17:29 -07:00
|
|
|
void
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el_end(EditLine *el)
|
1995-10-18 01:37:01 -07:00
|
|
|
{
|
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
if (el == NULL)
|
|
|
|
return;
|
1995-10-18 01:37:01 -07:00
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el_reset(el);
|
1995-10-18 01:37:01 -07:00
|
|
|
|
2016-01-29 16:06:39 -08:00
|
|
|
terminal_end(el);
|
2016-01-29 11:32:33 -08:00
|
|
|
keymacro_end(el);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
map_end(el);
|
|
|
|
tty_end(el);
|
|
|
|
ch_end(el);
|
2016-05-22 16:09:56 -07:00
|
|
|
read_end(el->el_read);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
search_end(el);
|
|
|
|
hist_end(el);
|
|
|
|
prompt_end(el);
|
|
|
|
sig_end(el);
|
|
|
|
|
2016-01-30 09:32:52 -08:00
|
|
|
free(el->el_prog);
|
|
|
|
free(el->el_scratch.cbuff);
|
|
|
|
free(el->el_scratch.wbuff);
|
|
|
|
free(el->el_lgcyconv.cbuff);
|
|
|
|
free(el->el_lgcyconv.wbuff);
|
|
|
|
free(el);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
}
|
1995-10-18 01:37:01 -07:00
|
|
|
|
|
|
|
|
|
|
|
/* el_reset():
|
|
|
|
* Reset the tty and the parser
|
|
|
|
*/
|
2016-04-11 14:17:29 -07:00
|
|
|
void
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el_reset(EditLine *el)
|
1995-10-18 01:37:01 -07:00
|
|
|
{
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
|
|
|
tty_cookedmode(el);
|
2016-05-22 16:09:56 -07:00
|
|
|
ch_reset(el); /* XXX: Do we want that? */
|
1995-10-18 01:37:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* el_set():
|
|
|
|
* set the editline parameters
|
|
|
|
*/
|
2016-04-11 14:17:29 -07:00
|
|
|
int
|
2016-04-11 12:54:53 -07:00
|
|
|
el_wset(EditLine *el, int op, ...)
|
1995-10-18 01:37:01 -07:00
|
|
|
{
|
2010-06-29 17:05:35 -07:00
|
|
|
va_list ap;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
if (el == NULL)
|
2016-01-30 04:22:20 -08:00
|
|
|
return -1;
|
2010-06-29 17:05:35 -07:00
|
|
|
va_start(ap, op);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case EL_PROMPT:
|
2010-06-29 17:05:35 -07:00
|
|
|
case EL_RPROMPT: {
|
|
|
|
el_pfunc_t p = va_arg(ap, el_pfunc_t);
|
|
|
|
|
|
|
|
rv = prompt_set(el, p, 0, op, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-06 22:40:42 -07:00
|
|
|
case EL_RESIZE: {
|
|
|
|
el_zfunc_t p = va_arg(ap, el_zfunc_t);
|
|
|
|
void *arg = va_arg(ap, void *);
|
|
|
|
rv = ch_resizefun(el, p, arg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-29 17:05:35 -07:00
|
|
|
case EL_PROMPT_ESC:
|
|
|
|
case EL_RPROMPT_ESC: {
|
|
|
|
el_pfunc_t p = va_arg(ap, el_pfunc_t);
|
|
|
|
int c = va_arg(ap, int);
|
|
|
|
|
|
|
|
rv = prompt_set(el, p, c, op, 1);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
2010-06-29 17:05:35 -07:00
|
|
|
}
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
|
|
|
case EL_TERMINAL:
|
2016-01-29 16:06:39 -08:00
|
|
|
rv = terminal_set(el, va_arg(ap, char *));
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_EDITOR:
|
2016-04-11 13:43:33 -07:00
|
|
|
rv = map_set_editor(el, va_arg(ap, wchar_t *));
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_SIGNAL:
|
2010-06-29 17:05:35 -07:00
|
|
|
if (va_arg(ap, int))
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el->el_flags |= HANDLE_SIGNALS;
|
|
|
|
else
|
|
|
|
el->el_flags &= ~HANDLE_SIGNALS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_BIND:
|
|
|
|
case EL_TELLTC:
|
|
|
|
case EL_SETTC:
|
|
|
|
case EL_ECHOTC:
|
|
|
|
case EL_SETTY:
|
1995-10-18 01:37:01 -07:00
|
|
|
{
|
2016-04-11 13:43:33 -07:00
|
|
|
const wchar_t *argv[20];
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i < 20; i++)
|
2016-04-11 13:43:33 -07:00
|
|
|
if ((argv[i] = va_arg(ap, wchar_t *)) == NULL)
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case EL_BIND:
|
2016-04-11 12:54:53 -07:00
|
|
|
argv[0] = L"bind";
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
rv = map_bind(el, i, argv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_TELLTC:
|
2016-04-11 12:54:53 -07:00
|
|
|
argv[0] = L"telltc";
|
2016-01-29 16:06:39 -08:00
|
|
|
rv = terminal_telltc(el, i, argv);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_SETTC:
|
2016-04-11 12:54:53 -07:00
|
|
|
argv[0] = L"settc";
|
2016-01-29 16:06:39 -08:00
|
|
|
rv = terminal_settc(el, i, argv);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_ECHOTC:
|
2016-04-11 12:54:53 -07:00
|
|
|
argv[0] = L"echotc";
|
2016-01-29 16:06:39 -08:00
|
|
|
rv = terminal_echotc(el, i, argv);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_SETTY:
|
2016-04-11 12:54:53 -07:00
|
|
|
argv[0] = L"setty";
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
rv = tty_stty(el, i, argv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = -1;
|
|
|
|
EL_ABORT((el->el_errfile, "Bad op %d\n", op));
|
|
|
|
break;
|
|
|
|
}
|
1995-10-18 01:37:01 -07:00
|
|
|
break;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
}
|
1995-10-18 01:37:01 -07:00
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
case EL_ADDFN:
|
|
|
|
{
|
2016-04-11 13:43:33 -07:00
|
|
|
wchar_t *name = va_arg(ap, wchar_t *);
|
|
|
|
wchar_t *help = va_arg(ap, wchar_t *);
|
2010-06-29 17:05:35 -07:00
|
|
|
el_func_t func = va_arg(ap, el_func_t);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
|
|
|
rv = map_addfunc(el, name, help, func);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EL_HIST:
|
|
|
|
{
|
2010-06-29 17:05:35 -07:00
|
|
|
hist_fun_t func = va_arg(ap, hist_fun_t);
|
2016-01-30 09:32:52 -08:00
|
|
|
void *ptr = va_arg(ap, void *);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
|
|
|
rv = hist_set(el, func, ptr);
|
2010-06-29 17:05:35 -07:00
|
|
|
if (!(el->el_flags & CHARSET_IS_UTF8))
|
|
|
|
el->el_flags &= ~NARROW_HISTORY;
|
1995-10-18 01:37:01 -07:00
|
|
|
break;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
}
|
1995-10-18 01:37:01 -07:00
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
case EL_EDITMODE:
|
2010-06-29 17:05:35 -07:00
|
|
|
if (va_arg(ap, int))
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el->el_flags &= ~EDIT_DISABLED;
|
|
|
|
else
|
|
|
|
el->el_flags |= EDIT_DISABLED;
|
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_GETCFN:
|
|
|
|
{
|
2010-06-29 17:05:35 -07:00
|
|
|
el_rfunc_t rc = va_arg(ap, el_rfunc_t);
|
2016-05-20 08:30:17 -07:00
|
|
|
rv = el_read_setfn(el->el_read, rc);
|
1995-10-18 01:37:01 -07:00
|
|
|
break;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
}
|
1995-10-18 01:37:01 -07:00
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
case EL_CLIENTDATA:
|
2010-06-29 17:05:35 -07:00
|
|
|
el->el_data = va_arg(ap, void *);
|
1995-10-18 01:37:01 -07:00
|
|
|
break;
|
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
case EL_UNBUFFERED:
|
2010-06-29 17:05:35 -07:00
|
|
|
rv = va_arg(ap, int);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
if (rv && !(el->el_flags & UNBUFFERED)) {
|
|
|
|
el->el_flags |= UNBUFFERED;
|
|
|
|
read_prepare(el);
|
|
|
|
} else if (!rv && (el->el_flags & UNBUFFERED)) {
|
|
|
|
el->el_flags &= ~UNBUFFERED;
|
|
|
|
read_finish(el);
|
|
|
|
}
|
|
|
|
rv = 0;
|
1995-10-18 01:37:01 -07:00
|
|
|
break;
|
|
|
|
|
2003-11-25 12:12:38 -08:00
|
|
|
case EL_PREP_TERM:
|
2010-06-29 17:05:35 -07:00
|
|
|
rv = va_arg(ap, int);
|
2003-11-25 12:12:38 -08:00
|
|
|
if (rv)
|
2010-06-29 17:05:35 -07:00
|
|
|
(void) tty_rawmode(el);
|
2003-11-25 12:12:38 -08:00
|
|
|
else
|
2010-06-29 17:05:35 -07:00
|
|
|
(void) tty_cookedmode(el);
|
2003-11-25 12:12:38 -08:00
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
|
2010-06-29 17:05:35 -07:00
|
|
|
case EL_SETFP:
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
int what;
|
|
|
|
|
|
|
|
what = va_arg(ap, int);
|
|
|
|
fp = va_arg(ap, FILE *);
|
|
|
|
|
|
|
|
rv = 0;
|
|
|
|
switch (what) {
|
|
|
|
case 0:
|
|
|
|
el->el_infile = fp;
|
|
|
|
el->el_infd = fileno(fp);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
el->el_outfile = fp;
|
2011-07-06 22:40:42 -07:00
|
|
|
el->el_outfd = fileno(fp);
|
2010-06-29 17:05:35 -07:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
el->el_errfile = fp;
|
2011-07-06 22:40:42 -07:00
|
|
|
el->el_errfd = fileno(fp);
|
2010-06-29 17:05:35 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rv = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EL_REFRESH:
|
|
|
|
re_clear_display(el);
|
|
|
|
re_refresh(el);
|
2016-01-29 16:06:39 -08:00
|
|
|
terminal__flush(el);
|
2010-06-29 17:05:35 -07:00
|
|
|
break;
|
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
default:
|
1995-10-18 01:37:01 -07:00
|
|
|
rv = -1;
|
|
|
|
break;
|
|
|
|
}
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
2010-06-29 17:05:35 -07:00
|
|
|
va_end(ap);
|
2016-01-30 04:22:20 -08:00
|
|
|
return rv;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* el_get():
|
|
|
|
* retrieve the editline parameters
|
|
|
|
*/
|
2016-04-11 14:17:29 -07:00
|
|
|
int
|
2016-04-11 12:54:53 -07:00
|
|
|
el_wget(EditLine *el, int op, ...)
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
{
|
2010-06-29 17:05:35 -07:00
|
|
|
va_list ap;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
int rv;
|
|
|
|
|
2010-06-29 17:05:35 -07:00
|
|
|
if (el == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
va_start(ap, op);
|
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
switch (op) {
|
|
|
|
case EL_PROMPT:
|
2010-06-29 17:05:35 -07:00
|
|
|
case EL_RPROMPT: {
|
|
|
|
el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
|
|
|
|
rv = prompt_get(el, p, 0, op);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
2010-06-29 17:05:35 -07:00
|
|
|
}
|
|
|
|
case EL_PROMPT_ESC:
|
|
|
|
case EL_RPROMPT_ESC: {
|
|
|
|
el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
|
2016-04-11 13:43:33 -07:00
|
|
|
wchar_t *c = va_arg(ap, wchar_t *);
|
2010-06-29 17:05:35 -07:00
|
|
|
|
|
|
|
rv = prompt_get(el, p, c, op);
|
|
|
|
break;
|
|
|
|
}
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
|
|
|
case EL_EDITOR:
|
2016-04-11 13:43:33 -07:00
|
|
|
rv = map_get_editor(el, va_arg(ap, const wchar_t **));
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_SIGNAL:
|
2010-06-29 17:05:35 -07:00
|
|
|
*va_arg(ap, int *) = (el->el_flags & HANDLE_SIGNALS);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_EDITMODE:
|
2010-06-29 17:05:35 -07:00
|
|
|
*va_arg(ap, int *) = !(el->el_flags & EDIT_DISABLED);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_TERMINAL:
|
2016-01-29 16:06:39 -08:00
|
|
|
terminal_get(el, va_arg(ap, const char **));
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
|
2010-06-29 17:05:35 -07:00
|
|
|
case EL_GETTC:
|
1995-10-18 01:37:01 -07:00
|
|
|
{
|
2010-06-29 17:05:35 -07:00
|
|
|
static char name[] = "gettc";
|
|
|
|
char *argv[20];
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
int i;
|
|
|
|
|
2016-03-20 16:48:27 -07:00
|
|
|
for (i = 1; i < (int)(sizeof(argv) / sizeof(argv[0])); i++)
|
2010-06-29 17:05:35 -07:00
|
|
|
if ((argv[i] = va_arg(ap, char *)) == NULL)
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
switch (op) {
|
2010-06-29 17:05:35 -07:00
|
|
|
case EL_GETTC:
|
|
|
|
argv[0] = name;
|
2016-01-29 16:06:39 -08:00
|
|
|
rv = terminal_gettc(el, i, argv);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = -1;
|
2010-06-29 17:05:35 -07:00
|
|
|
EL_ABORT((el->el_errfile, "Bad op %d\n", op));
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1995-10-18 01:37:01 -07:00
|
|
|
}
|
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
case EL_GETCFN:
|
2016-05-20 08:30:17 -07:00
|
|
|
*va_arg(ap, el_rfunc_t *) = el_read_getfn(el->el_read);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_CLIENTDATA:
|
2010-06-29 17:05:35 -07:00
|
|
|
*va_arg(ap, void **) = el->el_data;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EL_UNBUFFERED:
|
2010-06-29 17:05:35 -07:00
|
|
|
*va_arg(ap, int *) = (!(el->el_flags & UNBUFFERED));
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
|
2010-06-29 17:05:35 -07:00
|
|
|
case EL_GETFP:
|
|
|
|
{
|
|
|
|
int what;
|
|
|
|
FILE **fpp;
|
|
|
|
|
|
|
|
what = va_arg(ap, int);
|
|
|
|
fpp = va_arg(ap, FILE **);
|
|
|
|
rv = 0;
|
|
|
|
switch (what) {
|
|
|
|
case 0:
|
|
|
|
*fpp = el->el_infile;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
*fpp = el->el_outfile;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
*fpp = el->el_errfile;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rv = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
default:
|
|
|
|
rv = -1;
|
2010-06-29 17:05:35 -07:00
|
|
|
break;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
}
|
2010-06-29 17:05:35 -07:00
|
|
|
va_end(ap);
|
1995-10-18 01:37:01 -07:00
|
|
|
|
2016-01-30 04:22:20 -08:00
|
|
|
return rv;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
}
|
1995-10-18 01:37:01 -07:00
|
|
|
|
|
|
|
|
|
|
|
/* el_line():
|
|
|
|
* Return editing info
|
|
|
|
*/
|
2016-04-11 14:17:29 -07:00
|
|
|
const LineInfoW *
|
2016-04-11 12:54:53 -07:00
|
|
|
el_wline(EditLine *el)
|
1995-10-18 01:37:01 -07:00
|
|
|
{
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
2016-04-11 12:54:53 -07:00
|
|
|
return (const LineInfoW *)(void *)&el->el_line;
|
1995-10-18 01:37:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* el_source():
|
|
|
|
* Source a file
|
|
|
|
*/
|
2016-04-11 14:17:29 -07:00
|
|
|
int
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el_source(EditLine *el, const char *fname)
|
1995-10-18 01:37:01 -07:00
|
|
|
{
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
FILE *fp;
|
|
|
|
size_t len;
|
2016-03-20 15:09:24 -07:00
|
|
|
ssize_t slen;
|
|
|
|
char *ptr;
|
2010-06-29 17:05:35 -07:00
|
|
|
#ifdef HAVE_ISSETUGID
|
2015-01-16 08:48:51 -08:00
|
|
|
char path[PATH_MAX];
|
2010-06-29 17:05:35 -07:00
|
|
|
#endif
|
2016-04-11 13:43:33 -07:00
|
|
|
const wchar_t *dptr;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
|
|
|
fp = NULL;
|
|
|
|
if (fname == NULL) {
|
|
|
|
#ifdef HAVE_ISSETUGID
|
|
|
|
static const char elpath[] = "/.editrc";
|
|
|
|
|
|
|
|
if (issetugid())
|
2016-01-30 04:22:20 -08:00
|
|
|
return -1;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
if ((ptr = getenv("HOME")) == NULL)
|
2016-01-30 04:22:20 -08:00
|
|
|
return -1;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
|
2016-01-30 04:22:20 -08:00
|
|
|
return -1;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
|
2016-01-30 04:22:20 -08:00
|
|
|
return -1;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
fname = path;
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* If issetugid() is missing, always return an error, in order
|
|
|
|
* to keep from inadvertently opening up the user to a security
|
|
|
|
* hole.
|
|
|
|
*/
|
2016-01-30 04:22:20 -08:00
|
|
|
return -1;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (fp == NULL)
|
|
|
|
fp = fopen(fname, "r");
|
|
|
|
if (fp == NULL)
|
2016-01-30 04:22:20 -08:00
|
|
|
return -1;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
2016-03-20 15:09:24 -07:00
|
|
|
ptr = NULL;
|
|
|
|
len = 0;
|
|
|
|
while ((slen = getline(&ptr, &len, fp)) != -1) {
|
|
|
|
if (*ptr == '\n')
|
|
|
|
continue; /* Empty line. */
|
|
|
|
if (slen > 0 && ptr[--slen] == '\n')
|
|
|
|
ptr[slen] = '\0';
|
2011-07-13 04:05:17 -07:00
|
|
|
|
2010-06-29 17:05:35 -07:00
|
|
|
dptr = ct_decode_string(ptr, &el->el_scratch);
|
|
|
|
if (!dptr)
|
|
|
|
continue;
|
|
|
|
/* loop until first non-space char or EOL */
|
2016-04-09 13:15:26 -07:00
|
|
|
while (*dptr != '\0' && iswspace(*dptr))
|
2010-06-29 17:05:35 -07:00
|
|
|
dptr++;
|
|
|
|
if (*dptr == '#')
|
|
|
|
continue; /* ignore, this is a comment line */
|
|
|
|
if (parse_line(el, dptr) == -1) {
|
2016-03-20 15:09:24 -07:00
|
|
|
free(ptr);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
(void) fclose(fp);
|
2016-01-30 04:22:20 -08:00
|
|
|
return -1;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
}
|
1995-10-18 01:37:01 -07:00
|
|
|
}
|
2016-03-20 15:09:24 -07:00
|
|
|
free(ptr);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
(void) fclose(fp);
|
2016-01-30 04:22:20 -08:00
|
|
|
return 0;
|
1995-10-18 01:37:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* el_resize():
|
|
|
|
* Called from program when terminal is resized
|
|
|
|
*/
|
2016-04-11 14:17:29 -07:00
|
|
|
void
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el_resize(EditLine *el)
|
|
|
|
{
|
|
|
|
int lins, cols;
|
|
|
|
sigset_t oset, nset;
|
|
|
|
|
|
|
|
(void) sigemptyset(&nset);
|
|
|
|
(void) sigaddset(&nset, SIGWINCH);
|
|
|
|
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
|
|
|
|
|
|
|
|
/* get the correct window size */
|
2016-01-29 16:06:39 -08:00
|
|
|
if (terminal_get_size(el, &lins, &cols))
|
|
|
|
terminal_change_size(el, lins, cols);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
|
|
|
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* el_beep():
|
|
|
|
* Called from the program to beep
|
|
|
|
*/
|
2016-04-11 14:17:29 -07:00
|
|
|
void
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el_beep(EditLine *el)
|
1995-10-18 01:37:01 -07:00
|
|
|
{
|
|
|
|
|
2016-01-29 16:06:39 -08:00
|
|
|
terminal_beep(el);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
}
|
|
|
|
|
1995-10-18 01:37:01 -07:00
|
|
|
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
/* el_editmode()
|
|
|
|
* Set the state of EDIT_DISABLED from the `edit' command.
|
|
|
|
*/
|
|
|
|
protected int
|
2016-04-11 13:43:33 -07:00
|
|
|
el_editmode(EditLine *el, int argc, const wchar_t **argv)
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
{
|
2016-04-11 13:43:33 -07:00
|
|
|
const wchar_t *how;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
|
|
|
if (argv == NULL || argc != 2 || argv[1] == NULL)
|
2016-01-30 04:22:20 -08:00
|
|
|
return -1;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
|
|
|
|
how = argv[1];
|
2016-04-11 12:54:53 -07:00
|
|
|
if (wcscmp(how, L"on") == 0) {
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el->el_flags &= ~EDIT_DISABLED;
|
2010-06-29 17:05:35 -07:00
|
|
|
tty_rawmode(el);
|
2016-04-11 12:54:53 -07:00
|
|
|
} else if (wcscmp(how, L"off") == 0) {
|
2010-06-29 17:05:35 -07:00
|
|
|
tty_cookedmode(el);
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
el->el_flags |= EDIT_DISABLED;
|
2010-06-29 17:05:35 -07:00
|
|
|
}
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
else {
|
2016-04-09 13:15:26 -07:00
|
|
|
(void) fprintf(el->el_errfile, "edit: Bad value `%ls'.\n",
|
2010-06-29 17:05:35 -07:00
|
|
|
how);
|
2016-01-30 04:22:20 -08:00
|
|
|
return -1;
|
Update to NetBSD libedit (from Oct 1, 2003), adding some string
cleaning and history bug fixes. The code includes GNU libreadline
functionality, but the corresponding header files are not installed,
since some libreadline functions are missing. There are some minor API
changes, notably:
old: EditLine *el_init(const char *, FILE *, FILE *);
new: EditLine *el_init(const char *, FILE *, FILE *, FILE *);
old: HistEvent *history(History *h, int op, ...);
new: int history(History *h, HistEvent *ev, int op, ...); plus some
changes in operation names. See editline(3) for details.
Tested by djm@, mouring@, jmc@.
ok deraadt@
2003-10-31 00:42:23 -08:00
|
|
|
}
|
2016-01-30 04:22:20 -08:00
|
|
|
return 0;
|
1995-10-18 01:37:01 -07:00
|
|
|
}
|