[go: up one dir, main page]

File: metadon

package info (click to toggle)
coin3 3.1.3-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 48,344 kB
  • ctags: 70,042
  • sloc: cpp: 314,328; ansic: 15,927; sh: 13,635; makefile: 8,780; perl: 2,149; lex: 1,302; lisp: 1,247; yacc: 184; xml: 175; sed: 68
file content (523 lines) | stat: -rwxr-xr-x 18,071 bytes parent folder | download | duplicates (10)
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
#!/usr/bin/perl
############################################################################
#
#  metadon - meta documentation system
#
#  The file Metadon.conf is the starting point.  Source files can include
#  comments for the meta documentation by inserting /* ... */ comments.
#  Flags and weights in all the *.metadon files decides how the module
#  progress is calculated.
#
#  I might document this a bit better later...
#
#  Hacked in perl by Lars J. Aas <larsa@sim.no>, 1998-2000.
#

if (@ARGV != 2) { die "Usage: metadon <topsrcdir> <outputdir>\n" };

$coindir = @ARGV[0];
$docdir = @ARGV[1];
$docdir =~ s/\/$//; # strip trailing slash, if any

$indentsize = 4;

$defaultweight = 1;
$defaultmoduleweight = 1;
$progressfactor = 0.5;

$bgcolor = "#000000";
$textcol = "#cccccc";

############################################################################

%parent    = ();
%comments  = ();
@flags     = ();
%flagvals  = ();
$date = `date "+%d. %B, %Y - %X (%Z)"`;

&GenGifs();

&LoadConfig();

open( IDX, "$docdir/index.html" );
chop( @index = <IDX> );
close( IDX );
@index = grep( /<!--OPEN-->/, @index );
foreach ( @index ) { s/^.*<!--OPEN-->//; s/<!--CLOSE-->.*//; }

open( INDEX, "> $docdir/index.html" );
print INDEX "<html><head><title>", $globalname, " Development</title></head>\n",
    "<body bgcolor=$bgcolor text=$textcol link=$textcol vlink=$textcol>\n",
    "<h1 align=center>", $globalname, " Development</h1>\n",
    "<hr><p align=center><img src=http://www.sim.no/images/dilbert1.gif></p>\n",
    "<hr>\n<p>\n",
    "<table columns=3 width=100%>";

$total = 0;
$allweights = 0;
$filenum = 0;

for ( $mod = 0; $mod < @configfiles; $mod++ ) {
    $configfile = $configfiles[$mod];
    $modweight = $moduleweights[$mod];

    if ( $configfile eq "separator" ) {
        print INDEX "<tr><td width=33%>&nbsp;</td>\n",
                    "<td width=33%></td><td width=33%></td></tr>\n";
        next;
    }

    @commenttext = ();
    next if ! &ReadConfig( "$coindir/$configfile" );

    $path = $configfile;
    $path =~ s#/[^/]+$##;
    $dir = $path;
    $dir =~ s/^.*\///;

    $filenum++;

    &FindInheritance( scalar( @flags ), @hierarchy );
    &LoadComments( $path );

    $comments = join( "\n", @comments );
    $comments =~ s/\n\n/<p>/g;

    print "$docdir/file$filenum.html ($module)\n";
    open( HTML, "> $docdir/file$filenum.html" );
    print HTML "<html><head><title>$module</title></head>\n";
    print HTML "<body bgcolor=$bgcolor text=$textcol link=$textcol vlink=$textcol>\n";
    print HTML "<font face=arial>\n";
    &PrintHeader( $module );
    if ( length( $comments ) > 4 ) {
        print HTML "<hr>\n<blockquote>$comments</blockquote>\n";
    }
    print HTML "<hr>\n";
    $totalweight = 0;
    foreach $flagline ( @flags ) {
        $line = $flagline;
        $weight = $defaultweight;
        if ( $line =~ m/\[[0-9,.]+\]$/ ) {
            $weight = $line;
            $weight =~ s/.*\[([0-9\.]+)\]$/\1/;
            print HTML "$line<br>\n";
        } else {
            print HTML "$line [$weight]<br>\n";
        }
        $totalweight += $weight;
    }

    print HTML "<hr>\n";
    $columns = @flags + 1;
    print HTML "<table width=100% columns=$columns cellspacing=0 border=0>\n";
    print HTML "<tr><td colspan=$columns width=100% align=center><font face=arial>LEGEND: (incomplete) <strong>";
    for ( $i = 0.0; $i <= 1.0; $i += 0.05 ) {
        ($rval, $gval, $bval) = &FactorToColor( $i );
        $color = sprintf( "#%02x%02x%02x", $rval*255, $gval*255, $bval*255 );
        print HTML "<font color=$color>X</font>";
    }
    print HTML "</strong> (finished)</font></td></tr>\n";

    print HTML "<tr>";
    foreach $flagline ( @flags ) {
        print HTML "<td align=center><font face=arial>",
                   substr( $flagline, 0, 1 ), "</font></td>";
    }
    print HTML "<td width=100%></td></tr>\n";
    $totalprogress = 0;
    foreach $class ( @classes ) {
        if ( $class =~ / / ) {
            print STDERR "Class hierarchy parse error ($class):\n",
                         " - Could be a flag block problem.\n",
                         " - Could be the classname got trailing text.\n";
            next;
        }
        print HTML "<tr>";
        $classdepth = 0;
        $temp = $class;
        while ( defined $parent{$temp} && $temp ne "" ) {
            $classdepth++;
            $temp = $parent{$temp};
        }
        ( $to, $tc ) = ( "<font face=helvetica>", "</font>" );
        $color = "black";
        $value = 1.0;
        for ( $i = 0; $i < @flags; $i++ ) {
            $weight = $defaultweight;
            if ( $flags[$i] =~ /\[[0-9\.]+\]$/ ) {
                $weight = $flags[$i];
                $weight =~ s/.*\[([0-9\.]+)\]$/\1/;
            }
            $weight = $weight / $totalweight;
            $char = substr( $flagvals{$class}, $i, 1 );
            if ( $char =~ m#[A-Z!-]# ) {
                print HTML "<td><img src=g.gif></td>";
            } elsif ( $char =~ m#[a-z]# ) {
                $value -= $weight * $progressfactor;
                print HTML "<td><img src=y.gif></td>";
            } else {
                $value -= $weight;
                print HTML "<td><img src=r.gif></td>";
            }
        }
        $totalprogress += $value;
        if ( $value == 1.0 ) {
            $to .= "<em><strong>";
            $tc = "</strong></em>" . $tc;
        }
        ( $rval, $gval, $bval ) = &FactorToColor( $value );
        $color = sprintf( "#%02x%02x%02x", $rval*255, $gval*255, $bval*255 );
        $indent = "&nbsp;" x ($classdepth*$indentsize);
        $flagvals{$class} =~ s/ /&nbsp;/g;
        print HTML "<td><font color=$color face=arial>$indent$to$class$tc";
        my $valuestr = sprintf("%.2f", ($value < 0.01) ? 0 : $value);
        print HTML " <font color=$textcol>(\"$flagvals{$class}\" = $valuestr)</font>";
        if ( defined $comments{$class} ) {
            print HTML "[<a href=#", $class, ".comments>comments</a>]\n";
            push( @commenttext, "<a name=$class.comments><strong>$class</strong></a>" );
            push( @commenttext, "<ul>" );
            foreach $comment ( split( "\n", $comments{$class} ) ) {
                push( @commenttext,  "<li><em>$comment</em>" );
            }
            push( @commenttext, "</ul>" );
        }
        print HTML "</font></td></tr>\n";
        print HTML "</td>";
        $last = $class;
        print HTML "</tr>\n";
    }
    print HTML "</table>\n",
               "<p align=center>\n";
    $value = $totalprogress / @classes;
    $moduleweight += $value;
    ( $rval, $gval, $bval ) = &FactorToColor( $value );
    $color = sprintf( "#%02x%02x%02x", $rval*255, $gval*255, $bval*255 );

    $color = "#555555" if ( $modweight == 0.0 );
   
    ( $po, $pc ) = ( '', '' );
    if ( $value == 1.0 ) {
        ( $po, $pc ) = ( '<strong><em>', '</em></strong>' );
    }
    print HTML "$po<font color=$color>total progress: ",
               sprintf( "%5.3f", $value ), "</font>$pc<p>\n";
    print HTML "<hr>", join( "\n", @commenttext );
    print HTML "<p>\n";
    print HTML "<div align=right><hr>",
               "<font size=-2><em>Generated with Metadon</em></font>\n";
    print HTML "</font></body></html>\n";
    close( HTML );
    print INDEX "<tr><td width=33%>",
                "<!--OPEN--><a href=file$filenum.html>",
                "<font color=$color>$po$module$pc</font></a><!--CLOSE--></td>",
                "<td width=33%><font face=arial>";
    for ( $c = 0.0; $c <= 1.0; $c += 0.05 ) {
        ( $r, $g, $b ) = &FactorToColor( $c );
        $col = sprintf( "#%02x%02x%02x", $r*255, $g*255, $b*255 );
        print INDEX "<font color=$col>X</font>" if $c < $value;
    }
    print INDEX "</font></td>";
    print INDEX "<td><font color=$color>$po(", sprintf( "%2d%%", $value * 100 ),
                " finished)";
    print INDEX " [", scalar( @flags ), " flags]</font></td></font></tr>\n";
    print INDEX "$pc</font></td></font></tr>\n";
    if ( $modweight != 0.0 ) {
        $allweights += $modweight;
        $total += $modweight * $value;
    }
}

print INDEX "<tr><td width=33%>&nbsp;</td><td width=33%></td><td width=33%></td></tr>\n";

$value = $total / $allweights;
( $r, $g, $b ) = &FactorToColor( $value );
$color = sprintf( "#%02x%02x%02x", $r*255, $g*255, $b*255 );

print INDEX "<tr><td width=33%><font color=$color>",
            "<strong>Totally Bogus $name Total</strong></font></td>";
print INDEX "<td width=33%><font face=arial>";
for ( $c = 0.0; $c <= 1.0; $c += 0.05 ) {
    ( $r, $g, $b ) = &FactorToColor( $c );
    $col = sprintf( "#%02x%02x%02x", $r*255, $g*255, $b*255 );
    print INDEX "<font color=$col>X</font>" if $c < $value;
}
print INDEX "</font></td>",
            "<td><font color=$color>$po(", sprintf( "%2d%%", $value * 100 ),
            " finished)$pc</font></td></font>\n",
            "</table>\n<p>\n<hr>\n";

$globalcomments = join( "\n", @globalcomments );
$globalcomments =~ s/\n\n/<p>/g;

print INDEX "<blockquote>\n$globalcomments\n</blockquote>\n<hr>\n";

print INDEX "<div align=right>\n",
            "<font size=-2><em>Generated with Metadon, $date</em></font>\n";
print INDEX "</body></html>\n";
close( INDEX );

############################################################################
# subroutine that returns all the _files_ from $basedir and inwards (only
# following real directories) that has a filename (excluding the leading path)
# that matches the regular expression in $filenameexp.

sub FindFiles {
    local( $basedir, $filenameexp ) = ( @_ );
    local( @files, @entries, $entry, $pathname ) = ();
    opendir( DIRECTORY, $basedir );
    @entries = readdir( DIRECTORY );
    closedir( DIRECTORY );
    foreach $entry ( @entries ) {
        next if ( $entry eq "." || $entry eq ".." );
        $pathname = join( '/', $basedir, $entry );
        if ( -f $pathname ) {
            push( @files, $pathname ) if ( $entry =~ /$filenameexp/ );
        } elsif ( -d $pathname ) {
            push( @files, &FindFiles( $pathname, $filenameexp ) );
        }
    }
    return sort( @files );
} # sub FindFiles

############################################################################

sub LoadConfig {
    local( %tags ) = ( 'NAME', 1, 'MODULES', 1, 'COMMENTS', 1 );
    local( @config, $i, $weight, $tag ) = ();

    @globalcomments = ();
    @configfiles = ();
    @moduleweights = ();
    $globalname = "";

    open( CONFIG, "$coindir/Metadon.conf" ) ||
        die "Metadon.conf: could not open file.\n";
    chop( @config = <CONFIG> );
    close( CONFIG );

    @config = grep( /^#/, @config );
    foreach $line ( @config ) {
        $line =~ s/^#\s*//;
        $line =~ s/\s*$//;
    }

    for ( $i = 0; $i < @config; $i++ ) {
        if ( defined $tags{$config[$i]} ) {
            $tag = $config[$i];
            next;
        }
        if ( $config[$i] eq "" && $tag ne 'COMMENTS' ) {
            $tag = '';
            next;
        }
        if ( $tag eq 'NAME' ) {
            $globalname = $config[$i];
            next;
        }
        if ( $tag eq 'MODULES' ) {
            $weight = $defaultmoduleweight;
            if ( $config[$i] =~ / \[[0-9\.]+\]$/ ) {
                ( $config[$i], $weight ) =
                    ( $config[$i] =~ m/^([^\s]+)\s+\[([0-9\.]+)\]$/ );
            }
            push( @configfiles, $config[$i] );
            push( @moduleweights, $weight );
            next;
        }
        if ( $tag eq 'COMMENTS' ) {
            if ( $config[$i] eq 'END COMMENTS' ) {
                $tag = '';
                next;
            }
            push( @globalcomments, $config[$i] );
            next;
        }
    }
    @config = ();
}

############################################################################
# subroutine that sill open a file and extract information from it.
# designed for files of the *.metadon type.

sub ReadConfig {
    local( $filename ) = ( @_ );
    local( $i, @body ) = ( );

    open( FILE, $filename );
    chop( @body = <FILE> );
    close( FILE );
    @body = grep( /^#/, @body );    # grep for comment text
    foreach ( @body ) { s/^# ?//; } # remove comment prefix
    foreach ( @body ) { s/\s*$//; } # remove trailing whitespace

    while ( $body[0] !~ /^CONFIG/ && @body > 0 ) {
        shift( @body );
    }

    @tags = ( '^FLAGS', '^HIERARCHY$', '^COMMENTS$', '^END$' );

    @flags = ();
    @hierarchy = ();
    @comments = ();

    $i = 1;
    while ( $i < @body ) {
        for ( $c = 0; $c < @tags; $c++ ) {
            if ( $body[$i] =~ /$tags[$c]/ ) {
                if ( $body[$i] =~ /^FLAGS/ ) {
                    if ( $body[$i] =~ /^FLAGS *\[[0-9\.]+]/ ) {
                        $defaultweight = $body[$i];
                        $defaultweight =~ s/.*\[([0-9\.]+)\]$/\1/;
                    }
                    for ( $i++; $body[$i] ne "" && $i < @body; $i++ )
                      { push( @flags, $body[$i] ); }
                } elsif ( $body[$i] eq 'HIERARCHY' ) {
                    for ( $i++; $body[$i] ne "" && $i < @body; $i++ )
                      { push( @hierarchy, $body[$i] ); }
                } elsif ( $body[$i] eq 'COMMENTS' ) {
                   for ( $i++; $body[$i] ne "END COMMENTS" && $i < @body; $i++ )
                      { push( @comments, $body[$i] ); }
                }
                $c = @tags;
            }
        }
        $i++;
    }

    $module = $body[0];
    $module =~ s/^CONFIG\s*\"(.*)\"\s*$/\1/;

    return 0 if @hierarchy < 1;
    return 1;
} # sub ReadConfig

############################################################################
# subroutine that will from space indentation deduce the inheritance
# hierarchy of the items in the list.  The hierarchy information is inserted
# into the associative array named %parent.

sub FindInheritance {
    local( $flags, @list ) = ( @_ );
    local( @namestack, @indentstack ) = ();
    local( $name, $indent, $linenum ) = ();

    @classes = ();
    $linenum = 1;
    push( @namestack, "" );
    push( @indentstack, 0 );
    foreach $item ( @list ) {
        $linenum++;
        $flagstring = substr( $item, 0, $flags );
        $name = substr( $item, $flags );
        $indent = $name;
        $indent =~ s/[^ ]*$//;
        $indent = length( $indent ); # numeric length instead of string
        $name =~ s/^ *//;
#        $name =~ s/\s.*//; # only first word
        push( @classes, $name );
        $flagvals{$name} = $flagstring;
        if ( $indent > $indentstack[$#indentstack] ) { # indented further
            $parent{$name} = $namestack[$#namestack];
            push( @indentstack, $indent );
            push( @namestack, $name );
        } elsif ( $indent == $indentstack[$#indentstack] ) { # same indentation
            $parent{$name} = $namestack[$#namestack-1];
            $namestack[$#namestack] = $name;
        } else { # less indentation
            while ( $indent < $indentstack[$#indentstack] ) {
                pop( @indentstack );
                pop( @namestack );
            }
            if ( $indent == $indentstack[$#indentstack] ) { # same indent
                $parent{$name} = $namestack[$#namestack-1];
                $namestack[$#namestack] = $name;
            } else {
                print STDERR "Error: hierarchy entry #", $linenum,
                    " has illegal indentation ($name).\n";
            }
        }
    }
} # sub FindInheritance

############################################################################

sub LoadComments {
    local( $path ) = ( @_ );
    local( $file, $class, $data, @comments ) = ();

#   print "&LoadComments( \"$path\" );\n";
    foreach $file ( &FindFiles( $path, '\.cpp$' ) ) {
        $class = $file;
        $class =~ s/\.cpp$//;
        $class =~ s/.*\///;
        $data = ();
        open( FILE, $file ) || print STDERR "error: \!: $file\n";
        read( FILE, $data, (stat( $file ))[7] );
        close( FILE );
        $data =~ tr/\n/ /;
        @comments = ();
        @comments = split( '/*', $data );
        shift( @comments );
        
        if ( @comments > 0 ) {
            foreach ( @comments ) {
                s#^\s+##;
                s#\s*\*/.*##;
                s/\s+/ /g;
            }
            $comments{$class} = join( "\n", @comments );
        }
    }
} # sub LoadComments

############################################################################

sub FactorToColor {
    local( $factor ) = ( @_ );
    local( $rval, $gval, $bval ) = ( 0.0, 0.0, 0.0 );

    $rval = 1.0 - $factor;
    $gval = $factor;
    $rval = sin( 3.141593/2 * $rval );
    $gval = sin( 3.141593/2 * $gval );
    ( $rval, $gval, $bval );
} # sub FactorToColor

############################################################################

sub PrintHeader {
    local( $label ) = ( @_ );
    print HTML "<div align=center>\n";
    for ( $c = 0; $c < @index; $c++ ) {
        if ( $index[$c] =~ /$label/ ) {
            print HTML "<h1 align=center>$label</h1>\n",
        } else {
            print HTML $index[$c], "<br>\n";
        }
    }
    print HTML "<div align=left>";
} # sub PrintHeader

############################################################################

sub GenGifs {
    open( GIF, "> $docdir/r.gif" );
    print GIF pack( "A6C36", "GIF87a", 0x9,0,0xc,0,0xf0,0,0,0xff,0,0,
                    0,0,0,0x2c,0,0,0,0,0x9,0,0xc,0,0,0x2,0x8,0x84,
                    0x8f,0xa9,0xcb,0xed,0xf,0xa3,0x3c,0x5,0,0x3b );
    close( GIF );
    open( GIF, "> $docdir/g.gif" );
    print GIF pack( "A6C36", "GIF87a", 0x9,0,0xc,0,0xf0,0,0,0,0xff,0,
                    0,0,0,0x2c,0,0,0,0,0x9,0,0xc,0,0,0x2,0x8,0x84,
                    0x8f,0xa9,0xcb,0xed,0xf,0xa3,0x3c,0x5,0,0x3b );
    close( GIF );
    open( GIF, "> $docdir/y.gif" );
    print GIF pack( "A6C36", "GIF87a", 0x9,0,0xc,0,0xf0,0,0,0xf0,0xb4,0,
                    0,0,0,0x2c,0,0,0,0,0x9,0,0xc,0,0,0x2,0x8,0x84,
                    0x8f,0xa9,0xcb,0xed,0xf,0xa3,0x3c,0x5,0,0x3b );
    close( GIF );
}

############################################################################