* Copyright (c) 1992 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Christos Zoulas of Cornell University.
* %sccs.include.redist.c%
#if !defined(lint) && !defined(SCCSID)
static char sccsid
[] = "@(#)el.c 5.3 (Berkeley) %G%";
#endif /* not lint && not SCCSID */
* el.c: EditLine interface functions
* Initialize editline and set default parameters.
EditLine
*el
= (EditLine
*) el_malloc(sizeof(EditLine
));
memset(el
, 0, sizeof(EditLine
));
el
->el_infd
= fileno(fin
);
el
->el_prog
= strdup(prog
);
if ((tty
= getenv("DEBUGTTY")) != NULL
) {
el
->el_errfile
= fopen(tty
, "w");
if (el
->el_errfile
== NULL
) {
(void) fprintf(stderr
, "Cannot open %s (%s).\n",
* Initialize all the modules. Order is important!!!
el_free((ptr_t
) el
->el_prog
);
* Reset the tty and the parser
ch_reset(el
); /* XXX: Do we want that? */
* set the editline parameters
el_set(EditLine
*el
, int op
, ...)
el
= va_arg(va
, EditLine
*);
rv
= prompt_set(el
, va_arg(va
, el_pfunc_t
));
rv
= term_set(el
, va_arg(va
, char *));
rv
= map_set_editor(el
, va_arg(va
, char *));
el
->el_flags
|= HANDLE_SIGNALS
;
el
->el_flags
&= ~HANDLE_SIGNALS
;
if ((argv
[i
] = va_arg(va
, char *)) == NULL
)
rv
= map_bind(el
, i
, argv
);
rv
= term_telltc(el
, i
, argv
);
rv
= term_settc(el
, i
, argv
);
rv
= term_echotc(el
, i
, argv
);
rv
= tty_stty(el
, i
, argv
);
char *name
= va_arg(va
, char *);
char *help
= va_arg(va
, char *);
el_func_t func
= va_arg(va
, el_func_t
);
rv
= map_addfunc(el
, name
, help
, func
);
hist_fun_t func
= va_arg(va
, hist_fun_t
);
ptr_t ptr
= va_arg(va
, char *);
rv
= hist_set(el
, func
, ptr
);
return (const LineInfo
*) &el
->el_line
;
static const char elpath
[] = "/.editrc";
char *ptr
, path
[MAXPATHLEN
];
if ((fp
= fopen(fname
, "r")) == NULL
) {
if ((ptr
= getenv("HOME")) == NULL
)
fname
= strncpy(path
, ptr
, MAXPATHLEN
);
(void) strncat(path
, elpath
, MAXPATHLEN
);
path
[MAXPATHLEN
-1] = '\0';
if ((fp
= fopen(fname
, "r")) == NULL
)
while ((ptr
= fgetline(fp
, &len
)) != NULL
)
if (parse_line(el
, ptr
) == -1) {
* Called from program when terminal is resized
(void) sigemptyset(&nset
);
(void) sigaddset(&nset
, SIGWINCH
);
(void) sigprocmask(SIG_BLOCK
, &nset
, &oset
);
/* get the correct window size */
if (term_get_size(el
, &lins
, &cols
))
term_change_size(el
, lins
, cols
);
(void) sigprocmask(SIG_SETMASK
, &oset
, NULL
);