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,194 @@
1
+ /* $Id: dbm_map.c,v 1.8 2017/02/17 14:43:54 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2016 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
+ * Low-level routines for the map-based version
18
+ * of the mandoc database, for read-only access.
19
+ * The interface is defined in "dbm_map.h".
20
+ */
21
+ #include "config.h"
22
+
23
+ #include <sys/mman.h>
24
+ #include <sys/stat.h>
25
+ #include <sys/types.h>
26
+
27
+ #if HAVE_ENDIAN
28
+ #include <endian.h>
29
+ #elif HAVE_SYS_ENDIAN
30
+ #include <sys/endian.h>
31
+ #elif HAVE_NTOHL
32
+ #include <arpa/inet.h>
33
+ #endif
34
+ #if HAVE_ERR
35
+ #include <err.h>
36
+ #endif
37
+ #include <errno.h>
38
+ #include <fcntl.h>
39
+ #include <regex.h>
40
+ #include <stdint.h>
41
+ #include <stdlib.h>
42
+ #include <string.h>
43
+ #include <unistd.h>
44
+
45
+ #include "mansearch.h"
46
+ #include "dbm_map.h"
47
+ #include "dbm.h"
48
+
49
+ static struct stat st;
50
+ static char *dbm_base;
51
+ static int ifd;
52
+ static int32_t max_offset;
53
+
54
+ /*
55
+ * Open a disk-based database for read-only access.
56
+ * Validate the file format as far as it is not mandoc-specific.
57
+ * Return 0 on success. Return -1 and set errno on failure.
58
+ */
59
+ int
60
+ dbm_map(const char *fname)
61
+ {
62
+ int save_errno;
63
+ const int32_t *magic;
64
+
65
+ if ((ifd = open(fname, O_RDONLY)) == -1)
66
+ return -1;
67
+ if (fstat(ifd, &st) == -1)
68
+ goto fail;
69
+ if (st.st_size < 5) {
70
+ warnx("dbm_map(%s): File too short", fname);
71
+ errno = EFTYPE;
72
+ goto fail;
73
+ }
74
+ if (st.st_size > INT32_MAX) {
75
+ errno = EFBIG;
76
+ goto fail;
77
+ }
78
+ if ((dbm_base = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED,
79
+ ifd, 0)) == MAP_FAILED)
80
+ goto fail;
81
+ magic = dbm_getint(0);
82
+ if (be32toh(*magic) != MANDOCDB_MAGIC) {
83
+ if (strncmp(dbm_base, "SQLite format 3", 15))
84
+ warnx("dbm_map(%s): "
85
+ "Bad initial magic %x (expected %x)",
86
+ fname, be32toh(*magic), MANDOCDB_MAGIC);
87
+ else
88
+ warnx("dbm_map(%s): "
89
+ "Obsolete format based on SQLite 3",
90
+ fname);
91
+ errno = EFTYPE;
92
+ goto fail;
93
+ }
94
+ magic = dbm_getint(1);
95
+ if (be32toh(*magic) != MANDOCDB_VERSION) {
96
+ warnx("dbm_map(%s): Bad version number %d (expected %d)",
97
+ fname, be32toh(*magic), MANDOCDB_VERSION);
98
+ errno = EFTYPE;
99
+ goto fail;
100
+ }
101
+ max_offset = be32toh(*dbm_getint(3)) + sizeof(int32_t);
102
+ if (st.st_size != max_offset) {
103
+ warnx("dbm_map(%s): Inconsistent file size %lld (expected %d)",
104
+ fname, (long long)st.st_size, max_offset);
105
+ errno = EFTYPE;
106
+ goto fail;
107
+ }
108
+ if ((magic = dbm_get(*dbm_getint(3))) == NULL) {
109
+ errno = EFTYPE;
110
+ goto fail;
111
+ }
112
+ if (be32toh(*magic) != MANDOCDB_MAGIC) {
113
+ warnx("dbm_map(%s): Bad final magic %x (expected %x)",
114
+ fname, be32toh(*magic), MANDOCDB_MAGIC);
115
+ errno = EFTYPE;
116
+ goto fail;
117
+ }
118
+ return 0;
119
+
120
+ fail:
121
+ save_errno = errno;
122
+ close(ifd);
123
+ errno = save_errno;
124
+ return -1;
125
+ }
126
+
127
+ void
128
+ dbm_unmap(void)
129
+ {
130
+ if (munmap(dbm_base, st.st_size) == -1)
131
+ warn("dbm_unmap: munmap");
132
+ if (close(ifd) == -1)
133
+ warn("dbm_unmap: close");
134
+ dbm_base = (char *)-1;
135
+ }
136
+
137
+ /*
138
+ * Take a raw integer as it was read from the database.
139
+ * Interpret it as an offset into the database file
140
+ * and return a pointer to that place in the file.
141
+ */
142
+ void *
143
+ dbm_get(int32_t offset)
144
+ {
145
+ offset = be32toh(offset);
146
+ if (offset < 0) {
147
+ warnx("dbm_get: Database corrupt: offset %d", offset);
148
+ return NULL;
149
+ }
150
+ if (offset >= max_offset) {
151
+ warnx("dbm_get: Database corrupt: offset %d > %d",
152
+ offset, max_offset);
153
+ return NULL;
154
+ }
155
+ return dbm_base + offset;
156
+ }
157
+
158
+ /*
159
+ * Assume the database starts with some integers.
160
+ * Assume they are numbered starting from 0, increasing.
161
+ * Get a pointer to one with the number "offset".
162
+ */
163
+ int32_t *
164
+ dbm_getint(int32_t offset)
165
+ {
166
+ return (int32_t *)dbm_base + offset;
167
+ }
168
+
169
+ /*
170
+ * The reverse of dbm_get().
171
+ * Take pointer into the database file
172
+ * and convert it to the raw integer
173
+ * that would be used to refer to that place in the file.
174
+ */
175
+ int32_t
176
+ dbm_addr(const void *p)
177
+ {
178
+ return htobe32((const char *)p - dbm_base);
179
+ }
180
+
181
+ int
182
+ dbm_match(const struct dbm_match *match, const char *str)
183
+ {
184
+ switch (match->type) {
185
+ case DBM_EXACT:
186
+ return strcmp(str, match->str) == 0;
187
+ case DBM_SUB:
188
+ return strcasestr(str, match->str) != NULL;
189
+ case DBM_REGEX:
190
+ return regexec(match->re, str, 0, NULL, 0) == 0;
191
+ default:
192
+ abort();
193
+ }
194
+ }
@@ -0,0 +1,29 @@
1
+ /* $Id: dbm_map.h,v 1.2 2019/07/01 22:56:24 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2016 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
+ * Private interface for low-level routines for the map-based version
18
+ * of the mandoc database, for read-only access.
19
+ * To be used by dbm*.c only.
20
+ */
21
+
22
+ struct dbm_match;
23
+
24
+ int dbm_map(const char *);
25
+ void dbm_unmap(void);
26
+ void *dbm_get(int32_t);
27
+ int32_t *dbm_getint(int32_t);
28
+ int32_t dbm_addr(const void *);
29
+ int dbm_match(const struct dbm_match *, const char *);
@@ -0,0 +1,260 @@
1
+ /* $Id: demandoc.c,v 1.33 2019/03/03 11:01:15 schwarze Exp $ */
2
+ /*
3
+ * Copyright (c) 2011 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 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 <ctype.h>
23
+ #include <stdio.h>
24
+ #include <stdlib.h>
25
+ #include <string.h>
26
+ #include <unistd.h>
27
+
28
+ #include "mandoc.h"
29
+ #include "roff.h"
30
+ #include "man.h"
31
+ #include "mdoc.h"
32
+ #include "mandoc_parse.h"
33
+
34
+ static void pline(int, int *, int *, int);
35
+ static void pman(const struct roff_node *, int *, int *, int);
36
+ static void pmandoc(struct mparse *, int, const char *, int);
37
+ static void pmdoc(const struct roff_node *, int *, int *, int);
38
+ static void pstring(const char *, int, int *, int);
39
+ static void usage(void);
40
+
41
+ static const char *progname;
42
+
43
+ int
44
+ main(int argc, char *argv[])
45
+ {
46
+ struct mparse *mp;
47
+ int ch, fd, i, list;
48
+ extern int optind;
49
+
50
+ if (argc < 1)
51
+ progname = "demandoc";
52
+ else if ((progname = strrchr(argv[0], '/')) == NULL)
53
+ progname = argv[0];
54
+ else
55
+ ++progname;
56
+
57
+ mp = NULL;
58
+ list = 0;
59
+
60
+ while (-1 != (ch = getopt(argc, argv, "ikm:pw")))
61
+ switch (ch) {
62
+ case ('i'):
63
+ /* FALLTHROUGH */
64
+ case ('k'):
65
+ /* FALLTHROUGH */
66
+ case ('m'):
67
+ /* FALLTHROUGH */
68
+ case ('p'):
69
+ break;
70
+ case ('w'):
71
+ list = 1;
72
+ break;
73
+ default:
74
+ usage();
75
+ return (int)MANDOCLEVEL_BADARG;
76
+ }
77
+
78
+ argc -= optind;
79
+ argv += optind;
80
+
81
+ mchars_alloc();
82
+ mp = mparse_alloc(MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1 |
83
+ MPARSE_VALIDATE, MANDOC_OS_OTHER, NULL);
84
+ assert(mp);
85
+
86
+ if (argc < 1)
87
+ pmandoc(mp, STDIN_FILENO, "<stdin>", list);
88
+
89
+ for (i = 0; i < argc; i++) {
90
+ mparse_reset(mp);
91
+ if ((fd = mparse_open(mp, argv[i])) == -1) {
92
+ perror(argv[i]);
93
+ continue;
94
+ }
95
+ pmandoc(mp, fd, argv[i], list);
96
+ }
97
+
98
+ mparse_free(mp);
99
+ mchars_free();
100
+ return (int)MANDOCLEVEL_OK;
101
+ }
102
+
103
+ static void
104
+ usage(void)
105
+ {
106
+
107
+ fprintf(stderr, "usage: %s [-w] [files...]\n", progname);
108
+ }
109
+
110
+ static void
111
+ pmandoc(struct mparse *mp, int fd, const char *fn, int list)
112
+ {
113
+ struct roff_meta *meta;
114
+ int line, col;
115
+
116
+ mparse_readfd(mp, fd, fn);
117
+ close(fd);
118
+ meta = mparse_result(mp);
119
+ line = 1;
120
+ col = 0;
121
+
122
+ if (meta->macroset == MACROSET_MDOC)
123
+ pmdoc(meta->first->child, &line, &col, list);
124
+ else
125
+ pman(meta->first->child, &line, &col, list);
126
+
127
+ if ( ! list)
128
+ putchar('\n');
129
+ }
130
+
131
+ /*
132
+ * Strip the escapes out of a string, emitting the results.
133
+ */
134
+ static void
135
+ pstring(const char *p, int col, int *colp, int list)
136
+ {
137
+ enum mandoc_esc esc;
138
+ const char *start, *end;
139
+ int emit;
140
+
141
+ /*
142
+ * Print as many column spaces til we achieve parity with the
143
+ * input document.
144
+ */
145
+
146
+ again:
147
+ if (list && '\0' != *p) {
148
+ while (isspace((unsigned char)*p))
149
+ p++;
150
+
151
+ while ('\'' == *p || '(' == *p || '"' == *p)
152
+ p++;
153
+
154
+ emit = isalpha((unsigned char)p[0]) &&
155
+ isalpha((unsigned char)p[1]);
156
+
157
+ for (start = p; '\0' != *p; p++)
158
+ if ('\\' == *p) {
159
+ p++;
160
+ esc = mandoc_escape(&p, NULL, NULL);
161
+ if (ESCAPE_ERROR == esc)
162
+ return;
163
+ emit = 0;
164
+ } else if (isspace((unsigned char)*p))
165
+ break;
166
+
167
+ end = p - 1;
168
+
169
+ while (end > start)
170
+ if ('.' == *end || ',' == *end ||
171
+ '\'' == *end || '"' == *end ||
172
+ ')' == *end || '!' == *end ||
173
+ '?' == *end || ':' == *end ||
174
+ ';' == *end)
175
+ end--;
176
+ else
177
+ break;
178
+
179
+ if (emit && end - start >= 1) {
180
+ for ( ; start <= end; start++)
181
+ if (ASCII_HYPH == *start)
182
+ putchar('-');
183
+ else
184
+ putchar((unsigned char)*start);
185
+ putchar('\n');
186
+ }
187
+
188
+ if (isspace((unsigned char)*p))
189
+ goto again;
190
+
191
+ return;
192
+ }
193
+
194
+ while (*colp < col) {
195
+ putchar(' ');
196
+ (*colp)++;
197
+ }
198
+
199
+ /*
200
+ * Print the input word, skipping any special characters.
201
+ */
202
+ while ('\0' != *p)
203
+ if ('\\' == *p) {
204
+ p++;
205
+ esc = mandoc_escape(&p, NULL, NULL);
206
+ if (ESCAPE_ERROR == esc)
207
+ break;
208
+ } else {
209
+ putchar((unsigned char )*p++);
210
+ (*colp)++;
211
+ }
212
+ }
213
+
214
+ static void
215
+ pline(int line, int *linep, int *col, int list)
216
+ {
217
+
218
+ if (list)
219
+ return;
220
+
221
+ /*
222
+ * Print out as many lines as needed to reach parity with the
223
+ * original input.
224
+ */
225
+
226
+ while (*linep < line) {
227
+ putchar('\n');
228
+ (*linep)++;
229
+ }
230
+
231
+ *col = 0;
232
+ }
233
+
234
+ static void
235
+ pmdoc(const struct roff_node *p, int *line, int *col, int list)
236
+ {
237
+
238
+ for ( ; p; p = p->next) {
239
+ if (NODE_LINE & p->flags)
240
+ pline(p->line, line, col, list);
241
+ if (ROFFT_TEXT == p->type)
242
+ pstring(p->string, p->pos, col, list);
243
+ if (p->child)
244
+ pmdoc(p->child, line, col, list);
245
+ }
246
+ }
247
+
248
+ static void
249
+ pman(const struct roff_node *p, int *line, int *col, int list)
250
+ {
251
+
252
+ for ( ; p; p = p->next) {
253
+ if (NODE_LINE & p->flags)
254
+ pline(p->line, line, col, list);
255
+ if (ROFFT_TEXT == p->type)
256
+ pstring(p->string, p->pos, col, list);
257
+ if (p->child)
258
+ pman(p->child, line, col, list);
259
+ }
260
+ }