Turn perl or C program listings into html with line numbers. Link header, module, data or other files to the source.

I use this all the time for my own hompage when I try to get help with programs I am writing. Let me know what you think.

WEBIFY.PL
#!/usr/bin/perl use Text::Tabs; $tabstop = 4; $target = shift @ARGV; open ( FILE, "<$target"); chomp ( @code = <FILE> ); close FILE; foreach $line (@code) { $line =~ s/\</&#60;/; $line =~ s/\>/&#62;/; $line = expand ($line); } unshift @code, "<ol>"; unshift @code, "<code>"; while (@ARGV) { # add links to page # use filename description $linkname = shift; $linkdescrip = shift; $link_html = qq\ <a href="$linkname">$linkdescrip</a>< +br>\; print "Link = $link_html \n"; unshift @code, $link_html; } unshift @code,"<body>"; unshift @code,"<title> $target </title>"; unshift @code, "<html>"; push @code, "</ol>"; push @code, "<" . "/code>"; # split to fool PM formatting! push @code, "</body>"; push @code, "</html>"; open (FILE,">".$target.".html"); $body = 0; foreach $line (@code) { if ( ( $line =~ m/^#.*/) || ( $line =~ m/^\/\*/ ) || ( $line =~ m/^[a-zA-Z0-9_]/) ) { $body = 1; } if ($line =~ m/^\<\/ol\>/) { $body = 0; } if ($body) { print FILE "<LI>".$line."\n"; } else { print FILE $line."\n"; } } close FILE;

Replies are listed 'Best First'.
Re: webify
by talwyn (Monk) on Jul 02, 2002 at 01:02 UTC
    Um... I guess snippets have a limited amount of room... try Talwyn's Scratchpad for a more readable version. Talwyn
      No, you just had a </code> in your source (pay attention to where it got cut off), which threw the Everything engine off.

      Makeshifts last the longest.