New manpage compression support. Only one macro controls compression
authorJordan K. Hubbard <jkh@FreeBSD.org>
Sat, 5 Mar 1994 13:48:38 +0000 (13:48 +0000)
committerJordan K. Hubbard <jkh@FreeBSD.org>
Sat, 5 Mar 1994 13:48:38 +0000 (13:48 +0000)
now, DO_COMPRESS.  This controls whether or not catpages are compressed or
not (on by default, since little else uses the catpages and those few things
that do can always configure in a `zmore' in place of more or something, and
saving space is more important, IMHO).

Uncompression support is now on by default since that's the only way to support
mixed-mode environments.  If you don't like it, just don't compress your man
pages and it won't be used! :-).  Supports gzip.  You can also compress
the man pages themselves (or gzip them) now and it will work.

gnu/usr.bin/man/Makefile.inc
gnu/usr.bin/man/catman/Makefile
gnu/usr.bin/man/lib/Makefile
gnu/usr.bin/man/lib/config.h_dist
gnu/usr.bin/man/makewhatis/Makefile
gnu/usr.bin/man/makewhatis/makewhatis.sh
gnu/usr.bin/man/man/Makefile
gnu/usr.bin/man/man/man.c
gnu/usr.bin/man/man/man.man

index c0df250..b993e79 100644 (file)
@@ -19,6 +19,8 @@ refer=                        /usr/bin/refer
 grap=                  # no grap
 pic=                   /usr/bin/pic
 zcat=                  /usr/bin/zcat
 grap=                  # no grap
 pic=                   /usr/bin/pic
 zcat=                  /usr/bin/zcat
+compress=              gzip -c
+compext=               .gz
 
 # For scripts.
 .if !target(obj)
 
 # For scripts.
 .if !target(obj)
index de870e3..15672d5 100644 (file)
@@ -1,8 +1,15 @@
-obj cleandir clean depend rcsfreeze tags all:
-       @echo -n
+NOMAN= noman
+CLEANFILES=    catman
 
 
-install:
-       install -c -o bin -g bin -m 555 catman ${DESTDIR}/usr/bin
+beforeinstall: catman
+       install -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
+            ${.CURDIR}/catman ${DESTDIR}${BINDIR}
 
 
-.include "../Makefile.inc"
 .include <bsd.prog.mk>
 .include <bsd.prog.mk>
+
+catman: catman.sh
+       sed -e 's,%compress%,${compress},' \
+       -e 's,%compext%,${compext},' \
+       -e 's,%zcat%,${zcat},' \
+          ${.CURDIR}/catman.sh > catman
+
index d364b32..7134c86 100644 (file)
@@ -6,8 +6,9 @@ CONFH=  ${.CURDIR}/obj/config.h
 CONFH=  ${.CURDIR}/config.h
 .endif
 
 CONFH=  ${.CURDIR}/config.h
 .endif
 
+NOPROFILE=     YES
 
 
-CFLAGS+= -I${.CURDIR} -DSTDC_HEADERS -DPOSIX -DHAS_TROFF -DDO_UNCOMPRESS -DALT_SYSTEMS
+CFLAGS+= -I${.CURDIR} -DSTDC_HEADERS -DPOSIX -DHAS_TROFF -DDO_COMPRESS -DALT_SYSTEMS
 CLEANFILES+=   ${CONFH}
 SRCS = util.c gripes.c
 
 CLEANFILES+=   ${CONFH}
 SRCS = util.c gripes.c
 
@@ -25,6 +26,8 @@ depend ${CONFH}:      ${.CURDIR}/config.h_dist ../Makefile.inc
            -e 's,%vgrind%,${vgrind},' -e 's,%refer%,${refer},' \
            -e 's,%grap%,${grap},' -e 's,%zcat%,${zcat},' \
            -e 's,%manpath_config_file%,${manpath_config_file},' \
            -e 's,%vgrind%,${vgrind},' -e 's,%refer%,${refer},' \
            -e 's,%grap%,${grap},' -e 's,%zcat%,${zcat},' \
            -e 's,%manpath_config_file%,${manpath_config_file},' \
+           -e 's,%compress%,${compress},' \
+           -e 's,%compext%,${compext},' \
         ${.CURDIR}/config.h_dist > ${CONFH}
 
 .include <bsd.lib.mk>
         ${.CURDIR}/config.h_dist > ${CONFH}
 
 .include <bsd.lib.mk>
index 74122df..3438e6f 100644 (file)
  * Austin, Texas  78712
  */
 
  * Austin, Texas  78712
  */
 
-#ifdef COMPRESS
-#define DO_COMPRESS
-#define DO_UNCOMPRESS
-#endif
-
 /*
  * This is the size of a number of internal buffers.  It should
  * probably not be less than 512.
 /*
  * This is the size of a number of internal buffers.  It should
  * probably not be less than 512.
 /*
  * Define the uncompression program(s) to use for those preformatted
  * pages that end in the given character.  If you add extras here, you
 /*
  * Define the uncompression program(s) to use for those preformatted
  * pages that end in the given character.  If you add extras here, you
- * may need to change man.c.
+ * may need to change man.c.  [I have no idea what FCAT and YCAT files
+ * are! - I will leave them in for now.. -jkh]
  */
  */
-#ifdef DO_UNCOMPRESS
 /* .F files */
 #define FCAT ""
 /* .Y files */
 #define YCAT ""
 /* .Z files */
 #define ZCAT "%zcat%"
 /* .F files */
 #define FCAT ""
 /* .Y files */
 #define YCAT ""
 /* .Z files */
 #define ZCAT "%zcat%"
-#endif
 
 /*
  * This is the standard program to use on this system for compressing
  * pages once they have been formatted, and the character to tack on
  * to the end of those files.  The program listed is expected to read
  * from the standard input and write compressed output to the standard
 
 /*
  * This is the standard program to use on this system for compressing
  * pages once they have been formatted, and the character to tack on
  * to the end of those files.  The program listed is expected to read
  * from the standard input and write compressed output to the standard
- * output.
+ * output.  These won't actually be used unless compression is enabled.
  */
 #ifdef DO_COMPRESS
  */
 #ifdef DO_COMPRESS
-#define COMPRESSOR ""
-#define COMPRESS_EXT ""
+#define COMPRESSOR "%compress%"
+#define COMPRESS_EXT "%compext%"
 #endif
 
 /*
 #endif
 
 /*
index f146c9d..ea9c4e4 100644 (file)
@@ -5,11 +5,13 @@ CLEANFILES= makewhatis
 
 beforeinstall: makewhatis
        install -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
 
 beforeinstall: makewhatis
        install -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
-            ${.CURDIR}/makewhatis.sh ${DESTDIR}${BINDIR}/makewhatis
+            ${.CURDIR}/makewhatis ${DESTDIR}${BINDIR}
 
 .include <bsd.prog.mk>
 
 makewhatis: makewhatis.sh
        sed -e 's/%sections%/ "1", "n", "l", "6", "8", "2", "3", "4", "5", "7", "p", "o", NULL/' \
 
 .include <bsd.prog.mk>
 
 makewhatis: makewhatis.sh
        sed -e 's/%sections%/ "1", "n", "l", "6", "8", "2", "3", "4", "5", "7", "p", "o", NULL/' \
+       -e 's,%zcat%,${zcat},' \
+       -e 's,%compext%,${compext},' \
           ${.CURDIR}/makewhatis.sh > makewhatis
 
           ${.CURDIR}/makewhatis.sh > makewhatis
 
index 1d86d19..28b871d 100644 (file)
@@ -30,9 +30,16 @@ do
         then
             for f in `find $subdir -type f -print`
             do
         then
             for f in `find $subdir -type f -print`
             do
+               suffix=`echo $f | sed -e 's/.*\\.//'`
+               if [ ".$suffix" = "%compext%" ]; then
+                       output=%zcat%
+               else
+                       output=cat
+               fi
+               $output $f | \
                 sed -n '/^\.TH.*$/p
                        /^\.Dt.*$/p
                 sed -n '/^\.TH.*$/p
                        /^\.Dt.*$/p
-                        /^\.S[hH][         ]*NAME/,/^\.S[hH]/p' $f |\
+                        /^\.S[hH][         ]*NAME/,/^\.S[hH]/p'|\
                 sed -e 's/\\[   ]*\-/-/
                         s/^.P[Pp].*$//
                         s/\\(em//
                 sed -e 's/\\[   ]*\-/-/
                         s/^.P[Pp].*$//
                         s/\\(em//
index c00976b..4181aef 100644 (file)
@@ -17,13 +17,14 @@ MAN1=   ${.CURDIR}/man.1
 
 DPADD+=  ${MAN1}
 CFLAGS+= -I${.CURDIR}/../lib -DSTDC_HEADERS -DPOSIX -DHAS_TROFF 
 
 DPADD+=  ${MAN1}
 CFLAGS+= -I${.CURDIR}/../lib -DSTDC_HEADERS -DPOSIX -DHAS_TROFF 
-CFLAGS+= -DDO_UNCOMPRESS -DALT_SYSTEMS -DSETREUID -DCATMODE=0664
+CFLAGS+= -DDO_COMPRESS -DALT_SYSTEMS -DSETREUID -DCATMODE=0664
 CLEANFILES+=   ${MAN1}
 
 ${MAN1}: ${.CURDIR}/man.man
        sed -e 's,%libdir%,${libdir},' -e 's,%bindir%,${bindir},' \
            -e 's,%pager%,${pager},' -e 's,%troff%,${troff},' \
            -e 's,%manpath_config_file%,${manpath_config_file},' \
 CLEANFILES+=   ${MAN1}
 
 ${MAN1}: ${.CURDIR}/man.man
        sed -e 's,%libdir%,${libdir},' -e 's,%bindir%,${bindir},' \
            -e 's,%pager%,${pager},' -e 's,%troff%,${troff},' \
            -e 's,%manpath_config_file%,${manpath_config_file},' \
+           -e 's,%compress%,${compress},' \
        ${.CURDIR}/man.man > ${MAN1}
 
 .include <bsd.prog.mk>
        ${.CURDIR}/man.man > ${MAN1}
 
 .include <bsd.prog.mk>
index c5b4ee0..5e7d157 100644 (file)
@@ -524,11 +524,15 @@ convert_name (name, to_cat)
   if (to_cat)
     {
       int len = strlen (name) + 3;
   if (to_cat)
     {
       int len = strlen (name) + 3;
+      int cextlen = strlen(COMPRESS_EXT);
+
       to_name = (char *) malloc (len);
       if (to_name == NULL)
        gripe_alloc (len, "to_name");
       strcpy (to_name, name);
       to_name = (char *) malloc (len);
       if (to_name == NULL)
        gripe_alloc (len, "to_name");
       strcpy (to_name, name);
-      strcat (to_name, ".Z");
+      /* Avoid tacking it on twice */
+      if (strcmp(name + (len - (3 + cextlen)), COMPRESS_EXT))
+       strcat (to_name, COMPRESS_EXT);
     }
   else
     to_name = strdup (name);
     }
   else
     to_name = strdup (name);
@@ -660,43 +664,30 @@ make_name (path, section, name, cat)
   return &names[0];
 }
 
   return &names[0];
 }
 
-#ifdef DO_UNCOMPRESS
 char *
 get_expander (file)
      char *file;
 {
 char *
 get_expander (file)
      char *file;
 {
-  char *expander = NULL;
-  int len = strlen (file);
+  char *end = file + (strlen (file) - 1);
 
 
-  if (file[len - 2] == '.')
-    {
-      switch (file[len - 1])
-       {
+  while (end > file && end[-1] != '.')
+    --end;
+  if (end == file)
+    return NULL;
 #ifdef FCAT
 #ifdef FCAT
-       case 'F':
-         if (strcmp (FCAT, "") != 0)
-           expander = strdup (FCAT);
-         break;
-#endif
+  if (*end == 'F')
+    return FCAT;
+#endif /* FCAT */
 #ifdef YCAT
 #ifdef YCAT
-       case 'Y':
-         if (strcmp (YCAT, "") != 0)
-           expander = strdup (YCAT);
-         break;
-#endif
+  if (*end == 'Y')
+    return YCAT;
+#endif /* YCAT */
 #ifdef ZCAT
 #ifdef ZCAT
-       case 'Z':
-         if (strcmp (ZCAT, "") != 0)
-           expander = strdup (ZCAT);
-         break;
-#endif
-       default:
-         break;
-       }
-    }
-  return expander;
+  if (*end == 'Z' || !strcmp(end, "gz"))
+    return ZCAT;
+#endif /* ZCAT */
+  return NULL;
 }
 }
-#endif
 
 /*
  * Simply display the preformatted page.
 
 /*
  * Simply display the preformatted page.
@@ -712,16 +703,12 @@ display_cat_file (file)
 
   if (access (file, R_OK) == 0)
     {
 
   if (access (file, R_OK) == 0)
     {
-#ifdef DO_UNCOMPRESS
       char *expander = get_expander (file);
 
       if (expander != NULL)
        sprintf (command, "%s %s | %s", expander, file, pager);
       else
        sprintf (command, "%s %s", pager, file);
       char *expander = get_expander (file);
 
       if (expander != NULL)
        sprintf (command, "%s %s | %s", expander, file, pager);
       else
        sprintf (command, "%s %s", pager, file);
-#else
-      sprintf (command, "%s %s", pager, file);
-#endif
 
       found = do_system_command (command);
     }
 
       found = do_system_command (command);
     }
@@ -911,7 +898,6 @@ parse_roff_directive (cp, file, buf)
       strcat (buf, " | ");
       strcat (buf, NROFF);
     }
       strcat (buf, " | ");
       strcat (buf, NROFF);
     }
-
   if (tbl_found && !troff && strcmp (COL, "") != 0)
     {
       strcat (buf, " | ");
   if (tbl_found && !troff && strcmp (COL, "") != 0)
     {
       strcat (buf, " | ");
@@ -992,22 +978,21 @@ make_roff_command (file)
   if (debug)
     fprintf (stderr, "using default preprocessor sequence\n");
 
   if (debug)
     fprintf (stderr, "using default preprocessor sequence\n");
 
+  if ((cp = get_expander(file)) == NULL)
+    cp = "cat";
+  sprintf(buf, "%s %s | ", cp, file);
 #ifdef HAS_TROFF
   if (troff)
     {
       if (strcmp (TBL, "") != 0)
        {
 #ifdef HAS_TROFF
   if (troff)
     {
       if (strcmp (TBL, "") != 0)
        {
-         strcpy (buf, TBL);
-         strcat (buf, " ");
-         strcat (buf, file);
+         strcat (buf, TBL);
          strcat (buf, " | ");
          strcat (buf, TROFF);
        }
       else
        {
          strcat (buf, " | ");
          strcat (buf, TROFF);
        }
       else
        {
-         strcpy (buf, TROFF);
-         strcat (buf, " ");
-         strcat (buf, file);
+         strcat (buf, TROFF);
        }
     }
   else
        }
     }
   else
@@ -1015,17 +1000,13 @@ make_roff_command (file)
     {
       if (strcmp (TBL, "") != 0)
        {
     {
       if (strcmp (TBL, "") != 0)
        {
-         strcpy (buf, TBL);
-         strcat (buf, " ");
-         strcat (buf, file);
+         strcat (buf, TBL);
          strcat (buf, " | ");
          strcat (buf, NROFF);
        }
       else
        {
          strcpy (buf, NROFF);
          strcat (buf, " | ");
          strcat (buf, NROFF);
        }
       else
        {
          strcpy (buf, NROFF);
-         strcat (buf, " ");
-         strcat (buf, file);
        }
 
       if (strcmp (COL, "") != 0)
        }
 
       if (strcmp (COL, "") != 0)
@@ -1073,7 +1054,7 @@ make_cat_file (path, man_file, cat_file)
 #endif
       /*
        * Don't let the user interrupt the system () call and screw up
 #endif
       /*
        * Don't let the user interrupt the system () call and screw up
-       * the formmatted man page if we're not done yet.
+       * the formatted man page if we're not done yet.
        */
       fprintf (stderr, "Formatting page, please wait...");
       fflush(stderr);
        */
       fprintf (stderr, "Formatting page, please wait...");
       fflush(stderr);
index 2c034fe..bddfc02 100644 (file)
@@ -27,7 +27,9 @@ like to display the formatted pages.  If section is specified, man
 only looks in that section of the manual.  You may also specify the
 order to search the sections for entries and which preprocessors to
 run on the source files via command line options or environment
 only looks in that section of the manual.  You may also specify the
 order to search the sections for entries and which preprocessors to
 run on the source files via command line options or environment
-variables.
+variables.  If enabled by the system administrator, formatted man
+pages will also be compressed with the `%compress%' command to save
+space.
 .SH OPTIONS
 .TP
 .B \-\^M " path"
 .SH OPTIONS
 .TP
 .B \-\^M " path"