version 1.76, 2010/06/19 20:46:28 |
version 1.92, 2010/12/08 10:58:22 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
|
#include <stdarg.h> |
#include <stdarg.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |
Line 37 const char *const __man_macronames[MAN_MAX] = { |
|
Line 36 const char *const __man_macronames[MAN_MAX] = { |
|
"IP", "HP", "SM", "SB", |
"IP", "HP", "SM", "SB", |
"BI", "IB", "BR", "RB", |
"BI", "IB", "BR", "RB", |
"R", "B", "I", "IR", |
"R", "B", "I", "IR", |
"RI", "na", "i", "sp", |
"RI", "na", "sp", "nf", |
"nf", "fi", "r", "RE", |
"fi", "RE", "RS", "DT", |
"RS", "DT", "UC", "PD", |
"UC", "PD", "AT", "in", |
"Sp", "Vb", "Ve", "AT", |
"ft" |
}; |
}; |
|
|
const char * const *man_macronames = __man_macronames; |
const char * const *man_macronames = __man_macronames; |
Line 56 static int man_ptext(struct man *, int, char *, int) |
|
Line 55 static int man_ptext(struct man *, int, char *, int) |
|
static int man_pmacro(struct man *, int, char *, int); |
static int man_pmacro(struct man *, int, char *, int); |
static void man_free1(struct man *); |
static void man_free1(struct man *); |
static void man_alloc1(struct man *); |
static void man_alloc1(struct man *); |
static int macrowarn(struct man *, int, const char *, int); |
|
|
|
|
|
const struct man_node * |
const struct man_node * |
Line 94 man_free(struct man *man) |
|
Line 92 man_free(struct man *man) |
|
|
|
|
|
struct man * |
struct man * |
man_alloc(void *data, int pflags, mandocmsg msg) |
man_alloc(struct regset *regs, void *data, mandocmsg msg) |
{ |
{ |
struct man *p; |
struct man *p; |
|
|
Line 102 man_alloc(void *data, int pflags, mandocmsg msg) |
|
Line 100 man_alloc(void *data, int pflags, mandocmsg msg) |
|
|
|
man_hash_init(); |
man_hash_init(); |
p->data = data; |
p->data = data; |
p->pflags = pflags; |
|
p->msg = msg; |
p->msg = msg; |
|
p->regs = regs; |
|
|
man_alloc1(p); |
man_alloc1(p); |
return(p); |
return(p); |
Line 217 man_node_append(struct man *man, struct man_node *p) |
|
Line 215 man_node_append(struct man *man, struct man_node *p) |
|
case (MAN_TEXT): |
case (MAN_TEXT): |
if ( ! man_valid_post(man)) |
if ( ! man_valid_post(man)) |
return(0); |
return(0); |
if ( ! man_action_post(man)) |
|
return(0); |
|
break; |
break; |
default: |
default: |
break; |
break; |
Line 407 man_ptext(struct man *m, int line, char *buf, int offs |
|
Line 403 man_ptext(struct man *m, int line, char *buf, int offs |
|
*/ |
*/ |
|
|
assert(i); |
assert(i); |
if (mandoc_eos(buf, (size_t)i)) |
if (mandoc_eos(buf, (size_t)i, 0)) |
m->last->flags |= MAN_EOS; |
m->last->flags |= MAN_EOS; |
|
|
descope: |
descope: |
|
|
} |
} |
|
|
|
|
static int |
|
macrowarn(struct man *m, int ln, const char *buf, int offs) |
|
{ |
|
int rc; |
|
|
|
rc = man_vmsg(m, MANDOCERR_MACRO, ln, offs, |
|
"unknown macro: %s%s", |
|
buf, strlen(buf) > 3 ? "..." : ""); |
|
|
|
return(MAN_IGN_MACRO & m->pflags ? rc : 0); |
|
} |
|
|
|
|
|
int |
int |
man_pmacro(struct man *m, int ln, char *buf, int offs) |
man_pmacro(struct man *m, int ln, char *buf, int offs) |
{ |
{ |
Line 478 man_pmacro(struct man *m, int ln, char *buf, int offs) |
|
Line 461 man_pmacro(struct man *m, int ln, char *buf, int offs) |
|
|
|
ppos = i; |
ppos = i; |
|
|
/* Copy the first word into a nil-terminated buffer. */ |
/* |
|
* Copy the first word into a nil-terminated buffer. |
|
* Stop copying when a tab, space, or eoln is encountered. |
|
*/ |
|
|
for (j = 0; j < 4; j++, i++) { |
j = 0; |
if ('\0' == (mac[j] = buf[i])) |
while (j < 4 && '\0' != buf[i] && ' ' != buf[i] && '\t' != buf[i]) |
break; |
mac[j++] = buf[i++]; |
else if (' ' == buf[i]) |
|
break; |
|
|
|
/* Check for invalid characters. */ |
|
|
|
if (isgraph((u_char)buf[i])) |
|
continue; |
|
if ( ! man_pmsg(m, ln, i, MANDOCERR_BADCHAR)) |
|
return(0); |
|
i--; |
|
} |
|
|
|
mac[j] = '\0'; |
mac[j] = '\0'; |
|
|
if (j == 4 || j < 1) { |
tok = (j > 0 && j < 4) ? man_hash_find(mac) : MAN_MAX; |
if ( ! macrowarn(m, ln, mac, ppos)) |
if (MAN_MAX == tok) { |
goto err; |
man_vmsg(m, MANDOCERR_MACRO, ln, ppos, "%s", buf + ppos - 1); |
return(1); |
return(1); |
} |
} |
|
|
if (MAN_MAX == (tok = man_hash_find(mac))) { |
|
if ( ! macrowarn(m, ln, mac, ppos)) |
|
goto err; |
|
return(1); |
|
} |
|
|
|
/* The macro is sane. Jump to the next word. */ |
/* The macro is sane. Jump to the next word. */ |
|
|
Line 524 man_pmacro(struct man *m, int ln, char *buf, int offs) |
|
Line 492 man_pmacro(struct man *m, int ln, char *buf, int offs) |
|
goto err; |
goto err; |
|
|
/* |
/* |
* Remove prior ELINE macro, as it's being clobbering by a new |
* Remove prior ELINE macro, as it's being clobbered by a new |
* macro. Note that NSCOPED macros do not close out ELINE |
* macro. Note that NSCOPED macros do not close out ELINE |
* macros---they don't print text---so we let those slip by. |
* macros---they don't print text---so we let those slip by. |
*/ |
*/ |
|
|
if ( ! (MAN_NSCOPED & man_macros[tok].flags) && |
if ( ! (MAN_NSCOPED & man_macros[tok].flags) && |
m->flags & MAN_ELINE) { |
m->flags & MAN_ELINE) { |
assert(MAN_TEXT != m->last->type); |
|
|
|
/* |
|
* This occurs in the following construction: |
|
* .B |
|
* .br |
|
* .B |
|
* .br |
|
* I hate man macros. |
|
* Flat-out disallow this madness. |
|
*/ |
|
if (MAN_NSCOPED & man_macros[m->last->tok].flags) { |
|
man_pmsg(m, ln, ppos, MANDOCERR_SYNTLINESCOPE); |
|
return(0); |
|
} |
|
|
|
n = m->last; |
n = m->last; |
|
assert(MAN_TEXT != n->type); |
|
|
assert(n); |
/* Remove repeated NSCOPED macros causing ELINE. */ |
assert(NULL == n->child); |
|
assert(0 == n->nchild); |
|
|
|
if ( ! man_nmsg(m, n, MANDOCERR_LINESCOPE)) |
if (MAN_NSCOPED & man_macros[n->tok].flags) |
return(0); |
n = n->parent; |
|
|
|
man_vmsg(m, MANDOCERR_LINESCOPE, n->line, n->pos, |
|
"%s", man_macronames[n->tok]); |
|
|
man_node_delete(m, n); |
man_node_delete(m, n); |
m->flags &= ~MAN_ELINE; |
m->flags &= ~MAN_ELINE; |