#!/usr/bin/perl
use strict ;
use warnings ;
use Term::ANSIColor;
# ****************************************************************************#
# Test the idpp application using the raw, unprocessed block/block.html file. #
# Copyright (c) 2006-2024 Mahlon R. Smith, The Software Samurai               #
#     GNU GPL copyright notice located in idpp.hpp                            #
# Developed under: Perl 5.38.2                                                #
# Updated: 23 May 2024                                                        #
# ****************************************************************************#

   my $Title  = colored("  doblock                                           \n", 'bold underline blue');
   my $raw    = "block/block.html" ;         # raw (unprocessed) HTML file
   my $src    = "block.html" ;               # source copy of HTML file
   my $css    = "../infodoc-styles.css" ;    # target CSS style sheet
   my $idpp   = "./idpp" ;                   # post-processor application
   my $option = @ARGV[0] ;                   # option from command line

   if ( -e $raw )
   {
      system ( "clear" ) ;
      system ( "cp --preserve=all '$raw' '$src'" ) ;
      #print ( "Raw: '$raw' Source: '$src'\n" ) ;

      if ( not defined $option )       # Full automagic processing
      {
         system ( "'$idpp' -f='$css' '$src'" ) ;
      }
      elsif ( $option eq 'i' )         # Full interactive processing
      {
         system ( "'$idpp' -f'$css' -i '$src'" ) ;
      }
      elsif ( $option eq 't' )         # Interactive Tables, with auto for other
      {
         system ( "'$idpp' -f'$css' --table_border=specify '$src'" ) ;
      }
      elsif ( $option eq 'c' )         # Interactive Cartouche, with auto for other
      {
         system ( "'$idpp' -f'$css' --cartouche=specify '$src'" ) ;
      }
      elsif ( $option eq 'b' )         # Automatic, with BOOK debugging option
      {
         system ( "'$idpp' -f'$css' --book '$src'" ) ;
      }
      elsif ( $option eq 's' )         # Interactive processing with 'Scan'
      {                                #  - requires arguments @ARGV[1] and @ARGV[2]
         # test for range arguments
         if ( defined @ARGV[1] and defined @ARGV[2] )
         { system ( "'$idpp' -f'$css' -i --scan='@ARGV[1]','@ARGV[2]' '$src'" ) ; }
         else
         { print colored ( "  --scan option requires three arguments: s startline endline\n", 'bright_red' ) ; }
      }
      elsif ( $option eq 'k' )         # Automatic, with SKIP debugging option
      {                                # - requires argument @ARGV[1]
         if ( defined @ARGV[1] )
         {
            print "skip_count automatic\n" ;
            system ( "'$idpp' -f'$css' --skip='@ARGV[1]' '$src'" ) ;
         }
         else
         { print colored ( "  --skip option requires a count argument\n", 'bright_red' ) ; }
      }
      elsif ( $option eq 'v' )         # Automatic, with VERBOSE option
      {
         print "verbose automatic\n" ;
         system ( "'$idpp' -f'$css' -v '$src'" ) ;
      }
      elsif ( $option eq 'p' )         # Pause after each response from response file
      {
         # Note: block.html processing currently has no response file
         print ( "  $Title" ) ;
         print colored ( "  $src currently has no response file.\n", 'blue' ) ;
      }
      else
      {
         print ( "  $Title" ) ;
         print colored ( "  no argument: full automatic processing\n", 'blue' ) ;
         print colored ( "  i: full interactive processing\n", 'blue' ) ;
         print colored ( "  t: interactive table formatting\n", 'blue' ) ;
         print colored ( "  c: interactive cartouche formatting\n", 'blue' ) ;
         print colored ( "  b: automatic with   --book option\n", 'blue' ) ;
         print colored ( "  s: interactive with --scan='a,b' option\n", 'blue' ) ;
         print colored ( "  k: automatic with   --skip=n option\n", 'blue' ) ;
         print colored ( "  v: automatic with   -v (verbose) option\n", 'blue' ) ;
         print colored ( "  p: interactive with --step='a' option\n", 'blue' ) ;
      }
   }
   else
   { print colored ( "  $raw Not Found!\n\n", 'bright_red' ) ; }
   exit ;
