Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Aug 2012 03:47:00 +0000
From:      jhagewood@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r240287 - soc2012/jhagewood/sdiff
Message-ID:  <20120812034700.8A17B106566C@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhagewood
Date: Sun Aug 12 03:46:59 2012
New Revision: 240287
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240287

Log:
  gzip decompression in sdiff

Modified:
  soc2012/jhagewood/sdiff/Makefile
  soc2012/jhagewood/sdiff/common.h
  soc2012/jhagewood/sdiff/sdiff.c

Modified: soc2012/jhagewood/sdiff/Makefile
==============================================================================
--- soc2012/jhagewood/sdiff/Makefile	Sun Aug 12 02:51:28 2012	(r240286)
+++ soc2012/jhagewood/sdiff/Makefile	Sun Aug 12 03:46:59 2012	(r240287)
@@ -3,20 +3,20 @@
 
 #.if defined(__FreeBSD__)
 
-INCLUDEDIR+=/usr/src/crypto/openssh/openbsd-compat /usr/src/contrib/traceroute/lbl
+INCLUDEDIR+= /usr/src/crypto/openssh/openbsd-compat /usr/src/contrib/traceroute/lbl
 
 .for dir in ${INCLUDEDIR}
           CFLAGS+= -I${dir}
 .endfor
 
-COPTS+=     -std=c99 -pedantic
+COPTS+= -std=c99 -pedantic
 DEBUG_FLAGS+= -g
 
 #.endif
 
-PROG=sdiff
-SRCS=common.c edit.c sdiff.c
-COPTS+=-Wall -W
+PROG= sdiff zsdiff
+SRCS= common.c edit.c sdiff.c
+COPTS+= -Wall -W
 
 LDADD+=	-lutil
 DPADD+=	${LIBUTIL}

Modified: soc2012/jhagewood/sdiff/common.h
==============================================================================
--- soc2012/jhagewood/sdiff/common.h	Sun Aug 12 02:51:28 2012	(r240286)
+++ soc2012/jhagewood/sdiff/common.h	Sun Aug 12 03:46:59 2012	(r240287)
@@ -7,3 +7,9 @@
 
 void cleanup(const char *) __dead2;
 FILE *decompressfile(char *, char *);
+
+/*
+ * File input types
+ */
+#define FILE_NORMAL	0
+#define FILE_GZIP	1

Modified: soc2012/jhagewood/sdiff/sdiff.c
==============================================================================
--- soc2012/jhagewood/sdiff/sdiff.c	Sun Aug 12 02:51:28 2012	(r240286)
+++ soc2012/jhagewood/sdiff/sdiff.c	Sun Aug 12 03:46:59 2012	(r240287)
@@ -88,6 +88,8 @@
 int	sflag;		/* skip identical lines */
 FILE *outfp;		/* file to save changes to */
 const char *tmpdir;	/* TMPDIR or /tmp */
+char *pn;		/* program name */
+char *filebehave;	/* open file behavior */
 	
 enum {
 	    HELP_OPT = CHAR_MAX + 1,
@@ -249,6 +251,15 @@
 	struct option *popt;
 	char **diffargv, *diffprog = "/usr/bin/diff", *filename1, *filename2,
 	    *tmp1, *tmp2, *s1, *s2;
+	    
+	filebehave = FILE_NORMAL;
+	/* Check what is the program name of the binary.  In this
+	   way we can have all the funcionalities in one binary
+	   without the need of scripting and using ugly hacks. */
+	pn = getprogname();
+	if (pn[0] == 'z') {
+		filebehave = FILE_GZIP;
+	}
 
 	/*
 	 * Process diff flags.
@@ -430,12 +441,19 @@
 		if ((diffpipe = fdopen(fd[0], "r")) == NULL)
 			err(2, "could not open diff pipe");
 	}
-	
-	if ((file1 = fopen(filename1, "r")) == NULL)
-		err(2, "could not open %s", filename1);
-	if ((file2 = fopen(filename2, "r")) == NULL)
-		err(2, "could not open %s", filename2);
-
+	if (filebehave == FILE_NORMAL) {
+		if ((file1 = fopen(filename1, "r")) == NULL)
+			err(2, "could not open %s", filename1);
+		if ((file2 = fopen(filename2, "r")) == NULL)
+			err(2, "could not open %s", filename2);
+	}
+	/* Decompress gzip input files, treat them as regular FILEs. */
+	if (filebehave == FILE_GZIP) {
+		if ((file1 = decompressfile(filename1, "r")) == NULL)
+			err(2, "could not open %s", filename1);
+		if ((file2 = decompressfile(filename2, "r")) == NULL)
+			err(2, "could not open %s", filename2);		
+	}
 	if (!istextfile(file1) || !istextfile(file2)) {
 		/* Close open files and pipe, delete temps */ 
 		fclose(file1);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120812034700.8A17B106566C>