Ingo Schwarze [Thu, 6 Jun 2013 14:27:02 +0000 (14:27 +0000)]
No point in inventing yet another file name for the database.
We are not going back to Berkeley DB and don't care about
overwriting any obsolete files that may be lying around.
So, go back from "mandocdb.db" to "mandoc.db".
Ingo Schwarze [Thu, 6 Jun 2013 02:40:37 +0000 (02:40 +0000)]
In parse_catpage(), the comment saying that the filename would be
used as a default page description if no usable NAME section was found
was preserved when moving from db to sqlite, but the code line actually
doing that was removed without replacement. So, put it back.
Ingo Schwarze [Wed, 5 Jun 2013 20:27:11 +0000 (20:27 +0000)]
Two sanity checks got lost in treescan()
during the switch from db to sqlite; restore these:
* Warn and skip when directory and file name mismatch.
* Warn and skip when finding special files.
* Warning about "mandocdb.db" is useless, it is always present.
* While here, do not hardcode "mandocdb.db", use MANDOC_DB.
Ingo Schwarze [Wed, 5 Jun 2013 17:48:14 +0000 (17:48 +0000)]
Add back the realpath() checks that got lost during the change from
db to sqlite; they are needed to prevent corruption of the database
when paths containing dot, dotdot, or symlinks are given on the
command line. Also make sure the exit-code is really non-zero on
system errors and use mandoc(1) exit codes.
To make all this simpler,
* Drop the "basedir" argument from almost every function and make it
global because it is really state info used all over the place.
* Move "startdir" and "fd" as local vars into set_basedir() because they
are only used for this one purpose, i.e. to move out of basedir again.
While here,
* Clarify the name of path_arg in the main program; in the -C case,
it is not a dir, and anyway there are lots of different dirs around.
* Include missing <stdio.h> needed for perror().
Ingo Schwarze [Wed, 5 Jun 2013 02:00:26 +0000 (02:00 +0000)]
Some places used PATH_MAX from <limits.h>, some MAXPATHLEN from <sys/param.h>.
Consistently use the PATH_MAX since it is specified by POSIX,
while MAXPATHLEN is not.
In preparation for using this at a few more places.
Ingo Schwarze [Mon, 3 Jun 2013 22:51:14 +0000 (22:51 +0000)]
Changing existing SQLite databases was utterly broken:
1) SQL statements were only prepared when creating a new database.
2) We rely heavily on foreign_keys, but never enabled them.
Ingo Schwarze [Mon, 3 Jun 2013 19:01:31 +0000 (19:01 +0000)]
Starting the preparations to integrate this into OpenBSD.
As variadic macros are not supported on all architectures,
replace them by a real function. While here,
* choose a more logical order for "dir" and "file" arguments
* choose a more logical order when printing; as a bonus,
a simple sed 's/:.*//' will get you valid file names
* in ofmerge(), skip diagnostic string comparisons
when we don't want warnings anyway
Ingo Schwarze [Sun, 2 Jun 2013 18:16:57 +0000 (18:16 +0000)]
Let .Do .Dq .Ql .So .Sq generate the correct roff(7) character escape
sequences such that output modes like -Tutf8 have a chance to select
nice glyphs. This doesn't change anything for -Tascii, and, for now,
it doesn't affect -Tps and -Tpdf either.
OK matthew@ bentley@; like the idea tedu@; no opinion jmc@.
Ingo Schwarze [Sun, 2 Jun 2013 03:52:21 +0000 (03:52 +0000)]
Sync to OpenBSD, no functional change:
* Add the missing mparse_parse_buffer prototype.
* Drop the useless MAP_FILE constant: It's not specified in POSIX,
so it's not required, it's the default anyway, and it's 0 anyway.
Ingo Schwarze [Sat, 1 Jun 2013 22:57:35 +0000 (22:57 +0000)]
This file contains too much complexity.
Remove one layer of indirection by deleting mparse_readfd_r()
and doing its work in the public mparse_readfd().
As a bonus, catch recursive .so.
This is part of the preparations to resync to openbsd.org.
Ingo Schwarze [Sat, 1 Jun 2013 05:44:39 +0000 (05:44 +0000)]
Some documentation of the tbl parser.
I needed this when working on tbl(7) bug fixes.
Deliberately not linked to the build;
this is developer documentation, not user documentation.
Ingo Schwarze [Sat, 1 Jun 2013 04:56:50 +0000 (04:56 +0000)]
If a table contained at least one complete line
and on its last line, the first T{ remained unclosed,
roff_parseln() never returned ROFF_TBL for that last line,
so {man,mdoc}_addspan() never got called for that last line,
so we ended up with a table
where no line associated with a node had TBL_SPAN_LAST set,
so tbl_term() never free()'d the cols in struct roffcol,
so tblcalc() crashed on the NULL == tbl->cols assertion
when starting the *next* table in the same file.
Fix this by returning ROFF_TBL as soon as we open a data cell,
not only when finishing it - as explained above, it may never
get properly closed but instead be interrupted by .TE.
Problem reported by bentley@ in latex2man.1.
I love it when bugs take half a day to debug but
the fix turns out to be flipping one single bit in the source code.
Ingo Schwarze [Fri, 31 May 2013 22:08:09 +0000 (22:08 +0000)]
More cleanup: Consistently use the name "struct tbl_node *tbl"
that is already used almost everywhere instead of gratuitiously
inventing different names at four places. No functional change.
Ingo Schwarze [Fri, 31 May 2013 21:37:17 +0000 (21:37 +0000)]
The name "struct tbl" was badly misleading for two reasons:
1) This struct almost exclusively contains the table options.
2) Information about the table as a whole is actually in "struct tbl_node".
Besides, "struct tbl" was almost impossible to search for.
So rename it to "struct tbl_opts". No functional change.
Ingo Schwarze [Thu, 30 May 2013 03:52:59 +0000 (03:52 +0000)]
Reject non-printable characters found in the input stream even when
preceded by a backslash; otherwise, the escape sequence would later
be identified as invalid and the non-printable character would be
passed through to the output backends, sometimes triggering assertions.
Reported by Mike Small <smallm at panix dot com> on the mdocml discuss list.
Ingo Schwarze [Wed, 29 May 2013 22:48:10 +0000 (22:48 +0000)]
Sync to OpenBSD:
* Guard <sys/param.h> inclusion by #ifdef USE_MANPATH
to make it more obvious why this isn't needed on OpenBSD.
Noticed by deraadt@.
* Resolve gratuitious whitespace differences:
Blanks before tabs and on empty lines.
Ingo Schwarze [Sun, 19 May 2013 21:40:24 +0000 (21:40 +0000)]
Support .Bl -offset in -mdoc -Tman.
Issue found when Thomas Klausner <wiz at NetBSD dot org> made me
look at the manuals of his http://www.nih.at/libzip library.
Ingo Schwarze [Sun, 19 May 2013 21:07:51 +0000 (21:07 +0000)]
Move printing of the .RS macro into print_offs() such that print_offs()
takes care of printing the whole line. This reduces code duplication -
in particular after the upcoming commit to repair .Bl -offset -
and makes print_offs() more similar to what print_width() does.
No functional change.
Ingo Schwarze [Sat, 18 May 2013 17:47:47 +0000 (17:47 +0000)]
Should termp_xx_pre() ever get called for a macro it cannot handle,
use abort(3), just like in the three other comparable cases in this file,
instead of ignoring the problem and causing a null pointer access.
Cosmetical issue reported by Ulrich Spoerlein <uqs@spoerlein.net>
found by Coverity Scan CID 976115.
No functional change.
Ingo Schwarze [Sat, 18 May 2013 17:08:43 +0000 (17:08 +0000)]
Remove the variable sz because it's invariantly == 0,
along with the dead code testing whether it's positive.
Reported by Ulrich Spoerlein <uqs@spoerlein.net>,
found by Coverity Scan CID 975717.
While here, remove the now unused **params array as well,
which Coverity apparently missed, at least it wasn't reported...
Ingo Schwarze [Sat, 18 May 2013 16:40:15 +0000 (16:40 +0000)]
Even though the size of a pointer should not depend on the type of the
data pointed to, pass the size of the right pointer type to calloc;
cosmetic issue reported by Ulrich Spoerlein <uqs@spoerlein.net>
found in Coverity Scan CID 978734.
No binary change - ok cmp(1).
Ingo Schwarze [Sat, 5 Jan 2013 22:19:12 +0000 (22:19 +0000)]
In literal mode (.nf), each input line must be kept together
on the same output line, even if it is longer than the output width.
This commit fixes a bug allowing an overly long last line of an
indented block (.RS) to be broken even in literal mode.
The bug was found using the sudo_plugin(4) manual provided by millert@.
I introduced the bug in rev. 1.84 during the g2k12 Budapest hackathon.
Ingo Schwarze [Mon, 31 Dec 2012 22:34:48 +0000 (22:34 +0000)]
Rewrite indentation handling for nested lists in a more systematic way
to fix multiple issues reported by Todd Miller; thanks!
Specifically,
- avoid double indentation after .Bd inside .Bl
- set up correct indentation after .Bl inside .Bl
- set up correct indentation after .Dl and .D1 inside .Bl
While here, also
- set up correct indentation *inside* .Dl and .D1 inside .Bl.
Ingo Schwarze [Mon, 19 Nov 2012 17:57:23 +0000 (17:57 +0000)]
In groff, trying to redefine standard man(7) macros before .TH has no effect;
after .TH, it works. Trying to redefine standard mdoc(7) macros before .Dd
works when calling groff with the -mdoc command line option, but does not
when calling groff with -mandoc; after .Dd, it always works.
Arguably, one might call that buggy behaviour in groff, but it is very
unlikely that anybody will change groff in this respect (certainly, i'm
not volunteering). So let's be bug-compatible.
This fixes the vertical spacing in sox(1).
Merging from OpenBSD libmandoc.h 1.18, read.c 1.8, roff.c 1.47, June 2, 2012.
Ingo Schwarze [Mon, 19 Nov 2012 02:08:33 +0000 (02:08 +0000)]
Three portability improvements by millert@:
* Use "\\ " not "\\~" as the non-breaking space as historic nroff
doesn't support the latter.
* The '-' before the flags needs to be quoted to prevent nroff
from putting a line break between the '-' and the flag character.
* Disable hyphenation and, for nroff, disable justification which is
consistent with how mdoc behaves (and produces more readable manuals).
Ingo Schwarze [Sun, 18 Nov 2012 18:02:23 +0000 (18:02 +0000)]
Correct indentation for lists and displays inside lists.
Inspired by a diff from millert@, but implemented rather
differently and with slightly better functionality.
In particular, this one respects -offset and -width
arguments found in the input file.
Ingo Schwarze [Sat, 17 Nov 2012 00:26:33 +0000 (00:26 +0000)]
Cleanup naming of local variables to make the code easier on the eye:
Settle for "struct man *man", "struct mdoc *mdoc", "struct meta *meta"
and avoid the confusing "*m" which was sometimes this, sometimes that.
No functional change.
Ingo Schwarze [Fri, 16 Nov 2012 18:44:32 +0000 (18:44 +0000)]
End of sentence spacing after trailing punctuation after .In and .Ap
has just been fixed. Note that my problem description was somewhat
misleading, even though Nicolas Joly's problem report was fine.
Ingo Schwarze [Fri, 16 Nov 2012 18:41:18 +0000 (18:41 +0000)]
Two more macros (.Ap and .In) do trailing delimiter handling.
This fixes the end of sentence spacing in OpenBSD open(2)
and in about 150 pages in the NetBSD base system.
Reported by Nicolas Joly <njoly a pasteur point fr>, merci!
Ingo Schwarze [Fri, 16 Nov 2012 17:16:55 +0000 (17:16 +0000)]
Improve formatting of badly nested font blocks.
The basic idea is to already pop the font at the end marker
instead of allowing it to linger until the final end of the block.
This requires a few preliminaries:
* For each block, save a pointer to the previous font
to be used in case the block breaks another and gets extended.
* That requires making node information writable during rendering.
* Now fonts may get popped in the wrong order; hence, after the stack
has already been rewound further by some block that began earlier,
ignore popping a font that was put on the stack later.
* To be able to exploit all this for font blocks, tie processing
to their body, not their block, which is more logical anyway.
Triggered by florian@ reporting vaguely similar issues with list blocks.
Ingo Schwarze [Fri, 16 Nov 2012 13:40:36 +0000 (13:40 +0000)]
Fix a crash triggered by .Bl -tag .It Xo .El .Sh found by florian@.
* When allocating a body end marker, copy the pointer to the normalized
block information from the body block, avoiding the risk of subsequent
null pointer derefence.
* When inserting the body end marker into the syntax tree, do not try to
copy that pointer from the parent block, because not being a direkt child
of the block it belongs to is the whole point of a body end marker.
* Even non-callable blocks (like Bd and Bl) can break other blocks;
when this happens, postpone closing them out in the usual way.
Completed and tested at the OpenBSD impromptu Coimbra hackathon (c2k12).
Thanks to Pedro Almeida and the Laborat'orio de Computa,c~ao Avan,cada
da Universidade de Coimbra (http://www.uc.pt/lca) for their hospitality!
Ingo Schwarze [Wed, 29 Aug 2012 23:38:50 +0000 (23:38 +0000)]
1) Remove documentation of the groff-1.15 compatibility quirk
of suppressing spacing before a third .Xr argument
because that quirk was removed in mdoc_macro.c rev. 1.113.
2) Mark the "section" argument to .Xr as (syntactically) optional,
but still do not encourage omitting it.
The missing .Op was reported by espie@.
Fix handling of paragraph macros inside lists:
* When they are trailing the last item, move them outside the list.
* When they are trailing any other none-compact item, drop them.
The mdoc(7) \*(Ba predefined string actually forces roman font;
that's stupid because it may break enclosing font changes,
but let's do the same for groff bug compatibility.
--> Never use \*(Ba, use just plain "|"! <--
Also, predefined strings are already expanded by the roff(7) parser,
so the mdoc(7) parser has to look for the expanded string.
Always fix the man(7) subsection header (.SS) indent to 3n,
do not let it depend on the default indent provided by -Oindent.
By default, this doesn't change anything because 7 / 2 = 3;
in -Omdoc mode, it makes man(7) output the same as mdoc(7) output.
OpenBSD rev. 1.87
In flush-left mode of both man(7) and mdoc(7), when an output line is broken
at the position of a literal tab, the tab indents the following line.
Fixes the perl(1) SYNOPSIS; reminded by deraadt@; OpenBSD rev. 1.66.
Several -mdoc parser improvements related to vertical spacing:
* So far, .Pp and .Lp were removed before paragraph type blocks.
* Now also remove .br before paragraph type blocks.
* Treat .Lp as a paragraph like .Pp, so remove .Pp, .Lp, .br before it.
* Do not treat .sp as a paragraph, don't remove anything before it.
* After .Sh, .Ss, .Pp, and .Lp, remove .Pp, .Lp, .sp, .br, and blank lines.
* After .sp and .br, remove .br.
OpenBSD rev. mdoc.c 1.89 and mdoc_validate.c 1.106
Translate blank input lines to .sp just like in mdoc(7),
and ignore .sp after .PP. This fixes vertical spacing
for blank lines after .PP and for .sp after .PP.
OpenBSD rev. man.c 1.68 and man_term.c 1.86
In -Tman .Bl -compact, skip the blank line only before the first item
of the first list in a section, not before every item of the first list.
OpenBSD rev. 1.37
If the tag in .Bl -tag .It would leave exactly one blank before the
body of the item, mdoc(7) breaks the line, whereas the .TP used to
translate this to man(7) does not. Thus, insert an explicit roff(7)
line break in this place.
To be able to correctly count the characters, do not pass font escapes
an the like through print_word().
OpenBSD rev. 1.35
In -man -Tascii, support .sp with negative argument.
In -mdoc -Tman, improve the framework to control vertical spacing.
Use both to support .Bl -compact (surprisingly hard to get right).
OpenBSD rev. 1.85 and 1.34, respectively.
The post_nm() validation function crashed when the first .Nm child node
was a non-text node. Fix this by rewriting post_nm() to always set
the meta name to UNKNOWN when the name is missing or unusable.
While here, make MANDOCERR_NONAME an ERROR, as it usually renders
the page content unintelligible.
Bug reported by Maxim <Belooussov at gmail dot com>, thanks.
OpenBSD rev. 1.105
Do not crash in -Tman on:
* .Fn with exactly one argument
* .Bl -hang without a -width
Now all 3776 OpenBSD base manuals build without crashing.
OpenBSD rev. 1.33
multiple fixes to -Tascii .HP rendering:
* do not add an excessive blank line before the block
* in literal mode, start a new line after the tag
getting this to work requires some general (print_man_node) fixes:
* in literal mode, break the output line at the end of each
input line, not just after those input lines ending in text
* but don't break it when there was no output on the line
* and adjust the margins after the .HP tag
these general fixes require an adjustment to -Tascii .TP rendering:
* set up NOBREAK mode before the body, not after the head
finally, based on all this, implement -Tman .Bl -hang in terms of .HP
Remove a hack that was intended for groff-1.15 bug compatibility:
When the width of a tag in .Bl -hang was exactly one character
shorter than the maximum length that would fit, the following text
would have a negative hang of one character (i.e., hang to the left).
That bug is no longer present in groff-1.21, so relax mandoc, too.
OpenBSD rev. 1.65
* implement -Tman .Bl -item -inset -diag -ohang -dash -hyphen -enum .It
* fix -Tman .Bl -bullet .It
* adjust the -Tascii .Bl -bullet -dash -hyphen .It
default and minimum width to new groff standards,
it changed from 4n (in groff 1.15) to 2n (in groff 1.21)
* same for -Tascii -enum, it changed from 5n to 2n
* use -hang formatting for -Tascii -enum -width 2n
* for -Tascii -enum, the default is -width 3n
Implement -Tman .Bf.
To get the spacing right,
* avoid man(7) code line breaks at places where no spacing is allowed
* allow spacing right after .Sm on
* allow spacing after empty .Fl at the end of an input line
OpenBSD rev. 1.25
Add flags to insert a .sp or .br request before the next output,
shortening some frequent idioms and preparing for better vertical
spacing in the SYNOPSIS; no functional change intended.
OpenBSD rev. 1.19
Instead of adding one integer variable for each global boolean output flag
and passing around a structure containing them into each and every function,
just use a single static bitfield.
In preparation for adding more output flags to support more features.
OpenBSD rev. 1.18
Basic implementation of -Tman .Fo and .Fa;
again, some blank lines still missing from the output.
While here, remove the trailing semicolon
from .Fn when outside .Sh SYNOPSIS.
OpenBSD rev. 1.14
minor -mdoc -Tman fixes
* right after .Ns, avoid breaking the line in man code
* after .Fl without arguments, do not insert a blank into man code
* before each .Nm in .Sh SYNOPSIS, insert a .br into man code
* skip .Pp arguments, don't copy them to man code
Ingo Schwarze [Wed, 20 Jun 2012 22:06:30 +0000 (22:06 +0000)]
When i moved some low-level stuff from mdoc(7) and man(7)
to roff(7) some time ago, i forgot to adjust the cross-references.
Reported by Tim van der Molen <tbvdm at xs4all dot nl>, thanks.
Add `cc' support.
This was reported by espie@ and in the TODO.
Caveat: `cc' has buggy behaviour when invoked in groff(1) and followed
by a line-breaking control character macro, e.g., in a -man doc,
.cc |
.B foo
'B foo
|cc
'B foo
will cause groff(1) to behave properly for `.B' but inline the macro
definition for `B' when invoked with the line-breaking macro.