Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!panda!genrad!decvax!decwrl!amdcad!cae780!leadsv!esl!mac From: mac@esl.UUCP Newsgroups: net.sources Subject: Mods to pathalias to recognize compressed input files Message-ID: <316@esl.UUCP> Date: Fri, 19-Sep-86 16:27:28 EDT Article-I.D.: esl.316 Posted: Fri Sep 19 16:27:28 1986 Date-Received: Sat, 20-Sep-86 05:48:14 EDT Reply-To: mac@tflop.UUCP (Mike McNamara) Organization: ESL, Inc., Sunnyvale, CA. Lines: 183 Keywords: compress(1) pathalias(l) 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| ------------------------------------+-----------------------------------------+