Commit Graph

66 Commits

Author SHA1 Message Date
Fabian Homborg
da1b32f0ad
Remove option to use system wcwidth (#5777)
As it turns out it didn't work much better, and it fell behind in
support when it comes to things that wcwidth traditionally can't
express like variation selectors and hangul combining characters, but
also simply $fish_*_width.

I've had to tell a few people now to rebuild with widecharwidth after
sending them on a fool's errand to set X variable.

So keeping this option is doing our users a disservice.
2019-04-01 15:59:33 +02:00
Mahmoud Al-Qudsi
da8e343076 Use is_console_session() to signal using system wcwidth()
The system version of `wcwidth()` reflects the capabilities of the
system's own virtual terminal's view of the width of the character in
question, while fish's enhanced version (`widechar_wcwidth`) is much too
smart for most login terminals, which generally barely support anything
beyond ASCII text.

If, at startup, it is detected that we are running under a physical
console rather than within a terminal emulator running in a desktop
environment, take that as a hint to use the system-provided `wcwidth`.
2019-03-20 21:47:34 -05:00
Fabian Homborg
1a53bbeb9d src/fallback: Include locale.h for the wcstod_l fallback
Fixes #5753.
2019-03-20 08:54:40 +01:00
Fabian Homborg
05b9c07816 wcwidth: Return 0 for median/final jamo
Fixes #5729.
2019-03-13 12:39:08 +01:00
Aaron Gyes
f92c2921d2 Remove mini() and maxi()
C++11 provides std::min/std::max which we're using all over,
obviating the need for our own templates for this.

util.h now only provides two things: get_time and wcsfilecmp.
This commit removes everything that includes it which doesn't
use either; most because they no longer need mini or maxi from
it but some others were #including it unnecessarily.
2019-03-12 23:25:15 -07:00
Fabian Homborg
b318ab17d2 wcwidth: Classify some Hangul Jamo as combiners
Hangul uses three codepoints to combine to one glyph. The first has a
width of 2 (like the final glyph), but the second and third were
assigned a width of 1, which seems to match EastAsianWidth.txt:

> 1160..11FF;N # Lo [160] HANGUL JUNGSEONG FILLER..HANGUL JONGSEONG SSANGNIEUN

Instead, we override that and treat the middle and end codepoint as combiners,
always, because there's no way to figure out what the terminal will
think and that's the way it's supposed to work.

If they stand by themselves or in another combination, they'll indeed
show up with a width of 1 so we'll get it wrong, but that's less
likely and not expressible with wcwidth().

Fixes #5729.
2019-03-12 23:42:50 +01:00
Aaron Gyes
aaacdb89b6 Switches over to cstring from string.h. 2019-03-12 15:09:36 -07:00
Aaron Gyes
d5ac239f68 This commit changes wchar.h includes to cwchar, and uses std::
for everything it provides.
2019-03-12 15:09:36 -07:00
Aaron Gyes
6aa2f29901 Don't increase the width for variation selector 15.
See discussion in #5668 and #5583
2019-02-19 04:27:17 -08:00
Fabian Homborg
f037b0f30f fallback: Use passed locale in wcstod_l
Strange idea, but it just might work.
2019-02-14 10:57:38 +01:00
Fabian Homborg
4562f8f4e3 fallback: Set LC_ALL in wcstod_l fallback
Apparently some wcstod's don't care about LC_NUMERIC.
2019-02-13 20:32:07 +01:00
Aaron Gyes
34fa8ef2d2 Prefer c++11-style [[attr]] syntax over __attribute__ (attr)
Where Clang and GCC both support __attribute__ (attr) and
GCC supports [[gnu::attr]], Clang promises it will support
[[gnu::attr]]
2019-02-10 04:22:40 -08:00
Fabian Homborg
c66b3128ec Use wcstod_l on NetBSD
It has wcstod_l, but not uselocale, so we can't use the fallback.
2019-01-20 18:35:38 +01:00
ridiculousfish
b1f5cb9bf4 Revert "Revert "Fix unsafe locale usage in wcstod_l fallback""
This reverts commit c15a702f18.

The tests are no longer broken after rerunning CMake.
2019-01-19 13:27:28 -08:00
ridiculousfish
c15a702f18 Revert "Fix unsafe locale usage in wcstod_l fallback"
This reverts commit 3444e1db18.

The reverted commit broke tests on the Mac.
2019-01-09 15:23:55 -08:00
Mahmoud Al-Qudsi
3444e1db18 Fix unsafe locale usage in wcstod_l fallback
Using `setlocale` is both not thread-safe and not correct, as
a) The global locale is usually stored in static storage, so
   simultaneous calls to `setlocale` can result in corruption, and
b) `setlocale` changes the locale for the entire application, not
   just the calling thread. This means that even if we wrapped the
   `wcstod_l` in a mutex to prevent the previous point, the results
   would still be incorrect because this would incorrectly influence the
   results of locale-aware functions executed in other threads while
   this thread is executing.

The previous comment mentioned that `uselocale` hadn't worked. I'm not
sure what the failing implementation looked like, but `uselocale` can be
tricky. The committed implementation passes the tests for me under Linux
and FreeBSD.
2019-01-02 18:43:43 -06:00
Mahmoud Al-Qudsi
bc0a0b4bc8 Fix wcstod_l infinite recursion under FreeBSD
This was the actual issue leading to memory corruption under FreeBSD in
issue #5453, worked around by correcting the detection of `wcstod_l` so
that our version of the function is not called at all.

If we are 100% certain that `wcstod_l` does not exist, then then the
existing code is fine. But given that our checks have failed seperately
on two different platforms already (FreeBSD and Cygwin/newlib), it's a
good precaution to take.
2019-01-02 18:43:43 -06:00
Fabian Homborg
a3085a3059 Use varargs tparm on netbsd
This needs to be defined _early_.
2018-12-31 14:24:21 +01:00
Fabian Homborg
ffab420e43 Add fallback wcstod_l for musl
Just sets locale to "C" (because that's the only one we need), does
wcstod and resets the locale.

No idea why uselocale(loc) failed for me, but it did.

Fixes #5407.
2018-12-12 15:12:12 +01:00
ridiculousfish
cbcabf6d00 Add support for fish_ambiguous_width
fish_ambiguous_width is a variable which controls the width of ambiguous CJK
characters.

Fixes #5149
2018-08-18 15:38:05 -07:00
ridiculousfish
1f2b2b119a Remove some disabled (commented or ifdef'd out) code 2018-08-10 20:48:02 -07:00
ridiculousfish
28455235b1 Migrate to widechar_wcwidth
Adopt the new widechar_wcwidth() function from
https://github.com/ridiculousfish/widecharwidth

Fixes #5081
2018-07-09 20:31:16 -07:00
ridiculousfish
5692adbdf6 Teach fish_wcwidth about variation selectors
System wcwidth() misreports variation selectors as width 1. Special
case these to width -1 (unprintable).

See #2652
2018-06-23 16:40:25 -07:00
ridiculousfish
abcc9647da Fix some unused variable warnings 2018-03-31 17:06:13 -07:00
ridiculousfish
5282d3e711 Add fish_emoji_width variable to control computed emoji width
This is part of an effort to improve fish's Unicode handling. This commit
attempts to grapple with the fact that, certain characters (principally
emoji) were considered to have a wcwidth of 1 in Unicode 8, but a width of
2 in Unicode 9.

The system wcwidth() here cannot be trusted; terminal emulators do not
respect it. iTerm2 even allows this to be set in preferences.

This commit introduces a new function is_width_2_in_Uni9_but_1_in_Uni8() to
detect characters of version-ambiguous width. For these characters, it
returns a width guessed based on the value of TERM_PROGRAM and
TERM_VERSION, defaulting to 1. This value can be overridden by setting the
value of a new variable fish_emoji_width (presumably either to 1 or 2).

Fixes #4539, #2652.
2018-02-25 23:38:10 -08:00
ridiculousfish
7bd4af51a1 Switch to Unicode 9 savvy wcwidth
Previously fish used the venerable wcwidth implementation from Markus Kuhn.
This switches to wcwidth9() from https://github.com/joshuarubin/wcwidth9
2018-02-25 23:12:37 -08:00
Mahmoud Al-Qudsi
63c8a197e5 [cmake] Clean up curses vs ncurses includes
There were several issues with the way that the include tests for curses.h
were being done that were ultimately causing fish to use the headers from
ncurses but link against curses on platforms that provide an actual
libcurses.so that isn't just a symlink to libncurses.so

In particular, the old code was first testing for curses's cureses.h and then
falling back to libncurses's implementation of the same - but that logic was
reversed when it came to including term.h, in which case it was testing for
the ncurses term.h and falling back to the curses.h header. Long story short,
while cmake will link against libcurses.so if both libcurses.so and
libncurses.so are present (unless CURSES_NEED_NCURSES evaluates to TRUE, but
that makes ncurses a hard requirement), but we were brining in some of the
defines from the ncurses headers, causing SIGSEGV panics when fish ultimately
tried to access variables that weren't exported or were mapped to undefined
areas of memory in the other library.

Additionally it is an error to include termios.h prior to including the plain
Jane curses.h (not ncurses/curses.h), causing errors about unimplemented types
SGTTY/chtype. So far as I can tell, both curses.h and ncurses/curses.h pull in
termios.h themselves so it shouldn't even be necessary to manually include it,
but I have just moved its #include below that of curses.h
2018-02-04 03:11:22 -06:00
Valery Ushakov
8f0f05ca44 Rewrite tparm_solaris_kludge to call tparm with default parameters
Closes #4502.
2017-10-31 16:48:35 +08:00
Kurtis Rader
be2b6bfdc9 fix lint errors that have crept in 2017-05-06 22:08:07 -07:00
Kurtis Rader
84cf391faa style cleanups 2017-03-15 14:06:58 -07:00
David Adam
42a320064c fallback: restore wcsndup fallback for Apple platforms
Problem introduced in commit 002757225a.
2017-03-06 21:39:37 +08:00
David Adam
002757225a fallback: check for existence of std:: namespace functions
Before defining fallback functions of wcsdup(), wcscasecmp() and
wcsncasecmp(), use the std:: namespace functions instead if they exist.

0019c12af3 fixed the build on Solaris 10, but broke it on Solaris 11.
2017-03-06 21:24:40 +08:00
Kurtis Rader
509ee64fc9 implement our own assert() function
I recently upgraded the software on my macOS server and was dismayed to
see that cppcheck reported a huge number of format string errors due to
mismatches between the format string and its arguments from calls to
`assert()`. It turns out they are due to the macOS header using `%lu`
for the line number which is obviously wrong since it is using the C
preprocessor `__LINE__` symbol which evaluates to a signed int.

I also noticed that the macOS implementation writes to stdout, rather
than stderr. It also uses `printf()` which can be a problem on some
platforms if the stream is already in wide mode which is the normal case
for fish.

So implement our own `assert()` implementation. This also eliminates
double-negative warnings that we get from some of our calls to
`assert()` on some platforms by oclint.

Also reimplement the `DIE()` macro in terms of our internal
implementation.

Rewrite `assert(0 && msg)` statements to `DIE(msg)` for clarity and to
eliminate oclint warnings about constant expressions.

Fixes #3276, albeit not in the fashion I originally envisioned.
2017-02-14 18:48:27 -08:00
Kurtis Rader
7fc1994339 some trivial lint cleanups 2017-02-13 18:48:59 -08:00
Kurtis Rader
5b6cc5af6d time for another make style-all
Gotta keep the entropy (i.e., disorder) from increasing.
2017-01-26 20:05:46 -08:00
ridiculousfish
e5bfdb99b6 Enable mkostemp to be weak-linked
mkostemp is not available on some older versions of macOS. In order
for our built binaries to run on them, mkostemp must be weak-linked.
On other systems, we use the autoconf check.

Introduce a function fish_mkstemp_cloexec which uses mkostemp if
it was detected and is available at runtime, else falls back to
mkstemp. This isolates some logic that is currently duplicated in
two places.

See #3138 for more on weak linking.
2017-01-08 22:18:27 -08:00
ridiculousfish
eb3ed2680b Fix macOS Xcode build
React to Solaris fixes (0019c12af3) by hiding some more
functions from macOS. The Xcode build uses special weak-linking
magic.
2016-12-10 20:48:54 -08:00
Kurtis Rader
0019c12af3 changes to allow building on Solaris 10
Fixes #3456
2016-12-08 19:15:11 -08:00
Kurtis Rader
9443a415bf time for another make style-all 2016-12-03 20:12:53 -08:00
David Adam
3289797248 flock fallback: remove noop path
"fail to no locking" is not an ideal strategy.
2016-12-03 16:36:06 +08:00
David Adam
2b7dddf342 add flock fallback
Import the flock compatibility wrapper from NetBSD.

Work on #3340.
2016-12-03 16:36:06 +08:00
Kurtis Rader
1fb8f4e277 lint: misc cleanups
Earlier lint cleanups overlooked a couple of modules because on macOS at
the moment oclint ignores them. I noticed this when I ran `make lint-all`
on Ubuntu.
2016-11-04 20:12:51 -07:00
Kurtis Rader
00303ed07f lint cleanup: parameter reassignment 2016-10-20 18:53:31 -07:00
Kurtis Rader
c07c98ac05 eliminate many "unused parameter" warnings
Partially addresses issue #3430.
2016-10-09 14:38:26 -07:00
Aaron Gyes
5d4fffcae4 Remove nan() fallback
We stopped using nan() when @krader1961 changed the timef() function
a while back. I removed the autoconf check recently as well.
2016-10-09 07:09:52 -07:00
Kurtis Rader
9f21e3792a remove dependency on dcgettext()
While fixing issue #3110 I noticed there is exactly one place we use
dcgettext() and that use is completely unnecessary. So remove it.
2016-06-05 18:52:19 -07:00
Kurtis Rader
5bf1b0e5f5 fix random lint issues
This only eliminates errors reported by `make lint`. It shouldn't cause any
functional changes.

This change does remove several functions that are unused. It also removes the
`desc_arr` variable which is both unused and out of date with reality.
2016-05-29 22:24:29 -07:00
Kurtis Rader
9ad3488b5d fix some style bogosities that crept in 2016-05-27 14:44:30 -07:00
Kurtis Rader
7c24369454 fix building on Cygwin
Cygwin still doesn't support any of the backtrace functions. Also, remove a
spurious newline from a debug message.

Fixes #2993
2016-05-19 19:27:22 -07:00
Kurtis Rader
46be5ac468 make fish buildable on OS X Snow Leopard
I noticed that the `test_convert()` function was randomly failing when
run on OS X Snow Leopard. I tracked it down to the `mbrtowc()` function on
that OS being broken. Explicitly testing for UTF-8 prefixes that identify
a sequence longer than four bytes (which the Unicode standard made illegal
long ago) keeps us from having encoding errors on those OS's.

This also makes the errors reported by the `test_convert()` function actually
useful and readable.

Lastly, it makes it possible to build fish on OS X Snow Leopard.
2016-05-19 18:42:34 -07:00