grep: fix integer-width bugs in undossify_input etc.

undossify_input bug reported by Vincent Lefevre in:
http://bugs.gnu.org/18269
* src/dosbuf.c (undossify_input): Return size_t, not int.
* src/grep.c (fillbuf): Work portably even if safe_read returns a
value greater than SSIZE_MAX, e.g., if there's an I/O error.
grep: -P now treats invalid UTF-8 input as non-matching

Problem reported by Santiago Vila in: http://bugs.gnu.org/18266
* NEWS: Mention this.
* src/pcresearch.c (Pexecute): Treat UTF-8 encoding errors
as non-matching data, instead of exiting 'grep'.
* tests/pcre-infloop: grep now exits with status 1, not 2.
* tests/pcre-invalid-utf8-input: grep now exits with status 0, not 2.
grep: port recent fix to older pcre version

* src/pcresearch.c (Pexecute): Don't assume that a pcre_exec
that returns PCRE_ERROR_NOMATCH leaves its sub argument alone.
This assumption is false for libpcre-3 version 8.31-2ubuntu2.
maint: avoid distcheck failure

* Makefile.am (EXTRA_DIST): Add .mailmap.
tests: add expect-to-fail test for a glibc regexp bug

* tests/triple-backref: New file.
* tests/Makefile.am (TESTS): Add it.
(XFAIL_TESTS): List it as a known, always-failing test.
Based on the bug report from Paul Eggert:
https://sourceware.org/bugzilla/show_bug.cgi?id=17356
grep: fix false matches with -P '...$' and invalid UTF-8

* src/pcresearch.c (Pexecute): Use PCRE_NOTEOL when matching
initial substrings of a line.
grep: fix false matches with -P '...$' and invalid UTF-8

* tests/pcre-invalid-utf8-input: Add a test for that.
doc: bug tracker has moved to debbugs.gnu.org

* README (KNOWN BUGS):
* doc/grep.in.1:
* doc/grep.texi (Reporting Bugs): Document this.
grep: make GREP_OPTIONS obsolescent

* NEWS:
* doc/grep.in.1 (ENVIRONMENT_VARIABLES):
* doc/grep.texi (Environment Variables):
Document that GREP_OPTIONS is obsolescent now.
* src/grep.c (main): Warn if GREP_OPTIONS is used.
* tests/r-dot, tests/skip-device: Don't use GREP_OPTIONS.
doc: move NEWS note about GREP_OPTIONS into proper section

* NEWS (Changes in behavior): Move the note about GREP_OPTIONS
from the 2.20 section into the section for the upcoming release.
grep: diagnose -P in non-UTF-8 multibyte locale

* src/pcresearch.c (Pcompile):
libpcre supports only unibyte and UTF-8 locales,
so report an error and exit if used in other locales.
* NEWS: Mention this.
* tests/euc-mb: Test this.
grep: remove/refactor unnecessary code about line splitting

* src/grep.c (do_execute): Remove.  Caller now uses 'execute'.
* src/pcresearch.c (Pexecute): Improve comment about this.
grep: speed up -P on files containing many multibyte errors

* src/pcresearch.c (empty_match): New var.
(Pcompile): Set it.
(Pexecute): Use it.
grep: use bool for boolean in grep.c

* src/grep.c (show_version, suppress_errors, only_matching)
(align_tabs, match_icase, match_words, match_lines, errseen)
(write_error_seen, is_device_mode, usable_st_size)
(file_is_binary, skipped_file, reset, fillbuf, out_quiet)
(out_line, out_byte, count_matches, no_filenames, line_buffered)
(done_on_match, exit_on_match, print_line_head, prline, grep)
(grepdirent, grepfile, grepdesc, grep_command_line_arg)
(get_nondigit_option, main): Use bool for boolean.
(print_line_head, prline): Use char for byte.
* src/grep.h: Include <stdbool.h>, and adjust decls to match
changes in grep.c.
grep: treat a file as binary if its prefix contains encoding errors

* NEWS:
* doc/grep.texi (File and Directory Selection):
Document this.
* src/grep.c (buffer_encoding, buffer_textbin): New functions.
(file_textbin): Rename from file_is_binary.  Now returns 3-way value.
All callers changed.
(file_textbin, grep): Check the input more carefully for text vs
binary data.
(contains_encoding_error): Remove; use replaced by buffer_encoding.
* tests/backref-multibyte-slow:
* tests/high-bit-range:
* tests/invalid-multibyte-infloop:
Use -a, since the input is now considered to be binary.
* tests/invalid-multibyte-infloop: Add a check for new behavior.
grep: improve performance for older glibc

glibc has a bug where mbrlen and mbrtowc mishandle length-0 inputs.
Working around it in gnulib slows grep down, so disable the tests for it
and make sure grep works even if the bug is present.
* bootstrap.conf (avoided_gnulib_modules): Add mbrtowc-tests.
* configure.ac (gl_cv_func_mbrtowc_empty_input): Assume yes.
* src/searchutils.c (mb_next_wc): Don't invoke mbrtowc on empty input.
grep: use mbclen cache more effectively

* src/grep.c (buffer_textbin, contains_encoding_error):
Use mb_clen for speed.
(buffer_textbin): Bypass mb_clen in unibyte locales.
(main): Always initialize the cache, since it's sometimes used in
unibyte locales now.  Initialize it before contains_encoding_error
might be called.
* src/search.h (SEARCH_INLINE): New macro.
(mbclen_cache): Now extern decl.
(mb_clen): New inline function.
* src/searchutils.c (SEARCH_INLINE, SYSTEM_INLINE): Define.
(mbclen_cache): Now extern.
(build_mbclen_cache): Put 1 into the cache when mbrlen returns 0.
(mb_goback): Use mb_len for speed, and rely on it returning nonzero.
* src/system.h (SYSTEM_INLINE): New macro.
(to_uchar): Use it.
grep: avoid false alarms for mb_clen and to_uchar

* cfg.mk (_gl_TS_unmarked_extern_functions): New var,
to bypass the tight_scope false alarms on mb_clen and to_uchar.
grep: use mbclen cache in one more place

* src/grep.c (fgrep_to_grep_pattern): Use mb_clen here, too.
grep: port -P speedup to hosts lacking PCRE_STUDY_JIT_COMPILE

* src/pcresearch.c (Pcompile): Do not assume that
PCRE_STUDY_JIT_COMPILE is defined.
(empty_match): Define on all platforms.