3
# Format ImageMagick comments into POD-format or HTML format
5
# Produces *.pod or *.html files corresponding to *.c files
7
# Written by Bob Friesenhahn, April 1997
16
'format=s' => \$opt_format,
17
'srcdir=s' => \$opt_srcdir,
18
'outdir=s' => \$opt_outdir,
21
print("Usage: fmtdocs [-srcdir srcdir] [-outdir outdir] [-format format] \n");
65
$tmpname_pre_format = "/tmp/fmtdocs_pre.$$";
66
$tmpname_pod = "/tmp/fmtdocs_pod.$$";
67
$tmpname_html = "/tmp/fmtdocs_html.$$";
72
# What is for source files
76
'animate', 'Interactively animate an image sequence',
77
'annotate', 'Annotate an image with text',
78
'attribute', 'Access key,value image attributes',
79
'blob', 'Read or write formatted images in memory (BLOBs)',
80
'color', 'Color related functions',
81
'constitute', 'Read or write an image',
82
'composite', 'Merge image pixels using a specified algorithm',
83
'decorate', 'Add decorative frames and borders',
84
'deprecate', 'Methods which should no longer be used',
85
'display', 'Interactively display and edit an image',
86
'render', 'Low-level methods to draw on an image',
87
'draw', 'User-friendly methods to draw on an image',
88
'effect', 'Image effects methods',
89
'fx', 'Image special effects methods',
90
'enhance', 'Methods to enhance or adjust an image',
91
'error', 'Error reporting methods',
92
'image', 'Miscellaneous image methods',
93
'list', 'Image list support',
94
'cache', 'Low-level access to image pixels',
95
'cache_view', 'Low-level access to image pixels with multiple views',
96
'magick', 'Image format support interfaces',
97
'memory', 'Memory allocation/deallocation functions',
98
'monitor', 'Progress monitor support',
99
'montage', 'Create a thumbnail image mosaic',
100
'paint', 'Methods to fill image pixel regions',
101
'profile', 'Manipulate embedded profiles',
102
'quantize', 'Reduce the number of colors in an image',
103
'registry', 'In-memory image registration interface',
104
'resource', 'Set resource consumption limits (e.g. memory)',
105
'segment', 'Segment and image with thresholding using the fuzzy c-means method',
106
'shear', 'Rotate image, shear image, or apply a 2D affine transformation',
107
'signature', 'Add a digital signature to the image',
108
'stream', 'Low-level image pixel FIFO (tap into encode/decode pixel stream)',
109
'transform', 'Crop, flip, flop, roll, coalesce, etc.',
110
'resize', 'Resize an image',
111
'widget', 'X11 Widgets'
115
# Key words to replace with HTML links
119
AffineMatrix => 'types.html#AffineMatrix',
120
BlobInfo => 'types.html#BlobInfo',
121
Cache => 'types.html#Cache',
122
ChannelType => 'types.html#ChannelType',
123
ChromaticityInfo => 'types.html#ChromaticityInfo',
124
ClassType => 'types.html#ClassType',
125
ClipPathUnits => 'types.html#ClipPathUnits',
126
ColorPacket => 'types.html#ColorPacket',
127
ColorspaceType => 'types.html#ColorspaceType',
128
ComplianceType => 'types.html#ComplianceType',
129
CompositeOperator => 'types.html#CompositeOperator',
130
CompressionType => 'types.html#CompressionType',
131
DecorationType => 'types.html#DecorationType',
132
DrawContext => 'types.html#DrawContext',
133
DrawInfo => 'types.html#DrawInfo',
134
ErrorHandler => 'types.html#ErrorHandler',
135
ExceptionInfo => 'types.html#ExceptionInfo',
136
ExceptionType => 'types.html#ExceptionType',
137
FillRule => 'types.html#FillRule',
138
FilterTypes => 'types.html#FilterTypes',
139
FrameInfo => 'types.html#FrameInfo',
140
GravityType => 'types.html#GravityType',
141
Image => 'types.html#Image',
142
ImageInfo => 'types.html#ImageInfo',
143
ImageType => 'types.html#ImageType',
144
InterlaceType => 'types.html#InterlaceType',
145
LayerType => 'types.html#LayerType',
146
MagickInfo => 'types.html#MagickInfo',
147
MonitorHandler => 'types.html#MonitorHandler',
148
MontageInfo => 'types.html#MontageInfo',
149
NoiseType => 'types.html#NoiseType',
150
PaintMethod => 'types.html#PaintMethod',
151
PixelPacket => 'types.html#PixelPacket',
152
PointInfo => 'types.html#PointInfo',
153
ProfileInfo => 'types.html#ProfileInfo',
154
QuantizeInfo => 'types.html#QuantizeInfo',
155
Quantum => 'types.html#Quantum',
156
QuantumType => 'types.html#QuantumType',
157
RectangleInfo => 'types.html#RectangleInfo',
158
RegistryType => 'types.html#RegistryType',
159
RenderingIntent => 'types.html#RenderingIntent',
160
ResolutionType => 'types.html#ResolutionType',
161
ResourceType => 'types.html#ResourceType',
162
SegmentInfo => 'types.html#SegmentInfo',
163
SignatureInfo => 'types.html#SignatureInfo',
164
StorageType => 'types.html#StorageType',
165
StreamHandler => 'types.html#StreamHandler',
166
StretchType => 'types.html#StretchType',
167
StyleType => 'types.html#StyleType',
168
TypeMetric => 'types.html#TypeMetric',
169
ViewInfo => 'types.html#ViewInfo',
170
VirtualPixelMethod => 'types.html#VirtualPixelMethod',
171
XResourceInfo => 'types.html#XResourceInfo',
175
foreach $src (@srcs) {
180
($base = $src) =~ s/\.[^\.]*$//g;
182
$out = "${base}.${opt_format}";
183
if ("${opt_outdir}" ne "") {
184
$out = "${opt_outdir}/${base}.${opt_format}";
187
if ("${opt_srcdir}" ne "") {
188
$src = "${opt_srcdir}/${src}";
191
$command='pod2html -netscape';
192
if ( $opt_format eq 'html' ) {
193
$command='pod2html -netscape';
194
} elsif ( $opt_format eq 'latex' ) {
195
$command='pod2latex';
196
} elsif ( $opt_format eq 'man' ) {
198
} elsif ( $opt_format eq 'text' ) {
200
} elsif ( $opt_format eq 'pod' ) {
204
print( "Processing $src -> $out\n" );
206
pre_format($src, $tmpname_pre_format); # Make easily parsed
207
format_to_pod($tmpname_pre_format, $tmpname_pod); # Format to pod.
209
if ( $opt_format eq 'html' ) {
210
system("$command $tmpname_pod > \"$tmpname_html\"");
211
reformat_html($tmpname_html,$out);
213
system("$command $tmpname_pod > \"$out\"");
215
unlink($tmpname_pre_format);
216
unlink($tmpname_pod);
217
unlink($tmpname_html);
220
#unlink($tmpname_pre_format);
224
# Reformat pod2html-generated HTML into nicer form.
227
my($infile, $outfile) = @_;
229
open( IN, "<$infile" ) || die("Failed to open \"$infile\" for read\n" );
230
open( OUT, ">$outfile" ) || die("Failed to open \"$outfile\" for write\n" );
234
s|<HTML>|<\!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"<HTML>|;
235
s|<HTML>| "http://www.w3.org/TR/html4/loose.dtd"><HTML>|;
237
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
240
\@page { size: 8.5in 11in }
241
TD P { color: #000000; font-family: "Verdana", "Arial", "Helvetica", sans-serif; font-size: 12pt }
242
P { color: #000000; font-family: "Verdana", "Arial", "Helvetica", sans-serif; font-size: 12pt }
243
H2 { color: #000000 }
244
A:link { color: #0085c0 }
245
A:visited { color: #800080 }
249
s|<BODY>|<BODY LANG="en-US" TEXT="#000000" LINK="#0085c0" VLINK="#800080" BGCOLOR="#ffffff">|;
259
s|<DT>|<DD><P></P><DT>|g;
260
s|<DL>|<DL><DT><DD><DL>|g;
261
s|</DL>|</DL></DL>|g;
267
s|unsignedint|unsigned int|g;
275
# Pre-process file into intermediate form
277
# Initializes globals:
279
# @functions - Function names
280
# %synopsis - Function synopsis
283
my($infile, $tmpfile) = @_;
285
my $inpara = 0; # Set to 1 if in paragraph
286
my $inlist = 0; # Set to 1 if in list-item paragraph
289
open( IN, "<$infile" ) || die("Failed to open \"$infile\" for read\n" );
292
open( TMP, ">$tmpfile" ) || die("Failed to open \"$tmpfile\" for write\n" );
297
# Skip past first form feed
313
# Extract and save function title
314
if (m/^%\s+((\w )+)\s+%/) {
315
($ftitle = $1) =~ s/ //g;
316
push(@functions, $ftitle);
317
print( TMP "===$ftitle\n" );
321
# Zap text we don't want
322
next if ( m/^%.+%/ ); # "%*%
325
# Extract and save synopsis info
330
elsif ( m/${ftitle}\(.*\)$/ ) {
344
$synopsis{$ftitle} = $_ . ';'; # Append semi-colon, prototype style
345
print ( TMP " " . $synopsis{$ftitle} . "\n" );
348
elsif ( m/${ftitle}\(.*/ ) {
349
$synopsis{$ftitle} = $_;
353
# Zap text we don't want
354
next if m/^%.+%/; # "%*%
356
$synopsis{$ftitle} .= $_;
358
$_ = $synopsis{$ftitle};
373
$synopsis{$ftitle} = $_ . ';'; # Append semi-colon, prototype style
374
print ( TMP " " . $synopsis{$ftitle} . "\n" );
378
# Keep track of paragraphing
380
if ( $inpara == 0 ) {
381
$inpara = 1; # Start of paragraph
382
$para = "$_"; # Start paragraph string
385
$para .= " $_"; # Add line to paragraph
388
# Keep track of list items so they can
389
# be wrapped as a paragraph
390
if( m/^\s+(o[^:]+:|o|[0-9]\.)\s(.*)/ ) {
394
if ( $inpara == 1 ) {
395
if( $para =~ m/^\s+\S+/ && ! $inlist ) {
396
# Lines that start with a space shouldn't be munged
397
$inpara = 0; # End of paragraph
399
$para .= ""; # Terminate paragraph
400
print( TMP "$para\n" );
404
$inpara = 0; # End of paragraph
406
$para .= ""; # Terminate paragraph
407
$para =~ s/^\s+//g; # Eliminate any leading space
408
$para =~ s/\s+/ /g; # Canonicalize whitespace
409
$para =~ s/ $//; # Trim final space
410
$para =~ s/([a-zA-Z0-9][.!?][)'"]*) /$1 /g; #' Fix sentance ends
411
print( TMP "\n$para\n\n" );
422
# Process into formatted form
425
my($infile, $outfile) = @_;
429
my $inlist = 0; # Set to one if in indented list
432
open( IN, "<$infile" ) || die("Failed to open \"$infile\" for read\n" );
435
open( OUT, ">$outfile" ) || die("Failed to open \"$outfile\" for write\n" );
438
print( OUT head1("NAME") );
439
if (!defined($whatis{$base})) {
440
print("Whatis definition missing for \"$base\"!\n");
441
print( OUT "${base} - Unknown\n\n" );
443
print( OUT "${base} - $whatis{$base}\n\n" );
446
# Synopsis field (function signatures)
447
print( OUT head1("SYNOPSIS") );
448
foreach $func (sort( @functions )) {
449
if (defined $synopsis{$func} ) {
450
$_ = $synopsis{$func};
454
print( OUT $synopsis, "\n\n" );
459
print( OUT head1("FUNCTION DESCRIPTIONS") );
466
if( m/^(o[^:]+:|o|[0-9]\.?)\s(.*)/ ) {
468
my $bullet_text = $2;
470
print( OUT startlist() ) unless $inlist;
472
print( OUT item($bullet), "$bullet_text\n\n" );
475
print( OUT endlist() ) if $inlist;
479
# Match synopsis item
480
if( defined $func && m/$func\s*\(.*\)/ ) {
481
# Split all words with spaces to aid with tokenization
489
# Replace tokens matching keywords with HTML links.
490
TOKEN: foreach $token ( split(' ', $_ ) ) {
491
foreach $keyword ( %keywords ) {
492
if ( $token eq $keyword ) {
493
$html .= linked( $keyword, $keywords{$keyword} );
501
# Remove excess spaces
509
# This is very poor because text is output specifically
510
# for HTML so the text isn't output at all for other target
512
print( OUT html("<blockquote>$_</blockquote>") );
516
# Match function title
517
if( m/===([a-zA-Z0-9]+)/ ) {
519
print( OUT head2($func) );
523
print( OUT "\n") if /^[^ ]/;
525
print( OUT "\n") if /^[^ ]/;
533
# Return level 1 heading
534
# Similar to: <H1>heading</H1>
538
return( "=head1 $heading\n\n" );
542
# Return level 2 heading
543
# Similar to: <H2>heading</H2>
547
return( "=head2 $heading\n\n" );
557
return( "=item $item\n\n" );
566
return( "=over 4\n\n" )
574
return( "=back\n\n" );
579
# Similar to <PRE></PRE>
583
return( " $text\n\n" );
591
return return( "=for html $html\n\n" );
596
# Similar to: <A HREF="url">description</A>
599
local($description, $url) = @_;
600
return( "<A HREF=\"" . $url . "\">" . $description . "</A>" );