summaryrefslogtreecommitdiffstats
path: root/roff.c
Commit message (Collapse)AuthorAgeFilesLines
* With the current architecture, we can't support inline equationsIngo Schwarze2014-10-251-1/+2
| | | | | | | 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>.
* Report arguments to .EQ as an error, and simplify the code:Ingo Schwarze2014-10-251-20/+9
| | | | | | | * drop trivial wrapper function roff_openeqn() * drop unused first arg of function eqn_alloc() * drop usused member "name" of struct eqn_node While here, sync to OpenBSD by killing some trailing blanks.
* Protect the roff parser from dividing by zero. ok schwarze@Kristaps Dzonsons2014-10-201-13/+24
|
* correctly parse spacing around in-line equationsIngo Schwarze2014-10-201-5/+36
| | | | | at the beginning and at the end of input lines; issue reported by kristaps@
* correct spacing before inline equationsIngo Schwarze2014-10-201-11/+3
|
* oops, don't escape the first token of inline equationsIngo Schwarze2014-10-161-2/+2
|
* Implement in-line equations, much needed by Xenocara manuals.Ingo Schwarze2014-10-161-11/+58
| | | | | | | | 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.
* Parse and ignore the .pl (page length) request;Ingo Schwarze2014-09-071-0/+2
| | | | Daniel Levai reports that Slackware Linux uses this.
* Simplify by handling empty request lines at the one logical placeIngo Schwarze2014-09-061-0/+9
| | | | | in the roff parser instead of in three other places in other parsers. No functional change.
* Move main format autodetection from the parser dispatcher to theIngo Schwarze2014-09-061-2/+18
| | | | | | | | | | | 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.
* libroff depends on libmandoc and so libmandoc should be included first;Ingo Schwarze2014-08-191-1/+1
| | | | merge from OpenBSD, patch by daniel@
* Get rid of HAVE_CONFIG_H, it is always defined; idea from libnbcompat.Ingo Schwarze2014-08-101-2/+2
| | | | | | Include <sys/types.h> where needed, it does not belong in config.h. Remove <stdio.h> from config.h; if it is missing somewhere, it should be added, but i cannot find a *.c file where it is missing.
* mention requests and macros in more messagesIngo Schwarze2014-08-011-2/+3
|
* Dynamically allocate the stack of roff(7) .ie condition valuesIngo Schwarze2014-08-011-16/+17
| | | | and thus get rid of the last useless fatal error.
* better name and wording for the last two non-generic errorsIngo Schwarze2014-07-301-1/+1
|
* Clean up ERROR messages related to document structure and macros:Ingo Schwarze2014-07-071-15/+24
| | | | Hierarchical naming and mention macro names in messages.
* implement .dei and .amiIngo Schwarze2014-07-071-32/+54
|
* Clean up messages related to plain text and to escape sequences.Ingo Schwarze2014-07-061-12/+12
| | | | | * Mention invalid escape sequences and string names, and fallbacks. * Hierarchical naming.
* Fix expansion of escape sequences with incomplete arguments.Ingo Schwarze2014-07-061-7/+14
| | | | | | * 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).
* Clean up messages regarding excess arguments:Ingo Schwarze2014-07-041-2/+4
| | | | | | * Downgrade ".Bf -emphasis Em" from FATAL to WARNING. * Mention the macros, the arguments, and the fallbacks. * Hierarchical naming.
* MANDOCERR_NOARGS reported three completely unrelated classes of problems.Ingo Schwarze2014-07-031-2/+4
| | | | Split the roff(7) parts out of it and report the request names for these cases.
* The previous commit to this file broke the control flow keywords \{ and \}Ingo Schwarze2014-07-011-1/+3
| | | | | | | | 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.
* Use the freshly improved roff_getname() functionIngo Schwarze2014-06-291-16/+15
| | | | | | | | 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!).
* Use the freshly improved roff_getname() functionIngo Schwarze2014-06-291-38/+18
| | | | | | for the .de parsing routine, roff_block(), to correctly handle names terminated by escape sequences. Besides, this saves us 20 lines of code.
* Major roff_getname() cleanup.Ingo Schwarze2014-06-291-35/+51
| | | | | | | | | * 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.
* Bugfix in roff_setstrn():Ingo Schwarze2014-06-291-1/+2
| | | | Do not call strcmp() on an array of char that might not be NUL-terminated.
* Improve messages related to the roff(7) .so request.Ingo Schwarze2014-06-251-3/+4
| | | | | | | | | | | | | 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.
* Audit strlcpy(3)/strlcat(3) usage.Ingo Schwarze2014-04-231-19/+9
| | | | | | | | | | | | | * 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.
* make sure static buffers for snprintf(3) are large enoughIngo Schwarze2014-04-201-3/+3
| | | | and cast snprintf return value to (void) where they are
* KNF: case (FOO): -> case FOO:, remove /* LINTED */ and /* ARGSUSED */,Ingo Schwarze2014-04-201-162/+120
| | | | | remove trailing whitespace and blanks before tabs, improve some indenting; no functional change
* Fully implement the \B (validate numerical expression) andIngo Schwarze2014-04-081-27/+70
| | | | | | | | | | | 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.
* We already supported (outer) user-defined strings containing referencesIngo Schwarze2014-04-071-36/+44
| | | | | | | | 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).
* Almost complete implementation of roff(7) numerical expressions.Ingo Schwarze2014-04-071-57/+207
| | | | | | | 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().
* Implement the roff(7) .rr (remove register) request.Ingo Schwarze2014-04-051-0/+28
| | | | | As reported by sthen@, the perl-5.18 pod2man(1) preamble thinks cool kids use that in manuals. I hope *you* know better.
* avoid repetitive code for asprintf error handlingIngo Schwarze2014-03-231-5/+1
|
* The files mandoc.c and mandoc.h contained both specialised low-levelIngo Schwarze2014-03-231-0/+1
| | | | | | | 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.
* Remove currently unimplemented macros from the lists of used-definedIngo Schwarze2014-03-201-14/+16
| | | | | | | 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.
* Generalize the mparse_alloc() and roff_alloc() functions by givingIngo Schwarze2014-03-191-7/+5
| | | | | | | | 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().
* Improve .if/.ie condition handling.Ingo Schwarze2014-03-081-55/+86
| | | | | | | | | | | | | | * 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.
* In roff_cond_sub(), make sure that the incorrect input sequence `\\}',Ingo Schwarze2014-03-071-11/+12
| | | | | | | 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.
* Even on macro lines, \} must not cause whitespace.Ingo Schwarze2014-03-071-14/+10
|
* Three bugfixes related to the closing of conditional blocks:Ingo Schwarze2014-03-071-25/+12
| | | | | | | | | | 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.
* Parse and ignore the roff(7) .ce request (center some lines).Ingo Schwarze2014-02-141-0/+2
| | | | | | | | 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).
* Implement the roff(7) .as request (append to user-defined string).Ingo Schwarze2014-02-141-13/+15
| | | | | | | | | 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.
* Handle some predefined read-only number registers, e.g. .H and .V.Ingo Schwarze2014-02-141-0/+43
| | | | | | | | 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.
* Gprof(1) is fun. You should use it more often.Ingo Schwarze2014-01-061-9/+6
| | | | | | | | | | 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.
* Another 25% speedup for mandocdb(8) -Q mode, found with gprof(1).Ingo Schwarze2014-01-061-4/+6
| | | | | | | | | | | | | | | | | | | | | | | 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.
* Oops, missed one:Ingo Schwarze2013-12-301-2/+1
| | | | | | Remove duplicate const specifier from a call to mandoc_escape(). Found by Thomas Klausner <wiz at NetBSD dot org> using clang. No functional change.
* s/[Nn]ull/NUL/ in comments where appropriate;Ingo Schwarze2013-12-251-1/+1
| | | | suggested by Thomas Klausner <wiz @ NetBSD dot org>.
* The "value" argument to the roff(7) .nr requests ends right beforeIngo Schwarze2013-12-151-4/+17
| | | | | | | | the first non-digit character. While here, implement and document an optional sign, requesting increment or decrement, as documented in the Ossanna/Kernighan/Ritter troff manual and supported by groff. Reported by bentley@ on discuss@.