From owner-p4-projects@FreeBSD.ORG Tue Jul 6 06:48:06 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E8C301065674; Tue, 6 Jul 2010 06:48:05 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 94E141065672 for ; Tue, 6 Jul 2010 06:48:05 +0000 (UTC) (envelope-from bfiedler@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 806EC8FC15 for ; Tue, 6 Jul 2010 06:48:05 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o666m55V051481 for ; Tue, 6 Jul 2010 06:48:05 GMT (envelope-from bfiedler@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o666m5p1051479 for perforce@freebsd.org; Tue, 6 Jul 2010 06:48:05 GMT (envelope-from bfiedler@FreeBSD.org) Date: Tue, 6 Jul 2010 06:48:05 GMT Message-Id: <201007060648.o666m5p1051479@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bfiedler@FreeBSD.org using -f From: Benjamin Fiedler To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 180518 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jul 2010 06:48:06 -0000 http://p4web.freebsd.org/@@180518?ac=10 Change 180518 by bfiedler@freebsd-home on 2010/07/06 06:48:02 Rename strrep to repstr (reserved names). Start group and line format support, as well as function match. Still a fair amount of work to do on these implementations. Affected files ... .. //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.c#9 edit .. //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.h#8 edit .. //depot/projects/soc2010/bsdtextproc/gabor_diff/diffreg.c#10 edit Differences ... ==== //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.c#9 (text+ko) ==== @@ -53,11 +53,12 @@ int tabsize = 8; int format, status; int fcase_behave = FCASE_SENSITIVE; +char *line_format[3] = {NULL}, *group_format[4] = {NULL}; unsigned long long context; -char *start, *ifdefname, *diffargs, *label[2], *ignore_pats; +char *start, *ifdefname, *diffargs, *label[2], *ignore_pats, *fnline_pat; struct stat stb1, stb2; struct excludes *excludes_list; -regex_t ignore_re; +regex_t ignore_re, fnline_re; enum { HELP_OPT = CHAR_MAX + 1, @@ -72,13 +73,20 @@ LEFTC_OPT, SUPCL_OPT, LF_OPT, + +/* the following groupings must be in sequence +*/ + OLDGF_OPT, + NEWGF_OPT, UNCGF_OPT, CHGF_OPT, - OLDGF_OPT, - NEWGF_OPT, - UNCLF_OPT, + OLDLF_OPT, NEWLF_OPT, + UNCLF_OPT, +/* end order-sensitive enums +*/ + TSIZE_OPT, HLINES_OPT, LFILES_OPT, @@ -136,17 +144,41 @@ /* XXX: the following are not very well documented and rarely used. */ { "line-format", required_argument, NULL, LF_OPT }, + { "old-line-format", required_argument, NULL, OLDLF_OPT }, + { "new-line-format", required_argument, NULL, NEWLF_OPT }, + { "unchanged-line-format", required_argument, NULL, UNCLF_OPT }, + { "show-function-line", required_argument, NULL, 'F' }, - { "unchanged-group-format", required_argument, NULL, UNCGF_OPT }, { "old-group-format", required_argument, NULL, OLDGF_OPT }, { "new-group-format", required_argument, NULL, NEWGF_OPT }, + { "unchanged-group-format", required_argument, NULL, UNCGF_OPT }, { "changed-group-format", required_argument, NULL, CHGF_OPT }, - { "unchanged-line-format", required_argument, NULL, UNCLF_OPT }, - { "old-line-format", required_argument, NULL, OLDLF_OPT }, - { "new-line-format", required_argument, NULL, NEWLF_OPT }, { NULL, 0, NULL, '\0'} }; +/* + * allow for grep-style regex's by substituting regex equivalent +*/ +static struct { + char *orig; + char *sub; +} const grep_regex[] = { + { "[:alpha:]", "" }, + { "[:upper:]", "" }, + { "[:lower:]", "" }, + { "[:digit:]", "" }, + { "[:xdigit:]", "" }, + { "[:space:]", "" }, + { "[:punct:]", "" }, + { "[:alnum:]", "" }, + { "[:print:]", "" }, + { "[:graph:]", "" }, + { "[:cntrl:]", "" }, + { "[:blank:]", "" }, + { NULL, NULL }, +}; + + static const char *help_msg[] = { "-a --text treat files as ASCII text", "-B --ignore-blank-lines Ignore blank newlines in the comparison", @@ -160,9 +192,12 @@ void usage(void); void push_excludes(char *); void push_ignore_pats(char *); +void compile_regex(regex_t *, char *); void read_excludes_file(char *); void set_argstr(char **, char **); +char *estrdup(const char *); + int main(int argc, char **argv) { @@ -337,11 +372,34 @@ case HORIZ_OPT: if (optarg != NULL) { context = strtol(optarg, &ep, 10); - if (*ep != '\0' || context < 1 || context >=ULLONG_MAX) + if (*ep != '\0' || context < 1 || + context >=ULLONG_MAX) err(2, "context out of range\n"); horizon= (int)context; } break; + case LF_OPT: + line_format[OLD] = line_format[NEW] = line_format[UNCHANGED] + = optarg; + flags |= D_LINE; + break; + case OLDLF_OPT: + case NEWLF_OPT: + case UNCLF_OPT: + line_format[ ch - OLDLF_OPT ] = optarg; + flags |= D_LINE; + break; + case 'F': + pflag = 1; + fnline_pat = optarg; + break; + case OLDGF_OPT: + case NEWGF_OPT: + case UNCGF_OPT: + case CHGF_OPT: + group_format[ch - OLDGF_OPT] = optarg; + flags |= D_GROUP; + break; case NOOP_OPT: /* noop, compatibility */ @@ -350,13 +408,15 @@ /* compatibility, this is the default */ break; case HELP_OPT: - default: for(;*help_strs;help_strs++) { printf( "%s\n", *help_strs); } exit(2); break; + default: + usage(); + break; } lastch = ch; newarg = optind != prevoptind; @@ -377,18 +437,22 @@ else if (argc != 2 ) usage(); if (ignore_pats != NULL) { - char buf[BUFSIZ]; - int error; + compile_regex(&ignore_re, ignore_pats); + } + if ( fnline_pat != NULL) { + char *expand; + expand = estrdup(fnline_pat); + fnline_pat = expand; + int i; + for( i = 0; grep_regex[i].orig; i++) + { + fnline_pat = repstr(fnline_pat, grep_regex[i].orig, + grep_regex[i].sub); + } - if ((error = regcomp(&ignore_re, ignore_pats, - REG_NEWLINE | REG_EXTENDED)) != 0) { - regerror(error, &ignore_re, buf, sizeof(buf)); - if (*ignore_pats != '\0') - errx(2, "%s: %s", ignore_pats, buf); - else - errx(2, "%s", buf); - } - } + compile_regex(&fnline_re, fnline_pat); + } + src = fromfile ? fromfile : argv[0]; dst = fromfile ? argv[0] : (tofile ? tofile : argv[1]); if (strcmp(src, "-") == 0) { @@ -528,6 +592,25 @@ fclose(fp); } + +/* + * compile regex from string into re, call errx() if failure +*/ +void compile_regex(regex_t *re, char *re_pat) +{ + char buf[BUFSIZ]; + int error; + + if ((error = regcomp(re, re_pat, + REG_NEWLINE | REG_EXTENDED)) != 0) { + regerror(error, re, buf, sizeof(buf)); + if (*re_pat != '\0') + errx(2, "%s: %s", re_pat, buf); + else + errx(2, "%s", buf); + } +} + /* * Push a pattern onto the excludes list. */ ==== //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.h#8 (text+ko) ==== @@ -55,6 +55,8 @@ #define D_HEADER 1 /* Print a header/footer between files */ #define D_EMPTY1 2 /* Treat first file as empty (/dev/null) */ #define D_EMPTY2 4 /* Treat second file as empty (/dev/null) */ +#define D_LINE 8 /* There is a line format given */ +#define D_GROUP 16 /* There is a group format given */ /* * Status values for print_status() and diffreg() return values @@ -82,6 +84,16 @@ struct excludes *next; }; +/* + * enums for line/group formats + */ +enum { + OLD = 0, + NEW, + UNCHANGED, + CHANGED, +}; + extern int aflag, bflag, Bflag, dflag, Eflag, iflag; extern int lflag, Nflag, Pflag, pflag, rflag, sflag; extern int tflag, Tflag, wflag, uniflag; @@ -90,12 +102,13 @@ extern int fcase_behave; extern unsigned long long context; extern char *start, *ifdefname, *diffargs, *label[2], *ignore_pats; +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; +extern regex_t ignore_re, fnline_re; char *splice(char *, char *); -char *strrep(char*, char*, char*); +char *repstr(char*, const char*, const char*); int diffreg(char *, char *, int); int easprintf(char **, const char *, ...); void *emalloc(size_t); ==== //depot/projects/soc2010/bsdtextproc/gabor_diff/diffreg.c#10 (text+ko) ==== @@ -1308,7 +1308,14 @@ buf[nc] = '\0'; buf[strcspn(buf, "\n")] = '\0'; - if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') { + if ( fnline_pat != NULL) { + if ( regexec(&fnline_re, buf, 0, NULL, 0) != 0) { + return NULL; + } + } + + + else if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') { if (begins_with(buf, "private:")) { if (!state) state = " (private)"; @@ -1576,7 +1583,7 @@ * realloc()'ing base ptr if more characters necessary */ char * -strrep(char *base, char *old, char *new) +repstr(char *base, const char *old, const char *new) { char *ptr, *tmp; int occ, len1, len2, newlen;