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,256 @@
1
+ /* $Id: mdoc_state.c,v 1.17 2020/06/22 19:20:40 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2014, 2015, 2017 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
+ */
17
+ #include "config.h"
18
+
19
+ #include <sys/types.h>
20
+
21
+ #include <assert.h>
22
+ #include <stdio.h>
23
+ #include <stdlib.h>
24
+ #include <string.h>
25
+
26
+ #include "mandoc.h"
27
+ #include "roff.h"
28
+ #include "mdoc.h"
29
+ #include "libmandoc.h"
30
+ #include "roff_int.h"
31
+ #include "libmdoc.h"
32
+
33
+ #define STATE_ARGS struct roff_man *mdoc, struct roff_node *n
34
+
35
+ typedef void (*state_handler)(STATE_ARGS);
36
+
37
+ static void state_bl(STATE_ARGS);
38
+ static void state_sh(STATE_ARGS);
39
+ static void state_sm(STATE_ARGS);
40
+
41
+ static const state_handler state_handlers[MDOC_MAX - MDOC_Dd] = {
42
+ NULL, /* Dd */
43
+ NULL, /* Dt */
44
+ NULL, /* Os */
45
+ state_sh, /* Sh */
46
+ NULL, /* Ss */
47
+ NULL, /* Pp */
48
+ NULL, /* D1 */
49
+ NULL, /* Dl */
50
+ NULL, /* Bd */
51
+ NULL, /* Ed */
52
+ state_bl, /* Bl */
53
+ NULL, /* El */
54
+ NULL, /* It */
55
+ NULL, /* Ad */
56
+ NULL, /* An */
57
+ NULL, /* Ap */
58
+ NULL, /* Ar */
59
+ NULL, /* Cd */
60
+ NULL, /* Cm */
61
+ NULL, /* Dv */
62
+ NULL, /* Er */
63
+ NULL, /* Ev */
64
+ NULL, /* Ex */
65
+ NULL, /* Fa */
66
+ NULL, /* Fd */
67
+ NULL, /* Fl */
68
+ NULL, /* Fn */
69
+ NULL, /* Ft */
70
+ NULL, /* Ic */
71
+ NULL, /* In */
72
+ NULL, /* Li */
73
+ NULL, /* Nd */
74
+ NULL, /* Nm */
75
+ NULL, /* Op */
76
+ NULL, /* Ot */
77
+ NULL, /* Pa */
78
+ NULL, /* Rv */
79
+ NULL, /* St */
80
+ NULL, /* Va */
81
+ NULL, /* Vt */
82
+ NULL, /* Xr */
83
+ NULL, /* %A */
84
+ NULL, /* %B */
85
+ NULL, /* %D */
86
+ NULL, /* %I */
87
+ NULL, /* %J */
88
+ NULL, /* %N */
89
+ NULL, /* %O */
90
+ NULL, /* %P */
91
+ NULL, /* %R */
92
+ NULL, /* %T */
93
+ NULL, /* %V */
94
+ NULL, /* Ac */
95
+ NULL, /* Ao */
96
+ NULL, /* Aq */
97
+ NULL, /* At */
98
+ NULL, /* Bc */
99
+ NULL, /* Bf */
100
+ NULL, /* Bo */
101
+ NULL, /* Bq */
102
+ NULL, /* Bsx */
103
+ NULL, /* Bx */
104
+ NULL, /* Db */
105
+ NULL, /* Dc */
106
+ NULL, /* Do */
107
+ NULL, /* Dq */
108
+ NULL, /* Ec */
109
+ NULL, /* Ef */
110
+ NULL, /* Em */
111
+ NULL, /* Eo */
112
+ NULL, /* Fx */
113
+ NULL, /* Ms */
114
+ NULL, /* No */
115
+ NULL, /* Ns */
116
+ NULL, /* Nx */
117
+ NULL, /* Ox */
118
+ NULL, /* Pc */
119
+ NULL, /* Pf */
120
+ NULL, /* Po */
121
+ NULL, /* Pq */
122
+ NULL, /* Qc */
123
+ NULL, /* Ql */
124
+ NULL, /* Qo */
125
+ NULL, /* Qq */
126
+ NULL, /* Re */
127
+ NULL, /* Rs */
128
+ NULL, /* Sc */
129
+ NULL, /* So */
130
+ NULL, /* Sq */
131
+ state_sm, /* Sm */
132
+ NULL, /* Sx */
133
+ NULL, /* Sy */
134
+ NULL, /* Tn */
135
+ NULL, /* Ux */
136
+ NULL, /* Xc */
137
+ NULL, /* Xo */
138
+ NULL, /* Fo */
139
+ NULL, /* Fc */
140
+ NULL, /* Oo */
141
+ NULL, /* Oc */
142
+ NULL, /* Bk */
143
+ NULL, /* Ek */
144
+ NULL, /* Bt */
145
+ NULL, /* Hf */
146
+ NULL, /* Fr */
147
+ NULL, /* Ud */
148
+ NULL, /* Lb */
149
+ NULL, /* Lp */
150
+ NULL, /* Lk */
151
+ NULL, /* Mt */
152
+ NULL, /* Brq */
153
+ NULL, /* Bro */
154
+ NULL, /* Brc */
155
+ NULL, /* %C */
156
+ NULL, /* Es */
157
+ NULL, /* En */
158
+ NULL, /* Dx */
159
+ NULL, /* %Q */
160
+ NULL, /* %U */
161
+ NULL, /* Ta */
162
+ NULL, /* Tg */
163
+ };
164
+
165
+
166
+ void
167
+ mdoc_state(struct roff_man *mdoc, struct roff_node *n)
168
+ {
169
+ state_handler handler;
170
+
171
+ if (n->tok == TOKEN_NONE || n->tok < ROFF_MAX)
172
+ return;
173
+
174
+ assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
175
+ if ((mdoc_macro(n->tok)->flags & MDOC_PROLOGUE) == 0)
176
+ mdoc->flags |= MDOC_PBODY;
177
+
178
+ handler = state_handlers[n->tok - MDOC_Dd];
179
+ if (*handler)
180
+ (*handler)(mdoc, n);
181
+ }
182
+
183
+ static void
184
+ state_bl(STATE_ARGS)
185
+ {
186
+ struct mdoc_arg *args;
187
+ size_t i;
188
+
189
+ if (n->type != ROFFT_HEAD || n->parent->args == NULL)
190
+ return;
191
+
192
+ args = n->parent->args;
193
+ for (i = 0; i < args->argc; i++) {
194
+ switch(args->argv[i].arg) {
195
+ case MDOC_Diag:
196
+ n->norm->Bl.type = LIST_diag;
197
+ return;
198
+ case MDOC_Column:
199
+ n->norm->Bl.type = LIST_column;
200
+ return;
201
+ default:
202
+ break;
203
+ }
204
+ }
205
+ }
206
+
207
+ static void
208
+ state_sh(STATE_ARGS)
209
+ {
210
+ struct roff_node *nch;
211
+ char *secname;
212
+
213
+ if (n->type != ROFFT_HEAD)
214
+ return;
215
+
216
+ if ( ! (n->flags & NODE_VALID)) {
217
+ secname = NULL;
218
+ deroff(&secname, n);
219
+
220
+ /*
221
+ * Set the section attribute for the BLOCK, HEAD,
222
+ * and HEAD children; the latter can only be TEXT
223
+ * nodes, so no recursion is needed. For other
224
+ * nodes, including the .Sh BODY, this is done
225
+ * when allocating the node data structures, but
226
+ * for .Sh BLOCK and HEAD, the section is still
227
+ * unknown at that time.
228
+ */
229
+
230
+ n->sec = n->parent->sec = secname == NULL ?
231
+ SEC_CUSTOM : mdoc_a2sec(secname);
232
+ for (nch = n->child; nch != NULL; nch = nch->next)
233
+ nch->sec = n->sec;
234
+ free(secname);
235
+ }
236
+
237
+ if ((mdoc->lastsec = n->sec) == SEC_SYNOPSIS) {
238
+ roff_setreg(mdoc->roff, "nS", 1, '=');
239
+ mdoc->flags |= MDOC_SYNOPSIS;
240
+ } else {
241
+ roff_setreg(mdoc->roff, "nS", 0, '=');
242
+ mdoc->flags &= ~MDOC_SYNOPSIS;
243
+ }
244
+ }
245
+
246
+ static void
247
+ state_sm(STATE_ARGS)
248
+ {
249
+
250
+ if (n->child == NULL)
251
+ mdoc->flags ^= MDOC_SMOFF;
252
+ else if ( ! strcmp(n->child->string, "on"))
253
+ mdoc->flags &= ~MDOC_SMOFF;
254
+ else if ( ! strcmp(n->child->string, "off"))
255
+ mdoc->flags |= MDOC_SMOFF;
256
+ }