Annotation of mandoc/man_action.c, Revision 1.29
1.29 ! kristaps 1: /* $Id: man_action.c,v 1.28 2010/03/24 03:46:02 kristaps Exp $ */
1.1 kristaps 2: /*
1.11 kristaps 3: * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
1.1 kristaps 4: *
5: * Permission to use, copy, modify, and distribute this software for any
1.10 kristaps 6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
1.1 kristaps 8: *
1.10 kristaps 9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 kristaps 16: */
1.25 kristaps 17: #ifdef HAVE_CONFIG_H
18: #include "config.h"
19: #endif
1.1 kristaps 20:
21: #include <assert.h>
22: #include <stdlib.h>
23: #include <string.h>
24:
25: #include "libman.h"
1.22 kristaps 26: #include "libmandoc.h"
1.1 kristaps 27:
28: struct actions {
29: int (*post)(struct man *);
30: };
31:
1.2 kristaps 32: static int post_TH(struct man *);
1.29 ! kristaps 33: static int post_de(struct man *);
1.18 kristaps 34: static int post_fi(struct man *);
35: static int post_nf(struct man *);
1.2 kristaps 36:
1.1 kristaps 37: const struct actions man_actions[MAN_MAX] = {
1.12 kristaps 38: { NULL }, /* br */
1.2 kristaps 39: { post_TH }, /* TH */
1.1 kristaps 40: { NULL }, /* SH */
41: { NULL }, /* SS */
42: { NULL }, /* TP */
43: { NULL }, /* LP */
44: { NULL }, /* PP */
45: { NULL }, /* P */
46: { NULL }, /* IP */
47: { NULL }, /* HP */
48: { NULL }, /* SM */
49: { NULL }, /* SB */
50: { NULL }, /* BI */
51: { NULL }, /* IB */
52: { NULL }, /* BR */
53: { NULL }, /* RB */
54: { NULL }, /* R */
55: { NULL }, /* B */
56: { NULL }, /* I */
57: { NULL }, /* IR */
1.5 kristaps 58: { NULL }, /* RI */
1.8 kristaps 59: { NULL }, /* na */
1.9 kristaps 60: { NULL }, /* i */
1.14 kristaps 61: { NULL }, /* sp */
1.18 kristaps 62: { post_nf }, /* nf */
63: { post_fi }, /* fi */
1.16 kristaps 64: { NULL }, /* r */
65: { NULL }, /* RE */
66: { NULL }, /* RS */
1.17 kristaps 67: { NULL }, /* DT */
1.19 kristaps 68: { NULL }, /* UC */
1.20 kristaps 69: { NULL }, /* PD */
1.27 kristaps 70: { NULL }, /* Sp */
71: { post_nf }, /* Vb */
72: { post_fi }, /* Ve */
1.29 ! kristaps 73: { post_de }, /* de */
! 74: { post_de }, /* dei */
! 75: { post_de }, /* am */
! 76: { post_de }, /* ami */
! 77: { post_de }, /* ig */
! 78: { NULL }, /* . */
1.1 kristaps 79: };
80:
81:
82: int
83: man_action_post(struct man *m)
84: {
85:
86: if (MAN_ACTED & m->last->flags)
87: return(1);
88: m->last->flags |= MAN_ACTED;
89:
90: switch (m->last->type) {
91: case (MAN_TEXT):
1.18 kristaps 92: /* FALLTHROUGH */
1.1 kristaps 93: case (MAN_ROOT):
1.18 kristaps 94: return(1);
95: default:
1.1 kristaps 96: break;
97: }
1.18 kristaps 98:
99: if (NULL == man_actions[m->last->tok].post)
100: return(1);
101: return((*man_actions[m->last->tok].post)(m));
102: }
103:
104:
105: static int
106: post_fi(struct man *m)
107: {
108:
109: if ( ! (MAN_LITERAL & m->flags))
110: if ( ! man_nwarn(m, m->last, WNLITERAL))
111: return(0);
112: m->flags &= ~MAN_LITERAL;
113: return(1);
114: }
115:
116:
117: static int
1.29 ! kristaps 118: post_de(struct man *m)
! 119: {
! 120:
! 121: /*
! 122: * XXX: for the time being, we indiscriminately remove roff
! 123: * instructions from the parse stream.
! 124: */
! 125: if (MAN_BLOCK == m->last->type)
! 126: man_node_delete(m, m->last);
! 127:
! 128: return(1);
! 129: }
! 130:
! 131:
! 132: static int
1.18 kristaps 133: post_nf(struct man *m)
134: {
135:
136: if (MAN_LITERAL & m->flags)
137: if ( ! man_nwarn(m, m->last, WOLITERAL))
138: return(0);
139: m->flags |= MAN_LITERAL;
1.1 kristaps 140: return(1);
141: }
142:
1.2 kristaps 143:
1.1 kristaps 144: static int
1.2 kristaps 145: post_TH(struct man *m)
1.1 kristaps 146: {
1.2 kristaps 147: struct man_node *n;
148: char *ep;
149: long lval;
1.1 kristaps 150:
151: if (m->meta.title)
152: free(m->meta.title);
153: if (m->meta.vol)
154: free(m->meta.vol);
1.2 kristaps 155: if (m->meta.source)
156: free(m->meta.source);
1.1 kristaps 157:
1.2 kristaps 158: m->meta.title = m->meta.vol = m->meta.source = NULL;
1.1 kristaps 159: m->meta.msec = 0;
1.2 kristaps 160: m->meta.date = 0;
161:
162: /* ->TITLE<- MSEC DATE SOURCE VOL */
163:
164: n = m->last->child;
165: assert(n);
1.22 kristaps 166: m->meta.title = mandoc_strdup(n->string);
1.2 kristaps 167:
168: /* TITLE ->MSEC<- DATE SOURCE VOL */
1.1 kristaps 169:
1.2 kristaps 170: n = n->next;
171: assert(n);
1.1 kristaps 172:
1.2 kristaps 173: lval = strtol(n->string, &ep, 10);
174: if (n->string[0] != '\0' && *ep == '\0')
175: m->meta.msec = (int)lval;
1.13 kristaps 176: else if ( ! man_nwarn(m, n, WMSEC))
1.2 kristaps 177: return(0);
1.1 kristaps 178:
1.2 kristaps 179: /* TITLE MSEC ->DATE<- SOURCE VOL */
1.1 kristaps 180:
1.24 kristaps 181: n = n->next;
182: if (n) {
183: m->meta.date = mandoc_a2time
184: (MTIME_ISO_8601, n->string);
185:
186: if (0 == m->meta.date) {
187: if ( ! man_nwarn(m, n, WDATE))
188: return(0);
189: m->meta.date = time(NULL);
190: }
191: } else
1.2 kristaps 192: m->meta.date = time(NULL);
1.1 kristaps 193:
1.2 kristaps 194: /* TITLE MSEC DATE ->SOURCE<- VOL */
1.1 kristaps 195:
1.5 kristaps 196: if (n && (n = n->next))
1.22 kristaps 197: m->meta.source = mandoc_strdup(n->string);
1.1 kristaps 198:
1.2 kristaps 199: /* TITLE MSEC DATE SOURCE ->VOL<- */
1.1 kristaps 200:
1.5 kristaps 201: if (n && (n = n->next))
1.22 kristaps 202: m->meta.vol = mandoc_strdup(n->string);
1.1 kristaps 203:
1.29 ! kristaps 204: /*
! 205: * Remove the `TH' node after we've processed it for our
! 206: * meta-data.
! 207: */
! 208: man_node_delete(m, m->last);
1.2 kristaps 209: return(1);
210: }
CVSweb