From: mitra@pandora.sf.ca.us (Mitra)
Subject: Re: patches to index compressed files?
Organization: Pandora Systems
Date: Tue, 15 Dec 1992 07:12:04 GMT
X-Newsreader: TIN [version 1.1 PL6]

I've finally tracked the problem in this, one easy one was a reference
to /usr/ucb/zcat which is BSD specific, the other nasty one was opening
one file to many, this causes core-dumps if you try and index too large 
a directory.

Here is a fixed patch - Jonathon, perhaps you'd like to integrate it
into the next distribution?

- Mitra

*** futil.c.orig	Tue Mar 24 10:30:35 1992
--- futil.c	Mon Dec 14 22:53:36 1992
***************
*** 233,240 ****
    struct stat *buf = (struct stat*)s_malloc((size_t)sizeof(struct stat));
    time_t mtime;
  
!   if(0 != stat(filename, buf)){
      panic("could not stat %s", filename);
    }
    mtime =  buf->st_mtime;
    s_free(buf);
--- 245,257 ----
    struct stat *buf = (struct stat*)s_malloc((size_t)sizeof(struct stat));
    time_t mtime;
  	
!   if(0 != stat(filename, buf)) {
!     /* might be the compressed one. */
!     char buffer[MAX_FILENAME_LEN+2];
!     sprintf(buffer, "%s.Z", filename);
!     if (0 != stat(buffer, buf)) {
        panic("could not stat %s", filename);
+     }
    }
    mtime =  buf->st_mtime;
    s_free(buf);
*** irtfiles.c.orig	Wed May  6 17:31:33 1992
--- irtfiles.c	Mon Dec 14 22:49:08 1992
***************




















*** 614,619 ****
--- 614,624 ----
  }
  
  #define LENGTH_OF_NEWLINE 1 /* this will be 2 on a PC, I think */  
+ #ifdef M_SCOUNIX
+ #define UNCOMPRESSOR "/usr/bin/zcat"
+ #else
+ #define UNCOMPRESSOR "/usr/ucb/zcat"
+ #endif
  
  void index_text_file(filename,
  		     separator_function,
***************
*** 662,672 ****
    long filename_id;
    document_table_entry the_document_table_entry;
    long document_id = next_document_id(db);
!   FILE* input_stream = s_fopen(filename, "r");
    long file_position_before_line = 0;
    long file_position_before_document = 0;
    long date;
  
    if(NULL == input_stream){
      waislog(WLOG_HIGH, WLOG_ERROR, 
  	    "File %s does not exist", filename);
--- 667,711 ----
    long filename_id;
    document_table_entry the_document_table_entry;
    long document_id = next_document_id(db);
!   FILE* input_stream = NULL;
    long file_position_before_line = 0;
    long file_position_before_document = 0;
    long date;
  
+ #if (defined(NeXT) || defined(Mach) || defined(BSD43))    
+   char tmpFileName[MAX_FILENAME_LEN+1];
+ #else
+   char *tmpFileName = NULL;
+ #endif /* NeXT or Mach */
+ 
+ 
+   if(filename != NULL &&
+      strlen(filename) > 1 &&
+      !strcmp(filename+(strlen(filename)-2), ".Z"))
+     /* it's a .Z file.  First, remove the suffix or many things get confused. */
+     filename[(strlen(filename)-2)] = 0;
+     
+   if(probe_file(filename)) {
+     input_stream = s_fopen(filename, "r");
+   }
+   else {
+     if(probe_file_possibly_compressed(filename)) {
+       char buffer[ 2 * MAX_FILENAME_LEN + 10 ];
+ #if (defined(NeXT) || defined(Mach) || defined(BSD43))
+       tmpnam(tmpFileName);
+ #else
+       tmpFileName = tempnam( "/tmp/", 0 );
+ #endif /* NeXT or Mach */
+       sprintf(buffer, "%s %s >%s", UNCOMPRESSOR, filename, tmpFileName);
+       if(system(buffer) != 0) {
+ 	waislog(WLOG_HIGH, WLOG_ERROR, "Error excuting system command: %s",
+ 		buffer);
+       }
+       input_stream = s_fopen(tmpFileName,"r");
+       unlink (tmpFileName);
+     }
+   }
    if(NULL == input_stream){
      waislog(WLOG_HIGH, WLOG_ERROR, 
  	    "File %s does not exist", filename);

Newsgroups: comp.infosystems.wais