From owner-svn-soc-all@FreeBSD.ORG Sun Aug 12 03:47:02 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 8A17B106566C for ; Sun, 12 Aug 2012 03:47:00 +0000 (UTC) (envelope-from jhagewood@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sun, 12 Aug 2012 03:47:00 +0000 Date: Sun, 12 Aug 2012 03:47:00 +0000 From: jhagewood@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120812034700.8A17B106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r240287 - soc2012/jhagewood/sdiff X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Aug 2012 03:47:02 -0000 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);