rillig [Fri, 26 Feb 2021 15:15:34 +0000 (15:15 +0000)]
cgram: place the 'solved' marker nearer to the text
This way, it cannot be overlooked as easily as before. It also doesn't
change the position of the keyboard help text anymore. Only if there is
not enough space, the 'solved' marker is put into the bottom line.
rillig [Mon, 22 Feb 2021 19:34:07 +0000 (19:34 +0000)]
cgram: fix assertion when substituting at the end of the longest line
Reported by Weitian LI via GitHub.
Contrary to the patch suggested in [1], still allow the cursor to be
placed to the very right of the text in a line since that is the usual
behavior of text editors.
Split the function substitute() into two parts: one that handles the
curses-specific part of checking whether a substitution is possible at
the current cursor position, and one that performs the actual
substitution. Only the latter is kept in the code section for the
string manipulation functions, the other is moved to the section for
curses code. Having all the curses code in one place reduces the places
that call beep(). Previously, as well as now, there is a single beep
per invalid key before, but that was not obvious from the previous code.
rillig [Mon, 22 Feb 2021 16:28:20 +0000 (16:28 +0000)]
cgram: properly handle input errors
On both NetBSD and Cygwin, a missing /usr/bin/fortune would previously
continue since popen does not return an error (as /bin/sh is found and
can be executed), so the next chance to catch an error is pclose. At
that point, the shell has already printed an informative error message
about what happened (or what didn't happen), so that cgram does not need
to print an error by itself.
rillig [Sun, 21 Feb 2021 20:33:42 +0000 (20:33 +0000)]
cgram: rewrite completely, fixing bugs and style
Fixed bugs:
Do not consider the puzzle solved if all letters in the visible area are
substituted correctly. To be properly solved, the whole puzzle must be
solved, even those parts that are currently off-screen.
Never place the cursor at the very right edge of the screen since that
does not work well with some terminals. The maximum valid x coordinate
is COLS - 1.
Add horizontal scrolling. Make all coordinate handling symmetric in
regard to the horizontal and vertical axes. Previously, lines longer
than 80 characters could not be seen on the screen.
Improvements:
Remove the arbitrary limit of 128 characters per line. Even if
fortune(6) may never generate such long lines, the code is easy enough
to adapt to other sources.
Properly clean up the allocated memory. Previously, only the string
arrays were freed but not the strings themselves.
Stylistic:
Add RCS ID.
Fix ctype functions in lint's strict bool mode.
Avoid excessive calls to strlen whenever the cursor moves. Given that
the whole screen is redrawn every time a key is pressed, this is an
unnecessary optimization, but the code smelled nevertheless.
rillig [Sun, 21 Feb 2021 16:50:57 +0000 (16:50 +0000)]
cgram: consistently use char for characters
Having to convert back and forth between char, unsigned char and int is
confusing. Just stay with char, until the support for wide characters
is added.
rillig [Sun, 21 Feb 2021 15:41:04 +0000 (15:41 +0000)]
cgram: indent
With manual corrections afterwards:
- indent removes empty lines between statement and declaration. This
had been a syntax error in C90, since C99 this is common style and
should be accepted by indent.
- indent didn't format the first line of main for whatever reason, did
that manually.
- indent removed the empty line above the '/////' separators. It should
have left these empty lines as-is.
dholland [Mon, 9 Nov 2020 03:23:14 +0000 (03:23 +0000)]
Restore the catman joke.
It needs the (8), or it fails to work for people who don't know or had
forgotten catman(8) was ever a thing.
as the de facto fortunes editor and also I think the person who added
that fortune in the first place, and given the discussion in
tech-userlevel, I think I get to do this.
christos [Sat, 3 Oct 2020 22:27:00 +0000 (22:27 +0000)]
PR/55693: Andreas Gustafsson: factor(6) lists factors in wrong order
Sync with FreeBSD and change their -h (that printed hex) to -x because
we were already using -h.
Avoid messing up the display when too many letters are guessed at once.
The field to put them in was made 26 characters wide... but includes
the string "Guessed: ". So if you get to 17 it wraps to the next line
and clreol()'s it. Instead, when reaching this point step on the
"Guessed:" string instead.
sevan [Sat, 22 Feb 2020 19:03:04 +0000 (19:03 +0000)]
Andrew Weatherall's tattoo and a track on A Pox On The Pioneers album.
https://pbs.twimg.com/media/ERAuddhU4AAFv3w?format=jpg&name=orig
Story:
https://www.dummymag.com/features/andrew-weatherall-interview-it-s-bollocks-it-s-discos-tell-me-tales-of-the/
use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.
we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."