Ingo Schwarze [Sat, 5 Oct 2013 22:21:20 +0000 (22:21 +0000)]
ROFFRULE_ALLOW = 0, ROFFRULE_DENY = 1 was confusing,
so exchange the two entries in enum roffrule; no functional change;
from Christos Zoulas, NetBSD rev. 1.11, April 4, 2013.
Ingo Schwarze [Sat, 5 Oct 2013 22:19:10 +0000 (22:19 +0000)]
Avoid code duplication in roff_parseln() as suggested by
Christos Zoulas in NetBSD rev. 1.11;
i'm even going a step further and making this yet a bit shorter.
No functional change.
Ingo Schwarze [Sat, 5 Oct 2013 22:15:03 +0000 (22:15 +0000)]
Expand references to number registers in exactly the same way as
references to user-defined strings. While here, make number registers
signed int, like in groff.
Inspired by NetBSD roff.c rev. 1.8 and read.c rev. 1.7
written by Christos Zoulas on March 21, 2013, but implemented
in a completely different way, without hacking into read.c,
where this functionality really doesn't belong.
Ingo Schwarze [Sat, 5 Oct 2013 22:08:12 +0000 (22:08 +0000)]
Support setting arbitrary roff(7) number registers,
preserving read support for the ".nr nS" SYNOPSIS state register.
Inspired by NetBSD roff.c rev. 1.18 (Christos Zoulas, March 21, 2013),
but implemented differently. I don't want to have yet another different
implementation of a hash table in mandoc - it would be the second one
in roff.c alone and the fifth one in mandoc grand total.
Instead, i designed and implemented roff_setreg() and roff_getreg()
to be similar to roff_setstrn() and roff_getstrn().
Once we feel the need to optimize, we can introduce one common
hash table implementation for everything in mandoc.
Ingo Schwarze [Sat, 5 Oct 2013 20:30:05 +0000 (20:30 +0000)]
Cleanup suggested by gcc-4.8.1, following hints by Christos Zoulas:
- avoid bad qualifier casting in roff.c, roff_parsetext()
by changing the mandoc_escape arguments to "const char const **"
- avoid bad qualifier casting in mandocdb.c, index_merge()
- do not complain about unused variables in test-*.c
- garbage collect a few unused variables elsewhere
Ingo Schwarze [Wed, 2 Oct 2013 06:45:43 +0000 (06:45 +0000)]
Merge from branch VERSION_1_12:
- mention that groff is GPL version 3
- link the new tbl.3.html
- list FreeBSD base version of mandoc
- document downstream versions
- copy the version 1.12.2 News
Ingo Schwarze [Wed, 2 Oct 2013 06:44:55 +0000 (06:44 +0000)]
Merge from branch VERSION_1_12:
- add the new SCRS files NEWS and gmdiff
- add tbl.3 to SRCS, INDEX_MANS, and install
- bring back the SCRS files apropos.{c,1} that somehow got lost
- bring back the INDEX_MANS apropos.1.html that also got lost
- update VERSION, VDATE, and OSNAME
- improve comment regarding STATIC
Throwing FATAL MANDOCERR_SYNTCHILD on non-.It children of .Bl
feels so 2008-ish, one of the last remnants of the
Kristaps-doesnt-like-syntax-errors-so-lets-just-give-up--Era.
One of the WARNING messages has to use the word "section" twice in two
different meanings, that cannot be helped. But we can make this less
confusing by stating that the second instance refers to stuff like (2),
(3), and (9), and by adding the sections header the first instance
refers to, for example ERRORS or RETURN VALUES.
Source for confusion noticed by Jan Stary <hans at stare dot cz>,
better wording suggested by jmc@, tweaked by me.
Use normal line macro recognition, do not attempt to roll your own.
This fixes horizontal spacing when an Ns macro follows a block-closing
macro and the corresponding block-opening macro is not on the same line.
Block closing macros do not allocate a new node but finish an existing
one, so they miss the clearing of MDOC_NEWLINE in mdoc.c, node_alloc().
Consequently, MDOC_NEWLINE must be cleared before processing the next
macro on the same line.
This fixes horizontal spacing for input lines beginning like .Oc Ns ...
Issue found by Franco Fichtner <franco at lastsummer dot de>
while working on DragonFly mandoc integration.
For some mdoc(7) macros, it is (unfortunately) semantically significant
whether they are the first macro on the line or called by another macro.
To help debugging, indicate this property "first macro on a new input line"
by prefixing an asterisk to the line number in -Ttree output.
Ingo Schwarze [Wed, 21 Aug 2013 21:20:40 +0000 (21:20 +0000)]
Move the last column-counting members of struct termp (col and maxcols)
from int to size_t, to match some existing ones (offset, *rmargin, viscol).
Move some related local variables from int to size_t as well.
Needed as a preparation to make a generalized adjbuf() function available
beyond the file term.c, i.e. in mandoc.c.
Also saves a couple of ugly casts.
Ingo Schwarze [Wed, 14 Aug 2013 15:08:31 +0000 (15:08 +0000)]
Use text production macros to document themselves.
Part of the patch was sent in by Jan Stary <hans at stare dot cz>,
another part was added by jmc@, the rest was added by myself;
ok jmc@.
Ingo Schwarze [Thu, 8 Aug 2013 20:07:47 +0000 (20:07 +0000)]
Implement the roff(7) font-escape sequence \f(BI "bold+italic".
This improves the formatting of about 40 base manuals
and reduces groff-mandoc formatting differences in base by about 5%.
Ingo Schwarze [Mon, 5 Aug 2013 23:36:42 +0000 (23:36 +0000)]
After a leading blank on an output line, the first word was counted twice
against vend, causing a premature line break. Fix that bug by reverting
revision 1.93 which Kristaps committed four years ago. Kristaps patch is no
longer needed because the code below /* Write out the [remaining] word. */
now handles leading blanks correctly, probably already for a long time.
This avoids premature line breaks in about a dozen base system manuals,
for example as(1) and gdb(1), and alignment issues in another twenty,
for example mount(2), ip6(4), pfctl(8), and crypto(9).
Rudimentary implementation of the .it request (input line trap).
As with any low-level roff request involving subtle interactions
with macro internals, this implementation is not exact, but it
does handle the simplest cases.
This request occurs in man(7) code generated from DocBook,
for example mysql(1) and yasm_arch(7).
Thanks to brad@ for reporting the issue back in January 2011.
Simple partial sync with OpenBSD:
* Again accept suffixes on the name of the whatis utility.
* The usage line for whatis must not invite expressions.
* Revert the argument names in the SYNOPSIS back to the usual ones.
* Revert a few gratuitious changes regarding line breaks etc.
Restore the check whether each page added to the database
is actually reachable by man(1). This check got lost when
the database backend was changed from Berkeley to sqlite.
Ingo Schwarze [Thu, 27 Jun 2013 09:49:47 +0000 (09:49 +0000)]
Parse for the closing delimiter `\}' for conditionals
even when the conditional evaluated to false.
While here, reshuffle the code to reduce indentation and make it
more readable; that way, we can even trim down the comments because
it becomes obvious what the code does.
Found in zipinfo(1) - thanks to espie@ and naddy@
for making me look at that manual page.
Ingo Schwarze [Sat, 22 Jun 2013 08:54:13 +0000 (08:54 +0000)]
A very simple utility script to automatically compare groff and mandoc
output on collections of manual source files. I'm using this for quite
some time now, and it has proven to be rather useful.
Obviously, this will not be installed on user's systems.
Ingo Schwarze [Thu, 20 Jun 2013 22:39:30 +0000 (22:39 +0000)]
Improve handling of the roff(7) "\t" escape sequence:
* Parsing macro arguments has to be done in copy mode,
which implies replacing "\t" by a literal tab character.
* Otherwise, render "\t" as the empty string, not as a 't' character.
This fixes formatting of the distfile example in the oldrdist(1) manual.
This also shows up in the unzip(1) manual as one of several issues
preventing the removal of USE_GROFF from the archivers/unzip port.
Thanks to espie@ for attracting my attention to the unzip(1) manual.
Ingo Schwarze [Wed, 19 Jun 2013 21:20:27 +0000 (21:20 +0000)]
Add .St values for POSIX 1003.1d, 1003.1j, and 1003.1q.
Tweak descriptions of the other POSIX 1003.1<letter> standards.
Sort a few others into their proper places.
Ingo Schwarze [Fri, 7 Jun 2013 05:27:50 +0000 (05:27 +0000)]
The mdoc_handler flags are unused and will never be used.
Having a mask is sufficient to trigger putmdockey.
Simplify by dropping the flags; no functional change.
Ingo Schwarze [Fri, 7 Jun 2013 01:01:34 +0000 (01:01 +0000)]
The string hash table is only needed to combine multiple occurences
of the same string within the same manual, so initialize and purge
it for each manual in ofmerge() instead of one single time in main().
There is no point in saving manual names and descriptions in that
table because each of them occurs only once, or very few times.
The is no point in saving section numbers there because they are
so much shorter than the descriptions.
Testing with the complete tree /usr/share/man/ on my notebook shows
that this change slightly reduces memory consumption by about 20%
while there is no measurable difference in execution time.
As a bonus, this allows to delete the functions stradd() and stradds(),
the "next" member from struct str, and the global struct str *words.
While adapting the places in the code using stradd(), i noticed that
parsing of the mdoc(7) .Nd macro was completely broken and that for
formatted manual pages with unusable NAME section, the description
was never set in the struct of. This commit fixes both bugs as well.
Ingo Schwarze [Thu, 6 Jun 2013 19:00:28 +0000 (19:00 +0000)]
Optimize stradds() and putkeys() to not call ohash_qlookupi()
and ohash_find() twice. As a bonus, this allows to drop hashget().
While here, rename index to slot to match the terminology in the ohash
manual; it also prevents potential clashes with index(3).
Drop the slot variable altogether where it is used only once.
Ingo Schwarze [Thu, 6 Jun 2013 17:51:31 +0000 (17:51 +0000)]
Drop wordaddbuf() which is identical to putkeys().
Also rename straddbuf() to stradds() to be more similar to putkeys().
Just cleanup, no functional change.
Ingo Schwarze [Thu, 6 Jun 2013 15:15:07 +0000 (15:15 +0000)]
In dbopen(), check success of remove("mandoc.db~").
While here, simplify dbopen() and dbclose(): No need for strlcpy()
and strlcat() when dealing with constant strings only.
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@.