socsvn commit: r240337 - soc2012/jhagewood/sdiff

jhagewood at FreeBSD.org jhagewood at FreeBSD.org
Mon Aug 13 23:06:18 UTC 2012


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 *);


More information about the svn-soc-all mailing list