Module Name: src Committed By: christos Date: Wed Dec 30 23:54:52 UTC 2009
Modified Files: src/lib/libedit: Makefile chartype.h el.c el.h eln.c hist.c hist.h histedit.h history.c makelist readline.c search.c tokenizer.c Log Message: Fix wide build, test it, but don't turn it on yet. To generate a diff of this commit: cvs rdiff -u -r1.38 -r1.39 src/lib/libedit/Makefile cvs rdiff -u -r1.1 -r1.2 src/lib/libedit/chartype.h src/lib/libedit/eln.c cvs rdiff -u -r1.56 -r1.57 src/lib/libedit/el.c cvs rdiff -u -r1.19 -r1.20 src/lib/libedit/el.h cvs rdiff -u -r1.16 -r1.17 src/lib/libedit/hist.c src/lib/libedit/tokenizer.c cvs rdiff -u -r1.11 -r1.12 src/lib/libedit/hist.h cvs rdiff -u -r1.42 -r1.43 src/lib/libedit/histedit.h cvs rdiff -u -r1.35 -r1.36 src/lib/libedit/history.c cvs rdiff -u -r1.13 -r1.14 src/lib/libedit/makelist cvs rdiff -u -r1.86 -r1.87 src/lib/libedit/readline.c cvs rdiff -u -r1.22 -r1.23 src/lib/libedit/search.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libedit/Makefile diff -u src/lib/libedit/Makefile:1.38 src/lib/libedit/Makefile:1.39 --- src/lib/libedit/Makefile:1.38 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/Makefile Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.38 2009/12/30 22:37:40 christos Exp $ +# $NetBSD: Makefile,v 1.39 2009/12/30 23:54:52 christos Exp $ # @(#)Makefile 8.1 (Berkeley) 6/4/93 USE_SHLIBDIR= yes @@ -26,17 +26,14 @@ editline.3 tok_line.3 editline.3 tok_str.3 # For speed and debugging -SRCS= ${OSRCS} readline.c +SRCS= ${OSRCS} readline.c tokenizer.c history.c # For protection -#SRCS= editline.c readline.c +#SRCS= editline.c readline.c tokenizer.c history.c .if ${WIDECHAR} == "yes" -SRCS += tokenizern.c tokenizerw.c historyn.c historyw.c eln.c -CLEANFILES+=tokenizern.c.tmp tokenizern.c tokenizerw.c.tmp tokenizerw.c -CLEANFILES+=historyn.c.tmp historyn.c historyw.c.tmp historyw.c +SRCS += tokenizern.c historyn.c eln.c +CLEANFILES+=tokenizern.c.tmp tokenizern.c historyn.c.tmp historyn.c CPPFLAGS+=-DWIDECHAR -.else -SRCS += tokenizer.c history.c .endif LIBEDITDIR?=${.CURDIR} @@ -106,22 +103,12 @@ tokenizern.c: makelist Makefile ${_MKTARGET_CREATE} - ${HOST_SH} ${LIBEDITDIR}/makelist -t NARROW tokenizer > ${.TARGET}.tmp && \ - mv ${.TARGET}.tmp ${.TARGET} - -tokenizerw.c: makelist Makefile - ${_MKTARGET_CREATE} - ${HOST_SH} ${LIBEDITDIR}/makelist -t WIDE tokenizer > ${.TARGET}.tmp && \ + ${HOST_SH} ${LIBEDITDIR}/makelist -n tokenizer.c > ${.TARGET}.tmp && \ mv ${.TARGET}.tmp ${.TARGET} historyn.c: makelist Makefile ${_MKTARGET_CREATE} - ${HOST_SH} ${LIBEDITDIR}/makelist -t NARROW history > ${.TARGET}.tmp && \ - mv ${.TARGET}.tmp ${.TARGET} - -historyw.c: makelist Makefile - ${_MKTARGET_CREATE} - ${HOST_SH} ${LIBEDITDIR}/makelist -t WIDE history > ${.TARGET}.tmp && \ + ${HOST_SH} ${LIBEDITDIR}/makelist -n history.c > ${.TARGET}.tmp && \ mv ${.TARGET}.tmp ${.TARGET} tc1.o: ${LIBEDITDIR}/TEST/tc1.c Index: src/lib/libedit/chartype.h diff -u src/lib/libedit/chartype.h:1.1 src/lib/libedit/chartype.h:1.2 --- src/lib/libedit/chartype.h:1.1 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/chartype.h Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: chartype.h,v 1.1 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: chartype.h,v 1.2 2009/12/30 23:54:52 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -185,14 +185,18 @@ protected void ct_conv_buff_resize(ct_buffer_t *, size_t, size_t); protected ssize_t ct_encode_char(char *, size_t, Char); +#define ct_free_argv(s) el_free(s) + #else #define ct_encode_string(s, b) (s) #define ct_decode_string(s, b) (s) #define ct_decode_argv(l, s, b) (s) #define ct_conv_buff_resize(b, os, ns) #define ct_encode_char(d, l, s) (*d = s, 1) +#define ct_free_argv(s) #endif +#ifndef NARROWCHAR /* Encode a characted into the destination buffer, provided there is sufficent * buffer space available. Returns the number of bytes used up (zero if the * character cannot be encoded, -1 if there was not enough space available). */ @@ -232,6 +236,7 @@ #define CHTYPE_NONPRINT (-4) /* classification of character c, as one of the above defines */ protected int ct_chr_class(Char c); +#endif #endif /* _chartype_f */ Index: src/lib/libedit/eln.c diff -u src/lib/libedit/eln.c:1.1 src/lib/libedit/eln.c:1.2 --- src/lib/libedit/eln.c:1.1 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/eln.c Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: eln.c,v 1.1 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: eln.c,v 1.2 2009/12/30 23:54:52 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: eln.c,v 1.1 2009/12/30 22:37:40 christos Exp $"); +__RCSID("$NetBSD: eln.c,v 1.2 2009/12/30 23:54:52 christos Exp $"); #endif /* not lint && not SCCSID */ #include "histedit.h" @@ -42,6 +42,7 @@ #include "read.h" #include <stdarg.h> #include <stdio.h> +#include <stdlib.h> public int el_getc(EditLine *el, char *cp) @@ -89,7 +90,7 @@ if (!wargv) return -1; ret = el_wparse(el, argc, wargv); - free(wargv); + ct_free_argv(wargv); return ret; } @@ -171,7 +172,7 @@ default: ret = -1; } - free(wargv); + ct_free_argv(wargv); break; } @@ -191,14 +192,14 @@ goto out; } ret = el_wset(el, op, wargv[0], wargv[1], func); - free(wargv); + ct_free_argv(wargv); break; } case EL_HIST: { /* hist_fun_t, const char * */ hist_fun_t fun = va_arg(ap, hist_fun_t); ptr_t ptr = va_arg(ap, ptr_t); - ret = hist_set(el, fun, - ct_decode_string(ptr, &el->el_lgcyconv)); + ret = hist_set(el, fun, ptr); + el->el_flags |= NARROW_HISTORY; break; } /* XXX: do we need to change el_rfunc_t? */ @@ -247,7 +248,7 @@ case EL_PROMPT: /* el_pfunc_t * */ case EL_RPROMPT: { el_pfunc_t *p = va_arg(ap, el_pfunc_t *); - ret = prompt_get(el, p, 0, 0, op); + ret = prompt_get(el, p, 0, op); break; } @@ -256,7 +257,7 @@ el_pfunc_t *p = va_arg(ap, el_pfunc_t *); char *c = va_arg(ap, char *); wchar_t wc; - ret = prompt_get(el, p, 0, &wc, op); + ret = prompt_get(el, p, &wc, op); *c = (unsigned char)wc; break; } Index: src/lib/libedit/el.c diff -u src/lib/libedit/el.c:1.56 src/lib/libedit/el.c:1.57 --- src/lib/libedit/el.c:1.56 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/el.c Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: el.c,v 1.56 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: el.c,v 1.57 2009/12/30 23:54:52 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.56 2009/12/30 22:37:40 christos Exp $"); +__RCSID("$NetBSD: el.c,v 1.57 2009/12/30 23:54:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -266,6 +266,7 @@ ptr_t ptr = va_arg(ap, ptr_t); rv = hist_set(el, func, ptr); + el->el_flags &= ~NARROW_HISTORY; break; } Index: src/lib/libedit/el.h diff -u src/lib/libedit/el.h:1.19 src/lib/libedit/el.h:1.20 --- src/lib/libedit/el.h:1.19 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/el.h Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: el.h,v 1.19 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: el.h,v 1.20 2009/12/30 23:54:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -59,6 +59,7 @@ #define UNBUFFERED 0x08 #define CHARSET_IS_UTF8 0x10 #define IGNORE_EXTCHARS 0x20 /* Ignore characters read > 0xff */ +#define NARROW_HISTORY 0x40 typedef int bool_t; /* True or not */ Index: src/lib/libedit/hist.c diff -u src/lib/libedit/hist.c:1.16 src/lib/libedit/hist.c:1.17 --- src/lib/libedit/hist.c:1.16 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/hist.c Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: hist.c,v 1.16 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: hist.c,v 1.17 2009/12/30 23:54:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: hist.c,v 1.16 2009/12/30 22:37:40 christos Exp $"); +__RCSID("$NetBSD: hist.c,v 1.17 2009/12/30 23:54:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -209,3 +209,15 @@ return 1; } + +#ifdef WIDECHAR +protected wchar_t * +hist_convert(EditLine *el, int fn, ptr_t arg) +{ + HistEventW ev; + if ((*(el)->el_history.fun)((el)->el_history.ref, &ev, fn, arg) == -1) + return NULL; + return ct_decode_string((const char *)(const void *)ev.str, + &el->el_scratch); +} +#endif Index: src/lib/libedit/tokenizer.c diff -u src/lib/libedit/tokenizer.c:1.16 src/lib/libedit/tokenizer.c:1.17 --- src/lib/libedit/tokenizer.c:1.16 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/tokenizer.c Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: tokenizer.c,v 1.16 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: tokenizer.c,v 1.17 2009/12/30 23:54:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: tokenizer.c,v 1.16 2009/12/30 22:37:40 christos Exp $"); +__RCSID("$NetBSD: tokenizer.c,v 1.17 2009/12/30 23:54:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -68,7 +68,7 @@ #define tok_strdup(a) Strdup(a) -struct TYPE(tokenizer) { +struct FUNW(tokenizer) { Char *ifs; /* In field separator */ int argc, amax; /* Current and maximum number of args */ Char **argv; /* Argument list */ @@ -189,7 +189,7 @@ * cursorv if !NULL, offset in argv[cursorc] of cursor */ public int -FUN(tok,line)(TYPE(Tokenizer) *tok, const LineInfo *line, +FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line, int *argc, const Char ***argv, int *cursorc, int *cursoro) { const Char *ptr; @@ -441,7 +441,7 @@ FUN(tok,str)(TYPE(Tokenizer) *tok, const Char *line, int *argc, const Char ***argv) { - LineInfo li; + TYPE(LineInfo) li; memset(&li, 0, sizeof(li)); li.buffer = line; Index: src/lib/libedit/hist.h diff -u src/lib/libedit/hist.h:1.11 src/lib/libedit/hist.h:1.12 --- src/lib/libedit/hist.h:1.11 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/hist.h Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: hist.h,v 1.11 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: hist.h,v 1.12 2009/12/30 23:54:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -54,9 +54,17 @@ TYPE(HistEvent) ev; /* Event cookie */ } el_history_t; -#define HIST_FUN(el, fn, arg) \ +#define HIST_FUN_INTERNAL(el, fn, arg) \ ((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \ fn, arg)) == -1) ? NULL : (el)->el_history.ev.str) +#ifdef WIDECHAR +#define HIST_FUN(el, fn, arg) \ + (((el)->el_flags & NARROW_HISTORY) ? hist_convert(el, fn, arg) : \ + HIST_FUN_INTERNAL(el, fn, arg)) +#else +#define HIST_FUN(el, fn, arg) HIST_FUN_INTERNAL(el, fn, arg) +#endif + #define HIST_NEXT(el) HIST_FUN(el, H_NEXT, NULL) #define HIST_FIRST(el) HIST_FUN(el, H_FIRST, NULL) @@ -72,5 +80,8 @@ protected int hist_set(EditLine *, hist_fun_t, ptr_t); protected int hist_command(EditLine *, int, const Char **); protected int hist_enlargebuf(EditLine *, size_t, size_t); +#ifdef WIDECHAR +protected wchar_t *hist_convert(EditLine *, int, ptr_t); +#endif #endif /* _h_el_hist */ Index: src/lib/libedit/histedit.h diff -u src/lib/libedit/histedit.h:1.42 src/lib/libedit/histedit.h:1.43 --- src/lib/libedit/histedit.h:1.42 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/histedit.h Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.h,v 1.42 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: histedit.h,v 1.43 2009/12/30 23:54:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -287,8 +287,8 @@ typedef struct historyw HistoryW; -HistoryW * historyw_init(void); -void historyw_end(HistoryW *); +HistoryW * history_winit(void); +void history_wend(HistoryW *); int historyw(HistoryW *, HistEventW *, int, ...); Index: src/lib/libedit/history.c diff -u src/lib/libedit/history.c:1.35 src/lib/libedit/history.c:1.36 --- src/lib/libedit/history.c:1.35 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/history.c Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: history.c,v 1.35 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: history.c,v 1.36 2009/12/30 23:54:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: history.c,v 1.35 2009/12/30 22:37:40 christos Exp $"); +__RCSID("$NetBSD: history.c,v 1.36 2009/12/30 23:54:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -64,7 +64,7 @@ typedef void (*history_vfun_t)(ptr_t, TYPE(HistEvent) *); typedef int (*history_sfun_t)(ptr_t, TYPE(HistEvent) *, const int); -struct TYPE(history) { +struct FUNW(history) { ptr_t h_ref; /* Argument for history fcns */ int h_ent; /* Last entry point for history */ history_gfun_t h_first; /* Get the first element */ @@ -563,7 +563,7 @@ /* history_init(): * Initialization function. */ -public TYPE(TYPE(History)) * +public TYPE(History) * FUN(history,init)(void) { TYPE(HistEvent) ev; @@ -736,7 +736,7 @@ int i = -1; TYPE(HistEvent) ev; #ifdef WIDECHAR - static el_conv_buff_t conv; + static ct_buffer_t conv; #endif if ((fp = fopen(fname, "r")) == NULL) @@ -796,7 +796,7 @@ size_t len, max_size; char *ptr; #ifdef WIDECHAR - static el_conv_buff_t conv; + static ct_buffer_t conv; #endif if ((fp = fopen(fname, "w")) == NULL) @@ -1053,7 +1053,7 @@ } case H_END: - history_end(h); + FUN(history,end)(h); retval = 0; break; Index: src/lib/libedit/makelist diff -u src/lib/libedit/makelist:1.13 src/lib/libedit/makelist:1.14 --- src/lib/libedit/makelist:1.13 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/makelist Wed Dec 30 18:54:52 2009 @@ -1,5 +1,5 @@ #!/bin/sh - -# $NetBSD: makelist,v 1.13 2009/12/30 22:37:40 christos Exp $ +# $NetBSD: makelist,v 1.14 2009/12/30 23:54:52 christos Exp $ # # Copyright (c) 1992, 1993 # The Regents of the University of California. All rights reserved. @@ -36,7 +36,7 @@ # makelist.sh: Automatically generate header files... AWK=awk -USAGE="Usage: $0 -t <def>|-h|-e|-fc|-fh|-bc|-bh|-m <filenames>" +USAGE="Usage: $0 -n|-h|-e|-fc|-fh|-bc|-bh|-m <filenames>" if [ "x$1" = "x" ] then @@ -53,10 +53,11 @@ # generate foo.h file from foo.c # --t) +-n) cat << _EOF -#define ${FILES} -#include "tokenizer.c" +#undef WIDECHAR +#define NARROWCHAR +#include "${FILES}" _EOF ;; Index: src/lib/libedit/readline.c diff -u src/lib/libedit/readline.c:1.86 src/lib/libedit/readline.c:1.87 --- src/lib/libedit/readline.c:1.86 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/readline.c Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: readline.c,v 1.86 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: readline.c,v 1.87 2009/12/30 23:54:52 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: readline.c,v 1.86 2009/12/30 22:37:40 christos Exp $"); +__RCSID("$NetBSD: readline.c,v 1.87 2009/12/30 23:54:52 christos Exp $"); #endif /* not lint && not SCCSID */ #include <sys/types.h> @@ -279,7 +279,7 @@ if (e != NULL) el_end(e); if (h != NULL) - history_end(h); + FUN(history,end)(h); if (!rl_instream) rl_instream = stdin; @@ -295,9 +295,9 @@ e = el_init(rl_readline_name, rl_instream, rl_outstream, stderr); if (!editmode) - el_set(e, EL_EDITMODE, 0); + FUN(el,set)(e, EL_EDITMODE, 0); - h = history_init(); + h = FUN(history,init)(); if (!e || !h) return (-1); @@ -312,7 +312,7 @@ /* for proper prompt printing in readline() */ if (rl_set_prompt("") == -1) { - history_end(h); + FUN(history,end)(h); el_end(e); return -1; } Index: src/lib/libedit/search.c diff -u src/lib/libedit/search.c:1.22 src/lib/libedit/search.c:1.23 --- src/lib/libedit/search.c:1.22 Wed Dec 30 17:37:40 2009 +++ src/lib/libedit/search.c Wed Dec 30 18:54:52 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: search.c,v 1.22 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: search.c,v 1.23 2009/12/30 23:54:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: search.c,v 1.22 2009/12/30 22:37:40 christos Exp $"); +__RCSID("$NetBSD: search.c,v 1.23 2009/12/30 23:54:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -110,7 +110,7 @@ el_match(const Char *str, const Char *pat) { #ifdef WIDECHAR - static el_conv_buff_t conv; + static ct_buffer_t conv; #endif #if defined (REGEX) regex_t re;