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

$| = 1;

require $ENV{'ECHO_SCRIPTS_DIR'} . "/share/common_functions.pl";

# Filter_3_make_wellformed.pl
# 2010-05-05
# Wolfgang Schmidle

# This script calls all individual scripts in step 3
# i.e. it transforms a well-formed document into a valid document

# input: a well-formed document after step 2

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",
	"Filter_3_04_replace_underscores.pl",
	"Filter_3_05_add_basic_xml.pl",
	"Filter_3_06_make_tags_wellformed.pl"
);

my $file = shift @ARGV;

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

my $result = `$command`;

# print $result;
printInOutputTextFile($result);


# my $filterDir = "/Users/wschmidle/Library/Application Support/TextWrangler/Unix Support/Unix Filters/";

# my $result = `perl Filter_3_1_pb.pl "$file" `;
# my $result = `perl Filter_3_0_Schummelskript.pl "$file" | perl Filter_3_1_pb.pl`;

# my $result = `perl $filterEscapeSequences "$file"`;
# my @text = split "\n", $result;


