[BACK]Return to Makefile CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

File: [local] / src / usr.bin / mandoc / Makefile (download)

Revision 1.119, Thu May 19 15:17:50 2022 UTC (2 years ago) by schwarze
Branch: MAIN
Changes since 1.118: +3 -2 lines

Make roff_expand() parse left-to-right rather than right-to-left.
Some escape sequences have side effects on global state, implying
that the order of evaluation matters.  For example, this fixes the
long-standing bug that "\n+x\n+x\n+x" after ".nr x 0 1" used to
print "321"; now it correctly prints "123".

Right-to-left parsing was convenient because it implicitly handled
nested escape sequences.  With correct left-to-right parsing, nesting
now requires an explicit implementation, here solved as follows:
1. Handle nested expanding escape sequences iteratively.
When finding one, expand it, then retry parsing the enclosing escape
sequence from the beginning, which will ultimately succeed as soon
as it no longer contains any nested expanding escape sequences.
2. Handle nested non-expanding escape sequences recursively.
When finding one, the escape sequence parser calls itself to find
the end of the inner sequence, then continues parsing the outer
sequence after that point.

This requires the mandoc_escape() function to operate in two different
modes.  The roff(7) parser uses it in a mode where it generates
diagnostics and may return an expansion request instead of a parse
result.  All other callers, in particular the formatters, use it
in a simpler mode that never generates diagnostics and always returns
a definite parsing result, but that requires all expanding escape
sequences to already have been expanded earlier.  The bulk of the
code is the same for both modes.
Since this required a major rewrite of the function anyway, move
it into its own new file roff_escape.c and out of the file mandoc.c,
which was misnamed in the first place and lacks a clear focus.

As a side benefit, this also fixes a number of assertion failures
that tb@ found with afl(1), for example "\n\\\\*0", "\v\-\\*0",
and "\w\-\\\\\$0*0".

As another side benefit, it also resolves some code duplication
between mandoc_escape() and roff_expand() and centralizes all
handling of escape sequences (except for expansion) in roff_escape.c,
hopefully easing maintenance and feature improvements in the future.

While here, also move end-of-input handling out of the complicated
function roff_expand() and into the simpler function roff_parse_comment(),
making the logic easier to understand.

Since this is a major reorganization of a central component of
mandoc(1), stability of the program might slightly suffer for a few
weeks, but i believe that's not a problem at this point of the
release cycle.  The new code already satisfies the regression suite,
but more tweaking and regression testing to further improve the
handling of various escape sequences will likely follow in the near
future.

# $OpenBSD: Makefile,v 1.119 2022/05/19 15:17:50 schwarze Exp $

.include <bsd.own.mk>

CFLAGS  += -W -Wall -Wstrict-prototypes -Wno-unused-parameter
DPADD	+= ${LIBUTIL}
LDADD	+= -lutil -lz

SRCS=	mandoc_aux.c mandoc_ohash.c mandoc.c mandoc_msg.c mandoc_xr.c \
	arch.c chars.c msec.c preconv.c read.c tag.c
SRCS+=	roff.c roff_escape.c roff_validate.c
SRCS+=	tbl.c tbl_opts.c tbl_layout.c tbl_data.c eqn.c
SRCS+=	mdoc.c mdoc_argv.c mdoc_macro.c mdoc_state.c mdoc_validate.c \
	att.c st.c
SRCS+=	man_macro.c man.c man_validate.c
SRCS+=	main.c out.c tree.c
SRCS+=	term.c term_ascii.c term_ps.c term_tab.c term_tag.c
SRCS+=	roff_term.c mdoc_term.c man_term.c eqn_term.c tbl_term.c
SRCS+=	mdoc_man.c
SRCS+=	html.c roff_html.c mdoc_html.c man_html.c eqn_html.c tbl_html.c
SRCS+=	mdoc_markdown.c
SRCS+=	dbm_map.c dbm.c dba_write.c dba_array.c dba.c dba_read.c
SRCS+=	manpath.c mandocdb.c mansearch.c

PROG=	mandoc

LINKS =	${BINDIR}/mandoc ${BINDIR}/apropos \
	${BINDIR}/mandoc ${BINDIR}/help \
	${BINDIR}/mandoc ${BINDIR}/man \
	${BINDIR}/mandoc ${BINDIR}/whatis \
	${BINDIR}/mandoc /usr/sbin/makewhatis \
	${BINDIR}/mandoc /usr/libexec/makewhatis

MAN =	apropos.1 man.1 mandoc.1 man.conf.5 makewhatis.8

CLEANFILES += man.cgi cgi.o

afterinstall:
	install -o ${BINOWN} -g ${BINGRP} -m 444 \
	    ${.CURDIR}/mandoc.css ${DESTDIR}/usr/share/misc


# ----------------------------------------------------------------------
# Variables and targets to build and install man.cgi(8),
# not used during make build and make release.

# To configure, run:	cp cgi.h.example cgi.h; vi cgi.h
# To build, run:	make man.cgi
# To install, run:	sudo make installcgi
# After that, read:	man man.cgi.8

LIBMDOC_OBJS =	mdoc_argv.o mdoc_macro.o mdoc_state.o \
		mdoc_validate.o mdoc.o att.o st.o
LIBMAN_OBJS =	man.o man_macro.o man_validate.o
LIBROFF_OBJS =	roff.o roff_validate.o eqn.o \
		tbl.o tbl_data.o tbl_layout.o tbl_opts.o
LIBMANDOC_OBJS = ${LIBMDOC_OBJS} ${LIBMAN_OBJS} ${LIBROFF_OBJS} \
		arch.o mandoc.o mandoc_aux.o mandoc_msg.o mandoc_ohash.o \
		mandoc_xr.o chars.o msec.o preconv.o read.o tag.o
HTML_OBJS =	html.o roff_html.o mdoc_html.o man_html.o \
		tbl_html.o eqn_html.o out.o
CGI_OBJS =	${LIBMANDOC_OBJS} ${HTML_OBJS} \
		dbm_map.o dbm.o mansearch.o cgi.o

cgi.o: cgi.h main.h manconf.h mandoc.h mandoc_aux.h mandoc_parse.h \
	mansearch.h man.h mdoc.h roff.h

man.cgi: ${CGI_OBJS}
	${CC} ${LDFLAGS} ${STATIC} -o ${.TARGET} ${CGI_OBJS} ${LDADD}

installcgi: man.cgi
	${INSTALL} -d -o root -g wheel -m 755 ${DESTDIR}/var/www/cgi-bin
	${INSTALL} ${INSTALL_COPY} ${INSTALL_STRIP} \
	    -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
	    man.cgi ${DESTDIR}/var/www/cgi-bin/man.cgi
	${INSTALL} ${INSTALL_COPY} -o root -g wheel -m 644 \
	    ${.CURDIR}/mandoc.css ${DESTDIR}/var/www/htdocs/

.include <bsd.prog.mk>