+# Should we print lines containing blobs, false positives, and neither?
+print_blob = 0
+with_context = 0
+print_falsepos = 0
+print_nomatch = 0
+
+# Should we print name_to_list and exit if we find blobs or false positives?
+list_blob = 0
+list_falsepos = 0
+name_to_list = '$input'
+
+# Should we forget everything we know about false positives?
+falsepos = None
+no_falsepos = 0
+
+verbose = $vp
+
+# Which of the defaults above should we override?
+$@ = 1
+
+EOF
+
+ if test "X$DEBLOB_CHECK_PYTHON_REGEX" = Xdebug; then
+ ${SED-sed} -e "$adjust_rx" \
+ -e 's,\([^-+]*\)\(.*\),re.compile (r'"'\\2'"'),g' \
+ < "$regex_name" >> "$scriptname"
+ fi
+
+ ${SED-sed} -n 's,^[+],,p' < "$regex_name" |
+ ${SED-sed} -n -e "$adjust_rx" -e 's,\^,,' \
+ -e '1h; 1!H; $ { g; s,[\n],|,g; '"\
+s,^\\(.*\\)\$,falsepos = r'(?P<falsepos>\\1)',;\
+"' p;}' >> "$scriptname"
+
+ ${SED-sed} -n 's,^[-],,p' < "$regex_name" |
+ ${SED-sed} -n -e "$adjust_rx" \
+ -e '1h; 1!H; $ { g; s,[\n],|,g; '"\
+s,^\\(.*\\)\$,blob = r'(?P<blob>\\1)',;\
+"' p;}' >> "$scriptname"
+
+ echo "\\($initblob\\|$defineblob\\|$asmblob\\)" |
+ ${SED-sed} -e "$adjust_rx" \
+ -e "s,^\\(.*\\)\$,cblob = r'(?P<cblob>\\1)'," >> "$scriptname"
+
+ cat >> "$scriptname" <<\EOF
+
+if no_falsepos or falsepos is None:
+ falsepos = r'(?!)'
+
+rx = '^%s|%s' % (falsepos, blob)
+
+if with_context:
+ rx += '|^' + cblob
+
+rxc = re.compile('(?<=.)(?:%s)' % rx, re.M | re.S)
+
+filenames = None
+
+s = '\n'
+
+for line in sys.stdin:
+ # Read into s all lines between begin and end. An empty line, without
+ # even the '\n', flags the end of the input.
+ if line[:3] == ';/*' and line[-4:] == '*/;\n':
+ if line[3:9] == 'begin ':
+ nextfilenames = (line[9:-4], filenames)
+ if s == '\n':
+ filenames = nextfilenames
+ del nextfilenames
+ continue
+ elif line[3:7] == 'end ':
+ assert line[7:-4] == filenames[0]
+ nextfilenames = filenames[1]
+ else:
+ assert filenames != None
+ s += line
+ continue
+ else:
+ assert filenames != None
+ s += line
+ continue
+
+ if verbose:
+ print 'looking for matches'
+ sfilenames = filenames
+ while filenames != None:
+ if filenames[0] == name_to_list:
+ print name_to_list
+ assert filenames[1] == None
+ else:
+ print filenames[0] + ' within'
+ assert filenames[1] != None
+ filenames = filenames[1]
+ filenames = sfilenames
+
+ if s[-1] == '\n':
+ s = s[:-1]
+
+ pp = 1
+ p = pend = 0
+ match = rxc.search (s, p)
+ while match != None:
+ firstmatch = match
+ blobs = falses = 0
+ while 1:
+ if verbose:
+ print 'found match'
+ what = match.lastgroup
+
+ if what == 'cblob':
+ if verbose: print 'match is a blob context'
+ pend = s.find ('\n', match.end()) + 1
+ if pend == 0:
+ pend = len(s)
+ p = match.start() + 1
+ else:
+ blob_p = what == 'blob'
+ assert blob_p or what == 'falsepos'
+
+ if blob_p:
+ if verbose: print 'match is a blob'
+ blobs += 1
+ else:
+ if verbose: print 'match is a false positive'
+ falses += 1
+
+ if blob_p and replace_blob or not blob_p and replace_falsepos:
+ s = s[:match.start(what)] + replacement + s[match.end(what):]
+ p = match.start(what) + len(replacement)
+ if pend > match.start(what):
+ pend += p - match.end(what)
+ else:
+ p = match.end(what)
+
+ if p > pend:
+ pend = s.find ('\n', p) + 1
+ if (pend == 0):
+ pend = len(s)
+
+ match = rxc.search (s, p)
+ if match == None or match.start () >= pend:
+ break
+
+ if print_nomatch:
+ sys.stdout.write (s[pp:firstmatch.start() + 1])
+ pp = firstmatch.start() + 1
+ else:
+ pp = s.rfind ('\n', 0, firstmatch.start () + 1) + 1
+
+ if print_blob and blobs or print_falsepos and falses:
+ if not print_nomatch:
+ sfilenames = filenames
+ while filenames != None:
+ print '::: ' + filenames[0] + ' :::'
+ if filenames[0] == name_to_list:
+ assert filenames[1] == None
+ else:
+ assert filenames[1] != None
+ filenames = filenames[1]
+ filenames = sfilenames
+ sys.stdout.write (s[pp:pend])
+ pp = pend
+
+ if list_blob and blobs or list_falsepos and falses:
+ while filenames != None:
+ if filenames[0] == name_to_list:
+ print name_to_list
+ assert filenames[1] == None
+ else:
+ print filenames[0] + ' within'
+ assert filenames[1] != None
+ filenames = filenames[1]
+ exit (1)
+
+ if print_nomatch:
+ sys.stdout.write(s[pp:])
+
+ if verbose:
+ print 'no further matches'
+
+ s = '\n'
+ filenames = nextfilenames
+ del nextfilenames
+
+assert filenames == None
+
+exit (0)
+EOF
+
+ scriptcmd="${PYTHON-python} "'"$scriptname"'
+}
+
+set_perl_main () {
+ adjust_rx='
+s,\\(,\\(?:,g;
+s,\\\([{(|)}?+]\),\1,g;
+'
+
+ # Add $ before arguments
+ set `echo "$@" | sed 's,\(^\|= *\),&$,g'`
+
+ cat >> "$scriptname" <<\EOF
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+# Should we replace blobs and false positives with replacement?
+my $replace_blob = 0;
+my $replace_falsepos = 0;
+my $replacement = '/*(DEBLOBBED)*/';
+
+# Should we print lines containing blobs, false positives, and neither?
+my $print_blob = 0;
+my $with_context = 0;
+my $print_falsepos = 0;
+my $print_nomatch = 0;
+
+# Should we print name_to_list and exit if we find blobs or false positives?
+my $list_blob = 0;
+my $list_falsepos = 0;
+
+# Should we forget everything we know about false positives?
+my $falsepos;
+my $no_falsepos = 0;
+
+EOF
+
+ cat >> "$scriptname" <<EOF
+my \$name_to_list = '$input';
+
+my \$verbose = $vp;
+
+# Which of the defaults above should we override?
+$@ = 1;
+
+EOF
+
+ ${SED-sed} -n 's,^[+],,p' < "$regex_name" |
+ ${SED-sed} -n -e "$adjust_rx" -e 's,\^,,' \
+ -e '1h; 1!H; $ { g; s,[\n],|,g; '"\
+s,^\\(.*\\)\$,\$falsepos = qr'(?<falsepos>\\1)'ms;,;\
+"' p;}' >> "$scriptname"
+
+ ${SED-sed} -n 's,^[-],,p' < "$regex_name" |
+ ${SED-sed} -n -e "$adjust_rx" \
+ -e '1h; 1!H; $ { g; s,[\n],|,g; '"\
+s,^\\(.*\\)\$,my \$blob = qr'(?<blob>\\1)'ms;,;\
+"' p;}' >> "$scriptname"
+
+ echo "\\($initblob\\|$defineblob\\|$asmblob\\)" |
+ ${SED-sed} -e "$adjust_rx" \
+ -e "s,^\\(.*\\)\$,my \$cblob = qr'(?<cblob>\\1)'ms if \$with_context;," >> "$scriptname"
+
+ cat >> "$scriptname" <<\EOF
+
+$falsepos = qr/(?<falsepos>(?!))/ if $no_falsepos || ! defined $falsepos;
+
+my $rx = qr/^$falsepos|$blob/ms;
+
+$rx = qr/$rx|^$cblob/ms if $with_context;
+
+my @filenames;
+my $nfilenames = 0;
+my $nextnfilenames;
+
+my $s = '';
+
+while (<STDIN>) {
+ # Read into s all lines between begin and end. An empty line, without
+ # even the '\n', flags the end of the input.
+ if (m:^[;][/][*](begin|end) (.*)[*][/][;]$:) {
+ if ($1 eq 'begin') {
+ print "entering $2\n" if $verbose;
+ $filenames[$nfilenames] = $2;
+ $nextnfilenames = $nfilenames + 1;
+ if ($s eq '') {
+ $nfilenames = $nextnfilenames;
+ next;
+ }
+ } else {
+ $nextnfilenames = $nfilenames - 1;
+ print "processing $filenames[$nextnfilenames]\n" if $verbose;
+ }
+ } else {
+ $s .= $_;
+ next;