diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-11-06 18:58:00 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-11-06 18:58:00 +0000 |
commit | e7b9f1287fa3b69e6b82148f3838cf4a47b1ac39 (patch) | |
tree | 875eeebb1f1c91f6b49498490a0a515d0d36dbbf | |
parent | d342fa430e91c59a31ca21ada4b5f48d3793106f (diff) |
gzip embedded man pages, and pipe through gunzip when viewing.
ok deraadt@
-rw-r--r-- | sbin/disklabel/Makefile | 14 | ||||
-rw-r--r-- | sbin/disklabel/editor.c | 16 | ||||
-rw-r--r-- | sbin/fdisk/Makefile | 14 | ||||
-rw-r--r-- | sbin/fdisk/cmd.c | 16 |
4 files changed, 34 insertions, 26 deletions
diff --git a/sbin/disklabel/Makefile b/sbin/disklabel/Makefile index d579685a120..e21d059622c 100644 --- a/sbin/disklabel/Makefile +++ b/sbin/disklabel/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.33 2004/05/03 15:18:19 drahn Exp $ +# $OpenBSD: Makefile,v 1.34 2004/11/06 18:57:59 otto Exp $ PROG= disklabel SRCS= disklabel.c dkcksum.c editor.c manual.c @@ -13,14 +13,14 @@ CLEANFILES+=manual.c .ifdef NOMAN manual.c: - (echo 'char manpage[] = "\\'; \ - echo "no manual\\"; \ - echo '";' ) > manual.c + (echo 'const char manpage[] = {'; \ + echo 'no manual' | gzip -9c | hexdump -ve '"0x" 1/1 "%02x,"'; \ + echo '};'; echo 'const int manpage_sz = sizeof(manpage);') > manual.c .else manual.c: disklabel.cat8 - (echo 'char manpage[] = "\\'; \ - sed -e 's/[\\"]/\\&/g' -e 's/$$/\\n\\/' disklabel.cat8; \ - echo '";' ) > manual.c + (echo 'const char manpage[] = {'; \ + gzip -9c disklabel.cat8 | hexdump -ve '"0x" 1/1 "%02x,"'; \ + echo '};'; echo 'const int manpage_sz = sizeof(manpage);') > manual.c .endif .if (${MACHINE} == "amiga") diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 83f8d689fa5..aa81c12bfee 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.96 2004/10/04 15:09:41 otto Exp $ */ +/* $OpenBSD: editor.c,v 1.97 2004/11/06 18:57:59 otto Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com> @@ -17,7 +17,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: editor.c,v 1.96 2004/10/04 15:09:41 otto Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.97 2004/11/06 18:57:59 otto Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -295,17 +295,21 @@ editor(struct disklabel *lp, int f, char *dev, char *fstabfile) case 'M': { sig_t opipe = signal(SIGPIPE, SIG_IGN); - char *pager; - extern char manpage[]; + char *pager, *cmd = NULL; + extern const char manpage[]; + extern const int manpage_sz; if ((pager = getenv("PAGER")) == NULL || *pager == '\0') pager = _PATH_LESS; - if ((fp = popen(pager, "w")) != NULL) { - (void) fwrite(manpage, strlen(manpage), 1, fp); + + if (asprintf(&cmd, "gunzip -qc|%s", pager) != -1 && + (fp = popen(cmd, "w")) != NULL) { + (void) fwrite(manpage, manpage_sz, 1, fp); pclose(fp); } else warn("unable to execute %s", pager); + free(cmd); (void)signal(SIGPIPE, opipe); break; } diff --git a/sbin/fdisk/Makefile b/sbin/fdisk/Makefile index 1c4ab151976..ca52b654f48 100644 --- a/sbin/fdisk/Makefile +++ b/sbin/fdisk/Makefile @@ -1,5 +1,5 @@ # -# $OpenBSD: Makefile,v 1.27 2004/05/03 15:18:19 drahn Exp $ +# $OpenBSD: Makefile,v 1.28 2004/11/06 18:57:59 otto Exp $ # # Copyright (c) 1997 Tobias Weingartner # All rights reserved. @@ -38,14 +38,14 @@ CLEANFILES+=manual.c .ifdef NOMAN manual.c: - (echo 'char manpage[] = "\\'; \ - echo "no manual\\"; \ - echo '";' ) > manual.c + (echo 'const char manpage[] = {'; \ + echo 'no manual' | gzip -9c | hexdump -ve '"0x" 1/1 "%02x,"'; \ + echo '};'; echo 'const int manpage_sz = sizeof(manpage);') > manual.c .else manual.c: fdisk.cat8 - (echo 'char manpage[] = "\\'; \ - sed -e 's/[\\"]/\\&/g' -e 's/$$/\\n\\/' fdisk.cat8; \ - echo '";' ) > manual.c + (echo 'const char manpage[] = {'; \ + gzip -9c fdisk.cat8 | hexdump -ve '"0x" 1/1 "%02x,"'; \ + echo '};'; echo 'const int manpage_sz = sizeof(manpage);') > manual.c .endif .else diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 9dc885c3a24..beb47b9f35b 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.36 2004/09/18 23:22:05 deraadt Exp $ */ +/* $OpenBSD: cmd.c,v 1.37 2004/11/06 18:57:59 otto Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -379,16 +379,20 @@ Xmanual(cmd_t *cmd, disk_t *disk, mbr_t *mbr, mbr_t *tt, int offset) char *pager = "/usr/bin/less"; char *p; sig_t opipe; - extern char manpage[]; + extern const char manpage[]; + extern const int manpage_sz; FILE *f; opipe = signal(SIGPIPE, SIG_IGN); if ((p = getenv("PAGER")) != NULL && (*p != '\0')) pager = p; - f = popen(pager, "w"); - if (f) { - (void) fwrite(manpage, strlen(manpage), 1, f); - pclose(f); + if (asprintf(&p, "gunzip -qc|%s", pager) != -1) { + f = popen(p, "w"); + if (f) { + (void) fwrite(manpage, manpage_sz, 1, f); + pclose(f); + } + free(p); } (void)signal(SIGPIPE, opipe); |