Ralph Corderoy [Sun, 27 Aug 2017 19:04:42 +0000 (20:04 +0100)]
mhparam: exit(3) zero if all components found, else one.
The exit status used to be a count of the number missing, clipped to
120. That doesn't seem useful, and is overhead to document, read, and
test. Use the normal Unix 0 or 1 instead.
Ralph Corderoy [Sun, 27 Aug 2017 11:13:39 +0000 (12:13 +0100)]
Replace add(foo, NULL) with mh_xstrdup(foo).
add()'s arguments are back to front so add(foo, bar) produces bar+foo in
the normal case. Thus add(foo, NULL) is read as the jarring NULL+foo.
Removing the NULL with mh_xstrdup() avoids this. FENDNULL is used when
it isn't obvious foo can't be NULL as add() treats it as "" in that
case.
Ralph Corderoy [Sun, 27 Aug 2017 10:34:50 +0000 (11:34 +0100)]
Add die(fmt, ...). Equivalent to adios(NULL, fmt, ...).
Avoids the noise of the `NULL' first parameter that's used in over 70%
of adios() calls. Removes the possibility of it being omitted and `fmt'
being used instead. `die' is already in use in nmh's shell scripts.
Had to rename post.c's existing die() to avoid it clashing.
Ralph Corderoy [Fri, 25 Aug 2017 21:36:01 +0000 (22:36 +0100)]
Print pointers in debug with C99's `%p' rather than `0x%x'.
The `%x' needed a double cast, the `%p' needs just a single to void
pointer. The output can differ, e.g. `0x0' v. perhaps
implementation-defined `(nil)'.
Ralph Corderoy [Fri, 25 Aug 2017 21:20:17 +0000 (22:20 +0100)]
picksbr.c: fprintf function pointer with unsigned-long-long cast.
It was previously a double cast, to unsigned long, and then to unsigned
int, and formatted with `0x%x'. Now we're C99, at least, we can use
unsigned long long and `%#llx'. Though the fprintf() in question should
be a BUG() that abort(3)s.
Ralph Corderoy [Fri, 25 Aug 2017 08:45:00 +0000 (09:45 +0100)]
build_nmh: Stop -d enabling assert(3)s.
c347c3bb enabled asserts by default so alter -d's description to not say
it enables them as this may make users thing that have to disable
optimisation, -d's other action, to get them. Don't add
`--enable-assert' to configure's options.
Ralph Corderoy [Wed, 23 Aug 2017 20:20:25 +0000 (21:20 +0100)]
mhlistsbr.c: Replace list_application() with body at call site.
list_application()'s comment said the function didn't need to exist.
It's correct, so delete it. The sole caller now calls list_content(),
as list_application() used to do. That's actually the same as other
cases in the switch so merge them. There is a slight difference:
list_application() used to call list_content() and then return OK
regardless, now it returns list_content()'s value, but that's always OK
too.
Ralph Corderoy [Mon, 21 Aug 2017 10:09:02 +0000 (11:09 +0100)]
Add ZERO(p) for the typical memset(p, 0, sizeof *p) dance.
Also seen as memset(&foo->bar_xyzzy, 0, sizeof foo->bar_xyzzy). I find
it tedious to keep checking the parameters are in agreement when reading
the code.
Ralph Corderoy [Sun, 20 Aug 2017 13:16:09 +0000 (14:16 +0100)]
cppflags.m4: Don't trample CFLAGS and CPPFLAGS.
They were always being restored, but not necessarily saved first. There
might still be some odd behaviour in this area. I'm seeing -D...
preprocessor symbols disappear on subsequent runs causing compilation
problems, e.g. strcasecmp(3) not prototyped.
Ralph Corderoy [Sun, 20 Aug 2017 11:20:45 +0000 (12:20 +0100)]
sbr/mf.c: Simplify logic, ditching endless for-loops and switch.
Some of the control flow follows the pattern of the larger sections: an
endless for-loop with a switch, and then cases that continue or break,
and another break out of the for loop. For the simpler cases, it's much
easier to read a simple while-loop that achieves the same in fewer
lines. No functional change intended.
Ralph Corderoy [Sun, 20 Aug 2017 10:56:55 +0000 (11:56 +0100)]
sbr/mf.c: Remove QUOTE macro, use its '\\' definition instead.
The name suggests a quote character, not the backslash as an escape
character that quotes what comes after it. It's easier to read '\\' and
instantly know what's meant.
Ralph Corderoy [Sun, 20 Aug 2017 10:38:04 +0000 (11:38 +0100)]
contains8bit(): Don't fetch a byte when start >= end.
The test for a NUL byte was before the test for start being before end.
Whilst here, hoist the test of end out of the per-byte loop, alter the
function to return bool, and merge the two, different, comments
explaining the function's behaviour.
Ralph Corderoy [Sat, 19 Aug 2017 14:58:49 +0000 (15:58 +0100)]
test-sendfiles: Feed `lzma -cd' stdin rather than a filename.
HÃ¥kon Alstadheim reported that Debian's lzma-9.22-2 would complain at
`lzma -cd foo.tar' with `unknown suffix -- unchanged' even though it was
not being asked to alter the file, or produce a new one based on its
filename. This appears to be https://bugs.debian.org/700681. The lzma
from Arch Linux's xz 5.2.3-1 does no have this fault. Work around it by
feeding the file to decompress on standard input for all the compression
programs being tested; none of the others should mind.
David Levine [Thu, 17 Aug 2017 23:45:20 +0000 (19:45 -0400)]
Default CFLAGS to -std=c99 instead of -ansi.
gcc -ansi -pedantic issued a few warnings about C90 not supporting the
"ll" printf length modifier. Ralph pointed out that
http://www.unix.org/version4/overview.html says:
The following source code portability standards lie at the core of
the Single UNIX Specification:
POSIX.1-2008
(This is technically identical to the Base Specifications, Issue 7;
they are one and the same document.)
The ISO/IEC 9899:1999 standard
So perhaps we're wrong to expect modern POSIX code to compile as C90.
Leonardo Taccari [Thu, 17 Aug 2017 23:42:48 +0000 (19:42 -0400)]
mhical expected an ics file as input and after just pressing
^D I've found that mhical wasn't happy about an empty input.
A trivial patch that should fix this issue.
Ralph Corderoy [Thu, 17 Aug 2017 11:20:16 +0000 (12:20 +0100)]
fmtdump.c, fmttest.c: Remove tests for FT_LIT_FORCE.
It isn't defined, and git-grep(1) suggests it was a local Lawrence
Berkeley Laboratory modification that output a literal without consuming
any of the width budget.
Ralph Corderoy [Thu, 17 Aug 2017 10:59:38 +0000 (11:59 +0100)]
Makefile.am: Remove multiple `mkdir -p' for etc; use ./configure.
A `mkdir -p' was used in each rule that created a file in etc to ensure
the directory already existed. Ken pointed out existing ./configure
code to do that for the man directory, just once. Use that for etc too.
Remove the `test -d' because `mkdir -p' does that itself.
Ken Hornstein [Thu, 17 Aug 2017 05:24:08 +0000 (01:24 -0400)]
Fix bug in cpnumber().
The cpnumber() function (which handles the NUMF instruction, among others)
would hang if a 0 width was given to it. Make sure that (and negative
widths) are handled correctly. Note that normally NUMF did not handle
left padding which is indicated by a negative width; that may change
in the future.
Ralph Corderoy [Sun, 13 Aug 2017 23:52:57 +0000 (00:52 +0100)]
inc.c: Use closure for pop_retr()'s action callback.
Allows file-static variables to become local to a function. In fact,
two of them no longer need to exist: one of them becomes the closure's
struct's member, and the other is always 0 and probably just present due
to copy and paste.
Ralph Corderoy [Sun, 13 Aug 2017 16:54:59 +0000 (17:54 +0100)]
popsbr.c: Alter traverse() to check action callback's result.
The action callback returned zero, with a 1999 comment asking if it was
checked. traverse() didn't check it. Change it so it does, wanting
`OK' if all's well, else returning the non-OK value to traverse's
caller; though that only checks for NOTOK. No functional change
intended.
Ralph Corderoy [Sun, 13 Aug 2017 16:13:34 +0000 (17:13 +0100)]
pop_retr(): Add a `void *closure' to be passed to action callback.
Only caller passes in NULL for the moment, and doesn't use it in the
callback, but it will allow fewer scopes by name of the variables the
action callback uses.
Ralph Corderoy [Sun, 13 Aug 2017 15:58:14 +0000 (16:58 +0100)]
inc.c: Narrow scope of inc_type. Chain mutually-exclusive ifs.
Joining the separate if-statements with `else' tells the reader it's not
expected that more than one branch can be taken. Useful when each is
many lines long. No functional change intended.
Ralph Corderoy [Sun, 13 Aug 2017 15:33:06 +0000 (16:33 +0100)]
scan(): Don't ioctl(2) for TTY's width every call.
Saves a system call per message scanned. Does mean it won't adjust
should the terminal width change mid scan, but that seems fine; after
all, the retrieved width could be out of date by the time a message's
output is written anyway.
Ralph Corderoy [Sun, 13 Aug 2017 14:20:14 +0000 (15:20 +0100)]
m_getfld() et al: Replace with m_getfld2(), etc., in many places.
The difference is the FILE pointer isn't passed in on each call.
Instead, it's stored in the m_getfld_state_t once, on
m_getfld_state_init(). No functional change intended.
Ralph Corderoy [Fri, 11 Aug 2017 14:34:41 +0000 (15:34 +0100)]
mhparse.c: Cast ptrdiff_t from subtraction to long.
Cygwin's 32-bit doesn't like `%ld' for the `p - q' difference between
two pointers as the value is an int, not a long. printf(3)'s `t' length
modifier, for ptrdiff_t, can't be used as that's C99, and we're C90.
Cast the difference to a long explicitly instead.
Ralph Corderoy [Thu, 10 Aug 2017 14:44:20 +0000 (15:44 +0100)]
m_getfld() et al: Add wrapper without FILE *iob parameter.
m_getfld(), m_getfld_track_filepos(), and m_unknown() all take a FILE
*iob that's used to update *m_getfld_state_t, even though it's probably,
hopefully, the same as the previous calls. Create wrapper functions for
these with an arbitrary `2' suffix that don't have this parameter.
After checking the m_getfld_state_t is initialised, they pass in its
existing FILE *iob. This allows callers to transition to the wrappers
in the cases where it's obviously the same FILE *iob being passed in.
It isn't always obvious, in part because of the convention for calling
this variable `in', even when it's a file-level static, a word that also
occurs in comments.
Ralph Corderoy [Wed, 9 Aug 2017 22:56:27 +0000 (23:56 +0100)]
m_getfld.c: Alter Peek() to match Getc()'s structure.
Their logic was equivalent, but written differently, which didn't help
the reader easily see they were the same apart from whether the returned
character was consumed. Now they're visually similar too.
Ralph Corderoy [Wed, 9 Aug 2017 18:46:26 +0000 (19:46 +0100)]
m_getfld.c: Use intmax_t and PRIdMAX to printf off_t values.
Compiling for ISO C90 prohibits casting to long long and printing with
"%lld", and printing as "%ld" is wrong on Mac OS where David reports
off_t is long long.