From owner-svn-soc-all@FreeBSD.ORG Mon Aug 13 23:06:18 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 AD226106564A for ; Mon, 13 Aug 2012 23:06:16 +0000 (UTC) (envelope-from jhagewood@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Mon, 13 Aug 2012 23:06:16 +0000 Date: Mon, 13 Aug 2012 23:06:16 +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: <20120813230616.AD226106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r240337 - 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: Mon, 13 Aug 2012 23:06:18 -0000 Author: jhagewood Date: Mon Aug 13 23:06:16 2012 New Revision: 240337 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240337 Log: File extension detection. Modified: soc2012/jhagewood/sdiff/decompress.c soc2012/jhagewood/sdiff/sdiff.c soc2012/jhagewood/sdiff/sdiff.h Modified: soc2012/jhagewood/sdiff/decompress.c ============================================================================== --- soc2012/jhagewood/sdiff/decompress.c Mon Aug 13 21:29:34 2012 (r240336) +++ soc2012/jhagewood/sdiff/decompress.c Mon Aug 13 23:06:16 2012 (r240337) @@ -71,3 +71,16 @@ return file; } + +/* Checks for a gz file extension. */ +int +isgzip(char *filename) { + + int length = (sizeof filename)-1; + + if (filename[length-1] == 'g' && filename[length] == 'z') + return 1; + + return 0; + +} Modified: soc2012/jhagewood/sdiff/sdiff.c ============================================================================== --- soc2012/jhagewood/sdiff/sdiff.c Mon Aug 13 21:29:34 2012 (r240336) +++ soc2012/jhagewood/sdiff/sdiff.c Mon Aug 13 23:06:16 2012 (r240337) @@ -62,6 +62,7 @@ }; extern FILE *decompressfile(char *, char *); +extern int isgzip(char *); static void astrcat(char **, const char *); static void enqueue(char *, char, char *); @@ -444,6 +445,13 @@ if ((diffpipe = fdopen(fd[0], "r")) == NULL) err(2, "could not open diff pipe"); } + + /* Checks for file extension to determine behavior. */ + if (isgzip(filename1) || isgzip(filename2)) + filebehave = FILE_GZIP); + else + filebehave = FILE_NORMAL; + if (filebehave == FILE_NORMAL) { if ((file1 = fopen(filename1, "r")) == NULL) err(2, "could not open %s", filename1); Modified: soc2012/jhagewood/sdiff/sdiff.h ============================================================================== --- soc2012/jhagewood/sdiff/sdiff.h Mon Aug 13 21:29:34 2012 (r240336) +++ soc2012/jhagewood/sdiff/sdiff.h Mon Aug 13 23:06:16 2012 (r240337) @@ -37,3 +37,4 @@ #define ZDIFF_PATH "/usr/bin/zdiff" FILE *decompressfile(char *, char *); +int isgzip(char *);