summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/term.c
AgeCommit message (Collapse)Author
2015-10-23apply bold and italic to all non-ASCII Unicode codepoints,Ingo Schwarze
fixing input like \fB\('e; issue reported by bentley@
2015-10-13Major character table cleanup:Ingo Schwarze
* Use ohash(3) rather than a hand-rolled hash table. * Make the character table static in the chars.c module: There is no need to pass a pointer around, we most certainly never want to use two different character tables concurrently. * No need to keep the characters in a separate file chars.in; that merely encourages downstream porters to mess with them. * Sort the characters to agree with the mandoc_chars(7) manual page. * Specify Unicode codepoints in hex, not decimal (that's the detail that originally triggered this patch). No functional change, minus 100 LOC, and i don't see a performance change.
2015-10-12To make the code more readable, delete 283 /* FALLTHROUGH */ commentsIngo Schwarze
that were right between two adjacent case statement. Keep only those 24 where the first case actually executes some code before falling through to the next case.
2015-10-06modernize style: "return" is not a function; ok cmp(1)Ingo Schwarze
2015-09-26/* NOTREACHED */ after abort() is silly, delete itIngo Schwarze
2015-09-21Trailing whitespace is significant when determining the width of a tagIngo Schwarze
in mdoc(7) .Bl -tag and man(7) .TP, but not in man(7) .IP. Quirk reported by Jan Stary <hans at stare dot cz> on ports@.
2015-08-30Drop leading, internal, and trailing blank characters in \o (overstrike)Ingo Schwarze
escape sequences; that's cleaner for all output modes, and it's required to prevent the PostScript/PDF formatter from dying on assertions. Bug found by jsg@ with afl.
2015-04-29Replace the kludge for the \z escape sequence by an actualIngo Schwarze
implementation. As a side effect, minus ten lines of code. As another side effect, this also fixes the assertion failure that used to be triggered by "\z\o'ab'c" at the beginning of an output line, found by jsg@ with afl (test case 022/Apr27).
2015-04-04Rounding rules for horizontal scaling widths are more complicated.Ingo Schwarze
There is a first rounding to basic units on the input side. After that, rounding rules differ between requests and macros. Requests round to the nearest possible character position. Macros round to the next character position to the left. Implement that by changing the return value of term_hspan() to basic units and leaving the second scaling and rounding stage to the formatters instead of doing it in the terminal handler. Improves for example argtable2(3).
2015-04-02Third step towards parser unification:Ingo Schwarze
Replace struct mdoc_meta and struct man_meta by a unified struct roff_meta. Written of the train from London to Exeter on the way to p2k15.
2015-03-09prevent the skipvsp flag from creeping past actual textIngo Schwarze
2015-01-31Use relative offsets instead of absolute pointers for the terminalIngo Schwarze
font stack. The latter fail after the stack is grown with realloc(). Fixing an assertion failure found by jsg@ with afl some time ago (test case number 51).
2015-01-21Rudimentary implementation of the roff(7) \o escape sequence (overstrike).Ingo Schwarze
This is of some relevance because the pod2man(1) preamble abuses it for the icelandic letter Thorn, instead of simply using \(TP and \(Tp. Missing feature found by sthen@ in DateTime::Locale::is_IS(3p).
2014-12-24Support negative indentations for mdoc(7) displays and lists.Ingo Schwarze
Not exactly recommended for use, rather for groff compatibility. While here, introduce similar SHRT_MAX limits as in man(7), fixing a few cases of infinite output found by jsg@ with afl.
2014-12-24When a man(7) document contains unreasonably large numbers forIngo Schwarze
indentations or paragraph distances, large output may be generated, which is practically the same as an endless loop; found by jsg@ with afl. Reject such unreasonably large numbers beyond arbitrary limits similar to those used by groff (max. 65 blank lines between paragraphs and max. SHRT_MAX characters per output line) and fall back to defaults when exceeded. Having the limits behave in exactly the same way is not relevant.
2014-12-23support negative horizontal widths in man(7);Ingo Schwarze
minus twenty lines of code in spite of enhanced functionality
2014-12-23Fix vertical scaling. Obviously, nobody ever had a serious look at this.Ingo Schwarze
Basic units, centimeters, points, ens, ems, and the rounding algorithm were all wrong, only inches, pica, and the default vertical span worked.
2014-12-19Enforcing an arbitrary, implementation dependent, undocumented limitIngo Schwarze
by calling assert() when valid user input exceeds it is a bad idea. Allocate the terminal font stack dynamically instead of crashing above 10 entries. Issue found by jsg@ with afl.
2014-12-02Fix the implementation and documentation of \c (continue text input line).Ingo Schwarze
In particular, make it work in no-fill mode, too. Reminded by Carsten dot Kunze at arcor dot de (Heirloom roff).
2014-11-21We repeatedly observed assertion crashes in the low-level terminalIngo Schwarze
output handler because the high level terminal formatters could be tricked into setting the left margin further to the right than the right margin. Today, jsg@ found more of these with afl. Change the internal interface between both levels, aiming for simplicity and robustness of the code. Treat both margins as *independent* settings: Now, termp.offset is the requested left margin, and termp.rmargin is the available space. Let the lower level cope with that case of insufficient space. Obviously, high level code that does centering or flush right still has to do careful checks, so i did a full audit of margin settings in the terminal formatters. Fixes crashes caused by excessively long title or date strings in the man(7) footer, operating system or date strings in the mdoc(7) footer, volume strings in the man(7) or mdoc(7) header, and a few cases related to some non-prologue macros.
2014-11-16When a line (in the sense of term_flushln()) contains white space only,Ingo Schwarze
the `vbl' variable includes the left margin, but `vis' does not. Prevent a `vis' underflow that caused a bogus blank line. Bug reported by Carsten Kunze, found in less(1): .Bl -tag ... .It " "
2014-11-01fix a typo causing crashes in Unicode string length measurementIngo Schwarze
2014-10-29In terminal output, unify handling of Unicode and numbered characterIngo Schwarze
escape sequences just like it was earlier implemented for -Thtml. Do not let control characters other than ASCII 9 (horizontal tab) propagate to the output, even though groff allows them; but that really doesn't look like a great idea. Let mchars_num2char() return int such that we can distinguish invalid \N syntax from \N'0'. This also reduces the danger of signed char issues popping up.
2014-10-28In -Tascii mode, print "<?>" only for Unicode escapes of unknownIngo Schwarze
representation, not for character escapes with unknown names. According to groff, the latter produce no output, and we now warn about them.
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-27Fix a regression in term.c rev. 1.89 reported by bentley@:Ingo Schwarze
In UTF-8 output, do not print anything if mchars_spec2cp() returns 0. In particular, this repairs handling of zero-width spaces (\&). While here, let mchars_spec2cp() return 0xFFFD instead of -1 if the character is not found, simplifying the using code. In HTML output, do not print obfuscated ASCII characters and do not test for one-char escapes, mchars_spec2cp() already does that.
2014-10-26Improve -Tascii output for Unicode escape sequences: For the first 512Ingo Schwarze
code points, provide ASCII approximations. This is already much better than what groff does, which prints nothing for most code points. A few minor fixes while here: * Handle Unicode escape sequences in the ASCII range. * In case of errors, use the REPLACEMENT CHARACTER U+FFFD for -Tutf8 and the string "<?>" for -Tascii output. * Handle all one-character escape sequences in mchars_spec2{cp,str}() and remove the workarounds on the higher level.
2014-08-18Fix read access to uninitialized memory found by kristaps@ with valgrind,Ingo Schwarze
patch from kristaps@. Theoretically, this could lead to a buffer overrun and segfault, but only for very long output lines (about 1000 charecters) of exactly the right length or if by ill chance, the complete unused, uninitialized tail of the line output buffer (at least 1000 characters total length) would contain all blank characters. Anyway, the uninitialized data read wasn't used for anything.
2014-08-08Fix floating point handling: When converting double to size_t,Ingo Schwarze
properly round to the nearest M (=0.001m), which is the smallest available unit. This avoids weirdness like (size_t)(0.6 * 10.0) == 5 by instead calculating (size_t)(0.6 * 10.0 + 0.0005) == 6, and so it fixes the indentation of the readline(3) manual.
2014-08-08Clarity with respect to floating point handling:Ingo Schwarze
Write double constants as double rather than integer literals. Remove useless explicit (double) cast done at one place and nowhere else. No functional change.
2014-07-06After skipping an escape sequence with incomplete arguments,Ingo Schwarze
do not throw away the rest of the string to be rendered.
2014-04-23Audit malloc(3)/calloc(3)/realloc(3) usage.Ingo Schwarze
* 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).
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-08Add a new term_flushln() flag TERMP_BRIND (if break, then indent)Ingo Schwarze
to control indentation of continuation lines in TERMP_NOBREAK mode. In the past, this was always on; continue using it for .Bl, .Nm, .Fn, .Fo, and .HP, but no longer for .IP and .TP. I looked at this because sthen@ reported the issue in a manual of a Perl module from ports, but it affects base, too: This patch reduces groff-mandoc differences in base by more than 15%.
2014-04-05bugfix: make sure all variables are properly initializedIngo Schwarze
when rendering .ll (line length) requests. oops.
2014-03-30Support relative arguments to .ll (increase or decrease line length).Ingo 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-13In -Tutf8 mode, make sure that hyphens get counted against the output lineIngo Schwarze
length even when they are breakable. Before this, a line containing N breakable hyphens could get up to N characters wider than the right margin in -Tutf8 output mode. Issue reported by tedu@ on bugs@.
2014-01-22Implement the \: (optional line break) escape sequence,Ingo Schwarze
documented in the Ossanna-Kernighan-Ritter troff manual and also supported by groff. Missing feature reported by Steffen Nurpmeso <sdaoden at gmail dot com>.
2013-12-31remove assignments that will be overwritten right afterwards,Ingo Schwarze
and remove pointless local variables; found in a clang output from Ulrich Spoerlein <uqs at FreeBSD>
2013-12-25Do not break output lines in .Fn function arguments in SYNOPSIS mode.Ingo Schwarze
Following an idea from Franco Fichtner, but implemented more cleanly. This reduces groff-mandoc-differences in base by a fantastic 7.5%.
2013-12-24Delete the unused flag TERMP_IGNDELIMIngo Schwarze
and the empty callback termp_igndelim_pre(). Sort the remaining termp flags.
2013-12-23Implement a long-standing desideratum,Ingo Schwarze
hanging indentation for .Fn in SYNOPSIS mode, exploiting the new trailspace feature by deliberately *NOT* using it.
2013-12-22Polishing the worms in my favourite can, term_flushln().Ingo Schwarze
The TERMP_TWOSPACE flag i introduced in August 2009 was idiosyncratic and served only a very narrow purpose. Replace it by a more intuitive and more general termp attribute "trailspace", to be used together with TERMP_NOBREAK, to request a minimum amount of whitespace at the end of the current column. Adapt all code to the new interface. No functional change intended; code reviews to confirm that are welcome *eg*.
2013-08-21Move the last column-counting members of struct termp (col and maxcols)Ingo Schwarze
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.
2013-08-08Implement the roff(7) font-escape sequence \f(BI "bold+italic".Ingo Schwarze
This improves the formatting of about 40 base manuals and reduces groff-mandoc formatting differences in base by about 5%.
2013-08-05After a leading blank on an output line, the first word was counted twiceIngo Schwarze
against vend, causing a premature line break. Fix that bug by reverting revision 1.10 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).
2013-05-29In keep mode, if any text is printed (even in NOSPACE mode),Ingo Schwarze
any text that follows must be kept on the same line. I already found the issue and wrote the patch in April 2011, but didn't come round to do proper testing and forgot about it.
2012-11-16Improve formatting of badly nested font blocks.Ingo Schwarze
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.
2012-07-16Release polishing: finally fix the perl(1) SYNOPSIS.Ingo Schwarze
In flush-left mode of both man(7) and mdoc(7), when an output line is broken at the position of a literal tab, the tab indents the following line. Reminded by deraadt@ in Pest, Ujlipotvaros, Csanady utza.