2
0

test1544.pl 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. # SPDX-License-Identifier: curl
  23. #
  24. #
  25. ###########################################################################
  26. #
  27. # Check the OS/400 translating wrapper properly handles all translatable
  28. # string options.
  29. use strict;
  30. use warnings;
  31. my $root=$ARGV[0] || ".";
  32. my $incdir = "$root/include/curl";
  33. my $os400dir = "$root/packages/OS400";
  34. my $errcount = 0;
  35. # Scan header file for string option definitions.
  36. sub scan_header {
  37. my ($f)=@_;
  38. my $line = "";
  39. my $incomment = 0;
  40. my @stringopts;
  41. open(my $h, "<", "$f");
  42. while(<$h>) {
  43. s/^\s*(.*?)\s*$/$1/; # Trim.
  44. # Remove multi-line comment trail.
  45. if($incomment) {
  46. if($_ !~ /.*?\*\/\s*(.*)$/) {
  47. next;
  48. }
  49. $_ = $1;
  50. $incomment = 0;
  51. }
  52. if($line ne "") {
  53. # Unfold line.
  54. $_ = "$line $1";
  55. $line = "";
  56. }
  57. if($_ =~ /^(.*)\\$/) {
  58. $line = "$1 ";
  59. next;
  60. }
  61. # Remove comments.
  62. while($_ =~ /^(.*?)\/\*.*?\*\/(.*)$/) {
  63. $_ = "$1 $2";
  64. }
  65. if($_ =~ /^(.*)\/\*/) {
  66. $_ = "$1 ";
  67. $incomment = 1;
  68. }
  69. s/^\s*(.*?)\s*$/$1/; # Trim again.
  70. # Ignore preprocessor directives and blank lines.
  71. if($_ =~ /^(?:#|$)/) {
  72. next;
  73. }
  74. # Handle lines that may be continued as if they were folded.
  75. if($_ !~ /[;,{}]$/ || $_ =~ /[^)],$/) {
  76. # Folded line.
  77. $line = $_;
  78. next;
  79. }
  80. # Keep string options only.
  81. if($_ =~ /CURLOPT(?:DEPRECATED)?\s*\(\s*([^, \t]+)\s*,\s*CURLOPTTYPE_STRINGPOINT/) {
  82. push(@stringopts, $1);
  83. }
  84. }
  85. close $h;
  86. return @stringopts;
  87. }
  88. # Scan packages/OS400/ccsidcurl.c for translatable string option cases.
  89. sub scan_wrapper_for_strings {
  90. my ($f)=@_;
  91. my $inarmor = 0;
  92. my @stringopts;
  93. open(my $h, "<", "$f");
  94. while(<$h>) {
  95. if($_ =~ /(BEGIN|END) TRANSLATABLE STRING OPTIONS/) {
  96. $inarmor = $1 eq "BEGIN";
  97. }
  98. elsif($inarmor && $_ =~ /case\s+([^:]+):/) {
  99. push(@stringopts, $1);
  100. }
  101. }
  102. close $h;
  103. return @stringopts;
  104. }
  105. # Get translatable string options from header file.
  106. my @stringdefs = scan_header("$incdir/curl.h");
  107. # Get translated string options.
  108. my @stringrefs = scan_wrapper_for_strings("$os400dir/ccsidcurl.c");
  109. # Lists should be equal: check differences.
  110. my %diff;
  111. @diff{@stringdefs} = 0..$#stringdefs;
  112. delete @diff{@stringrefs};
  113. foreach(keys %diff) {
  114. print "$_ is not translated\n";
  115. delete $diff{$_};
  116. $errcount++;
  117. }
  118. @diff{@stringrefs} = 0..$#stringrefs;
  119. delete @diff{@stringdefs};
  120. foreach(keys %diff) {
  121. print "translated option $_ does not exist\n";
  122. $errcount++;
  123. }
  124. # Check translated string option cases are sorted alphanumerically.
  125. foreach(my $i = 1; $i < $#stringrefs; $i++) {
  126. if($stringrefs[$i] lt $stringrefs[$i - 1]) {
  127. print("Translated string options are not sorted (" . $stringrefs[$i - 1] .
  128. "/" . $stringrefs[$i] . ")\n");
  129. $errcount++;
  130. last;
  131. }
  132. }
  133. exit !!$errcount;