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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +7 -0
- data/COPYING +674 -0
- data/README.md +117 -0
- data/ext/mandoc/extconf.rb +59 -0
- data/ext/mandoc/rb_mandoc.c +548 -0
- data/ext/mandoc/rb_mandoc.h +22 -0
- data/lib/mandoc/version.rb +19 -0
- data/lib/mandoc.rb +26 -0
- data/mandoc-1.14.6/LICENSE +55 -0
- data/mandoc-1.14.6/arch.c +54 -0
- data/mandoc-1.14.6/att.c +49 -0
- data/mandoc-1.14.6/catman.c +260 -0
- data/mandoc-1.14.6/cgi.c +1279 -0
- data/mandoc-1.14.6/chars.c +507 -0
- data/mandoc-1.14.6/compat_err.c +103 -0
- data/mandoc-1.14.6/compat_fts.c +696 -0
- data/mandoc-1.14.6/compat_fts.h +106 -0
- data/mandoc-1.14.6/compat_getline.c +59 -0
- data/mandoc-1.14.6/compat_getsubopt.c +87 -0
- data/mandoc-1.14.6/compat_isblank.c +23 -0
- data/mandoc-1.14.6/compat_mkdtemp.c +50 -0
- data/mandoc-1.14.6/compat_mkstemps.c +63 -0
- data/mandoc-1.14.6/compat_ohash.c +330 -0
- data/mandoc-1.14.6/compat_ohash.h +72 -0
- data/mandoc-1.14.6/compat_progname.c +31 -0
- data/mandoc-1.14.6/compat_reallocarray.c +40 -0
- data/mandoc-1.14.6/compat_recallocarray.c +99 -0
- data/mandoc-1.14.6/compat_strcasestr.c +64 -0
- data/mandoc-1.14.6/compat_stringlist.c +135 -0
- data/mandoc-1.14.6/compat_stringlist.h +48 -0
- data/mandoc-1.14.6/compat_strlcat.c +57 -0
- data/mandoc-1.14.6/compat_strlcpy.c +52 -0
- data/mandoc-1.14.6/compat_strndup.c +42 -0
- data/mandoc-1.14.6/compat_strsep.c +70 -0
- data/mandoc-1.14.6/compat_strtonum.c +67 -0
- data/mandoc-1.14.6/compat_vasprintf.c +47 -0
- data/mandoc-1.14.6/config.h +52 -0
- data/mandoc-1.14.6/dba.c +508 -0
- data/mandoc-1.14.6/dba.h +50 -0
- data/mandoc-1.14.6/dba_array.c +190 -0
- data/mandoc-1.14.6/dba_array.h +47 -0
- data/mandoc-1.14.6/dba_read.c +74 -0
- data/mandoc-1.14.6/dba_write.c +127 -0
- data/mandoc-1.14.6/dba_write.h +30 -0
- data/mandoc-1.14.6/dbm.c +480 -0
- data/mandoc-1.14.6/dbm.h +68 -0
- data/mandoc-1.14.6/dbm_map.c +194 -0
- data/mandoc-1.14.6/dbm_map.h +29 -0
- data/mandoc-1.14.6/demandoc.c +260 -0
- data/mandoc-1.14.6/eqn.c +1132 -0
- data/mandoc-1.14.6/eqn.h +72 -0
- data/mandoc-1.14.6/eqn_html.c +246 -0
- data/mandoc-1.14.6/eqn_parse.h +48 -0
- data/mandoc-1.14.6/eqn_term.c +174 -0
- data/mandoc-1.14.6/html.c +1102 -0
- data/mandoc-1.14.6/html.h +142 -0
- data/mandoc-1.14.6/lib.c +35 -0
- data/mandoc-1.14.6/libman.h +42 -0
- data/mandoc-1.14.6/libmandoc.h +85 -0
- data/mandoc-1.14.6/libmdoc.h +87 -0
- data/mandoc-1.14.6/main.c +1375 -0
- data/mandoc-1.14.6/main.h +53 -0
- data/mandoc-1.14.6/man.c +345 -0
- data/mandoc-1.14.6/man.h +21 -0
- data/mandoc-1.14.6/man_html.c +640 -0
- data/mandoc-1.14.6/man_macro.c +470 -0
- data/mandoc-1.14.6/man_term.c +1143 -0
- data/mandoc-1.14.6/man_validate.c +660 -0
- data/mandoc-1.14.6/manconf.h +58 -0
- data/mandoc-1.14.6/mandoc.c +669 -0
- data/mandoc-1.14.6/mandoc.h +329 -0
- data/mandoc-1.14.6/mandoc_aux.c +118 -0
- data/mandoc-1.14.6/mandoc_aux.h +27 -0
- data/mandoc-1.14.6/mandoc_msg.c +375 -0
- data/mandoc-1.14.6/mandoc_ohash.c +65 -0
- data/mandoc-1.14.6/mandoc_ohash.h +23 -0
- data/mandoc-1.14.6/mandoc_parse.h +44 -0
- data/mandoc-1.14.6/mandoc_xr.c +123 -0
- data/mandoc-1.14.6/mandoc_xr.h +31 -0
- data/mandoc-1.14.6/mandocd.c +282 -0
- data/mandoc-1.14.6/mandocdb.c +2448 -0
- data/mandoc-1.14.6/manpath.c +363 -0
- data/mandoc-1.14.6/mansearch.c +851 -0
- data/mandoc-1.14.6/mansearch.h +118 -0
- data/mandoc-1.14.6/mdoc.c +433 -0
- data/mandoc-1.14.6/mdoc.h +158 -0
- data/mandoc-1.14.6/mdoc_argv.c +682 -0
- data/mandoc-1.14.6/mdoc_html.c +1762 -0
- data/mandoc-1.14.6/mdoc_macro.c +1600 -0
- data/mandoc-1.14.6/mdoc_man.c +1850 -0
- data/mandoc-1.14.6/mdoc_markdown.c +1610 -0
- data/mandoc-1.14.6/mdoc_state.c +256 -0
- data/mandoc-1.14.6/mdoc_term.c +1964 -0
- data/mandoc-1.14.6/mdoc_validate.c +3062 -0
- data/mandoc-1.14.6/msec.c +37 -0
- data/mandoc-1.14.6/out.c +544 -0
- data/mandoc-1.14.6/out.h +70 -0
- data/mandoc-1.14.6/preconv.c +179 -0
- data/mandoc-1.14.6/read.c +732 -0
- data/mandoc-1.14.6/roff.c +4390 -0
- data/mandoc-1.14.6/roff.h +561 -0
- data/mandoc-1.14.6/roff_html.c +119 -0
- data/mandoc-1.14.6/roff_int.h +94 -0
- data/mandoc-1.14.6/roff_term.c +266 -0
- data/mandoc-1.14.6/roff_validate.c +151 -0
- data/mandoc-1.14.6/soelim.c +182 -0
- data/mandoc-1.14.6/st.c +82 -0
- data/mandoc-1.14.6/tag.c +327 -0
- data/mandoc-1.14.6/tag.h +35 -0
- data/mandoc-1.14.6/tbl.c +183 -0
- data/mandoc-1.14.6/tbl.h +121 -0
- data/mandoc-1.14.6/tbl_data.c +323 -0
- data/mandoc-1.14.6/tbl_html.c +293 -0
- data/mandoc-1.14.6/tbl_int.h +47 -0
- data/mandoc-1.14.6/tbl_layout.c +376 -0
- data/mandoc-1.14.6/tbl_opts.c +173 -0
- data/mandoc-1.14.6/tbl_parse.h +30 -0
- data/mandoc-1.14.6/tbl_term.c +948 -0
- data/mandoc-1.14.6/term.c +1113 -0
- data/mandoc-1.14.6/term.h +158 -0
- data/mandoc-1.14.6/term_ascii.c +424 -0
- data/mandoc-1.14.6/term_ps.c +1362 -0
- data/mandoc-1.14.6/term_tab.c +130 -0
- data/mandoc-1.14.6/term_tag.c +227 -0
- data/mandoc-1.14.6/term_tag.h +34 -0
- data/mandoc-1.14.6/tree.c +536 -0
- metadata +170 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/* $Id: term_tab.c,v 1.6 2020/06/22 19:20:40 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 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 <stddef.h>
|
|
22
|
+
|
|
23
|
+
#include "mandoc_aux.h"
|
|
24
|
+
#include "out.h"
|
|
25
|
+
#include "term.h"
|
|
26
|
+
|
|
27
|
+
struct tablist {
|
|
28
|
+
size_t *t; /* Allocated array of tab positions. */
|
|
29
|
+
size_t s; /* Allocated number of positions. */
|
|
30
|
+
size_t n; /* Currently used number of positions. */
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
static struct {
|
|
34
|
+
struct tablist a; /* All tab positions for lookup. */
|
|
35
|
+
struct tablist p; /* Periodic tab positions to add. */
|
|
36
|
+
size_t d; /* Default tab width in units of n. */
|
|
37
|
+
} tabs;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
void
|
|
41
|
+
term_tab_set(const struct termp *p, const char *arg)
|
|
42
|
+
{
|
|
43
|
+
static int recording_period;
|
|
44
|
+
|
|
45
|
+
struct roffsu su;
|
|
46
|
+
struct tablist *tl;
|
|
47
|
+
size_t pos;
|
|
48
|
+
int add;
|
|
49
|
+
|
|
50
|
+
/* Special arguments: clear all tabs or switch lists. */
|
|
51
|
+
|
|
52
|
+
if (arg == NULL) {
|
|
53
|
+
tabs.a.n = tabs.p.n = 0;
|
|
54
|
+
recording_period = 0;
|
|
55
|
+
if (tabs.d == 0) {
|
|
56
|
+
a2roffsu(".8i", &su, SCALE_IN);
|
|
57
|
+
tabs.d = term_hen(p, &su);
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (arg[0] == 'T' && arg[1] == '\0') {
|
|
62
|
+
recording_period = 1;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* Parse the sign, the number, and the unit. */
|
|
67
|
+
|
|
68
|
+
if (*arg == '+') {
|
|
69
|
+
add = 1;
|
|
70
|
+
arg++;
|
|
71
|
+
} else
|
|
72
|
+
add = 0;
|
|
73
|
+
if (a2roffsu(arg, &su, SCALE_EM) == NULL)
|
|
74
|
+
return;
|
|
75
|
+
|
|
76
|
+
/* Select the list, and extend it if it is full. */
|
|
77
|
+
|
|
78
|
+
tl = recording_period ? &tabs.p : &tabs.a;
|
|
79
|
+
if (tl->n >= tl->s) {
|
|
80
|
+
tl->s += 8;
|
|
81
|
+
tl->t = mandoc_reallocarray(tl->t, tl->s, sizeof(*tl->t));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* Append the new position. */
|
|
85
|
+
|
|
86
|
+
pos = term_hen(p, &su);
|
|
87
|
+
tl->t[tl->n] = pos;
|
|
88
|
+
if (add && tl->n)
|
|
89
|
+
tl->t[tl->n] += tl->t[tl->n - 1];
|
|
90
|
+
tl->n++;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/*
|
|
94
|
+
* Simplified version without a parser,
|
|
95
|
+
* never incremental, never periodic, for use by tbl(7).
|
|
96
|
+
*/
|
|
97
|
+
void
|
|
98
|
+
term_tab_iset(size_t inc)
|
|
99
|
+
{
|
|
100
|
+
if (tabs.a.n >= tabs.a.s) {
|
|
101
|
+
tabs.a.s += 8;
|
|
102
|
+
tabs.a.t = mandoc_reallocarray(tabs.a.t, tabs.a.s,
|
|
103
|
+
sizeof(*tabs.a.t));
|
|
104
|
+
}
|
|
105
|
+
tabs.a.t[tabs.a.n++] = inc;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
size_t
|
|
109
|
+
term_tab_next(size_t prev)
|
|
110
|
+
{
|
|
111
|
+
size_t i, j;
|
|
112
|
+
|
|
113
|
+
for (i = 0;; i++) {
|
|
114
|
+
if (i == tabs.a.n) {
|
|
115
|
+
if (tabs.p.n == 0)
|
|
116
|
+
return prev;
|
|
117
|
+
tabs.a.n += tabs.p.n;
|
|
118
|
+
if (tabs.a.s < tabs.a.n) {
|
|
119
|
+
tabs.a.s = tabs.a.n;
|
|
120
|
+
tabs.a.t = mandoc_reallocarray(tabs.a.t,
|
|
121
|
+
tabs.a.s, sizeof(*tabs.a.t));
|
|
122
|
+
}
|
|
123
|
+
for (j = 0; j < tabs.p.n; j++)
|
|
124
|
+
tabs.a.t[i + j] = tabs.p.t[j] +
|
|
125
|
+
(i ? tabs.a.t[i - 1] : 0);
|
|
126
|
+
}
|
|
127
|
+
if (prev < tabs.a.t[i])
|
|
128
|
+
return tabs.a.t[i];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/* $Id: term_tag.c,v 1.6 2021/03/30 17:16:55 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2015,2016,2018,2019,2020 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
|
+
* Functions to write a ctags(1) file.
|
|
18
|
+
* For use by the mandoc(1) ASCII and UTF-8 formatters only.
|
|
19
|
+
*/
|
|
20
|
+
#include "config.h"
|
|
21
|
+
|
|
22
|
+
#include <sys/types.h>
|
|
23
|
+
|
|
24
|
+
#include <errno.h>
|
|
25
|
+
#include <fcntl.h>
|
|
26
|
+
#include <signal.h>
|
|
27
|
+
#include <stddef.h>
|
|
28
|
+
#include <stdio.h>
|
|
29
|
+
#include <stdlib.h>
|
|
30
|
+
#include <string.h>
|
|
31
|
+
#include <unistd.h>
|
|
32
|
+
|
|
33
|
+
#include "mandoc.h"
|
|
34
|
+
#include "roff.h"
|
|
35
|
+
#include "roff_int.h"
|
|
36
|
+
#include "tag.h"
|
|
37
|
+
#include "term_tag.h"
|
|
38
|
+
|
|
39
|
+
static void tag_signal(int) __attribute__((__noreturn__));
|
|
40
|
+
|
|
41
|
+
static struct tag_files tag_files;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* Prepare for using a pager.
|
|
46
|
+
* Not all pagers are capable of using a tag file,
|
|
47
|
+
* but for simplicity, create it anyway.
|
|
48
|
+
*/
|
|
49
|
+
struct tag_files *
|
|
50
|
+
term_tag_init(const char *outfilename, const char *suffix,
|
|
51
|
+
const char *tagfilename)
|
|
52
|
+
{
|
|
53
|
+
struct sigaction sa;
|
|
54
|
+
int ofd; /* In /tmp/, dup(2)ed to stdout. */
|
|
55
|
+
int tfd;
|
|
56
|
+
|
|
57
|
+
ofd = tfd = -1;
|
|
58
|
+
tag_files.tfs = NULL;
|
|
59
|
+
tag_files.tcpgid = -1;
|
|
60
|
+
|
|
61
|
+
/* Clean up when dying from a signal. */
|
|
62
|
+
|
|
63
|
+
memset(&sa, 0, sizeof(sa));
|
|
64
|
+
sigfillset(&sa.sa_mask);
|
|
65
|
+
sa.sa_handler = tag_signal;
|
|
66
|
+
sigaction(SIGHUP, &sa, NULL);
|
|
67
|
+
sigaction(SIGINT, &sa, NULL);
|
|
68
|
+
sigaction(SIGTERM, &sa, NULL);
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
* POSIX requires that a process calling tcsetpgrp(3)
|
|
72
|
+
* from the background gets a SIGTTOU signal.
|
|
73
|
+
* In that case, do not stop.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
sa.sa_handler = SIG_IGN;
|
|
77
|
+
sigaction(SIGTTOU, &sa, NULL);
|
|
78
|
+
|
|
79
|
+
/* Save the original standard output for use by the pager. */
|
|
80
|
+
|
|
81
|
+
if ((tag_files.ofd = dup(STDOUT_FILENO)) == -1) {
|
|
82
|
+
mandoc_msg(MANDOCERR_DUP, 0, 0, "%s", strerror(errno));
|
|
83
|
+
goto fail;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* Create both temporary output files. */
|
|
87
|
+
|
|
88
|
+
if (outfilename == NULL) {
|
|
89
|
+
(void)snprintf(tag_files.ofn, sizeof(tag_files.ofn),
|
|
90
|
+
"/tmp/man.XXXXXXXXXX%s", suffix);
|
|
91
|
+
if ((ofd = mkstemps(tag_files.ofn, strlen(suffix))) == -1) {
|
|
92
|
+
mandoc_msg(MANDOCERR_MKSTEMP, 0, 0,
|
|
93
|
+
"%s: %s", tag_files.ofn, strerror(errno));
|
|
94
|
+
goto fail;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
(void)strlcpy(tag_files.ofn, outfilename,
|
|
98
|
+
sizeof(tag_files.ofn));
|
|
99
|
+
unlink(outfilename);
|
|
100
|
+
ofd = open(outfilename, O_WRONLY | O_CREAT | O_EXCL, 0644);
|
|
101
|
+
if (ofd == -1) {
|
|
102
|
+
mandoc_msg(MANDOCERR_OPEN, 0, 0,
|
|
103
|
+
"%s: %s", outfilename, strerror(errno));
|
|
104
|
+
goto fail;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (tagfilename == NULL) {
|
|
108
|
+
(void)strlcpy(tag_files.tfn, "/tmp/man.XXXXXXXXXX",
|
|
109
|
+
sizeof(tag_files.tfn));
|
|
110
|
+
if ((tfd = mkstemp(tag_files.tfn)) == -1) {
|
|
111
|
+
mandoc_msg(MANDOCERR_MKSTEMP, 0, 0,
|
|
112
|
+
"%s: %s", tag_files.tfn, strerror(errno));
|
|
113
|
+
goto fail;
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
(void)strlcpy(tag_files.tfn, tagfilename,
|
|
117
|
+
sizeof(tag_files.tfn));
|
|
118
|
+
unlink(tagfilename);
|
|
119
|
+
tfd = open(tagfilename, O_WRONLY | O_CREAT | O_EXCL, 0644);
|
|
120
|
+
if (tfd == -1) {
|
|
121
|
+
mandoc_msg(MANDOCERR_OPEN, 0, 0,
|
|
122
|
+
"%s: %s", tagfilename, strerror(errno));
|
|
123
|
+
goto fail;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if ((tag_files.tfs = fdopen(tfd, "w")) == NULL) {
|
|
127
|
+
mandoc_msg(MANDOCERR_FDOPEN, 0, 0, "%s", strerror(errno));
|
|
128
|
+
goto fail;
|
|
129
|
+
}
|
|
130
|
+
tfd = -1;
|
|
131
|
+
if (dup2(ofd, STDOUT_FILENO) == -1) {
|
|
132
|
+
mandoc_msg(MANDOCERR_DUP, 0, 0, "%s", strerror(errno));
|
|
133
|
+
goto fail;
|
|
134
|
+
}
|
|
135
|
+
close(ofd);
|
|
136
|
+
return &tag_files;
|
|
137
|
+
|
|
138
|
+
fail:
|
|
139
|
+
term_tag_unlink();
|
|
140
|
+
if (ofd != -1)
|
|
141
|
+
close(ofd);
|
|
142
|
+
if (tfd != -1)
|
|
143
|
+
close(tfd);
|
|
144
|
+
if (tag_files.ofd != -1) {
|
|
145
|
+
close(tag_files.ofd);
|
|
146
|
+
tag_files.ofd = -1;
|
|
147
|
+
}
|
|
148
|
+
return NULL;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
void
|
|
152
|
+
term_tag_write(struct roff_node *n, size_t line)
|
|
153
|
+
{
|
|
154
|
+
const char *cp;
|
|
155
|
+
int len;
|
|
156
|
+
|
|
157
|
+
if (tag_files.tfs == NULL)
|
|
158
|
+
return;
|
|
159
|
+
cp = n->tag == NULL ? n->child->string : n->tag;
|
|
160
|
+
if (cp[0] == '\\' && (cp[1] == '&' || cp[1] == 'e'))
|
|
161
|
+
cp += 2;
|
|
162
|
+
len = strcspn(cp, " \t\\");
|
|
163
|
+
fprintf(tag_files.tfs, "%.*s %s %zu\n",
|
|
164
|
+
len, cp, tag_files.ofn, line);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/*
|
|
168
|
+
* Close both output files and restore the original standard output
|
|
169
|
+
* to the terminal. In the unlikely case that the latter fails,
|
|
170
|
+
* trying to start a pager would be useless, so report the failure
|
|
171
|
+
* to the main program.
|
|
172
|
+
*/
|
|
173
|
+
int
|
|
174
|
+
term_tag_close(void)
|
|
175
|
+
{
|
|
176
|
+
int irc = 0;
|
|
177
|
+
|
|
178
|
+
if (tag_files.tfs != NULL) {
|
|
179
|
+
fclose(tag_files.tfs);
|
|
180
|
+
tag_files.tfs = NULL;
|
|
181
|
+
}
|
|
182
|
+
if (tag_files.ofd != -1) {
|
|
183
|
+
fflush(stdout);
|
|
184
|
+
if ((irc = dup2(tag_files.ofd, STDOUT_FILENO)) == -1)
|
|
185
|
+
mandoc_msg(MANDOCERR_DUP, 0, 0, "%s", strerror(errno));
|
|
186
|
+
close(tag_files.ofd);
|
|
187
|
+
tag_files.ofd = -1;
|
|
188
|
+
}
|
|
189
|
+
return irc;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
void
|
|
193
|
+
term_tag_unlink(void)
|
|
194
|
+
{
|
|
195
|
+
pid_t tc_pgid;
|
|
196
|
+
|
|
197
|
+
if (tag_files.tcpgid != -1) {
|
|
198
|
+
tc_pgid = tcgetpgrp(STDOUT_FILENO);
|
|
199
|
+
if (tc_pgid == tag_files.pager_pid ||
|
|
200
|
+
tc_pgid == getpgid(0) ||
|
|
201
|
+
getpgid(tc_pgid) == -1)
|
|
202
|
+
(void)tcsetpgrp(STDOUT_FILENO, tag_files.tcpgid);
|
|
203
|
+
}
|
|
204
|
+
if (strncmp(tag_files.ofn, "/tmp/man.", 9) == 0) {
|
|
205
|
+
unlink(tag_files.ofn);
|
|
206
|
+
*tag_files.ofn = '\0';
|
|
207
|
+
}
|
|
208
|
+
if (strncmp(tag_files.tfn, "/tmp/man.", 9) == 0) {
|
|
209
|
+
unlink(tag_files.tfn);
|
|
210
|
+
*tag_files.tfn = '\0';
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static void
|
|
215
|
+
tag_signal(int signum)
|
|
216
|
+
{
|
|
217
|
+
struct sigaction sa;
|
|
218
|
+
|
|
219
|
+
term_tag_unlink();
|
|
220
|
+
memset(&sa, 0, sizeof(sa));
|
|
221
|
+
sigemptyset(&sa.sa_mask);
|
|
222
|
+
sa.sa_handler = SIG_DFL;
|
|
223
|
+
sigaction(signum, &sa, NULL);
|
|
224
|
+
kill(getpid(), signum);
|
|
225
|
+
/* NOTREACHED */
|
|
226
|
+
_exit(1);
|
|
227
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* $Id: term_tag.h,v 1.4 2021/03/30 17:16:55 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2015, 2018, 2019, 2020 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
|
+
* Internal interfaces to write a ctags(1) file.
|
|
18
|
+
* For use by the mandoc(1) ASCII and UTF-8 formatters only.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
struct tag_files {
|
|
22
|
+
char ofn[80]; /* Output file name. */
|
|
23
|
+
char tfn[80]; /* Tag file name. */
|
|
24
|
+
FILE *tfs; /* Tag file object. */
|
|
25
|
+
int ofd; /* Original output file descriptor. */
|
|
26
|
+
pid_t tcpgid; /* Process group controlling the terminal. */
|
|
27
|
+
pid_t pager_pid; /* Process ID of the pager. */
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
struct tag_files *term_tag_init(const char *, const char *, const char *);
|
|
32
|
+
void term_tag_write(struct roff_node *, size_t);
|
|
33
|
+
int term_tag_close(void);
|
|
34
|
+
void term_tag_unlink(void);
|