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 config qw($current_dir $wine_dir);
  21. use modules qw($modules);
  22. use nativeapi qw($nativeapi);
  23. use options qw($options);
  24. use output qw($output);
  25. use winapi qw($win16api $win32api @winapis);
  26. my %comment_width;
  27. my %comment_indent;
  28. my %comment_spacing;
  29. sub check_documentation($) {
  30. local $_;
  31. my $function = shift;
  32. my $file = $function->file;
  33. my $external_name16 = $function->external_name16;
  34. my $external_name32 = $function->external_name32;
  35. my $internal_name = $function->internal_name;
  36. my $module16 = $function->module16;
  37. my $module32 = $function->module32;
  38. my $ordinal16 = $function->ordinal16;
  39. my $ordinal32 = $function->ordinal32;
  40. my $documentation = $function->documentation;
  41. my $documentation_line = $function->documentation_line;
  42. my $documentation_error = 0;
  43. my $documentation_warning = 0;
  44. if($options->documentation_name ||
  45. $options->documentation_ordinal ||
  46. $options->documentation_pedantic)
  47. {
  48. my @winapis = ($win16api, $win32api);
  49. my @modules = ($module16, $module32);
  50. my @external_names = ($external_name16, $external_name32);
  51. my @ordinals = ($ordinal16, $ordinal32);
  52. while(
  53. defined(my $winapi = shift @winapis) &&
  54. defined(my $external_name = shift @external_names) &&
  55. defined(my $module = shift @modules) &&
  56. defined(my $ordinal = shift @ordinals))
  57. {
  58. if($winapi->is_function_stub_in_module($module, $internal_name)) { next; }
  59. my @external_name = split(/\s*\&\s*/, $external_name);
  60. my @modules = split(/\s*\&\s*/, $module);
  61. my @ordinals = split(/\s*\&\s*/, $ordinal);
  62. my $pedantic_failed = 0;
  63. while(defined(my $external_name = shift @external_name) &&
  64. defined(my $module = shift @modules) &&
  65. defined(my $ordinal = shift @ordinals))
  66. {
  67. my $found_name = 0;
  68. my $found_ordinal = 0;
  69. $module = "kernel" if $module eq "krnl386"; # FIXME: Kludge
  70. foreach (split(/\n/, $documentation)) {
  71. if(/^(\s*)\*(\s*)(\@|\S+)(\s*)([\(\[])(\w+(?:\.\w+)?)\.(\@|\d+)([\)\]])/) {
  72. my $external_name2 = $3;
  73. my $module2 = $6;
  74. my $ordinal2 = $7;
  75. if ($winapi->function_wine_extension(lc($module2), $external_name2)) {
  76. # $output->write("documentation: $external_name2 (\U$module2\E.$ordinal2) is a Wine extension \\\n$documentation\n");
  77. }
  78. if(length($1) != 1 || length($2) < 1 ||
  79. length($4) < 1 || $5 ne "(" || $8 ne ")")
  80. {
  81. $pedantic_failed = 1;
  82. }
  83. if($external_name eq $external_name2) {
  84. $found_name = 1;
  85. if("\U$module\E" eq $module2 &&
  86. $ordinal eq $ordinal2)
  87. {
  88. $found_ordinal = 1;
  89. }
  90. }
  91. }
  92. }
  93. if((($options->documentation_name && !$found_name) ||
  94. ($options->documentation_ordinal && !$found_ordinal)) &&
  95. !$winapi->is_function_stub($module, $external_name) &&
  96. !$winapi->function_wine_extension($module, $external_name))
  97. {
  98. $documentation_error = 1;
  99. $output->write("documentation: expected $external_name (\U$module\E.$ordinal): \\\n$documentation\n");
  100. }
  101. }
  102. if($options->documentation_pedantic && $pedantic_failed) {
  103. $documentation_warning = 1;
  104. $output->write("documentation: pedantic failed: \\\n$documentation\n");
  105. }
  106. }
  107. }
  108. if(!$documentation_error && $options->documentation_wrong) {
  109. foreach (split(/\n/, $documentation)) {
  110. if (/^\s*\*\s*(\S+)\s*[\(\[]\s*(\w+(?:\.(?:DRV|EXE|OCX|VXD))?)\s*\.\s*([^\s\)\]]*)\s*[\)\]].*?$/) {
  111. my $external_name = $1;
  112. my $module = $2;
  113. my $ordinal = $3;
  114. if ($ordinal eq "@") {
  115. # Nothing
  116. } elsif ($ordinal =~ /^\d+$/) {
  117. $ordinal = int($ordinal);
  118. } elsif ($ordinal eq "init") {
  119. $ordinal = 0;
  120. } else {
  121. $output->write("documentation: invalid ordinal for $external_name (\U$module\E.$ordinal)\n");
  122. next;
  123. }
  124. my $found = 0;
  125. foreach my $entry2 (winapi::get_all_module_internal_ordinal($internal_name)) {
  126. (my $external_name2, my $module2, my $ordinal2) = @$entry2;
  127. my $_module2 = $module2;
  128. $_module2 =~ s/\.(acm|dll|drv|exe|ocx)$//; # FIXME: Kludge
  129. $_module2 = "kernel" if $_module2 eq "krnl386"; # FIXME: Kludge
  130. if($external_name eq $external_name2 &&
  131. lc($module) eq $_module2 &&
  132. $ordinal eq $ordinal2 &&
  133. ($external_name2 eq "@" ||
  134. ($win16api->is_module($module2) && !$win16api->is_function_stub_in_module($module2, $external_name2)) ||
  135. ($win32api->is_module($module2) && !$win32api->is_function_stub_in_module($module2, $external_name2))) ||
  136. $modules->is_allowed_module_in_file($module2, "$current_dir/$file"))
  137. {
  138. $found = 1;
  139. last;
  140. }
  141. }
  142. if (!$found && $external_name ne "DllMain" && $ordinal ne "0") {
  143. $output->write("documentation: $external_name (\U$module\E.$ordinal) not declared in the spec file\n");
  144. }
  145. }
  146. }
  147. }
  148. if($options->documentation_comment_indent) {
  149. foreach (split(/\n/, $documentation)) {
  150. if(/^\s*\*(\s*)\S+(\s*)[\(\[]\s*\w+\s*\.\s*[^\s\)\]]*\s*[\)\]].*?$/) {
  151. my $indent = $1;
  152. my $spacing = $2;
  153. $indent =~ s/\t/ /g;
  154. $indent = length($indent);
  155. $spacing =~ s/\t/ /g;
  156. $spacing = length($spacing);
  157. $comment_indent{$indent}++;
  158. if($indent >= 20) {
  159. $output->write("documentation: comment indent is $indent\n");
  160. }
  161. $comment_spacing{$spacing}++;
  162. }
  163. }
  164. }
  165. if($options->documentation_comment_width) {
  166. if($documentation =~ /(^\/\*\*+)/) {
  167. my $width = length($1);
  168. $comment_width{$width}++;
  169. if($width <= 65 || $width >= 81) {
  170. $output->write("comment is $width columns wide\n");
  171. }
  172. }
  173. }
  174. if($options->documentation_arguments) {
  175. my $refargument_documentations = $function->argument_documentations;
  176. if(defined($refargument_documentations)) {
  177. my $n = 0;
  178. for my $argument_documentation (@$refargument_documentations) {
  179. $n++;
  180. if($argument_documentation ne "") {
  181. if($argument_documentation !~ /^\/\*\s+\[(?:in|out|in\/out|\?\?\?|I|O|I\/O)\].*?\*\/$/s) {
  182. $output->write("argument $n documentation: \\\n$argument_documentation\n");
  183. }
  184. }
  185. }
  186. }
  187. }
  188. }
  189. sub report_documentation() {
  190. if($options->documentation_comment_indent) {
  191. foreach my $indent (sort(keys(%comment_indent))) {
  192. my $count = $comment_indent{$indent};
  193. $output->write("*.c: $count functions have comment that is indented $indent\n");
  194. }
  195. }
  196. if($options->documentation_comment_width) {
  197. foreach my $width (sort(keys(%comment_width))) {
  198. my $count = $comment_width{$width};
  199. $output->write("*.c: $count functions have comments of width $width\n");
  200. }
  201. }
  202. }
  203. 1;