### ### DirHotBar ### ### Produce a hot bar that includes a next and previous link, ### as well as information from the HOTBAR file. ### ### The next and prev links come from an alphabetical listing ### of directories which contain a "webc" directory. ### ### Call with: ### #call DirHotBar HOTBAR.FILE ### ### The HOTBAR.FILE indicates which buttons to put on the ### hotbar. ### ### It might be nice to have images associated with buttons. ### ### Include this file with "#localcode DirHotBar.lc". ### ### This is very tailored for use in the cornvalley directory. ### use Cwd; $DirHotBarRoot = "/export/virtual-www/cornvalley"; sub DirHotBar { my($args) = @_; my($prev, $next); my($basename, $dir, @dirs, $fname, $hotbar, $idx, $item, $last, $mydir, $name, @names, $slash, $value, @values); # First find the previous and next information $prev = ""; $next = ""; ($hotbar) = split(/\s+/, $args); if ($hotbar eq "") { print OUT "Usage: #call DirHotBar HOTBAR.FILE\n"; return; } $hotbar = "$Directory/$hotbar" if ($hotbar !~ m#^/#); $hotbar = CanonFname($hotbar); # Find the pairs of URLs/description from the hotbar file. if (!open(HB, "<$hotbar")) { print OUT "Cannot open hotbar file $hotbar\n"; } else { while () { chomp; next if (/^#/ || /^\s*$/); s/^\s*//; ($name, $value) = split(/\s+/, Expand($_), 2); next if (!defined(!$value)); push(@names, $name); push(@values, $value); } close HB; } # Find all of the directories which are possibilities @dirs = findpattern($DirHotBarRoot, "webc.src", 1); return if (scalar(@dirs) == 0); # @dirs = sort(`find $DirHotBarRoot -name webc.src -a -type d`); $mydir = cwd(); $mydir =~ s#/webc.src/?##; $mydir =~ s#.*$DirHotBarRoot#$DirHotBarRoot#; # Deal w/ NFS names for $dir (@dirs) { chomp $dir; $dir =~ s#^\./##; $dir =~ s#/webc.src/?##; } @dirs = sort { lc($a) cmp lc($b) } @dirs; $prev = ""; $prev = "$dirs[$#dirs]/" if (defined($dirs[$#dirs])); $next = ""; for ($idx = 0; $idx < scalar(@dirs); $idx++) { if ($dirs[$idx] eq $mydir) { $next = $dirs[0]; $next = $dirs[$idx + 1] if (defined($dirs[$idx + 1])); last; } $prev = $dirs[$idx]; } $next =~ s#$DirHotBarRoot##; $prev =~ s#$DirHotBarRoot##; #print STDERR "prev is |$prev| next is |$next|\n"; # OK. We've now got all the information we are going to get. # It's time to emit the code. print OUT Expand($Symbols{'__HR__'}) . "\n"; $slash = ($prev =~ /.html/) ? "" : "/"; print OUT "[Previous]\n" if ($prev ne ""); for ($item = 0; $item <= $#names; $item++) { $basename = $names[$item]; $basename =~ s/\.[^.]*$//; if (($Symbols{'__FILE__'} =~ m#/$basename#) || ($Symbols{'__FILE__'} =~ m#^$basename#)) { print OUT "[$values[$item]]\n"; } else { $basename = $names[$item]; $basename .= ".html" if ($basename !~ /\./); $slash = ($basename =~ /.html/) ? "" : "/"; print OUT "[$values[$item]]\n"; } } $slash = ($next =~ /.html/) ? "" : "/"; print OUT "[Next]\n" if ($next ne ""); print OUT Expand($Symbols{'__HR__'}) . "\n"; } ### ### findpattern ### ### Look for a directory of a certain name. Only go down two levels. ### sub findpattern { my($root, $name, $level) = @_; my($file, @files, @retval); return @retval if ($level > 2); opendir(DIR, $root) || return @retval; @files = sort(grep(!/^\./, readdir(DIR))); closedir DIR; for $file (@files) { if ($file eq $name && $level == 2) { push(@retval, "$root/$file"); } elsif (-d "$root/$file") { push(@retval, findpattern("$root/$file", $name, $level + 1)); } } return @retval; } return 1;