Annotation of mandoc/tbl.c, Revision 1.9
1.9 ! kristaps 1: /* $Id: tbl.c,v 1.8 2010/12/29 16:44:23 kristaps Exp $ */
1.1 kristaps 2: /*
1.4 kristaps 3: * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
1.1 kristaps 4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
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.
16: */
17: #include <assert.h>
1.3 kristaps 18: #include <stdio.h>
1.1 kristaps 19: #include <stdlib.h>
20: #include <string.h>
21: #include <time.h>
22:
23: #include "mandoc.h"
24: #include "roff.h"
25: #include "libmandoc.h"
26: #include "libroff.h"
27:
28: static void tbl_init(struct tbl *);
29: static void tbl_clear(struct tbl *);
30:
31: static void
32: tbl_clear(struct tbl *tbl)
33: {
1.6 kristaps 34: struct tbl_row *rp;
35: struct tbl_cell *cp;
1.9 ! kristaps 36: struct tbl_span *sp;
! 37: struct tbl_dat *dp;
1.1 kristaps 38:
1.9 ! kristaps 39: while (tbl->first_row) {
! 40: rp = tbl->first_row;
! 41: tbl->first_row = rp->next;
1.6 kristaps 42: while (rp->first) {
43: cp = rp->first;
44: rp->first = cp->next;
45: free(cp);
46: }
47: free(rp);
48: }
49:
1.9 ! kristaps 50: tbl->last_row = NULL;
! 51:
! 52: while (tbl->first_span) {
! 53: sp = tbl->first_span;
! 54: tbl->first_span = sp->next;
! 55: while (sp->first) {
! 56: dp = sp->first;
! 57: sp->first = dp->next;
! 58: if (dp->string)
! 59: free(dp->string);
! 60: free(dp);
! 61: }
! 62: free(sp);
! 63: }
! 64:
! 65: tbl->last_span = NULL;
1.1 kristaps 66: }
67:
68: static void
69: tbl_init(struct tbl *tbl)
70: {
71:
72: tbl->part = TBL_PART_OPTS;
1.5 kristaps 73: tbl->tab = '\t';
74: tbl->linesize = 12;
75: tbl->decimal = '.';
1.1 kristaps 76: }
77:
78: enum rofferr
79: tbl_read(struct tbl *tbl, int ln, const char *p, int offs)
80: {
81: int len;
82: const char *cp;
83:
84: cp = &p[offs];
85: len = (int)strlen(cp);
86:
1.5 kristaps 87: /*
88: * If we're in the options section and we don't have a
89: * terminating semicolon, assume we've moved directly into the
90: * layout section. No need to report a warning: this is,
91: * apparently, standard behaviour.
92: */
93:
94: if (TBL_PART_OPTS == tbl->part && len)
1.1 kristaps 95: if (';' != cp[len - 1])
96: tbl->part = TBL_PART_LAYOUT;
1.5 kristaps 97:
98: /* Now process each logical section of the table. */
99:
100: switch (tbl->part) {
101: case (TBL_PART_OPTS):
102: return(tbl_option(tbl, ln, p) ? ROFF_IGN : ROFF_ERR);
1.6 kristaps 103: case (TBL_PART_LAYOUT):
104: return(tbl_layout(tbl, ln, p) ? ROFF_IGN : ROFF_ERR);
1.8 kristaps 105: case (TBL_PART_DATA):
1.5 kristaps 106: break;
1.8 kristaps 107: }
108:
1.9 ! kristaps 109: /*
! 110: * FIXME: allow the original string to slip through for the time
! 111: * being.
! 112: */
! 113: return(tbl_data(tbl, ln, p) ? ROFF_CONT : ROFF_ERR);
1.1 kristaps 114: }
115:
116: struct tbl *
1.5 kristaps 117: tbl_alloc(void *data, const mandocmsg msg)
1.1 kristaps 118: {
119: struct tbl *p;
120:
1.6 kristaps 121: p = mandoc_calloc(1, sizeof(struct tbl));
1.5 kristaps 122: p->data = data;
123: p->msg = msg;
1.1 kristaps 124: tbl_init(p);
125: return(p);
126: }
127:
128: void
129: tbl_free(struct tbl *p)
130: {
131:
132: tbl_clear(p);
133: free(p);
134: }
135:
136: void
137: tbl_reset(struct tbl *tbl)
138: {
139:
140: tbl_clear(tbl);
141: tbl_init(tbl);
1.7 kristaps 142: }
143:
144: void
145: tbl_restart(struct tbl *tbl)
146: {
147:
148: tbl->part = TBL_PART_LAYOUT;
1.1 kristaps 149: }
1.3 kristaps 150:
CVSweb