PERFORCE change 181079 for review
Gabor Kovesdan
gabor at FreeBSD.org
Sat Jul 17 05:37:48 UTC 2010
http://p4web.freebsd.org/@@181079?ac=10
Change 181079 by gabor at gabor_server on 2010/07/17 05:37:18
- style(9) and readability nits
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/grep/fastgrep.c#19 edit
.. //depot/projects/soc2008/gabor_textproc/grep/file.c#52 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.c#98 edit
.. //depot/projects/soc2008/gabor_textproc/grep/grep.h#55 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#92 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/grep/fastgrep.c#19 (text+ko) ====
@@ -123,8 +123,7 @@
fg->pattern[fg->len] = '\0';
/* Look for ways to cheat...er...avoid the full regex engine. */
- for (i = 0; i < fg->len; i++)
- {
+ for (i = 0; i < fg->len; i++) {
/* Can still cheat? */
if (fg->pattern[i] == '.') {
hasDot = i;
@@ -152,7 +151,8 @@
*/
if ((!(lflag || cflag)) && ((!(bol || eol)) &&
((lastHalfDot) && ((firstHalfDot < 0) ||
- ((fg->len - (lastHalfDot + 1)) < (size_t)firstHalfDot)))) && !oflag && !color) {
+ ((fg->len - (lastHalfDot + 1)) < (size_t)firstHalfDot)))) &&
+ !oflag && !color) {
fg->reversed = true;
hasDot = fg->len - (firstHalfDot < 0 ?
firstLastHalfDot : firstHalfDot) - 1;
@@ -223,10 +223,7 @@
/* Verify data is >= pattern length before searching on it. */
if (len >= fg->len) {
/* Determine where in data to start search at. */
- if (fg->eol)
- j = len - fg->len;
- else
- j = 0;
+ j = fg->eol ? len - fg->len : 0;
if (!((fg->bol && fg->eol) && (len != fg->len)))
if (grep_cmp(fg->pattern, data + j,
fg->len) == -1) {
@@ -285,15 +282,18 @@
unsigned int i;
if (iflag) {
- if ((size = mbstowcs(NULL, (const char *)data, 0)) == ((size_t) - 1))
+ if ((size = mbstowcs(NULL, (const char *)data, 0)) ==
+ ((size_t) - 1))
return (-1);
wdata = grep_malloc(size * sizeof(wint_t));
- if (mbstowcs(wdata, (const char *)data, size) == ((size_t) - 1))
+ if (mbstowcs(wdata, (const char *)data, size) ==
+ ((size_t) - 1))
return (-1);
- if ((size = mbstowcs(NULL, (const char *)pat, 0)) == ((size_t) - 1))
+ if ((size = mbstowcs(NULL, (const char *)pat, 0)) ==
+ ((size_t) - 1))
return (-1);
wpat = grep_malloc(size * sizeof(wint_t));
@@ -301,7 +301,8 @@
if (mbstowcs(wpat, (const char *)pat, size) == ((size_t) - 1))
return (-1);
for (i = 0; i < len; i++) {
- if ((towlower(wpat[i]) == towlower(wdata[i])) || ((grepbehave != GREP_FIXED) && wpat[i] == L'.'))
+ if ((towlower(wpat[i]) == towlower(wdata[i])) ||
+ ((grepbehave != GREP_FIXED) && wpat[i] == L'.'))
continue;
free(wpat);
free(wdata);
@@ -309,7 +310,8 @@
}
} else {
for (i = 0; i < len; i++) {
- if ((pat[i] == data[i]) || ((grepbehave != GREP_FIXED) && pat[i] == '.'))
+ if ((pat[i] == data[i]) || ((grepbehave != GREP_FIXED) &&
+ pat[i] == '.'))
continue;
return (i);
}
==== //depot/projects/soc2008/gabor_textproc/grep/file.c#52 (text+ko) ====
@@ -60,7 +60,8 @@
unsigned char *binbufptr;
static int bzerr;
-#define iswbinary(ch) (!iswspace((ch)) && iswcntrl((ch)) && (ch != L'\b') && (ch != L'\0'))
+#define iswbinary(ch) (!iswspace((ch)) && iswcntrl((ch)) && \
+ (ch != L'\b') && (ch != L'\0'))
/*
* Returns a single character according to the file type.
@@ -131,7 +132,8 @@
else if (stat(fname, &st) != 0)
err(2, NULL);
- bufsiz = (MAXBUFSIZ > (st.st_size * PREREAD_M)) ? (st.st_size / 2) : MAXBUFSIZ;
+ bufsiz = (MAXBUFSIZ > (st.st_size * PREREAD_M)) ?
+ (st.st_size / 2) : MAXBUFSIZ;
binbuf = grep_malloc(sizeof(char) * bufsiz);
@@ -142,14 +144,16 @@
binbuf[i++] = ch;
}
- f->binary = memchr(binbuf, (filebehave != FILE_GZIP) ? '\0' : '\200', i - 1) != NULL;
+ f->binary = memchr(binbuf, (filebehave != FILE_GZIP) ?
+ '\0' : '\200', i - 1) != NULL;
}
binbufsiz = i;
binbufptr = binbuf;
}
/* Read a line whether from the buffer or from the file itself. */
- for (i = 0; !(grep_feof(f) && (binbufptr == &binbuf[binbufsiz])); i++) {
+ for (i = 0; !(grep_feof(f) &&
+ (binbufptr == &binbuf[binbufsiz])); i++) {
if (binbufptr == &binbuf[binbufsiz]) {
ch = grep_fgetc(f);
} else {
==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#98 (text+ko) ====
@@ -225,7 +225,8 @@
/* Increase size if necessary */
if (patterns == pattern_sz) {
pattern_sz *= 2;
- pattern = grep_realloc(pattern, ++pattern_sz * sizeof(*pattern));
+ pattern = grep_realloc(pattern, ++pattern_sz *
+ sizeof(*pattern));
}
if (len > 0 && pat[len - 1] == '\n')
--len;
@@ -246,7 +247,8 @@
/* Increase size if necessary */
if (epatterns == epattern_sz) {
epattern_sz *= 2;
- epattern = grep_realloc(epattern, ++epattern_sz * sizeof(struct epat));
+ epattern = grep_realloc(epattern, ++epattern_sz *
+ sizeof(struct epat));
}
if (len > 0 && pat[len - 1] == '\n')
--len;
@@ -280,9 +282,9 @@
int
main(int argc, char *argv[])
{
- unsigned long long l;
char **aargv, **eargv, *eopts;
char *ep;
+ unsigned long long l;
unsigned int aargc, eargc, i;
int c, lastc, needpattern, newarg, prevoptind;
@@ -342,13 +344,15 @@
eargc = 0;
while(str != NULL) {
- eargv[++eargc] = (char *)grep_malloc(sizeof(char) * (strlen(str) + 1));
+ eargv[++eargc] = (char *)grep_malloc(sizeof(char) *
+ (strlen(str) + 1));
strlcpy(eargv[eargc], str, strlen(str) + 1);
str = strtok(NULL, " ");
}
eargv[++eargc] = NULL;
- aargv = (char **)grep_malloc(sizeof(char *) * (eargc + argc + 1));
+ aargv = (char **)grep_malloc(sizeof(char *) *
+ (eargc + argc + 1));
aargv[0] = argv[0];
for(i = 1; i < eargc; i++)
@@ -363,7 +367,8 @@
aargc = argc;
}
- while (((c = getopt_long(aargc, aargv, optstr, long_options, NULL)) != -1)) {
+ while (((c = getopt_long(aargc, aargv, optstr, long_options, NULL)) !=
+ -1)) {
switch (c) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
@@ -382,6 +387,7 @@
}
/* FALLTHROUGH */
case 'A':
+ /* FALLTHROUGH */
case 'B':
errno = 0;
l = strtoull(optarg, &ep, 10);
@@ -537,7 +543,8 @@
errx(2, "%s", getstr(8));
break;
case COLOR_OPT:
- if (optarg == NULL || strcmp("auto", optarg) == 0 || strcmp("always", optarg) == 0 ) {
+ if (optarg == NULL || strcmp("auto", optarg) == 0 ||
+ strcmp("always", optarg) == 0 ) {
color = getenv("GREP_COLOR");
if (color == NULL) {
color = grep_malloc(sizeof(char) * 6);
@@ -559,19 +566,23 @@
break;
case R_INCLUDE_OPT:
exclflag = true;
- add_epattern(basename(optarg), strlen(basename(optarg)), FILE_PAT, INCL_PAT);
+ add_epattern(basename(optarg), strlen(basename(optarg)),
+ FILE_PAT, INCL_PAT);
break;
case R_EXCLUDE_OPT:
exclflag = true;
- add_epattern(basename(optarg), strlen(basename(optarg)), FILE_PAT, EXCL_PAT);
+ add_epattern(basename(optarg), strlen(basename(optarg)),
+ FILE_PAT, EXCL_PAT);
break;
case R_DINCLUDE_OPT:
exclflag = true;
- add_epattern(basename(optarg), strlen(basename(optarg)), DIR_PAT, INCL_PAT);
+ add_epattern(basename(optarg), strlen(basename(optarg)),
+ DIR_PAT, INCL_PAT);
break;
case R_DEXCLUDE_OPT:
exclflag = true;
- add_epattern(basename(optarg), strlen(basename(optarg)), DIR_PAT, EXCL_PAT);
+ add_epattern(basename(optarg), strlen(basename(optarg)),
+ DIR_PAT, EXCL_PAT);
break;
case HELP_OPT:
default:
@@ -652,15 +663,5 @@
/* Find out the correct return value according to the
results and the command line option. */
- if (c) {
- if (notfound && qflag)
- exit(0);
- else if (notfound)
- exit (2);
- else
- exit (0);
- } else if (notfound)
- exit(2);
- else
- exit(1);
+ exit(c ? (notfound ? (qflag ? 0 : 2) : 0) : (notfound ? 2 : 1));
}
==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#55 (text+ko) ====
@@ -1,5 +1,6 @@
/* $OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $ */
/* $FreeBSD$ */
+
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008-2009 Gabor Kovesdan <gabor at FreeBSD.org>
==== //depot/projects/soc2008/gabor_textproc/grep/util.c#92 (text+ko) ====
@@ -95,7 +95,7 @@
case FTS_DP:
break;
case FTS_DC:
- /* Print a warning if there is a recursive directory loop */
+ /* Print a warning for recursive directory loop */
warnx("warning: %s: recursive directory loop",
p->fts_path);
break;
@@ -104,16 +104,20 @@
ok = true;
if (exclflag) {
d = strrchr(p->fts_path, '/');
- dir = grep_malloc(sizeof(char) * (d - p->fts_path + 2));
- strlcpy(dir, p->fts_path, (d - p->fts_path + 1));
+ dir = grep_malloc(sizeof(char) *
+ (d - p->fts_path + 2));
+ strlcpy(dir, p->fts_path,
+ (d - p->fts_path + 1));
for (i = 0; i < epatterns; ++i) {
switch(epattern[i].type) {
case FILE_PAT:
- if (fnmatch(epattern[i].pat, basename(p->fts_path), 0) == 0)
+ if (fnmatch(epattern[i].pat,
+ basename(p->fts_path), 0) == 0)
ok = epattern[i].mode != EXCL_PAT;
break;
case DIR_PAT:
- if (strstr(dir, epattern[i].pat) != NULL)
+ if (strstr(dir,
+ epattern[i].pat) != NULL)
ok = epattern[i].mode != EXCL_PAT;
break;
}
@@ -132,7 +136,7 @@
/*
* Opens a file and processes it. Each file is processed line-by-line
- * passing the lines to procline().
+ * passing the lines to procline().
*/
int
procfile(const char *fn)
@@ -147,10 +151,7 @@
return (0);
if (strcmp(fn, "-") == 0) {
- if (label != NULL)
- fn = label;
- else
- fn = getstr(1);
+ fn = label != NULL ? label : getstr(1);
f = grep_stdin_open();
} else {
if (!stat(fn, &sb)) {
@@ -264,12 +265,14 @@
* removed in the future. See fastgrep.c.
*/
if (fg_pattern[i].pattern) {
- r = grep_search(&fg_pattern[i], (unsigned char *)l->dat,
+ r = grep_search(&fg_pattern[i],
+ (unsigned char *)l->dat,
l->len, &pmatch);
r = (r == 0) ? 0 : REG_NOMATCH;
st = pmatch.rm_eo;
} else {
- r = regexec(&r_pattern[i], l->dat, 1, &pmatch, eflags);
+ r = regexec(&r_pattern[i], l->dat, 1,
+ &pmatch, eflags);
r = (r == 0) ? 0 : REG_NOMATCH;
st = pmatch.rm_eo;
}
@@ -277,25 +280,31 @@
continue;
/* Check for full match */
if (r == 0 && xflag)
- if (pmatch.rm_so != 0 || (size_t)pmatch.rm_eo != l->len)
+ if (pmatch.rm_so != 0 ||
+ (size_t)pmatch.rm_eo != l->len)
r = REG_NOMATCH;
/* Check for whole word match */
- if (r == 0 && wflag && pmatch.rm_so != 0 && (size_t)pmatch.rm_eo != l->len) {
+ if (r == 0 && wflag && pmatch.rm_so != 0 &&
+ (size_t)pmatch.rm_eo != l->len) {
wchar_t *wbegin;
wint_t wend;
size_t size;
- size = mbstowcs(NULL, l->dat, pmatch.rm_so);
+ size = mbstowcs(NULL, l->dat,
+ pmatch.rm_so);
if (size == ((size_t) - 1))
r = REG_NOMATCH;
else {
wbegin = grep_malloc(size);
- if (mbstowcs(wbegin, l->dat, pmatch.rm_so) == ((size_t) - 1))
+ if (mbstowcs(wbegin, l->dat,
+ pmatch.rm_so) == ((size_t) - 1))
r = REG_NOMATCH;
- else if (sscanf(&l->dat[pmatch.rm_eo], "%lc", &wend) != 1)
+ else if (sscanf(&l->dat[pmatch.rm_eo],
+ "%lc", &wend) != 1)
r = REG_NOMATCH;
- else if (iswword(wbegin[wcslen(wbegin)]) ||iswword(wend))
+ else if (iswword(wbegin[wcslen(wbegin)]) ||
+ iswword(wend))
r = REG_NOMATCH;
free(wbegin);
}
@@ -305,7 +314,7 @@
c++;
if (m < MAX_LINE_MATCHES)
matches[m++] = pmatch;
- /* Matches - no need to check more patterns */
+ /* matches - skip further patterns */
break;
}
}
@@ -429,12 +438,14 @@
if ((oflag || color) && m > 0) {
for (i = 0; i < m; i++) {
if (!oflag)
- fwrite(line->dat + a, matches[i].rm_so - a, 1, stdout);
+ fwrite(line->dat + a, matches[i].rm_so - a, 1,
+ stdout);
if (color)
fprintf(stdout, "\33[%sm\33[K", color);
fwrite(line->dat + matches[i].rm_so,
- matches[i].rm_eo - matches[i].rm_so, 1, stdout);
+ matches[i].rm_eo - matches[i].rm_so, 1,
+ stdout);
if (color)
fprintf(stdout, "\33[m\33[K");
a = matches[i].rm_eo;
More information about the p4-projects
mailing list