winapi_documentation.pm 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #
  2. # Copyright 1999, 2000, 2001 Patrik Stridvall
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public
  15. # License along with this library; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  17. #
  18. package winapi_documentation;
  19. use strict;
  20. use warnings 'all';
  21. use config qw($current_dir $wine_dir);
  22. use modules qw($modules);
  23. use nativeapi qw($nativeapi);
  24. use options qw($options);
  25. use output qw($output);
  26. use winapi qw($win16api $win32api @winapis);
  27. my %comment_width;
  28. my %comment_indent;
  29. my %comment_spacing;
  30. sub check_documentation($) {
  31. local $_;
  32. my $function = shift;
  33. my $file = $function->file;
  34. my $external_name16 = $function->external_name16;
  35. my $external_name32 = $function->external_name32;
  36. my $internal_name = $function->internal_name;
  37. my $module16 = $function->module16;
  38. my $module32 = $function->module32;
  39. my $ordinal16 = $function->ordinal16;
  40. my $ordinal32 = $function->ordinal32;
  41. my $documentation = $function->documentation;
  42. my $documentation_line = $function->documentation_line;
  43. my $documentation_error = 0;
  44. my $documentation_warning = 0;
  45. if($options->documentation_name ||
  46. $options->documentation_ordinal ||
  47. $options->documentation_pedantic)
  48. {
  49. my @winapis = ($win16api, $win32api);
  50. my @modules = ($module16, $module32);
  51. my @external_names = ($external_name16, $external_name32);
  52. my @ordinals = ($ordinal16, $ordinal32);
  53. while(
  54. defined(my $winapi = shift @winapis) &&
  55. defined(my $external_name = shift @external_names) &&
  56. defined(my $module = shift @modules) &&
  57. defined(my $ordinal = shift @ordinals))
  58. {
  59. if($winapi->is_function_stub_in_module($module, $internal_name)) { next; }
  60. my @external_name = split(/\s*\&\s*/, $external_name);
  61. my @modules = split(/\s*\&\s*/, $module);
  62. my @ordinals = split(/\s*\&\s*/, $ordinal);
  63. my $pedantic_failed = 0;
  64. while(defined(my $external_name = shift @external_name) &&
  65. defined(my $module = shift @modules) &&
  66. defined(my $ordinal = shift @ordinals))
  67. {
  68. my $found_name = 0;
  69. my $found_ordinal = 0;
  70. $module = "kernel" if $module eq "krnl386"; # FIXME: Kludge
  71. foreach (split(/\n/, $documentation)) {
  72. if(/^(\s*)\*(\s*)(\@|\S+)(\s*)([\(\[])(\w+(?:\.\w+)?)\.(\@|\d+)([\)\]])/) {
  73. my $external_name2 = $3;
  74. my $module2 = $6;
  75. my $ordinal2 = $7;
  76. if ($winapi->function_wine_extension(lc($module2), $external_name2)) {
  77. # $output->write("documentation: $external_name2 (\U$module2\E.$ordinal2) is a Wine extension \\\n$documentation\n");
  78. }
  79. if(length($1) != 1 || length($2) < 1 ||
  80. length($4) < 1 || $5 ne "(" || $8 ne ")")
  81. {
  82. $pedantic_failed = 1;
  83. }
  84. if($external_name eq $external_name2) {
  85. $found_name = 1;
  86. if("\U$module\E" eq $module2 &&
  87. $ordinal eq $ordinal2)
  88. {
  89. $found_ordinal = 1;
  90. }
  91. }
  92. }
  93. }
  94. if((($options->documentation_name && !$found_name) ||
  95. ($options->documentation_ordinal && !$found_ordinal)) &&
  96. !$winapi->is_function_stub($module, $external_name) &&
  97. !$winapi->function_wine_extension($module, $external_name))
  98. {
  99. $documentation_error = 1;
  100. $output->write("documentation: expected $external_name (\U$module\E.$ordinal): \\\n$documentation\n");
  101. }
  102. }
  103. if($options->documentation_pedantic && $pedantic_failed) {
  104. $documentation_warning = 1;
  105. $output->write("documentation: pedantic failed: \\\n$documentation\n");
  106. }
  107. }
  108. }
  109. if(!$documentation_error && $options->documentation_wrong) {
  110. foreach (split(/\n/, $documentation)) {
  111. if (/^\s*\*\s*(\S+)\s*[\(\[]\s*(\w+(?:\.(?:DRV|EXE|OCX|VXD))?)\s*\.\s*([^\s\)\]]*)\s*[\)\]].*?$/) {
  112. my $external_name = $1;
  113. my $module = $2;
  114. my $ordinal = $3;
  115. if ($ordinal eq "@") {
  116. # Nothing
  117. } elsif ($ordinal =~ /^\d+$/) {
  118. $ordinal = int($ordinal);
  119. } elsif ($ordinal eq "init") {
  120. $ordinal = 0;
  121. } else {
  122. $output->write("documentation: invalid ordinal for $external_name (\U$module\E.$ordinal)\n");
  123. next;
  124. }
  125. my $found = 0;
  126. foreach my $entry2 (winapi::get_all_module_internal_ordinal($internal_name)) {
  127. (my $external_name2, my $module2, my $ordinal2) = @$entry2;
  128. my $_module2 = $module2;
  129. $_module2 =~ s/\.(acm|dll|drv|exe|ocx)$//; # FIXME: Kludge
  130. $_module2 = "kernel" if $_module2 eq "krnl386"; # FIXME: Kludge
  131. if($external_name eq $external_name2 &&
  132. lc($module) eq $_module2 &&
  133. $ordinal eq $ordinal2 &&
  134. ($external_name2 eq "@" ||
  135. ($win16api->is_module($module2) && !$win16api->is_function_stub_in_module($module2, $external_name2)) ||
  136. ($win32api->is_module($module2) && !$win32api->is_function_stub_in_module($module2, $external_name2))) ||
  137. $modules->is_allowed_module_in_file($module2, "$current_dir/$file"))
  138. {
  139. $found = 1;
  140. last;
  141. }
  142. }
  143. if (!$found && $external_name ne "DllMain" && $ordinal ne "0") {
  144. $output->write("documentation: $external_name (\U$module\E.$ordinal) not declared in the spec file\n");
  145. }
  146. }
  147. }
  148. }
  149. if($options->documentation_comment_indent) {
  150. foreach (split(/\n/, $documentation)) {
  151. if(/^\s*\*(\s*)\S+(\s*)[\(\[]\s*\w+\s*\.\s*[^\s\)\]]*\s*[\)\]].*?$/) {
  152. my $indent = $1;
  153. my $spacing = $2;
  154. $indent =~ s/\t/ /g;
  155. $indent = length($indent);
  156. $spacing =~ s/\t/ /g;
  157. $spacing = length($spacing);
  158. $comment_indent{$indent}++;
  159. if($indent >= 20) {
  160. $output->write("documentation: comment indent is $indent\n");
  161. }
  162. $comment_spacing{$spacing}++;
  163. }
  164. }
  165. }
  166. if($options->documentation_comment_width) {
  167. if($documentation =~ /(^\/\*\*+)/) {
  168. my $width = length($1);
  169. $comment_width{$width}++;
  170. if($width <= 65 || $width >= 81) {
  171. $output->write("comment is $width columns wide\n");
  172. }
  173. }
  174. }
  175. if($options->documentation_arguments) {
  176. my $refargument_documentations = $function->argument_documentations;
  177. if(defined($refargument_documentations)) {
  178. my $n = 0;
  179. for my $argument_documentation (@$refargument_documentations) {
  180. $n++;
  181. if($argument_documentation ne "") {
  182. if($argument_documentation !~ /^\/\*\s+\[(?:in|out|in\/out|\?\?\?|I|O|I\/O)\].*?\*\/$/s) {
  183. $output->write("argument $n documentation: \\\n$argument_documentation\n");
  184. }
  185. }
  186. }
  187. }
  188. }
  189. }
  190. sub report_documentation() {
  191. if($options->documentation_comment_indent) {
  192. foreach my $indent (sort(keys(%comment_indent))) {
  193. my $count = $comment_indent{$indent};
  194. $output->write("*.c: $count functions have comment that is indented $indent\n");
  195. }
  196. }
  197. if($options->documentation_comment_width) {
  198. foreach my $width (sort(keys(%comment_width))) {
  199. my $count = $comment_width{$width};
  200. $output->write("*.c: $count functions have comments of width $width\n");
  201. }
  202. }
  203. }
  204. 1;