PERFORCE change 180670 for review
Benjamin Fiedler
bfiedler at FreeBSD.org
Thu Jul 8 22:37:36 UTC 2010
http://p4web.freebsd.org/@@180670?ac=10
Change 180670 by bfiedler at 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;
+}
+
More information about the p4-projects
mailing list