regedit: Don't call ungetc() twice consecutively.
[wine.git] / tools / c2man.pl
blob4fff8d7e713f334d23a044f97b939c07dbba6495
1 #! /usr/bin/perl -w
3 # Generate API documentation. See http://www.winehq.org/docs/winedev-guide/api-docs for details.
5 # Copyright (C) 2000 Mike McCormack
6 # Copyright (C) 2003 Jon Griffiths
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 # TODO
23 # Consolidate A+W pairs together, and only write one doc, without the suffix
24 # Implement automatic docs fo structs/defines in headers
25 # SGML gurus - feel free to smarten up the SGML.
26 # Add any other relevant information for the dll - imports etc
27 # Should we have a special output mode for WineHQ?
29 use strict;
30 use bytes;
32 # Function flags. most of these come from the spec flags
33 my $FLAG_DOCUMENTED = 1;
34 my $FLAG_NONAME = 2;
35 my $FLAG_I386 = 4;
36 my $FLAG_REGISTER = 8;
37 my $FLAG_APAIR = 16; # The A version of a matching W function
38 my $FLAG_WPAIR = 32; # The W version of a matching A function
39 my $FLAG_64PAIR = 64; # The 64 bit version of a matching 32 bit function
42 # Options
43 my $opt_output_directory = "man3w"; # All default options are for nroff (man pages)
44 my $opt_manual_section = "3w";
45 my $opt_source_dir = "";
46 my $opt_wine_root_dir = "";
47 my $opt_output_format = ""; # '' = nroff, 'h' = html, 's' = sgml, 'x' = xml
48 my $opt_output_empty = 0; # Non-zero = Create 'empty' comments (for every implemented function)
49 my $opt_fussy = 1; # Non-zero = Create only if we have a RETURNS section
50 my $opt_verbose = 0; # >0 = verbosity. Can be given multiple times (for debugging)
51 my @opt_header_file_list = ();
52 my @opt_spec_file_list = ();
53 my @opt_source_file_list = ();
55 # All the collected details about all the .spec files being processed
56 my %spec_files;
57 # All the collected details about all the source files being processed
58 my %source_files;
59 # All documented functions that are to be placed in the index
60 my @index_entries_list = ();
62 # useful globals
63 my $pwd = `pwd`."/";
64 $pwd =~ s/\n//;
65 my @datetime = localtime;
66 my @months = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun",
67 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
68 my $year = $datetime[5] + 1900;
69 my $date = "$months[$datetime[4]] $year";
72 sub output_api_comment($);
73 sub output_api_footer($);
74 sub output_api_header($);
75 sub output_api_name($);
76 sub output_api_synopsis($);
77 sub output_close_api_file();
78 sub output_comment($);
79 sub output_html_index_files();
80 sub output_html_stylesheet();
81 sub output_open_api_file($);
82 sub output_sgml_dll_file($);
83 sub output_xml_dll_file($);
84 sub output_sgml_master_file($);
85 sub output_xml_master_file($);
86 sub output_spec($);
87 sub process_comment($);
88 sub process_extra_comment($);
91 # Generate the list of exported entries for the dll
92 sub process_spec_file($)
94 my $spec_name = shift;
95 my ($dll_name, $dll_ext) = split(/\./, $spec_name);
96 $dll_ext = "dll" if ( $dll_ext eq "spec" );
97 my $uc_dll_name = uc $dll_name;
99 my $spec_details =
101 NAME => $spec_name,
102 DLL_NAME => $dll_name,
103 DLL_EXT => $dll_ext,
104 NUM_EXPORTS => 0,
105 NUM_STUBS => 0,
106 NUM_FUNCS => 0,
107 NUM_FORWARDS => 0,
108 NUM_VARS => 0,
109 NUM_DOCS => 0,
110 CONTRIBUTORS => [ ],
111 SOURCES => [ ],
112 DESCRIPTION => [ ],
113 EXPORTS => [ ],
114 EXPORTED_NAMES => { },
115 IMPLEMENTATION_NAMES => { },
116 EXTRA_COMMENTS => [ ],
117 CURRENT_EXTRA => [ ] ,
120 if ($opt_verbose > 0)
122 print "Processing ".$spec_name."\n";
125 # We allow opening to fail just to cater for the peculiarities of
126 # the Wine build system. This doesn't hurt, in any case
127 open(SPEC_FILE, "<$spec_name")
128 || (($opt_source_dir ne "")
129 && open(SPEC_FILE, "<$opt_source_dir/$spec_name"))
130 || return;
132 while(<SPEC_FILE>)
134 s/^\s+//; # Strip leading space
135 s/\s+\n$/\n/; # Strip trailing space
136 s/\s+/ /g; # Strip multiple tabs & spaces to a single space
137 s/\s*#.*//; # Strip comments
138 s/\(.*\)/ /; # Strip arguments
139 s/\s+/ /g; # Strip multiple tabs & spaces to a single space (again)
140 s/\n$//; # Strip newline
142 my $flags = 0;
143 if( /\-noname/ )
145 $flags |= $FLAG_NONAME;
147 if( /\-i386/ )
149 $flags |= $FLAG_I386;
151 if( /\-register/ )
153 $flags |= $FLAG_REGISTER;
155 s/ \-[a-z0-9]+//g; # Strip flags
157 if( /^(([0-9]+)|@) / )
159 # This line contains an exported symbol
160 my ($ordinal, $call_convention, $exported_name, $implementation_name) = split(' ');
162 for ($call_convention)
164 /^(cdecl|stdcall|varargs|pascal)$/
165 && do { $spec_details->{NUM_FUNCS}++; last; };
166 /^(variable|equate)$/
167 && do { $spec_details->{NUM_VARS}++; last; };
168 /^(extern)$/
169 && do { $spec_details->{NUM_FORWARDS}++; last; };
170 /^stub$/ && do { $spec_details->{NUM_STUBS}++; last; };
171 if ($opt_verbose > 0)
173 print "Warning: didn't recognise convention \'",$call_convention,"'\n";
175 last;
178 # Convert ordinal only names so we can find them later
179 if ($exported_name eq "@")
181 $exported_name = $uc_dll_name.'_'.$ordinal;
183 if (!defined($implementation_name))
185 $implementation_name = $exported_name;
187 if ($implementation_name eq "")
189 $implementation_name = $exported_name;
192 if ($implementation_name =~ /(.*?)\./)
194 $call_convention = "forward"; # Referencing a function from another dll
195 $spec_details->{NUM_FUNCS}--;
196 $spec_details->{NUM_FORWARDS}++;
199 # Add indices for the exported and implementation names
200 $spec_details->{EXPORTED_NAMES}{$exported_name} = $spec_details->{NUM_EXPORTS};
201 if ($implementation_name ne $exported_name)
203 $spec_details->{IMPLEMENTATION_NAMES}{$exported_name} = $spec_details->{NUM_EXPORTS};
206 # Add the exported entry
207 $spec_details->{NUM_EXPORTS}++;
208 my @export = ($ordinal, $call_convention, $exported_name, $implementation_name, $flags);
209 push (@{$spec_details->{EXPORTS}},[@export]);
212 close(SPEC_FILE);
214 # Add this .spec files details to the list of .spec files
215 $spec_files{$uc_dll_name} = [$spec_details];
218 # Read each source file, extract comments, and generate API documentation if appropriate
219 sub process_source_file($)
221 my $source_file = shift;
222 my $source_details =
224 CONTRIBUTORS => [ ],
225 DEBUG_CHANNEL => "",
227 my $comment =
229 FILE => $source_file,
230 COMMENT_NAME => "",
231 ALT_NAME => "",
232 DLL_NAME => "",
233 DLL_EXT => "",
234 ORDINAL => "",
235 RETURNS => "",
236 PROTOTYPE => [],
237 TEXT => [],
239 my $parse_state = 0;
240 my $ignore_blank_lines = 1;
241 my $extra_comment = 0; # 1 if this is an extra comment, i.e its not a .spec export
243 if ($opt_verbose > 0)
245 print "Processing ".$source_file."\n";
247 open(SOURCE_FILE,"<$source_file")
248 || (($opt_source_dir ne "")
249 && open(SOURCE_FILE,"<$opt_source_dir/$source_file"))
250 || die "couldn't open ".$source_file."\n";
252 # Add this source file to the list of source files
253 $source_files{$source_file} = [$source_details];
255 while(<SOURCE_FILE>)
257 s/\n$//; # Strip newline
258 s/^\s+//; # Strip leading space
259 s/\s+$//; # Strip trailing space
260 if (! /^\*\|/ )
262 # Strip multiple tabs & spaces to a single space
263 s/\s+/ /g;
266 if ( / +Copyright *(\([Cc]\))*[0-9 \-\,\/]*([[:alpha:][:^ascii:] \.\-]+)/ )
268 # Extract a contributor to this file
269 my $contributor = $2;
270 $contributor =~ s/ *$//;
271 $contributor =~ s/^by //;
272 $contributor =~ s/\.$//;
273 $contributor =~ s/ (for .*)/ \($1\)/;
274 if ($contributor ne "")
276 if ($opt_verbose > 3)
278 print "Info: Found contributor:'".$contributor."'\n";
280 push (@{$source_details->{CONTRIBUTORS}},$contributor);
283 elsif ( /WINE_DEFAULT_DEBUG_CHANNEL\(([A-Za-z]*)\)/ )
285 # Extract the debug channel to use
286 if ($opt_verbose > 3)
288 print "Info: Found debug channel:'".$1."'\n";
290 $source_details->{DEBUG_CHANNEL} = $1;
293 if ($parse_state == 0) # Searching for a comment
295 if ( /^\/\**$/ )
297 # Found a comment start
298 $comment->{COMMENT_NAME} = "";
299 $comment->{ALT_NAME} = "";
300 $comment->{DLL_NAME} = "";
301 $comment->{ORDINAL} = "";
302 $comment->{RETURNS} = "";
303 $comment->{PROTOTYPE} = [];
304 $comment->{TEXT} = [];
305 $ignore_blank_lines = 1;
306 $extra_comment = 0;
307 $parse_state = 3;
310 elsif ($parse_state == 1) # Reading in a comment
312 if ( /^\**\// )
314 # Found the end of the comment
315 $parse_state = 2;
317 elsif ( s/^\*\|/\|/ )
319 # A line of comment not meant to be pre-processed
320 push (@{$comment->{TEXT}},$_); # Add the comment text
322 elsif ( s/^ *\** *// )
324 # A line of comment, starting with an asterisk
325 if ( /^[A-Z]+$/ || $_ eq "")
327 # This is a section start, so skip blank lines before and after it.
328 my $last_line = pop(@{$comment->{TEXT}});
329 if (defined($last_line) && $last_line ne "")
331 # Put it back
332 push (@{$comment->{TEXT}},$last_line);
334 if ( /^[A-Z]+$/ )
336 $ignore_blank_lines = 1;
338 else
340 $ignore_blank_lines = 0;
344 if ($ignore_blank_lines == 0 || $_ ne "")
346 push (@{$comment->{TEXT}},$_); # Add the comment text
349 else
351 # This isn't a well formatted comment: look for the next one
352 $parse_state = 0;
355 elsif ($parse_state == 2) # Finished reading in a comment
357 if ( /(WINAPIV|WINAPI|__cdecl|PASCAL|CALLBACK|FARPROC16)/ ||
358 /.*?\(/ )
360 # Comment is followed by a function definition
361 $parse_state = 4; # Fall through to read prototype
363 else
365 # Allow cpp directives and blank lines between the comment and prototype
366 if ($extra_comment == 1)
368 # An extra comment not followed by a function definition
369 $parse_state = 5; # Fall through to process comment
371 elsif (!/^\#/ && !/^ *$/ && !/^__ASM_GLOBAL_FUNC/)
373 # This isn't a well formatted comment: look for the next one
374 if ($opt_verbose > 1)
376 print "Info: Function '",$comment->{COMMENT_NAME},"' not followed by prototype.\n";
378 $parse_state = 0;
382 elsif ($parse_state == 3) # Reading in the first line of a comment
384 s/^ *\** *//;
385 if ( /^([\@A-Za-z0-9_]+) +(\(|\[)([A-Za-z0-9_]+)\.(([0-9]+)|@)(\)|\])\s*(.*)$/ )
387 # Found a correctly formed "ApiName (DLLNAME.Ordinal)" line.
388 if (defined ($7) && $7 ne "")
390 push (@{$comment->{TEXT}},$_); # Add the trailing comment text
392 $comment->{COMMENT_NAME} = $1;
393 $comment->{DLL_NAME} = uc $3;
394 $comment->{ORDINAL} = $4;
395 $comment->{DLL_NAME} =~ s/^KERNEL$/KRNL386/; # Too many of these to ignore, _old_ code
396 $parse_state = 1;
398 elsif ( /^([A-Za-z0-9_-]+) +\{([A-Za-z0-9_]+)\}$/ )
400 # Found a correctly formed "CommentTitle {DLLNAME}" line (extra documentation)
401 $comment->{COMMENT_NAME} = $1;
402 $comment->{DLL_NAME} = uc $2;
403 $comment->{ORDINAL} = "";
404 $extra_comment = 1;
405 $parse_state = 1;
407 else
409 # This isn't a well formatted comment: look for the next one
410 $parse_state = 0;
414 if ($parse_state == 4) # Reading in the function definition
416 push (@{$comment->{PROTOTYPE}},$_);
417 # Strip comments from the line before checking for ')'
418 my $stripped_line = $_;
419 $stripped_line =~ s/ *(\/\* *)(.*?)( *\*\/ *)//;
420 if ( $stripped_line =~ /\)/ )
422 # Strip a blank last line
423 my $last_line = pop(@{$comment->{TEXT}});
424 if (defined($last_line) && $last_line ne "")
426 # Put it back
427 push (@{$comment->{TEXT}},$last_line);
430 if ($opt_output_empty != 0 && @{$comment->{TEXT}} == 0)
432 # Create a 'not implemented' comment
433 @{$comment->{TEXT}} = ("fixme: This function has not yet been documented.");
435 $parse_state = 5;
439 if ($parse_state == 5) # Processing the comment
441 # Process it, if it has any text
442 if (@{$comment->{TEXT}} > 0)
444 if ($extra_comment == 1)
446 process_extra_comment($comment);
448 else
450 @{$comment->{TEXT}} = ("DESCRIPTION", @{$comment->{TEXT}});
451 process_comment($comment);
454 elsif ($opt_verbose > 1 && $opt_output_empty == 0)
456 print "Info: Function '",$comment->{COMMENT_NAME},"' has no documentation.\n";
458 $parse_state = 0;
461 close(SOURCE_FILE);
464 # Standardise a comments text for consistency
465 sub process_comment_text($)
467 my $comment = shift;
468 my $in_params = 0;
469 my @tmp_list = ();
470 my $i = 0;
472 for (@{$comment->{TEXT}})
474 my $line = $_;
476 if ( /^\s*$/ || /^[A-Z]+$/ || /^-/ )
478 $in_params = 0;
480 if ( $in_params > 0 && !/\[/ && !/\]/ )
482 # Possibly a continuation of the parameter description
483 my $last_line = pop(@tmp_list);
484 if ( $last_line =~ /\[/ && $last_line =~ /\]/ )
486 $line = $last_line." ".$_;
488 else
490 $in_params = 0;
491 push (@tmp_list, $last_line);
494 if ( /^(PARAMS|MEMBERS)$/ )
496 $in_params = 1;
498 push (@tmp_list, $line);
501 @{$comment->{TEXT}} = @tmp_list;
503 for (@{$comment->{TEXT}})
505 if (! /^\|/ )
507 # Map I/O values. These come in too many formats to standardise now....
508 s/\[I\]|\[i\]|\[in\]|\[IN\]/\[In\] /g;
509 s/\[O\]|\[o\]|\[out\]|\[OUT\]/\[Out\]/g;
510 s/\[I\/O\]|\[I\,O\]|\[i\/o\]|\[in\/out\]|\[IN\/OUT\]/\[In\/Out\]/g;
511 # TRUE/FALSE/NULL are defines, capitilise them
512 s/True|true/TRUE/g;
513 s/False|false/FALSE/g;
514 s/Null|null/NULL/g;
515 # Preferred capitalisations
516 s/ wine| WINE/ Wine/g;
517 s/ API | api / Api /g;
518 s/ DLL | Dll / dll /g;
519 s/ URL | url / Url /g;
520 s/WIN16|win16/Win16/g;
521 s/WIN32|win32/Win32/g;
522 s/WIN64|win64/Win64/g;
523 s/ ID | id / Id /g;
524 # Grammar
525 s/([a-z])\.([A-Z])/$1\. $2/g; # Space after full stop
526 s/ \:/\:/g; # Colons to the left
527 s/ \;/\;/g; # Semi-colons too
528 # Common idioms
529 s/^See ([A-Za-z0-9_]+)\.$/See $1\(\)\./; # Referring to A version from W
530 s/^Unicode version of ([A-Za-z0-9_]+)\.$/See $1\(\)\./; # Ditto
531 s/^64\-bit version of ([A-Za-z0-9_]+)\.$/See $1\(\)\./; # Referring to 32 bit version from 64
532 s/^PARAMETERS$/PARAMS/; # Name of parameter section should be 'PARAMS'
533 # Trademarks
534 s/( |\.)(M\$|MS|Microsoft|microsoft|micro\$oft|Micro\$oft)( |\.)/$1Microsoft\(tm\)$3/g;
535 s/( |\.)(Windows|windows|windoze|winblows)( |\.)/$1Windows\(tm\)$3/g;
536 s/( |\.)(DOS|dos|msdos)( |\.)/$1MS-DOS\(tm\)$3/g;
537 s/( |\.)(UNIX|unix)( |\.)/$1Unix\(tm\)$3/g;
538 s/( |\.)(LINIX|linux)( |\.)/$1Linux\(tm\)$3/g;
539 # Abbreviations
540 s/( char )/ character /g;
541 s/( chars )/ characters /g;
542 s/( info )/ information /g;
543 s/( app )/ application /g;
544 s/( apps )/ applications /g;
545 s/( exe )/ executable /g;
546 s/( ptr )/ pointer /g;
547 s/( obj )/ object /g;
548 s/( err )/ error /g;
549 s/( bool )/ boolean /g;
550 s/( no\. )/ number /g;
551 s/( No\. )/ Number /g;
552 # Punctuation
553 if ( /\[I|\[O/ && ! /\.$/ )
555 $_ = $_."."; # Always have a full stop at the end of parameter desc.
557 elsif ($i > 0 && /^[A-Z]*$/ &&
558 !(@{$comment->{TEXT}}[$i-1] =~ /\.$/) &&
559 !(@{$comment->{TEXT}}[$i-1] =~ /\:$/))
562 if (!(@{$comment->{TEXT}}[$i-1] =~ /^[A-Z]*$/))
564 # Paragraphs always end with a full stop
565 @{$comment->{TEXT}}[$i-1] = @{$comment->{TEXT}}[$i-1].".";
569 $i++;
573 # Standardise our comment and output it if it is suitable.
574 sub process_comment($)
576 my $comment = shift;
578 # Don't process this comment if the function isn't exported
579 my $spec_details = $spec_files{$comment->{DLL_NAME}}[0];
581 if (!defined($spec_details))
583 if ($opt_verbose > 2)
585 print "Warning: Function '".$comment->{COMMENT_NAME}."' belongs to '".
586 $comment->{DLL_NAME}."' (not passed with -w): not processing it.\n";
588 return;
591 if ($comment->{COMMENT_NAME} eq "@")
593 my $found = 0;
595 # Find the name from the .spec file
596 for (@{$spec_details->{EXPORTS}})
598 if (@$_[0] eq $comment->{ORDINAL})
600 $comment->{COMMENT_NAME} = @$_[2];
601 $found = 1;
605 if ($found == 0)
607 # Create an implementation name
608 $comment->{COMMENT_NAME} = $comment->{DLL_NAME}."_".$comment->{ORDINAL};
612 my $exported_names = $spec_details->{EXPORTED_NAMES};
613 my $export_index = $exported_names->{$comment->{COMMENT_NAME}};
614 my $implementation_names = $spec_details->{IMPLEMENTATION_NAMES};
616 if (!defined($export_index))
618 # Perhaps the comment uses the implementation name?
619 $export_index = $implementation_names->{$comment->{COMMENT_NAME}};
621 if (!defined($export_index))
623 # This function doesn't appear to be exported. hmm.
624 if ($opt_verbose > 2)
626 print "Warning: Function '".$comment->{COMMENT_NAME}."' claims to belong to '".
627 $comment->{DLL_NAME}."' but is not exported by it: not processing it.\n";
629 return;
632 # When the function is exported twice we have the second name below the first
633 # (you see this a lot in ntdll, but also in some other places).
634 my $first_line = ${$comment->{TEXT}}[1];
636 if ( $first_line =~ /^(@|[A-Za-z0-9_]+) +(\(|\[)([A-Za-z0-9_]+)\.(([0-9]+)|@)(\)|\])$/ )
638 # Found a second name - mark it as documented
639 my $alt_index = $exported_names->{$1};
640 if (defined($alt_index))
642 if ($opt_verbose > 2)
644 print "Info: Found alternate name '",$1,"\n";
646 my $alt_export = @{$spec_details->{EXPORTS}}[$alt_index];
647 @$alt_export[4] |= $FLAG_DOCUMENTED;
648 $spec_details->{NUM_DOCS}++;
649 ${$comment->{TEXT}}[1] = "";
653 if (@{$spec_details->{CURRENT_EXTRA}})
655 # We have an extra comment that might be related to this one
656 my $current_comment = ${$spec_details->{CURRENT_EXTRA}}[0];
657 my $current_name = $current_comment->{COMMENT_NAME};
658 if ($comment->{COMMENT_NAME} =~ /^$current_name/ && $comment->{COMMENT_NAME} ne $current_name)
660 if ($opt_verbose > 2)
662 print "Linking ",$comment->{COMMENT_NAME}," to $current_name\n";
664 # Add a reference to this comment to our extra comment
665 push (@{$current_comment->{TEXT}}, $comment->{COMMENT_NAME}."()","");
669 # We want our docs generated using the implementation name, so they are unique
670 my $export = @{$spec_details->{EXPORTS}}[$export_index];
671 $comment->{COMMENT_NAME} = @$export[3];
672 $comment->{ALT_NAME} = @$export[2];
674 # Mark the function as documented
675 $spec_details->{NUM_DOCS}++;
676 @$export[4] |= $FLAG_DOCUMENTED;
678 # This file is used by the DLL - Make sure we get our contributors right
679 push (@{$spec_details->{SOURCES}},$comment->{FILE});
681 # If we have parameter comments in the prototype, extract them
682 my @parameter_comments;
683 for (@{$comment->{PROTOTYPE}})
685 s/ *\, */\,/g; # Strip spaces from around commas
687 if ( s/ *(\/\* *)(.*?)( *\*\/ *)// ) # Strip out comment
689 my $parameter_comment = $2;
690 if (!$parameter_comment =~ /^\[/ )
692 # Add [IO] markers so we format the comment correctly
693 $parameter_comment = "[fixme] ".$parameter_comment;
695 if ( /( |\*)([A-Za-z_]{1}[A-Za-z_0-9]*)(\,|\))/ )
697 # Add the parameter name
698 $parameter_comment = $2." ".$parameter_comment;
700 push (@parameter_comments, $parameter_comment);
704 # If we extracted any prototype comments, add them to the comment text.
705 if (@parameter_comments)
707 @parameter_comments = ("PARAMS", @parameter_comments);
708 my @new_comment = ();
709 my $inserted_params = 0;
711 for (@{$comment->{TEXT}})
713 if ( $inserted_params == 0 && /^[A-Z]+$/ )
715 # Found a section header, so this is where we insert
716 push (@new_comment, @parameter_comments);
717 $inserted_params = 1;
719 push (@new_comment, $_);
721 if ($inserted_params == 0)
723 # Add them to the end
724 push (@new_comment, @parameter_comments);
726 $comment->{TEXT} = [@new_comment];
729 if ($opt_fussy == 1 && $opt_output_empty == 0)
731 # Reject any comment that doesn't have a description or a RETURNS section.
732 # This is the default for now, 'coz many comments aren't suitable.
733 my $found_returns = 0;
734 my $found_description_text = 0;
735 my $in_description = 0;
736 for (@{$comment->{TEXT}})
738 if ( /^RETURNS$/ )
740 $found_returns = 1;
741 $in_description = 0;
743 elsif ( /^DESCRIPTION$/ )
745 $in_description = 1;
747 elsif ($in_description == 1)
749 if ( !/^[A-Z]+$/ )
751 # Don't reject comments that refer to another doc (e.g. A/W)
752 if ( /^See ([A-Za-z0-9_]+)\.$/ )
754 if ($comment->{COMMENT_NAME} =~ /W$/ )
756 # This is probably a Unicode version of an Ascii function.
757 # Create the Ascii name and see if its been documented
758 my $ascii_name = $comment->{COMMENT_NAME};
759 $ascii_name =~ s/W$/A/;
761 my $ascii_export_index = $exported_names->{$ascii_name};
763 if (!defined($ascii_export_index))
765 $ascii_export_index = $implementation_names->{$ascii_name};
767 if (!defined($ascii_export_index))
769 if ($opt_verbose > 2)
771 print "Warning: Function '".$comment->{COMMENT_NAME}."' is not an A/W pair.\n";
774 else
776 my $ascii_export = @{$spec_details->{EXPORTS}}[$ascii_export_index];
777 if (@$ascii_export[4] & $FLAG_DOCUMENTED)
779 # Flag these functions as an A/W pair
780 @$ascii_export[4] |= $FLAG_APAIR;
781 @$export[4] |= $FLAG_WPAIR;
785 $found_returns = 1;
787 elsif ( /^Unicode version of ([A-Za-z0-9_]+)\.$/ )
789 @$export[4] |= $FLAG_WPAIR; # Explicitly marked as W version
790 $found_returns = 1;
792 elsif ( /^64\-bit version of ([A-Za-z0-9_]+)\.$/ )
794 @$export[4] |= $FLAG_64PAIR; # Explicitly marked as 64 bit version
795 $found_returns = 1;
797 $found_description_text = 1;
799 else
801 $in_description = 0;
805 if ($found_returns == 0 || $found_description_text == 0)
807 if ($opt_verbose > 2)
809 print "Info: Function '",$comment->{COMMENT_NAME},"' has no ",
810 "description and/or RETURNS section, skipping\n";
812 $spec_details->{NUM_DOCS}--;
813 @$export[4] &= ~$FLAG_DOCUMENTED;
814 return;
818 process_comment_text($comment);
820 # Strip the prototypes return value, call convention, name and brackets
821 # (This leaves it as a list of types and names, or empty for void functions)
822 my $prototype = join(" ", @{$comment->{PROTOTYPE}});
823 $prototype =~ s/ / /g;
825 if ( $prototype =~ /(WINAPIV|WINAPI|__cdecl|PASCAL|CALLBACK|FARPROC16)/ )
827 $prototype =~ s/^(.*?)\s+(WINAPIV|WINAPI|__cdecl|PASCAL|CALLBACK|FARPROC16)\s+(.*?)\(\s*(.*)/$4/;
828 $comment->{RETURNS} = $1;
830 else
832 $prototype =~ s/^(.*?)([A-Za-z0-9_]+)\s*\(\s*(.*)/$3/;
833 $comment->{RETURNS} = $1;
836 $prototype =~ s/ *\).*//; # Strip end bracket
837 $prototype =~ s/ *\* */\*/g; # Strip space around pointers
838 $prototype =~ s/ *\, */\,/g; # Strip space around commas
839 $prototype =~ s/^(void|VOID)$//; # If void, leave blank
840 $prototype =~ s/\*([A-Za-z_])/\* $1/g; # Separate pointers from parameter name
841 @{$comment->{PROTOTYPE}} = split ( /,/ ,$prototype);
843 # FIXME: If we have no parameters, make sure we have a PARAMS: None. section
845 # Find header file
846 my $h_file = "";
847 if (@$export[4] & $FLAG_NONAME)
849 $h_file = "Exported by ordinal only. Use GetProcAddress() to obtain a pointer to the function.";
851 else
853 if ($comment->{COMMENT_NAME} ne "")
855 my $tmp = "grep -s -l $comment->{COMMENT_NAME} @opt_header_file_list 2>/dev/null";
856 $tmp = `$tmp`;
857 my $exit_value = $? >> 8;
858 if ($exit_value == 0)
860 $tmp =~ s/\n.*//g;
861 if ($tmp ne "")
863 $h_file = `basename $tmp`;
867 elsif ($comment->{ALT_NAME} ne "")
869 my $tmp = "grep -s -l $comment->{ALT_NAME} @opt_header_file_list"." 2>/dev/null";
870 $tmp = `$tmp`;
871 my $exit_value = $? >> 8;
872 if ($exit_value == 0)
874 $tmp =~ s/\n.*//g;
875 if ($tmp ne "")
877 $h_file = `basename $tmp`;
881 $h_file =~ s/^ *//;
882 $h_file =~ s/\n//;
883 if ($h_file eq "")
885 $h_file = "Not defined in a Wine header. The function is either undocumented, or missing from Wine."
887 else
889 $h_file = "Defined in \"".$h_file."\".";
893 # Find source file
894 my $c_file = $comment->{FILE};
895 if ($opt_wine_root_dir ne "")
897 my $cfile = $pwd."/".$c_file; # Current dir + file
898 $cfile =~ s/(.+)(\/.*$)/$1/; # Strip the filename
899 $cfile = `cd $cfile && pwd`; # Strip any relative parts (e.g. "../../")
900 $cfile =~ s/\n//; # Strip newline
901 my $newfile = $c_file;
902 $newfile =~ s/(.+)(\/.*$)/$2/; # Strip all but the filename
903 $cfile = $cfile."/".$newfile; # Append filename to base path
904 $cfile =~ s/$opt_wine_root_dir//; # Get rid of the root directory
905 $cfile =~ s/\/\//\//g; # Remove any double slashes
906 $cfile =~ s/^\/+//; # Strip initial directory slash
907 $c_file = $cfile;
909 $c_file = "Implemented in \"".$c_file."\".";
911 # Add the implementation details
912 push (@{$comment->{TEXT}}, "IMPLEMENTATION","",$h_file,"",$c_file);
914 if (@$export[4] & $FLAG_I386)
916 push (@{$comment->{TEXT}}, "", "Available on x86 platforms only.");
918 if (@$export[4] & $FLAG_REGISTER)
920 push (@{$comment->{TEXT}}, "", "This function passes one or more arguments in registers. ",
921 "For more details, please read the source code.");
923 my $source_details = $source_files{$comment->{FILE}}[0];
924 if ($source_details->{DEBUG_CHANNEL} ne "")
926 push (@{$comment->{TEXT}}, "", "Debug channel \"".$source_details->{DEBUG_CHANNEL}."\".");
929 # Write out the documentation for the API
930 output_comment($comment)
933 # process our extra comment and output it if it is suitable.
934 sub process_extra_comment($)
936 my $comment = shift;
938 my $spec_details = $spec_files{$comment->{DLL_NAME}}[0];
940 if (!defined($spec_details))
942 if ($opt_verbose > 2)
944 print "Warning: Extra comment '".$comment->{COMMENT_NAME}."' belongs to '".
945 $comment->{DLL_NAME}."' (not passed with -w): not processing it.\n";
947 return;
950 # Check first to see if this is documentation for the DLL.
951 if ($comment->{COMMENT_NAME} eq $comment->{DLL_NAME})
953 if ($opt_verbose > 2)
955 print "Info: Found DLL documentation\n";
957 for (@{$comment->{TEXT}})
959 push (@{$spec_details->{DESCRIPTION}}, $_);
961 return;
964 # Add the comment to the DLL page as a link
965 push (@{$spec_details->{EXTRA_COMMENTS}},$comment->{COMMENT_NAME});
967 # If we have a prototype, process as a regular comment
968 if (@{$comment->{PROTOTYPE}})
970 $comment->{ORDINAL} = "@";
972 # Add an index for the comment name
973 $spec_details->{EXPORTED_NAMES}{$comment->{COMMENT_NAME}} = $spec_details->{NUM_EXPORTS};
975 # Add a fake exported entry
976 $spec_details->{NUM_EXPORTS}++;
977 my ($ordinal, $call_convention, $exported_name, $implementation_name, $documented) =
978 ("@", "fake", $comment->{COMMENT_NAME}, $comment->{COMMENT_NAME}, 0);
979 my @export = ($ordinal, $call_convention, $exported_name, $implementation_name, $documented);
980 push (@{$spec_details->{EXPORTS}},[@export]);
981 @{$comment->{TEXT}} = ("DESCRIPTION", @{$comment->{TEXT}});
982 process_comment($comment);
983 return;
986 if ($opt_verbose > 0)
988 print "Processing ",$comment->{COMMENT_NAME},"\n";
991 if (@{$spec_details->{CURRENT_EXTRA}})
993 my $current_comment = ${$spec_details->{CURRENT_EXTRA}}[0];
995 if ($opt_verbose > 0)
997 print "Processing old current: ",$current_comment->{COMMENT_NAME},"\n";
999 # Output the current comment
1000 process_comment_text($current_comment);
1001 output_open_api_file($current_comment->{COMMENT_NAME});
1002 output_api_header($current_comment);
1003 output_api_name($current_comment);
1004 output_api_comment($current_comment);
1005 output_api_footer($current_comment);
1006 output_close_api_file();
1009 if ($opt_verbose > 2)
1011 print "Setting current to ",$comment->{COMMENT_NAME},"\n";
1014 my $comment_copy =
1016 FILE => $comment->{FILE},
1017 COMMENT_NAME => $comment->{COMMENT_NAME},
1018 ALT_NAME => $comment->{ALT_NAME},
1019 DLL_NAME => $comment->{DLL_NAME},
1020 ORDINAL => $comment->{ORDINAL},
1021 RETURNS => $comment->{RETURNS},
1022 PROTOTYPE => [],
1023 TEXT => [],
1026 for (@{$comment->{TEXT}})
1028 push (@{$comment_copy->{TEXT}}, $_);
1030 # Set this comment to be the current extra comment
1031 @{$spec_details->{CURRENT_EXTRA}} = ($comment_copy);
1034 # Write a standardised comment out in the appropriate format
1035 sub output_comment($)
1037 my $comment = shift;
1039 if ($opt_verbose > 0)
1041 print "Processing ",$comment->{COMMENT_NAME},"\n";
1044 if ($opt_verbose > 4)
1046 print "--PROTO--\n";
1047 for (@{$comment->{PROTOTYPE}})
1049 print "'".$_."'\n";
1052 print "--COMMENT--\n";
1053 for (@{$comment->{TEXT} })
1055 print $_."\n";
1059 output_open_api_file($comment->{COMMENT_NAME});
1060 output_api_header($comment);
1061 output_api_name($comment);
1062 output_api_synopsis($comment);
1063 output_api_comment($comment);
1064 output_api_footer($comment);
1065 output_close_api_file();
1068 # Write out an index file for each .spec processed
1069 sub process_index_files()
1071 foreach my $spec_file (keys %spec_files)
1073 my $spec_details = $spec_files{$spec_file}[0];
1074 if (defined ($spec_details->{DLL_NAME}))
1076 if (@{$spec_details->{CURRENT_EXTRA}})
1078 # We have an unwritten extra comment, write it
1079 my $current_comment = ${$spec_details->{CURRENT_EXTRA}}[0];
1080 process_extra_comment($current_comment);
1081 @{$spec_details->{CURRENT_EXTRA}} = ();
1083 output_spec($spec_details);
1088 # Write a spec files documentation out in the appropriate format
1089 sub output_spec($)
1091 my $spec_details = shift;
1093 if ($opt_verbose > 2)
1095 print "Writing:",$spec_details->{DLL_NAME},"\n";
1098 # Use the comment output functions for consistency
1099 my $comment =
1101 FILE => $spec_details->{DLL_NAME},
1102 COMMENT_NAME => $spec_details->{DLL_NAME}.".".$spec_details->{DLL_EXT},
1103 ALT_NAME => $spec_details->{DLL_NAME},
1104 DLL_NAME => "",
1105 ORDINAL => "",
1106 RETURNS => "",
1107 PROTOTYPE => [],
1108 TEXT => [],
1110 my $total_implemented = $spec_details->{NUM_FORWARDS} + $spec_details->{NUM_VARS} +
1111 $spec_details->{NUM_FUNCS};
1112 my $percent_implemented = 0;
1113 if ($total_implemented)
1115 $percent_implemented = $total_implemented /
1116 ($total_implemented + $spec_details->{NUM_STUBS}) * 100;
1118 $percent_implemented = int($percent_implemented);
1119 my $percent_documented = 0;
1120 if ($spec_details->{NUM_DOCS})
1122 # Treat forwards and data as documented funcs for statistics
1123 $percent_documented = $spec_details->{NUM_DOCS} / $spec_details->{NUM_FUNCS} * 100;
1124 $percent_documented = int($percent_documented);
1127 # Make a list of the contributors to this DLL. Do this only for the source
1128 # files that make up the DLL, because some directories specify multiple dlls.
1129 my @contributors;
1131 for (@{$spec_details->{SOURCES}})
1133 my $source_details = $source_files{$_}[0];
1134 for (@{$source_details->{CONTRIBUTORS}})
1136 push (@contributors, $_);
1140 my %saw;
1141 @contributors = grep(!$saw{$_}++, @contributors); # remove dups, from perlfaq4 manpage
1142 @contributors = sort @contributors;
1144 # Remove duplicates and blanks
1145 for(my $i=0; $i<@contributors; $i++)
1147 if ($i > 0 && ($contributors[$i] =~ /$contributors[$i-1]/ || $contributors[$i-1] eq ""))
1149 $contributors[$i-1] = $contributors[$i];
1152 undef %saw;
1153 @contributors = grep(!$saw{$_}++, @contributors);
1155 if ($opt_verbose > 3)
1157 print "Contributors:\n";
1158 for (@contributors)
1160 print "'".$_."'\n";
1163 my $contribstring = join (", ", @contributors);
1165 # Create the initial comment text
1166 @{$comment->{TEXT}} = (
1167 "NAME",
1168 $comment->{COMMENT_NAME}
1171 # Add the description, if we have one
1172 if (@{$spec_details->{DESCRIPTION}})
1174 push (@{$comment->{TEXT}}, "DESCRIPTION");
1175 for (@{$spec_details->{DESCRIPTION}})
1177 push (@{$comment->{TEXT}}, $_);
1181 # Add the statistics and contributors
1182 push (@{$comment->{TEXT}},
1183 "STATISTICS",
1184 "Forwards: ".$spec_details->{NUM_FORWARDS},
1185 "Variables: ".$spec_details->{NUM_VARS},
1186 "Stubs: ".$spec_details->{NUM_STUBS},
1187 "Functions: ".$spec_details->{NUM_FUNCS},
1188 "Exports-Total: ".$spec_details->{NUM_EXPORTS},
1189 "Implemented-Total: ".$total_implemented." (".$percent_implemented."%)",
1190 "Documented-Total: ".$spec_details->{NUM_DOCS}." (".$percent_documented."%)",
1191 "CONTRIBUTORS",
1192 "The following people hold copyrights on the source files comprising this dll:",
1194 $contribstring,
1195 "Note: This list may not be complete.",
1196 "For a complete listing, see the Files \"AUTHORS\" and \"Changelog\" in the Wine source tree.",
1200 if ($opt_output_format eq "h")
1202 # Add the exports to the comment text
1203 push (@{$comment->{TEXT}},"EXPORTS");
1204 my $exports = $spec_details->{EXPORTS};
1205 for (@$exports)
1207 my $line = "";
1209 # @$_ => ordinal, call convention, exported name, implementation name, flags;
1210 if (@$_[1] eq "forward")
1212 my $forward_dll = @$_[3];
1213 $forward_dll =~ s/\.(.*)//;
1214 $line = @$_[2]." (forward to ".$1."() in ".$forward_dll."())";
1216 elsif (@$_[1] eq "extern")
1218 $line = @$_[2]." (extern)";
1220 elsif (@$_[1] eq "stub")
1222 $line = @$_[2]." (stub)";
1224 elsif (@$_[1] eq "fake")
1226 # Don't add this function here, it gets listed with the extra documentation
1227 if (!(@$_[4] & $FLAG_WPAIR))
1229 # This function should be indexed
1230 push (@index_entries_list, @$_[3].",".@$_[3]);
1233 elsif (@$_[1] eq "equate" || @$_[1] eq "variable")
1235 $line = @$_[2]." (data)";
1237 else
1239 # A function
1240 if (@$_[4] & $FLAG_DOCUMENTED)
1242 # Documented
1243 $line = @$_[2]." (implemented as ".@$_[3]."())";
1244 if (@$_[2] ne @$_[3])
1246 $line = @$_[2]." (implemented as ".@$_[3]."())";
1248 else
1250 $line = @$_[2]."()";
1252 if (!(@$_[4] & $FLAG_WPAIR))
1254 # This function should be indexed
1255 push (@index_entries_list, @$_[2].",".@$_[3]);
1258 else
1260 $line = @$_[2]." (not documented)";
1263 if ($line ne "")
1265 push (@{$comment->{TEXT}}, $line, "");
1269 # Add links to the extra documentation
1270 if (@{$spec_details->{EXTRA_COMMENTS}})
1272 push (@{$comment->{TEXT}}, "SEE ALSO");
1273 my %htmp;
1274 @{$spec_details->{EXTRA_COMMENTS}} = grep(!$htmp{$_}++, @{$spec_details->{EXTRA_COMMENTS}});
1275 for (@{$spec_details->{EXTRA_COMMENTS}})
1277 push (@{$comment->{TEXT}}, $_."()", "");
1281 # The dll entry should also be indexed
1282 push (@index_entries_list, $spec_details->{DLL_NAME}.",".$spec_details->{DLL_NAME});
1284 # Write out the document
1285 output_open_api_file($spec_details->{DLL_NAME});
1286 output_api_header($comment);
1287 output_api_comment($comment);
1288 output_api_footer($comment);
1289 output_close_api_file();
1291 # Add this dll to the database of dll names
1292 my $output_file = $opt_output_directory."/dlls.db";
1294 # Append the dllname to the output db of names
1295 open(DLLDB,">>$output_file") || die "Couldn't create $output_file\n";
1296 print DLLDB $spec_details->{DLL_NAME},"\n";
1297 close(DLLDB);
1299 if ($opt_output_format eq "s")
1301 output_sgml_dll_file($spec_details);
1302 return;
1305 if ($opt_output_format eq "x")
1307 output_xml_dll_file($spec_details);
1308 return;
1314 # OUTPUT FUNCTIONS
1315 # ----------------
1316 # Only these functions know anything about formatting for a specific
1317 # output type. The functions above work only with plain text.
1318 # This is to allow new types of output to be added easily.
1320 # Open the api file
1321 sub output_open_api_file($)
1323 my $output_name = shift;
1324 $output_name = $opt_output_directory."/".$output_name;
1326 if ($opt_output_format eq "h")
1328 $output_name = $output_name.".html";
1330 elsif ($opt_output_format eq "s")
1332 $output_name = $output_name.".sgml";
1334 elsif ($opt_output_format eq "x")
1336 $output_name = $output_name.".xml";
1338 else
1340 $output_name = $output_name.".".$opt_manual_section;
1342 open(OUTPUT,">$output_name") || die "Couldn't create file '$output_name'\n";
1345 # Close the api file
1346 sub output_close_api_file()
1348 close (OUTPUT);
1351 # Output the api file header
1352 sub output_api_header($)
1354 my $comment = shift;
1356 if ($opt_output_format eq "h")
1358 print OUTPUT "<!-- Generated file - DO NOT EDIT! -->\n";
1359 print OUTPUT "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
1360 print OUTPUT "<HTML>\n<HEAD>\n";
1361 print OUTPUT "<LINK REL=\"StyleSheet\" href=\"apidoc.css\" type=\"text/css\">\n";
1362 print OUTPUT "<META NAME=\"GENERATOR\" CONTENT=\"tools/c2man.pl\">\n";
1363 print OUTPUT "<META NAME=\"keywords\" CONTENT=\"Win32,Wine,API,$comment->{COMMENT_NAME}\">\n";
1364 print OUTPUT "<TITLE>Wine API: $comment->{COMMENT_NAME}</TITLE>\n</HEAD>\n<BODY>\n";
1366 elsif ($opt_output_format eq "s" || $opt_output_format eq "x")
1368 print OUTPUT "<!-- Generated file - DO NOT EDIT! -->\n",
1369 "<sect1>\n",
1370 "<title>$comment->{COMMENT_NAME}</title>\n";
1372 else
1374 print OUTPUT ".\\\" -*- nroff -*-\n.\\\" Generated file - DO NOT EDIT!\n".
1375 ".TH ",$comment->{COMMENT_NAME}," ",$opt_manual_section," \"",$date,"\" \"".
1376 "Wine API\" \"Wine API\"\n";
1380 sub output_api_footer($)
1382 if ($opt_output_format eq "h")
1384 print OUTPUT "<hr><p><i class=\"copy\">Copyright &copy ".$year." The Wine Project.".
1385 " All trademarks are the property of their respective owners.".
1386 " Visit <a href=\"http://www.winehq.org\">WineHQ</a> for license details.".
1387 " Generated $date.</i></p>\n</body>\n</html>\n";
1389 elsif ($opt_output_format eq "s" || $opt_output_format eq "x")
1391 print OUTPUT "</sect1>\n";
1392 return;
1394 else
1399 sub output_api_section_start($$)
1401 my $comment = shift;
1402 my $section_name = shift;
1404 if ($opt_output_format eq "h")
1406 print OUTPUT "\n<h2 class=\"section\">",$section_name,"</h2>\n";
1408 elsif ($opt_output_format eq "s" || $opt_output_format eq "x")
1410 print OUTPUT "<bridgehead>",$section_name,"</bridgehead>\n";
1412 else
1414 print OUTPUT "\n\.SH ",$section_name,"\n";
1418 sub output_api_section_end()
1420 # Not currently required by any output formats
1423 sub output_api_name($)
1425 my $comment = shift;
1426 my $readable_name = $comment->{COMMENT_NAME};
1427 $readable_name =~ s/-/ /g; # make section names more readable
1429 output_api_section_start($comment,"NAME");
1432 my $dll_ordinal = "";
1433 if ($comment->{ORDINAL} ne "")
1435 $dll_ordinal = "(".$comment->{DLL_NAME}.".".$comment->{ORDINAL}.")";
1437 if ($opt_output_format eq "h")
1439 print OUTPUT "<p><b class=\"func_name\">",$readable_name,
1440 "</b>&nbsp;&nbsp;<i class=\"dll_ord\">",
1441 ,$dll_ordinal,"</i></p>\n";
1443 elsif ($opt_output_format eq "s" || $opt_output_format eq "x")
1445 print OUTPUT "<para>\n <command>",$readable_name,"</command> <emphasis>",
1446 $dll_ordinal,"</emphasis>\n</para>\n";
1448 else
1450 print OUTPUT "\\fB",$readable_name,"\\fR ",$dll_ordinal;
1453 output_api_section_end();
1456 sub output_api_synopsis($)
1458 my $comment = shift;
1459 my @fmt;
1461 output_api_section_start($comment,"SYNOPSIS");
1463 if ($opt_output_format eq "h")
1465 print OUTPUT "<pre class=\"proto\">\n ", $comment->{RETURNS}," ",$comment->{COMMENT_NAME},"\n (\n";
1466 @fmt = ("", "\n", "<tt class=\"param\">", "</tt>");
1468 elsif ($opt_output_format eq "s" || $opt_output_format eq "x")
1470 print OUTPUT "<screen>\n ",$comment->{RETURNS}," ",$comment->{COMMENT_NAME},"\n (\n";
1471 @fmt = ("", "\n", "<emphasis>", "</emphasis>");
1473 else
1475 print OUTPUT $comment->{RETURNS}," ",$comment->{COMMENT_NAME},"\n (\n";
1476 @fmt = ("", "\n", "\\fI", "\\fR");
1479 # Since our prototype is output in a pre-formatted block, line up the
1480 # parameters and parameter comments in the same column.
1482 # First caluculate where the columns should start
1483 my $biggest_length = 0;
1484 for(my $i=0; $i < @{$comment->{PROTOTYPE}}; $i++)
1486 my $line = ${$comment->{PROTOTYPE}}[$i];
1487 if ($line =~ /(.+?)([A-Za-z_][A-Za-z_0-9]*)$/)
1489 my $length = length $1;
1490 if ($length > $biggest_length)
1492 $biggest_length = $length;
1497 # Now pad the string with blanks
1498 for(my $i=0; $i < @{$comment->{PROTOTYPE}}; $i++)
1500 my $line = ${$comment->{PROTOTYPE}}[$i];
1501 if ($line =~ /(.+?)([A-Za-z_][A-Za-z_0-9]*)$/)
1503 my $pad_len = $biggest_length - length $1;
1504 my $padding = " " x ($pad_len);
1505 ${$comment->{PROTOTYPE}}[$i] = $1.$padding.$2;
1509 for(my $i=0; $i < @{$comment->{PROTOTYPE}}; $i++)
1511 # Format the parameter name
1512 my $line = ${$comment->{PROTOTYPE}}[$i];
1513 my $comma = ($i == @{$comment->{PROTOTYPE}}-1) ? "" : ",";
1514 $line =~ s/(.+?)([A-Za-z_][A-Za-z_0-9]*)$/ $fmt[0]$1$fmt[2]$2$fmt[3]$comma$fmt[1]/;
1515 print OUTPUT $line;
1518 if ($opt_output_format eq "h")
1520 print OUTPUT " )\n</pre>\n";
1522 elsif ($opt_output_format eq "s" || $opt_output_format eq "x")
1524 print OUTPUT " )\n</screen>\n";
1526 else
1528 print OUTPUT " )\n";
1531 output_api_section_end();
1534 sub output_api_comment($)
1536 my $comment = shift;
1537 my $open_paragraph = 0;
1538 my $open_raw = 0;
1539 my $param_docs = 0;
1540 my @fmt;
1542 if ($opt_output_format eq "h")
1544 @fmt = ("<p>", "</p>\n", "<tt class=\"const\">", "</tt>", "<b class=\"emp\">", "</b>",
1545 "<tt class=\"coderef\">", "</tt>", "<tt class=\"param\">", "</tt>",
1546 "<i class=\"in_out\">", "</i>", "<pre class=\"raw\">\n", "</pre>\n",
1547 "<table class=\"tab\"><colgroup><col><col><col></colgroup><tbody>\n",
1548 "</tbody></table>\n","<tr><td>","</td></tr>\n","</td>","</td><td>");
1550 elsif ($opt_output_format eq "s" || $opt_output_format eq "x")
1552 @fmt = ("<para>\n","\n</para>\n","<constant>","</constant>","<emphasis>","</emphasis>",
1553 "<command>","</command>","<constant>","</constant>","<emphasis>","</emphasis>",
1554 "<screen>\n","</screen>\n",
1555 "<informaltable frame=\"none\">\n<tgroup cols=\"3\">\n<tbody>\n",
1556 "</tbody>\n</tgroup>\n</informaltable>\n","<row><entry>","</entry></row>\n",
1557 "</entry>","</entry><entry>");
1559 else
1561 @fmt = ("\.PP\n", "\n", "\\fB", "\\fR", "\\fB", "\\fR", "\\fB", "\\fR", "\\fI", "\\fR",
1562 "\\fB", "\\fR ", "", "", "", "","","\n.PP\n","","");
1565 # Extract the parameter names
1566 my @parameter_names;
1567 for (@{$comment->{PROTOTYPE}})
1569 if ( /(.+?)([A-Za-z_][A-Za-z_0-9]*)$/ )
1571 push (@parameter_names, $2);
1575 for (@{$comment->{TEXT}})
1577 if ($opt_output_format eq "h" || $opt_output_format eq "s" || $opt_output_format eq "x")
1579 # Map special characters
1580 s/\&/\&amp;/g;
1581 s/\</\&lt;/g;
1582 s/\>/\&gt;/g;
1583 s/\([Cc]\)/\&copy;/g;
1584 s/\(tm\)/&#174;/;
1587 if ( s/^\|// )
1589 # Raw output
1590 if ($open_raw == 0)
1592 if ($open_paragraph == 1)
1594 # Close the open paragraph
1595 print OUTPUT $fmt[1];
1596 $open_paragraph = 0;
1598 # Start raw output
1599 print OUTPUT $fmt[12];
1600 $open_raw = 1;
1602 if ($opt_output_format eq "")
1604 print OUTPUT ".br\n"; # Prevent 'man' running these lines together
1606 print OUTPUT $_,"\n";
1608 else
1610 if ($opt_output_format eq "h")
1612 # Link to the file in WineHQ cvs
1613 s/^(Implemented in \")(.+?)(\"\.)/$1$2$3 http:\/\/source.winehq.org\/source\/$2/g;
1615 # Highlight strings
1616 s/(\".+?\")/$fmt[2]$1$fmt[3]/g;
1617 # Highlight literal chars
1618 s/(\'.\')/$fmt[2]$1$fmt[3]/g;
1619 s/(\'.{2}\')/$fmt[2]$1$fmt[3]/g;
1620 # Highlight numeric constants
1621 s/( |\-|\+|\.|\()([0-9\-\.]+)( |\-|$|\.|\,|\*|\?|\))/$1$fmt[2]$2$fmt[3]$3/g;
1623 # Leading cases ("xxxx:","-") start new paragraphs & are emphasised
1624 # FIXME: Using bullet points for leading '-' would look nicer.
1625 if ($open_paragraph == 1 && $param_docs == 0)
1627 s/^(\-)/$fmt[1]$fmt[0]$fmt[4]$1$fmt[5]/;
1628 s/^([[A-Za-z\-]+\:)/$fmt[1]$fmt[0]$fmt[4]$1$fmt[5]/;
1630 else
1632 s/^(\-)/$fmt[4]$1$fmt[5]/;
1633 s/^([[A-Za-z\-]+\:)/$fmt[4]$1$fmt[5]/;
1636 if ($opt_output_format eq "h")
1638 # Html uses links for API calls
1639 while ( /([A-Za-z_]+[A-Za-z_0-9-]+)(\(\))/)
1641 my $link = $1;
1642 my $readable_link = $1;
1643 $readable_link =~ s/-/ /g;
1645 s/([A-Za-z_]+[A-Za-z_0-9-]+)(\(\))/<a href\=\"$link\.html\">$readable_link<\/a>/;
1647 # Index references
1648 s/\{\{(.*?)\}\}\{\{(.*?)\}\}/<a href\=\"$2\.html\">$1<\/a>/g;
1649 s/ ([A-Z_])(\(\))/<a href\=\"$1\.html\">$1<\/a>/g;
1650 # And references to COM objects (hey, they'll get documented one day)
1651 s/ (I[A-Z]{1}[A-Za-z0-9_]+) (Object|object|Interface|interface)/ <a href\=\"$1\.html\">$1<\/a> $2/g;
1652 # Convert any web addresses to real links
1653 s/(http\:\/\/)(.+?)($| )/<a href\=\"$1$2\">$2<\/a>$3/g;
1655 else
1657 if ($opt_output_format eq "")
1659 # Give the man section for API calls
1660 s/ ([A-Za-z_]+[A-Za-z_0-9-]+)\(\)/ $fmt[6]$1\($opt_manual_section\)$fmt[7]/g;
1662 else
1664 # Highlight API calls
1665 s/ ([A-Za-z_]+[A-Za-z_0-9-]+\(\))/ $fmt[6]$1$fmt[7]/g;
1668 # And references to COM objects
1669 s/ (I[A-Z]{1}[A-Za-z0-9_]+) (Object|object|Interface|interface)/ $fmt[6]$1$fmt[7] $2/g;
1672 if ($open_raw == 1)
1674 # Finish the raw output
1675 print OUTPUT $fmt[13];
1676 $open_raw = 0;
1679 if ( /^[A-Z]+$/ || /^SEE ALSO$/ )
1681 # Start of a new section
1682 if ($open_paragraph == 1)
1684 if ($param_docs == 1)
1686 print OUTPUT $fmt[17],$fmt[15];
1687 $param_docs = 0;
1689 else
1691 print OUTPUT $fmt[1];
1693 $open_paragraph = 0;
1695 output_api_section_start($comment,$_);
1696 if ( /^PARAMS$/ || /^MEMBERS$/ )
1698 print OUTPUT $fmt[14];
1699 $param_docs = 1;
1701 else
1703 #print OUTPUT $fmt[15];
1704 #$param_docs = 0;
1707 elsif ( /^$/ )
1709 # Empty line, indicating a new paragraph
1710 if ($open_paragraph == 1)
1712 if ($param_docs == 0)
1714 print OUTPUT $fmt[1];
1715 $open_paragraph = 0;
1719 else
1721 if ($param_docs == 1)
1723 if ($open_paragraph == 1)
1725 # For parameter docs, put each parameter into a new paragraph/table row
1726 print OUTPUT $fmt[17];
1727 $open_paragraph = 0;
1729 s/(\[.+\])( *)/$fmt[19]$fmt[10]$1$fmt[11]$fmt[19] /; # Format In/Out
1731 else
1733 # Within paragraph lines, prevent lines running together
1734 $_ = $_." ";
1737 # Format parameter names where they appear in the comment
1738 for my $parameter_name (@parameter_names)
1740 s/(^|[ \.\,\(\-\*])($parameter_name)($|[ \.\)\,\-\/]|(\=[^"]))/$1$fmt[8]$2$fmt[9]$3/g;
1742 # Structure dereferences include the dereferenced member
1743 s/(\-\>[A-Za-z_]+)/$fmt[8]$1$fmt[9]/g;
1744 s/(\-\&gt\;[A-Za-z_]+)/$fmt[8]$1$fmt[9]/g;
1746 if ($open_paragraph == 0)
1748 if ($param_docs == 1)
1750 print OUTPUT $fmt[16];
1752 else
1754 print OUTPUT $fmt[0];
1756 $open_paragraph = 1;
1758 # Anything in all uppercase on its own gets emphasised
1759 s/(^|[ \.\,\(\[\|\=])([A-Z]+?[A-Z0-9_]+)($|[ \.\,\*\?\|\)\=\'])/$1$fmt[6]$2$fmt[7]$3/g;
1761 print OUTPUT $_;
1765 if ($open_raw == 1)
1767 print OUTPUT $fmt[13];
1769 if ($param_docs == 1 && $open_paragraph == 1)
1771 print OUTPUT $fmt[17];
1772 $open_paragraph = 0;
1774 if ($param_docs == 1)
1776 print OUTPUT $fmt[15];
1778 if ($open_paragraph == 1)
1780 print OUTPUT $fmt[1];
1784 # Create the master index file
1785 sub output_master_index_files()
1787 if ($opt_output_format eq "")
1789 return; # No master index for man pages
1792 if ($opt_output_format eq "h")
1794 # Append the index entries to the output db of index entries
1795 my $output_file = $opt_output_directory."/index.db";
1796 open(INDEXDB,">>$output_file") || die "Couldn't create $output_file\n";
1797 for (@index_entries_list)
1799 $_ =~ s/A\,/\,/;
1800 print INDEXDB $_."\n";
1802 close(INDEXDB);
1805 # Use the comment output functions for consistency
1806 my $comment =
1808 FILE => "",
1809 COMMENT_NAME => "The Wine Api Guide",
1810 ALT_NAME => "The Wine Api Guide",
1811 DLL_NAME => "",
1812 ORDINAL => "",
1813 RETURNS => "",
1814 PROTOTYPE => [],
1815 TEXT => [],
1818 if ($opt_output_format eq "s" || $opt_output_format eq "x")
1820 $comment->{COMMENT_NAME} = "Introduction";
1821 $comment->{ALT_NAME} = "Introduction",
1823 elsif ($opt_output_format eq "h")
1825 @{$comment->{TEXT}} = (
1826 "NAME",
1827 $comment->{COMMENT_NAME},
1828 "INTRODUCTION",
1832 # Create the initial comment text
1833 push (@{$comment->{TEXT}},
1834 "This document describes the Api calls made available",
1835 "by Wine. They are grouped by the dll that exports them.",
1837 "Please do not edit this document, since it is generated automatically",
1838 "from the Wine source code tree. Details on updating this documentation",
1839 "are given in the \"Wine Developers Guide\".",
1840 "CONTRIBUTORS",
1841 "Api documentation is generally written by the person who ",
1842 "implements a given Api call. Authors of each dll are listed in the overview ",
1843 "section for that dll. Additional contributors who have updated source files ",
1844 "but have not entered their names in a copyright statement are noted by an ",
1845 "entry in the file \"Changelog\" from the Wine source code distribution.",
1849 # Read in all dlls from the database of dll names
1850 my $input_file = $opt_output_directory."/dlls.db";
1851 my @dlls = `cat $input_file|sort|uniq`;
1853 if ($opt_output_format eq "h")
1855 # HTML gets a list of all the dlls and an index. For docbook the index creates this for us
1856 push (@{$comment->{TEXT}},
1857 "INDEX",
1858 "For an alphabetical listing of the functions available, please click the ",
1859 "first letter of the functions name below:","",
1860 "[ _(), A(), B(), C(), D(), E(), F(), G(), H(), ".
1861 "I(), J(), K(), L(), M(), N(), O(), P(), Q(), ".
1862 "R(), S(), T(), U(), V(), W(), X(), Y(), Z() ]", "",
1863 "DLLS",
1864 "Each dll provided by Wine is documented individually. The following dlls are provided :",
1867 # Add the dlls to the comment
1868 for (@dlls)
1870 $_ =~ s/(\..*)?\n/\(\)/;
1871 push (@{$comment->{TEXT}}, $_, "");
1873 output_open_api_file("index");
1875 elsif ($opt_output_format eq "s" || $opt_output_format eq "x")
1877 # Just write this as the initial blurb, with a chapter heading
1878 output_open_api_file("blurb");
1879 print OUTPUT "<chapter id =\"blurb\">\n<title>Introduction to The Wine Api Guide</title>\n"
1882 # Write out the document
1883 output_api_header($comment);
1884 output_api_comment($comment);
1885 output_api_footer($comment);
1886 if ($opt_output_format eq "s" || $opt_output_format eq "x")
1888 print OUTPUT "</chapter>\n" # finish the chapter
1890 output_close_api_file();
1892 if ($opt_output_format eq "s")
1894 output_sgml_master_file(\@dlls);
1895 return;
1897 if ($opt_output_format eq "x")
1899 output_xml_master_file(\@dlls);
1900 return;
1902 if ($opt_output_format eq "h")
1904 output_html_index_files();
1905 output_html_stylesheet();
1906 return;
1910 # Write the master wine-api.xml, linking it to each dll.
1911 sub output_xml_master_file($)
1913 my $dlls = shift;
1915 output_open_api_file("wine-api");
1916 print OUTPUT "<?xml version='1.0'?>";
1917 print OUTPUT "<!-- Generated file - DO NOT EDIT! -->\n";
1918 print OUTPUT "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook V5.0/EN\" ";
1919 print OUTPUT " \"http://www.docbook.org/xml/5.0/dtd/docbook.dtd\" [\n\n";
1920 print OUTPUT "<!ENTITY blurb SYSTEM \"blurb.xml\">\n";
1922 # List the entities
1923 for (@$dlls)
1925 $_ =~ s/(\..*)?\n//;
1926 print OUTPUT "<!ENTITY ",$_," SYSTEM \"",$_,".xml\">\n"
1929 print OUTPUT "]>\n\n<book id=\"index\">\n<bookinfo><title>The Wine Api Guide</title></bookinfo>\n\n";
1930 print OUTPUT " &blurb;\n";
1932 for (@$dlls)
1934 print OUTPUT " &",$_,";\n"
1936 print OUTPUT "\n\n</book>\n";
1938 output_close_api_file();
1941 # Write the master wine-api.sgml, linking it to each dll.
1942 sub output_sgml_master_file($)
1944 my $dlls = shift;
1946 output_open_api_file("wine-api");
1947 print OUTPUT "<!-- Generated file - DO NOT EDIT! -->\n";
1948 print OUTPUT "<!doctype book PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\" [\n\n";
1949 print OUTPUT "<!entity blurb SYSTEM \"blurb.sgml\">\n";
1951 # List the entities
1952 for (@$dlls)
1954 $_ =~ s/(\..*)?\n//;
1955 print OUTPUT "<!entity ",$_," SYSTEM \"",$_,".sgml\">\n"
1958 print OUTPUT "]>\n\n<book id=\"index\">\n<bookinfo><title>The Wine Api Guide</title></bookinfo>\n\n";
1959 print OUTPUT " &blurb;\n";
1961 for (@$dlls)
1963 print OUTPUT " &",$_,";\n"
1965 print OUTPUT "\n\n</book>\n";
1967 output_close_api_file();
1970 # Produce the sgml for the dll chapter from the generated files
1971 sub output_sgml_dll_file($)
1973 my $spec_details = shift;
1975 # Make a list of all the documentation files to include
1976 my $exports = $spec_details->{EXPORTS};
1977 my @source_files = ();
1978 for (@$exports)
1980 # @$_ => ordinal, call convention, exported name, implementation name, documented;
1981 if (@$_[1] ne "forward" && @$_[1] ne "extern" && @$_[1] ne "stub" && @$_[1] ne "equate" &&
1982 @$_[1] ne "variable" && @$_[1] ne "fake" && @$_[4] & 1)
1984 # A documented function
1985 push (@source_files,@$_[3]);
1989 push (@source_files,@{$spec_details->{EXTRA_COMMENTS}});
1991 @source_files = sort @source_files;
1993 # create a new chapter for this dll
1994 my $tmp_name = $opt_output_directory."/".$spec_details->{DLL_NAME}.".tmp";
1995 open(OUTPUT,">$tmp_name") || die "Couldn't create $tmp_name\n";
1996 print OUTPUT "<chapter>\n<title>$spec_details->{DLL_NAME}</title>\n";
1997 output_close_api_file();
1999 # Add the sorted documentation, cleaning up as we go
2000 `cat $opt_output_directory/$spec_details->{DLL_NAME}.sgml >>$tmp_name`;
2001 for (@source_files)
2003 `cat $opt_output_directory/$_.sgml >>$tmp_name`;
2004 `rm -f $opt_output_directory/$_.sgml`;
2007 # close the chapter, and overwite the dll source
2008 open(OUTPUT,">>$tmp_name") || die "Couldn't create $tmp_name\n";
2009 print OUTPUT "</chapter>\n";
2010 close OUTPUT;
2011 `mv $tmp_name $opt_output_directory/$spec_details->{DLL_NAME}.sgml`;
2014 # Produce the xml for the dll chapter from the generated files
2015 sub output_xml_dll_file($)
2017 my $spec_details = shift;
2019 # Make a list of all the documentation files to include
2020 my $exports = $spec_details->{EXPORTS};
2021 my @source_files = ();
2022 for (@$exports)
2024 # @$_ => ordinal, call convention, exported name, implementation name, documented;
2025 if (@$_[1] ne "forward" && @$_[1] ne "extern" && @$_[1] ne "stub" && @$_[1] ne "equate" &&
2026 @$_[1] ne "variable" && @$_[1] ne "fake" && @$_[4] & 1)
2028 # A documented function
2029 push (@source_files,@$_[3]);
2033 push (@source_files,@{$spec_details->{EXTRA_COMMENTS}});
2035 @source_files = sort @source_files;
2037 # create a new chapter for this dll
2038 my $tmp_name = $opt_output_directory."/".$spec_details->{DLL_NAME}.".tmp";
2039 open(OUTPUT,">$tmp_name") || die "Couldn't create $tmp_name\n";
2040 print OUTPUT "<?xml version='1.0' encoding='UTF-8'?>\n<chapter>\n<title>$spec_details->{DLL_NAME}</title>\n";
2041 output_close_api_file();
2043 # Add the sorted documentation, cleaning up as we go
2044 `cat $opt_output_directory/$spec_details->{DLL_NAME}.xml >>$tmp_name`;
2045 for (@source_files)
2047 `cat $opt_output_directory/$_.xml >>$tmp_name`;
2048 `rm -f $opt_output_directory/$_.xml`;
2051 # close the chapter, and overwite the dll source
2052 open(OUTPUT,">>$tmp_name") || die "Couldn't create $tmp_name\n";
2053 print OUTPUT "</chapter>\n";
2054 close OUTPUT;
2055 `mv $tmp_name $opt_output_directory/$spec_details->{DLL_NAME}.xml`;
2058 # Write the html index files containing the function names
2059 sub output_html_index_files()
2061 if ($opt_output_format ne "h")
2063 return;
2066 my @letters = ('_', 'A' .. 'Z');
2068 # Read in all functions
2069 my $input_file = $opt_output_directory."/index.db";
2070 my @funcs = `cat $input_file|sort|uniq`;
2072 for (@letters)
2074 my $letter = $_;
2075 my $comment =
2077 FILE => "",
2078 COMMENT_NAME => "",
2079 ALT_NAME => "",
2080 DLL_NAME => "",
2081 ORDINAL => "",
2082 RETURNS => "",
2083 PROTOTYPE => [],
2084 TEXT => [],
2087 $comment->{COMMENT_NAME} = $letter." Functions";
2088 $comment->{ALT_NAME} = $letter." Functions";
2090 push (@{$comment->{TEXT}},
2091 "NAME",
2092 $comment->{COMMENT_NAME},
2093 "FUNCTIONS"
2096 # Add the functions to the comment
2097 for (@funcs)
2099 my $first_char = substr ($_, 0, 1);
2100 $first_char = uc $first_char;
2102 if ($first_char eq $letter)
2104 my $name = $_;
2105 my $file;
2106 $name =~ s/(^.*?)\,(.*?)\n/$1/;
2107 $file = $2;
2108 push (@{$comment->{TEXT}}, "{{".$name."}}{{".$file."}}","");
2112 # Write out the document
2113 output_open_api_file($letter);
2114 output_api_header($comment);
2115 output_api_comment($comment);
2116 output_api_footer($comment);
2117 output_close_api_file();
2121 # Output the stylesheet for HTML output
2122 sub output_html_stylesheet()
2124 if ($opt_output_format ne "h")
2126 return;
2129 my $css;
2130 ($css = <<HERE_TARGET) =~ s/^\s+//gm;
2132 * Default styles for Wine HTML Documentation.
2134 * This style sheet should be altered to suit your needs/taste.
2136 BODY { /* Page body */
2137 background-color: white;
2138 color: black;
2139 font-family: Tahoma,sans-serif;
2140 font-style: normal;
2141 font-size: 10pt;
2143 a:link { color: #4444ff; } /* Links */
2144 a:visited { color: #333377 }
2145 a:active { color: #0000dd }
2146 H2.section { /* Section Headers */
2147 font-family: sans-serif;
2148 color: #777777;
2149 background-color: #F0F0FE;
2150 margin-left: 0.2in;
2151 margin-right: 1.0in;
2153 b.func_name { /* Function Name */
2154 font-size: 10pt;
2155 font-style: bold;
2157 i.dll_ord { /* Italicised DLL+ordinal */
2158 color: #888888;
2159 font-family: sans-serif;
2160 font-size: 8pt;
2162 p { /* Paragraphs */
2163 margin-left: 0.5in;
2164 margin-right: 0.5in;
2166 table { /* tables */
2167 margin-left: 0.5in;
2168 margin-right: 0.5in;
2170 pre.proto /* API Function prototype */
2172 border-style: solid;
2173 border-width: 1px;
2174 border-color: #777777;
2175 background-color: #F0F0BB;
2176 color: black;
2177 font-size: 10pt;
2178 vertical-align: top;
2179 margin-left: 0.5in;
2180 margin-right: 1.0in;
2182 pre.raw { /* Raw text output */
2183 margin-left: 0.6in;
2184 margin-right: 1.1in;
2185 background-color: #8080DC;
2187 tt.param { /* Parameter name */
2188 font-style: italic;
2189 color: blue;
2191 tt.const { /* Constant */
2192 color: red;
2194 i.in_out { /* In/Out */
2195 font-size: 8pt;
2196 color: grey;
2198 tt.coderef { /* Code in description text */
2199 color: darkgreen;
2201 b.emp /* Emphasis */ {
2202 font-style: bold;
2203 color: darkblue;
2205 i.footer { /* Footer */
2206 font-family: sans-serif;
2207 font-size: 6pt;
2208 color: darkgrey;
2210 HERE_TARGET
2212 my $output_file = "$opt_output_directory/apidoc.css";
2213 open(CSS,">$output_file") || die "Couldn't create the file $output_file\n";
2214 print CSS $css;
2215 close(CSS);
2219 sub usage()
2221 print "\nCreate API Documentation from Wine source code.\n\n",
2222 "Usage: c2man.pl [options] {-w <spec>} {-I <include>} {<source>}\n",
2223 "Where: <spec> is a .spec file giving a DLL's exports.\n",
2224 " <include> is an include directory used by the DLL.\n",
2225 " <source> is a source file of the DLL.\n",
2226 " The above can be given multiple times on the command line, as appropriate.\n",
2227 "Options:\n",
2228 " -Th : Output HTML instead of a man page\n",
2229 " -Ts : Output SGML (Docbook source) instead of a man page\n",
2230 " -C <dir> : Source directory, to find source files if they are not found in the\n",
2231 " current directory. Default is \"",$opt_source_dir,"\"\n",
2232 " -R <dir> : Root of build directory, default is \"",$opt_wine_root_dir,"\"\n",
2233 " -o <dir> : Create output in <dir>, default is \"",$opt_output_directory,"\"\n",
2234 " -s <sect>: Set manual section to <sect>, default is ",$opt_manual_section,"\n",
2235 " -e : Output \"FIXME\" documentation from empty comments.\n",
2236 " -v : Verbosity. Can be given more than once for more detail.\n";
2241 # Main
2244 # Print usage if we're called with no args
2245 if( @ARGV == 0)
2247 usage();
2250 # Process command line options
2251 while(defined($_ = shift @ARGV))
2253 if( s/^-// )
2255 # An option.
2256 for ($_)
2258 /^o$/ && do { $opt_output_directory = shift @ARGV; last; };
2259 s/^S// && do { $opt_manual_section = $_; last; };
2260 /^Th$/ && do { $opt_output_format = "h"; last; };
2261 /^Ts$/ && do { $opt_output_format = "s"; last; };
2262 /^Tx$/ && do { $opt_output_format = "x"; last; };
2263 /^v$/ && do { $opt_verbose++; last; };
2264 /^e$/ && do { $opt_output_empty = 1; last; };
2265 /^L$/ && do { last; };
2266 /^w$/ && do { @opt_spec_file_list = (@opt_spec_file_list, shift @ARGV); last; };
2267 s/^I// && do { if ($_ ne ".") {
2268 my $include = $_."/*.h";
2269 $include =~ s/\/\//\//g;
2270 my $have_headers = `ls $include >/dev/null 2>&1`;
2271 if ($? >> 8 == 0) { @opt_header_file_list = (@opt_header_file_list, $include); }
2273 last;
2275 s/^C// && do {
2276 if ($_ ne "") { $opt_source_dir = $_; }
2277 last;
2279 s/^R// && do { if ($_ =~ /^\//) { $opt_wine_root_dir = $_; }
2280 else { $opt_wine_root_dir = `cd $pwd/$_ && pwd`; }
2281 $opt_wine_root_dir =~ s/\n//;
2282 $opt_wine_root_dir =~ s/\/\//\//g;
2283 if (! $opt_wine_root_dir =~ /\/$/ ) { $opt_wine_root_dir = $opt_wine_root_dir."/"; };
2284 last;
2286 die "Unrecognised option $_\n";
2289 else
2291 # A source file.
2292 push (@opt_source_file_list, $_);
2296 # Remove duplicate include directories
2297 my %htmp;
2298 @opt_header_file_list = grep(!$htmp{$_}++, @opt_header_file_list);
2300 if ($opt_verbose > 3)
2302 print "Output dir:'".$opt_output_directory."'\n";
2303 print "Section :'".$opt_manual_section."'\n";
2304 print "Format :'".$opt_output_format."'\n";
2305 print "Source dir:'".$opt_source_dir."'\n";
2306 print "Root :'".$opt_wine_root_dir."'\n";
2307 print "Spec files:'@opt_spec_file_list'\n";
2308 print "Includes :'@opt_header_file_list'\n";
2309 print "Sources :'@opt_source_file_list'\n";
2312 if (@opt_spec_file_list == 0)
2314 exit 0; # Don't bother processing non-dll files
2317 # Make sure the output directory exists
2318 unless (-d $opt_output_directory)
2320 mkdir $opt_output_directory or die "Cannot create directory $opt_output_directory\n";
2323 # Read in each .spec files exports and other details
2324 while(my $spec_file = shift @opt_spec_file_list)
2326 process_spec_file($spec_file);
2329 if ($opt_verbose > 3)
2331 foreach my $spec_file ( keys %spec_files )
2333 print "in '$spec_file':\n";
2334 my $spec_details = $spec_files{$spec_file}[0];
2335 my $exports = $spec_details->{EXPORTS};
2336 for (@$exports)
2338 print @$_[0].",".@$_[1].",".@$_[2].",".@$_[3]."\n";
2343 # Extract and output the comments from each source file
2344 while(defined($_ = shift @opt_source_file_list))
2346 process_source_file($_);
2349 # Write the index files for each spec
2350 process_index_files();
2352 # Write the master index file
2353 output_master_index_files();
2355 exit 0;