#!/usr/bin/perl -w
use strict;
use warnings;
use utf8;
use open qw(:std :utf8);
use integer;

$| = 1;

# Filter_2_05_check_escape_sequences.pl
# 2010-05-04
# Wolfgang Schmidle

# This script tests whether there are characters in the text that will not be removed
# by Filter_escape_sequences.pl

# input: raw text, normally as a whole
# output: a (possibly empty) list of warnings


my @filters = (
	"Filter_3_00_Schummelskript.pl",
	"Filter_3_01_replace_unknown_characters.pl",
	"Filter_3_02_replace_replacements.pl",
	"Filter_3_03_replace_escape_sequences.pl"
);

my $file = shift @ARGV;

$_ = shift @filters;
my $command = "perl $_ \"$file\"";
foreach (@filters) { $command .= " | perl $_"; }

my $result = `$command`;

my @text = split "\n", $result;


# go through the text

my $i = 0;
my $pb = 0;
my $page;

foreach (@text) {
	$i++;
	if (m!<pb[ >]!) { 
		$pb++;
		$page = ( m!\[(.+?)\]! ? $1 : $pb );
	}
	
	if (/\\/) { 
		warn "Line $i (page $page) contains \"\\\":\n$_\n"; 
	} 
	if (/{/) { 
		warn "Line $i (page $page) contains \"{\":\n$_\n"; 
	} 
}

die "That's all.\n";


# TO DO:
