Annotation of mandoc/man_action.c, Revision 1.26
1.26 ! kristaps 1: /* $Id: man_action.c,v 1.25 2010/01/01 17:14:27 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.1 kristaps 71: };
72:
73:
74: int
75: man_action_post(struct man *m)
76: {
77:
78: if (MAN_ACTED & m->last->flags)
79: return(1);
80: m->last->flags |= MAN_ACTED;
81:
82: switch (m->last->type) {
83: case (MAN_TEXT):
1.18 kristaps 84: /* FALLTHROUGH */
1.1 kristaps 85: case (MAN_ROOT):
1.18 kristaps 86: return(1);
87: default:
1.1 kristaps 88: break;
89: }
1.18 kristaps 90:
91: if (NULL == man_actions[m->last->tok].post)
92: return(1);
93: return((*man_actions[m->last->tok].post)(m));
94: }
95:
96:
97: static int
98: post_fi(struct man *m)
99: {
100:
101: if ( ! (MAN_LITERAL & m->flags))
102: if ( ! man_nwarn(m, m->last, WNLITERAL))
103: return(0);
104: m->flags &= ~MAN_LITERAL;
105: return(1);
106: }
107:
108:
109: static int
110: post_nf(struct man *m)
111: {
112:
113: if (MAN_LITERAL & m->flags)
114: if ( ! man_nwarn(m, m->last, WOLITERAL))
115: return(0);
116: m->flags |= MAN_LITERAL;
1.1 kristaps 117: return(1);
118: }
119:
1.2 kristaps 120:
1.1 kristaps 121: static int
1.2 kristaps 122: post_TH(struct man *m)
1.1 kristaps 123: {
1.2 kristaps 124: struct man_node *n;
125: char *ep;
126: long lval;
1.1 kristaps 127:
128: if (m->meta.title)
129: free(m->meta.title);
130: if (m->meta.vol)
131: free(m->meta.vol);
1.2 kristaps 132: if (m->meta.source)
133: free(m->meta.source);
1.1 kristaps 134:
1.2 kristaps 135: m->meta.title = m->meta.vol = m->meta.source = NULL;
1.1 kristaps 136: m->meta.msec = 0;
1.2 kristaps 137: m->meta.date = 0;
138:
139: /* ->TITLE<- MSEC DATE SOURCE VOL */
140:
141: n = m->last->child;
142: assert(n);
1.22 kristaps 143: m->meta.title = mandoc_strdup(n->string);
1.2 kristaps 144:
145: /* TITLE ->MSEC<- DATE SOURCE VOL */
1.1 kristaps 146:
1.2 kristaps 147: n = n->next;
148: assert(n);
1.1 kristaps 149:
1.2 kristaps 150: lval = strtol(n->string, &ep, 10);
151: if (n->string[0] != '\0' && *ep == '\0')
152: m->meta.msec = (int)lval;
1.13 kristaps 153: else if ( ! man_nwarn(m, n, WMSEC))
1.2 kristaps 154: return(0);
1.1 kristaps 155:
1.2 kristaps 156: /* TITLE MSEC ->DATE<- SOURCE VOL */
1.1 kristaps 157:
1.24 kristaps 158: n = n->next;
159: if (n) {
160: m->meta.date = mandoc_a2time
161: (MTIME_ISO_8601, n->string);
162:
163: if (0 == m->meta.date) {
164: if ( ! man_nwarn(m, n, WDATE))
165: return(0);
166: m->meta.date = time(NULL);
167: }
168: } else
1.2 kristaps 169: m->meta.date = time(NULL);
1.1 kristaps 170:
1.2 kristaps 171: /* TITLE MSEC DATE ->SOURCE<- VOL */
1.1 kristaps 172:
1.5 kristaps 173: if (n && (n = n->next))
1.22 kristaps 174: m->meta.source = mandoc_strdup(n->string);
1.1 kristaps 175:
1.2 kristaps 176: /* TITLE MSEC DATE SOURCE ->VOL<- */
1.1 kristaps 177:
1.5 kristaps 178: if (n && (n = n->next))
1.22 kristaps 179: m->meta.vol = mandoc_strdup(n->string);
1.1 kristaps 180:
1.26 ! kristaps 181: n = m->last;
! 182: man_node_unlink(m, n);
1.2 kristaps 183: man_node_freelist(n);
184: return(1);
185: }
CVSweb