summaryrefslogtreecommitdiffstats
path: root/mdoc_argv.c
Commit message (Collapse)AuthorAgeFilesLines
* When parsing a tab character that is not preceded by a space characterIngo Schwarze2019-07-111-1/+2
| | | | | | | | | | | | | | | | on an .It -column line, args() sets the MDOC_PHRASEQL flag to Quote the Last word of the Phrase. Even if it turns out this quoting is not needed because the word is already quoted for other reasons, clear the flag at the end of parsing the phrase, such that the flag does not leak to the next phrase. This patch fixes the bug that the trailing Macro on a line of the form .It "word<tab>word" Ta word Macro<eol> was incorrectly considered quoted and hence not parsed. Bug found by Havard Eidnes (he@) with the NetBSD gettytab(5) manual page: https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=54361 Reported via Thomas Klausner (wiz@).
* Rename mandoc_getarg() to roff_getarg() and pass it the roff parserIngo Schwarze2018-12-211-12/+18
| | | | | | | | | | | | | | | | | | struct as an argument such that after copy-in, it can call roff_expand() once again, which used to be called roff_res() before this. This fixes a subtle low-level roff(7) parsing bug reported by Fabio Scotoni <fabio at esse dot ch> in the 4.4BSD-Lite2 mdoc.samples(7) manual page, because that page used an escaped escape sequence in a macro argument. To expand escaped escape sequences in quoted mdoc(7) arguments, too, stop bypassing the call to roff_getarg() in mdoc_argv.c, function args() for this case. This does not solve the case of escaped escape sequences in quoted .Bl -column phrases yet. Because roff_expand() can make the string longer, roff_getarg() can no longer operate in-place but needs to malloc(3) the returned string. In the high-level parsers, free(3) that string after processing it.
* Cleanup, no functional change:Ingo Schwarze2018-12-141-1/+1
| | | | | | | | | | Now that message handling is properly encapsulated, remove struct mparse pointers from four structs (roff, roff_man, tbl_node, eqn_node) and from the argument lists of five functions (roff_alloc, roff_man_alloc, mandoc_getarg, tbl_alloc, eqn_alloc). Except for being passed to the main program as an opaque object, it now only occurs in read.c, as it should, and not across 15 files like in the past.
* Almost mechanical diff to remove the "struct mparse *" argumentIngo Schwarze2018-12-141-6/+4
| | | | | | | | from mandoc_msg(), where it is no longer used. While here, rename mandoc_vmsg() to mandoc_msg() and retire the old version: There is really no point in having another function merely to save "%s" in a few places. Minus 140 lines of code.
* Remove more pointer arithmetic passing via regions outside the arrayIngo Schwarze2018-08-171-6/+5
| | | | | that is undefined according to the C standard. Robert Elz <kre at munnari dot oz dot au> pointed out i wasn't quite done yet.
* Macro argument quoting does not prevent recognition of punctuationIngo Schwarze2017-05-301-3/+3
| | | | | | | | | | | and of called macros. This bug affects almost all macros, and fixing it simplifies the code. It is amazing that the bogus ARGS_QWORD feature got implemented in the first place, and then carrier along for more than eight years without anybody ever noticing that it was pointless. Reported by Leah Neukirchen <leah at vuxu dot org>, found on Void Linux.
* Move .sp to the roff modules. Enough infrastructure is in placeIngo Schwarze2017-05-051-1/+0
| | | | now that this actually saves code: -70 LOC.
* move .ll to the roff modulesIngo Schwarze2017-05-051-1/+0
|
* Parser reorg:Ingo Schwarze2017-05-041-1/+0
| | | | | Generate the first node on the roff level: .br Fix some column numbers in diagnostic messages while here.
* Continue parser unification:Ingo Schwarze2017-04-241-4/+6
| | | | | | | | * Make enum rofft an internal interface as enum roff_tok in "roff.h". * Represent mdoc and man macros in enum roff_tok. * Make TOKEN_NONE a proper enum value and use it throughout. * Put the prologue macros first in the macro tables. * Unify mdoc_macroname[] and man_macroname[] into roff_name[].
* Markdown output mode helped us to find the first parser bug (as such,Ingo Schwarze2017-03-031-8/+9
| | | | | | | | | | this bug could cause wrong output in other modes as well): Do not misinterpret tab characters as .Ta macros when they appear on non-column .It lines in non-column .Bl lists that are nested inside a parent .Bl -column list. (Admittedly, such constructions are not very useful; don't use them!) Found by tb@ with afl(1) because the resulting tree corruption triggered an assertion in the markdown output module.
* If a line inside .Bl -column starts with a tab characterIngo Schwarze2016-08-281-1/+1
| | | | | | and there was no preceding .It macro, do not read the byte before the beginning of the line buffer. Found by tb@ with afl@.
* add missing prototypes, no code change;Ingo Schwarze2016-07-151-0/+1
| | | | noticed by Christos Zoulas with -Wmissing-prototypes
* Very tricky diff to fix macro interpretation and spacing around tabsIngo Schwarze2015-10-171-15/+45
| | | | | | | | | | | | | | in .Bl -column; it took me more than a day to get this right. Triggered by a loosely related bug report from tim@. The lesson for you is: Use .Ta macros in .Bl -column, avoid tabs, or you are in for surprises: The last word before a tab is not interpreted as a macro (unless there is a blank in between), the first word after a tab isn't either (unless there is a blank in between), and a blank after a tab causes a leading blank in the respective output cell. Yes, "blank", "tab", "blank tab" and "tab blank" all have different semantics; if you write code relying on that, good luck maintaining it afterwards...
* Simplify the part of args() that is handling .Bl -column phrases:Ingo Schwarze2015-10-151-72/+27
| | | | | | | | | | Delete manual "Ta" handling because macro handling should not be done in an argument parser but should be left to the macro parsers, which exist anyway and work well. No functional change, minus 40 lines of code. Confusing and redundant code found while investigating an old bug report from tim@.
* modernize style: "return" is not a functionIngo Schwarze2015-10-061-16/+16
|
* Decouple the token code for "no request or macro" from the individualIngo Schwarze2015-04-191-1/+1
| | | | | | high-level parsers to allow further unification of functions that only need to recognize this code, but that don't care about different high-level macrosets beyond that.
* Replace the structs mdoc and man by a unified struct roff_man.Ingo Schwarze2015-04-181-9/+9
| | | | | Almost completely mechanical, no functional change. Written on the train from Exeter to London returning from p2k15.
* Second step towards parser unification:Ingo Schwarze2015-04-021-3/+3
| | | | | | | | | Replace struct mdoc_node and struct man_node by a unified struct roff_node. To be able to use the tok member for both mdoc(7) and man(7) without defining all the macros in roff.h, sacrifice a tiny bit of type safety and make tok an int rather than an enum. Almost mechanical, no functional change. Written on the Eurostar from Bruxelles to London on the way to p2k15.
* First step towards parser unification:Ingo Schwarze2015-04-021-5/+6
| | | | | | Replace enum mdoc_type and enum man_type by a unified enum roff_type. Almost mechanical, no functional change. Written on the ICE train from Frankfurt to Bruxelles on the way to p2k15.
* fix column numbers of macro arguments in messagesIngo Schwarze2015-02-041-2/+2
|
* Provide a helper function macro_or_word() and use it to prune theIngo Schwarze2014-11-291-11/+6
| | | | | | | | | | same chunk of argument parsing code out of five of the eight callback functions. The other three have too much special handling to participate. As a bonus, let lookup() and mdoc_args() deal with line macros and retire the lookup_raw() helper and the mdoc_zargs() internal interface function. No functional change, minus 40 lines of code.
* Fold the loop around mdoc_argv() into the function itself,Ingo Schwarze2014-11-281-70/+77
| | | | | | it was the same in all four cases. As a bonus, get rid of one enum type that was used for internal communication. No functional change, minus 40 lines of code.
* Simplify the code by making various mdoc parser helper functions void.Ingo Schwarze2014-11-281-22/+12
| | | | No functional change, minus 130 lines of code.
* Get rid of HAVE_CONFIG_H, it is always defined; idea from libnbcompat.Ingo Schwarze2014-08-101-2/+0
| | | | | | 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.
* Clean up messages related to plain text and to escape sequences.Ingo Schwarze2014-07-061-4/+8
| | | | | * Mention invalid escape sequences and string names, and fallbacks. * Hierarchical naming.
* Implement the obsolete macros .En .Es .Fr .Ot for backward compatibility,Ingo Schwarze2014-07-021-3/+3
| | | | | since this is hardly more complicated than explicitly ignoring them as we did in the past. Of course, do not use them!
* Audit malloc(3)/calloc(3)/realloc(3) usage.Ingo Schwarze2014-04-231-4/+4
| | | | | | | * Change eight reallocs to reallocarray to be safe from overflows. * Change one malloc to reallocarray to be safe from overflows. * Change one calloc to reallocarray, no zeroing needed. * Change the order of arguments of three callocs (aesthetical).
* KNF: case (FOO): -> case FOO:, remove /* LINTED */ and /* ARGSUSED */,Ingo Schwarze2014-04-201-45/+45
| | | | | remove trailing whitespace and blanks before tabs, improve some indenting; no functional change
* Implement the roff(7) .ll (line length) request.Ingo Schwarze2014-03-301-0/+1
| | | | | Found by naddy@ in the textproc/enchant(1) port. Of course, do not use this in new manuals.
* 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.
* s/[Nn]ull/NUL/ in comments where appropriate;Ingo Schwarze2013-12-251-3/+3
| | | | suggested by Thomas Klausner <wiz @ NetBSD dot org>.
* Fix end-of-sentence spacing after the DragonFly text production macro.Ingo Schwarze2013-12-221-1/+1
| | | | Patch from Franco Fichtner <franco at lastsummer dot de>.
* In quoted macro arguments, double quotes can be quoted by doubling them.Ingo Schwarze2013-12-151-0/+12
| | | | | | | | | For a long time, we handle this in roff(7) and man(7) macros. Now add correct handling for the mdoc(7) case, too. Closely based on a patch by Tsugutomo dot ENAMI at jp dot sony dot com, see http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=48438 received via Thomas Klausner (wiz@), slightly tweaked by me.
* Fix four small whitespace issues related to trailing punctuationIngo Schwarze2012-11-181-3/+3
| | | | | | | | | reported by Nicolas Joly <njoly at pasteur dot fr>: - add EOS spacing after trailing punctuation after .Cd, .Fc, and .Lb - suppress spacing before trailing punctuation after .Fd Add the remaining issues from the same report to the TODO file.
* Cleanup naming of local variables to make the code easier on the eye:Ingo Schwarze2012-11-171-29/+29
| | | | | | | | 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. ok kristaps@ some time ago
* Two more macros (.Ap and .In) do trailing delimiter handling.Ingo Schwarze2012-11-161-2/+3
| | | | | | | 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!
* The -width and -offset macro arguments consume the next argumentIngo Schwarze2012-04-151-38/+4
| | | | | even if it starts with a dash. ok kristaps@
* Make the `-width' field to `Bl' not puke if it doesn't have an argument.Kristaps Dzonsons2012-03-231-1/+1
| | | | This makes mandoc work much, much nicer with Mac OSX manpages.
* forgotten Copyright bumps; no code changeIngo Schwarze2011-09-181-1/+1
| | | | found while syncing to OpenBSD
* Add back in a check that the leading `-' exists for arguments. ThisKristaps Dzonsons2011-06-181-6/+5
| | | | | mysteriously disappeared in 1.14. No idea why. While here, remove an unnecessary header and order the function prototypes.
* Clean-up: remove a function only called once.Kristaps Dzonsons2011-06-181-37/+16
|
* Fix an assertion failure raised by the following interesting scenario: aKristaps Dzonsons2011-06-181-191/+163
| | | | | | | | | | | | | | auto-opened `It' (i.e., a column list with a free-text first line) with leading spaces in the line triggering assertion when searching for arguments. This led to a fix giving a nice performance speed-ups (a few percent, with some quick trials): the search for flags immediately exits if the macro has no flags, instead of having to first parse the leading word then look it up. I also cleaned up the argv parsing stuff a little bit and added more documentation. This comes from a TODO by joerg@.
* Lint fixes: remove unused function variables and pass in proper enumKristaps Dzonsons2011-05-121-7/+6
| | | | values instead of ints.
* Clean up parsing of delimiters in -mdoc. First, remove the "dowarn"Kristaps Dzonsons2011-04-191-170/+156
| | | | | | | | variable from mandoc_getarg() so that it prints the warning every time. Then, remove the warning from args_checkpunct(). This way, warnings are being posted at the correct time. This makes the flag argument to mdoc_zargs() superfluous, so make it be zero when it's invoked. Finally, move the args() flags into mdoc_argv.c and make them enums.
* Use mandoc_getarg() for the regular case of processing unquotedKristaps Dzonsons2011-04-171-19/+3
| | | | arguments in -mdoc documents.
* Don't shadow global identifiers.Joerg Sonnenberger2011-04-071-12/+12
|
* As per joerg@'s suggestion, use const arrays when looking up mdoc argvs.Kristaps Dzonsons2011-03-231-37/+68
|
* libmdoc.h and libman.h were including mdoc.h and man.h, respectively.Kristaps Dzonsons2011-03-221-0/+1
| | | | | Don't have them do that (includes in header files = faugh), and have individual files directly include these files.
* mdoc_argn_free is only used local to mdoc_argv.c, so make it static.Kristaps Dzonsons2011-03-221-3/+4
|