aboutsummaryrefslogtreecommitdiff
path: root/el.c
diff options
context:
space:
mode:
Diffstat (limited to 'el.c')
-rw-r--r--el.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/el.c b/el.c
index 8e1b3b5701fa..d7932cba7f7b 100644
--- a/el.c
+++ b/el.c
@@ -1,4 +1,4 @@
-/* $NetBSD: el.c,v 1.74 2015/12/08 12:56:55 christos Exp $ */
+/* $NetBSD: el.c,v 1.83 2016/02/24 17:13:22 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#else
-__RCSID("$NetBSD: el.c,v 1.74 2015/12/08 12:56:55 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.83 2016/02/24 17:13:22 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -46,13 +46,17 @@ __RCSID("$NetBSD: el.c,v 1.74 2015/12/08 12:56:55 christos Exp $");
*/
#include <sys/types.h>
#include <sys/param.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
#include <ctype.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef WIDECHAR
#include <locale.h>
#include <langinfo.h>
+#endif
+
#include "el.h"
+#include "parse.h"
/* el_init():
* Initialize editline and set default parameters.
@@ -93,12 +97,10 @@ el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
* Initialize all the modules. Order is important!!!
*/
el->el_flags = 0;
-#ifdef WIDECHAR
if (setlocale(LC_CTYPE, NULL) != NULL){
if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
el->el_flags |= CHARSET_IS_UTF8;
}
-#endif
if (terminal_init(el) == -1) {
el_free(el->el_prog);
@@ -207,7 +209,7 @@ FUN(el,set)(EditLine *el, int op, ...)
el_pfunc_t p = va_arg(ap, el_pfunc_t);
int c = va_arg(ap, int);
- rv = prompt_set(el, p, c, op, 1);
+ rv = prompt_set(el, p, (Char)c, op, 1);
break;
}
@@ -306,7 +308,6 @@ FUN(el,set)(EditLine *el, int op, ...)
{
el_rfunc_t rc = va_arg(ap, el_rfunc_t);
rv = el_read_setfn(el, rc);
- el->el_flags &= ~NARROW_READ;
break;
}
@@ -435,7 +436,7 @@ FUN(el,get)(EditLine *el, int op, ...)
char *argv[20];
int i;
- for (i = 1; i < (int)__arraycount(argv); i++)
+ for (i = 1; i < (int)__arraycount(argv); i++)
if ((argv[i] = va_arg(ap, char *)) == NULL)
break;
@@ -512,6 +513,7 @@ el_source(EditLine *el, const char *fname)
{
FILE *fp;
size_t len;
+ ssize_t slen;
char *ptr;
char *path = NULL;
const Char *dptr;
@@ -548,15 +550,17 @@ el_source(EditLine *el, const char *fname)
return -1;
}
- while ((ptr = fgetln(fp, &len)) != NULL) {
+ 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';
+
dptr = ct_decode_string(ptr, &el->el_scratch);
if (!dptr)
continue;
- if (len > 0 && dptr[len - 1] == '\n')
- --len;
-
/* loop until first non-space char or EOL */
while (*dptr != '\0' && Isspace(*dptr))
dptr++;
@@ -565,6 +569,7 @@ el_source(EditLine *el, const char *fname)
if ((error = parse_line(el, dptr)) == -1)
break;
}
+ free(ptr);
el_free(path);
(void) fclose(fp);