[net.sources] Mods to pathalias to recognize compressed input files

mac@esl.UUCP (09/19/86)

	I try to keep the mod.maps newsgroup in compacted form, to
	conserve disk space.  When ever I update my pathalias database,
	I have to uncompact, then recompact these files.  I here post
	a modification of pathalias that allows it to recognize and
	read compacted input files.

*** parse.y.orig	Tue Jan 28 09:50:21 1986
--- parse.y	Fri Sep 19 11:20:51 1986
***************
*** 1,5
  %{
  /* pathalias -- by steve bellovin, as told to peter honeyman */
  #ifndef lint
  static char	*sccsid = "@(#)parse.y	8.1 (down!honey) 86/01/19";
  #endif lint

--- 1,8 -----
  %{
  /* pathalias -- by steve bellovin, as told to peter honeyman */
+ 
+ /* Added the ability for pathalias to recognize & read compressed input */
+ /*   files   -esl!mac Fri Sep 19 11:20:08 PDT 1986                      */
  #ifndef lint
  static char	*sccsid = "@(#)parse.y	8.2 (esl!mac) 86/01/19";
  #endif lint
***************
*** 1,7
  %{
  /* pathalias -- by steve bellovin, as told to peter honeyman */
  #ifndef lint
! static char	*sccsid = "@(#)parse.y	8.1 (down!honey) 86/01/19";
  #endif lint
  
  #include "def.h"

--- 4,10 -----
  /* Added the ability for pathalias to recognize & read compressed input */
  /*   files   -esl!mac Fri Sep 19 11:20:08 PDT 1986                      */
  #ifndef lint
! static char	*sccsid = "@(#)parse.y	8.2 (esl!mac) 86/01/19";
  #endif lint
  
  #include "def.h"
***************
*** 369,374
  	return((Cost) 0);
  }
  
  yywrap()
  {
  	char	errbuf[100];

--- 372,380 -----
  	return((Cost) 0);
  }
  
+ char magic_header[] = { "\037\235" };	/* 1F 9D */
+ #define WRITE 1
+ #define READ  0
  yywrap()
  {
  	char	errbuf[100];
***************
*** 372,377
  yywrap()
  {
  	char	errbuf[100];
  
  	fixprivate();	/* munge private host definitions */
  

--- 378,385 -----
  yywrap()
  {
  	char	errbuf[100];
+ 	int fds[2];
+ 	int f;
  
  	fixprivate();	/* munge private host definitions */
  
***************
*** 378,384
  	if (Ifiles == 0) 
  		return(1);
  
- 	fclose(stdin);
  	while (*Ifiles) {
  		Lineno = 1;
  		if (fopen((Cfile = *Ifiles++), "r"))

--- 386,391 -----
  	if (Ifiles == 0) 
  		return(1);
  
  	while (*Ifiles) {
  		Lineno = 1;
  		if (freopen((Cfile = *Ifiles++), "r", stdin)){
***************
*** 381,387
  	fclose(stdin);
  	while (*Ifiles) {
  		Lineno = 1;
! 		if (fopen((Cfile = *Ifiles++), "r"))
  			return(0);
  		sprintf(errbuf, "%s: %s", ProgName, Cfile);
  		perror(errbuf);

--- 388,413 -----
  
  	while (*Ifiles) {
  		Lineno = 1;
! 		if (freopen((Cfile = *Ifiles++), "r", stdin)){
! 			/* if compacted, undo .. */
! 			if (strcmp(Cfile + strlen(Cfile) - 2, ".Z") == 0) { 
! 				/* Check the magic number */
! 		      if ((getchar() == (magic_header[0] & 0xFF))
! 				  && (getchar() == (magic_header[1] & 0xFF))) {
! 					pipe(fds);
! 					if ((f=fork()) == -1 ){
! 						perror("Could not fork");
! 						exit(0);
! 					}else if (f==0) { /*child*/
! 						close(fds[READ]);
! 						dup2(fds[WRITE],1);
! 						execlp("compress","compress","-dc",Cfile,(char*) 0);
! 						perror("Could not execl...");
! 						exit(0);
! 					}else{ /* parent */
! 						close(fds[WRITE]);
! 						fclose(stdin);
! 						if (fdopen(fds[READ],"r"))
  							return(0);
  					}
  				}else /* ends in .Z, but nomagic ?? Assume not compressed */ 
***************
*** 383,388
  		Lineno = 1;
  		if (fopen((Cfile = *Ifiles++), "r"))
  			return(0);
  		sprintf(errbuf, "%s: %s", ProgName, Cfile);
  		perror(errbuf);
  	}

--- 409,420 -----
  						fclose(stdin);
  						if (fdopen(fds[READ],"r"))
  							return(0);
+ 					}
+ 				}else /* ends in .Z, but nomagic ?? Assume not compressed */ 
+ 					return(0);
+ 			}else /* not compressed */
+ 			return(0);
+ 		}
  		sprintf(errbuf, "%s: %s", ProgName, Cfile);
  		perror(errbuf);
  	}
*** CHANGES.orig	Fri Sep 19 13:22:44 1986
--- CHANGES	Fri Sep 19 13:24:20 1986
***************
*** 1,3
  -- mod.sources, 4.3bsd, 1/86
  Improved alias treatment.
  Routes to domain gateways.

--- 1,6 -----
+ -- mac@esl.UUCP -  9/86
+ Gave pathalias the ability to read compressed input files
+ 
  -- mod.sources, 4.3bsd, 1/86
  Improved alias treatment.
  Routes to domain gateways.

-- 
------------------------------------+-----------------------------------------+
| Michael Mc Namara                 |  MM MM MM    OO   SSS   AAA   II  CCCC  |
| ESL Incorporated                  |   M   M  M  O  O S         A   I C    C |
| ARPA: mac%esl.UUCP@ames.ARPA      |   M   M  M  O  O  SSS   AAAA   I C      |
|       mac%esl.UUCP@shasta.ARPA    |   M   M  M  O  O     S A   A   I C    C |
|       mac%esl.UUCP@lll-lcc.ARPA   |  MM   M  M   OO   SSS   AAA A III CCCC  |
------------------------------------+-----------------------------------------+
| Note: esl used to be called tflop; the path mac%tflop will still work awhile|
------------------------------------+-----------------------------------------+

tony@xios.UUCP (Keeper Of News) (10/01/86)

Anyone who has tried mac@esl.UUCP's patch to pathalais has probably
noticed that you quickly run out of processses.  I find it hard to
believe that this patch has ever worked, unless on his system fclose
(actually freopen) knows that the file it is closing is a pipe and does
a wait() automagicly. 

Here is a fix, just add it near the beginning of yywrap at the end of
parse.y. 


	while (*Ifiles) {
		Lineno = 1;
+		if( Cfile != NULL &&
+			strcmp(Cfile + strlen(Cfile) - 2, ".Z") == 0) { 
+				/*
+				 * Ignore the case where it ends in .Z but is not compressed
+				 * This is the hight of paranoia, and is more effort than I wish
+				 * to exert tonight.
+				 */
+				pclose(stdin);
+				}
		if (freopen((Cfile = *Ifiles++), "r", stdin)){
			/* if compacted, undo .. */
			if (strcmp(Cfile + strlen(Cfile) - 2, ".Z") == 0) { 
				/* Check the magic number */

-- 
-------------------------------------------------------------------------------
Tony Lill	Keeper of News @ Xios Systems Corporation 
				 1600 Carling Avenue, Suite 150, Ottawa,
				 Ontario, Canada, K1Z 8R8	(613) 725-5411
				 xios!tony
-------------------------------------------------------------------------------
		Not the edge of the world, but we can see it from here.