Mods to pathalias to recognize compressed input files
mac at esl.UUCP
mac at esl.UUCP
Sat Sep 20 06:27:28 AEST 1986
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 at 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 at ames.ARPA | M M M O O SSS AAAA I C |
| mac%esl.UUCP at shasta.ARPA | M M M O O S A A I C C |
| mac%esl.UUCP at 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|
------------------------------------+-----------------------------------------+
More information about the Comp.sources.unix
mailing list