>From 52700b8b23649a19e02f4b9a5736c0d9056c06e4 Mon Sep 17 00:00:00 2001 From: Akira Yokosawa <akiyks@xxxxxxxxx> Date: Sat, 26 Jan 2019 20:48:16 +0900 Subject: [PATCH 1/3] Add checkfcv.pl Add a script to detect collisions in commandchars choice Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx> --- utilities/checkfcv.pl | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 utilities/checkfcv.pl diff --git a/utilities/checkfcv.pl b/utilities/checkfcv.pl new file mode 100755 index 0000000..94621ba --- /dev/null +++ b/utilities/checkfcv.pl @@ -0,0 +1,78 @@ +#!/usr/bin/perl +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Check LaTeX source of snippet extracted by fcvextract.pl +# +# Copyright (C) Akira Yokosawa, 2019 +# +# Authors: Akira Yokosawa <akiyks@xxxxxxxxx> + +use strict; +use warnings; + +my $line; +my $lnlbl_re; +my $checking = 0; +my $linelabel_re = qr/\\begin\{linelabel\}\[([^\]]*)\]/ ; +my $end_linelabel_re = qr/\\end\{linelabel\}/ ; +my $Verbatim_cmd_re = qr/\\begin\{Verbatim[LNU]\}\[commandchars=(.{6}).*\]/ ; +my $Verbatim_re = qr/\\begin\{Verbatim[LNU]\}/ ; +my $end_Verbatim_re = qr/\\end\{Verbatim[LNU]\}/ ; +my $commandchars = ""; +my $esc_bsl; +my $esc_open; +my $esc_close; +my $esc_bsl_re; +my $esc_open_re; +my $esc_close_re; +my $line_count = 0; + +my $fcv_file = $ARGV[0]; +open(my $fh, '<:encoding(UTF-8)', $fcv_file) + or die "Could not open file '$fcv_file' $!"; + +while($line = <$fh>) { + $line_count = $line_count + 1; + if ($line =~ /$linelabel_re/) { + $checking = 1; + } + if ($checking == 3) { + if ($line =~ /$end_linelabel_re/) { + $checking = 4; + } + } + if ($checking == 2) { + if ($line =~ /$end_Verbatim_re/) { + $checking = 3; + } elsif ($commandchars =~ /\S/) { + $_ = $line; + s/$lnlbl_re//; + if (/$esc_bsl_re/ || /$esc_open_re/ || /$esc_close_re/) { + die "commandchars collision detected in $fcv_file, line: $line_count\n$line\n"; + } + } + } + if ($checking == 1) { + if ($line =~ /$Verbatim_cmd_re/) { + $commandchars = $1; + $esc_bsl = substr $commandchars, 0, 2; + $esc_open = substr $commandchars, 2, 2; + $esc_close = substr $commandchars, 4, 2; + $lnlbl_re = $esc_bsl."lnlbl".$esc_open.".*".$esc_close; + $esc_bsl_re = qr/$esc_bsl/; + $esc_open_re = qr/$esc_open/; + $esc_close_re = qr/$esc_close/; + $checking = 2; + } elsif ($line =~ /$Verbatim_re/) { + $checking = 2; + } + } + if (eof) { + last; + } +} +if ($checking == 4) { + exit 0; +} else { + die "incomplete fcv file $fcv_file\n"; +} -- 2.7.4