]> git.lyx.org Git - lyx.git/blobdiff - development/tools/GetOptions.pm
Adjust bookmark position when inserting/deleting from paragraph
[lyx.git] / development / tools / GetOptions.pm
index 81be0e55a44ea5c3323ad04bcb6bd40ddf80b190..3141ee18bd2499bf67cb4256ceaaf544a2778019 100644 (file)
@@ -47,15 +47,27 @@ sub makeHelp();            # Create help-string to describe options
 
 my %optionsDef = ();
 #option|param|type|aliases|comment
-my $helpFormat = "  %-8s|%-9s|%-7s|%-17s|%s\n";
+my $helpFormat = "  %-8.8s|%-9.9s|%-7.7s|%-17.17s|%s\n";
 
 sub handleOptions($)
 {
-  %optionsDef = %{$_[0]};
+  if (ref($_[0]) eq "ARRAY") {
+    for (my $i = 0; defined($_[0]->[$i]); $i++) {
+      my $rO = $_[0]->[$i];
+      $optionsDef{$rO->[0]} = $rO->[1];
+      $optionsDef{$rO->[0]}->{Sort} = $i+2;
+    }
+  }
+  else {
+    %optionsDef = %{$_[0]};
+  }
   $optionsDef{h}->{fieldname} = "help";
   $optionsDef{h}->{alias} = ["help"];
+  $optionsDef{h}->{Sort} = 0;
   $optionsDef{v}->{fieldname} = "verbose";
   $optionsDef{v}->{alias} = ["verbose"];
+  $optionsDef{v}->{comment} = "Display recognized params";
+  $optionsDef{v}->{Sort} = 1;
 
   my %options = ("help" => 0);
   my $opts = &makeOpts();
@@ -64,6 +76,20 @@ sub handleOptions($)
   while( my( $option, $value, $pretty ) = Getopt::Mixed::nextOption()) {
     if (defined($optionsDef{$option})) {
       my $fieldname = $optionsDef{$option}->{fieldname};
+      if (exists($options{$fieldname}) && ($option ne "h")) {
+       print "Option $option already set\n";
+        if (defined($options{$fieldname})) {
+          print "Value \"$value\" would overwrite ";
+          if (ref($options{$fieldname}) eq "ARRAY") {
+            print "\"" . join(',', @{$options{$fieldname}}) . "\"\n";
+          }
+          else {
+            print "\"$options{$fieldname}\"\n";
+          }
+        }
+       $option = "h";
+       $fieldname = "help";
+      }
       if ($option eq "h") {
         print "Syntax: $0 options xxxx ...\n";
         print "Available options:\n";
@@ -75,7 +101,7 @@ sub handleOptions($)
       }
       else {
         if (defined($optionsDef{$option}->{listsep})) {
-          my @list = split($optionsDef{$option}->{listsep}, $value);
+          my @list = split(/(?<!\\)$optionsDef{$option}->{listsep}/, $value);
           $options{$fieldname} = \@list;
         }
         else {
@@ -91,7 +117,14 @@ sub handleOptions($)
     print "    " . "-" x 32 . "\n";
     for my $k (sort keys %options) {
       if (defined($options{$k})) {
-        printf("    %-16s%s\n", $k, $options{$k});
+        my $val;
+        if (ref($options{$k}) eq "ARRAY") {
+          $val = join(',', @{$options{$k}});
+        }
+        else {
+          $val = $options{$k};
+        }
+        printf("    %-16s%s\n", $k, $val);
       }
       else {
         print "    $k\n";
@@ -131,6 +164,22 @@ sub makeOpts()
   return($opts);
 }
 
+sub sortHelp
+{
+  if (defined($optionsDef{$a}->{Sort})) {
+    if (defined($optionsDef{$b}->{Sort})) {
+      return $optionsDef{$a}->{Sort} <=> $optionsDef{$b}->{Sort};
+    }
+    return -1;
+  }
+  if (defined($optionsDef{$b}->{Sort})) {
+    return 1;
+  }
+  else {
+    return $a cmp $b;
+  }
+}
+
 # Create help-string to describe options
 sub makeHelp()
 {
@@ -142,7 +191,7 @@ sub makeHelp()
     "i" => "integer",
     "f" => "float",
       );
-  for my $ex (sort keys %optionsDef) {
+  for my $ex (sort sortHelp keys %optionsDef) {
     my $e = $optionsDef{$ex};
     my $type = "";
     my $needed = "";
@@ -167,6 +216,10 @@ sub makeHelp()
       $comment = $e->{comment};
     }
     $opts .= sprintf($helpFormat, $ex, $needed, $partype, $aliases, $comment);
+    if (defined($e->{comment2})) {
+      my $fill = "_" x 20;
+      $opts .= sprintf($helpFormat, $fill, $fill, $fill, $fill, $e->{comment2});
+    }
   }
   return($opts);
 }