1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 16:42:56 -08:00
Commit Graph

46 Commits

Author SHA1 Message Date
schwarze
2fb659f945 Quirk-compatibility with GNU tbl(1):
With the "nospaces" option, skip space characters before and after "T{",
in addition to skipping those at the beginning and end of data cells.

Minor issue reported by <Oliver dot Corff at email dot de>.
2021-09-10 13:23:44 +00:00
schwarze
86dcadab37 In a tbl(7) having the "nospaces" option, skip space characters
not only at the end of data cells, but also after "T}",
aligning the behaviour of the parser with GNU tbl(1).

Issue reported by <Oliver dot Corff at email dot de>.
2021-09-10 12:06:29 +00:00
schwarze
fbc27a2f16 we already parse the GNU tbl(7) "nospaces" option,
so let it have the intended effect, too
2021-09-07 11:47:42 +00:00
schwarze
7d063611b9 Support two-character font names (BI, CW, CR, CB, CI)
in the tbl(7) layout font modifier.

Get rid of the TBL_CELL_BOLD and TBL_CELL_ITALIC flags and use
the usual ESCAPE_FONT* enum mandoc_esc members from mandoc.h instead,
which simplifies and unifies some code.

While here, also support CB and CI in roff(7) \f escape sequences
and in roff(7) .ft requests for all output modes.  Using those is
certainly not recommended because portability is limited even with
groff, but supporting them makes some existing third-party manual
pages look better, in particular in HTML output mode.

Bug-compatible with groff as far as i'm aware, except that i consider
font names starting with the '\n' (ASCII 0x0a line feed) character
so insane that i decided to not support them.

Missing feature reported by nabijaczleweli dot xyz in
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=992002.
I used none of the code from the initial patch submitted by
nabijaczleweli, but some of their ideas.
Final patch tested by them, too.
2021-08-10 12:36:42 +00:00
schwarze
1a285ef1a4 When looking for column separators on tbl(7) data lines, properly skip
escape sequences; do not misinterpret bytes from the middle of escape
sequence names or arguments as column separators.
Bug reported and patch tested by Oliver dot Corff at email dot de.
2021-05-18 13:22:37 +00:00
schwarze
61deec7370 When looking for the last layout row used, we need to look at the layout
row used for the previous data line containing data, not at the previous
data line outright, which might be a horizontal ruler.  If it is, do not
restart from the first layout row but still proceed to the next data row,
which may have been just read from T&.

Bug originally reported by Oliver dot Corff at email dot de
on groff at gnu dot org:
https://lists.gnu.org/archive/html/groff/2021-03/msg00003.html
and forwarded to me by bentley@.

Patch OK'ed by bentley@ back in April.
2021-05-15 17:16:38 +00:00
schwarze
ebc37634d6 When autogenerating one layout cell from a data cell just beyond the
last layout cell that was explicitly specified, properly initialize
the spacing attribute to indicate that the default is to be used.
Failing to do so and leaving the spacing at zero in this case caused
misformatting when another row further down the table had even more
explicitly specified cells.
Bug found while trying to write regression tests for tbl_term.c rev. 1.61.
2020-01-11 20:48:13 +00:00
schwarze
ef2f450588 ignore empty request lines in the table data reader;
fixing a minibug reported by bentley@
2019-02-09 16:00:06 +00:00
schwarze
a5a5f808f8 Almost mechanical diff to remove the "struct mparse *" argument
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.
2018-12-14 05:17:45 +00:00
schwarze
e501e731de Major cleanup; may imply minor changes in edge cases of error reporting.
Finally, drop support for the run-time configurable mandocmsg()
callback.  It was over-engineered from the start, never used for
anything in a decade, and repeatedly caused maintenance headaches.

Consolidate reporting infrastructure into two files, mandoc.h and
mandoc_msg.c, mopping up the bits and pieces that were scattered
around main.c, read.c, mandoc_parse.h, libmandoc.h, the prototypes
of four parsing-related functions, and both parser structs.
2018-12-14 01:17:46 +00:00
schwarze
fb382a019a Cleanup, no functional change:
Move tbl(7)-specific parser internals out of libroff.h.
Move some tbl(7)-internal processing from roff.c to tbl.c.
2018-12-13 02:05:57 +00:00
schwarze
fae2491ec8 Cleanup, no functional change:
No need to expose the tbl(7) syntax tree data structures everywhere.
Move them to their own include file, "tbl.h", and improve comments.
2018-12-12 21:54:30 +00:00
schwarze
7a5a8f145d Let cells containing nothing but \^ extend the cell above.
Missing feature reported by Pali dot Rohar at gmail dot com.
2018-11-25 21:17:30 +00:00
schwarze
a93944b218 In tbl(7) -T html output,
span cells horizontally and vertically as requested by the layout.
Does not handle spans requested in the data section yet.

To be able to do this, record the number of rows spanned
in the first data cell (struct tbl_dat) of a vertical span.

Missing feature reported by Pali dot Rohar at gmail dot com.
2018-11-25 19:23:59 +00:00
schwarze
d93f856190 Simplify by creating struct roff_node syntax tree nodes for tbl(7)
right from roff_parseln() rather than delegating to read.c,
similar to what i just did for eqn(7).

The interface function roff_span() becomes obsolete and is deleted,
the former interface function roff_addtbl() becomes static,
the interface functions tbl_read() and tbl_cdata() become void,
and minus twelve linus of code.

No functional change.
2017-07-08 17:52:42 +00:00
schwarze
acb996efb1 It turns out association of tbl spans with layout rows is simpler than
i thought.  Fixing a bug in curs_addch(3) and minus 25 lines of code.
2017-07-04 20:59:17 +00:00
schwarze
eaa4dcb476 Multiple tbl(7) improvements:
* Do not discard data that lacks a matching layout cell but remains
within the number of columns of the table as a whole.
* Do not insert dummy data rows for any layout row starting with a
horizontal line, but only for layout rows that would discard all
the data on a matching non-empty data row.
* Print horizontal lines specified in the layout even if there is
no matching data cell.
* Improve the logic for extending vertical lines to adjacent rows,
for choosing cross marks versus line segments, and some related details.
2017-06-16 20:00:41 +00:00
schwarze
2c3e66c426 Implement w layout specifier (minimum column width).
Improve width calculation of text blocks.
Reduces the groff/mandoc diff in Base+Xenocara by about 800 lines.
2017-06-08 18:11:15 +00:00
schwarze
526e306b37 modernize style: "return" is not a function; ok cmp(1) 2015-10-06 18:30:43 +00:00
schwarze
3569c65295 More than one data field may follow T} on the same input line.
Issue found by Christian Neukirchen <chneukirchen at gmail dot com>
in the socket(2) manual on Linux.
Also fixes major rendering bugs (including partial loss of content)
in XkbChangeControls(3), XkbFreeClientMap(3), XkbGetMap(3),
XkbKeyNumGroups(3), and XkbSetMap(3).
2015-04-19 20:34:56 +00:00
schwarze
cb1515965e Delete the redundant tbl span flags, just inspect the actual data
where needed, which is less fragile.
This fixes a subtle NULL pointer access to tp->tbl.cols:
Due to a bug in the man(7) parser, the first span of a table can
end up in a .TP head, in which case tblcalc() was never called.
Found by jsg@ with afl.
2015-01-30 17:31:20 +00:00
schwarze
5f6d1ba3b6 Abolish struct tbl_head and replace it by an "int col" member in
struct tbl_cell.  No functional change, minus 40 lines of code.
2015-01-30 04:08:37 +00:00
schwarze
21da0636bd Auditing the tbl(7) code for more NULL pointer accesses, i came out
empty-handed; so this is just KNF and some code simplifications,
no functional change.
2015-01-30 02:08:37 +00:00
schwarze
92ff8da656 * Polish tbl(7) error reporting.
* Do not print out macro names in tbl(7) data blocks.
* Like with GNU tbl, let empty tables cause a blank line.
* Avoid producing empty tables in -Tman.
2015-01-28 17:30:37 +00:00
schwarze
39aede77f0 For now, it can't be helped that mandoc tbl(7) ignores high-level macros,
but stop throwing away their arguments.  This fixes information loss in a
handful of Xenocara manuals, at the price of a small amount of formatting
noise creeping through.
2015-01-28 15:02:25 +00:00
schwarze
fd9b947ea2 Multiple parser and formatter fixes for line drawing in tbl(7).
* Allow mixing vertical line bars with the layout options
of the preceding layout cell.
* Correctly combine box options with layout lines.
* Correctly print vertical lines in data rows, with the right spacing.
* Correctly print cross markers and left and right ends of
horizontal lines even if vertical lines differ above and below.
* Avoid the bogus error message "no table data cells"
when a table data section starts with a horizontal line.
No increase in code size.
2015-01-27 05:20:30 +00:00
schwarze
17e372422b blank lines in tables do not need special handling; simplifies code
and reduces groff/mandoc differences in base by about 1%
2015-01-21 00:45:16 +00:00
schwarze
30997c59ae Add some missing OpenBSD RCS markers
and a few missing <sys/types.h> inclusions; no code change.
2014-11-28 19:25:03 +00:00
schwarze
0b2f1307db Audit strlcpy(3)/strlcat(3) usage.
* 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.
2014-04-23 16:07:06 +00:00
schwarze
49aff9f832 KNF: case (FOO): -> case FOO, remove /* LINTED */ and /* ARGSUSED */,
remove trailing whitespace and blanks before tabs, improve some indenting;
no functional change
2014-04-20 16:44:44 +00:00
schwarze
4f4f797233 The files mandoc.c and mandoc.h contained both specialised low-level
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-21 22:17:01 +00:00
schwarze
6ff6a9aa19 Merge NetBSD rev. 1.4:
Rename static function data() to getdata()
to work around bugs in the NetBSD PPC64 toolchain.
Original author of the patch: Christos Zoulas <christos@NetBSD>.
Received via Joerg Sonnenberger <joerg@NetBSD>.
2014-01-05 21:02:43 +00:00
schwarze
fb4e135051 If a table contained at least one complete line
and on its last line, the first T{ remained unclosed,
roff_parseln() never returned ROFF_TBL for that last line,
so {man,mdoc}_addspan() never got called for that last line,
so we ended up with a table
where no line associated with a node had TBL_SPAN_LAST set,
so tbl_term() never free()'d the cols in struct roffcol,
so tblcalc() crashed on the NULL == tbl->cols assertion
when starting the *next* table in the same file.

Fix this by returning ROFF_TBL as soon as we open a data cell,
not only when finishing it - as explained above, it may never
get properly closed but instead be interrupted by .TE.

Problem reported by bentley@ in latex2man.1.

I love it when bugs take half a day to debug but
the fix turns out to be flipping one single bit in the source code.
2013-06-01 04:56:41 +00:00
schwarze
c7497e73a9 The name "struct tbl" was badly misleading for two reasons:
1) This struct almost exclusively contains the table options.
2) Information about the table as a whole is actually in "struct tbl_node".
Besides, "struct tbl" was almost impossible to search for.
So rename it to "struct tbl_opts".  No functional change.
2013-05-31 21:37:08 +00:00
schwarze
3006448a3a Do not handle vertical lines as additional tbl(7) columns,
instead save their properties with the following column.
This simplifies layout parsing and saves a lot of code
related to column handling.

At output time, print all white space and vertical lines
separating columns before printing the following column,
and none after printing the preceding column, considerably
simplifying white space handling and width calculations.

No functional change, but it saves 150 lines of code,
and it allows the next patch to tbl_term.c, tbl_literal().
2012-05-26 20:03:34 +00:00
schwarze
a35fc07a7b Merge version 1.11.1:
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-24 16:22:02 +00:00
schwarze
19a69263bb Merge version 1.10.10:
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-04-21 22:59:54 +00:00
schwarze
2733b5d3e4 Tbl code maintenance by kristaps@.
- Remember the line-number of a tbl_span, and use it in messages.
- Put *_span_alloc() functions right into the *_addspan() ones,
  since these are the only places they are called from.
2011-02-10 00:06:30 +00:00
schwarze
7374e4fe2e Since tbl_data() can now produce multiple spans, let parsebuf()
generate man(7) or mdoc(7) nodes for all these spans,
not only for the last one.
Restores the horizontal lines in the cpu(4/hppa) tables.
ok kristaps@
2011-01-25 12:24:26 +00:00
schwarze
a7f5ddf902 Do not skip data after horizontal lines in the layout.
Instead, let one line of input data add two new spans
to the tbl tree during one single call of tbl_data().
Note that this causes the horizontal line to get parsed
into the tbl tree, but not yet used in the output,
which will be fixed next.
Avoids data loss in cpu(4/hppa).
ok kristaps@
2011-01-25 12:16:19 +00:00
schwarze
8351ebcfb4 Various tbl improvements from kristaps@:
* horizontal lines do not consume layout lines
* skip excessive data cells
* prepare rendering of spanned cells
* support vertical spans
2011-01-16 01:11:50 +00:00
schwarze
ec04407b0d Sync tbl handling to bsd.lv release 1.10.9:
* .T} can be followed by a delimiter, then more data.
* Do not limit table column widths (improves terminfo(5)).
* Let numerical cells respect explicitly specified minimum cell widths.
* Let terminal output survive missing data cells.
* Parse and ignore arguments in parentheses on layout cell specifications.
* Move tbl_calc() into out.c such that it can be used by all frontends.
* Give tables an HTML class.
* Some cleanup in tbl -Thtml code.
All code by kristaps@.
2011-01-09 14:30:48 +00:00
schwarze
2791bd1c99 Merge kristaps@' cleaner tbl integration, removing mine;
there are still a few bugs, but fixing these will be easier in tree.
2011-01-04 22:28:17 +00:00
schwarze
4ae97e2f31 Allow blank lines and ignore comments in tbl data.
This finally allows terminfo(5) to build.
Now we can build all man(7)-tbl(1) in base without loss of information,
though some still look ugly.
2010-10-15 23:19:40 +00:00
schwarze
c37b59270e Move tbl output from plain stdio to mandoc terminal output routines.
This fixes (1) all escape sequences and (2) some aspects of indentation.
Table column widths are still way off, though.
"move forward" deraadt@
2010-10-15 21:33:47 +00:00
schwarze
393cb51e9a Import tbl parser and renderer written by kristaps@.
Unchanged code from bsd.lv release 0.1.5, but without the main program.
Not yet linked to the build; next commit will integrate it into mandoc.
2010-10-15 19:20:03 +00:00