summaryrefslogtreecommitdiffstats
path: root/mdoc_validate.c
Commit message (Collapse)AuthorAgeFilesLines
* As suggested by jmc@, only include line and column numbers into messagesIngo Schwarze2014-06-201-13/+9
| | | | | | | | | | | | | | when they are meaningful, to avoid confusing stuff like this: $ mandoc /dev/null mandoc: /dev/null:0:1: FATAL: not a manual Instead, just say: mandoc: /dev/null: FATAL: not a manual Another example this applies to is documents having a prologue, but lacking a body. Do not throw a FATAL error for these; instead, issue a WARNING and show the empty document, in the man(7) case with the same amount of blank lines as groff does. Also downgrade mdoc(7) documents having content before the first .Sh from FATAL to WARNING.
* Start systematic improvements of error reporting.Ingo Schwarze2014-06-201-9/+9
| | | | | | | | | | | So far, this covers all WARNINGs related to the prologue. 1) hierarchical naming of MANDOCERR_* constants 2) mention the macro name in messages where that adds clarity 3) add one missing MANDOCERR_DATE_MISSING msg 4) fix the wording of one message related to the man(7) prologue Started on the plane back from Ottawa.
* 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).
* Audit strlcpy(3)/strlcat(3) usage.Ingo Schwarze2014-04-231-20/+11
| | | | | | | | | | | | | * 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.
* strlen+malloc+snprintf is error prone;Ingo Schwarze2014-04-201-22/+13
| | | | rewrite post_lb() to use asprintf(3) instead
* make sure static buffers for snprintf(3) are large enoughIngo Schwarze2014-04-201-6/+4
| | | | and cast snprintf return value to (void) where they are
* KNF: case (FOO): -> case FOO:, remove /* LINTED */ and /* ARGSUSED */,Ingo Schwarze2014-04-201-253/+239
| | | | | remove trailing whitespace and blanks before tabs, improve some indenting; no functional change
* Using macros in .Sh header lines, or having .Sm off or .Bk -words openIngo Schwarze2014-04-151-11/+7
| | | | | | | | | while processing .Sh, is not at all recommended, but it's not strictly a syntax violation either, and in any case, mandoc must not die in an assertion. I broke this in rev. 1.124. Crash found while trying to read the (rather broken) original 4.3BSD-Reno od(1) manual page.
* Support the CONTEXT section for kernel manual pages found in Solaris andIngo Schwarze2014-03-311-0/+3
| | | | | OpenBSD manuals. It describes which contexts you can call functions in. from dlg@, ok jmc@ deraadt@
* Allow ERRORS in section 4; OpenBSD rev. 1.121.Ingo Schwarze2014-03-301-2/+4
|
* 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.
* Retire the old concat() function.Ingo Schwarze2014-03-231-77/+26
| | | | | | | | For .Sh, i wasn't even needed at all. For .Dd, .Nm, and .Os, use the new mdoc_deroff() instead. This gets rid of the last limited-size static buffers in this file, hence eliminates the last explicit MANDOCERR_MEM throwers here, and it shortens the code by 50 lines.
* avoid repetitive code for asprintf error handlingIngo Schwarze2014-03-231-5/+3
|
* 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 useless use of strnlen(3).Ingo Schwarze2014-01-111-1/+1
| | | | Yuckiness pointed out by deraadt@.
* Cache the result of uname(3) such that we don't need to call itIngo Schwarze2014-01-071-29/+22
| | | | | over and over again for each manual; found with gprof(1). Speeds up mandocdb(8) -Q by 3%, now at 39.5% of makewhatis(8).
* Another 18% speedup for mandocdb(8) -Q, found by gprof(1).Ingo Schwarze2014-01-061-5/+5
| | | | | | | In -Q mode, refrain form validating and normalizing the format of the date given in .Dd or .TH, as it won't be used anyway. For /usr/share/man, mandocdb -Q now takes 45% of the time of makewhatis(8).
* Joerg Sonnenberger contributed copyrightable amounts of text toIngo Schwarze2014-01-061-0/+1
| | | | | | some files. To make it clear that he also put his contributions under the ISC license, with his explicit permission, add his Copyright notice to the relevant files. No code change.
* The "value" argument to the roff(7) .nr requests ends right beforeIngo Schwarze2013-12-151-2/+2
| | | | | | | | 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@.
* There are three kinds of input lines: text lines, macros takingIngo Schwarze2013-10-211-2/+8
| | | | | | | | | | | | | | | positional arguments (like Dt Fn Xr) and macros taking text as arguments (like Nd Sh Em %T An). In the past, even the latter put each word of their arguments into its own MDOC_TEXT node; instead, concatenate arguments unless delimiters, keeps or spacing mode prevent that. Regarding mandoc(1), this is internal refactoring, no output change intended. Regarding mandocdb(8), this fixes yet another regression introduced when switching from DB to SQLite: The ability to search for strings crossing word boundaries was lost and is hereby restored. At the same time, database sizes and build times are both reduced by a bit more than 5% each.
* We don't do hyphenation, but we allow breaking the line at hyphens that areIngo Schwarze2013-10-061-19/+61
| | | | | | | | | | | | already there in the middle of words. So far, we only allowed this on text lines. Now it turns out some macros allow this for their arguments, too, in particular .Nd and most of the .%? citation macros. Issue found by Franco Fichtner <franco at lastsummer dot de> while doing systematic groff-mandoc comparisons in the DragonFly base system, THANKS! While here, garbage collect two empty prevalidator function pointer lists and sort a couple of function declarations.
* If there is random stuff inside a .Bl block body before the first .It,Ingo Schwarze2013-10-061-19/+58
| | | | | | | | | | | do not throw a FATAL error and do not die, but just throw a WARNING and move the stuff out of the .Bl block. This bug felt completely 2008-ish; meanwhile, such bugs from the Kristaps-doesnt-like-syntax-errors-so-lets-just-give-up--Era are becoming rare, but this was one of the last survivors. Thanks to bentley@ for reminding me to finally fix this.
* Support setting arbitrary roff(7) number registers,Ingo Schwarze2013-10-051-5/+6
| | | | | | | | | | | | | | 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.
* One of the WARNING messages has to use the word "section" twice in twoIngo Schwarze2013-09-161-1/+2
| | | | | | | | | | 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.
* Put .%C before .%D in .Rs outputIngo Schwarze2013-08-051-2/+2
| | | | | | | because that's the usual order in formal citations. My patch that was accepted into groff by Werner Lemberg uses the same order, so keep groff and mandoc consistent.
* Cleanup naming of local variables to make the code easier on the eye:Ingo Schwarze2012-11-171-16/+16
| | | | | | | | 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
* Warn about unknown volume or arch in Dt macro arguments;Ingo Schwarze2012-11-161-1/+1
| | | | patch written by Nicolas Joly <njoly at pasteur dot fr>.
* Fix handling of paragraph macros inside lists:Ingo Schwarze2012-07-181-4/+33
| | | | | | | * When they are trailing the last item, move them outside the list. * When they are trailing any other none-compact item, drop them. OpenBSD rev. mdoc_validate.c 1.107, mdoc.c 1.91
* Several -mdoc parser improvements related to vertical spacing:Ingo Schwarze2012-07-161-6/+36
| | | | | | | | | | * 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
* The post_nm() validation function crashed when the first .Nm child nodeIngo Schwarze2012-07-121-12/+17
| | | | | | | | | | 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
* fix position and formatting of %U;Ingo Schwarze2012-07-111-2/+2
| | | | OpenBSD rev. 1.104 and 1.145, respectively
* * implement -Tman .Bl -item -inset -diag -ohang -dash -hyphen -enum .ItIngo Schwarze2012-07-101-4/+16
| | | | | | | | | | * 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
* Support -Ios='OpenBSD 5.1' to override uname(3) as the source of theIngo Schwarze2012-05-271-11/+12
| | | | | | | | | | default value for the mdoc(7) .Os macro. Needed for man.cgi on the OpenBSD website. Problem with man.cgi first noticed by deraadt@; beck@ and deraadt@ agree with the way to solve the issue. "Please check them in and I'll look into them later!" kristaps@
* update Copyright years according to the CVS logs; no code changeIngo Schwarze2012-05-271-1/+1
|
* Make the `-width' field to `Bl' not puke if it doesn't have an argument.Kristaps Dzonsons2012-03-231-2/+7
| | | | This makes mandoc work much, much nicer with Mac OSX manpages.
* When processing .Sh HEAD, as soon as we know which section this is,Ingo Schwarze2011-12-031-0/+15
| | | | | | | | | | | fix up the section attributes of the HEAD, it's parent BLOCK, and all its (text) children. This is required because the section attributes get set when each node is allocated, i.e. before processing the content of the node itself. Thus, the listed nodes got the section attribute of the preceding section. No need to fix up the BODY, all is fine there already. Found while implementing TYPE_Sh for mandocdb(8). OK and comment requested by kristaps@.
* In man(7), when no explicit volume name is given, use the defaultIngo Schwarze2011-12-021-1/+1
| | | | | | | | | | | | volume name for the respective manual section, just like in mdoc(7). This gives us nicer page headers for cvs(1), lynx(1), tic(1), mkhybrid(8), and many curses(3) manuals. ok kristaps@ To not break compatibility, i wrote a corresponding patch for GNU troff which Werner Lemberg accepted upstream at rev. 1.65 of: http://cvs.savannah.gnu.org/viewvc/groff/tmac/an-old.tmac?root=groff
* Improve misleading comment:Ingo Schwarze2011-11-191-1/+5
| | | | | | | | * Not sure there were any text nodes, might have been other stuff instead. * Not sure it was just one node, maybe several were deleted. * No problem if some nodes were deleted, as long as some valid ones are left. * We do not leave early, but after cleaning out all the crap. * We are not "bailing", but we consider the block valid after cleanup.
* Bail out explicitly on invalid .Rs content like:Joerg Sonnenberger2011-11-181-0/+4
| | | | | | | | .Rs plain text .Re This avoids a crash on invalid.
* Remove a bunch of useless assignments,Ingo Schwarze2011-10-161-5/+4
| | | | | | | and assert that print_bvspace cannot be called on NULL pointers. No change in behaviour, none of these were bugs, but the code becomes easier to understand. Based on a clang report posted by joerg@; ok kristaps@.
* Make -man check for tabs correctly print the column.VERSION.1.11.7Kristaps Dzonsons2011-09-021-1/+1
|
* Avoid incorrect casting by using an implicit cast. Reported by ThomasKristaps Dzonsons2011-08-191-2/+2
| | | | Klausner.
* Fixed mingw compatibility where the "z" printf() modifier isn'tKristaps Dzonsons2011-08-161-2/+2
| | | | | recognised. It's easier to make these u_int than to jump through hoops for a special formatter.
* Allow `Sx' and `Ss' to have child nodes. Fixes manuals in NetBSD.Kristaps Dzonsons2011-08-101-34/+41
| | | | | | Originally pointed out by joerg@ then again by Thomas Klausner by way of Nicolas Joy. Note: don't use these constructions as you can't link to the sections with `Sx'.
* Move checking of escapes into roff.c, where we're already steppingKristaps Dzonsons2011-07-261-31/+5
| | | | | through looking for user-defined escapes. This clears up a nice bit of validation code.
* Scary-looking but otherwise harmless changes allow me to build for Windows.Kristaps Dzonsons2011-07-241-1/+1
| | | | | | | | | | | | That is to say, with mingw32. This amounts to the following: (1) break compat.c into compat_strlcpy.c and compat_strlcat.c (2) add compat_getsubopt.c (from OpenBSD) and test-getsubopt.c (3) add test-strptime.c for HAVE_STRPTIME (4) add ifdef bits here and there, where necessary (5) remove some harmless unportable stuff (u_char, localtime_r) I've added the appropriate mdocml.zip target to the Makefile, too.
* Make `struct roff' be passed into libmdoc and libman upon creation.Kristaps Dzonsons2011-07-181-1/+1
| | | | | This is required for supporting in-line equations. While here, push registers properly into roff and add an set/get/mod interface.
* No code change: fixing spelling errors. From a patch by uqs@. Thanks!Kristaps Dzonsons2011-04-301-1/+1
|
* Remove the warning for empty bodies of `Sh', `Ss', `SH', and `SS'. ThisKristaps Dzonsons2011-04-131-2/+2
| | | | | | | | | | | prompted by a TODO by schwarze@, originally from Gleydson Soares, that an empty `SS' was raising an error (it hasn't for some time). It makes sense these shouldn't warn, as omitting their contents doesn't change anything in the structure of the document (groff and mandoc specifically account for the whitespace between empty sections). This doesn't change any manuals, which only refer to the line arguments (or possibly next-line, in the case of man(7) syntax).
* Remove a2roffdeco() and mandoc_special() functions and replace them withKristaps Dzonsons2011-04-091-11/+19
| | | | | | | | | | | | | | | | | | a public (mandoc.h) function mandoc_escape(), which merges the functionality of both prior functions. Reason: code duplication. The a2roffdeco() and mandoc_special() functions were pretty much the same thing and both quite complex. This allows one function to receive improvements in (e.g.) subexpression handling and performance, instead of having to replicate functionality. As such, the mandoc_escape() function already handles a superset of the escapes handled in previous versions and has improvements in performance (using strcspn(), for example) and reliable handling of subexpressions. This code Works For Me, but may need work to catch any regressions. Since the benefits are great (leaner code, simpler API), I'd rather have it in-tree than floating as a patch.