#!/usr/bin/perl # Copyright 1997, 1998, 2001, Adrian Offerman # All rights reserved # Chiplist Cutter # Process command line options if ($#ARGV != 0) { print STDERR "Chiplist Cutter\n"; print STDERR "Usage: $0 [chiplist.html]\n"; exit 1; } # Collect NAMEs open (CHIPLIST, "<@ARGV[0]") || # open Chiplist for reading die "Couldn't open \"@ARGV[0]\"\n"; $auto_sectioning = 1; # turn on auto sectioning $section = 'null'; while () { $header_name = 0; if (/CLCUTTER/io) { # inline sectioning if (/BEGIN_SECTION\s*=\s*"([^"]+)"/io) { $auto_sectioning = 0; $section = $1; # set current section } elsif (/END_SECTION/io) { $auto_sectioning = 1; # turn on auto sectioning $section = 'null'; } next; } elsif ($auto_sectioning) { # auto sectioning if (/

; if (/^\s*(\d+(\.\d+)*)\s+/io) { $section = $1; } else { print STDERR "$.: header without section number found\n"; } $_ = $previous_line; $header_name = 1; # current NAME is a header } } if (/NAME\s*=\s*"([^"]+)"/io) { # collect NAMEs if (!defined $names{$1}) { $names{$1} = $section; if ($header_name) { # current NAME is a header $headers{$1} = 1; } } else { print STDERR "$.: NAME redefinition: $1\n"; } } } close CHIPLIST; # to reset $. # Cut Chiplist open (CHIPLIST, "<@ARGV[0]") || # open Chiplist for reading die "Couldn't open \"@ARGV[0]\"\n"; $auto_sectioning = 1; # turn on auto sectioning $section = 'null'; open (OUTPUT, '/dev/null'); # open output for writing $files{'/dev/null'} = 1; while () { if (/CLCUTTER/io) { # inline commands if (/BEGIN_SECTION\s*=\s*"([^"]+)"/io) { $auto_sectioning = 0; $section = $1; # set current section if ($section eq 'null') { # open output for writing open (OUTPUT, '/dev/null'); $files{'/dev/null'} = 1; } else { if (!$files{"cl.$section.html"}) { open (OUTPUT, ">cl.$section.html"); # open output for writing $files{"cl.$section.html"} = 1; print OUTPUT "\n\n\n"; # print OUTPUT "\n\n\n"; print OUTPUT "\n\nChiplist\n\n\n\n\n"; # add header if ($section =~ /((\d+)(\.\d+)*)\.\d+/io) { # add link to super sections print OUTPUT "

\n"; print OUTPUT "home
\n"; print OUTPUT "contents
\n"; print OUTPUT "up one level\n"; print OUTPUT "

\n\n"; } else { print STDERR "$.: unable to resolve parent section\n"; } } else { open (OUTPUT, ">>cl.$section.html"); # open output for writing $files{"cl.$section.html"} = 1; } } } elsif (/END_SECTION/io) { $auto_sectioning = 1; # turn on auto sectioning $section = 'null'; open (OUTPUT, '/dev/null'); # open output for writing $files{'/dev/null'} = 1; } elsif (/INCLUDE/io) { # nothing to be done } else { print STDERR "$.: unrecognized CLCUTTER directive\n"; } next; } elsif ($auto_sectioning) { # auto sectioning if (/

; if (/^\s*(\d+(\.\d+)*)\s+/io) { $section = $1; if (!$files{"cl.$section.html"}) { open (OUTPUT, ">cl.$section.html"); # open output for writing $files{"cl.$section.html"} = 1; print OUTPUT "\n\n\n"; # print OUTPUT "\n\n\n"; print OUTPUT "\n\nChiplist\n\n\n\n\n"; # add header if ($section =~ /((\d+)(\.\d+)*)\.\d+/io) { # add link to super section print OUTPUT "

\n"; print OUTPUT "home
\n"; print OUTPUT "contents
\n"; print OUTPUT "up one level\n"; print OUTPUT "

\n\n\n"; } elsif ($section =~ /^(\d+)$/io) { # root section # add link to super section print OUTPUT "

\n"; print OUTPUT "home
\n"; print OUTPUT "contents\n"; print OUTPUT "

\n\n\n"; } else { print STDERR "$.: unable to resolve section structure: $section\n"; } } else { open (OUTPUT, ">>cl.$section.html"); # open output for writing $files{"cl.$section.html"} = 1; } # generate links to sub sections in parents $previous_line =~ />cl.$parent_section.html"); print PARENT "

\n"; print PARENT "\n"; print PARENT "$_\n"; print PARENT ""; print PARENT "

\n\n"; } else { print STDERR "$.: unable to resolve parent section: $section\n"; } } else { print STDERR "$.: header without section number found\n"; } $previous_line =~ s/HREF\s*=\s*"#([^"]+)"/ if (!defined $names{$1}) { sprintf "danglingHREF=\"cl.$names{$1}.html\""; print STDERR "$.: local HREF dangling: $1\n"; } elsif ($names{$1} eq "null") { sprintf "danglingHREF=\"cl.$names{$1}.html\""; print STDERR "$.: local HREF to null section: $1\n"; } elsif ($headers{$1}) { # referred NAME is a header sprintf "HREF=\"cl.$names{$1}.html\"" } else { sprintf "HREF=\"cl.$names{$1}.html#$1\"" } /egio; print OUTPUT $previous_line; } } s/HREF\s*=\s*"#([^"]+)"/ if (!defined $names{$1}) { sprintf "danglingHREF=\"cl.$names{$1}.html\""; print STDERR "$.: local HREF dangling: $1\n"; } elsif ($names{$1} eq "null") { sprintf "danglingHREF=\"cl.$names{$1}.html\""; print STDERR "$.: local HREF to null section: $1\n"; } elsif ($headers{$1}) { # referred NAME is a header sprintf "HREF=\"cl.$names{$1}.html\"" } else { sprintf "HREF=\"cl.$names{$1}.html#$1\"" } /egio; print OUTPUT; } close PARENT; close CHIPLIST; foreach $file (keys %files) { # add footer open (OUTPUT, ">>$file"); # print OUTPUT "\n", ''; print OUTPUT "\n", "\n"; } close OUTPUT; exit;