Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Aug 2012 23:19:52 +0000
From:      jhagewood@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r240338 - in soc2012/jhagewood: diff sdiff
Message-ID:  <20120813231952.B0BD3106566C@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhagewood
Date: Mon Aug 13 23:19:52 2012
New Revision: 240338
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240338

Log:
  File extension detection.

Modified:
  soc2012/jhagewood/diff/decompress.c
  soc2012/jhagewood/diff/diff.h
  soc2012/jhagewood/diff/diffreg.c
  soc2012/jhagewood/sdiff/sdiff.c

Modified: soc2012/jhagewood/diff/decompress.c
==============================================================================
--- soc2012/jhagewood/diff/decompress.c	Mon Aug 13 23:06:16 2012	(r240337)
+++ soc2012/jhagewood/diff/decompress.c	Mon Aug 13 23:19:52 2012	(r240338)
@@ -72,3 +72,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/diff/diff.h
==============================================================================
--- soc2012/jhagewood/diff/diff.h	Mon Aug 13 23:06:16 2012	(r240337)
+++ soc2012/jhagewood/diff/diff.h	Mon Aug 13 23:19:52 2012	(r240338)
@@ -104,3 +104,4 @@
 void	print_status(int, char *, char *, char *);
 
 FILE *decompressfile(char *, char *);
+int isgzip(char *);

Modified: soc2012/jhagewood/diff/diffreg.c
==============================================================================
--- soc2012/jhagewood/diff/diffreg.c	Mon Aug 13 23:06:16 2012	(r240337)
+++ soc2012/jhagewood/diff/diffreg.c	Mon Aug 13 23:19:52 2012	(r240338)
@@ -192,6 +192,7 @@
 };
 
 extern FILE *decompressfile(char *, char *);
+extern int isgzip(char *);
 
 static FILE	*opentemp(const char *);
 static void output(char *, FILE *, char *, FILE *, int);
@@ -338,6 +339,10 @@
 		} else if (strcmp(file1, "-") == 0)
 			f1 = stdin;
 		else {
+			if (isgzip(file1))
+				filebehave = FILE_GZIP;
+			else
+				filebehave = FILE_NORMAL;
 			if (filebehave == FILE_NORMAL) 
 				f1 = fopen(file1, "r");
 			if (filebehave == FILE_GZIP) {
@@ -364,6 +369,10 @@
 		} else if (strcmp(file2, "-") == 0)
 			f2 = stdin;
 		else {
+			if (isgzip(file1))
+				filebehave = FILE_GZIP;
+			else
+				filebehave = FILE_NORMAL;
 			if (filebehave == FILE_NORMAL) 
 				f2 = fopen(file2, "r");
 			if (filebehave == FILE_GZIP)

Modified: soc2012/jhagewood/sdiff/sdiff.c
==============================================================================
--- soc2012/jhagewood/sdiff/sdiff.c	Mon Aug 13 23:06:16 2012	(r240337)
+++ soc2012/jhagewood/sdiff/sdiff.c	Mon Aug 13 23:19:52 2012	(r240338)
@@ -448,7 +448,7 @@
 	
 	/* Checks for file extension to determine behavior. */
 	if (isgzip(filename1) || isgzip(filename2))
-		filebehave = FILE_GZIP);
+		filebehave = FILE_GZIP;
 	else
 		filebehave = FILE_NORMAL;
 		



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