-/* $OpenBSD: libman.h,v 1.49 2015/04/19 13:50:10 schwarze Exp $ */
+/* $OpenBSD: libman.h,v 1.50 2015/04/19 14:25:05 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
__BEGIN_DECLS
-void man_word_alloc(struct roff_man *, int, int, const char *);
-void man_word_append(struct roff_man *, const char *);
void man_block_alloc(struct roff_man *, int, int, int);
void man_elem_alloc(struct roff_man *, int, int, int);
int man_hash_find(const char *);
-/* $OpenBSD: libmandoc.h,v 1.45 2015/04/19 13:50:10 schwarze Exp $ */
+/* $OpenBSD: libmandoc.h,v 1.46 2015/04/19 14:25:05 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
void mdoc_hash_init(void);
int mdoc_parseln(struct roff_man *, int, char *, int);
void mdoc_endparse(struct roff_man *);
-void mdoc_addspan(struct roff_man *, const struct tbl_span *);
-void mdoc_addeqn(struct roff_man *, const struct eqn *);
void man_hash_init(void);
int man_parseln(struct roff_man *, int, char *, int);
void man_endparse(struct roff_man *);
-void man_addspan(struct roff_man *, const struct tbl_span *);
-void man_addeqn(struct roff_man *, const struct eqn *);
int preconv_cue(const struct buf *, size_t);
int preconv_encode(struct buf *, size_t *,
-/* $OpenBSD: libmdoc.h,v 1.74 2015/04/19 13:50:10 schwarze Exp $ */
+/* $OpenBSD: libmdoc.h,v 1.75 2015/04/19 14:25:05 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
__BEGIN_DECLS
void mdoc_macro(MACRO_PROT_ARGS);
-void mdoc_word_alloc(struct roff_man *, int, int, const char *);
-void mdoc_word_append(struct roff_man *, const char *);
void mdoc_elem_alloc(struct roff_man *, int, int,
int, struct mdoc_arg *);
struct roff_node *mdoc_block_alloc(struct roff_man *, int, int,
const char *mdoc_a2att(const char *);
const char *mdoc_a2st(const char *);
const char *mdoc_a2arch(const char *);
-void mdoc_valid_pre(struct roff_man *, struct roff_node *);
-void mdoc_valid_post(struct roff_man *);
void mdoc_argv(struct roff_man *, int, int,
struct mdoc_arg **, int *, char *);
-void mdoc_argv_free(struct mdoc_arg *);
enum margserr mdoc_args(struct roff_man *, int,
int *, char *, int, char **);
void mdoc_macroend(struct roff_man *);
-/* $OpenBSD: man.c,v 1.107 2015/04/19 13:59:37 schwarze Exp $ */
+/* $OpenBSD: man.c,v 1.108 2015/04/19 14:25:05 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
const char * const *man_macronames = __man_macronames;
-static void man_breakscope(struct roff_man *, int);
static void man_descope(struct roff_man *, int, int);
static int man_ptext(struct roff_man *, int, char *, int);
static int man_pmacro(struct roff_man *, int, char *, int);
man->next = ROFF_NEXT_CHILD;
}
-void
-man_word_alloc(struct roff_man *man, int line, int pos, const char *word)
-{
- struct roff_node *n;
-
- n = roff_node_alloc(man, line, pos, ROFFT_TEXT, TOKEN_NONE);
- n->string = roff_strdup(man->roff, word);
- roff_node_append(man, n);
- man_valid_post(man);
- man->next = ROFF_NEXT_SIBLING;
-}
-
-void
-man_word_append(struct roff_man *man, const char *word)
-{
- struct roff_node *n;
- char *addstr, *newstr;
-
- n = man->last;
- addstr = roff_strdup(man->roff, word);
- mandoc_asprintf(&newstr, "%s %s", n->string, addstr);
- free(addstr);
- free(n->string);
- n->string = newstr;
- man->next = ROFF_NEXT_SIBLING;
-}
-
-void
-man_addeqn(struct roff_man *man, const struct eqn *ep)
-{
- struct roff_node *n;
-
- n = roff_node_alloc(man, ep->ln, ep->pos, ROFFT_EQN, TOKEN_NONE);
- n->eqn = ep;
- if (ep->ln > man->last->line)
- n->flags |= MAN_LINE;
- roff_node_append(man, n);
- man->next = ROFF_NEXT_SIBLING;
- man_descope(man, ep->ln, ep->pos);
-}
-
-void
-man_addspan(struct roff_man *man, const struct tbl_span *sp)
-{
- struct roff_node *n;
-
- man_breakscope(man, TOKEN_NONE);
- n = roff_node_alloc(man, sp->line, 0, ROFFT_TBL, TOKEN_NONE);
- n->span = sp;
- roff_node_append(man, n);
- man_valid_post(man);
- man->next = ROFF_NEXT_SIBLING;
- man_descope(man, sp->line, 0);
-}
-
static void
man_descope(struct roff_man *man, int line, int offs)
{
/* Literal free-form text whitespace is preserved. */
if (man->flags & MAN_LITERAL) {
- man_word_alloc(man, line, offs, buf + offs);
+ roff_word_alloc(man, line, offs, buf + offs);
man_descope(man, line, offs);
return(1);
}
buf[i] = '\0';
}
- man_word_alloc(man, line, offs, buf + offs);
+ roff_word_alloc(man, line, offs, buf + offs);
/*
* End-of-sentence check. If the last character is an unescaped
-/* $OpenBSD: man_macro.c,v 1.68 2015/04/19 13:50:10 schwarze Exp $ */
+/* $OpenBSD: man_macro.c,v 1.69 2015/04/19 14:25:05 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2012, 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
la = *pos;
if (man_args(man, line, pos, buf, &p))
- man_word_alloc(man, line, la, p);
+ roff_word_alloc(man, line, la, p);
if (buf[*pos] != '\0')
mandoc_vmsg(MANDOCERR_ARG_EXCESS,
la = *pos;
if ( ! man_args(man, line, pos, buf, &p))
break;
- man_word_alloc(man, line, la, p);
+ roff_word_alloc(man, line, la, p);
}
/*
break;
if (man_macros[tok].flags & MAN_JOIN &&
man->last->type == ROFFT_TEXT)
- man_word_append(man, p);
+ roff_word_append(man, p);
else
- man_word_alloc(man, line, la, p);
+ roff_word_alloc(man, line, la, p);
}
/*
-/* $OpenBSD: mdoc.c,v 1.137 2015/04/19 13:59:37 schwarze Exp $ */
+/* $OpenBSD: mdoc.c,v 1.138 2015/04/19 14:25:05 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
mdoc_macroend(mdoc);
}
-void
-mdoc_addeqn(struct roff_man *mdoc, const struct eqn *ep)
-{
- struct roff_node *n;
-
- n = roff_node_alloc(mdoc, ep->ln, ep->pos, ROFFT_EQN, TOKEN_NONE);
- n->eqn = ep;
- if (ep->ln > mdoc->last->line)
- n->flags |= MDOC_LINE;
- roff_node_append(mdoc, n);
- mdoc->next = ROFF_NEXT_SIBLING;
-}
-
-void
-mdoc_addspan(struct roff_man *mdoc, const struct tbl_span *sp)
-{
- struct roff_node *n;
-
- n = roff_node_alloc(mdoc, sp->line, 0, ROFFT_TBL, TOKEN_NONE);
- n->span = sp;
- roff_node_append(mdoc, n);
- mdoc_valid_post(mdoc);
- mdoc->next = ROFF_NEXT_SIBLING;
-}
-
/*
* Main parse routine. Parses a single line -- really just hands off to
* the macro (mdoc_pmacro()) or text parser (mdoc_ptext()).
mdoc->next = ROFF_NEXT_CHILD;
}
-void
-mdoc_word_alloc(struct roff_man *mdoc, int line, int pos, const char *p)
-{
- struct roff_node *n;
-
- n = roff_node_alloc(mdoc, line, pos, ROFFT_TEXT, TOKEN_NONE);
- n->string = roff_strdup(mdoc->roff, p);
- roff_node_append(mdoc, n);
- mdoc_valid_post(mdoc);
- mdoc->next = ROFF_NEXT_SIBLING;
-}
-
-void
-mdoc_word_append(struct roff_man *mdoc, const char *p)
-{
- struct roff_node *n;
- char *addstr, *newstr;
-
- n = mdoc->last;
- addstr = roff_strdup(mdoc->roff, p);
- mandoc_asprintf(&newstr, "%s %s", n->string, addstr);
- free(addstr);
- free(n->string);
- n->string = newstr;
- mdoc->next = ROFF_NEXT_SIBLING;
-}
-
void
mdoc_node_relink(struct roff_man *mdoc, struct roff_node *p)
{
return(1);
}
- mdoc_word_alloc(mdoc, line, offs, buf+offs);
+ roff_word_alloc(mdoc, line, offs, buf+offs);
if (mdoc->flags & MDOC_LITERAL)
return(1);
-/* $OpenBSD: mdoc_macro.c,v 1.147 2015/04/19 13:59:37 schwarze Exp $ */
+/* $OpenBSD: mdoc_macro.c,v 1.148 2015/04/19 14:25:05 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
! (mdoc->flags & (MDOC_SYNOPSIS | MDOC_KEEP | MDOC_SMOFF)) &&
d == DELIM_NONE && mdoc->last->type == ROFFT_TEXT &&
mdoc_isdelim(mdoc->last->string) == DELIM_NONE) {
- mdoc_word_append(mdoc, p);
+ roff_word_append(mdoc, p);
return;
}
- mdoc_word_alloc(mdoc, line, col, p);
+ roff_word_alloc(mdoc, line, col, p);
/*
* If the word consists of a bare delimiter,
-/* $OpenBSD: mdoc_validate.c,v 1.204 2015/04/19 13:59:37 schwarze Exp $ */
+/* $OpenBSD: mdoc_validate.c,v 1.205 2015/04/19 14:25:05 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
switch (nn->tok) {
case MDOC_Ar:
- mdoc_word_alloc(mdoc, nn->line, nn->pos, "file");
- mdoc_word_alloc(mdoc, nn->line, nn->pos, "...");
+ roff_word_alloc(mdoc, nn->line, nn->pos, "file");
+ roff_word_alloc(mdoc, nn->line, nn->pos, "...");
break;
case MDOC_Pa:
/* FALLTHROUGH */
case MDOC_Mt:
- mdoc_word_alloc(mdoc, nn->line, nn->pos, "~");
+ roff_word_alloc(mdoc, nn->line, nn->pos, "~");
break;
default:
abort();
n = mdoc->last;
if (n->child == NULL) {
mdoc->next = ROFF_NEXT_CHILD;
- mdoc_word_alloc(mdoc, n->line, n->pos, "AT&T UNIX");
+ roff_word_alloc(mdoc, n->line, n->pos, "AT&T UNIX");
mdoc->last = n;
return;
}
}
mdoc->next = ROFF_NEXT_CHILD;
- mdoc_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name);
+ roff_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name);
mdoc->last = n;
}
-/* $OpenBSD: read.c,v 1.113 2015/04/19 13:59:37 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.114 2015/04/19 14:25:05 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
#include "mdoc.h"
#include "man.h"
#include "libmandoc.h"
+#include "roff_int.h"
#define REPARSE_LIMIT 1000
* Do the same for ROFF_EQN.
*/
- if (rr == ROFF_TBL) {
+ if (rr == ROFF_TBL)
while ((span = roff_span(curp->roff)) != NULL)
- if (curp->man->macroset == MACROSET_MDOC)
- mdoc_addspan(curp->man, span);
- else
- man_addspan(curp->man, span);
- } else if (rr == ROFF_EQN) {
- if (curp->man->macroset == MACROSET_MDOC)
- mdoc_addeqn(curp->man, roff_eqn(curp->roff));
- else
- man_addeqn(curp->man, roff_eqn(curp->roff));
- } else if ((curp->man->macroset == MACROSET_MDOC ?
+ roff_addtbl(curp->man, span);
+ else if (rr == ROFF_EQN)
+ roff_addeqn(curp->man, roff_eqn(curp->roff));
+ else if ((curp->man->macroset == MACROSET_MDOC ?
mdoc_parseln(curp->man, curp->line, ln.buf, of) :
man_parseln(curp->man, curp->line, ln.buf, of)) == 2)
break;
-/* $OpenBSD: roff.c,v 1.138 2015/04/19 13:50:10 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.139 2015/04/19 14:25:05 schwarze Exp $ */
/*
- * Copyright (c) 2009-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
#include "libmandoc.h"
#include "roff_int.h"
#include "libroff.h"
-#include "libmdoc.h"
/* Maximum number of nested if-else conditionals. */
#define RSTACK_MAX 128
man->last = n;
}
+void
+roff_word_alloc(struct roff_man *man, int line, int pos, const char *word)
+{
+ struct roff_node *n;
+
+ n = roff_node_alloc(man, line, pos, ROFFT_TEXT, TOKEN_NONE);
+ n->string = roff_strdup(man->roff, word);
+ roff_node_append(man, n);
+ if (man->macroset == MACROSET_MDOC)
+ mdoc_valid_post(man);
+ else
+ man_valid_post(man);
+ man->next = ROFF_NEXT_SIBLING;
+}
+
+void
+roff_word_append(struct roff_man *man, const char *word)
+{
+ struct roff_node *n;
+ char *addstr, *newstr;
+
+ n = man->last;
+ addstr = roff_strdup(man->roff, word);
+ mandoc_asprintf(&newstr, "%s %s", n->string, addstr);
+ free(addstr);
+ free(n->string);
+ n->string = newstr;
+ man->next = ROFF_NEXT_SIBLING;
+}
+
struct roff_node *
roff_head_alloc(struct roff_man *man, int line, int pos, int tok)
{
return(n);
}
+void
+roff_addeqn(struct roff_man *man, const struct eqn *eqn)
+{
+ struct roff_node *n;
+
+ n = roff_node_alloc(man, eqn->ln, eqn->pos, ROFFT_EQN, TOKEN_NONE);
+ n->eqn = eqn;
+ if (eqn->ln > man->last->line)
+ n->flags |= MDOC_LINE;
+ roff_node_append(man, n);
+ man->next = ROFF_NEXT_SIBLING;
+}
+
+void
+roff_addtbl(struct roff_man *man, const struct tbl_span *tbl)
+{
+ struct roff_node *n;
+
+ if (man->macroset == MACROSET_MAN)
+ man_breakscope(man, TOKEN_NONE);
+ n = roff_node_alloc(man, tbl->line, 0, ROFFT_TBL, TOKEN_NONE);
+ n->span = tbl;
+ roff_node_append(man, n);
+ if (man->macroset == MACROSET_MDOC)
+ mdoc_valid_post(man);
+ else
+ man_valid_post(man);
+ man->next = ROFF_NEXT_SIBLING;
+}
+
void
roff_node_unlink(struct roff_man *man, struct roff_node *n)
{
-/* $OpenBSD: roff_int.h,v 1.1 2015/04/19 13:50:10 schwarze Exp $ */
+/* $OpenBSD: roff_int.h,v 1.2 2015/04/19 14:25:05 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
struct roff_node *roff_node_alloc(struct roff_man *, int, int,
enum roff_type, int);
void roff_node_append(struct roff_man *, struct roff_node *);
+void roff_word_alloc(struct roff_man *, int, int, const char *);
+void roff_word_append(struct roff_man *, const char *);
struct roff_node *roff_head_alloc(struct roff_man *, int, int, int);
struct roff_node *roff_body_alloc(struct roff_man *, int, int, int);
+void roff_addeqn(struct roff_man *, const struct eqn *);
+void roff_addtbl(struct roff_man *, const struct tbl_span *);
void roff_node_unlink(struct roff_man *, struct roff_node *);
void roff_node_free(struct roff_node *);
void roff_node_delete(struct roff_man *, struct roff_node *);
+/*
+ * Functions called from roff.c need to be declared here,
+ * not in libmdoc.h or libman.h, even if they are specific
+ * to either the mdoc(7) or the man(7) parser.
+ */
+
+void man_breakscope(struct roff_man *, int);
+void man_valid_post(struct roff_man *);
+
+void mdoc_valid_pre(struct roff_man *, struct roff_node *);
+void mdoc_valid_post(struct roff_man *);
+void mdoc_argv_free(struct mdoc_arg *);
+
__END_DECLS