[BACK]Return to eqn_term.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Annotation of src/usr.bin/mandoc/eqn_term.c, Revision 1.2

1.2     ! schwarze    1: /*     $Id: eqn_term.c,v 1.1 2011/09/18 10:25:28 schwarze Exp $ */
1.1       schwarze    2: /*
                      3:  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
                      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>
                     18: #include <stdio.h>
                     19: #include <stdlib.h>
                     20: #include <string.h>
                     21:
                     22: #include "mandoc.h"
                     23: #include "out.h"
                     24: #include "term.h"
                     25:
                     26: static const enum termfont fontmap[EQNFONT__MAX] = {
                     27:        TERMFONT_NONE, /* EQNFONT_NONE */
                     28:        TERMFONT_NONE, /* EQNFONT_ROMAN */
                     29:        TERMFONT_BOLD, /* EQNFONT_BOLD */
                     30:        TERMFONT_BOLD, /* EQNFONT_FAT */
                     31:        TERMFONT_UNDER /* EQNFONT_ITALIC */
                     32: };
                     33:
                     34: static void    eqn_box(struct termp *, const struct eqn_box *);
                     35:
1.2     ! schwarze   36:
1.1       schwarze   37: void
                     38: term_eqn(struct termp *p, const struct eqn *ep)
                     39: {
                     40:
                     41:        p->flags |= TERMP_NONOSPACE;
                     42:        eqn_box(p, ep->root);
                     43:        term_word(p, " ");
                     44:        p->flags &= ~TERMP_NONOSPACE;
                     45: }
                     46:
                     47: static void
                     48: eqn_box(struct termp *p, const struct eqn_box *bp)
                     49: {
                     50:
                     51:        if (EQNFONT_NONE != bp->font)
                     52:                term_fontpush(p, fontmap[(int)bp->font]);
                     53:        if (bp->left)
                     54:                term_word(p, bp->left);
                     55:        if (EQN_SUBEXPR == bp->type)
                     56:                term_word(p, "(");
                     57:
                     58:        if (bp->text)
                     59:                term_word(p, bp->text);
                     60:
                     61:        if (bp->first)
                     62:                eqn_box(p, bp->first);
                     63:
                     64:        if (EQN_SUBEXPR == bp->type)
                     65:                term_word(p, ")");
                     66:        if (bp->right)
                     67:                term_word(p, bp->right);
1.2     ! schwarze   68:        if (EQNFONT_NONE != bp->font)
1.1       schwarze   69:                term_fontpop(p);
                     70:
                     71:        if (bp->next)
                     72:                eqn_box(p, bp->next);
                     73: }