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