Annotation of mandoc/man_action.c, Revision 1.28
1.28 ! kristaps 1: /* $Id: man_action.c,v 1.27 2010/03/23 11:30:48 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.18 kristaps 33: static int post_fi(struct man *);
34: static int post_nf(struct man *);
1.2 kristaps 35:
1.1 kristaps 36: const struct actions man_actions[MAN_MAX] = {
1.12 kristaps 37: { NULL }, /* br */
1.2 kristaps 38: { post_TH }, /* TH */
1.1 kristaps 39: { NULL }, /* SH */
40: { NULL }, /* SS */
41: { NULL }, /* TP */
42: { NULL }, /* LP */
43: { NULL }, /* PP */
44: { NULL }, /* P */
45: { NULL }, /* IP */
46: { NULL }, /* HP */
47: { NULL }, /* SM */
48: { NULL }, /* SB */
49: { NULL }, /* BI */
50: { NULL }, /* IB */
51: { NULL }, /* BR */
52: { NULL }, /* RB */
53: { NULL }, /* R */
54: { NULL }, /* B */
55: { NULL }, /* I */
56: { NULL }, /* IR */
1.5 kristaps 57: { NULL }, /* RI */
1.8 kristaps 58: { NULL }, /* na */
1.9 kristaps 59: { NULL }, /* i */
1.14 kristaps 60: { NULL }, /* sp */
1.18 kristaps 61: { post_nf }, /* nf */
62: { post_fi }, /* fi */
1.16 kristaps 63: { NULL }, /* r */
64: { NULL }, /* RE */
65: { NULL }, /* RS */
1.17 kristaps 66: { NULL }, /* DT */
1.19 kristaps 67: { NULL }, /* UC */
1.20 kristaps 68: { NULL }, /* PD */
1.27 kristaps 69: { NULL }, /* Sp */
70: { post_nf }, /* Vb */
71: { post_fi }, /* Ve */
1.1 kristaps 72: };
73:
74:
75: int
76: man_action_post(struct man *m)
77: {
78:
79: if (MAN_ACTED & m->last->flags)
80: return(1);
81: m->last->flags |= MAN_ACTED;
82:
83: switch (m->last->type) {
84: case (MAN_TEXT):
1.18 kristaps 85: /* FALLTHROUGH */
1.1 kristaps 86: case (MAN_ROOT):
1.18 kristaps 87: return(1);
88: default:
1.1 kristaps 89: break;
90: }
1.18 kristaps 91:
92: if (NULL == man_actions[m->last->tok].post)
93: return(1);
94: return((*man_actions[m->last->tok].post)(m));
95: }
96:
97:
98: static int
99: post_fi(struct man *m)
100: {
101:
102: if ( ! (MAN_LITERAL & m->flags))
103: if ( ! man_nwarn(m, m->last, WNLITERAL))
104: return(0);
105: m->flags &= ~MAN_LITERAL;
106: return(1);
107: }
108:
109:
110: static int
111: post_nf(struct man *m)
112: {
113:
114: if (MAN_LITERAL & m->flags)
115: if ( ! man_nwarn(m, m->last, WOLITERAL))
116: return(0);
117: m->flags |= MAN_LITERAL;
1.1 kristaps 118: return(1);
119: }
120:
1.2 kristaps 121:
1.1 kristaps 122: static int
1.2 kristaps 123: post_TH(struct man *m)
1.1 kristaps 124: {
1.2 kristaps 125: struct man_node *n;
126: char *ep;
127: long lval;
1.1 kristaps 128:
129: if (m->meta.title)
130: free(m->meta.title);
131: if (m->meta.vol)
132: free(m->meta.vol);
1.2 kristaps 133: if (m->meta.source)
134: free(m->meta.source);
1.1 kristaps 135:
1.2 kristaps 136: m->meta.title = m->meta.vol = m->meta.source = NULL;
1.1 kristaps 137: m->meta.msec = 0;
1.2 kristaps 138: m->meta.date = 0;
139:
140: /* ->TITLE<- MSEC DATE SOURCE VOL */
141:
142: n = m->last->child;
143: assert(n);
1.22 kristaps 144: m->meta.title = mandoc_strdup(n->string);
1.2 kristaps 145:
146: /* TITLE ->MSEC<- DATE SOURCE VOL */
1.1 kristaps 147:
1.2 kristaps 148: n = n->next;
149: assert(n);
1.1 kristaps 150:
1.2 kristaps 151: lval = strtol(n->string, &ep, 10);
152: if (n->string[0] != '\0' && *ep == '\0')
153: m->meta.msec = (int)lval;
1.13 kristaps 154: else if ( ! man_nwarn(m, n, WMSEC))
1.2 kristaps 155: return(0);
1.1 kristaps 156:
1.2 kristaps 157: /* TITLE MSEC ->DATE<- SOURCE VOL */
1.1 kristaps 158:
1.24 kristaps 159: n = n->next;
160: if (n) {
161: m->meta.date = mandoc_a2time
162: (MTIME_ISO_8601, n->string);
163:
164: if (0 == m->meta.date) {
165: if ( ! man_nwarn(m, n, WDATE))
166: return(0);
167: m->meta.date = time(NULL);
168: }
169: } else
1.2 kristaps 170: m->meta.date = time(NULL);
1.1 kristaps 171:
1.2 kristaps 172: /* TITLE MSEC DATE ->SOURCE<- VOL */
1.1 kristaps 173:
1.5 kristaps 174: if (n && (n = n->next))
1.22 kristaps 175: m->meta.source = mandoc_strdup(n->string);
1.1 kristaps 176:
1.2 kristaps 177: /* TITLE MSEC DATE SOURCE ->VOL<- */
1.1 kristaps 178:
1.5 kristaps 179: if (n && (n = n->next))
1.22 kristaps 180: m->meta.vol = mandoc_strdup(n->string);
1.1 kristaps 181:
1.26 kristaps 182: n = m->last;
183: man_node_unlink(m, n);
1.2 kristaps 184: man_node_freelist(n);
185: return(1);
186: }
CVSweb