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,330 @@
1
+ /* $Id: compat_ohash.c,v 1.7 2020/06/15 01:37:15 schwarze Exp $ */
2
+ /* $OpenBSD: ohash.c,v 1.1 2014/06/02 18:52:03 deraadt Exp $ */
3
+
4
+ /* Copyright (c) 1999, 2004 Marc Espie <espie@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
+ #include <stddef.h>
22
+ #include <stdint.h>
23
+ #include <stdlib.h>
24
+ #include <string.h>
25
+ #include <limits.h>
26
+ #include "compat_ohash.h"
27
+
28
+ struct _ohash_record {
29
+ uint32_t hv;
30
+ const char *p;
31
+ };
32
+
33
+ #define DELETED ((const char *)h)
34
+ #define NONE (h->size)
35
+
36
+ /* Don't bother changing the hash table if the change is small enough. */
37
+ #define MINSIZE (1UL << 4)
38
+ #define MINDELETED 4
39
+
40
+ static void ohash_resize(struct ohash *);
41
+
42
+
43
+ /* This handles the common case of variable length keys, where the
44
+ * key is stored at the end of the record.
45
+ */
46
+ void *
47
+ ohash_create_entry(struct ohash_info *i, const char *start, const char **end)
48
+ {
49
+ char *p;
50
+
51
+ if (!*end)
52
+ *end = start + strlen(start);
53
+ p = (i->alloc)(i->key_offset + (*end - start) + 1, i->data);
54
+ if (p) {
55
+ memcpy(p+i->key_offset, start, *end-start);
56
+ p[i->key_offset + (*end - start)] = '\0';
57
+ }
58
+ return (void *)p;
59
+ }
60
+
61
+ /* hash_delete only frees the hash structure. Use hash_first/hash_next
62
+ * to free entries as well. */
63
+ void
64
+ ohash_delete(struct ohash *h)
65
+ {
66
+ (h->info.free)(h->t, h->info.data);
67
+ #ifndef NDEBUG
68
+ h->t = NULL;
69
+ #endif
70
+ }
71
+
72
+ static void
73
+ ohash_resize(struct ohash *h)
74
+ {
75
+ struct _ohash_record *n;
76
+ size_t ns;
77
+ unsigned int j;
78
+ unsigned int i, incr;
79
+
80
+ if (4 * h->deleted < h->total) {
81
+ if (h->size >= (UINT_MAX >> 1U))
82
+ ns = UINT_MAX;
83
+ else
84
+ ns = h->size << 1U;
85
+ } else if (3 * h->deleted > 2 * h->total)
86
+ ns = h->size >> 1U;
87
+ else
88
+ ns = h->size;
89
+ if (ns < MINSIZE)
90
+ ns = MINSIZE;
91
+ #ifdef STATS_HASH
92
+ STAT_HASH_EXPAND++;
93
+ STAT_HASH_SIZE += ns - h->size;
94
+ #endif
95
+
96
+ n = (h->info.calloc)(ns, sizeof(struct _ohash_record), h->info.data);
97
+ if (!n)
98
+ return;
99
+
100
+ for (j = 0; j < h->size; j++) {
101
+ if (h->t[j].p != NULL && h->t[j].p != DELETED) {
102
+ i = h->t[j].hv % ns;
103
+ incr = ((h->t[j].hv % (ns - 2)) & ~1) + 1;
104
+ while (n[i].p != NULL) {
105
+ i += incr;
106
+ if (i >= ns)
107
+ i -= ns;
108
+ }
109
+ n[i].hv = h->t[j].hv;
110
+ n[i].p = h->t[j].p;
111
+ }
112
+ }
113
+ (h->info.free)(h->t, h->info.data);
114
+ h->t = n;
115
+ h->size = ns;
116
+ h->total -= h->deleted;
117
+ h->deleted = 0;
118
+ }
119
+
120
+ void *
121
+ ohash_remove(struct ohash *h, unsigned int i)
122
+ {
123
+ void *result = (void *)h->t[i].p;
124
+
125
+ if (result == NULL || result == DELETED)
126
+ return NULL;
127
+
128
+ #ifdef STATS_HASH
129
+ STAT_HASH_ENTRIES--;
130
+ #endif
131
+ h->t[i].p = DELETED;
132
+ h->deleted++;
133
+ if (h->deleted >= MINDELETED && 4 * h->deleted > h->total)
134
+ ohash_resize(h);
135
+ return result;
136
+ }
137
+
138
+ void *
139
+ ohash_find(struct ohash *h, unsigned int i)
140
+ {
141
+ if (h->t[i].p == DELETED)
142
+ return NULL;
143
+ else
144
+ return (void *)h->t[i].p;
145
+ }
146
+
147
+ void *
148
+ ohash_insert(struct ohash *h, unsigned int i, void *p)
149
+ {
150
+ #ifdef STATS_HASH
151
+ STAT_HASH_ENTRIES++;
152
+ #endif
153
+ if (h->t[i].p == DELETED) {
154
+ h->deleted--;
155
+ h->t[i].p = p;
156
+ } else {
157
+ h->t[i].p = p;
158
+ /* Arbitrary resize boundary. Tweak if not efficient enough. */
159
+ if (++h->total * 4 > h->size * 3)
160
+ ohash_resize(h);
161
+ }
162
+ return p;
163
+ }
164
+
165
+ unsigned int
166
+ ohash_entries(struct ohash *h)
167
+ {
168
+ return h->total - h->deleted;
169
+ }
170
+
171
+ void *
172
+ ohash_first(struct ohash *h, unsigned int *pos)
173
+ {
174
+ *pos = 0;
175
+ return ohash_next(h, pos);
176
+ }
177
+
178
+ void *
179
+ ohash_next(struct ohash *h, unsigned int *pos)
180
+ {
181
+ for (; *pos < h->size; (*pos)++)
182
+ if (h->t[*pos].p != DELETED && h->t[*pos].p != NULL)
183
+ return (void *)h->t[(*pos)++].p;
184
+ return NULL;
185
+ }
186
+
187
+ void
188
+ ohash_init(struct ohash *h, unsigned int size, struct ohash_info *info)
189
+ {
190
+ h->size = 1UL << size;
191
+ if (h->size < MINSIZE)
192
+ h->size = MINSIZE;
193
+ #ifdef STATS_HASH
194
+ STAT_HASH_CREATION++;
195
+ STAT_HASH_SIZE += h->size;
196
+ #endif
197
+ /* Copy info so that caller may free it. */
198
+ h->info.key_offset = info->key_offset;
199
+ h->info.calloc = info->calloc;
200
+ h->info.free = info->free;
201
+ h->info.alloc = info->alloc;
202
+ h->info.data = info->data;
203
+ h->t = (h->info.calloc)(h->size, sizeof(struct _ohash_record),
204
+ h->info.data);
205
+ h->total = h->deleted = 0;
206
+ }
207
+
208
+ uint32_t
209
+ ohash_interval(const char *s, const char **e)
210
+ {
211
+ uint32_t k;
212
+
213
+ if (!*e)
214
+ *e = s + strlen(s);
215
+ if (s == *e)
216
+ k = 0;
217
+ else
218
+ k = *s++;
219
+ while (s != *e)
220
+ k = ((k << 2) | (k >> 30)) ^ *s++;
221
+ return k;
222
+ }
223
+
224
+ unsigned int
225
+ ohash_lookup_interval(struct ohash *h, const char *start, const char *end,
226
+ uint32_t hv)
227
+ {
228
+ unsigned int i, incr;
229
+ unsigned int empty;
230
+
231
+ #ifdef STATS_HASH
232
+ STAT_HASH_LOOKUP++;
233
+ #endif
234
+ empty = NONE;
235
+ i = hv % h->size;
236
+ incr = ((hv % (h->size-2)) & ~1) + 1;
237
+ while (h->t[i].p != NULL) {
238
+ #ifdef STATS_HASH
239
+ STAT_HASH_LENGTH++;
240
+ #endif
241
+ if (h->t[i].p == DELETED) {
242
+ if (empty == NONE)
243
+ empty = i;
244
+ } else if (h->t[i].hv == hv &&
245
+ strncmp(h->t[i].p+h->info.key_offset, start,
246
+ end - start) == 0 &&
247
+ (h->t[i].p+h->info.key_offset)[end-start] == '\0') {
248
+ if (empty != NONE) {
249
+ h->t[empty].hv = hv;
250
+ h->t[empty].p = h->t[i].p;
251
+ h->t[i].p = DELETED;
252
+ return empty;
253
+ } else {
254
+ #ifdef STATS_HASH
255
+ STAT_HASH_POSITIVE++;
256
+ #endif
257
+ return i;
258
+ }
259
+ }
260
+ i += incr;
261
+ if (i >= h->size)
262
+ i -= h->size;
263
+ }
264
+
265
+ /* Found an empty position. */
266
+ if (empty != NONE)
267
+ i = empty;
268
+ h->t[i].hv = hv;
269
+ return i;
270
+ }
271
+
272
+ unsigned int
273
+ ohash_lookup_memory(struct ohash *h, const char *k, size_t size, uint32_t hv)
274
+ {
275
+ unsigned int i, incr;
276
+ unsigned int empty;
277
+
278
+ #ifdef STATS_HASH
279
+ STAT_HASH_LOOKUP++;
280
+ #endif
281
+ empty = NONE;
282
+ i = hv % h->size;
283
+ incr = ((hv % (h->size-2)) & ~1) + 1;
284
+ while (h->t[i].p != NULL) {
285
+ #ifdef STATS_HASH
286
+ STAT_HASH_LENGTH++;
287
+ #endif
288
+ if (h->t[i].p == DELETED) {
289
+ if (empty == NONE)
290
+ empty = i;
291
+ } else if (h->t[i].hv == hv &&
292
+ memcmp(h->t[i].p+h->info.key_offset, k, size) == 0) {
293
+ if (empty != NONE) {
294
+ h->t[empty].hv = hv;
295
+ h->t[empty].p = h->t[i].p;
296
+ h->t[i].p = DELETED;
297
+ return empty;
298
+ } else {
299
+ #ifdef STATS_HASH
300
+ STAT_HASH_POSITIVE++;
301
+ #endif
302
+ } return i;
303
+ }
304
+ i += incr;
305
+ if (i >= h->size)
306
+ i -= h->size;
307
+ }
308
+
309
+ /* Found an empty position. */
310
+ if (empty != NONE)
311
+ i = empty;
312
+ h->t[i].hv = hv;
313
+ return i;
314
+ }
315
+
316
+ unsigned int
317
+ ohash_qlookup(struct ohash *h, const char *s)
318
+ {
319
+ const char *e = NULL;
320
+ return ohash_qlookupi(h, s, &e);
321
+ }
322
+
323
+ unsigned int
324
+ ohash_qlookupi(struct ohash *h, const char *s, const char **e)
325
+ {
326
+ uint32_t hv;
327
+
328
+ hv = ohash_interval(s, e);
329
+ return ohash_lookup_interval(h, s, *e, hv);
330
+ }
@@ -0,0 +1,72 @@
1
+ /* $OpenBSD: ohash.h,v 1.2 2014/06/02 18:52:03 deraadt Exp $ */
2
+
3
+ /* Copyright (c) 1999, 2004 Marc Espie <espie@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
+
18
+ #ifndef OHASH_H
19
+ #define OHASH_H
20
+
21
+ /* Open hashing support.
22
+ * Open hashing was chosen because it is much lighter than other hash
23
+ * techniques, and more efficient in most cases.
24
+ */
25
+
26
+ /* user-visible data structure */
27
+ struct ohash_info {
28
+ ptrdiff_t key_offset;
29
+ void *data; /* user data */
30
+ void *(*calloc)(size_t, size_t, void *);
31
+ void (*free)(void *, void *);
32
+ void *(*alloc)(size_t, void *);
33
+ };
34
+
35
+ struct _ohash_record;
36
+
37
+ /* private structure. It's there just so you can do a sizeof */
38
+ struct ohash {
39
+ struct _ohash_record *t;
40
+ struct ohash_info info;
41
+ unsigned int size;
42
+ unsigned int total;
43
+ unsigned int deleted;
44
+ };
45
+
46
+ /* For this to be tweakable, we use small primitives, and leave part of the
47
+ * logic to the client application. e.g., hashing is left to the client
48
+ * application. We also provide a simple table entry lookup that yields
49
+ * a hashing table index (opaque) to be used in find/insert/remove.
50
+ * The keys are stored at a known position in the client data.
51
+ */
52
+ void ohash_init(struct ohash *, unsigned, struct ohash_info *);
53
+ void ohash_delete(struct ohash *);
54
+
55
+ unsigned int ohash_lookup_interval(struct ohash *, const char *,
56
+ const char *, uint32_t);
57
+ unsigned int ohash_lookup_memory(struct ohash *, const char *,
58
+ size_t, uint32_t);
59
+ void *ohash_find(struct ohash *, unsigned int);
60
+ void *ohash_remove(struct ohash *, unsigned int);
61
+ void *ohash_insert(struct ohash *, unsigned int, void *);
62
+ void *ohash_first(struct ohash *, unsigned int *);
63
+ void *ohash_next(struct ohash *, unsigned int *);
64
+ unsigned int ohash_entries(struct ohash *);
65
+
66
+ void *ohash_create_entry(struct ohash_info *, const char *, const char **);
67
+ uint32_t ohash_interval(const char *, const char **);
68
+
69
+ unsigned int ohash_qlookupi(struct ohash *, const char *, const char **);
70
+ unsigned int ohash_qlookup(struct ohash *, const char *);
71
+
72
+ #endif
@@ -0,0 +1,31 @@
1
+ /* $Id: compat_progname.c,v 1.2 2020/06/15 01:37:15 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2015 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
+ static const char *progname;
20
+
21
+ void
22
+ setprogname(const char *name)
23
+ {
24
+ progname = name;
25
+ }
26
+
27
+ const char *
28
+ getprogname(void)
29
+ {
30
+ return progname;
31
+ }
@@ -0,0 +1,40 @@
1
+ /* $Id: compat_reallocarray.c,v 1.5 2020/06/15 01:37:15 schwarze Exp $ */
2
+ /* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */
3
+ /*
4
+ * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
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
+ #include <errno.h>
22
+ #include <stdint.h>
23
+ #include <stdlib.h>
24
+
25
+ /*
26
+ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
27
+ * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
28
+ */
29
+ #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
30
+
31
+ void *
32
+ reallocarray(void *optr, size_t nmemb, size_t size)
33
+ {
34
+ if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
35
+ nmemb > 0 && SIZE_MAX / nmemb < size) {
36
+ errno = ENOMEM;
37
+ return NULL;
38
+ }
39
+ return realloc(optr, size * nmemb);
40
+ }
@@ -0,0 +1,99 @@
1
+ /* $Id: compat_recallocarray.c,v 1.2 2020/06/15 01:37:15 schwarze Exp $ */
2
+ /* $OpenBSD: recallocarray.c,v 1.1 2017/03/06 18:44:21 otto Exp $ */
3
+ /*
4
+ * Copyright (c) 2008, 2017 Otto Moerbeek <otto@drijf.net>
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
+ #include <errno.h>
22
+ #include <stdlib.h>
23
+ #include <stdint.h>
24
+ #include <string.h>
25
+
26
+ /*
27
+ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
28
+ * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
29
+ */
30
+ #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
31
+
32
+ /*
33
+ * Even though specified in POSIX, the PAGESIZE and PAGE_SIZE
34
+ * macros have very poor portability. Since we only use this
35
+ * to avoid free() overhead for small shrinking, simply pick
36
+ * an arbitrary number.
37
+ */
38
+ #define getpagesize() (1UL << 12)
39
+
40
+
41
+ void *
42
+ recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size)
43
+ {
44
+ size_t oldsize, newsize;
45
+ void *newptr;
46
+
47
+ if (ptr == NULL)
48
+ return calloc(newnmemb, size);
49
+
50
+ if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
51
+ newnmemb > 0 && SIZE_MAX / newnmemb < size) {
52
+ errno = ENOMEM;
53
+ return NULL;
54
+ }
55
+ newsize = newnmemb * size;
56
+
57
+ if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
58
+ oldnmemb > 0 && SIZE_MAX / oldnmemb < size) {
59
+ errno = EINVAL;
60
+ return NULL;
61
+ }
62
+ oldsize = oldnmemb * size;
63
+
64
+ /*
65
+ * Don't bother too much if we're shrinking just a bit,
66
+ * we do not shrink for series of small steps, oh well.
67
+ */
68
+ if (newsize <= oldsize) {
69
+ size_t d = oldsize - newsize;
70
+
71
+ if (d < oldsize / 2 && d < getpagesize()) {
72
+ memset((char *)ptr + newsize, 0, d);
73
+ return ptr;
74
+ }
75
+ }
76
+
77
+ newptr = malloc(newsize);
78
+ if (newptr == NULL)
79
+ return NULL;
80
+
81
+ if (newsize > oldsize) {
82
+ memcpy(newptr, ptr, oldsize);
83
+ memset((char *)newptr + oldsize, 0, newsize - oldsize);
84
+ } else
85
+ memcpy(newptr, ptr, newsize);
86
+
87
+ /*
88
+ * At this point, the OpenBSD implementation calls
89
+ * explicit_bzero() on the old memory before it is
90
+ * freed. Since explicit_bzero() is hard to implement
91
+ * portably and we don't handle confidential data in
92
+ * mandoc in the first place, simply free the memory
93
+ * without clearing it.
94
+ */
95
+
96
+ free(ptr);
97
+
98
+ return newptr;
99
+ }
@@ -0,0 +1,64 @@
1
+ /* $Id: compat_strcasestr.c,v 1.5 2020/06/15 01:37:15 schwarze Exp $ */
2
+ /* $NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $ */
3
+
4
+ /*-
5
+ * Copyright (c) 1990, 1993
6
+ * The Regents of the University of California. All rights reserved.
7
+ *
8
+ * This code is derived from software contributed to Berkeley by
9
+ * Chris Torek.
10
+ *
11
+ * Redistribution and use in source and binary forms, with or without
12
+ * modification, are permitted provided that the following conditions
13
+ * are met:
14
+ * 1. Redistributions of source code must retain the above copyright
15
+ * notice, this list of conditions and the following disclaimer.
16
+ * 2. Redistributions in binary form must reproduce the above copyright
17
+ * notice, this list of conditions and the following disclaimer in the
18
+ * documentation and/or other materials provided with the distribution.
19
+ * 3. Neither the name of the University nor the names of its contributors
20
+ * may be used to endorse or promote products derived from this software
21
+ * without specific prior written permission.
22
+ *
23
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33
+ * SUCH DAMAGE.
34
+ */
35
+ #include "config.h"
36
+
37
+ #include <sys/types.h>
38
+ #include <ctype.h>
39
+ #include <string.h>
40
+
41
+ #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
42
+
43
+ /*
44
+ * Find the first occurrence of find in s, ignore case.
45
+ */
46
+ char *
47
+ strcasestr(const char *s, const char *find)
48
+ {
49
+ char c, sc;
50
+ size_t len;
51
+
52
+ if ((c = *find++) != 0) {
53
+ c = tolower((unsigned char)c);
54
+ len = strlen(find);
55
+ do {
56
+ do {
57
+ if ((sc = *s++) == 0)
58
+ return (NULL);
59
+ } while ((char)tolower((unsigned char)sc) != c);
60
+ } while (strncasecmp(s, find, len) != 0);
61
+ s--;
62
+ }
63
+ return __UNCONST(s);
64
+ }