Created attachment 172364 [details] remove isprint check & switch setlocale() to use LC_ALL Using the following test: setenv LC_ALL de_CH.ISO8859-1 foreach i ( `jot 178 178 356` ) echo a | tr 'a' "\$i" | cat -v end output will contain some printable characters listed instead with a question mark. removing the !isprint() check for vflag results in printable characters being displayed correctly again. Making the behaviour of cat -v consistent whether locale is set to C (default) or another. Attached patch removes the !isprint() check and switches from just setting locale settings set in LC_CTYPE to LC_ALL to import all set locale variables.
Taking a guess at adding some folks I think might be more knowledgable about locales to cc.
Removing isprint() is good, but why you need LC_ALL?
From second thought, this patch does not help at all. Looking at the code I realize that cat should use wide chars everywhere, getwc(), isw*() etc (with fallback to getc() on error). Current code suppose single byte locale and will works incorrectly for any multibyte locale.
Created attachment 173315 [details] use wide chars with fallback to plain ones More testing required, I test a little.
Created attachment 173316 [details] use wide chars with fallback to plain ones Move err label higher to not miss clearerr(fp)
Created attachment 173318 [details] use wide chars with fallback to plain ones Use traditional M-^X form for non-ascii controls
BTW, this is wrong: foreach i ( `jot 178 178 356` ) echo a | tr 'a' "\$i" | cat -v tr suppose to take \octal numbers only, but they are decimal.
It must be foreach i ( `( echo obase=8 ; jot 178 178 255 1) | bc` )
(In reply to Andrey Chernov from comment #2) unless you want to be specific in the LC_ variables to inherit, it's better moving forward that you opt for LC_ALL, at present (tested on FreeBSD), only having LC_CTYPE means that localisation is broken Eg Stock cat in base: % cat ouauouau cat: ouauouau: No such file or directory Using LC_ALL instead. % /usr/obj/usr/src/bin/cat/cat thotuhou cat: thotuhou: Datei oder Verzeichnis nicht gefunden I could ammend the patch to use the addition of the specific variable but it'd create less churn in the future to switch or add new additions to setlocale().
(In reply to Andrey Chernov from comment #6) Will give the new patch a spin & provide feedback (In reply to Andrey Chernov from comment #8) thanks, I'll use that in my testing
Created attachment 174708 [details] use wide chars with fallback to plain ones Better version
Since initial test was wrong (see my fixed version at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=210995#c8 ) my patch does not solve this problem, because the problem does not exist. It solves completely different problem with multibyte encodings, and I plan to commit it soon. About LC_ALL, please fill separate PR.