-/* $Id: main.c,v 1.164 2011/09/17 15:00:51 schwarze Exp $ */
+/* $Id: main.c,v 1.165 2011/10/06 22:29:12 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp);
+ /*
+ * Conditionally start up the lookaside buffer before parsing.
+ */
+ if (OUTT_MAN == curp.outtype)
+ mparse_keep(curp.mp);
+
argc -= optind;
argv += optind;
break;
case (OUTT_MAN):
curp->outmdoc = man_mdoc;
+ curp->outman = man_man;
break;
case (OUTT_PDF):
/* FALLTHROUGH */
-/* $Id: main.h,v 1.14 2011/09/18 14:14:15 schwarze Exp $ */
+/* $Id: main.h,v 1.15 2011/10/06 22:29:12 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
void tree_man(void *, const struct man *);
void man_mdoc(void *, const struct mdoc *);
+void man_man(void *, const struct man *);
void *locale_alloc(char *);
void *utf8_alloc(char *);
-/* $Id: man.c,v 1.111 2011/07/28 14:17:11 kristaps Exp $ */
+/* $Id: man.c,v 1.112 2011/10/06 22:29:12 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
if (m && m->first == n)
m->first = NULL;
}
+
+const struct mparse *
+man_mparse(const struct man *m)
+{
+
+ assert(m && m->parse);
+ return(m->parse);
+}
-/* $Id: man.h,v 1.58 2011/03/23 12:33:01 kristaps Exp $ */
+/* $Id: man.h,v 1.59 2011/10/06 22:29:12 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
const struct man_node *man_node(const struct man *);
const struct man_meta *man_meta(const struct man *);
+const struct mparse *man_mparse(const struct man *);
__END_DECLS
-.\" $Id: mandoc.1,v 1.94 2011/10/05 21:35:17 kristaps Exp $
+.\" $Id: mandoc.1,v 1.95 2011/10/06 22:29:12 kristaps Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: October 5 2011 $
+.Dd $Mdocdate: October 6 2011 $
.Dt MANDOC 1
.Os
.Sh NAME
See
.Sx Locale Output .
.It Fl T Ns Cm man
-Produce output in
+Produce
.Xr man 7
-format; only useful when applied to
-.Fl m Ns Cm doc
-input.
+format output.
+See
+.Sx Man Output .
.It Fl T Ns Cm pdf
Produce PDF output.
See
See
.Sx ASCII Output
for font style specification and available command-line arguments.
+.Ss Man Output
+Translate input format into
+.Xr man 7
+output format.
+This is useful for distributing manual sources to legancy systems
+lacking
+.Xr mdoc 7
+formatters.
+.Pp
+If
+.Xr mdoc 7
+is passed as input, it is translated into
+.Xr man 7 ;
+if the input format is
+.Xr man 7 ,
+it is parsed and re-outputted.
+In either case, the
+.Xr roff 7
+.Sq so
+macros are processed prior to producing output.
.Ss PDF Output
PDF-1.1 output may be generated by
.Fl T Ns Cm pdf .
-.\" $Id: mandoc.3,v 1.13 2011/08/18 08:58:44 kristaps Exp $
+.\" $Id: mandoc.3,v 1.14 2011/10/06 22:29:12 kristaps Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: August 18 2011 $
+.Dd $Mdocdate: October 6 2011 $
.Dt MANDOC 3
.Os
.Sh NAME
.Nm mandoc ,
.Nm mandoc_escape ,
.Nm man_meta ,
+.Nm man_mparse ,
.Nm man_node ,
.Nm mchars_alloc ,
.Nm mchars_free ,
.Nm mdoc_node ,
.Nm mparse_alloc ,
.Nm mparse_free ,
+.Nm mparse_getkeep ,
+.Nm mparse_keep ,
.Nm mparse_readfd ,
.Nm mparse_reset ,
.Nm mparse_result ,
.Fo man_meta
.Fa "const struct man *man"
.Fc
+.Ft "const struct mparse *"
+.Fo man_mparse
+.Fa "const struct man *man"
+.Fc
.Ft "const struct man_node *"
.Fo man_node
.Fa "const struct man *man"
.Fo mparse_free
.Fa "struct mparse *parse"
.Fc
+.Ft void
+.Fo mparse_getkeep
+.Fa "const struct mparse *parse"
+.Fc
+.Ft void
+.Fo mparse_keep
+.Fa "struct mparse *parse"
+.Fc
.Ft "enum mandoclevel"
.Fo mparse_readfd
.Fa "struct mparse *parse"
Obtain the meta-data of a successful parse.
This may only be used on a pointer returned by
.Fn mparse_result .
+.It Fn man_mparse
+Get the parser used for the current output.
.It Fn man_node
Obtain the root node of a successful parse.
This may only be used on a pointer returned by
.It Fn mparse_free
Free all memory allocated by
.Fn mparse_alloc .
+.It Fn mparse_getkeep
+Acquire the keep buffer.
+Must follow a call of
+.Fn mparse_keep .
+.It Fn mparse_keep
+Instruct the parser to retain a copy of its parsed input.
+This can be acquired with subsequent
+.Fn mparse_getkeep
+calls.
.It Fn mparse_readfd
Parse a file or file descriptor.
If
-/* $Id: mandoc.h,v 1.95 2011/07/23 18:44:42 kristaps Exp $ */
+/* $Id: mandoc.h,v 1.96 2011/10/06 22:29:12 kristaps Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
__BEGIN_DECLS
-void mparse_free(struct mparse *);
-void mparse_reset(struct mparse *);
-struct mparse *mparse_alloc(enum mparset,
- enum mandoclevel, mandocmsg, void *);
-enum mandoclevel mparse_readfd(struct mparse *, int, const char *);
-void mparse_result(struct mparse *, struct mdoc **, struct man **);
-const char *mparse_strerror(enum mandocerr);
-const char *mparse_strlevel(enum mandoclevel);
-
void *mandoc_calloc(size_t, size_t);
+enum mandoc_esc mandoc_escape(const char **, const char **, int *);
void *mandoc_malloc(size_t);
void *mandoc_realloc(void *, size_t);
char *mandoc_strdup(const char *);
char *mandoc_strndup(const char *, size_t);
-
-enum mandoc_esc mandoc_escape(const char **, const char **, int *);
-
struct mchars *mchars_alloc(void);
+void mchars_free(struct mchars *);
char mchars_num2char(const char *, size_t);
int mchars_num2uc(const char *, size_t);
-const char *mchars_spec2str(struct mchars *, const char *, size_t, size_t *);
-int mchars_spec2cp(struct mchars *, const char *, size_t);
-void mchars_free(struct mchars *);
-
+int mchars_spec2cp(struct mchars *,
+ const char *, size_t);
+const char *mchars_spec2str(struct mchars *,
+ const char *, size_t, size_t *);
+struct mparse *mparse_alloc(enum mparset,
+ enum mandoclevel, mandocmsg, void *);
+void mparse_free(struct mparse *);
+void mparse_keep(struct mparse *);
+enum mandoclevel mparse_readfd(struct mparse *, int, const char *);
+void mparse_reset(struct mparse *);
+void mparse_result(struct mparse *,
+ struct mdoc **, struct man **);
+const char *mparse_getkeep(const struct mparse *);
+const char *mparse_strerror(enum mandocerr);
+const char *mparse_strlevel(enum mandoclevel);
__END_DECLS
-/* $Id: mdoc_man.c,v 1.3 2011/09/30 00:13:28 schwarze Exp $ */
+/* $Id: mdoc_man.c,v 1.4 2011/10/06 22:29:12 kristaps Exp $ */
/*
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
*
#include <string.h>
#include "mandoc.h"
+#include "man.h"
#include "mdoc.h"
#include "main.h"
}
}
+void
+man_man(void *arg, const struct man *man)
+{
+
+ fputs(mparse_getkeep(man_mparse(man)), stdout);
+}
+
void
man_mdoc(void *arg, const struct mdoc *mdoc)
{
-/* $Id: read.c,v 1.23 2011/07/23 18:41:18 kristaps Exp $ */
+/* $Id: read.c,v 1.24 2011/10/06 22:29:12 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
mandocmsg mmsg; /* warning/error message handler */
void *arg; /* argument to mmsg */
const char *file;
+ struct buf *secondary;
};
static void resize_buf(struct buf *, size_t);
of = 0;
+ /*
+ * Maintain a lookaside buffer of all parsed lines. We
+ * only do this if mparse_keep() has been invoked (the
+ * buffer may be accessed with mparse_getkeep()).
+ */
+
+ if (curp->secondary) {
+ curp->secondary->buf =
+ mandoc_realloc
+ (curp->secondary->buf,
+ curp->secondary->sz + pos + 2);
+ memcpy(curp->secondary->buf +
+ curp->secondary->sz,
+ ln.buf, pos);
+ curp->secondary->sz += pos;
+ curp->secondary->buf
+ [curp->secondary->sz] = '\n';
+ curp->secondary->sz++;
+ curp->secondary->buf
+ [curp->secondary->sz] = '\0';
+ }
rerun:
rr = roff_parseln
(curp->roff, curp->line,
assert(MANDOCLEVEL_FATAL <= curp->file_status);
break;
case (ROFF_SO):
+ /*
+ * We remove `so' clauses from our lookaside
+ * buffer because we're going to descend into
+ * the file recursively.
+ */
+ curp->secondary->sz -= pos + 1;
mparse_readfd_r(curp, -1, ln.buf + of, 1);
if (MANDOCLEVEL_FATAL <= curp->file_status)
break;
mdoc_reset(curp->mdoc);
if (curp->man)
man_reset(curp->man);
+ if (curp->secondary)
+ curp->secondary->sz = 0;
curp->file_status = MANDOCLEVEL_OK;
curp->mdoc = NULL;
man_free(curp->pman);
if (curp->roff)
roff_free(curp->roff);
+ if (curp->secondary)
+ free(curp->secondary->buf);
+ free(curp->secondary);
free(curp);
}
{
return(mandoclevels[lvl]);
}
+
+void
+mparse_keep(struct mparse *p)
+{
+
+ assert(NULL == p->secondary);
+ p->secondary = mandoc_calloc(1, sizeof(struct buf));
+}
+
+const char *
+mparse_getkeep(const struct mparse *p)
+{
+
+ assert(p->secondary);
+ return(p->secondary->sz ? p->secondary->buf : NULL);
+}