summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/term.c
AgeCommit message (Collapse)Author
2011-09-21As noticed by kristaps@, when breaking an overflowing line,Ingo Schwarze
forget about pending whitespace (vbl), or the next line would be misaligned and potentially too long; but i'm fixing this in a simpler way than he proposed. Also remove the kludges in .HP that compensated for this bug.
2011-09-19Remove the terminal frontend flag TERMP_NOLPAD.Ingo Schwarze
In columnated contexts (.Bl -column, .Bl -tag, .IP, .TP, .HP etc.), do not pad after writing a column. Instead, always pad before writing content. In itself, this change avoids: - writing trailing whitespace in some situations - with .fi/.nf in .HP, breaking lines that were already padded It allows several bugfixes included in this patch: - Do not count backspace as a character with positive width. - Set up proper indentation when encountering .fi/.nf in .HP. - Adjust the .HP indentation width to what groff does. - Never unlimit the right margin unless in the final column. This reduces the groff/mandoc-differences in base by nearly 20%, from 89k to 72k lines of diffs. ok kristaps@
2011-09-18fix a regression introduced in 1.11.7:Ingo Schwarze
even a breakable hyphen may be bold or underlined With this fix, 1.11.7 reduces the groff/mandoc differences in base by about 10% (100k -> 90k lines of diffs) with respect to 1.11.5.
2011-05-29Merge release 1.11.3, almost all code by kristaps@:Ingo Schwarze
* Unicode output support (no Unicode input yet, though). * Refactoring: completely handle predefined strings in roff.c. - New function mandoc_escape() replaces a2roffdeco() and mandoc_special(). - Start using mandoc_getarg() in mdoc_argv.c. - Clean up parsing of delimiters in mdoc(7). * And many minor fixes and lots of cleanup.
2011-04-24Merge version 1.11.1:Ingo Schwarze
Again lots of cleanup and maintenance work by kristaps@. - simplify error reporting: less function pointers, more mandoc_[v]msg - main: split document parsing out of main.c into read.c - roff, mdoc, man: improved recognition of control characters - roff: better handling of if/else stack overflows - roff: add some predefined strings for backward compatibility - mdoc, man: empty sections are not errors - mdoc: move delimiter handling to libmdoc - some header restructuring and some minor features and fixes This merge causes two minor regressions that i will fix in separate commits right afterwards.
2011-04-21Merge version 1.10.10:Ingo Schwarze
lots of cleanup and maintenance work by kristaps@. - move some main.c globals into struct curparse - move mandoc_*alloc to mandoc.h such that all code can use them - make mandoc_isdelim available to formatting frontends - dissolve mdoc_strings.c, move the code where it is used - make all error reporting functions void, their return values were useless - and various minor cleanups and fixes
2011-01-30Implement the \N'number' (numbered character) roff escape sequence.Ingo Schwarze
Don't use it in new manuals, it is inherently non-portable, but we need it for backward-compatibility with existing manuals, for example in Xenocara driver pages. ok kristaps@ matthieu@ jmc@
2011-01-04Merge kristaps@' cleaner tbl integration, removing mine;Ingo Schwarze
there are still a few bugs, but fixing these will be easier in tree.
2010-10-27Fix an off-by-one in an assertion, crashing the renderer on ".Os \&".Ingo Schwarze
This bug was a living fossil, introduced on Feb 21, 2009. Reported by joachimschipper dot nl, thanks.
2010-10-02style cleanup, no functional change:Ingo Schwarze
* make the initial maxvis/mmax calculation easier to understand * where real, non-indexing casts happen, make them explicit * avoid a few lint warnings that can easily be fixed * remove one needless LINTED comment "I like this" kristaps@
2010-10-01* need a space before .No even if it starts with a closing delimiterIngo Schwarze
* slightly simplify .Pf *_IGNDELIM code, and share part of it with .No * do not let opening delimiters fall out of the front of .Ns (from kristaps@) This fixes a few spacing issues in csh(1) and ksh(1). OK kristaps@
2010-09-23Count trailing escaped blanks correctly;Ingo Schwarze
those ruined the alignment of columns. Tested by jmc@, and kristaps@ agrees with the direction.
2010-09-21When calculating string lengths, resolve escape sequences and useIngo Schwarze
their actual lengths. Will improve vertical alignment in some uncommon situations, for example when escape sequences occur in list or column width strings or in .Nm block arguments in the SYNOPSIS. From kristaps@.
2010-08-20Centralize handling of literal tabs in term_flushln() in one place,Ingo Schwarze
making the code simpler and easier to understand. No functional change.
2010-08-20When a column contains trailing spaces, calculate the paddingIngo Schwarze
to the start of the next column correctly. Fixing a problem found by jmc@ in sysctl(3), reminded by kettenis@.
2010-08-20Implement a simple, consistent user interface for error handling.Ingo Schwarze
We now have sufficient practical experience to know what we want, so this is intended to be final: - provide -Wlevel (warning, error or fatal) to select what you care about - provide -Wstop to stop after parsing a file with warnings you care about - provide consistent exit status codes for those warnings you care about - fully document what warnings, errors and fatal errors mean - remove all other cruft from the user interface, less is more: - remove all -f knobs along with the whole -f option - remove the old -Werror because calling warnings "fatal" is silly - always finish parsing each file, unless fatal errors prevent that This commit also includes a couple of related simplifications behind the scenes regarding error handling. Feedback and OK kristaps@; Joerg Sonnenberger (NetBSD) and Sascha Wildner (DragonFly BSD) agree with the general direction.
2010-07-31Merge bsd.lv version 1.10.5: last larger batch of bug fixes before release.Ingo Schwarze
NOT including Kristaps' .Bd -literal changes which cause regressions. Features: * -Tpdf now fully working Bugfixes: * proper handling of quoted strings by .ds in roff(7) * allow empty .Dd * make .Sm start no-spacing after the first output word * underline .Ad * minor fixes in -Thtml and some optimisations in terminal output.
2010-07-25Sync to bsd.lv; in particular, pull in lots of bug fixes.Ingo Schwarze
new features: * support the .in macro in man(7) * support minimal PDF output * support .Sm in mdoc(7) HTML output * support .Vb and .nf in man(7) HTML output * complete the mdoc(7) manual bug fixes: * do not let mdoc(7) .Pp produce a newline before/after .Sh; reported by jmc@ * avoid double blank lines related to man(7) .sp and .br * let man(7) .nf and .fi flush the line; reported by jsg@ and naddy@ * let "\ " produce a non-breaking space; reported by deraadt@ * discard \m colour escape sequences; reported by J.C. Roberts * map undefined 1-character-escapes to the literal character itself maintenance: * express mdoc(7) arguments in terms of an enum for additional type-safety * simplify mandoc_special() and a2roffdeco() * use strcspn in term_word() in place of a manual loop * minor optimisations in the -Tps and -Thtml formatting frontends
2010-07-13Merge release 1.10.4 (all code by kristaps@), providing four new features:Ingo Schwarze
1) Proper .Bk support: allow output line breaks at input line breaks, but keep input lines together in the output, finally fixing synopses like aucat(1), mail(1) and tmux(1). 2) Mostly finished -Tps (PostScript) output. 3) Implement -Thtml output for .Nm blocks and .Bk -words. 4) Allow iterative interpolation of user-defined roff(7) strings. Also contains some minor bugfixes and some performance improvements.
2010-07-03Rudimentary implementation of user-defined strings;Ingo Schwarze
no time for more refinement right now. In particular, fixes terminfo(3) and mdoc.samples(7). ok kristaps@, who will add the HTML frontend bits
2010-06-29framework for glyph width encoding; from kristaps@Ingo Schwarze
2010-06-27Full .nr nS support, unbreaking the kernel manuals.Ingo Schwarze
Kristaps coded this from scratch after reading my .nr patch; it is simpler and more powerful. Registers live in struct regset in regs.h, struct man and struct mdoc contain pointers to it. The nS register is cleared when parsing .Sh. Frontends respect the MDOC_SYNPRETTY flag set in mdoc node_alloc.
2010-06-27Basic implementation of .Bk/.Ek.Ingo Schwarze
OK and one stylistic tweak by kristaps@.
2010-06-26As a first step towards variable-width font support,Ingo Schwarze
move all width calculations in term_*.c, *_width(). From kristaps.
2010-06-26merge release 1.10.2Ingo Schwarze
* bug fixes: - interaction of ASCII_HYPH with special chars (found by Ulrich Spoerlein) - handling of roff conditionals (found by Ulrich Spoerlein) - .Bd -offset will no more default to 6n * maintenance: - more caching of .Bd and .Bl arguments for efficiency - deconstify man(7) validation routines - add FreeBSD library names (provided by Ulrich Spoerlein) * start PostScript font-switching
2010-06-10minimal initial -Tps support, from kristaps@ GSOCIngo Schwarze
so far, monospace without font decoration, but it already has page headers and footers
2010-06-08Merge more bits that will be going into 1.10.1:Ingo Schwarze
Clean up vertical spacing in the SYNOPSIS, making the code much more systematic; this doesn't solve all SYNOPSIS problems yet, in particular not those related to keeps, indentation and the low-level .nr roff instruction, but it's a nice step forward and i couldn't find relevant regressions. (from kristaps) Besides, * make the output width configurable (default: -Owidth=80) (kristaps) * use mmap with MAP_SHARED (from Joerg Sonnenberger)
2010-05-26When a word does not fully fit onto the output line, but it containsIngo Schwarze
at least one hyphen, we already had support for breaking the line a the last fitting hyphen. This patch improves this functionality by only breaking at hyphens in free-form text, and by not breaking at hyphens * at the beginning or end of a word or * immediately preceded or followed by another hyphen or * escaped by a preceding backslash. Before this patch, differences in break-at-hyphen support were one of the major sources of noise in automatic comparisons to mdoc(7) groff output. Now, the remaining differences are hard to find among the noise coming from other sources. Where there are still differences, what we do seems to be better than what groff does, see e.g. the chio(1) exchange and position commands for one of the now rare examples. idea and coding by kristaps@ Besides, this was the last substantial code difference left between bsd.lv and openbsd.org. We are now in full sync.
2010-05-23Unified error and warning message system for all of mandoc,Ingo Schwarze
featuring three message levels, as agreed during the mandoc hackathon: * FATAL parser failure, cannot produce any output from this input file: eventually, we hope to convert most of these to ERRORs. * ERROR, meaning mandoc cannot cope fully with the input syntax and will probably lose information or produce structurally garbled output; it will try to produce output anyway but exit non-zero at the end, which is eventually intended to make the ports infrastructure happy. * WARNING, meaning you should clean up the input file, but output is probably mostly OK, so this will not cause error-exit at the end. This commit is mostly just converting the old system to the new one; before the classification will become really reliable, we must check all messages. In particular, * set up a new central message string table in main.c * drop the old message string tables from man.c and mdoc.c * get rid of the piece-meal merr enums in libman and libmdoc * reduce number of error/warning functions from 16 to 6 (still a lot...) While here, handle a few problems more gracefully: * allow .Rv and .Ex to work without a prior .Nm * allow .An to ignore extra arguments * allow undeclared columns in .Bl -column Written by kristaps@.
2010-05-17The function term_flushln() had effectively forked wrt to bsd.lv.Ingo Schwarze
This is the OpenBSD part of the main step to bring it back in sync. At the same time, this prevents trailing whitespace in the output: We delay writing blanks until we are sure printable characters follow. This is achieved by * not using vbl any longer for the control of line breaking * such that vbl can sum up all kinds of white space * before writing a word, printing all the blanks collected in vbl * within the word, adding NBSP chars to vbl, then continuing with the word * after the word, adding blanks to vbl, then starting the next word
2010-05-15More systematic output width handling by Joerg Sonnenberger:Ingo Schwarze
* save and restore the output width when switching to MANT_LITERAL * add an argument to ascii_alloc to specify the output width * set the default output width to 80 minus 2 characters * OpenBSD local: set the output width to 65 characters for -man
2010-05-14Integrate kristaps@' end-of-sentence (EOS) frameworkIngo Schwarze
which is simpler and more powerful than mine, and remove mine. * man(7) now has EOS handling, too * put EOS detection into its own function in libmandoc * use node and termp flags to communicate the EOS condition * no more EOS pseudo-macro * no more non-printable EOS marker character on the formatter level This slightly breaks EOS detection after trailing punctuation in mdoc(7) macros, but that will be restored soon.
2010-04-23Handle literal tab characters both in literal context (.Bd -literal)Ingo Schwarze
and outside. In literal context, tab stops are at each eigth column; outside, they are at each fifth column. Use tabwidth = 5 as the default and temporarily switch to 8 in termp_bd_pre(). This requires to move the term_flushln() of the final line of a display from termp_bd_post() to termp_bd_pre(); the former still needs term_newln() to handle the final lines of non-literal displays. Handling inside term_flushln() is tricky because a tab collapses with inter-word spacing, but not with another tab. Missing feature reported independently by jmc@ and deraadt@.
2010-04-13Fix rendering of multiple successive .It macros without intervening text;Ingo Schwarze
another problem reported by jmc@. The physical output line may contain output from more than one buffer. Thus, to decide whether a line break is needed, it's insufficient to only look at the number of bytes in the current output buffer. Keep track of the number of characters already written, too.
2010-04-12Partial revert of term.c rev. 1.23Ingo Schwarze
because jmc@ noticed that it broke blank lines in literal displays. The original idea was to suppress stray blank lines. But we don't want to suppress *all* blank lines, instead just those caused by nested lists. So do the check whether there was any output on this line, i.e. whether or not to break the line, at the right place, which is after processing the .It body.
2010-04-07Merge the good parts of 1.9.23,Ingo Schwarze
avoid the bad parts of 1.9.23, and keep local patches. Input in general: * Basic handling of roff-style font escapes \f, \F. * Quoted punctuation does not count as punctuation. mdoc(7) parser: * Make .Pf callable; noted by Claus Assmann. * Let .Bd and .Bl ignore unknown arguments; noted by deraadt@. * Do not warn when .Er is used outside certain sections. * Replace mdoc_node_free[list] by mdoc_node_delete. * Replace #define by enum for rew*() return values. man(7) parser: * When .TH is missing, use default section and date. Output in general: * Curly braces do not count as punctuation. * No space after .Fl w/o args when a macro follows on the same line. HTML output: * Unify PAIR_*_INIT macros, introduce new PAIR_ID_INIT(). * Print whitespace after, not before .Vt .Fn .Ft .Fo. Checked that all manuals in base still build.
2010-03-26merge 1.9.17, keeping local patchesIngo Schwarze
* much improved pod2man support and low-level roff robustness * have -Tlint imply -Wall and -fstrict * use fewer macros and more enum in libman * and various bug fixes
2010-03-22Only try to break the line at an existing hyphenIngo Schwarze
when there actually IS a hyphen. Fixing an endless loop that broke the xenocara build.
2010-03-20When the length of a single words exceeds the maximum acceptable lineIngo Schwarze
length, rather ignore the right margin than entering an endless loop. Found the hard way in /usr/xenocara/app/fvwm/modules/FvwmM4/FvwmM4.1.
2010-03-06When the last field on an output line is empty, break the lineIngo Schwarze
if and only if something was printed on that line. This avoids double line breaks after nested lists while still breaking lines after items with empty body.
2010-03-05At the end of lines, split words at existing hyphens:Ingo Schwarze
Making pages look better and helping comparisons with groff output. Note that proper hyphenation is postponed for now because it doesn't really help the switch.
2010-03-02Proper inter-sentence spacing for mdoc(7).Ingo Schwarze
When a text line or a non-block macro line in the source code ends in any of ".!?", consider that an end of sentence (EOS). This makes Jason's rule "new sentence, new line" even more important. Let the parser detect the EOS and insert a token into the AST. Let the -Tascii frontend render the EOS token as a double space before the next word.
2009-12-24sync to 1.9.14: rewrite escape sequence handling:Ingo Schwarze
- new function a2roffdeco - font modes (\f) only affect the current stack point - implement scaling (\s) - implement space suppression (\c) - implement non-breaking space (\~) in -Tascii - many manual improvements
2009-12-22sync to 1.9.12, mostly portability and refactoring:Ingo Schwarze
correctness/functionality: - bugfix: do not die when overstep hits the right margin - new option: -fign-escape - and various HTML features portability: - replace bzero(3) by memset(3), which is ANSI C - replace err(3)/warn(3) by perror(3)/exit(3), which is ANSI C - iuse argv[0] instead of __progname - add time.h to various files for FreeBSD compilation simplicity: - do not allocate header/footer data dynamically in *_term.c - provide and use malloc frontends that error out on failure for full changelogs, see http://bsd.lv/cgi-bin/cvsweb.cgi/
2009-10-27sync to 1.9.11: adapt printing of dates to groff conventions,Ingo Schwarze
NetBSD portability fixes and some minor bugfixes and feature enhancements; also checked that my hyphenation code still works on top of this
2009-10-24simplify overstep handling, removing one local variable;Ingo Schwarze
no functional change; ok kristaps@ and merged as rev. 1.110
2009-10-21sync to 1.9.9, featuring:Ingo Schwarze
* -Thtml output mode * roff scaling units * and some minor fixes for full changelogs, see http://bsd.lv/cgi-bin/cvsweb.cgi/
2009-10-19sync to 1.9.5: partial rewrite of special character and predefined stringIngo Schwarze
tables and the supporting infrastructure, mostly in preparation for HTML output support
2009-10-18sync to 1.9.5: integrate closedelim() and opendelim() into term_word(),Ingo Schwarze
removing unnecessary extra functions
2009-09-21sync to 1.9.5: make terminal_*, tree_* and out_* functions return void,Ingo Schwarze
making the code simpler