From: Kornel Benko Date: Fri, 10 Jan 2014 11:34:40 +0000 (+0100) Subject: Ctests perl scripts: Added use of prototypes X-Git-Tag: 2.1.0rc1~309 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=83071a23922147b8a2e0289682967cd86ff1c26e;p=features.git Ctests perl scripts: Added use of prototypes --- diff --git a/development/autotests/lyxStatus.pm b/development/autotests/lyxStatus.pm index fd2e3829ff..8182e49ac1 100644 --- a/development/autotests/lyxStatus.pm +++ b/development/autotests/lyxStatus.pm @@ -13,6 +13,26 @@ BEGIN { @EXPORT = qw(initLyxStack checkLyxLine closeLyxStack diestack); } +# Prototypes +sub initLyxStack($$); +sub diestack($); +sub closeLyxStack(); +sub setMatching($); +sub getMatching(); +sub checkForEndBlock($); +sub newMatch(%); +sub getSearch($); +sub getFileType($); +sub getFileIdx($); +sub getExt($); +sub getResult($); +sub checkForHeader($); +sub checkForPreamble($); +sub checkForLayoutStart($); +sub checkForInsetStart($); +sub checkForLatexCommand($); +sub checkLyxLine($); + my @stack = (); # list of HASH-Arrays my $rFont = {}; my $useNonTexFont = "true"; @@ -77,7 +97,7 @@ sub diestack($) sub closeLyxStack() { - &diestack("Stack not OK") if ($stack[0]->{type} ne "Starting"); + diestack("Stack not OK") if ($stack[0]->{type} ne "Starting"); } sub setMatching($) @@ -100,7 +120,7 @@ sub checkForEndBlock($) for my $et ( qw( layout inset preamble header)) { if ($l =~ /^\\end_$et$/) { - &diestack("Not in $et") if ($stack[0]->{type} ne "$et"); + diestack("Not in $et") if ($stack[0]->{type} ne "$et"); #print "End $et\n"; shift(@stack); return(1); @@ -109,7 +129,7 @@ sub checkForEndBlock($) return(0); } -sub newMatch($$) +sub newMatch(%) { my %elem = @_; @@ -122,7 +142,7 @@ sub newMatch($$) if (! defined($elem{"fileidx"})) { $elem{"fileidx"} = 1; } - &diestack("No result defined") if (! defined($elem{"result"})); + diestack("No result defined") if (! defined($elem{"result"})); return(\%elem); } @@ -171,22 +191,22 @@ sub checkForHeader($) $selem{name} = $1; unshift(@stack, \%selem); my @rElems = (); - $rElems[0] = &newMatch("search" => '^\\\\master\s+(.*\.lyx)', + $rElems[0] = newMatch("search" => '^\\\\master\s+(.*\.lyx)', "filetype" => "prefix_only", "result" => ["\\master ", ""]); if (keys %{$rFont}) { for my $ff ( keys %{$rFont}) { - my $elem = &newMatch("search" => '^\\\\font_' . $ff . '\s+', + my $elem = newMatch("search" => '^\\\\font_' . $ff . '\s+', "filetype" => "replace_only", "result" => ["\\font_$ff ", $rFont->{$ff}]); push(@rElems, $elem); } } - my $elemntf = &newMatch("search" => '^\\\\use_non_tex_fonts\s+(false|true)', + my $elemntf = newMatch("search" => '^\\\\use_non_tex_fonts\s+(false|true)', "filetype" => "replace_only", "result" => ["\\use_non_tex_fonts $useNonTexFont"]); push(@rElems, $elemntf); - &setMatching(\@rElems); + setMatching(\@rElems); return(1); } return(0); @@ -201,11 +221,11 @@ sub checkForPreamble($) $selem{type} = "preamble"; $selem{name} = $1; unshift(@stack, \%selem); - my $rElem = &newMatch("ext" => [".eps", ".png"], + my $rElem = newMatch("ext" => [".eps", ".png"], "search" => '^\\\\(photo|ecvpicture)(.*\{)(.*)\}', "fileidx" => 3, "result" => ["\\", "1", "2", "3", "}"]); - &setMatching([$rElem]); + setMatching([$rElem]); return(1); } return(0); @@ -222,10 +242,10 @@ sub checkForLayoutStart($) $selem{name} = $1; unshift(@stack, \%selem); if ($selem{name} =~ /^(Picture|Photo)$/ ) { - my $rElem = &newMatch("ext" => [".eps", ".png"], + my $rElem = newMatch("ext" => [".eps", ".png"], "search" => '^(.+)', "result" => ["", "", ""]); - &setMatching([$rElem]); + setMatching([$rElem]); } return(1); } @@ -243,10 +263,10 @@ sub checkForInsetStart($) $selem{name} = $1; unshift(@stack, \%selem); if ($selem{name} =~ /^(Graphics|External)$/) { - my $rElem = &newMatch("search" => '^\s+filename\s+(.+)$', + my $rElem = newMatch("search" => '^\s+filename\s+(.+)$', "filetype" => "copy_only", "result" => ["\tfilename ", "", ""]); - &setMatching([$rElem]); + setMatching([$rElem]); } return(1); } @@ -262,29 +282,29 @@ sub checkForLatexCommand($) my $param = $1; if ($stack[0]->{name} =~ /^CommandInset\s+bibtex$/) { if ($param eq "bibtex") { - my $rElem1 = &newMatch("ext" => ".bib", + my $rElem1 = newMatch("ext" => ".bib", "filetype" => "prefix_for_list", "search" => '^bibfiles\s+\"(.+)\"', "result" => ["bibfiles \"", "1", "\""]); - my $rElem2 = &newMatch("ext" => ".bst", + my $rElem2 = newMatch("ext" => ".bst", "filetype" => "prefix_for_list", "search" => '^options\s+\"(.+)\"', "result" => ["options \"", "1", "\""]); - &setMatching([$rElem1, $rElem2]); + setMatching([$rElem1, $rElem2]); } } elsif ($stack[0]->{name} =~ /^CommandInset\s+include$/) { if ($param =~ /^(verbatiminput\*?|lstinputlisting)$/) { - my $rElem = &newMatch("search" => '^filename\s+\"(.+)\"', + my $rElem = newMatch("search" => '^filename\s+\"(.+)\"', "filetype" => "copy_only", "result" => ["filename \"", "", "\""]); - &setMatching([$rElem]); + setMatching([$rElem]); } elsif ($param =~ /^(include|input)$/) { - my $rElem = &newMatch("search" => '^filename\s+\"(.+)\"', + my $rElem = newMatch("search" => '^filename\s+\"(.+)\"', "filetype" => "interpret", "result" => ["filename \"", "", "\""]); - &setMatching([$rElem]); + setMatching([$rElem]); } } } @@ -306,20 +326,20 @@ sub checkLyxLine($) { my ($l) = @_; - return({"found" => 0}) if (&checkForHeader($l)); - return({"found" => 0}) if (&checkForPreamble($l)); - return({"found" => 0}) if (&checkForEndBlock($l)); - return({"found" => 0}) if (&checkForLayoutStart($l)); - return({"found" => 0}) if (&checkForInsetStart($l)); - return({"found" => 0}) if (&checkForLatexCommand($l)); + return({"found" => 0}) if (checkForHeader($l)); + return({"found" => 0}) if (checkForPreamble($l)); + return({"found" => 0}) if (checkForEndBlock($l)); + return({"found" => 0}) if (checkForLayoutStart($l)); + return({"found" => 0}) if (checkForInsetStart($l)); + return({"found" => 0}) if (checkForLatexCommand($l)); if (defined($stack[0])) { - my $rMatch = &getMatching(); + my $rMatch = getMatching(); for my $m ( @{$rMatch}) { - my $search = &getSearch($m); + my $search = getSearch($m); if ($l =~ /$search/) { my @matches = ($1, $2, $3, $4); - my $filetype = &getFileType($m); - my @result2 = @{&getResult($m)}; + my $filetype = getFileType($m); + my @result2 = @{getResult($m)}; for my $r (@result2) { if ($r =~ /^\d$/) { @@ -334,12 +354,12 @@ sub checkLyxLine($) return(\%result); } else { - my $fileidx = &getFileIdx($m); + my $fileidx = getFileIdx($m); my $filename = $matches[$fileidx-1]; if ($filename !~ /^\.*$/) { my %result = ("found" => 1, "fileidx" => $fileidx, - "ext" => &getExt($m), + "ext" => getExt($m), "result" => \@result2); if ($filetype eq "prefix_for_list") { # bibfiles|options in CommandInset bibtex diff --git a/development/autotests/useSystemFonts.pl b/development/autotests/useSystemFonts.pl index 55f520aef9..7b71c82713 100644 --- a/development/autotests/useSystemFonts.pl +++ b/development/autotests/useSystemFonts.pl @@ -47,15 +47,28 @@ use File::Copy "cp"; use File::Temp qw/ :POSIX /; use lyxStatus; +# Prototypes +sub printCopiedDocuments($); +sub interpretedCopy($$$$); +sub copyFoundSubdocuments($); +sub copyJob($$); +sub isrelativeFix($$$); +sub isrelative($$$); +sub createTemporaryFileName($$); +sub copyJobPending($$); +sub addNewJob($$$$$); +sub addFileCopyJob($$$$); +sub getNewNameOf($$); + # convert lyx file to be compilable with xetex my ($source, $dest, $format, $fontT, $rest) = @ARGV; -&diestack("Too many arguments") if (defined($rest)); -&diestack("Sourcefilename not defined") if (! defined($source)); -&diestack("Destfilename not defined") if (! defined($dest)); -&diestack("Format (e.g. pdf4) not defined") if (! defined($format)); -&diestack("Font type (e.g. texF) not defined") if (! defined($fontT)); +diestack("Too many arguments") if (defined($rest)); +diestack("Sourcefilename not defined") if (! defined($source)); +diestack("Destfilename not defined") if (! defined($dest)); +diestack("Format (e.g. pdf4) not defined") if (! defined($format)); +diestack("Font type (e.g. texF) not defined") if (! defined($fontT)); $source = File::Spec->rel2abs($source); $dest = File::Spec->rel2abs($dest); @@ -95,7 +108,7 @@ else { my $sourcedir = dirname($source); my $destdir = dirname($dest); if (! -d $destdir) { - &diestack("could not make dir \"$destdir\"") if (! mkdir $destdir); + diestack("could not make dir \"$destdir\"") if (! mkdir $destdir); } my $destdirOfSubdocuments; @@ -115,11 +128,11 @@ my %type2hash = ( "copy_only" => "copyonly", "interpret" => "interpret"); -&addNewJob($source, $dest, "interpret", {}, \%IncludedFiles); +addNewJob($source, $dest, "interpret", {}, \%IncludedFiles); -©FoundSubdocuments(\%IncludedFiles); +copyFoundSubdocuments(\%IncludedFiles); -#&printCopiedDocuments(\%IncludedFiles); +#printCopiedDocuments(\%IncludedFiles); exit(0); ########################################################### @@ -143,14 +156,14 @@ sub interpretedCopy($$$$) my $sourcedir = dirname($source); my $res = 0; - &diestack("could not read \"$source\"") if (!open(FI, $source)); - &diestack("could not write \"$dest\"") if (! open(FO, '>', $dest)); + diestack("could not read \"$source\"") if (!open(FI, $source)); + diestack("could not write \"$dest\"") if (! open(FO, '>', $dest)); - &initLyxStack(\%font, $fontT); + initLyxStack(\%font, $fontT); while (my $l = ) { chomp($l); - my $rStatus = &checkLyxLine($l); + my $rStatus = checkLyxLine($l); if ($rStatus->{found}) { my $rF = $rStatus->{result}; if ($rStatus->{"filetype"} eq "replace_only") { @@ -163,18 +176,18 @@ sub interpretedCopy($$$$) my $separator = $rStatus->{"separator"}; my $foundrelative = 0; for my $f (@{$filelist}) { - my @isrel = &isrelative($f, + my @isrel = isrelative($f, $sourcedir, $rStatus->{ext}); if ($isrel[0]) { $foundrelative = 1; my $ext = $isrel[1]; if ($rStatus->{"filetype"} eq "prefix_only") { - $f = &getNewNameOf("$sourcedir/$f", $rFiles); + $f = getNewNameOf("$sourcedir/$f", $rFiles); } else { my ($newname, $res1); - ($newname, $res1) = &addFileCopyJob("$sourcedir/$f$ext", + ($newname, $res1) = addFileCopyJob("$sourcedir/$f$ext", "$destdirOfSubdocuments", $rStatus->{"filetype"}, $rFiles); @@ -198,7 +211,7 @@ sub interpretedCopy($$$$) close(FI); close(FO); - &closeLyxStack(); + closeLyxStack(); return($res); } @@ -211,12 +224,12 @@ sub copyFoundSubdocuments($) my %copylist = (); for my $filename (keys %{$rFiles}) { - next if (! ©JobPending($filename, $rFiles)); + next if (! copyJobPending($filename, $rFiles)); $copylist{$filename} = 1; } for my $f (keys %copylist) { # Second loop needed, because here $rFiles may change - my ($res1, @destfiles) = ©Job($f, $rFiles); + my ($res1, @destfiles) = copyJob($f, $rFiles); $res += $res1; for my $destfile (@destfiles) { print "res1 = $res1 for \"$f\" to be copied to $destfile\n"; @@ -239,10 +252,10 @@ sub copyJob($$) my $dest = $rFiles->{$source}->{$k}; push(@dest, $dest); if ($k eq "copyonly") { - &diestack("Could not copy \"$source\" to \"$dest\"") if (! cp($source, $dest)); + diestack("Could not copy \"$source\" to \"$dest\"") if (! cp($source, $dest)); } else { - &interpretedCopy($source, $dest, $destdirOfSubdocuments, $rFiles); + interpretedCopy($source, $dest, $destdirOfSubdocuments, $rFiles); } $res += 1; } @@ -266,7 +279,7 @@ sub isrelative($$$) if (ref($ext) eq "ARRAY") { for my $ext2 (@{$ext}) { - my @res = &isrelativeFix($f, $sourcedir, $ext2); + my @res = isrelativeFix($f, $sourcedir, $ext2); if ($res[0]) { return(@res); } @@ -274,7 +287,7 @@ sub isrelative($$$) return(0,0); } else { - return(&isrelativeFix($f, $sourcedir, $ext)); + return(isrelativeFix($f, $sourcedir, $ext)); } } @@ -307,7 +320,7 @@ sub copyJobPending($$) return 0; } -sub addNewJob($$$) +sub addNewJob($$$$$) { my ($source, $newname, $hashname, $rJob, $rFiles) = @_; @@ -324,11 +337,11 @@ sub addFileCopyJob($$$$) my $hashname = $type2hash{$filetype}; if (! defined($hashname)) { - &diestack("unknown filetype \"$filetype\""); + diestack("unknown filetype \"$filetype\""); } if (!defined($rJob->{$hashname})) { - &addNewJob($source, - &createTemporaryFileName($source, $destdirOfSubdocuments), + addNewJob($source, + createTemporaryFileName($source, $destdirOfSubdocuments), "$hashname", $rJob, $rFiles); $res = 1; }