From 1674f8e3086193342dfeadca04740e7ea8264e13 Mon Sep 17 00:00:00 2001 From: christos Date: Wed, 24 Feb 2016 19:45:48 +0000 Subject: [PATCH] Fix el_{w,}getc documentation (Ingo Schwarze) --- lib/libedit/editline.3 | 54 +++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3 index f9f8d01db7cc..688dee4aef60 100644 --- a/lib/libedit/editline.3 +++ b/lib/libedit/editline.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: editline.3,v 1.86 2016/02/24 18:28:54 christos Exp $ +.\" $NetBSD: editline.3,v 1.87 2016/02/24 19:45:48 christos Exp $ .\" .\" Copyright (c) 1997-2014 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -173,6 +173,16 @@ library (which needs the library). Programs should be linked with .Fl ledit ltermcap . +.Pp +The +.Nm +library respects the +.Dv LC_CTYPE +locale set by the application program and never uses +.Xr setlocale 3 +to change the locale. +The only locales supported are UTF-8 and the default C or POSIX locale. +If any other locale is set, behaviour is undefined. .Sh LINE EDITING FUNCTIONS The line editing functions use a common data structure, .Fa EditLine , @@ -238,14 +248,42 @@ contains the error code that caused it. The return value may not remain valid across calls to .Fn el_gets and must be copied if the data is to be retained. +.It Fn el_wgetc +Read a wide character from the tty, respecting the current locale, +or from the input stream written by +.Fn el_wpush +and +.Fn el_push +if that is not empty, and store it in +.Fa ch . +If an invalid or incomplete character is found, it is discarded, +.Va errno +is set to +.Dv EILSEQ , +and the next character is read and stored in +.Fa ch . +Returns 1 if a valid character was read, 0 on end of file, or -1 on +.Xr read 2 +failure. +In the latter case, +.Va errno +is set to indicate the error. .It Fn el_getc -Read a character from the tty. -.Fa ch -is modified to contain the character read. -Returns the number of characters read if successful, \-1 otherwise, -in which case -.Dv errno -can be inspected for the cause. +Read a wide character as described for +.Fn el_wgetc +and return 0 on end of file or -1 on failure. +If the wide character can be represented as a single-byte character, +convert it with +.Xr wctob 3 , +store the result in +.Fa ch , +and return 1; otherwise, set +.Va errno +to +.Dv ERANGE +and return -1. +In the C or POSIX locale, this simply reads a byte, but for any other +locale, including UTF-8, this is rarely useful. .It Fn el_push Pushes .Fa str