Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > 2aa39b423ede5fc57c0cec6c58460887 > files > 1

xman-1.0.3-6mdv2009.0.src.rpm

From 7dff8cbd7400a7118a9508623bee0c917da83c68 Mon Sep 17 00:00:00 2001
From: Paulo Cesar Pereira de Andrade <pcpa@mandriva.com.br>
Date: Thu, 17 Jan 2008 17:41:02 -0200
Subject: [PATCH] Add bzip2 manpage extension support.

This should really be handled by the existing code to handle multiple
extension formats...
---
 man.c    |    8 ++++++++
 man.h    |    1 +
 misc.c   |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 vendor.h |    9 ++++++++-
 4 files changed, 70 insertions(+), 1 deletions(-)

diff --git a/man.c b/man.c
index 8120048..8a83b89 100644
--- a/man.c
+++ b/man.c
@@ -447,6 +447,10 @@ ReadCurrentSection(Manual * local_manual, char * path)
     else if (streq(ptr + 1, GZIP_EXTENSION))
       *ptr = '\0';
 #endif
+#ifdef BZIP2_EXTENSION
+    else if (streq(ptr + 1, BZIP2_EXTENSION))
+      *ptr = '\0';
+#endif
   }
   
   nentries = local_manual->nentries;
@@ -485,6 +489,10 @@ ReadCurrentSection(Manual * local_manual, char * path)
       else if (streq(ptr + 1, GZIP_EXTENSION))
 	*ptr = '\0';
 #endif
+#ifdef BZIP2_EXTENSION
+      else if (streq(ptr + 1, BZIP2_EXTENSION))
+	*ptr = '\0';
+#endif
 #ifdef IGNORE_EXTENSION
       /* skip files with specified extension - they're not real man pages */
       else if (streq(ptr + 1, IGNORE_EXTENSION)) {
diff --git a/man.h b/man.h
index c284b36..4b256a1 100644
--- a/man.h
+++ b/man.h
@@ -166,6 +166,7 @@ typedef struct _ManpageGlobals{
 				   page from. */
   Boolean compress;		/* Compress file on save? */
   Boolean gzip;			/* Gzip file on save? */
+  Boolean bzip2;		/* Bzip2 file on save? */
   Boolean deletetempfile;	/* Need to delete tempfile when done? */
   char ** section_name;		/* The name of each of the sections */
 
diff --git a/misc.c b/misc.c
index 0175f43..fead780 100644
--- a/misc.c
+++ b/misc.c
@@ -255,6 +255,14 @@ FindManualFile(ManpageGlobals * man_globals, int section_num, int entry_num)
       return(file);
   }
 #endif
+#ifdef BZIP2_EXTENSION
+  {
+    sprintf(filename, "%s/%s%s/%s.%s", path, CAT,
+	    section + len_cat, page, BZIP2_EXTENSION);
+    if ( (file = Uncompress(man_globals, filename)) != NULL)
+      return(file);
+  }
+#endif
 #else
   for(i = 0; i < strlen(COMPRESSION_EXTENSIONS); i++) {
       snprintf(filename, sizeof(filename), "%s/%s%s/%s.%c", path, CAT,
@@ -381,6 +389,12 @@ UncompressNamed(ManpageGlobals * man_globals, char * filename, char * output,
     snprintf(cmdbuf, sizeof(cmdbuf), GUNZIP_FORMAT, filename, output);
   else
 #endif
+#ifdef BZIP2_EXTENSION
+  if (streq(filename + strlen(filename) - strlen(BZIP2_EXTENSION),
+	    BZIP2_EXTENSION))
+    sprintf(cmdbuf, BUNZIP2_FORMAT, filename, output);
+  else
+#endif
   snprintf(cmdbuf, sizeof(cmdbuf), UNCOMPRESS_FORMAT, filename, output);
   if(system(cmdbuf) == 0) 	/* execute search. */
     return(TRUE);
@@ -807,6 +821,8 @@ UncompressUnformatted(ManpageGlobals * man_globals, char * entry,
 
   ParseEntry(entry, path, section, page);
 
+  man_globals->bzip2 = FALSE;
+
 #if defined(__OpenBSD__) || defined(__NetBSD__)
   /*
    * look for uncompressed file in machine subdir first
@@ -856,6 +872,25 @@ UncompressUnformatted(ManpageGlobals * man_globals, char * entry,
   }
 #endif /* GZIP_EXTENSION */
 #endif /* __OpenBSD__ || __NetBSD__ */
+
+#ifdef BZIP2_EXTENSION
+ {
+    sprintf(input, "%s.%s", filename, BZIP2_EXTENSION);
+#ifndef HAS_MKSTEMP
+    if ( UncompressNamed(man_globals, input, filename) ) {
+#else
+    if ( UncompressNamed(man_globals, input, filename, file) ) {
+#endif
+      man_globals->compress = TRUE;
+      man_globals->gzip = FALSE;
+      man_globals->bzip2 = TRUE;
+      sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
+	      CAT, section + len_cat, page, BZIP2_EXTENSION);
+      return(TRUE);
+    }
+  }
+#endif /* BZIP2_EXTENSION */
+
 /*
  * Look for uncompressed file first.
  */
@@ -925,6 +960,24 @@ UncompressUnformatted(ManpageGlobals * man_globals, char * entry,
     }
   }
 #endif
+
+#ifdef BZIP2_EXTENSION
+  {
+    sprintf(input, "%s.%s", filename, BZIP2_EXTENSION);
+#ifndef HAS_MKSTEMP
+    if ( UncompressNamed(man_globals, input, filename) ) {
+#else
+    if ( UncompressNamed(man_globals, input, filename, file) ) {
+#endif	
+      man_globals->compress = TRUE;
+      man_globals->gzip = TRUE;
+      sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
+	      CAT, section + len_cat, page, BZIP2_EXTENSION);
+      return(TRUE);
+    }
+  }
+#endif
+
 /*
  * And lastly files in a compressed directory.
  */
diff --git a/vendor.h b/vendor.h
index 4632dcf..4412ccd 100644
--- a/vendor.h
+++ b/vendor.h
@@ -137,6 +137,13 @@ from the X Consortium.
 #    define GUNZIP_FORMAT "gzip -c -d < %s >> %s"
 #  endif
 #  define GZIP_COMPRESS "gzip"
+#  define BZIP2_EXTENSION "bz2"
+#  ifndef HAS_MKSTEMP
+#    define BUNZIP2_FORMAT "bunzip2 -c -d < %s > %s"
+#  else
+#    define BUNZIP2_FORMAT "bunzip2 -c -d < %s >> %s"
+#  endif
+#  define BZIP2_COMPRESS "bzip2"
 #endif
 
 
@@ -180,7 +187,7 @@ from the X Consortium.
 # define TBL "tbl"
 #else /* HANDLE_ROFFSEQ */
 # if defined(linux)
-#  define ZSOELIM	"zsoelim"
+#  define ZSOELIM	"soelim"
 # else
 #  define ZSOELIM	"soelim"
 #endif
-- 
1.5.3.5