1*95c635efSGarrett D'Amore /* $Id: eqn_term.c,v 1.4 2011/07/24 10:09:03 kristaps Exp $ */
2*95c635efSGarrett D'Amore /*
3*95c635efSGarrett D'Amore * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*95c635efSGarrett D'Amore *
5*95c635efSGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any
6*95c635efSGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above
7*95c635efSGarrett D'Amore * copyright notice and this permission notice appear in all copies.
8*95c635efSGarrett D'Amore *
9*95c635efSGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*95c635efSGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*95c635efSGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*95c635efSGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*95c635efSGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*95c635efSGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*95c635efSGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*95c635efSGarrett D'Amore */
17*95c635efSGarrett D'Amore #ifdef HAVE_CONFIG_H
18*95c635efSGarrett D'Amore #include "config.h"
19*95c635efSGarrett D'Amore #endif
20*95c635efSGarrett D'Amore
21*95c635efSGarrett D'Amore #include <assert.h>
22*95c635efSGarrett D'Amore #include <stdio.h>
23*95c635efSGarrett D'Amore #include <stdlib.h>
24*95c635efSGarrett D'Amore #include <string.h>
25*95c635efSGarrett D'Amore
26*95c635efSGarrett D'Amore #include "mandoc.h"
27*95c635efSGarrett D'Amore #include "out.h"
28*95c635efSGarrett D'Amore #include "term.h"
29*95c635efSGarrett D'Amore
30*95c635efSGarrett D'Amore static const enum termfont fontmap[EQNFONT__MAX] = {
31*95c635efSGarrett D'Amore TERMFONT_NONE, /* EQNFONT_NONE */
32*95c635efSGarrett D'Amore TERMFONT_NONE, /* EQNFONT_ROMAN */
33*95c635efSGarrett D'Amore TERMFONT_BOLD, /* EQNFONT_BOLD */
34*95c635efSGarrett D'Amore TERMFONT_BOLD, /* EQNFONT_FAT */
35*95c635efSGarrett D'Amore TERMFONT_UNDER /* EQNFONT_ITALIC */
36*95c635efSGarrett D'Amore };
37*95c635efSGarrett D'Amore
38*95c635efSGarrett D'Amore static void eqn_box(struct termp *, const struct eqn_box *);
39*95c635efSGarrett D'Amore
40*95c635efSGarrett D'Amore void
term_eqn(struct termp * p,const struct eqn * ep)41*95c635efSGarrett D'Amore term_eqn(struct termp *p, const struct eqn *ep)
42*95c635efSGarrett D'Amore {
43*95c635efSGarrett D'Amore
44*95c635efSGarrett D'Amore p->flags |= TERMP_NONOSPACE;
45*95c635efSGarrett D'Amore eqn_box(p, ep->root);
46*95c635efSGarrett D'Amore term_word(p, " ");
47*95c635efSGarrett D'Amore p->flags &= ~TERMP_NONOSPACE;
48*95c635efSGarrett D'Amore }
49*95c635efSGarrett D'Amore
50*95c635efSGarrett D'Amore static void
eqn_box(struct termp * p,const struct eqn_box * bp)51*95c635efSGarrett D'Amore eqn_box(struct termp *p, const struct eqn_box *bp)
52*95c635efSGarrett D'Amore {
53*95c635efSGarrett D'Amore
54*95c635efSGarrett D'Amore if (EQNFONT_NONE != bp->font)
55*95c635efSGarrett D'Amore term_fontpush(p, fontmap[(int)bp->font]);
56*95c635efSGarrett D'Amore if (bp->left)
57*95c635efSGarrett D'Amore term_word(p, bp->left);
58*95c635efSGarrett D'Amore if (EQN_SUBEXPR == bp->type)
59*95c635efSGarrett D'Amore term_word(p, "(");
60*95c635efSGarrett D'Amore
61*95c635efSGarrett D'Amore if (bp->text)
62*95c635efSGarrett D'Amore term_word(p, bp->text);
63*95c635efSGarrett D'Amore
64*95c635efSGarrett D'Amore if (bp->first)
65*95c635efSGarrett D'Amore eqn_box(p, bp->first);
66*95c635efSGarrett D'Amore
67*95c635efSGarrett D'Amore if (EQN_SUBEXPR == bp->type)
68*95c635efSGarrett D'Amore term_word(p, ")");
69*95c635efSGarrett D'Amore if (bp->right)
70*95c635efSGarrett D'Amore term_word(p, bp->right);
71*95c635efSGarrett D'Amore if (EQNFONT_NONE != bp->font)
72*95c635efSGarrett D'Amore term_fontpop(p);
73*95c635efSGarrett D'Amore
74*95c635efSGarrett D'Amore if (bp->next)
75*95c635efSGarrett D'Amore eqn_box(p, bp->next);
76*95c635efSGarrett D'Amore }
77