mandoc 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +7 -0
  3. data/COPYING +674 -0
  4. data/README.md +117 -0
  5. data/ext/mandoc/extconf.rb +59 -0
  6. data/ext/mandoc/rb_mandoc.c +548 -0
  7. data/ext/mandoc/rb_mandoc.h +22 -0
  8. data/lib/mandoc/version.rb +19 -0
  9. data/lib/mandoc.rb +26 -0
  10. data/mandoc-1.14.6/LICENSE +55 -0
  11. data/mandoc-1.14.6/arch.c +54 -0
  12. data/mandoc-1.14.6/att.c +49 -0
  13. data/mandoc-1.14.6/catman.c +260 -0
  14. data/mandoc-1.14.6/cgi.c +1279 -0
  15. data/mandoc-1.14.6/chars.c +507 -0
  16. data/mandoc-1.14.6/compat_err.c +103 -0
  17. data/mandoc-1.14.6/compat_fts.c +696 -0
  18. data/mandoc-1.14.6/compat_fts.h +106 -0
  19. data/mandoc-1.14.6/compat_getline.c +59 -0
  20. data/mandoc-1.14.6/compat_getsubopt.c +87 -0
  21. data/mandoc-1.14.6/compat_isblank.c +23 -0
  22. data/mandoc-1.14.6/compat_mkdtemp.c +50 -0
  23. data/mandoc-1.14.6/compat_mkstemps.c +63 -0
  24. data/mandoc-1.14.6/compat_ohash.c +330 -0
  25. data/mandoc-1.14.6/compat_ohash.h +72 -0
  26. data/mandoc-1.14.6/compat_progname.c +31 -0
  27. data/mandoc-1.14.6/compat_reallocarray.c +40 -0
  28. data/mandoc-1.14.6/compat_recallocarray.c +99 -0
  29. data/mandoc-1.14.6/compat_strcasestr.c +64 -0
  30. data/mandoc-1.14.6/compat_stringlist.c +135 -0
  31. data/mandoc-1.14.6/compat_stringlist.h +48 -0
  32. data/mandoc-1.14.6/compat_strlcat.c +57 -0
  33. data/mandoc-1.14.6/compat_strlcpy.c +52 -0
  34. data/mandoc-1.14.6/compat_strndup.c +42 -0
  35. data/mandoc-1.14.6/compat_strsep.c +70 -0
  36. data/mandoc-1.14.6/compat_strtonum.c +67 -0
  37. data/mandoc-1.14.6/compat_vasprintf.c +47 -0
  38. data/mandoc-1.14.6/config.h +52 -0
  39. data/mandoc-1.14.6/dba.c +508 -0
  40. data/mandoc-1.14.6/dba.h +50 -0
  41. data/mandoc-1.14.6/dba_array.c +190 -0
  42. data/mandoc-1.14.6/dba_array.h +47 -0
  43. data/mandoc-1.14.6/dba_read.c +74 -0
  44. data/mandoc-1.14.6/dba_write.c +127 -0
  45. data/mandoc-1.14.6/dba_write.h +30 -0
  46. data/mandoc-1.14.6/dbm.c +480 -0
  47. data/mandoc-1.14.6/dbm.h +68 -0
  48. data/mandoc-1.14.6/dbm_map.c +194 -0
  49. data/mandoc-1.14.6/dbm_map.h +29 -0
  50. data/mandoc-1.14.6/demandoc.c +260 -0
  51. data/mandoc-1.14.6/eqn.c +1132 -0
  52. data/mandoc-1.14.6/eqn.h +72 -0
  53. data/mandoc-1.14.6/eqn_html.c +246 -0
  54. data/mandoc-1.14.6/eqn_parse.h +48 -0
  55. data/mandoc-1.14.6/eqn_term.c +174 -0
  56. data/mandoc-1.14.6/html.c +1102 -0
  57. data/mandoc-1.14.6/html.h +142 -0
  58. data/mandoc-1.14.6/lib.c +35 -0
  59. data/mandoc-1.14.6/libman.h +42 -0
  60. data/mandoc-1.14.6/libmandoc.h +85 -0
  61. data/mandoc-1.14.6/libmdoc.h +87 -0
  62. data/mandoc-1.14.6/main.c +1375 -0
  63. data/mandoc-1.14.6/main.h +53 -0
  64. data/mandoc-1.14.6/man.c +345 -0
  65. data/mandoc-1.14.6/man.h +21 -0
  66. data/mandoc-1.14.6/man_html.c +640 -0
  67. data/mandoc-1.14.6/man_macro.c +470 -0
  68. data/mandoc-1.14.6/man_term.c +1143 -0
  69. data/mandoc-1.14.6/man_validate.c +660 -0
  70. data/mandoc-1.14.6/manconf.h +58 -0
  71. data/mandoc-1.14.6/mandoc.c +669 -0
  72. data/mandoc-1.14.6/mandoc.h +329 -0
  73. data/mandoc-1.14.6/mandoc_aux.c +118 -0
  74. data/mandoc-1.14.6/mandoc_aux.h +27 -0
  75. data/mandoc-1.14.6/mandoc_msg.c +375 -0
  76. data/mandoc-1.14.6/mandoc_ohash.c +65 -0
  77. data/mandoc-1.14.6/mandoc_ohash.h +23 -0
  78. data/mandoc-1.14.6/mandoc_parse.h +44 -0
  79. data/mandoc-1.14.6/mandoc_xr.c +123 -0
  80. data/mandoc-1.14.6/mandoc_xr.h +31 -0
  81. data/mandoc-1.14.6/mandocd.c +282 -0
  82. data/mandoc-1.14.6/mandocdb.c +2448 -0
  83. data/mandoc-1.14.6/manpath.c +363 -0
  84. data/mandoc-1.14.6/mansearch.c +851 -0
  85. data/mandoc-1.14.6/mansearch.h +118 -0
  86. data/mandoc-1.14.6/mdoc.c +433 -0
  87. data/mandoc-1.14.6/mdoc.h +158 -0
  88. data/mandoc-1.14.6/mdoc_argv.c +682 -0
  89. data/mandoc-1.14.6/mdoc_html.c +1762 -0
  90. data/mandoc-1.14.6/mdoc_macro.c +1600 -0
  91. data/mandoc-1.14.6/mdoc_man.c +1850 -0
  92. data/mandoc-1.14.6/mdoc_markdown.c +1610 -0
  93. data/mandoc-1.14.6/mdoc_state.c +256 -0
  94. data/mandoc-1.14.6/mdoc_term.c +1964 -0
  95. data/mandoc-1.14.6/mdoc_validate.c +3062 -0
  96. data/mandoc-1.14.6/msec.c +37 -0
  97. data/mandoc-1.14.6/out.c +544 -0
  98. data/mandoc-1.14.6/out.h +70 -0
  99. data/mandoc-1.14.6/preconv.c +179 -0
  100. data/mandoc-1.14.6/read.c +732 -0
  101. data/mandoc-1.14.6/roff.c +4390 -0
  102. data/mandoc-1.14.6/roff.h +561 -0
  103. data/mandoc-1.14.6/roff_html.c +119 -0
  104. data/mandoc-1.14.6/roff_int.h +94 -0
  105. data/mandoc-1.14.6/roff_term.c +266 -0
  106. data/mandoc-1.14.6/roff_validate.c +151 -0
  107. data/mandoc-1.14.6/soelim.c +182 -0
  108. data/mandoc-1.14.6/st.c +82 -0
  109. data/mandoc-1.14.6/tag.c +327 -0
  110. data/mandoc-1.14.6/tag.h +35 -0
  111. data/mandoc-1.14.6/tbl.c +183 -0
  112. data/mandoc-1.14.6/tbl.h +121 -0
  113. data/mandoc-1.14.6/tbl_data.c +323 -0
  114. data/mandoc-1.14.6/tbl_html.c +293 -0
  115. data/mandoc-1.14.6/tbl_int.h +47 -0
  116. data/mandoc-1.14.6/tbl_layout.c +376 -0
  117. data/mandoc-1.14.6/tbl_opts.c +173 -0
  118. data/mandoc-1.14.6/tbl_parse.h +30 -0
  119. data/mandoc-1.14.6/tbl_term.c +948 -0
  120. data/mandoc-1.14.6/term.c +1113 -0
  121. data/mandoc-1.14.6/term.h +158 -0
  122. data/mandoc-1.14.6/term_ascii.c +424 -0
  123. data/mandoc-1.14.6/term_ps.c +1362 -0
  124. data/mandoc-1.14.6/term_tab.c +130 -0
  125. data/mandoc-1.14.6/term_tag.c +227 -0
  126. data/mandoc-1.14.6/term_tag.h +34 -0
  127. data/mandoc-1.14.6/tree.c +536 -0
  128. metadata +170 -0
@@ -0,0 +1,72 @@
1
+ /* $Id: eqn.h,v 1.1 2018/12/13 05:23:38 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2011, 2014 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 AUTHORS DISCLAIM ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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
+ * Public data types for eqn(7) syntax trees.
18
+ */
19
+
20
+ enum eqn_boxt {
21
+ EQN_TEXT, /* Text, e.g. number, variable, operator, ... */
22
+ EQN_SUBEXPR, /* Nested eqn(7) subexpression. */
23
+ EQN_LIST, /* List, for example in braces. */
24
+ EQN_PILE, /* Vertical pile. */
25
+ EQN_MATRIX /* List of columns. */
26
+ };
27
+
28
+ enum eqn_fontt {
29
+ EQNFONT_NONE = 0,
30
+ EQNFONT_ROMAN,
31
+ EQNFONT_BOLD,
32
+ EQNFONT_FAT,
33
+ EQNFONT_ITALIC,
34
+ EQNFONT__MAX
35
+ };
36
+
37
+ enum eqn_post {
38
+ EQNPOS_NONE = 0,
39
+ EQNPOS_SUP,
40
+ EQNPOS_SUBSUP,
41
+ EQNPOS_SUB,
42
+ EQNPOS_TO,
43
+ EQNPOS_FROM,
44
+ EQNPOS_FROMTO,
45
+ EQNPOS_OVER,
46
+ EQNPOS_SQRT,
47
+ EQNPOS__MAX
48
+ };
49
+
50
+ /*
51
+ * A "box" is a parsed mathematical expression as defined by the eqn.7
52
+ * grammar.
53
+ */
54
+ struct eqn_box {
55
+ struct eqn_box *parent;
56
+ struct eqn_box *prev;
57
+ struct eqn_box *next;
58
+ struct eqn_box *first; /* First child node. */
59
+ struct eqn_box *last; /* Last child node. */
60
+ char *text; /* Text (or NULL). */
61
+ char *left; /* Left-hand fence. */
62
+ char *right; /* Right-hand fence. */
63
+ char *top; /* Symbol above. */
64
+ char *bottom; /* Symbol below. */
65
+ size_t expectargs; /* Maximal number of arguments. */
66
+ size_t args; /* Actual number of arguments. */
67
+ int size; /* Font size. */
68
+ #define EQN_DEFSIZE INT_MIN
69
+ enum eqn_boxt type; /* Type of node. */
70
+ enum eqn_fontt font; /* Font in this box. */
71
+ enum eqn_post pos; /* Position of the next box. */
72
+ };
@@ -0,0 +1,246 @@
1
+ /* $Id: eqn_html.c,v 1.19 2019/03/17 18:21:45 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4
+ * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
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
+ */
18
+ #include "config.h"
19
+
20
+ #include <sys/types.h>
21
+
22
+ #include <assert.h>
23
+ #include <ctype.h>
24
+ #include <stdio.h>
25
+ #include <stdlib.h>
26
+ #include <string.h>
27
+
28
+ #include "mandoc.h"
29
+ #include "roff.h"
30
+ #include "eqn.h"
31
+ #include "out.h"
32
+ #include "html.h"
33
+
34
+ static void
35
+ eqn_box(struct html *p, const struct eqn_box *bp)
36
+ {
37
+ struct tag *post, *row, *cell, *t;
38
+ const struct eqn_box *child, *parent;
39
+ const char *cp;
40
+ size_t i, j, rows;
41
+ enum htmltag tag;
42
+ enum eqn_fontt font;
43
+
44
+ if (NULL == bp)
45
+ return;
46
+
47
+ post = NULL;
48
+
49
+ /*
50
+ * Special handling for a matrix, which is presented to us in
51
+ * column order, but must be printed in row-order.
52
+ */
53
+ if (EQN_MATRIX == bp->type) {
54
+ if (NULL == bp->first)
55
+ goto out;
56
+ if (bp->first->type != EQN_LIST ||
57
+ bp->first->expectargs == 1) {
58
+ eqn_box(p, bp->first);
59
+ goto out;
60
+ }
61
+ if (NULL == (parent = bp->first->first))
62
+ goto out;
63
+ /* Estimate the number of rows, first. */
64
+ if (NULL == (child = parent->first))
65
+ goto out;
66
+ for (rows = 0; NULL != child; rows++)
67
+ child = child->next;
68
+ /* Print row-by-row. */
69
+ post = print_otag(p, TAG_MTABLE, "");
70
+ for (i = 0; i < rows; i++) {
71
+ parent = bp->first->first;
72
+ row = print_otag(p, TAG_MTR, "");
73
+ while (NULL != parent) {
74
+ child = parent->first;
75
+ for (j = 0; j < i; j++) {
76
+ if (NULL == child)
77
+ break;
78
+ child = child->next;
79
+ }
80
+ cell = print_otag(p, TAG_MTD, "");
81
+ /*
82
+ * If we have no data for this
83
+ * particular cell, then print a
84
+ * placeholder and continue--don't puke.
85
+ */
86
+ if (NULL != child)
87
+ eqn_box(p, child->first);
88
+ print_tagq(p, cell);
89
+ parent = parent->next;
90
+ }
91
+ print_tagq(p, row);
92
+ }
93
+ goto out;
94
+ }
95
+
96
+ switch (bp->pos) {
97
+ case EQNPOS_TO:
98
+ post = print_otag(p, TAG_MOVER, "");
99
+ break;
100
+ case EQNPOS_SUP:
101
+ post = print_otag(p, TAG_MSUP, "");
102
+ break;
103
+ case EQNPOS_FROM:
104
+ post = print_otag(p, TAG_MUNDER, "");
105
+ break;
106
+ case EQNPOS_SUB:
107
+ post = print_otag(p, TAG_MSUB, "");
108
+ break;
109
+ case EQNPOS_OVER:
110
+ post = print_otag(p, TAG_MFRAC, "");
111
+ break;
112
+ case EQNPOS_FROMTO:
113
+ post = print_otag(p, TAG_MUNDEROVER, "");
114
+ break;
115
+ case EQNPOS_SUBSUP:
116
+ post = print_otag(p, TAG_MSUBSUP, "");
117
+ break;
118
+ case EQNPOS_SQRT:
119
+ post = print_otag(p, TAG_MSQRT, "");
120
+ break;
121
+ default:
122
+ break;
123
+ }
124
+
125
+ if (bp->top || bp->bottom) {
126
+ assert(NULL == post);
127
+ if (bp->top && NULL == bp->bottom)
128
+ post = print_otag(p, TAG_MOVER, "");
129
+ else if (bp->top && bp->bottom)
130
+ post = print_otag(p, TAG_MUNDEROVER, "");
131
+ else if (bp->bottom)
132
+ post = print_otag(p, TAG_MUNDER, "");
133
+ }
134
+
135
+ if (EQN_PILE == bp->type) {
136
+ assert(NULL == post);
137
+ if (bp->first != NULL &&
138
+ bp->first->type == EQN_LIST &&
139
+ bp->first->expectargs > 1)
140
+ post = print_otag(p, TAG_MTABLE, "");
141
+ } else if (bp->type == EQN_LIST && bp->expectargs > 1 &&
142
+ bp->parent && bp->parent->type == EQN_PILE) {
143
+ assert(NULL == post);
144
+ post = print_otag(p, TAG_MTR, "");
145
+ print_otag(p, TAG_MTD, "");
146
+ }
147
+
148
+ if (bp->text != NULL) {
149
+ assert(post == NULL);
150
+ tag = TAG_MI;
151
+ cp = bp->text;
152
+ if (isdigit((unsigned char)cp[0]) ||
153
+ (cp[0] == '.' && isdigit((unsigned char)cp[1]))) {
154
+ tag = TAG_MN;
155
+ while (*++cp != '\0') {
156
+ if (*cp != '.' &&
157
+ isdigit((unsigned char)*cp) == 0) {
158
+ tag = TAG_MI;
159
+ break;
160
+ }
161
+ }
162
+ } else if (*cp != '\0' && isalpha((unsigned char)*cp) == 0) {
163
+ tag = TAG_MO;
164
+ while (*cp != '\0') {
165
+ if (cp[0] == '\\' && cp[1] != '\0') {
166
+ cp++;
167
+ mandoc_escape(&cp, NULL, NULL);
168
+ } else if (isalnum((unsigned char)*cp)) {
169
+ tag = TAG_MI;
170
+ break;
171
+ } else
172
+ cp++;
173
+ }
174
+ }
175
+ font = bp->font;
176
+ if (bp->text[0] != '\0' &&
177
+ (((tag == TAG_MN || tag == TAG_MO) &&
178
+ font == EQNFONT_ROMAN) ||
179
+ (tag == TAG_MI && font == (bp->text[1] == '\0' ?
180
+ EQNFONT_ITALIC : EQNFONT_ROMAN))))
181
+ font = EQNFONT_NONE;
182
+ switch (font) {
183
+ case EQNFONT_NONE:
184
+ post = print_otag(p, tag, "");
185
+ break;
186
+ case EQNFONT_ROMAN:
187
+ post = print_otag(p, tag, "?", "fontstyle", "normal");
188
+ break;
189
+ case EQNFONT_BOLD:
190
+ case EQNFONT_FAT:
191
+ post = print_otag(p, tag, "?", "fontweight", "bold");
192
+ break;
193
+ case EQNFONT_ITALIC:
194
+ post = print_otag(p, tag, "?", "fontstyle", "italic");
195
+ break;
196
+ default:
197
+ abort();
198
+ }
199
+ print_text(p, bp->text);
200
+ } else if (NULL == post) {
201
+ if (NULL != bp->left || NULL != bp->right)
202
+ post = print_otag(p, TAG_MFENCED, "??",
203
+ "open", bp->left == NULL ? "" : bp->left,
204
+ "close", bp->right == NULL ? "" : bp->right);
205
+ if (NULL == post)
206
+ post = print_otag(p, TAG_MROW, "");
207
+ else
208
+ print_otag(p, TAG_MROW, "");
209
+ }
210
+
211
+ eqn_box(p, bp->first);
212
+
213
+ out:
214
+ if (NULL != bp->bottom) {
215
+ t = print_otag(p, TAG_MO, "");
216
+ print_text(p, bp->bottom);
217
+ print_tagq(p, t);
218
+ }
219
+ if (NULL != bp->top) {
220
+ t = print_otag(p, TAG_MO, "");
221
+ print_text(p, bp->top);
222
+ print_tagq(p, t);
223
+ }
224
+
225
+ if (NULL != post)
226
+ print_tagq(p, post);
227
+
228
+ eqn_box(p, bp->next);
229
+ }
230
+
231
+ void
232
+ print_eqn(struct html *p, const struct eqn_box *bp)
233
+ {
234
+ struct tag *t;
235
+
236
+ if (bp->first == NULL)
237
+ return;
238
+
239
+ t = print_otag(p, TAG_MATH, "c", "eqn");
240
+
241
+ p->flags |= HTML_NONOSPACE;
242
+ eqn_box(p, bp);
243
+ p->flags &= ~HTML_NONOSPACE;
244
+
245
+ print_tagq(p, t);
246
+ }
@@ -0,0 +1,48 @@
1
+ /* $Id: eqn_parse.h,v 1.3 2018/12/14 06:33:14 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4
+ * Copyright (c) 2014, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
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 AUTHORS DISCLAIM ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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
+ *
18
+ * External interface of the eqn(7) parser.
19
+ * For use in the roff(7) and eqn(7) parsers only.
20
+ */
21
+
22
+ struct roff_node;
23
+ struct eqn_box;
24
+ struct eqn_def;
25
+
26
+ struct eqn_node {
27
+ struct roff_node *node; /* Syntax tree of this equation. */
28
+ struct eqn_def *defs; /* Array of definitions. */
29
+ char *data; /* Source code of this equation. */
30
+ char *start; /* First byte of the current token. */
31
+ char *end; /* First byte of the next token. */
32
+ size_t defsz; /* Number of definitions. */
33
+ size_t sz; /* Length of the source code. */
34
+ size_t toksz; /* Length of the current token. */
35
+ int gsize; /* Default point size. */
36
+ int delim; /* In-line delimiters enabled. */
37
+ char odelim; /* In-line opening delimiter. */
38
+ char cdelim; /* In-line closing delimiter. */
39
+ };
40
+
41
+
42
+ struct eqn_node *eqn_alloc(void);
43
+ struct eqn_box *eqn_box_new(void);
44
+ void eqn_box_free(struct eqn_box *);
45
+ void eqn_free(struct eqn_node *);
46
+ void eqn_parse(struct eqn_node *);
47
+ void eqn_read(struct eqn_node *, const char *);
48
+ void eqn_reset(struct eqn_node *);
@@ -0,0 +1,174 @@
1
+ /* $Id: eqn_term.c,v 1.19 2018/12/13 05:23:38 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4
+ * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
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
+ */
18
+ #include "config.h"
19
+
20
+ #include <sys/types.h>
21
+
22
+ #include <assert.h>
23
+ #include <ctype.h>
24
+ #include <stdio.h>
25
+ #include <stdlib.h>
26
+ #include <string.h>
27
+
28
+ #include "eqn.h"
29
+ #include "out.h"
30
+ #include "term.h"
31
+
32
+ static const enum termfont fontmap[EQNFONT__MAX] = {
33
+ TERMFONT_NONE, /* EQNFONT_NONE */
34
+ TERMFONT_NONE, /* EQNFONT_ROMAN */
35
+ TERMFONT_BOLD, /* EQNFONT_BOLD */
36
+ TERMFONT_BOLD, /* EQNFONT_FAT */
37
+ TERMFONT_UNDER /* EQNFONT_ITALIC */
38
+ };
39
+
40
+ static void eqn_box(struct termp *, const struct eqn_box *);
41
+
42
+
43
+ void
44
+ term_eqn(struct termp *p, const struct eqn_box *bp)
45
+ {
46
+
47
+ eqn_box(p, bp);
48
+ p->flags &= ~TERMP_NOSPACE;
49
+ }
50
+
51
+ static void
52
+ eqn_box(struct termp *p, const struct eqn_box *bp)
53
+ {
54
+ const struct eqn_box *child;
55
+ const char *cp;
56
+ int delim;
57
+
58
+ /* Delimiters around this box? */
59
+
60
+ if ((bp->type == EQN_LIST && bp->expectargs > 1) ||
61
+ (bp->type == EQN_PILE && (bp->prev || bp->next)) ||
62
+ (bp->parent != NULL && (bp->parent->pos == EQNPOS_SQRT ||
63
+ /* Diacritic followed by ^ or _. */
64
+ ((bp->top != NULL || bp->bottom != NULL) &&
65
+ bp->parent->type == EQN_SUBEXPR &&
66
+ bp->parent->pos != EQNPOS_OVER && bp->next != NULL) ||
67
+ /* Nested over, sub, sup, from, to. */
68
+ (bp->type == EQN_SUBEXPR && bp->pos != EQNPOS_SQRT &&
69
+ ((bp->parent->type == EQN_LIST && bp->expectargs == 1) ||
70
+ (bp->parent->type == EQN_SUBEXPR &&
71
+ bp->pos != EQNPOS_SQRT)))))) {
72
+ if ((bp->parent->type == EQN_SUBEXPR && bp->prev != NULL) ||
73
+ (bp->type == EQN_LIST &&
74
+ bp->first != NULL &&
75
+ bp->first->type != EQN_PILE &&
76
+ bp->first->type != EQN_MATRIX &&
77
+ bp->prev != NULL &&
78
+ (bp->prev->type == EQN_LIST ||
79
+ (bp->prev->type == EQN_TEXT &&
80
+ (*bp->prev->text == '\\' ||
81
+ isalpha((unsigned char)*bp->prev->text))))))
82
+ p->flags |= TERMP_NOSPACE;
83
+ term_word(p, bp->left != NULL ? bp->left : "(");
84
+ p->flags |= TERMP_NOSPACE;
85
+ delim = 1;
86
+ } else
87
+ delim = 0;
88
+
89
+ /* Handle Fonts and text. */
90
+
91
+ if (bp->font != EQNFONT_NONE)
92
+ term_fontpush(p, fontmap[(int)bp->font]);
93
+
94
+ if (bp->text != NULL) {
95
+ if (strchr("!\"'),.:;?]}", *bp->text) != NULL)
96
+ p->flags |= TERMP_NOSPACE;
97
+ term_word(p, bp->text);
98
+ if ((cp = strchr(bp->text, '\0')) > bp->text &&
99
+ (strchr("\"'([{", cp[-1]) != NULL ||
100
+ (bp->prev == NULL && (cp[-1] == '-' ||
101
+ (cp >= bp->text + 5 &&
102
+ strcmp(cp - 5, "\\[mi]") == 0)))))
103
+ p->flags |= TERMP_NOSPACE;
104
+ }
105
+
106
+ /* Special box types. */
107
+
108
+ if (bp->pos == EQNPOS_SQRT) {
109
+ term_word(p, "\\(sr");
110
+ if (bp->first != NULL) {
111
+ p->flags |= TERMP_NOSPACE;
112
+ eqn_box(p, bp->first);
113
+ }
114
+ } else if (bp->type == EQN_SUBEXPR) {
115
+ child = bp->first;
116
+ eqn_box(p, child);
117
+ p->flags |= TERMP_NOSPACE;
118
+ term_word(p, bp->pos == EQNPOS_OVER ? "/" :
119
+ (bp->pos == EQNPOS_SUP ||
120
+ bp->pos == EQNPOS_TO) ? "^" : "_");
121
+ child = child->next;
122
+ if (child != NULL) {
123
+ p->flags |= TERMP_NOSPACE;
124
+ eqn_box(p, child);
125
+ if (bp->pos == EQNPOS_FROMTO ||
126
+ bp->pos == EQNPOS_SUBSUP) {
127
+ p->flags |= TERMP_NOSPACE;
128
+ term_word(p, "^");
129
+ p->flags |= TERMP_NOSPACE;
130
+ child = child->next;
131
+ if (child != NULL)
132
+ eqn_box(p, child);
133
+ }
134
+ }
135
+ } else {
136
+ child = bp->first;
137
+ if (bp->type == EQN_MATRIX &&
138
+ child != NULL &&
139
+ child->type == EQN_LIST &&
140
+ child->expectargs > 1)
141
+ child = child->first;
142
+ while (child != NULL) {
143
+ eqn_box(p,
144
+ bp->type == EQN_PILE &&
145
+ child->type == EQN_LIST &&
146
+ child->expectargs > 1 &&
147
+ child->args == 1 ?
148
+ child->first : child);
149
+ child = child->next;
150
+ }
151
+ }
152
+
153
+ /* Handle Fonts and diacritics. */
154
+
155
+ if (bp->font != EQNFONT_NONE)
156
+ term_fontpop(p);
157
+ if (bp->top != NULL) {
158
+ p->flags |= TERMP_NOSPACE;
159
+ term_word(p, bp->top);
160
+ }
161
+ if (bp->bottom != NULL) {
162
+ p->flags |= TERMP_NOSPACE;
163
+ term_word(p, "_");
164
+ }
165
+
166
+ /* Right delimiter after this box? */
167
+
168
+ if (delim) {
169
+ p->flags |= TERMP_NOSPACE;
170
+ term_word(p, bp->right != NULL ? bp->right : ")");
171
+ if (bp->parent->type == EQN_SUBEXPR && bp->next != NULL)
172
+ p->flags |= TERMP_NOSPACE;
173
+ }
174
+ }