]> git.lyx.org Git - lyx.git/blobdiff - development/autotests/lyxStatus.pm
Cmake export tests:
[lyx.git] / development / autotests / lyxStatus.pm
index 8182e49ac11652f4eb5cf9b5cd170c4f573fabb8..6c3001953fe89903541b9831bcd85bce270dc35b 100644 (file)
@@ -14,7 +14,7 @@ BEGIN {
 }
 
 # Prototypes
-sub initLyxStack($$);
+sub initLyxStack($$$);
 sub diestack($);
 sub closeLyxStack();
 sub setMatching($);
@@ -36,6 +36,7 @@ sub checkLyxLine($);
 my @stack = ();                        # list of HASH-Arrays
 my $rFont = {};
 my $useNonTexFont = "true";
+my $inputEncoding = undef;
 
 # The elements are:
 # type (layout, inset, header, preamble, ...)
@@ -49,14 +50,18 @@ my $useNonTexFont = "true";
 #              but first set the modified value into $result->[$fileidx]
 #              numerical value will be replaced with appropriate matching group value
 
-sub initLyxStack($$)
+sub initLyxStack($$$)
 {
   $rFont = $_[0];
   if ($_[1] eq "systemF") {
     $useNonTexFont = "true";
   }
+  elsif ($_[1] eq "dontChange") {
+    $useNonTexFont = "dontChange";
+  }
   else {
     $useNonTexFont = "false";
+    $inputEncoding = $_[2];
   }
   $stack[0] = { type => "Starting"};
 }
@@ -142,6 +147,13 @@ sub newMatch(%)
   if (! defined($elem{"fileidx"})) {
     $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"}));
   return(\%elem);
 }
@@ -191,21 +203,38 @@ sub checkForHeader($)
     $selem{name} = $1;
     unshift(@stack, \%selem);
     my @rElems = ();
-    $rElems[0] = newMatch("search" => '^\\\\master\s+(.*\.lyx)',
+    $rElems[0] = newMatch("search" => qr/^\\master\s+(.*\.lyx)/,
                           "filetype" => "prefix_only",
                           "result" => ["\\master ", ""]);
     if (keys %{$rFont}) {
       for my $ff ( keys %{$rFont}) {
-       my $elem = newMatch("search" => '^\\\\font_' . $ff . '\s+',
+       # fontentry of type '\font_roman default'
+       my $elem = newMatch("search" => qr/^\\font_$ff\s+[^\"]*\s*$/,
                             "filetype" => "replace_only",
                             "result" => ["\\font_$ff ", $rFont->{$ff}]);
-       push(@rElems, $elem);
+       # fontentry of type '\font_roman "default"'
+       my $elem1 = newMatch("search" => qr/^\\font_$ff\s+\"[^\"]*\"\s*$/,
+                            "filetype" => "replace_only",
+                            "result" => ["\\font_$ff \"", $rFont->{$ff}, '"']);
+       # fontentry of type '\font_roman "default" "default"'
+       my $elem2 = newMatch("search" => qr/^\\font_$ff\s+\"(.*)\"\s+\"default\"\s*$/,
+                            "filetype" => "replace_only",
+                            "result" => ["\\font_$ff ", '"', "1", '" "', $rFont->{$ff}, '"']);
+       push(@rElems, $elem, $elem1, $elem2);
       }
     }
-    my $elemntf = newMatch("search" => '^\\\\use_non_tex_fonts\s+(false|true)',
-                           "filetype" => "replace_only",
-                           "result" => ["\\use_non_tex_fonts $useNonTexFont"]);
-    push(@rElems, $elemntf);
+    if ($useNonTexFont ne "dontChange") {
+      my $elemntf = newMatch("search" => qr/^\\use_non_tex_fonts\s+(false|true)/,
+                             "filetype" => "replace_only",
+                             "result" => ["\\use_non_tex_fonts $useNonTexFont"]);
+      push(@rElems, $elemntf);
+    }
+    if (defined($inputEncoding)) {
+      my $inputenc = newMatch("search" =>  qr/^\\inputencoding\s+($inputEncoding->{search})/,
+                             "filetype" => "replace_only",
+                             "result" => ["\\inputencoding " . $inputEncoding->{out}]);
+      push(@rElems, $inputenc);
+    }
     setMatching(\@rElems);
     return(1);
   }
@@ -222,10 +251,15 @@ sub checkForPreamble($)
     $selem{name} = $1;
     unshift(@stack, \%selem);
     my $rElem = newMatch("ext" => [".eps", ".png"],
-                         "search" => '^\\\\(photo|ecvpicture)(.*\{)(.*)\}',
+                         "search" => qr/^\\(photo|ecvpicture)(.*\{)(.*)\}/,
                          "fileidx" => 3,
                          "result" => ["\\", "1", "2", "3", "}"]);
-    setMatching([$rElem]);
+    #
+    # Remove comments from preamble
+    my $comments = newMatch("search" => qr/^([^%]*)([%]+)([^%]*)$/,
+                           "filetype" => "replace_only",
+                           "result" => ["1", "2"]);
+    setMatching([$rElem, $comments]);
     return(1);
   }
   return(0);
@@ -235,15 +269,16 @@ sub checkForLayoutStart($)
 {
   my ($l) = @_;
 
-  if ($l =~ /^\\begin_layout\s+(.+)$/) {
+  if ($l =~ /^\\begin_layout\s+(.*)$/) {
     #print "started layout\n";
     my %selem = ();
     $selem{type} = "layout";
     $selem{name} = $1;
     unshift(@stack, \%selem);
     if ($selem{name} =~ /^(Picture|Photo)$/ ) {
-      my $rElem = newMatch("ext" => [".eps", ".png"],
-                           "search" => '^(.+)',
+      my $rElem = newMatch("ext" => [".eps", ".png", ""],
+                            "filetype" => "copy_only",
+                           "search" => qr/^(.+)/,
                            "result" => ["", "", ""]);
       setMatching([$rElem]);
     }
@@ -263,7 +298,7 @@ sub checkForInsetStart($)
     $selem{name} = $1;
     unshift(@stack, \%selem);
     if ($selem{name} =~ /^(Graphics|External)$/) {
-      my $rElem = newMatch("search" => '^\s+filename\s+(.+)$',
+      my $rElem = newMatch("search" => qr/^\s+filename\s+(.+)$/,
                            "filetype" => "copy_only",
                            "result" => ["\tfilename ", "", ""]);
       setMatching([$rElem]);
@@ -284,24 +319,24 @@ sub checkForLatexCommand($)
        if ($param eq "bibtex") {
          my $rElem1 = newMatch("ext" => ".bib",
                                 "filetype" => "prefix_for_list",
-                                "search" => '^bibfiles\s+\"(.+)\"',
+                                "search" => qr/^bibfiles\s+\"(.+)\"/,
                                 "result" => ["bibfiles \"", "1", "\""]);
          my $rElem2 = newMatch("ext" => ".bst",
                                 "filetype" => "prefix_for_list",
-                                "search" => '^options\s+\"(.+)\"',
+                                "search" => qr/^options\s+\"(.+)\"/,
                                 "result" => ["options \"", "1", "\""]);
          setMatching([$rElem1, $rElem2]);
        }
       }
       elsif ($stack[0]->{name} =~ /^CommandInset\s+include$/) {
-       if ($param =~ /^(verbatiminput\*?|lstinputlisting)$/) {
-         my $rElem = newMatch("search" => '^filename\s+\"(.+)\"',
+       if ($param =~ /^(verbatiminput\*?|lstinputlisting|inputminted)$/) {
+         my $rElem = newMatch("search" => qr/^filename\s+\"(.+)\"/,
                                "filetype" => "copy_only",
                                "result" => ["filename \"", "", "\""]);
          setMatching([$rElem]);
        }
        elsif ($param =~ /^(include|input)$/) {
-         my $rElem = newMatch("search" => '^filename\s+\"(.+)\"',
+         my $rElem = newMatch("search" => qr/^filename\s+\"(.+)\"/,
                                "filetype" => "interpret",
                                "result" => ["filename \"", "", "\""]);
          setMatching([$rElem]);
@@ -336,7 +371,7 @@ sub checkLyxLine($)
     my $rMatch = getMatching();
     for my $m ( @{$rMatch}) {
       my $search = getSearch($m);
-      if ($l =~ /$search/) {
+      if ($l =~ $search) {
        my @matches = ($1, $2, $3, $4);
        my $filetype = getFileType($m);
        my @result2 = @{getResult($m)};