Some cleanups

Please don't merge as-is, go over these one-by-one and cherry-pick whatever you like (or merge if you like 'em all, of course).

Most patches inspired by the output of `checkincludes.pl` and `checkpatch.pl`.

The `sscanf` replacement (2f6f18a) could be wrong (didn't actually test this stuff, let CI do that :wink:)