txivarcheck 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env perl
  2. # $Id$
  3. # Copyright 2012, 2013, 2016 Free Software Foundation, Inc.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3 of the License,
  8. # or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # Original author: Karl Berry.
  19. #
  20. # Kludge of a script to check customization variables in refman vs. tp
  21. # for consistency. Although this has nothing to do with the reference
  22. # card, since it's similar to the txicmdcheck script, keep them
  23. # together. And maybe we'll add the cust.vars to the refcard.
  24. exit (&main ());
  25. sub main {
  26. my $no_common = $ARGV[0] eq "--no-common";
  27. my @man_vars = &read_refman ("../texinfo.texi");
  28. my @tp_vars = &read_tp ("../../util/txicustomvars");
  29. my (%man_vars, %tp_vars); # list to hash
  30. @man_vars{@man_vars} = ();
  31. @tp_vars{@tp_vars} = ();
  32. my @found = ();
  33. for my $name (@tp_vars) {
  34. if (exists $man_vars{$name}) {
  35. push (@found, $name);
  36. delete $man_vars{$name};
  37. delete $tp_vars{$name};
  38. }
  39. }
  40. printf ("common %3d: @{[sort @found]}\n", @found + 0)
  41. unless $no_common;
  42. # we can't reasonly reduce the list of variable names only in the
  43. # manual to null, since the manual necessarily includes many non-variables.
  44. #
  45. my @man_only = keys %man_vars;
  46. printf "man only %2s: @{[sort @man_only]}\n", @man_only + 0;
  47. my @tp_only = keys %tp_vars;
  48. printf "tp only %2s: @{[sort @tp_only]}\n", @tp_only + 0;
  49. return @tp_only;
  50. }
  51. # Return customization variable names from the section in the reference
  52. # manual. We assume their names are all uppercase, to avoid returning
  53. # numerous non-variables.
  54. #
  55. sub read_refman {
  56. my ($fname) = @_;
  57. my @ret = ();
  58. local *FILE;
  59. $FILE = $fname;
  60. open (FILE) || die "open($FILE) failed: $!";
  61. # since we have to look at generic commands like @item, at least
  62. # ignore until right section to reduce chance of false matches.
  63. while (<FILE>) {
  64. last if /^\@section Customization Variables$/;
  65. }
  66. while (<FILE>) {
  67. if (/^\@node Customization Variables for \@\@/) {
  68. # in this node we have a bare of bare @-commands which have cust.vars.
  69. while (<FILE>) {
  70. last if /^\@smallexample/;
  71. }
  72. my $atcmds = "";
  73. while (<FILE>) {
  74. last if /^\@end smallexample/;
  75. s/\@\@//g; # the variable names don't start with @
  76. $atcmds .= $_;
  77. }
  78. # done with special node.
  79. my @atcmds = split (" ", $atcmds);
  80. push (@ret, @atcmds);
  81. next;
  82. }
  83. # Stop looking for cust.var names after those nodes are done.
  84. last if /^\@node Internationalization of Document Strings/;
  85. # Otherwise, we're looking at a line in one of the cust.var
  86. # documentation nodes.
  87. next unless s/^\@(itemx?|vindex) *//; # look for item[x]s and vindex
  88. next unless /^[A-Z0-9_]+$/; # uppercase only
  89. chomp;
  90. push (@ret, $_);
  91. }
  92. close (FILE) || warn "close($FILE) failed: $!";
  93. return @ret;
  94. }
  95. # Return customization variable names implemented in the general parser.
  96. # The argument is the command to run which returns the list.
  97. #
  98. sub read_tp {
  99. my ($prog) = @_;
  100. my @ret = ();
  101. local *FILE;
  102. $FILE = "$prog |";
  103. open (FILE) || die "open($FILE) failed: $!";
  104. while (<FILE>) {
  105. chomp;
  106. my ($var,$where) = split (/\t/);
  107. next if ($where eq 'variable_other_settables'
  108. || $where eq 'parser_options');
  109. next if $var eq "OUTPUT_PERL_ENCODING"; # not for users
  110. next if $var eq "HTMLXREF"; # not documented
  111. # these are documented, but their lowercase names don't match
  112. # everything
  113. #next if $var =~ /^(even|every|odd)(heading|footing)$/;
  114. push (@ret, $var);
  115. }
  116. close (FILE) || warn "close($FILE) failed: $!";
  117. return @ret;
  118. }