PERFORCE change 180709 for review

Benjamin Fiedler bfiedler at FreeBSD.org
Fri Jul 9 23:33:06 UTC 2010


http://p4web.freebsd.org/@@180709?ac=10

Change 180709 by bfiedler at freebsd-7803 on 2010/07/09 23:32:13

	Added printf-style support to format specifiers

Affected files ...

.. //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.c#12 edit
.. //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.h#10 edit
.. //depot/projects/soc2010/bsdtextproc/gabor_diff/diffreg.c#12 edit

Differences ...

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

@@ -58,7 +58,7 @@
 char	*start, *ifdefname, *diffargs, *label[2], *ignore_pats, *fnline_pat;
 struct stat stb1, stb2;
 struct excludes *excludes_list;
-regex_t	 ignore_re, fnline_re;
+regex_t	 ignore_re, fnline_re, printf_re;
 
 enum {
 	HELP_OPT = CHAR_MAX + 1,
@@ -420,6 +420,11 @@
 	if ( fnline_pat != NULL) {
 		compile_regex(&fnline_re, fnline_pat);
         }
+
+	if((flags & D_GROUP) || (flags & D_LINE )) {
+		compile_regex(&printf_re, 
+			"(%[#0-9\\.\\-\\+ ']*[doxX]+)(eflmnEFLMN)+");
+	}
 		
 	src = fromfile ? fromfile : argv[0];
 	dst = fromfile ? argv[0] : (tofile ? tofile : argv[1]);

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

@@ -105,7 +105,7 @@
 extern char	*line_format[3], *group_format[4], *fnline_pat;
 extern struct	 stat stb1, stb2;
 extern struct	 excludes *excludes_list;
-extern regex_t	 ignore_re, fnline_re;
+extern regex_t	 ignore_re, fnline_re, printf_re;
 
 char	*splice(char *, char *);
 char	*repstr(char*, const char*, const char*);

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

@@ -1345,6 +1345,7 @@
 		}
 		pos--;
 	}
+
 	return (lastmatchline > 0 ? lastbuf : NULL);
 }
 
@@ -1643,9 +1644,13 @@
 char * 
 replace_line_format(FILE *file, int *f, int pos, char *format)
 {
-	char             buf[FUNCTION_CONTEXT_SIZE];
+	char            *buf = emalloc( sizeof(char) * FUNCTION_CONTEXT_SIZE+1);
         size_t           nc;
         int              last = lastline;
+	regmatch_t	 pmatch[3];
+	char	 	*smatch[3];
+	char		*rep;
+	int		*d, i;
 
         lastline = pos;
         while (pos > last) {
@@ -1660,10 +1665,40 @@
 		}
 	}
 
-	/* XXX: need to evaluate ternary and 'expand' printf 
-	   format specifiers (using sprintf?) */ 
+	/* XXX: need to evaluate ternary */
+
+     while( regexec(&printf_re, buf, 3, pmatch, 0) == 0 ){
+                for(i=0; i < 3; i++)
+                {
+                        smatch[i] = strndup( &buf[ pmatch[i].rm_so], 
+				pmatch[i].rm_eo - pmatch[i].rm_so );
+                }
+
+		switch (*smatch[2]) {
+		case 'e':
+		case 'f':
+		case 'l':
+		case 'm':
+		case 'n':
+		case 'E':
+		case 'F':
+		case 'L':
+		case 'M':
+		case 'N':
+		default:
+		d = &pos;
+		break;
+		}
+
+		asprintf(&rep, smatch[1], *d);
+		buf = repstr(buf, smatch[0], rep);
 
-	/* reg_printf = "(%[#0-9\\.\\-\\+ 'doxX]*)(eflmnEFLMN)+" */
+		free(rep);
+		for(i=0; i < 3; i++)
+                {
+                        free(smatch[i]);
+                }
+	}
 
 	char *rline = estrdup( format );
 	rline = repstr(rline, "%L", buf);


More information about the p4-projects mailing list