diff options
author | Jim Meyering <meyering@fb.com> | 2014-06-26 14:39:39 -0700 |
---|---|---|
committer | Jim Meyering <meyering@fb.com> | 2014-06-27 13:17:07 -0700 |
commit | 09434c399629d16bc4fceb443aa3e5cea412f4ea (patch) | |
tree | 30d29ffada817583e3ed270a16ede004c3403baa | |
parent | 83757018e571b4a3afe14daad7e4101b589480d5 (diff) | |
download | grep-09434c399629d16bc4fceb443aa3e5cea412f4ea.tar.gz |
maint: split long lines, and enforce the 80-column limit
* cfg.mk (sc_long_lines): New rule, from coreutils; exempt tests/*
* src/grep.c (usage): Tweak -F wording to shorten a line.
Correct grammar in a comment.
Split the --exclude-file=... description to fit within 80 columns.
Use emit_bug_reporting_address, eliminating another long line.
* src/dfa.c: Split long lines. No semantic change.
* doc/grep.texi: Likewise.
* tests/include-exclude: Split a long line.
* tests/backref: Split long lines.
* tests/empty: Likewise.
* tests/fmbtest: Likewise.
-rw-r--r-- | AUTHORS | 3 | ||||
-rw-r--r-- | TODO | 5 | ||||
-rw-r--r-- | cfg.mk | 21 | ||||
-rw-r--r-- | doc/grep.texi | 9 | ||||
-rw-r--r-- | src/dfa.c | 16 | ||||
-rw-r--r-- | src/grep.c | 14 | ||||
-rwxr-xr-x | tests/backref | 7 | ||||
-rwxr-xr-x | tests/empty | 43 | ||||
-rwxr-xr-x | tests/fmbtest | 22 | ||||
-rwxr-xr-x | tests/include-exclude | 3 |
10 files changed, 89 insertions, 54 deletions
@@ -53,7 +53,8 @@ Stepan Kasal <kasal@ucw.cz> maintained GNU grep since Feb 2004. Tony Abou-Assaleh <taa@acm.org> maintains GNU grep since Oct 2007. -Jim Meyering <jim@meyering.net> and Paolo Bonzini <bonzini@gnu.org> maintain GNU grep since Nov 2009. +Jim Meyering <jim@meyering.net> and Paolo Bonzini <bonzini@gnu.org> +began maintaining GNU grep in Nov 2009. Paolo bowed out in 2012. ;; Local Variables: ;; coding: utf-8 @@ -45,7 +45,7 @@ Check <http://tony.abou-assaleh.net/greps.html>. Take a look at these and consider opportunities for merging or cloning: -- ja-grep's mlb2 patch (Japanese grep) - <ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/grep-2.4.2-mlb2.patch.gz> + <ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/grep-2.4.2-mlb2.patch.gz> -- lgrep (from lv, a Powerful Multilingual File Viewer / Grep) <http://www.ff.iij4u.or.jp/~nrt/lv/>; -- cgrep (Context grep) <http://plg.uwaterloo.ca/~ftp/mt/cgrep/> @@ -103,7 +103,8 @@ repertoire reduced to the following various forms of “LATIN LETTER I”: 0049;LATIN CAPITAL LETTER I;Lu;0;L;;;;;N;;;;0069; 0069;LATIN SMALL LETTER I;Ll;0;L;;;;;N;;;0049;;0049 -0130;LATIN CAPITAL LETTER I WITH DOT ABOVE;Lu;0;L;0049 0307;;;;N;LATIN CAPITAL LETTER I DOT;;;0069; +0130;LATIN CAPITAL LETTER I WITH DOT ABOVE;Lu;0;L;0049 0307;;;;N;\ + LATIN CAPITAL LETTER I DOT;;;0069; 0131;LATIN SMALL LETTER DOTLESS I;Ll;0;L;;;;;N;;;0049;;0049 First note the differing UTF-8 octet lengths of U+0049 (0x49) and @@ -66,6 +66,25 @@ sc_prohibit_echo_minus_en: halt='do not use echo ''-e or echo ''-n; use printf instead' \ $(_sc_search_regexp) +# Look for lines longer than 80 characters, except omit: +# - program-generated long lines in diff headers, +# - the help2man script copied from upstream, +# - tests involving long checksum lines, and +# - the 'pr' test cases. +LINE_LEN_MAX = 80 +FILTER_LONG_LINES = \ + /^[^:]*\.diff:[^:]*:@@ / d; \ + \|^[^:]*man/help2man:| d; \ + \|^[^:]*tests/misc/sha[0-9]*sum.*\.pl[-:]| d; \ + \|^[^:]*tests/pr/|{ \|^[^:]*tests/pr/pr-tests:| !d; }; +sc_long_lines: + @files=$$($(VC_LIST_EXCEPT)) \ + halt='line(s) with more than $(LINE_LEN_MAX) characters; reindent'; \ + for file in $$files; do \ + expand $$file | grep -nE '^.{$(LINE_LEN_MAX)}.' | \ + sed -e "s|^|$$file:|" -e '$(FILTER_LONG_LINES)'; \ + done | grep . && { msg="$$halt" $(_sc_say_and_exit) } || : + # Indent only with spaces. sc_prohibit_tab_based_indentation: @prohibit='^ * ' \ @@ -104,3 +123,5 @@ exclude_file_name_regexp--sc_error_message_uppercase = ^src/dfa\.c$$ exclude_file_name_regexp--sc_prohibit_strncpy = ^src/dfa\.c$$ exclude_file_name_regexp--sc_prohibit_doubled_word = ^tests/count-newline$$ + +exclude_file_name_regexp--sc_long_lines = ^tests/.*$$ diff --git a/doc/grep.texi b/doc/grep.texi index 10cc2e44..6c484d69 100644 --- a/doc/grep.texi +++ b/doc/grep.texi @@ -1252,13 +1252,15 @@ in the current locale. @opindex alnum @r{character class} @cindex alphanumeric characters Alphanumeric characters: -@samp{[:alpha:]} and @samp{[:digit:]}; in the @samp{C} locale and ASCII character encoding, this is the same as @samp{[0-9A-Za-z]}. +@samp{[:alpha:]} and @samp{[:digit:]}; in the @samp{C} locale and ASCII +character encoding, this is the same as @samp{[0-9A-Za-z]}. @item [:alpha:] @opindex alpha @r{character class} @cindex alphabetic characters Alphabetic characters: -@samp{[:lower:]} and @samp{[:upper:]}; in the @samp{C} locale and ASCII character encoding, this is the same as @samp{[A-Za-z]}. +@samp{[:lower:]} and @samp{[:upper:]}; in the @samp{C} locale and ASCII +character encoding, this is the same as @samp{[A-Za-z]}. @item [:blank:] @opindex blank @r{character class} @@ -1362,7 +1364,8 @@ represents the open equivalence class. represents the close equivalence class. @item [: -represents the open character class symbol, and should be followed by a valid character class name. +represents the open character class symbol, and should be followed by a +valid character class name. @item :] represents the close character class symbol. @@ -1136,7 +1136,8 @@ parse_bracket_exp (void) if (wc != WEOF && wc2 != WEOF) { work_mbc->ranges - = maybe_realloc (work_mbc->ranges, work_mbc->nranges + 2, + = maybe_realloc (work_mbc->ranges, + work_mbc->nranges + 2, &ranges_al, sizeof *work_mbc->ranges); work_mbc->ranges[work_mbc->nranges].beg = case_fold ? towlower (wc) : wc; @@ -1145,7 +1146,8 @@ parse_bracket_exp (void) if (case_fold && (iswalpha (wc) || iswalpha (wc2))) { - work_mbc->ranges[work_mbc->nranges].beg = towupper (wc); + work_mbc->ranges[work_mbc->nranges].beg + = towupper (wc); work_mbc->ranges[work_mbc->nranges++].end = towupper (wc2); } @@ -3699,13 +3701,13 @@ dfafree (struct dfa *d) CAT (p->is==ZERO)? (q->is==ZERO)? (p->is!=ZERO && p->in plus p->left : q->right : q->is!=ZERO) ? q->in plus - p->is##q->left p->right##q->is p->is##q->is : p->right##q->left + p->is##q->left p->right##q->is p->is##q->is : p->right##q->left ZERO - OR longest common longest common (do p->is and substrings common to - leading trailing q->is have same p->in and q->in - (sub)sequence (sub)sequence length and - of p->left of p->right content) ? + OR longest common longest common (do p->is and substrings common + leading trailing to q->is have same p->in and + (sub)sequence (sub)sequence q->in length and content) ? + of p->left of p->right and q->left and q->right p->is : NULL If there's anything else we recognize in the tree, all four sequences get set @@ -1536,10 +1536,10 @@ Example: %s -i 'hello world' menu.h main.c\n\ Regexp selection and interpretation:\n"), program_name); printf (_("\ -E, --extended-regexp PATTERN is an extended regular expression (ERE)\n\ - -F, --fixed-strings PATTERN is a set of newline-separated fixed strings\n\ + -F, --fixed-strings PATTERN is a set of newline-separated strings\n\ -G, --basic-regexp PATTERN is a basic regular expression (BRE)\n\ -P, --perl-regexp PATTERN is a Perl regular expression\n")); - /* -X is undocumented on purpose. */ + /* -X is deliberately undocumented. */ printf (_("\ -e, --regexp=PATTERN use PATTERN for matching\n\ -f, --file=FILE obtain PATTERN from FILE\n\ @@ -1583,7 +1583,8 @@ Output control:\n\ ")); printf (_("\ --include=FILE_PATTERN search only files that match FILE_PATTERN\n\ - --exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN\n\ + --exclude=FILE_PATTERN skip files and directories matching\ + FILE_PATTERN\n\ --exclude-from=FILE skip files matching any file pattern from FILE\n\ --exclude-dir=PATTERN directories that match PATTERN will be skipped.\n\ ")); @@ -1617,12 +1618,7 @@ When FILE is -, read standard input. With no FILE, read . if a command-line\n\ -r is given, - otherwise. If fewer than two FILEs are given, assume -h.\n\ Exit status is 0 if any line is selected, 1 otherwise;\n\ if any error occurs and -q is not given, the exit status is 2.\n")); - printf (_("\nReport bugs to: %s\n"), PACKAGE_BUGREPORT); - printf (_("GNU Grep home page: <%s>\n"), - "http://www.gnu.org/software/grep/"); - fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>\n"), - stdout); - + emit_bug_reporting_address (); } exit (status); } diff --git a/tests/backref b/tests/backref index c01b140b..d9f3be34 100755 --- a/tests/backref +++ b/tests/backref @@ -19,8 +19,11 @@ if test $? -ne 0 ; then fi # hit hard with the 'Bond' tests -# For now, remove the '?' in the last parentheses, so that new glibc can do it. --Stepan -echo "civic" | grep -E -e '^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.).?\9\8\7\6\5\4\3\2\1$' > /dev/null 2>&1 +# For now, remove the '?' in the last parentheses, so that new glibc can do it. +# --Stepan +echo "civic" \ + | grep -E -e '^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.).?\9\8\7\6\5\4\3\2\1$' \ + > /dev/null 2>&1 if test $? -ne 0 ; then echo "Options: Bond, test #2 failed" failures=1 diff --git a/tests/empty b/tests/empty index fabd4d38..b72b13fa 100755 --- a/tests/empty +++ b/tests/empty @@ -20,36 +20,37 @@ for locale in C en_US.UTF-8; do # should return 0 found a match echo "" | LC_ALL=$locale timeout 10s grep $options -e '' if test $? -ne 0 ; then - echo "Status: Wrong status code, test \#1 failed ($options $locale)" - failures=1 + echo "Status: Wrong status code, test \#1 failed ($options $locale)" + failures=1 fi # should return 1 found no match - echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null + echo abcd | LC_ALL=$locale timeout 10s grep $options -f /dev/null if test $? -ne 1 ; then - echo "Status: Wrong status code, test \#2 failed ($options $locale)" - failures=1 + echo "Status: Wrong status code, test \#2 failed ($options $locale)" + failures=1 fi # should return 0 found a match - echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null -e "abcd" + echo abcd \ + | LC_ALL=$locale timeout 10s grep $options -f /dev/null -e abcd if test $? -ne 0 ; then - echo "Status: Wrong status code, test \#3 failed ($options $locale)" - failures=1 + echo "Status: Wrong status code, test \#3 failed ($options $locale)" + failures=1 fi # should return 0 found a match echo "" | LC_ALL=$locale timeout 10s grep $options -e '' if test $? -ne 0 ; then - echo "Status: Wrong status code, test \#4 failed ($options $locale)" - failures=1 + echo "Status: Wrong status code, test \#4 failed ($options $locale)" + failures=1 fi # should return 0 found a match - echo "abcd" | LC_ALL=$locale timeout 10s grep $options -e '' + echo abcd | LC_ALL=$locale timeout 10s grep $options -e '' if test $? -ne 0 ; then - echo "Status: Wrong status code, test \#5 failed ($options $locale)" - failures=1 + echo "Status: Wrong status code, test \#5 failed ($options $locale)" + failures=1 fi done @@ -58,22 +59,22 @@ for locale in C en_US.UTF-8; do # should return 0 found a match echo "" | LC_ALL=$locale timeout 10s grep $options -e '' if test $? -ne 0 ; then - echo "Status: Wrong status code, test \#6 failed ($options $locale)" - failures=1 + echo "Status: Wrong status code, test \#6 failed ($options $locale)" + failures=1 fi # should return 1 found no match - echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null + echo abcd | LC_ALL=$locale timeout 10s grep $options -f /dev/null if test $? -ne 1 ; then - echo "Status: Wrong status code, test \#7 failed ($options $locale)" - failures=1 + echo "Status: Wrong status code, test \#7 failed ($options $locale)" + failures=1 fi # should return 1 found no match - echo "abcd" | LC_ALL=$locale timeout 10s grep $options -f /dev/null -e "" + echo abcd | LC_ALL=$locale timeout 10s grep $options -f /dev/null -e "" if test $? -ne 1 ; then - echo "Status: Wrong status code, test \#8 failed ($options $locale)" - failures=1 + echo "Status: Wrong status code, test \#8 failed ($options $locale)" + failures=1 fi done done diff --git a/tests/fmbtest b/tests/fmbtest index 922f40b0..bec5403b 100755 --- a/tests/fmbtest +++ b/tests/fmbtest @@ -81,22 +81,28 @@ fi # failures=1 #fi -# Test that --color=always does not depend on individual pattern order within the pattern -# list, and that a longer match is preferred to a shorter one starting at the same point. +# Test that --color=always does not depend on individual pattern order +# within the pattern list, and that a longer match is preferred to a +# shorter one starting at the same point. test6="$(echo 'Cosi tu ČišÍ...' \ - | LC_ALL=$cz grep --color=always -${mode}i -e 'čiš' -e 'čiší')" -if echo "$test6" | LC_ALL=C grep -q 'Cosi tu .*\[.*m\(.\[K\)\?ČišÍ.*\[.*m\(.\[K\)\?\.\.\.'; then + | LC_ALL=$cz grep --color=always -${mode}i -e 'čiš' -e 'čiší')" +if echo "$test6" \ + | LC_ALL=C grep -q 'Cosi tu .*\[.*m\(.\[K\)\?ČišÍ.*\[.*m\(.\[K\)\?\.\.\.'; \ +then : else echo "Test #6 ${mode} failed: $test6" failures=1 fi -# Test that --color=always does not depend on individual pattern order within the pattern -# list, and that a longer match is preferred to a shorter one starting at the same point. +# Test that --color=always does not depend on individual pattern order +# within the pattern list, and that a longer match is preferred to a +# shorter one starting at the same point. test7="$(echo 'Cosi tu ČišÍ...' \ - | LC_ALL=$cz grep --color=always -${mode}i -e 'čiší' -e 'čiš')" -if echo "$test7" | LC_ALL=C grep -q 'Cosi tu .*\[.*m\(.\[K\)\?ČišÍ.*\[.*m\(.\[K\)\?\.\.\.'; then + | LC_ALL=$cz grep --color=always -${mode}i -e 'čiší' -e 'čiš')" +if echo "$test7" \ + | LC_ALL=C grep -q 'Cosi tu .*\[.*m\(.\[K\)\?ČišÍ.*\[.*m\(.\[K\)\?\.\.\.'; \ +then : else echo "Test #7 ${mode} failed: $test7" diff --git a/tests/include-exclude b/tests/include-exclude index 9c07139a..55819c59 100755 --- a/tests/include-exclude +++ b/tests/include-exclude @@ -51,7 +51,8 @@ grep -r --include='a*' . x > out || fail=1 compare exp-a out || fail=1 # --include (without --recursive) uses different code -grep --directories=skip --include=a --exclude-dir=dir '^aaa$' x/* > out || fail=1 +grep --directories=skip --include=a --exclude-dir=dir '^aaa$' x/* > out \ + || fail=1 compare exp-a out || fail=1 (cd x && grep -r --exclude-dir=. '^aaa$') > out || fail=1 |