eqn.c revision 1.1 1 1.1 joerg /* $Vendor-Id: eqn.c,v 1.4 2011/03/22 09:48:13 kristaps Exp $ */
2 1.1 joerg /*
3 1.1 joerg * Copyright (c) 2011 Kristaps Dzonsons <kristaps (at) bsd.lv>
4 1.1 joerg *
5 1.1 joerg * Permission to use, copy, modify, and distribute this software for any
6 1.1 joerg * purpose with or without fee is hereby granted, provided that the above
7 1.1 joerg * copyright notice and this permission notice appear in all copies.
8 1.1 joerg *
9 1.1 joerg * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 1.1 joerg * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 1.1 joerg * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 1.1 joerg * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 1.1 joerg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 1.1 joerg * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 1.1 joerg * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 1.1 joerg */
17 1.1 joerg #ifdef HAVE_CONFIG_H
18 1.1 joerg #include "config.h"
19 1.1 joerg #endif
20 1.1 joerg
21 1.1 joerg #include <assert.h>
22 1.1 joerg #include <stdio.h>
23 1.1 joerg #include <stdlib.h>
24 1.1 joerg #include <string.h>
25 1.1 joerg #include <time.h>
26 1.1 joerg
27 1.1 joerg #include "mandoc.h"
28 1.1 joerg #include "libmandoc.h"
29 1.1 joerg #include "libroff.h"
30 1.1 joerg
31 1.1 joerg /* ARGSUSED */
32 1.1 joerg enum rofferr
33 1.1 joerg eqn_read(struct eqn_node **epp, int ln, const char *p, int offs)
34 1.1 joerg {
35 1.1 joerg size_t sz;
36 1.1 joerg struct eqn_node *ep;
37 1.1 joerg
38 1.1 joerg if (0 == strcmp(p, ".EN")) {
39 1.1 joerg *epp = NULL;
40 1.1 joerg return(ROFF_EQN);
41 1.1 joerg }
42 1.1 joerg
43 1.1 joerg ep = *epp;
44 1.1 joerg
45 1.1 joerg sz = strlen(&p[offs]);
46 1.1 joerg ep->eqn.data = mandoc_realloc(ep->eqn.data, ep->eqn.sz + sz + 1);
47 1.1 joerg if (0 == ep->eqn.sz)
48 1.1 joerg *ep->eqn.data = '\0';
49 1.1 joerg
50 1.1 joerg ep->eqn.sz += sz;
51 1.1 joerg strlcat(ep->eqn.data, &p[offs], ep->eqn.sz + 1);
52 1.1 joerg return(ROFF_IGN);
53 1.1 joerg }
54 1.1 joerg
55 1.1 joerg struct eqn_node *
56 1.1 joerg eqn_alloc(int pos, int line)
57 1.1 joerg {
58 1.1 joerg struct eqn_node *p;
59 1.1 joerg
60 1.1 joerg p = mandoc_calloc(1, sizeof(struct eqn_node));
61 1.1 joerg p->eqn.line = line;
62 1.1 joerg p->eqn.pos = pos;
63 1.1 joerg
64 1.1 joerg return(p);
65 1.1 joerg }
66 1.1 joerg
67 1.1 joerg /* ARGSUSED */
68 1.1 joerg void
69 1.1 joerg eqn_end(struct eqn_node *e)
70 1.1 joerg {
71 1.1 joerg
72 1.1 joerg /* Nothing to do. */
73 1.1 joerg }
74 1.1 joerg
75 1.1 joerg void
76 1.1 joerg eqn_free(struct eqn_node *p)
77 1.1 joerg {
78 1.1 joerg
79 1.1 joerg free(p->eqn.data);
80 1.1 joerg free(p);
81 1.1 joerg }
82