forked from wine-mirror/wine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc2man.pl
executable file
·2380 lines (2171 loc) · 67.8 KB
/
c2man.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/perl -w
#
# Generate API documentation. See https://www.winehq.org/docs/winedev-guide/api-docs for details.
#
# Copyright (C) 2000 Mike McCormack
# Copyright (C) 2003 Jon Griffiths
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
# TODO
# Consolidate A+W pairs together, and only write one doc, without the suffix
# Implement automatic docs of structs/defines in headers
# SGML gurus - feel free to smarten up the SGML.
# Add any other relevant information for the dll - imports etc
# Should we have a special output mode for WineHQ?
use strict;
use bytes;
# Function flags. most of these come from the spec flags
my $FLAG_DOCUMENTED = 1;
my $FLAG_NONAME = 2;
my $FLAG_I386 = 4;
my $FLAG_REGISTER = 8;
my $FLAG_APAIR = 16; # The A version of a matching W function
my $FLAG_WPAIR = 32; # The W version of a matching A function
my $FLAG_64PAIR = 64; # The 64 bit version of a matching 32 bit function
# Export list slot labels.
my $EXPORT_ORDINAL = 0; # Ordinal.
my $EXPORT_CALL = 1; # Call type.
my $EXPORT_EXPNAME = 2; # Export name.
my $EXPORT_IMPNAME = 3; # Implementation name.
my $EXPORT_FLAGS = 4; # Flags - see above.
# Options
my $opt_output_directory = "man3w"; # All default options are for nroff (man pages)
my $opt_manual_section = "3w";
my $opt_source_dir = ".";
my $opt_parent_dir = "";
my $opt_wine_root_dir = "";
my $opt_output_format = ""; # '' = nroff, 'h' = html, 's' = sgml, 'x' = xml
my $opt_output_empty = 0; # Non-zero = Create 'empty' comments (for every implemented function)
my $opt_fussy = 1; # Non-zero = Create only if we have a RETURNS section
my $opt_verbose = 0; # >0 = verbosity. Can be given multiple times (for debugging)
my @opt_header_file_list = ();
my @opt_spec_file_list = ();
my @opt_source_file_list = ();
# All the collected details about all the .spec files being processed
my %spec_files;
# All the collected details about all the source files being processed
my %source_files;
# All documented functions that are to be placed in the index
my @index_entries_list = ();
# useful globals
my $pwd = `pwd`."/";
$pwd =~ s/\n//;
my @datetime = localtime;
my @months = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
my $year = $datetime[5] + 1900;
my $date = "$months[$datetime[4]] $year";
sub output_api_comment($);
sub output_api_footer($);
sub output_api_header($);
sub output_api_name($);
sub output_api_synopsis($);
sub output_close_api_file();
sub output_comment($);
sub output_html_index_files();
sub output_html_stylesheet();
sub output_open_api_file($);
sub output_sgml_dll_file($);
sub output_xml_dll_file($);
sub output_sgml_master_file($);
sub output_xml_master_file($);
sub output_spec($);
sub process_comment($);
sub process_extra_comment($);
# Generate the list of exported entries for the dll
sub process_spec_file($)
{
my $spec_name = shift;
(my $basename = $spec_name) =~ s/.*\///;
my ($dll_name, $dll_ext) = split(/\./, $basename);
$dll_ext = "dll" if ( $dll_ext eq "spec" );
my $uc_dll_name = uc $dll_name;
my $spec_details =
{
NAME => $basename,
DLL_NAME => $dll_name,
DLL_EXT => $dll_ext,
NUM_EXPORTS => 0,
NUM_STUBS => 0,
NUM_FUNCS => 0,
NUM_FORWARDS => 0,
NUM_VARS => 0,
NUM_DOCS => 0,
CONTRIBUTORS => [ ],
SOURCES => [ ],
DESCRIPTION => [ ],
EXPORTS => [ ],
EXPORTED_NAMES => { },
IMPLEMENTATION_NAMES => { },
EXTRA_COMMENTS => [ ],
CURRENT_EXTRA => [ ] ,
};
if ($opt_verbose > 0)
{
print "Processing ".$spec_name."\n";
}
# We allow opening to fail just to cater for the peculiarities of
# the Wine build system. This doesn't hurt, in any case
open(SPEC_FILE, "<$spec_name")
|| (($opt_source_dir ne "")
&& open(SPEC_FILE, "<$opt_source_dir/$spec_name"))
|| return;
while(<SPEC_FILE>)
{
s/^\s+//; # Strip leading space
s/\s+\n$/\n/; # Strip trailing space
s/\s+/ /g; # Strip multiple tabs & spaces to a single space
s/\s*#.*//; # Strip comments
s/\(.*\)/ /; # Strip arguments
s/\s+/ /g; # Strip multiple tabs & spaces to a single space (again)
s/\n$//; # Strip newline
my $flags = 0;
if( /\-noname/ )
{
$flags |= $FLAG_NONAME;
}
if( /\-i386/ )
{
$flags |= $FLAG_I386;
}
if( /\-register/ )
{
$flags |= $FLAG_REGISTER;
}
s/ \-[a-z0-9=_]+//g; # Strip flags
if( /^(([0-9]+)|@) / )
{
# This line contains an exported symbol
my ($ordinal, $call_convention, $exported_name, $implementation_name) = split(' ');
for ($call_convention)
{
/^(cdecl|stdcall|varargs|pascal)$/
&& do { $spec_details->{NUM_FUNCS}++; last; };
/^(variable|equate)$/
&& do { $spec_details->{NUM_VARS}++; last; };
/^(extern)$/
&& do { $spec_details->{NUM_FORWARDS}++; last; };
/^stub$/ && do { $spec_details->{NUM_STUBS}++; last; };
if ($opt_verbose > 0)
{
print "Warning: didn't recognise convention \'",$call_convention,"'\n";
}
last;
}
# Convert ordinal only names so we can find them later
if ($exported_name eq "@")
{
$exported_name = $uc_dll_name.'_'.$ordinal;
}
if (!defined($implementation_name))
{
$implementation_name = $exported_name;
}
if ($implementation_name eq "")
{
$implementation_name = $exported_name;
}
if ($implementation_name =~ /(.*?)\./)
{
$call_convention = "forward"; # Referencing a function from another dll
$spec_details->{NUM_FUNCS}--;
$spec_details->{NUM_FORWARDS}++;
}
# Add indices for the exported and implementation names
$spec_details->{EXPORTED_NAMES}{$exported_name} = $spec_details->{NUM_EXPORTS};
if ($implementation_name ne $exported_name)
{
$spec_details->{IMPLEMENTATION_NAMES}{$exported_name} = $spec_details->{NUM_EXPORTS};
}
# Add the exported entry
$spec_details->{NUM_EXPORTS}++;
my @export = ($ordinal, $call_convention, $exported_name, $implementation_name, $flags);
push (@{$spec_details->{EXPORTS}},[@export]);
}
}
close(SPEC_FILE);
# Add this .spec files details to the list of .spec files
$spec_files{$uc_dll_name} = [$spec_details];
}
# Read each source file, extract comments, and generate API documentation if appropriate
sub process_source_file($)
{
my $source_file = shift;
my $source_details =
{
CONTRIBUTORS => [ ],
DEBUG_CHANNEL => "",
};
my $comment =
{
FILE => $source_file,
COMMENT_NAME => "",
ALT_NAME => "",
DLL_NAME => "",
DLL_EXT => "",
ORDINAL => "",
RETURNS => "",
PROTOTYPE => [],
TEXT => [],
};
my $parse_state = 0;
my $ignore_blank_lines = 1;
my $extra_comment = 0; # 1 if this is an extra comment, i.e it's not a .spec export
if ($opt_verbose > 0)
{
print "Processing ".$source_file."\n";
}
open(SOURCE_FILE,"<$source_file")
|| (($opt_source_dir ne ".")
&& open(SOURCE_FILE,"<$opt_source_dir/$source_file"))
|| (($opt_parent_dir ne "")
&& open(SOURCE_FILE,"<$opt_source_dir/$opt_parent_dir/$source_file"))
|| die "couldn't open ".$source_file."\n";
# Add this source file to the list of source files
$source_files{$source_file} = [$source_details];
while(<SOURCE_FILE>)
{
s/\n$//; # Strip newline
s/^\s+//; # Strip leading space
s/\s+$//; # Strip trailing space
if (! /^\*\|/ )
{
# Strip multiple tabs & spaces to a single space
s/\s+/ /g;
}
if ( / +Copyright *(\([Cc]\))*[0-9 \-\,\/]*([[:alpha:][:^ascii:] \.\-]+)/ )
{
# Extract a contributor to this file
my $contributor = $2;
$contributor =~ s/ *$//;
$contributor =~ s/^by //;
$contributor =~ s/\.$//;
$contributor =~ s/ (for .*)/ \($1\)/;
if ($contributor ne "")
{
if ($opt_verbose > 3)
{
print "Info: Found contributor:'".$contributor."'\n";
}
push (@{$source_details->{CONTRIBUTORS}},$contributor);
}
}
elsif ( /WINE_DEFAULT_DEBUG_CHANNEL\(([A-Za-z]*)\)/ )
{
# Extract the debug channel to use
if ($opt_verbose > 3)
{
print "Info: Found debug channel:'".$1."'\n";
}
$source_details->{DEBUG_CHANNEL} = $1;
}
if ($parse_state == 0) # Searching for a comment
{
if ( /^\/\**$/ )
{
# This file is used by the DLL - Make sure we get our contributors right
@{$spec_files{$comment->{DLL_NAME}}[0]->{CURRENT_EXTRA}} = ();
push (@{$spec_files{$comment->{DLL_NAME}}[0]->{SOURCES}},$comment->{FILE});
# Found a comment start
$comment->{COMMENT_NAME} = "";
$comment->{ALT_NAME} = "";
$comment->{DLL_NAME} = "";
$comment->{ORDINAL} = "";
$comment->{RETURNS} = "";
$comment->{PROTOTYPE} = [];
$comment->{TEXT} = [];
$ignore_blank_lines = 1;
$extra_comment = 0;
$parse_state = 3;
}
}
elsif ($parse_state == 1) # Reading in a comment
{
if ( /^\**\// )
{
# Found the end of the comment
$parse_state = 2;
}
elsif ( s/^\*\|/\|/ )
{
# A line of comment not meant to be pre-processed
push (@{$comment->{TEXT}},$_); # Add the comment text
}
elsif ( s/^ *\** *// )
{
# A line of comment, starting with an asterisk
if ( /^[A-Z]+$/ || $_ eq "")
{
# This is a section start, so skip blank lines before and after it.
my $last_line = pop(@{$comment->{TEXT}});
if (defined($last_line) && $last_line ne "")
{
# Put it back
push (@{$comment->{TEXT}},$last_line);
}
if ( /^[A-Z]+$/ )
{
$ignore_blank_lines = 1;
}
else
{
$ignore_blank_lines = 0;
}
}
if ($ignore_blank_lines == 0 || $_ ne "")
{
push (@{$comment->{TEXT}},$_); # Add the comment text
}
}
else
{
# This isn't a well formatted comment: look for the next one
$parse_state = 0;
}
}
elsif ($parse_state == 2) # Finished reading in a comment
{
if ( /(WINAPIV|WINAPI|__cdecl|PASCAL|CALLBACK|FARPROC16)/ ||
/.*?\(/ )
{
# Comment is followed by a function definition
$parse_state = 4; # Fall through to read prototype
}
else
{
# Allow cpp directives and blank lines between the comment and prototype
if ($extra_comment == 1)
{
# An extra comment not followed by a function definition
$parse_state = 5; # Fall through to process comment
}
elsif (!/^\#/ && !/^ *$/ && !/^__ASM_GLOBAL_FUNC/)
{
# This isn't a well formatted comment: look for the next one
if ($opt_verbose > 1)
{
print "Info: Function '",$comment->{COMMENT_NAME},"' not followed by prototype.\n";
}
$parse_state = 0;
}
}
}
elsif ($parse_state == 3) # Reading in the first line of a comment
{
s/^ *\** *//;
if ( /^([\@A-Za-z0-9_]+) +(\(|\[)([A-Za-z0-9_]+)\.(([0-9]+)|@)(\)|\])\s*(.*)$/ )
{
# Found a correctly formed "ApiName (DLLNAME.Ordinal)" line.
if (defined ($7) && $7 ne "")
{
push (@{$comment->{TEXT}},$_); # Add the trailing comment text
}
$comment->{COMMENT_NAME} = $1;
$comment->{DLL_NAME} = uc $3;
$comment->{ORDINAL} = $4;
$comment->{DLL_NAME} =~ s/^KERNEL$/KRNL386/; # Too many of these to ignore, _old_ code
$parse_state = 1;
}
elsif ( /^([A-Za-z0-9_-]+) +\{([A-Za-z0-9_]+)\}$/ )
{
# Found a correctly formed "CommentTitle {DLLNAME}" line (extra documentation)
$comment->{COMMENT_NAME} = $1;
$comment->{DLL_NAME} = uc $2;
$comment->{ORDINAL} = "";
$extra_comment = 1;
$parse_state = 1;
}
else
{
# This isn't a well formatted comment: look for the next one
$parse_state = 0;
}
}
if ($parse_state == 4) # Reading in the function definition
{
push (@{$comment->{PROTOTYPE}},$_);
# Strip comments from the line before checking for ')'
my $stripped_line = $_;
$stripped_line =~ s/ *(\/\* *)(.*?)( *\*\/ *)//;
if ( $stripped_line =~ /\)/ )
{
# Strip a blank last line
my $last_line = pop(@{$comment->{TEXT}});
if (defined($last_line) && $last_line ne "")
{
# Put it back
push (@{$comment->{TEXT}},$last_line);
}
if ($opt_output_empty != 0 && @{$comment->{TEXT}} == 0)
{
# Create a 'not implemented' comment
@{$comment->{TEXT}} = ("fixme: This function has not yet been documented.");
}
$parse_state = 5;
}
}
if ($parse_state == 5) # Processing the comment
{
# Process it, if it has any text
if (@{$comment->{TEXT}} > 0)
{
if ($extra_comment == 1)
{
process_extra_comment($comment);
}
else
{
@{$comment->{TEXT}} = ("DESCRIPTION", @{$comment->{TEXT}});
process_comment($comment);
}
}
elsif ($opt_verbose > 1 && $opt_output_empty == 0)
{
print "Info: Function '",$comment->{COMMENT_NAME},"' has no documentation.\n";
}
$parse_state = 0;
}
}
close(SOURCE_FILE);
}
# Standardise a comments text for consistency
sub process_comment_text($)
{
my $comment = shift;
my $in_params = 0;
my @tmp_list = ();
my $i = 0;
for (@{$comment->{TEXT}})
{
my $line = $_;
if ( /^\s*$/ || /^[A-Z]+$/ || /^-/ )
{
$in_params = 0;
}
if ( $in_params > 0 && !/\[/ && !/\]/ )
{
# Possibly a continuation of the parameter description
my $last_line = pop(@tmp_list);
if ( $last_line =~ /\[/ && $last_line =~ /\]/ )
{
$line = $last_line." ".$_;
}
else
{
$in_params = 0;
push (@tmp_list, $last_line);
}
}
if ( /^(PARAMS|MEMBERS)$/ )
{
$in_params = 1;
}
push (@tmp_list, $line);
}
@{$comment->{TEXT}} = @tmp_list;
for (@{$comment->{TEXT}})
{
if (! /^\|/ )
{
# Map I/O values. These come in too many formats to standardise now....
s/\[I\]|\[i\]|\[in\]|\[IN\]/\[In\] /g;
s/\[O\]|\[o\]|\[out\]|\[OUT\]/\[Out\]/g;
s/\[I\/O\]|\[I\,O\]|\[i\/o\]|\[in\/out\]|\[IN\/OUT\]/\[In\/Out\]/g;
# TRUE/FALSE/NULL are defines, capitalise them
s/True|true/TRUE/g;
s/False|false/FALSE/g;
s/Null|null/NULL/g;
# Preferred capitalisations
s/ wine| WINE/ Wine/g;
s/ API | api / Api /g;
s/ DLL | Dll / dll /g;
s/ URL | url / Url /g;
s/WIN16|win16/Win16/g;
s/WIN32|win32/Win32/g;
s/WIN64|win64/Win64/g;
s/ ID | id / Id /g;
# Grammar
s/([a-z])\.([A-Z])/$1\. $2/g; # Space after full stop
s/ \:/\:/g; # Colons to the left
s/ \;/\;/g; # Semi-colons too
# Common idioms
s/^See ([A-Za-z0-9_]+)\.$/See $1\(\)\./; # Referring to A version from W
s/^Unicode version of ([A-Za-z0-9_]+)\.$/See $1\(\)\./; # Ditto
s/^64\-bit version of ([A-Za-z0-9_]+)\.$/See $1\(\)\./; # Referring to 32 bit version from 64
s/^PARAMETERS$/PARAMS/; # Name of parameter section should be 'PARAMS'
# Trademarks
s/( |\.)(M\$|MS|Microsoft|microsoft|micro\$oft|Micro\$oft)( |\.)/$1Microsoft\(tm\)$3/g;
s/( |\.)(Windows|windows|windoze|winblows)( |\.)/$1Windows\(tm\)$3/g;
s/( |\.)(DOS|dos|msdos)( |\.)/$1MS-DOS\(tm\)$3/g;
s/( |\.)(UNIX|unix)( |\.)/$1Unix\(tm\)$3/g;
s/( |\.)(LINIX|linux)( |\.)/$1Linux\(tm\)$3/g;
# Abbreviations
s/( char )/ character /g;
s/( chars )/ characters /g;
s/( info )/ information /g;
s/( app )/ application /g;
s/( apps )/ applications /g;
s/( exe )/ executable /g;
s/( ptr )/ pointer /g;
s/( obj )/ object /g;
s/( err )/ error /g;
s/( bool )/ boolean /g;
s/( no\. )/ number /g;
s/( No\. )/ Number /g;
# Punctuation
if ( /\[I|\[O/ && ! /\.$/ )
{
$_ = $_."."; # Always have a full stop at the end of parameter desc.
}
elsif ($i > 0 && /^[A-Z]*$/ &&
!(@{$comment->{TEXT}}[$i-1] =~ /\.$/) &&
!(@{$comment->{TEXT}}[$i-1] =~ /\:$/))
{
if (!(@{$comment->{TEXT}}[$i-1] =~ /^[A-Z]*$/))
{
# Paragraphs always end with a full stop
@{$comment->{TEXT}}[$i-1] = @{$comment->{TEXT}}[$i-1].".";
}
}
}
$i++;
}
}
# Standardise our comment and output it if it is suitable.
sub process_comment($)
{
my $comment = shift;
# Don't process this comment if the function isn't exported
my $spec_details = $spec_files{$comment->{DLL_NAME}}[0];
if (!defined($spec_details))
{
if ($opt_verbose > 2)
{
print "Warning: Function '".$comment->{COMMENT_NAME}."' belongs to '".
$comment->{DLL_NAME}."' (not passed with -w): not processing it.\n";
}
return;
}
if ($comment->{COMMENT_NAME} eq "@")
{
my $found = 0;
# Find the name from the .spec file
for (@{$spec_details->{EXPORTS}})
{
if (@$_[$EXPORT_ORDINAL] eq $comment->{ORDINAL})
{
$comment->{COMMENT_NAME} = @$_[$EXPORT_EXPNAME];
$found = 1;
}
}
if ($found == 0)
{
# Create an implementation name
$comment->{COMMENT_NAME} = $comment->{DLL_NAME}."_".$comment->{ORDINAL};
}
}
my $exported_names = $spec_details->{EXPORTED_NAMES};
my $export_index = $exported_names->{$comment->{COMMENT_NAME}};
my $implementation_names = $spec_details->{IMPLEMENTATION_NAMES};
if (!defined($export_index))
{
# Perhaps the comment uses the implementation name?
$export_index = $implementation_names->{$comment->{COMMENT_NAME}};
}
if (!defined($export_index))
{
# This function doesn't appear to be exported. hmm.
if ($opt_verbose > 2)
{
print "Warning: Function '".$comment->{COMMENT_NAME}."' claims to belong to '".
$comment->{DLL_NAME}."' but is not exported by it: not processing it.\n";
}
return;
}
# When the function is exported twice we have the second name below the first
# (you see this a lot in ntdll, but also in some other places).
my $first_line = ${$comment->{TEXT}}[1];
if ( $first_line =~ /^(@|[A-Za-z0-9_]+) +(\(|\[)([A-Za-z0-9_]+)\.(([0-9]+)|@)(\)|\])$/ )
{
# Found a second name - mark it as documented
my $alt_index = $exported_names->{$1};
if (defined($alt_index))
{
if ($opt_verbose > 2)
{
print "Info: Found alternate name '",$1,"\n";
}
my $alt_export = @{$spec_details->{EXPORTS}}[$alt_index];
@$alt_export[$EXPORT_FLAGS] |= $FLAG_DOCUMENTED;
$spec_details->{NUM_DOCS}++;
${$comment->{TEXT}}[1] = "";
}
}
if (@{$spec_details->{CURRENT_EXTRA}})
{
# We have an extra comment that might be related to this one
my $current_comment = ${$spec_details->{CURRENT_EXTRA}}[0];
my $current_name = $current_comment->{COMMENT_NAME};
if ($comment->{COMMENT_NAME} =~ /^$current_name/ && $comment->{COMMENT_NAME} ne $current_name)
{
if ($opt_verbose > 2)
{
print "Linking ",$comment->{COMMENT_NAME}," to $current_name\n";
}
# Add a reference to this comment to our extra comment
push (@{$current_comment->{TEXT}}, $comment->{COMMENT_NAME}."()","");
}
}
# We want our docs generated using the implementation name, so they are unique
my $export = @{$spec_details->{EXPORTS}}[$export_index];
$comment->{COMMENT_NAME} = @$export[$EXPORT_IMPNAME];
$comment->{ALT_NAME} = @$export[$EXPORT_EXPNAME];
# Mark the function as documented
$spec_details->{NUM_DOCS}++;
@$export[$EXPORT_FLAGS] |= $FLAG_DOCUMENTED;
# If we have parameter comments in the prototype, extract them
my @parameter_comments;
for (@{$comment->{PROTOTYPE}})
{
s/ *\, */\,/g; # Strip spaces from around commas
if ( s/ *(\/\* *)(.*?)( *\*\/ *)// ) # Strip out comment
{
my $parameter_comment = $2;
if (!$parameter_comment =~ /^\[/ )
{
# Add [IO] markers so we format the comment correctly
$parameter_comment = "[fixme] ".$parameter_comment;
}
if ( /( |\*)([A-Za-z_]{1}[A-Za-z_0-9]*)(\,|\))/ )
{
# Add the parameter name
$parameter_comment = $2." ".$parameter_comment;
}
push (@parameter_comments, $parameter_comment);
}
}
# If we extracted any prototype comments, add them to the comment text.
if (@parameter_comments)
{
@parameter_comments = ("PARAMS", @parameter_comments);
my @new_comment = ();
my $inserted_params = 0;
for (@{$comment->{TEXT}})
{
if ( $inserted_params == 0 && /^[A-Z]+$/ )
{
# Found a section header, so this is where we insert
push (@new_comment, @parameter_comments);
$inserted_params = 1;
}
push (@new_comment, $_);
}
if ($inserted_params == 0)
{
# Add them to the end
push (@new_comment, @parameter_comments);
}
$comment->{TEXT} = [@new_comment];
}
if ($opt_fussy == 1 && $opt_output_empty == 0)
{
# Reject any comment that doesn't have a description or a RETURNS section.
# This is the default for now, 'coz many comments aren't suitable.
my $found_returns = 0;
my $found_description_text = 0;
my $in_description = 0;
for (@{$comment->{TEXT}})
{
if ( /^RETURNS$/ )
{
$found_returns = 1;
$in_description = 0;
}
elsif ( /^DESCRIPTION$/ )
{
$in_description = 1;
}
elsif ($in_description == 1)
{
if ( !/^[A-Z]+$/ )
{
# Don't reject comments that refer to another doc (e.g. A/W)
if ( /^See ([A-Za-z0-9_]+)\.$/ )
{
if ($comment->{COMMENT_NAME} =~ /W$/ )
{
# This is probably a Unicode version of an Ascii function.
# Create the Ascii name and see if it has been documented
my $ascii_name = $comment->{COMMENT_NAME};
$ascii_name =~ s/W$/A/;
my $ascii_export_index = $exported_names->{$ascii_name};
if (!defined($ascii_export_index))
{
$ascii_export_index = $implementation_names->{$ascii_name};
}
if (!defined($ascii_export_index))
{
if ($opt_verbose > 2)
{
print "Warning: Function '".$comment->{COMMENT_NAME}."' is not an A/W pair.\n";
}
}
else
{
my $ascii_export = @{$spec_details->{EXPORTS}}[$ascii_export_index];
if (@$ascii_export[$EXPORT_FLAGS] & $FLAG_DOCUMENTED)
{
# Flag these functions as an A/W pair
@$ascii_export[$EXPORT_FLAGS] |= $FLAG_APAIR;
@$export[$EXPORT_FLAGS] |= $FLAG_WPAIR;
}
}
}
$found_returns = 1;
}
elsif ( /^Unicode version of ([A-Za-z0-9_]+)\.$/ )
{
@$export[$EXPORT_FLAGS] |= $FLAG_WPAIR; # Explicitly marked as W version
$found_returns = 1;
}
elsif ( /^64\-bit version of ([A-Za-z0-9_]+)\.$/ )
{
@$export[$EXPORT_FLAGS] |= $FLAG_64PAIR; # Explicitly marked as 64 bit version
$found_returns = 1;
}
$found_description_text = 1;
}
else
{
$in_description = 0;
}
}
}
if ($found_returns == 0 || $found_description_text == 0)
{
if ($opt_verbose > 2)
{
print "Info: Function '",$comment->{COMMENT_NAME},"' has no ",
"description and/or RETURNS section, skipping\n";
}
$spec_details->{NUM_DOCS}--;
@$export[$EXPORT_FLAGS] &= ~$FLAG_DOCUMENTED;
return;
}
}
process_comment_text($comment);
# Strip the prototypes return value, call convention, name and brackets
# (This leaves it as a list of types and names, or empty for void functions)
my $prototype = join(" ", @{$comment->{PROTOTYPE}});
$prototype =~ s/ / /g;
if ( $prototype =~ /(WINAPIV|WINAPI|__cdecl|PASCAL|CALLBACK|FARPROC16)/ )
{
$prototype =~ s/^(.*?)\s+(WINAPIV|WINAPI|__cdecl|PASCAL|CALLBACK|FARPROC16)\s+(.*?)\(\s*(.*)/$4/;
$comment->{RETURNS} = $1;
}
else
{
$prototype =~ s/^(.*?)([A-Za-z0-9_]+)\s*\(\s*(.*)/$3/;
$comment->{RETURNS} = $1;
}
$prototype =~ s/ *\).*//; # Strip end bracket
$prototype =~ s/ *\* */\*/g; # Strip space around pointers
$prototype =~ s/ *\, */\,/g; # Strip space around commas
$prototype =~ s/^(void|VOID)$//; # If void, leave blank
$prototype =~ s/\*([A-Za-z_])/\* $1/g; # Separate pointers from parameter name
@{$comment->{PROTOTYPE}} = split ( /,/ ,$prototype);
# FIXME: If we have no parameters, make sure we have a PARAMS: None. section
# Find header file
my $h_file = "";
if (@$export[$EXPORT_FLAGS] & $FLAG_NONAME)
{
$h_file = "Exported by ordinal only. Use GetProcAddress() to obtain a pointer to the function.";
}
else
{
if ($comment->{COMMENT_NAME} ne "")
{
my $tmp = "grep -s -l $comment->{COMMENT_NAME} @opt_header_file_list 2>/dev/null";
$tmp = `$tmp`;
my $exit_value = $? >> 8;
if ($exit_value == 0)
{
$tmp =~ s/\n.*//g;
if ($tmp ne "")
{
$h_file = "$tmp";
$h_file =~ s|^.*/\./||;
}
}
}
elsif ($comment->{ALT_NAME} ne "")
{
my $tmp = "grep -s -l $comment->{ALT_NAME} @opt_header_file_list"." 2>/dev/null";
$tmp = `$tmp`;
my $exit_value = $? >> 8;
if ($exit_value == 0)
{
$tmp =~ s/\n.*//g;
if ($tmp ne "")
{
$h_file = "$tmp";
$h_file =~ s|^.*/\./||;
}
}
}
$h_file =~ s/^ *//;
$h_file =~ s/\n//;
if ($h_file eq "")
{
$h_file = "Not declared in a Wine header. The function is either undocumented, or missing from Wine."
}
else
{
$h_file = "Declared in \"".$h_file."\".";
}
}
# Find source file
my $c_file = $comment->{FILE};
if ($opt_wine_root_dir ne "")
{
my $cfile = $pwd."/".$c_file; # Current dir + file
$cfile =~ s/(.+)(\/.*$)/$1/; # Strip the filename
$cfile = `cd $cfile && pwd`; # Strip any relative parts (e.g. "../../")
$cfile =~ s/\n//; # Strip newline
my $newfile = $c_file;
$newfile =~ s/(.+)(\/.*$)/$2/; # Strip all but the filename
$cfile = $cfile."/".$newfile; # Append filename to base path
$cfile =~ s/$opt_wine_root_dir//; # Get rid of the root directory
$cfile =~ s/\/\//\//g; # Remove any double slashes
$cfile =~ s/^\/+//; # Strip initial directory slash
$c_file = $cfile;
}
$c_file = "Implemented in \"".$c_file."\".";
# Add the implementation details
push (@{$comment->{TEXT}}, "IMPLEMENTATION","",$h_file,"",$c_file);
if (@$export[$EXPORT_FLAGS] & $FLAG_I386)
{
push (@{$comment->{TEXT}}, "", "Available on x86 platforms only.");
}
if (@$export[$EXPORT_FLAGS] & $FLAG_REGISTER)
{
push (@{$comment->{TEXT}}, "", "This function passes one or more arguments in registers. ",
"For more details, please read the source code.");
}
my $source_details = $source_files{$comment->{FILE}}[0];
if ($source_details->{DEBUG_CHANNEL} ne "")
{
push (@{$comment->{TEXT}}, "", "Debug channel \"".$source_details->{DEBUG_CHANNEL}."\".");
}
# Write out the documentation for the API
output_comment($comment)
}
# process our extra comment and output it if it is suitable.
sub process_extra_comment($)
{
my $comment = shift;
my $spec_details = $spec_files{$comment->{DLL_NAME}}[0];
if (!defined($spec_details))
{
if ($opt_verbose > 2)
{
print "Warning: Extra comment '".$comment->{COMMENT_NAME}."' belongs to '".
$comment->{DLL_NAME}."' (not passed with -w): not processing it.\n";
}
return;
}
# Check first to see if this is documentation for the DLL.
if ($comment->{COMMENT_NAME} eq $comment->{DLL_NAME})
{
if ($opt_verbose > 2)
{
print "Info: Found DLL documentation\n";
}
for (@{$comment->{TEXT}})
{
push (@{$spec_details->{DESCRIPTION}}, $_);
}
return;
}
# Add the comment to the DLL page as a link
push (@{$spec_details->{EXTRA_COMMENTS}},$comment->{COMMENT_NAME});
# If we have a prototype, process as a regular comment
if (@{$comment->{PROTOTYPE}})
{
$comment->{ORDINAL} = "@";
# Add an index for the comment name
$spec_details->{EXPORTED_NAMES}{$comment->{COMMENT_NAME}} = $spec_details->{NUM_EXPORTS};
# Add a fake exported entry
$spec_details->{NUM_EXPORTS}++;
my ($ordinal, $call_convention, $exported_name, $implementation_name, $documented) =
("@", "fake", $comment->{COMMENT_NAME}, $comment->{COMMENT_NAME}, 0);
my @export = ($ordinal, $call_convention, $exported_name, $implementation_name, $documented);
push (@{$spec_details->{EXPORTS}},[@export]);
@{$comment->{TEXT}} = ("DESCRIPTION", @{$comment->{TEXT}});
process_comment($comment);
return;
}
if ($opt_verbose > 0)
{
print "Processing ",$comment->{COMMENT_NAME},"\n";