From owner-p4-projects@FreeBSD.ORG Thu Jul 8 22:37:35 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id BD69F1065678; Thu, 8 Jul 2010 22:37:35 +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 809111065673 for ; Thu, 8 Jul 2010 22:37:35 +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 6CD498FC1C for ; Thu, 8 Jul 2010 22:37:35 +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 o68MbZkF027413 for ; Thu, 8 Jul 2010 22:37:35 GMT (envelope-from bfiedler@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o68MbZuD027411 for perforce@freebsd.org; Thu, 8 Jul 2010 22:37:35 GMT (envelope-from bfiedler@FreeBSD.org) Date: Thu, 8 Jul 2010 22:37:35 GMT Message-Id: <201007082237.o68MbZuD027411@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 180670 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: Thu, 08 Jul 2010 22:37:36 -0000 http://p4web.freebsd.org/@@180670?ac=10 Change 180670 by bfiedler@freebsd-7803 on 2010/07/08 22:37:27 Fix a pointer bug. Base code for function for parsing --*format args Affected files ... .. //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.c#10 edit .. //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.h#9 edit .. //depot/projects/soc2010/bsdtextproc/gabor_diff/diffreg.c#11 edit Differences ... ==== //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.c#10 (text+ko) ==== @@ -195,7 +195,6 @@ void compile_regex(regex_t *, char *); void read_excludes_file(char *); void set_argstr(char **, char **); -char *estrdup(const char *); int ==== //depot/projects/soc2010/bsdtextproc/gabor_diff/diff.h#9 (text+ko) ==== @@ -113,6 +113,7 @@ int easprintf(char **, const char *, ...); void *emalloc(size_t); void *erealloc(void *, size_t); +char *estrdup(const char *); void diffdir(char *, char *); void print_only(const char *, size_t, const char *); void print_status(int, char *, char *, char *); ==== //depot/projects/soc2010/bsdtextproc/gabor_diff/diffreg.c#11 (text+ko) ==== @@ -209,6 +209,8 @@ static int files_differ(FILE *, FILE *, int); static char *match_function(const long *, int, FILE *); static char *preadline(int, size_t, off_t); +static char *replace_line_format(FILE *file, int *f, int pos, char *format); + static int *J; /* will be overlaid on class */ static int *class; /* will be overlaid on file[0] */ @@ -993,7 +995,7 @@ if (format != D_IFDEF && a > b && c > d) return; if (ignore_pats != NULL) { - char *line; + char *line = NULL; /* * All lines in the change, insert, or delete must * match an ignore pattern for the change to be @@ -1003,18 +1005,24 @@ for (i = a; i <= b; i++) { line = preadline(fileno(f1), ixold[i] - ixold[i - 1], ixold[i - 1]); - if (!ignoreline(line)) + if (!ignoreline(line)) { + free(line); goto proceed; + } } } if (a > b || c <= d) { /* Changes and inserts. */ for (i = c; i <= d; i++) { line = preadline(fileno(f2), ixnew[i] - ixnew[i - 1], ixnew[i - 1]); - if (!ignoreline(line)) + if (!ignoreline(line)) { + free(line); goto proceed; + } } } + free(line); + return; } proceed: @@ -1632,3 +1640,49 @@ return base; } +char * +replace_line_format(FILE *file, int *f, int pos, char *format) +{ + char buf[FUNCTION_CONTEXT_SIZE]; + size_t nc; + int last = lastline; + + lastline = pos; + while (pos > last) { + fseek(file, f[pos - 1], SEEK_SET); + nc = f[pos] - f[pos - 1]; + if (nc >= sizeof(buf)) + nc = sizeof(buf) - 1; + nc = fread(buf, 1, nc, file); + if (nc > 0) { + buf[nc] = '\0'; + buf[strcspn(buf, "\n")] = '\0'; + } + } + + /* XXX: need to evaluate ternary and 'expand' printf + format specifiers (using sprintf?) */ + + /* reg_printf = "(%[#0-9\\.\\-\\+ 'doxX]*)(eflmnEFLMN)+" */ + + char *rline = estrdup( format ); + rline = repstr(rline, "%L", buf); + + if( strstr(format, "%l" ) != NULL ) + { + char *n = strrchr(buf, '\n'); + if( n != NULL) + { + *n = '\0'; + rline = repstr(rline, "%l", buf); + *n = '\n'; + } + else + { + rline = repstr(rline, "%l", buf); + } + } + + return rline; +} +