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,158 @@
1
+ /* $Id: term.h,v 1.131 2019/01/04 03:21:02 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4
+ * Copyright (c) 2011-2015, 2017, 2019 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
+
19
+ enum termenc {
20
+ TERMENC_ASCII,
21
+ TERMENC_LOCALE,
22
+ TERMENC_UTF8
23
+ };
24
+
25
+ enum termtype {
26
+ TERMTYPE_CHAR,
27
+ TERMTYPE_PS,
28
+ TERMTYPE_PDF
29
+ };
30
+
31
+ enum termfont {
32
+ TERMFONT_NONE = 0,
33
+ TERMFONT_BOLD,
34
+ TERMFONT_UNDER,
35
+ TERMFONT_BI,
36
+ TERMFONT__MAX
37
+ };
38
+
39
+ struct eqn_box;
40
+ struct roff_meta;
41
+ struct roff_node;
42
+ struct tbl_span;
43
+ struct termp;
44
+
45
+ typedef void (*term_margin)(struct termp *, const struct roff_meta *);
46
+
47
+ struct termp_tbl {
48
+ int width; /* width in fixed chars */
49
+ int decimal; /* decimal point position */
50
+ };
51
+
52
+ struct termp_col {
53
+ int *buf; /* Output buffer. */
54
+ size_t maxcols; /* Allocated bytes in buf. */
55
+ size_t lastcol; /* Last byte in buf. */
56
+ size_t col; /* Byte in buf to be written. */
57
+ size_t rmargin; /* Current right margin. */
58
+ size_t offset; /* Current left margin. */
59
+ };
60
+
61
+ struct termp {
62
+ struct rofftbl tbl; /* Table configuration. */
63
+ struct termp_col *tcols; /* Array of table columns. */
64
+ struct termp_col *tcol; /* Current table column. */
65
+ size_t maxtcol; /* Allocated table columns. */
66
+ size_t lasttcol; /* Last column currently used. */
67
+ size_t line; /* Current output line number. */
68
+ size_t defindent; /* Default indent for text. */
69
+ size_t defrmargin; /* Right margin of the device. */
70
+ size_t lastrmargin; /* Right margin before the last ll. */
71
+ size_t maxrmargin; /* Max right margin. */
72
+ size_t col; /* Byte position in buf. */
73
+ size_t viscol; /* Chars on current line. */
74
+ size_t trailspace; /* See term_flushln(). */
75
+ size_t minbl; /* Minimum blanks before next field. */
76
+ int synopsisonly; /* Print the synopsis only. */
77
+ int mdocstyle; /* Imitate mdoc(7) output. */
78
+ int ti; /* Temporary indent for one line. */
79
+ int skipvsp; /* Vertical space to skip. */
80
+ int flags;
81
+ #define TERMP_SENTENCE (1 << 0) /* Space before a sentence. */
82
+ #define TERMP_NOSPACE (1 << 1) /* No space before words. */
83
+ #define TERMP_NONOSPACE (1 << 2) /* No space (no autounset). */
84
+ #define TERMP_NBRWORD (1 << 3) /* Make next word nonbreaking. */
85
+ #define TERMP_KEEP (1 << 4) /* Keep words together. */
86
+ #define TERMP_PREKEEP (1 << 5) /* ...starting with the next one. */
87
+ #define TERMP_BACKAFTER (1 << 6) /* Back up after next character. */
88
+ #define TERMP_BACKBEFORE (1 << 7) /* Back up before next character. */
89
+ #define TERMP_NOBREAK (1 << 8) /* See term_flushln(). */
90
+ #define TERMP_BRTRSP (1 << 9) /* See term_flushln(). */
91
+ #define TERMP_BRIND (1 << 10) /* See term_flushln(). */
92
+ #define TERMP_HANG (1 << 11) /* See term_flushln(). */
93
+ #define TERMP_NOPAD (1 << 12) /* See term_flushln(). */
94
+ #define TERMP_NOSPLIT (1 << 13) /* Do not break line before .An. */
95
+ #define TERMP_SPLIT (1 << 14) /* Break line before .An. */
96
+ #define TERMP_NONEWLINE (1 << 15) /* No line break in nofill mode. */
97
+ #define TERMP_BRNEVER (1 << 16) /* Don't even break at maxrmargin. */
98
+ #define TERMP_NOBUF (1 << 17) /* Bypass output buffer. */
99
+ #define TERMP_NEWMC (1 << 18) /* No .mc printed yet. */
100
+ #define TERMP_ENDMC (1 << 19) /* Next break ends .mc mode. */
101
+ #define TERMP_MULTICOL (1 << 20) /* Multiple column mode. */
102
+ #define TERMP_CENTER (1 << 21) /* Center output lines. */
103
+ #define TERMP_RIGHT (1 << 22) /* Adjust to the right margin. */
104
+ enum termtype type; /* Terminal, PS, or PDF. */
105
+ enum termenc enc; /* Type of encoding. */
106
+ enum termfont fontl; /* Last font set. */
107
+ enum termfont *fontq; /* Symmetric fonts. */
108
+ int fontsz; /* Allocated size of font stack */
109
+ int fonti; /* Index of font stack. */
110
+ term_margin headf; /* invoked to print head */
111
+ term_margin footf; /* invoked to print foot */
112
+ void (*letter)(struct termp *, int);
113
+ void (*begin)(struct termp *);
114
+ void (*end)(struct termp *);
115
+ void (*endline)(struct termp *);
116
+ void (*advance)(struct termp *, size_t);
117
+ void (*setwidth)(struct termp *, int, int);
118
+ size_t (*width)(const struct termp *, int);
119
+ int (*hspan)(const struct termp *,
120
+ const struct roffsu *);
121
+ const void *argf; /* arg for headf/footf */
122
+ const char *mc; /* Margin character. */
123
+ struct termp_ps *ps;
124
+ };
125
+
126
+
127
+ const char *ascii_uc2str(int);
128
+
129
+ void roff_term_pre(struct termp *, const struct roff_node *);
130
+
131
+ void term_eqn(struct termp *, const struct eqn_box *);
132
+ void term_tbl(struct termp *, const struct tbl_span *);
133
+ void term_free(struct termp *);
134
+ void term_setcol(struct termp *, size_t);
135
+ void term_newln(struct termp *);
136
+ void term_vspace(struct termp *);
137
+ void term_word(struct termp *, const char *);
138
+ void term_flushln(struct termp *);
139
+ void term_begin(struct termp *, term_margin,
140
+ term_margin, const struct roff_meta *);
141
+ void term_end(struct termp *);
142
+
143
+ void term_setwidth(struct termp *, const char *);
144
+ int term_hspan(const struct termp *, const struct roffsu *);
145
+ int term_hen(const struct termp *, const struct roffsu *);
146
+ int term_vspan(const struct termp *, const struct roffsu *);
147
+ size_t term_strlen(const struct termp *, const char *);
148
+ size_t term_len(const struct termp *, size_t);
149
+
150
+ void term_tab_set(const struct termp *, const char *);
151
+ void term_tab_iset(size_t);
152
+ size_t term_tab_next(size_t);
153
+
154
+ void term_fontpush(struct termp *, enum termfont);
155
+ void term_fontpop(struct termp *);
156
+ void term_fontpopq(struct termp *, int);
157
+ void term_fontrepl(struct termp *, enum termfont);
158
+ void term_fontlast(struct termp *);
@@ -0,0 +1,424 @@
1
+ /* $Id: term_ascii.c,v 1.66 2020/09/09 13:45:05 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4
+ * Copyright (c) 2014,2015,2017,2018,2020 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
+ #include "config.h"
19
+
20
+ #include <sys/types.h>
21
+
22
+ #include <assert.h>
23
+ #if HAVE_WCHAR
24
+ #include <langinfo.h>
25
+ #include <locale.h>
26
+ #endif
27
+ #include <stdint.h>
28
+ #include <stdio.h>
29
+ #include <stdlib.h>
30
+ #include <string.h>
31
+ #include <unistd.h>
32
+ #if HAVE_WCHAR
33
+ #include <wchar.h>
34
+ #endif
35
+
36
+ #include "mandoc.h"
37
+ #include "mandoc_aux.h"
38
+ #include "out.h"
39
+ #include "term.h"
40
+ #include "manconf.h"
41
+ #include "main.h"
42
+
43
+ static struct termp *ascii_init(enum termenc, const struct manoutput *);
44
+ static int ascii_hspan(const struct termp *,
45
+ const struct roffsu *);
46
+ static size_t ascii_width(const struct termp *, int);
47
+ static void ascii_advance(struct termp *, size_t);
48
+ static void ascii_begin(struct termp *);
49
+ static void ascii_end(struct termp *);
50
+ static void ascii_endline(struct termp *);
51
+ static void ascii_letter(struct termp *, int);
52
+ static void ascii_setwidth(struct termp *, int, int);
53
+
54
+ #if HAVE_WCHAR
55
+ static void locale_advance(struct termp *, size_t);
56
+ static void locale_endline(struct termp *);
57
+ static void locale_letter(struct termp *, int);
58
+ static size_t locale_width(const struct termp *, int);
59
+ #endif
60
+
61
+
62
+ static struct termp *
63
+ ascii_init(enum termenc enc, const struct manoutput *outopts)
64
+ {
65
+ #if HAVE_WCHAR
66
+ char *v;
67
+ #endif
68
+ struct termp *p;
69
+
70
+ p = mandoc_calloc(1, sizeof(*p));
71
+ p->tcol = p->tcols = mandoc_calloc(1, sizeof(*p->tcol));
72
+ p->maxtcol = 1;
73
+
74
+ p->line = 1;
75
+ p->defrmargin = p->lastrmargin = 78;
76
+ p->fontq = mandoc_reallocarray(NULL,
77
+ (p->fontsz = 8), sizeof(*p->fontq));
78
+ p->fontq[0] = p->fontl = TERMFONT_NONE;
79
+
80
+ p->begin = ascii_begin;
81
+ p->end = ascii_end;
82
+ p->hspan = ascii_hspan;
83
+ p->type = TERMTYPE_CHAR;
84
+
85
+ p->enc = TERMENC_ASCII;
86
+ p->advance = ascii_advance;
87
+ p->endline = ascii_endline;
88
+ p->letter = ascii_letter;
89
+ p->setwidth = ascii_setwidth;
90
+ p->width = ascii_width;
91
+
92
+ #if HAVE_WCHAR
93
+ if (enc != TERMENC_ASCII) {
94
+
95
+ /*
96
+ * Do not change any of this to LC_ALL. It might break
97
+ * the formatting by subtly changing the behaviour of
98
+ * various functions, for example strftime(3). As a
99
+ * worst case, it might even cause buffer overflows.
100
+ */
101
+
102
+ v = enc == TERMENC_LOCALE ?
103
+ setlocale(LC_CTYPE, "") :
104
+ setlocale(LC_CTYPE, UTF8_LOCALE);
105
+
106
+ /*
107
+ * We only support UTF-8,
108
+ * so revert to ASCII for anything else.
109
+ */
110
+
111
+ if (v != NULL &&
112
+ strcmp(nl_langinfo(CODESET), "UTF-8") != 0)
113
+ v = setlocale(LC_CTYPE, "C");
114
+
115
+ if (v != NULL && MB_CUR_MAX > 1) {
116
+ p->enc = TERMENC_UTF8;
117
+ p->advance = locale_advance;
118
+ p->endline = locale_endline;
119
+ p->letter = locale_letter;
120
+ p->width = locale_width;
121
+ }
122
+ }
123
+ #endif
124
+
125
+ if (outopts->mdoc) {
126
+ p->mdocstyle = 1;
127
+ p->defindent = 5;
128
+ }
129
+ if (outopts->indent)
130
+ p->defindent = outopts->indent;
131
+ if (outopts->width)
132
+ p->defrmargin = outopts->width;
133
+ if (outopts->synopsisonly)
134
+ p->synopsisonly = 1;
135
+
136
+ assert(p->defindent < UINT16_MAX);
137
+ assert(p->defrmargin < UINT16_MAX);
138
+ return p;
139
+ }
140
+
141
+ void *
142
+ ascii_alloc(const struct manoutput *outopts)
143
+ {
144
+
145
+ return ascii_init(TERMENC_ASCII, outopts);
146
+ }
147
+
148
+ void *
149
+ utf8_alloc(const struct manoutput *outopts)
150
+ {
151
+
152
+ return ascii_init(TERMENC_UTF8, outopts);
153
+ }
154
+
155
+ void *
156
+ locale_alloc(const struct manoutput *outopts)
157
+ {
158
+
159
+ return ascii_init(TERMENC_LOCALE, outopts);
160
+ }
161
+
162
+ static void
163
+ ascii_setwidth(struct termp *p, int iop, int width)
164
+ {
165
+
166
+ width /= 24;
167
+ p->tcol->rmargin = p->defrmargin;
168
+ if (iop > 0)
169
+ p->defrmargin += width;
170
+ else if (iop == 0)
171
+ p->defrmargin = width ? (size_t)width : p->lastrmargin;
172
+ else if (p->defrmargin > (size_t)width)
173
+ p->defrmargin -= width;
174
+ else
175
+ p->defrmargin = 0;
176
+ if (p->defrmargin > 1000)
177
+ p->defrmargin = 1000;
178
+ p->lastrmargin = p->tcol->rmargin;
179
+ p->tcol->rmargin = p->maxrmargin = p->defrmargin;
180
+ }
181
+
182
+ void
183
+ terminal_sepline(void *arg)
184
+ {
185
+ struct termp *p;
186
+ size_t i;
187
+
188
+ p = (struct termp *)arg;
189
+ (*p->endline)(p);
190
+ for (i = 0; i < p->defrmargin; i++)
191
+ (*p->letter)(p, '-');
192
+ (*p->endline)(p);
193
+ (*p->endline)(p);
194
+ }
195
+
196
+ static size_t
197
+ ascii_width(const struct termp *p, int c)
198
+ {
199
+ return c != ASCII_BREAK;
200
+ }
201
+
202
+ void
203
+ ascii_free(void *arg)
204
+ {
205
+
206
+ term_free((struct termp *)arg);
207
+ }
208
+
209
+ static void
210
+ ascii_letter(struct termp *p, int c)
211
+ {
212
+
213
+ putchar(c);
214
+ }
215
+
216
+ static void
217
+ ascii_begin(struct termp *p)
218
+ {
219
+
220
+ (*p->headf)(p, p->argf);
221
+ }
222
+
223
+ static void
224
+ ascii_end(struct termp *p)
225
+ {
226
+
227
+ (*p->footf)(p, p->argf);
228
+ }
229
+
230
+ static void
231
+ ascii_endline(struct termp *p)
232
+ {
233
+
234
+ p->line++;
235
+ if ((int)p->tcol->offset > p->ti)
236
+ p->tcol->offset -= p->ti;
237
+ else
238
+ p->tcol->offset = 0;
239
+ p->ti = 0;
240
+ putchar('\n');
241
+ }
242
+
243
+ static void
244
+ ascii_advance(struct termp *p, size_t len)
245
+ {
246
+ size_t i;
247
+
248
+ /*
249
+ * XXX We used to have "assert(len < UINT16_MAX)" here.
250
+ * that is not quite right because the input document
251
+ * can trigger that by merely providing large input.
252
+ * For now, simply truncate.
253
+ */
254
+ if (len > 256)
255
+ len = 256;
256
+ for (i = 0; i < len; i++)
257
+ putchar(' ');
258
+ }
259
+
260
+ static int
261
+ ascii_hspan(const struct termp *p, const struct roffsu *su)
262
+ {
263
+ double r;
264
+
265
+ switch (su->unit) {
266
+ case SCALE_BU:
267
+ r = su->scale;
268
+ break;
269
+ case SCALE_CM:
270
+ r = su->scale * 240.0 / 2.54;
271
+ break;
272
+ case SCALE_FS:
273
+ r = su->scale * 65536.0;
274
+ break;
275
+ case SCALE_IN:
276
+ r = su->scale * 240.0;
277
+ break;
278
+ case SCALE_MM:
279
+ r = su->scale * 0.24;
280
+ break;
281
+ case SCALE_VS:
282
+ case SCALE_PC:
283
+ r = su->scale * 40.0;
284
+ break;
285
+ case SCALE_PT:
286
+ r = su->scale * 10.0 / 3.0;
287
+ break;
288
+ case SCALE_EN:
289
+ case SCALE_EM:
290
+ r = su->scale * 24.0;
291
+ break;
292
+ default:
293
+ abort();
294
+ }
295
+ return r > 0.0 ? r + 0.01 : r - 0.01;
296
+ }
297
+
298
+ const char *
299
+ ascii_uc2str(int uc)
300
+ {
301
+ static const char nbrsp[2] = { ASCII_NBRSP, '\0' };
302
+ static const char *tab[] = {
303
+ "<NUL>","<SOH>","<STX>","<ETX>","<EOT>","<ENQ>","<ACK>","<BEL>",
304
+ "<BS>", "\t", "<LF>", "<VT>", "<FF>", "<CR>", "<SO>", "<SI>",
305
+ "<DLE>","<DC1>","<DC2>","<DC3>","<DC4>","<NAK>","<SYN>","<ETB>",
306
+ "<CAN>","<EM>", "<SUB>","<ESC>","<FS>", "<GS>", "<RS>", "<US>",
307
+ " ", "!", "\"", "#", "$", "%", "&", "'",
308
+ "(", ")", "*", "+", ",", "-", ".", "/",
309
+ "0", "1", "2", "3", "4", "5", "6", "7",
310
+ "8", "9", ":", ";", "<", "=", ">", "?",
311
+ "@", "A", "B", "C", "D", "E", "F", "G",
312
+ "H", "I", "J", "K", "L", "M", "N", "O",
313
+ "P", "Q", "R", "S", "T", "U", "V", "W",
314
+ "X", "Y", "Z", "[", "\\", "]", "^", "_",
315
+ "`", "a", "b", "c", "d", "e", "f", "g",
316
+ "h", "i", "j", "k", "l", "m", "n", "o",
317
+ "p", "q", "r", "s", "t", "u", "v", "w",
318
+ "x", "y", "z", "{", "|", "}", "~", "<DEL>",
319
+ "<80>", "<81>", "<82>", "<83>", "<84>", "<85>", "<86>", "<87>",
320
+ "<88>", "<89>", "<8A>", "<8B>", "<8C>", "<8D>", "<8E>", "<8F>",
321
+ "<90>", "<91>", "<92>", "<93>", "<94>", "<95>", "<96>", "<97>",
322
+ "<98>", "<99>", "<9A>", "<9B>", "<9C>", "<9D>", "<9E>", "<9F>",
323
+ nbrsp, "!", "/\bc", "-\bL", "o\bx", "=\bY", "|", "<section>",
324
+ "\"", "(C)", "_\ba", "<<", "~", "", "(R)", "-",
325
+ "<degree>","+-","^2", "^3", "'","<micro>","<paragraph>",".",
326
+ ",", "^1", "_\bo", ">>", "1/4", "1/2", "3/4", "?",
327
+ "`\bA", "'\bA", "^\bA", "~\bA", "\"\bA","o\bA", "AE", ",\bC",
328
+ "`\bE", "'\bE", "^\bE", "\"\bE","`\bI", "'\bI", "^\bI", "\"\bI",
329
+ "Dh", "~\bN", "`\bO", "'\bO", "^\bO", "~\bO", "\"\bO","x",
330
+ "/\bO", "`\bU", "'\bU", "^\bU", "\"\bU","'\bY", "Th", "ss",
331
+ "`\ba", "'\ba", "^\ba", "~\ba", "\"\ba","o\ba", "ae", ",\bc",
332
+ "`\be", "'\be", "^\be", "\"\be","`\bi", "'\bi", "^\bi", "\"\bi",
333
+ "dh", "~\bn", "`\bo", "'\bo", "^\bo", "~\bo", "\"\bo","/",
334
+ "/\bo", "`\bu", "'\bu", "^\bu", "\"\bu","'\by", "th", "\"\by",
335
+ "A", "a", "A", "a", "A", "a", "'\bC", "'\bc",
336
+ "^\bC", "^\bc", "C", "c", "C", "c", "D", "d",
337
+ "/\bD", "/\bd", "E", "e", "E", "e", "E", "e",
338
+ "E", "e", "E", "e", "^\bG", "^\bg", "G", "g",
339
+ "G", "g", ",\bG", ",\bg", "^\bH", "^\bh", "/\bH", "/\bh",
340
+ "~\bI", "~\bi", "I", "i", "I", "i", "I", "i",
341
+ "I", "i", "IJ", "ij", "^\bJ", "^\bj", ",\bK", ",\bk",
342
+ "q", "'\bL", "'\bl", ",\bL", ",\bl", "L", "l", "L",
343
+ "l", "/\bL", "/\bl", "'\bN", "'\bn", ",\bN", ",\bn", "N",
344
+ "n", "'n", "Ng", "ng", "O", "o", "O", "o",
345
+ "O", "o", "OE", "oe", "'\bR", "'\br", ",\bR", ",\br",
346
+ "R", "r", "'\bS", "'\bs", "^\bS", "^\bs", ",\bS", ",\bs",
347
+ "S", "s", ",\bT", ",\bt", "T", "t", "/\bT", "/\bt",
348
+ "~\bU", "~\bu", "U", "u", "U", "u", "U", "u",
349
+ "U", "u", "U", "u", "^\bW", "^\bw", "^\bY", "^\by",
350
+ "\"\bY","'\bZ", "'\bz", "Z", "z", "Z", "z", "s",
351
+ "b", "B", "B", "b", "6", "6", "O", "C",
352
+ "c", "D", "D", "D", "d", "d", "3", "@",
353
+ "E", "F", ",\bf", "G", "G", "hv", "I", "/\bI",
354
+ "K", "k", "/\bl", "l", "W", "N", "n", "~\bO",
355
+ "O", "o", "OI", "oi", "P", "p", "YR", "2",
356
+ "2", "SH", "sh", "t", "T", "t", "T", "U",
357
+ "u", "Y", "V", "Y", "y", "/\bZ", "/\bz", "ZH",
358
+ "ZH", "zh", "zh", "/\b2", "5", "5", "ts", "w",
359
+ "|", "||", "|=", "!", "DZ", "Dz", "dz", "LJ",
360
+ "Lj", "lj", "NJ", "Nj", "nj", "A", "a", "I",
361
+ "i", "O", "o", "U", "u", "U", "u", "U",
362
+ "u", "U", "u", "U", "u", "@", "A", "a",
363
+ "A", "a", "AE", "ae", "/\bG", "/\bg", "G", "g",
364
+ "K", "k", "O", "o", "O", "o", "ZH", "zh",
365
+ "j", "DZ", "Dz", "dz", "'\bG", "'\bg", "HV", "W",
366
+ "`\bN", "`\bn", "A", "a", "'\bAE","'\bae","O", "o"};
367
+
368
+ assert(uc >= 0);
369
+ if ((size_t)uc < sizeof(tab)/sizeof(tab[0]))
370
+ return tab[uc];
371
+ return mchars_uc2str(uc);
372
+ }
373
+
374
+ #if HAVE_WCHAR
375
+ static size_t
376
+ locale_width(const struct termp *p, int c)
377
+ {
378
+ int rc;
379
+
380
+ if (c == ASCII_NBRSP)
381
+ c = ' ';
382
+ rc = wcwidth(c);
383
+ if (rc < 0)
384
+ rc = 0;
385
+ return rc;
386
+ }
387
+
388
+ static void
389
+ locale_advance(struct termp *p, size_t len)
390
+ {
391
+ size_t i;
392
+
393
+ /*
394
+ * XXX We used to have "assert(len < UINT16_MAX)" here.
395
+ * that is not quite right because the input document
396
+ * can trigger that by merely providing large input.
397
+ * For now, simply truncate.
398
+ */
399
+ if (len > 256)
400
+ len = 256;
401
+ for (i = 0; i < len; i++)
402
+ putwchar(L' ');
403
+ }
404
+
405
+ static void
406
+ locale_endline(struct termp *p)
407
+ {
408
+
409
+ p->line++;
410
+ if ((int)p->tcol->offset > p->ti)
411
+ p->tcol->offset -= p->ti;
412
+ else
413
+ p->tcol->offset = 0;
414
+ p->ti = 0;
415
+ putwchar(L'\n');
416
+ }
417
+
418
+ static void
419
+ locale_letter(struct termp *p, int c)
420
+ {
421
+
422
+ putwchar(c);
423
+ }
424
+ #endif