1*0a6a1f1dSLionel Sambuc /* Id: eqn_term.c,v 1.4 2011/07/24 10:09:03 kristaps Exp */
292395e9cSLionel Sambuc /*
392395e9cSLionel Sambuc * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
492395e9cSLionel Sambuc *
592395e9cSLionel Sambuc * Permission to use, copy, modify, and distribute this software for any
692395e9cSLionel Sambuc * purpose with or without fee is hereby granted, provided that the above
792395e9cSLionel Sambuc * copyright notice and this permission notice appear in all copies.
892395e9cSLionel Sambuc *
992395e9cSLionel Sambuc * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1092395e9cSLionel Sambuc * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1192395e9cSLionel Sambuc * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1292395e9cSLionel Sambuc * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1392395e9cSLionel Sambuc * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1492395e9cSLionel Sambuc * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1592395e9cSLionel Sambuc * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1692395e9cSLionel Sambuc */
1792395e9cSLionel Sambuc #ifdef HAVE_CONFIG_H
1892395e9cSLionel Sambuc #include "config.h"
1992395e9cSLionel Sambuc #endif
2092395e9cSLionel Sambuc
2192395e9cSLionel Sambuc #include <assert.h>
2292395e9cSLionel Sambuc #include <stdio.h>
2392395e9cSLionel Sambuc #include <stdlib.h>
2492395e9cSLionel Sambuc #include <string.h>
2592395e9cSLionel Sambuc
2692395e9cSLionel Sambuc #include "mandoc.h"
2792395e9cSLionel Sambuc #include "out.h"
2892395e9cSLionel Sambuc #include "term.h"
2992395e9cSLionel Sambuc
3092395e9cSLionel Sambuc static const enum termfont fontmap[EQNFONT__MAX] = {
3192395e9cSLionel Sambuc TERMFONT_NONE, /* EQNFONT_NONE */
3292395e9cSLionel Sambuc TERMFONT_NONE, /* EQNFONT_ROMAN */
3392395e9cSLionel Sambuc TERMFONT_BOLD, /* EQNFONT_BOLD */
3492395e9cSLionel Sambuc TERMFONT_BOLD, /* EQNFONT_FAT */
3592395e9cSLionel Sambuc TERMFONT_UNDER /* EQNFONT_ITALIC */
3692395e9cSLionel Sambuc };
3792395e9cSLionel Sambuc
3892395e9cSLionel Sambuc static void eqn_box(struct termp *, const struct eqn_box *);
3992395e9cSLionel Sambuc
4092395e9cSLionel Sambuc void
term_eqn(struct termp * p,const struct eqn * ep)4192395e9cSLionel Sambuc term_eqn(struct termp *p, const struct eqn *ep)
4292395e9cSLionel Sambuc {
4392395e9cSLionel Sambuc
4492395e9cSLionel Sambuc p->flags |= TERMP_NONOSPACE;
4592395e9cSLionel Sambuc eqn_box(p, ep->root);
4692395e9cSLionel Sambuc term_word(p, " ");
4792395e9cSLionel Sambuc p->flags &= ~TERMP_NONOSPACE;
4892395e9cSLionel Sambuc }
4992395e9cSLionel Sambuc
5092395e9cSLionel Sambuc static void
eqn_box(struct termp * p,const struct eqn_box * bp)5192395e9cSLionel Sambuc eqn_box(struct termp *p, const struct eqn_box *bp)
5292395e9cSLionel Sambuc {
5392395e9cSLionel Sambuc
5492395e9cSLionel Sambuc if (EQNFONT_NONE != bp->font)
5592395e9cSLionel Sambuc term_fontpush(p, fontmap[(int)bp->font]);
5692395e9cSLionel Sambuc if (bp->left)
5792395e9cSLionel Sambuc term_word(p, bp->left);
5892395e9cSLionel Sambuc if (EQN_SUBEXPR == bp->type)
5992395e9cSLionel Sambuc term_word(p, "(");
6092395e9cSLionel Sambuc
6192395e9cSLionel Sambuc if (bp->text)
6292395e9cSLionel Sambuc term_word(p, bp->text);
6392395e9cSLionel Sambuc
6492395e9cSLionel Sambuc if (bp->first)
6592395e9cSLionel Sambuc eqn_box(p, bp->first);
6692395e9cSLionel Sambuc
6792395e9cSLionel Sambuc if (EQN_SUBEXPR == bp->type)
6892395e9cSLionel Sambuc term_word(p, ")");
6992395e9cSLionel Sambuc if (bp->right)
7092395e9cSLionel Sambuc term_word(p, bp->right);
7192395e9cSLionel Sambuc if (EQNFONT_NONE != bp->font)
7292395e9cSLionel Sambuc term_fontpop(p);
7392395e9cSLionel Sambuc
7492395e9cSLionel Sambuc if (bp->next)
7592395e9cSLionel Sambuc eqn_box(p, bp->next);
7692395e9cSLionel Sambuc }
77