eqn_term.c (274880) | eqn_term.c (275432) |
---|---|
1/* $Id: eqn_term.c,v 1.5 2014/04/20 16:46:04 schwarze Exp $ */ | 1/* $Id: eqn_term.c,v 1.7 2014/10/12 14:49:39 schwarze Exp $ */ |
2/* 3 * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> | 2/* 3 * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
4 * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> |
|
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 */ | 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ |
17#ifdef HAVE_CONFIG_H | |
18#include "config.h" | 18#include "config.h" |
19#endif | |
20 | 19 |
20#include <sys/types.h> 21 |
|
21#include <assert.h> 22#include <stdio.h> 23#include <stdlib.h> 24#include <string.h> 25 26#include "mandoc.h" 27#include "out.h" 28#include "term.h" --- 8 unchanged lines hidden (view full) --- 37 38static void eqn_box(struct termp *, const struct eqn_box *); 39 40 41void 42term_eqn(struct termp *p, const struct eqn *ep) 43{ 44 | 22#include <assert.h> 23#include <stdio.h> 24#include <stdlib.h> 25#include <string.h> 26 27#include "mandoc.h" 28#include "out.h" 29#include "term.h" --- 8 unchanged lines hidden (view full) --- 38 39static void eqn_box(struct termp *, const struct eqn_box *); 40 41 42void 43term_eqn(struct termp *p, const struct eqn *ep) 44{ 45 |
45 p->flags |= TERMP_NONOSPACE; | |
46 eqn_box(p, ep->root); | 46 eqn_box(p, ep->root); |
47 term_word(p, " "); 48 p->flags &= ~TERMP_NONOSPACE; | 47 p->flags &= ~TERMP_NOSPACE; |
49} 50 51static void 52eqn_box(struct termp *p, const struct eqn_box *bp) 53{ | 48} 49 50static void 51eqn_box(struct termp *p, const struct eqn_box *bp) 52{ |
53 const struct eqn_box *child; |
|
54 | 54 |
55 if (EQNFONT_NONE != bp->font) | 55 if (bp->type == EQN_LIST || 56 (bp->type == EQN_PILE && (bp->prev || bp->next)) || 57 (bp->parent != NULL && bp->parent->pos == EQNPOS_SQRT)) { 58 if (bp->parent->type == EQN_SUBEXPR && bp->prev != NULL) 59 p->flags |= TERMP_NOSPACE; 60 term_word(p, bp->left != NULL ? bp->left : "("); 61 p->flags |= TERMP_NOSPACE; 62 } 63 if (bp->font != EQNFONT_NONE) |
56 term_fontpush(p, fontmap[(int)bp->font]); | 64 term_fontpush(p, fontmap[(int)bp->font]); |
57 if (bp->left) 58 term_word(p, bp->left); 59 if (EQN_SUBEXPR == bp->type) 60 term_word(p, "("); | |
61 | 65 |
62 if (bp->text) | 66 if (bp->text != NULL) |
63 term_word(p, bp->text); 64 | 67 term_word(p, bp->text); 68 |
65 if (bp->first) | 69 if (bp->pos == EQNPOS_SQRT) { 70 term_word(p, "sqrt"); 71 p->flags |= TERMP_NOSPACE; |
66 eqn_box(p, bp->first); | 72 eqn_box(p, bp->first); |
73 } else if (bp->type == EQN_SUBEXPR) { 74 child = bp->first; 75 eqn_box(p, child); 76 p->flags |= TERMP_NOSPACE; 77 term_word(p, bp->pos == EQNPOS_OVER ? "/" : 78 (bp->pos == EQNPOS_SUP || 79 bp->pos == EQNPOS_TO) ? "^" : "_"); 80 p->flags |= TERMP_NOSPACE; 81 child = child->next; 82 eqn_box(p, child); 83 if (bp->pos == EQNPOS_FROMTO || 84 bp->pos == EQNPOS_SUBSUP) { 85 p->flags |= TERMP_NOSPACE; 86 term_word(p, "^"); 87 p->flags |= TERMP_NOSPACE; 88 child = child->next; 89 eqn_box(p, child); 90 } 91 } else { 92 child = bp->first; 93 if (bp->type == EQN_MATRIX && child->type == EQN_LIST) 94 child = child->first; 95 while (child != NULL) { 96 eqn_box(p, 97 bp->type == EQN_PILE && 98 child->type == EQN_LIST && 99 child->args == 1 ? 100 child->first : child); 101 child = child->next; 102 } 103 } |
|
67 | 104 |
68 if (EQN_SUBEXPR == bp->type) 69 term_word(p, ")"); 70 if (bp->right) 71 term_word(p, bp->right); 72 if (EQNFONT_NONE != bp->font) | 105 if (bp->font != EQNFONT_NONE) |
73 term_fontpop(p); | 106 term_fontpop(p); |
107 if (bp->type == EQN_LIST || 108 (bp->type == EQN_PILE && (bp->prev || bp->next)) || 109 (bp->parent != NULL && bp->parent->pos == EQNPOS_SQRT)) { 110 p->flags |= TERMP_NOSPACE; 111 term_word(p, bp->right != NULL ? bp->right : ")"); 112 if (bp->parent->type == EQN_SUBEXPR && bp->next != NULL) 113 p->flags |= TERMP_NOSPACE; 114 } |
|
74 | 115 |
75 if (bp->next) 76 eqn_box(p, bp->next); | 116 if (bp->top != NULL) { 117 p->flags |= TERMP_NOSPACE; 118 term_word(p, bp->top); 119 } 120 if (bp->bottom != NULL) { 121 p->flags |= TERMP_NOSPACE; 122 term_word(p, "_"); 123 } |
77} | 124} |