Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Jun 2010 23:47:12 GMT
From:      Benjamin Fiedler <bfiedler@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 180060 for review
Message-ID:  <201006212347.o5LNlC5q000549@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@180060?ac=10

Change 180060 by bfiedler@freebsd-7803 on 2010/06/21 23:47:06

	Merge my missing additions(help, tabsize, 'y') to Gabor's branch

Affected files ...

.. //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.c#2 edit
.. //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.h#2 edit
.. //depot/projects/soc2010/bsdtextproc/gabor_diff/diffreg.c#2 edit
.. //depot/projects/soc2010/bsdtextproc/gabor_diff/pathnames.h#2 edit

Differences ...

==== //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.c#2 (text+ko) ====

@@ -44,9 +44,10 @@
 #include <unistd.h>
 
 #include "diff.h"
+#include "pathnames.h"
 
 int	 aflag, bflag, Bflag, dflag, iflag, lflag, Nflag, Pflag, pflag, rflag;
-int	 sflag, tflag, Tflag, wflag, uniflag, strip_cr;
+int	 sflag, tflag, Tflag, wflag, uniflag, yflag, strip_cr, tabsize=8;
 int	 format, status;
 int	 fcase_behave = FCASE_SENSITIVE;
 unsigned long long context;
@@ -64,17 +65,26 @@
 	TOFILE_OPT,
 	UNIDIR_OPT,
 	STRIPCR_OPT,
-	NOOP_OPT
+	NOOP_OPT,
+
+	LEFTC_OPT,
+	SUPCL_OPT,
+	GTYPE_OPT,
+	LF_OPT,
+	LLF_OPT,
+	TSIZE_OPT,
+	HLINES_OPT,
+	OPT_LFILES,
 };
 
-#define	OPTIONS	"0123456789abBC:cdD:efhI:iL:lnNPpqrS:sTtU:uvwX:x:"
+
+#define	OPTIONS	"0123456789abBC:cdD:efhI:iL:lnNPpqrS:sTtU:uvwX:x:y"
 static struct option longopts[] = {
 	{ "ignore-file-name-case",	no_argument,		NULL,	FCASE_IGNORE_OPT },
 	{ "no-ignore-file-name-case",	no_argument,		NULL,	FCASE_SENSITIVE_OPT },
 	{ "strip-trailing-cr",		no_argument,		NULL,	STRIPCR_OPT },
 	{ "normal",			no_argument,		NULL,	NORMAL_OPT },
-/* XXX: UNIMPLEMENTED
-	{ "tabsize",			optional_argument,	NULL,	OPT_TSIZE }, */
+	{ "tabsize",			optional_argument,	NULL,	TSIZE_OPT },
 	{ "unidirectional-new-file",	no_argument,		NULL,	UNIDIR_OPT },
 	{ "from-file",			required_argument,	NULL,	FROMFILE_OPT },
 	{ "to-file",			required_argument,	NULL,	TOFILE_OPT },
@@ -109,6 +119,8 @@
 	{ "exclude-from",		required_argument,	NULL,	'X' },
 	{ "exclude",			required_argument,	NULL,	'x' },
 	{ "speed-large-files",          no_argument,            NULL,   NOOP_OPT },
+	
+	{ "side-by-side",		no_argument,		NULL,	'y' },
 /* XXX: the following are not very well documented and rarely used. If we need
         them at all, we will need to dig into the code to see what do they do
         actually.
@@ -130,6 +142,16 @@
 	{ NULL,				0,			NULL,	'\0'}
 };
 
+static const char *help_msg[] = { 
+"-a --text  treat files as ASCII text",
+"-B --ignore-blank-lines  Ignore blank newlines in the comparison",
+"-b --ignore-space-change  Ignore all changes due to whitespace",
+"-C NUM --context=[NUM]  Show NUM lines before and after change (default 3)",
+"-D --ifdef=NAME",
+NULL,
+};
+char **help_strs = (char **)help_msg;
+
 void usage(void);
 void push_excludes(char *);
 void push_ignore_pats(char *);
@@ -140,11 +162,12 @@
 main(int argc, char **argv)
 {
 	char	*ep, *fromfile = NULL, *tofile = NULL, **oargv, *src, *dst;
-	int	 ch, lastch, gotstdin, prevoptind, newarg, flags = 0;
+	int	 ch, lastch, gotstdin, prevoptind, newarg, oargc, flags = 0;
 
 	setlocale(LC_ALL, "");
 
 	oargv = argv;
+	oargc = argc;
 	gotstdin = 0;
 
 	lastch = '\0';
@@ -266,6 +289,9 @@
 		case 'x':
 			push_excludes(optarg);
 			break;
+		case 'y':
+			yflag = 1;
+			break;
 		case FROMFILE_OPT:
 			if (tofile != NULL)
 				err(2, "--from-file and --to-file are both specified");
@@ -288,6 +314,15 @@
 		case STRIPCR_OPT:
 			strip_cr = 1;
 			break;
+		case TSIZE_OPT:
+                        if (optarg != NULL) {
+                                context = strtol(optarg, &ep, 10);
+                                if (*ep != '\0' || context < 1 || context >=ULLONG_MAX)
+                                        err(2, "context out of range\n");
+                                tabsize = (int)context;
+                        } else 
+                                tabsize = 8;
+                        break; 
 		case NOOP_OPT:
 			/* noop, compatibility */
 			break;
@@ -296,7 +331,11 @@
 			break;
 		case HELP_OPT:
 		default:
-			usage();
+			for(;*help_strs;help_strs++) 
+			{
+				printf( "%s\n", *help_strs);
+			}
+			exit(2);
 			break;
 		}
 		lastch = ch;
@@ -305,6 +344,20 @@
 	}
 	argc -= optind;
 	argv += optind;
+	
+	if(yflag) {
+		/* remove y flag from args and call sdiff */
+		for(argv=oargv; argv && strcmp(*argv, "-y") != 0; argv++);
+		while(argv != &oargv[oargc]){
+			*argv=*(argv+1);
+			argv++;
+		}
+		oargv[0] = _PATH_SDIFF;
+		*argv= "\0";
+
+		execv(_PATH_SDIFF, oargv);
+		_exit(127);
+	}
 
 	/*
 	 * Do sanity checks, fill in stb1 and stb2 and call the appropriate

==== //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.h#2 (text+ko) ====

@@ -83,7 +83,7 @@
 };
 
 extern int	 aflag, bflag, Bflag, dflag, iflag, lflag, Nflag, Pflag, pflag, rflag,
-		 sflag, tflag, Tflag, wflag, uniflag, strip_cr;
+		 sflag, tflag, Tflag, wflag, uniflag, strip_cr, tabsize;
 extern int	 format, status;
 extern int	 fcase_behave;
 extern unsigned long long context;

==== //depot/projects/soc2010/bsdtextproc/gabor_diff/diffreg.c#2 (text+ko) ====

@@ -1080,6 +1080,7 @@
 fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile)
 {
 	int	 i, j, c, lastc, col, nc;
+	int	 newcol;
 
 	/*
 	 * When doing #ifdef's, copy down to current line
@@ -1128,9 +1129,10 @@
 				return (0);
 			}
 			if (c == '\t' && tflag) {
+				newcol = ((col/tabsize)+1)*tabsize;
 				do {
-					putchar(' ');
-				} while (++col & 7);
+					putwchar(L' ');
+				} while (++col < newcol);
 			} else {
 				if (format == D_EDIT && j == 1 && c == '\n'
 				    && lastc == '.') {

==== //depot/projects/soc2010/bsdtextproc/gabor_diff/pathnames.h#2 (text+ko) ====

@@ -23,3 +23,4 @@
 #include <paths.h>
 
 #define	_PATH_PR	"/usr/bin/pr"
+#define _PATH_SDIFF     "/usr/bin/sdiff"



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