summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/roff.c
AgeCommit message (Collapse)Author
2014-11-19Support the ".if v" conditional operator (vroff mode, always false)Ingo Schwarze
for groff compatibility because pod2man(1) uses it that way. Weirdly, groff documents it as "for compatibility with other troff versions" but neither Heirloom nor Plan 9 have it. Issue reported by giovanni@ via sthen@.
2014-11-01Use struct buf in libroff, it is very natural thereIngo Schwarze
and reduces the number of arguments of many functions. While here, sprinkle some KNF. No functional change.
2014-10-28Make the character table available to libroff so it can check theIngo Schwarze
validity of character escape names and warn about unknown ones. This requires mchars_spec2cp() to report unknown names again. Fortunately, that doesn't require changing the calling code because according to groff, invalid character escapes should not produce output anyway, and now that we warn about them, that's fine.
2014-10-25With the current architecture, we can't support inline equationsIngo Schwarze
inside tables, sorry. So don't even try to parse tbl(7) blocks for eqn(7) delimiters. Broken table layout found in glPixelMap(3) while investigating a bug report by Theo Buehler <theo at math dot ethz dot ch>.
2014-10-25Report arguments to .EQ as an error, and simplify the code:Ingo Schwarze
* drop trivial wrapper function roff_openeqn() * drop unused first arg of function eqn_alloc() * drop usused member "name" of struct eqn_node
2014-10-20protect the roff parser from dividing by zero;Ingo Schwarze
issue found and patch written by kristaps@
2014-10-20correctly parse spacing around in-line equationsIngo Schwarze
at the beginning and at the end of input lines; issue reported by kristaps@
2014-10-20correct spacing before inline equationsIngo Schwarze
2014-10-16oops, don't escape the first token of inline equationsIngo Schwarze
2014-10-16Implement in-line equations, much needed by Xenocara manuals.Ingo Schwarze
Put the steering into the roff parser rather than into the mdoc parser such that it works for all macro languages and on both text and macro lines. Line breaks and blank characters generated before and after in-line equations are not perfect yet, but let's do one thing at a time.
2014-09-07Parse and ignore the .pl (page length) request;Ingo Schwarze
Daniel Levai reports that Slackware Linux uses this.
2014-09-06Simplify by handling empty request lines at the one logical placeIngo Schwarze
in the roff parser instead of in three other places in other parsers. No functional change.
2014-09-06Move main format autodetection from the parser dispatcher to theIngo Schwarze
roff parser where .Dd and .TH are already detected, anyway. This improves robustness because it correctly handles whitespace or an alternate control character before Dd. In the parser dispatcher, provide a fallback looking ahead in the input buffer instead of always assuming man(7). This corrects autodetection when Dd is preceded by other macros or macro-like handled requests like .ll. Triggered by reports from Daniel Levai about issues on Slackware Linux.
2014-08-19libroff depends on libmandoc and so libmandoc should be included first.Daniel Dickman
this change makes the code slightly more portable by removing a gcc extension (incomplete enum types) which is not part of ISO C. ok schwarze@
2014-08-08mention requests and macros in more messagesIngo Schwarze
2014-08-08Dynamically allocate the stack of roff(7) .ie condition valuesIngo Schwarze
and thus get rid of the last useless fatal error.
2014-08-08better name and wording for the last two non-generic errorsIngo Schwarze
2014-07-07Clean up ERROR messages related to document structure and macros:Ingo Schwarze
Hierarchical naming and mention macro names in messages.
2014-07-07implement .dei and .amiIngo Schwarze
2014-07-06Clean up messages related to plain text and to escape sequences.Ingo Schwarze
* Mention invalid escape sequences and string names, and fallbacks. * Hierarchical naming.
2014-07-06Fix expansion of escape sequences with incomplete arguments.Ingo Schwarze
* For \* and \n, discard the incomplete arg, expand to empty string. * For \B, discard the incomplete arg, expand to the digit 0. * For \w, use the incomplete arg (behaviour unchanged).
2014-07-04Clean up messages regarding excess arguments:Ingo Schwarze
* Downgrade ".Bf -emphasis Em" from FATAL to WARNING. * Mention the macros, the arguments, and the fallbacks. * Hierarchical naming. Also fix the handling of excess .It head arguments in -Tman.
2014-07-03MANDOCERR_NOARGS reported three completely unrelated classes of problems.Ingo Schwarze
Split the roff(7) parts out of it and report the request names for these cases.
2014-07-01The previous commit to this file broke the control flow keywords \{ and \}Ingo Schwarze
when they immediately follow a request or macro name, without intervening whitespace. Minimal fix. The lesson learnt here is that, despite their appearance, \{ and \} are not escape sequences, so never skip them when parsing for names.
2014-06-29Use the freshly improved roff_getname() functionIngo Schwarze
for the main roff request parsing routine, roff_parse(). In request or macro invocations, escape sequences now terminate the request or macro name; what follows is treated as arguments. Besides, the names of user-defined macros can now contain backslashes (eek!).
2014-06-29Use the freshly improved roff_getname() functionIngo Schwarze
for the .de parsing routine, roff_block(), to correctly handle names terminated by escape sequences. Besides, this saves us 20 lines of code.
2014-06-29Major roff_getname() cleanup.Ingo Schwarze
* Return the name even if it is terminated by an escape sequence, not a blank. * Skip the full escape sequence using mandoc_escape(), not just the first byte. * Make it non-destructive, return the length instead of writing a '\0'. * Let .ds and .as cope with the above changes to the internal interface. * Fix .rm and .rr to accept an escape sequence as the end of a name. * Fix .nr and .rr to not set/delete a register with an empty name.
2014-06-29Bugfix in roff_setstrn():Ingo Schwarze
Do not call strcmp() on an array of char that might not be NUL-terminated.
2014-06-25Improve messages related to the roff(7) .so request.Ingo Schwarze
In all these messages, show the filename argument that was passed to the .so request. In case of failure, show an additional message reporting the file and the line number where the failing request was found. The existing message reporting the reason for the failure - for example, "Permission denied" - is left in place, unchanged. Inspired by a question asked by Nick@ after he saw the confusing old messages that used to be emitted in this area.
2014-04-23Audit strlcpy(3)/strlcat(3) usage.Ingo Schwarze
* Repair three instances of silent truncation, use asprintf(3). * Change two instances of strlen(3)+malloc(3)+strlcpy(3)+strlcat(3)+... to use asprintf(3) instead to make them less error prone. * Cast the return value of four instances where the destination buffer is known to be large enough to (void). * Completely remove three useless instances of strlcpy(3)/strlcat(3). * Mark two places in -Thtml with XXX that can cause information loss and crashes but are not easy to fix, requiring design changes of some internal interfaces. * The file mandocdb.c remains to be audited.
2014-04-20make sure static buffers for snprintf(3) are large enoughIngo Schwarze
and cast snprintf return value to (void) where they are
2014-04-20KNF: case (FOO): -> case FOO, remove /* LINTED */ and /* ARGSUSED */,Ingo Schwarze
remove trailing whitespace and blanks before tabs, improve some indenting; no functional change
2014-04-08Fully implement the \B (validate numerical expression) andIngo Schwarze
partially implement the \w (measure text width) escape sequence in a way that makes them usable in numerical expressions and in conditional requests, similar to how \n (interpolate number register) and \* (expand user-defined string) are implemented. This lets mandoc(1) handle the baroque low-level roff code found at the beginning of the ggrep(1) manual. Thanks to pascal@ for the report.
2014-04-07We already supported (outer) user-defined strings containing referencesIngo Schwarze
to other (inner) user-defined strings in their values, such that the inner ones get expanded at expansion time of the outer ones (delayed evaluation). Now we also support specifying the name of an (outer) user-defined string to expand using the expanded values of some other (inner) user-defined strings (indirect reference).
2014-04-07Almost complete implementation of roff(7) numerical expressions.Ingo Schwarze
Support all binary operators except ';' (scale conversion). Fully support chained operations and nested parentheses. Use this for the .nr, .if, and .ie requests. While here, fix parsing of integer numbers in roff_getnum().
2014-04-05Implement the roff(7) .rr (remove register) request.Ingo Schwarze
As reported by sthen@, the perl-5.18 pod2man(1) preamble thinks cool kids use that in manuals. I hope *you* know better.
2014-03-21avoid repetitive code for asprintf error handlingIngo Schwarze
2014-03-21The files mandoc.c and mandoc.h contained both specialised low-levelIngo Schwarze
functions used for multiple languages (mdoc, man, roff), for example mandoc_escape(), mandoc_getarg(), mandoc_eos(), and generic auxiliary functions. Split the auxiliaries out into their own file and header. While here, do some #include cleanup.
2014-03-20Remove currently unimplemented macros from the lists of used-definedIngo Schwarze
macros to be cleared during .Dd and .TH because clearing them at that point defeats the purpose of backup implementations provided in the manual page itself, some of which _do_ work with mandoc(1). While here, add the new .%C macro to the list to be cleared.
2014-03-19Generalize the mparse_alloc() and roff_alloc() functions by givingIngo Schwarze
them an "options" argument, replacing the existing "inttype" and "quick" arguments, preparing for a future MPARSE_SO option. Store this argument in struct mparse and struct roff, replacing the existing "inttype", "parsetype", and "quick" members. No functional change except one tiny cosmetic fix in roff_TH().
2014-03-08Improve .if/.ie condition handling.Ingo Schwarze
* Support string comparisons. * Support negation not only for numerical, but for all conditions. * Switch the `o' condition from false to true. * Handle the `c', `d', and `r' conditions as false for now. * Use int for boolean data instead of rolling our own "enum roffrule"; needed such that we can use the standard ! and == operators. Havard Eidnes reported via the NetBSD bug tracking system that some Tcl*(3) manuals need this, and Thomas Klausner <wiz at NetBSD> forwarded the report to me. This doesn't make the crazy Tcl*(3) macrology maze happy yet, but brings us a bit closer.
2014-03-07In roff_cond_sub(), make sure that the incorrect input sequence `\\}',Ingo Schwarze
when found on a macro line, does not close a conditional block. The companion function roff_cond_text() already did this correctly, but make the code more readable without functional change. While here, report the correct column number in related error messages.
2014-03-07Even on macro lines, \} must not cause whitespace.Ingo Schwarze
2014-03-07Three bugfixes related to the closing of conditional blocks:Ingo Schwarze
1. Handle more than one `\}' on macro lines, as it was already done for text lines. 2. Do not treat `\}' as a macro invocation after a dot at the beginning of a line. That allows more than one `\}' to work on lines starting with `.\}'. It also simplifies the code. 3. Do not complain about characters following `\}'. Those are not lost, but handled normally both on text and macro lines.
2014-02-14Parse and ignore the roff(7) .ce request (center some lines).Ingo Schwarze
We even parse and ignore the .ad request (adjustment mode), and it doesn't make sense to more prominently warn about temporary than about permanent adjustment changes. Request found by naddy@ in xloadimage(1) and by juanfra@ in racket(1).
2014-02-14Implement the roff(7) .as request (append to user-defined string).Ingo Schwarze
Missing feature found by jca@ in ratpoison(1). The ratpoison(1) manual still doesn't work because it uses .shift and .while, too (apparently, ratpoison is so complex that it needs a Turing-complete language to even format its manual :-). Written at Christchurch International Airport.
2014-02-14Handle some predefined read-only number registers, e.g. .H and .V.Ingo Schwarze
In particular, this improves handling of the pod2man(1) preamble; for examples of the effect, see some author names in perlthrtut(1). Missing feature reported by Andreas Voegele <mail at andreasvoegele dot com> more than two years ago. Written at Christchurch International Airport.
2014-01-06Gprof(1) is fun. You should use it more often.Ingo Schwarze
Another 10% speedup for mandocdb(8) -Q, and even 3% without -Q. With -Q, we are now at 41% of the time required by makewhatis(8). Do not copy predefined strings into the dynamic string table, just leave them in their own static table and use that one as a fallback at lookup time. This saves us copying and deleting them for each manual. No functional change.
2014-01-06Another 25% speedup for mandocdb(8) -Q mode, found with gprof(1).Ingo Schwarze
For /usr/share/man, we only need 56% of the time of makewhatis(8) now. In groff, user-defined macros clashing with mdoc(7) or man(7) standard macros are cleared when parsing the .Dd or .TH macro, respectively. Of course, we continue doing that in standard mode to assure full groff bug compatibility. However, in -Q mode, full groff bug compatibility makes no sense when it's unreasonably expensive, so skip this step in -Q mode. Real-world manuals hardly ever redefine standard macros, that's terrible style, and if they do, it's pointless to do so before .Dd or .TH because it has no effect. Even if someone does, it's extremely unlikely to break mandocdb(8) -Q parsing because we abort the parse sequence after the NAME section, anyway. So if you manually redefine .Sh, .Nm, .Nd, or .SH in a way that doesn't work at all and rely on .Dd or .TH to fix it up for you, your broken manual will no longer get a perfect apropos(1) entry until you re-run mandocdb(8) without -Q. It think that consequence is acceptable in order to get a 25% speedup for everyone else.
2013-12-30Oops, missed one:Ingo Schwarze
Remove duplicate const specifier from a call to mandoc_escape(). Found by Thomas Klausner <wiz at NetBSD dot org> using clang. No functional change.