mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Cmake export tests: Use pre-compiled regular expressions
The expressions are used for determining the used external files in a lyx-source. Using pre-compiled expr makes it more readable.
This commit is contained in:
parent
05a5c43617
commit
597dcbb5be
@ -56,6 +56,7 @@ if(format MATCHES "dvi|pdf")
|
|||||||
if(NOT "${ENCODING}" STREQUAL "default")
|
if(NOT "${ENCODING}" STREQUAL "default")
|
||||||
# message(STATUS "ENCODING = ${ENCODING}")
|
# message(STATUS "ENCODING = ${ENCODING}")
|
||||||
endif()
|
endif()
|
||||||
|
message(STATUS "Executing ${PERL_EXECUTABLE} \"${Perl_Script}\" \"${LYX_ROOT}/${file}.lyx\" \"${LYX_SOURCE}\" ${format} ${_ft} ${ENCODING} ${LanguageFile}")
|
||||||
execute_process(COMMAND ${PERL_EXECUTABLE} "${Perl_Script}" "${LYX_ROOT}/${file}.lyx" "${LYX_SOURCE}" ${format} ${_ft} ${ENCODING} ${LanguageFile}
|
execute_process(COMMAND ${PERL_EXECUTABLE} "${Perl_Script}" "${LYX_ROOT}/${file}.lyx" "${LYX_SOURCE}" ${format} ${_ft} ${ENCODING} ${LanguageFile}
|
||||||
RESULT_VARIABLE _err)
|
RESULT_VARIABLE _err)
|
||||||
string(COMPARE EQUAL ${_err} 0 _erg)
|
string(COMPARE EQUAL ${_err} 0 _erg)
|
||||||
|
@ -144,6 +144,13 @@ sub newMatch(%)
|
|||||||
if (! defined($elem{"fileidx"})) {
|
if (! defined($elem{"fileidx"})) {
|
||||||
$elem{"fileidx"} = 1;
|
$elem{"fileidx"} = 1;
|
||||||
}
|
}
|
||||||
|
if (exists($elem{"search"})) {
|
||||||
|
my $ref = ref($elem{"search"});
|
||||||
|
diestack("Wrong or invalid regex (ref == $ref) specified") if ($ref ne "Regexp");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
diestack("No search defined");
|
||||||
|
}
|
||||||
diestack("No result defined") if (! defined($elem{"result"}));
|
diestack("No result defined") if (! defined($elem{"result"}));
|
||||||
return(\%elem);
|
return(\%elem);
|
||||||
}
|
}
|
||||||
@ -193,32 +200,32 @@ sub checkForHeader($)
|
|||||||
$selem{name} = $1;
|
$selem{name} = $1;
|
||||||
unshift(@stack, \%selem);
|
unshift(@stack, \%selem);
|
||||||
my @rElems = ();
|
my @rElems = ();
|
||||||
$rElems[0] = newMatch("search" => '^\\\\master\s+(.*\.lyx)',
|
$rElems[0] = newMatch("search" => qr/^\\master\s+(.*\.lyx)/,
|
||||||
"filetype" => "prefix_only",
|
"filetype" => "prefix_only",
|
||||||
"result" => ["\\master ", ""]);
|
"result" => ["\\master ", ""]);
|
||||||
if (keys %{$rFont}) {
|
if (keys %{$rFont}) {
|
||||||
for my $ff ( keys %{$rFont}) {
|
for my $ff ( keys %{$rFont}) {
|
||||||
# fontentry of type '\font_roman default'
|
# fontentry of type '\font_roman default'
|
||||||
my $elem = newMatch("search" => '^\\\\font_' . $ff . '\s+[^"]*\s*$',
|
my $elem = newMatch("search" => qr/^\\font_$ff\s+[^\"]*\s*$/,
|
||||||
"filetype" => "replace_only",
|
"filetype" => "replace_only",
|
||||||
"result" => ["\\font_$ff ", $rFont->{$ff}]);
|
"result" => ["\\font_$ff ", $rFont->{$ff}]);
|
||||||
# fontentry of type '\font_roman "default"'
|
# fontentry of type '\font_roman "default"'
|
||||||
my $elem1 = newMatch("search" => '^\\\\font_' . $ff . '\s+"[^"]*"\s*$',
|
my $elem1 = newMatch("search" => qr/^\\font_$ff\s+\"[^\"]*\"\s*$/,
|
||||||
"filetype" => "replace_only",
|
"filetype" => "replace_only",
|
||||||
"result" => ["\\font_$ff \"", $rFont->{$ff}, '"']);
|
"result" => ["\\font_$ff \"", $rFont->{$ff}, '"']);
|
||||||
# fontentry of type '\font_roman "default" "default"'
|
# fontentry of type '\font_roman "default" "default"'
|
||||||
my $elem2 = newMatch("search" => '^\\\\font_' . $ff . '\s+"(.*)"\s+"default"\s*$',
|
my $elem2 = newMatch("search" => qr/^\\font_$ff\s+\"(.*)\"\s+\"default\"\s*$/,
|
||||||
"filetype" => "replace_only",
|
"filetype" => "replace_only",
|
||||||
"result" => ["\\font_$ff ", '"', "1", '" "', $rFont->{$ff}, '"']);
|
"result" => ["\\font_$ff ", '"', "1", '" "', $rFont->{$ff}, '"']);
|
||||||
push(@rElems, $elem, $elem1, $elem2);
|
push(@rElems, $elem, $elem1, $elem2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
my $elemntf = newMatch("search" => '^\\\\use_non_tex_fonts\s+(false|true)',
|
my $elemntf = newMatch("search" => qr/^\\use_non_tex_fonts\s+(false|true)/,
|
||||||
"filetype" => "replace_only",
|
"filetype" => "replace_only",
|
||||||
"result" => ["\\use_non_tex_fonts $useNonTexFont"]);
|
"result" => ["\\use_non_tex_fonts $useNonTexFont"]);
|
||||||
push(@rElems, $elemntf);
|
push(@rElems, $elemntf);
|
||||||
if (defined($inputEncoding)) {
|
if (defined($inputEncoding)) {
|
||||||
my $inputenc = newMatch("search" => '^\\\\inputencoding\s+(' . $inputEncoding->{search} . ')',
|
my $inputenc = newMatch("search" => qr/^\\inputencoding\s+($inputEncoding->{search})/,
|
||||||
"filetype" => "replace_only",
|
"filetype" => "replace_only",
|
||||||
"result" => ["\\inputencoding " . $inputEncoding->{out}]);
|
"result" => ["\\inputencoding " . $inputEncoding->{out}]);
|
||||||
push(@rElems, $inputenc);
|
push(@rElems, $inputenc);
|
||||||
@ -239,12 +246,12 @@ sub checkForPreamble($)
|
|||||||
$selem{name} = $1;
|
$selem{name} = $1;
|
||||||
unshift(@stack, \%selem);
|
unshift(@stack, \%selem);
|
||||||
my $rElem = newMatch("ext" => [".eps", ".png"],
|
my $rElem = newMatch("ext" => [".eps", ".png"],
|
||||||
"search" => '^\\\\(photo|ecvpicture)(.*\{)(.*)\}',
|
"search" => qr/^\\(photo|ecvpicture)(.*\{)(.*)\}/,
|
||||||
"fileidx" => 3,
|
"fileidx" => 3,
|
||||||
"result" => ["\\", "1", "2", "3", "}"]);
|
"result" => ["\\", "1", "2", "3", "}"]);
|
||||||
#
|
#
|
||||||
# Remove comments from preamble
|
# Remove comments from preamble
|
||||||
my $comments = newMatch("search" => '^([^%]*)([%]+)([^%]*)$',
|
my $comments = newMatch("search" => qr/^([^%]*)([%]+)([^%]*)$/,
|
||||||
"filetype" => "replace_only",
|
"filetype" => "replace_only",
|
||||||
"result" => ["1", "2"]);
|
"result" => ["1", "2"]);
|
||||||
setMatching([$rElem, $comments]);
|
setMatching([$rElem, $comments]);
|
||||||
@ -265,7 +272,7 @@ sub checkForLayoutStart($)
|
|||||||
unshift(@stack, \%selem);
|
unshift(@stack, \%selem);
|
||||||
if ($selem{name} =~ /^(Picture|Photo)$/ ) {
|
if ($selem{name} =~ /^(Picture|Photo)$/ ) {
|
||||||
my $rElem = newMatch("ext" => [".eps", ".png"],
|
my $rElem = newMatch("ext" => [".eps", ".png"],
|
||||||
"search" => '^(.+)',
|
"search" => qr/^(.+)/,
|
||||||
"result" => ["", "", ""]);
|
"result" => ["", "", ""]);
|
||||||
setMatching([$rElem]);
|
setMatching([$rElem]);
|
||||||
}
|
}
|
||||||
@ -285,7 +292,7 @@ sub checkForInsetStart($)
|
|||||||
$selem{name} = $1;
|
$selem{name} = $1;
|
||||||
unshift(@stack, \%selem);
|
unshift(@stack, \%selem);
|
||||||
if ($selem{name} =~ /^(Graphics|External)$/) {
|
if ($selem{name} =~ /^(Graphics|External)$/) {
|
||||||
my $rElem = newMatch("search" => '^\s+filename\s+(.+)$',
|
my $rElem = newMatch("search" => qr/^\s+filename\s+(.+)$/,
|
||||||
"filetype" => "copy_only",
|
"filetype" => "copy_only",
|
||||||
"result" => ["\tfilename ", "", ""]);
|
"result" => ["\tfilename ", "", ""]);
|
||||||
setMatching([$rElem]);
|
setMatching([$rElem]);
|
||||||
@ -306,24 +313,24 @@ sub checkForLatexCommand($)
|
|||||||
if ($param eq "bibtex") {
|
if ($param eq "bibtex") {
|
||||||
my $rElem1 = newMatch("ext" => ".bib",
|
my $rElem1 = newMatch("ext" => ".bib",
|
||||||
"filetype" => "prefix_for_list",
|
"filetype" => "prefix_for_list",
|
||||||
"search" => '^bibfiles\s+\"(.+)\"',
|
"search" => qr/^bibfiles\s+\"(.+)\"/,
|
||||||
"result" => ["bibfiles \"", "1", "\""]);
|
"result" => ["bibfiles \"", "1", "\""]);
|
||||||
my $rElem2 = newMatch("ext" => ".bst",
|
my $rElem2 = newMatch("ext" => ".bst",
|
||||||
"filetype" => "prefix_for_list",
|
"filetype" => "prefix_for_list",
|
||||||
"search" => '^options\s+\"(.+)\"',
|
"search" => qr/^options\s+\"(.+)\"/,
|
||||||
"result" => ["options \"", "1", "\""]);
|
"result" => ["options \"", "1", "\""]);
|
||||||
setMatching([$rElem1, $rElem2]);
|
setMatching([$rElem1, $rElem2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($stack[0]->{name} =~ /^CommandInset\s+include$/) {
|
elsif ($stack[0]->{name} =~ /^CommandInset\s+include$/) {
|
||||||
if ($param =~ /^(verbatiminput\*?|lstinputlisting|inputminted)$/) {
|
if ($param =~ /^(verbatiminput\*?|lstinputlisting|inputminted)$/) {
|
||||||
my $rElem = newMatch("search" => '^filename\s+\"(.+)\"',
|
my $rElem = newMatch("search" => qr/^filename\s+\"(.+)\"/,
|
||||||
"filetype" => "copy_only",
|
"filetype" => "copy_only",
|
||||||
"result" => ["filename \"", "", "\""]);
|
"result" => ["filename \"", "", "\""]);
|
||||||
setMatching([$rElem]);
|
setMatching([$rElem]);
|
||||||
}
|
}
|
||||||
elsif ($param =~ /^(include|input)$/) {
|
elsif ($param =~ /^(include|input)$/) {
|
||||||
my $rElem = newMatch("search" => '^filename\s+\"(.+)\"',
|
my $rElem = newMatch("search" => qr/^filename\s+\"(.+)\"/,
|
||||||
"filetype" => "interpret",
|
"filetype" => "interpret",
|
||||||
"result" => ["filename \"", "", "\""]);
|
"result" => ["filename \"", "", "\""]);
|
||||||
setMatching([$rElem]);
|
setMatching([$rElem]);
|
||||||
@ -358,7 +365,7 @@ sub checkLyxLine($)
|
|||||||
my $rMatch = getMatching();
|
my $rMatch = getMatching();
|
||||||
for my $m ( @{$rMatch}) {
|
for my $m ( @{$rMatch}) {
|
||||||
my $search = getSearch($m);
|
my $search = getSearch($m);
|
||||||
if ($l =~ /$search/) {
|
if ($l =~ $search) {
|
||||||
my @matches = ($1, $2, $3, $4);
|
my @matches = ($1, $2, $3, $4);
|
||||||
my $filetype = getFileType($m);
|
my $filetype = getFileType($m);
|
||||||
my @result2 = @{getResult($m)};
|
my @result2 = @{getResult($m)};
|
||||||
|
Loading…
Reference in New Issue
Block a user