#!/usr/bin/perl # This program turns a bunch of index.txt files into tables of stuff # creates *.idx0 files from *.txt files, and a indexdata.idx1 and # indexdata.html file from the *.idx0 files. # # ... this language is crazy too.. $fullpathnameidx1 = $ARGV[0] . "/indexdata.idx1"; $fullpathnamehtml = $ARGV[0] . "/indexdata.html"; opendir DIR, $ARGV[0] or die "Can't open the current directory"; while (defined($file = readdir(DIR))) { next if ($file eq "."); next if ($file eq ".."); next if (!($file =~ m/.txt$/)); $idx0file = $file; $idx0file =~ s/.txt$//; $idx0file .= ".idx0"; %macs = (); print $file . "\n"; $fullpathname = $ARGV[0] . "/" . $file; $fullpathnameidx0 = $ARGV[0] . "/" . $idx0file; open FILEX, "<", $fullpathname or die "oops"; while (defined($voom = )) { chomp($voom); $voom =~ s/^\s+//; $voom =~ s/\s+$//; next if (length($voom) == 0); next if (substr($voom,0,1) eq "/"); $voom =~ s/^\*//; if ($voom =~ m/,/) { @stuffs = split (',', $voom); if (defined($stuffs[1])) { next if ((substr($stuffs[1],0,1) eq "-") && (substr(reverse($stuffs[1]),0,1) eq "-")); $stuffs[0] =~ s/\s+$//; next if (length($stuffs[0]) == 0); $macs{$stuffs[0]} = "y"; } else { next if (length($stuffs[0]) == 0); if (!defined($macs{$stuffs[0]})) { $macs{$stuffs[0]} = "n"; } } } else { next if ((substr($voom,0,1) eq "-") && (substr(reverse($voom),0,1) eq "-")); $macs{$voom} = "y"; } } close FILEX; @sortedmacs = sort { lc($a) cmp lc($b) } keys %macs; open FILEO, ">", $fullpathnameidx0 or die "oops"; foreach (@sortedmacs) { print FILEO $macs{$_} . " " . $_ . "\n"; } close FILEO; undef %macs; } closedir DIR; undef %macs; %macsall=(); opendir DIR, $ARGV[0] or die "Can't open the current directory"; while (defined($file = readdir(DIR))) { next if ($file eq "."); next if ($file eq ".."); next if (!($file =~ m/.idx0$/)); print $file . "\n"; $fullpathname = $ARGV[0] . "/" . $file; open FILEX, "<", $fullpathname or die "oops"; while (defined($voom = )) { chomp($voom); $b = substr($voom, 3); $macsall{$b} = ""; } close FILEX; } closedir DIR; $v = 0; opendir DIR, $ARGV[0] or die "Can't open the current directory"; while (defined($file = readdir(DIR))) { next if ($file eq "."); next if ($file eq ".."); next if (!($file =~ m/.idx0$/)); $indexname[$v] = $file; $indexname[$v] =~ s/.idx0$//; print $file . "\n"; $fullpathname = $ARGV[0] . "/" . $file; open FILEX, "<", $fullpathname or die "oops"; while (defined($voom = )) { chomp($voom); $a = substr($voom, 0,1); $b = substr($voom, 3); $macsall{$b} .= $a; } close FILEX; foreach $d (keys %macsall) { if (length($macsall{$d}) == $v) { $macsall{$d} .= " "; } } $v++; } closedir DIR; @sortedmacs = sort { lc($a) cmp lc($b) } keys %macsall; open FILEO, ">", $fullpathnameidx1 or die "oops"; print FILEO "*startlist\n"; $c = 0; foreach (@indexname) { print FILEO $c . "," . $_ . "\n"; $c++ } print FILEO "*endlist\n"; foreach (@sortedmacs) { print FILEO $macsall{$_} . "," . $_ . "\n"; } close FILEO; open FILEO, ">", $fullpathnamehtml or die "oops"; print FILEO ""; print FILEO "index.txt overview"; print FILEO ""; print FILEO ""; $c = 0; print FILEO ""; foreach (@indexname) { print FILEO ""; $c++ } $maxc = $c; print FILEO "
ColumnIndex Name
" . $c . "" . $_ . "



"; print FILEO "Legend:
y = categorized and visible
n = categorized and invisible
  = not mentioned
"; print FILEO "


"; print FILEO ""; print FILEO ""; for ($c = 0; $c < $maxc; $c++) { print FILEO ""; } print FILEO ""; foreach (@sortedmacs) { print FILEO ""; for ($c = 0; $c < $maxc; $c++) { print FILEO ""; } print FILEO ""; } print FILEO "
Machine Name" . $c . "
" . $_ . "" . substr($macsall{$_},$c,1) . "
"; print FILEO ""; print FILEO ""; close FILEO;