#!/usr/local/bin/perl # A "salami machine" for readying data for WWW/Mosaic # # (C) Rob Hartill 1994 # 1st read the configuration file... $config_file = $0; $config_file =~ s#.pl$#.ph#; open ( CONFIG , "$config_file" ) || die "Error. I was unable to open $config_file"; @configuration = ; close ( CONFIG ); # Process the configuration file while ( $#configuration ) { $setting = shift(@configuration); next if $setting =~ /^#/ || $setting eq "\n"; chop $setting; ($variable, $value) = split(/ is /,$setting); $set{$variable} = $value; } #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # Process any configuration settings $set{STRIPFROMURL} =~ s/(\W)/\\$1/g; #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # Ok lets try to open the input file #print "sort $set{SORTFLAGS} -t\\$set{DELIMITER} $set{INFILE} \n"; if ( $set{SORTFLAGS} ne "none" ) { open ( INFILE , "sort $set{SORTFLAGS} -t\\$set{DELIMITER} $set{INFILE} |" ) || die "Error, I was unable to open $set{INFILE}"; } else { open ( INFILE , "$set{INFILE}" ) || die "Error, I was unable to open $set{INFILE}"; } $records_output_this_page = 0; $records_output_this_group = 0; $this_index = 1; # INDEXLENGTH links per index page. Start with index_1.html $links_indexed = 0; @fields = split(/,/, $set{ORDER}); for ($key=0; $key ) { chop; @line = split(/$set{DELIMITER}/, $_); unshift(@line,""); # add an empy element so that the real array starts ind 1 $lastindex = @line[$set{SORTFIELD}]; $firstindex = $lastindex if !defined $firstindex; if ( (defined $last_divide && $set{DIVIDEFIELD} != 0 && $last_divide ne @line[$set{DIVIDEFIELD}]) || $records_output_this_page == $set{PAGESIZE} ) { if ( $nail ne "" || $group ne "" ) { $nails =~ s/\.JPG"/\.GIF"/g; $page .= "$nails

\n$group\n"; } print PART "

Entries $firstindex to $lastindex

\n"; if ( $set{DIVIDEFIELD} != 0 ) { $extra = "$set{DIVTITLE} @line[$set{DIVIDEFIELD}]: "; } else { $extra = ""; } if ( $firstindex ne $lastindex ) { $lastindex = "to $lastindex"; } else { $lastindex = ""; } $big_index .= "
  • $extra$firstindex $lastindex
  • \n"; if (++$links_indexed == $set{INDEXLENGTH} ) { &new_index(); } print PART "$page\n"; $group = ""; $nails = ""; $page = ""; undef $firstindex; $records_output_this_group = 0; $records_output_this_page = 0; &open_new_part(); } $last_divide = @line[$set{DIVIDEFIELD}]; @line[$set{LINKFIELD}] =~ s/$set{STRIPFROMURL}//; $numbdir = @line[$set{LINKFIELD}]; $numbdir =~ s/[^0-9]//g; $numbdir = int($numbdir / 100); $numbdir = sprintf("%04d/",$numbdir); $set{NUMBEREDDIRECTORIES} = "GIFJPEG" if $set{NUMBEREDDIRECTORIES} =~ "ON"; if ( $set{NUMBEREDDIRECTORIES} =~ /GIF/ ) { $gifnumbdir = $numbdir; } else { $gifnumbdir = ""; } if ( $set{NUMBEREDDIRECTORIES} =~ /JPEG/ ) { $jpegnumbdir = $numbdir; } else { $jpegnumbdir = ""; } if ( $thumbnail ) { $nails .= "\"THUMBNAIL\""; } #-- display one the current record. foreach $field ( @fields ) { if ( $set{HOTFIELD} == $field ) { $line[$field] = "@line[$field]" } $group .= " @line[$field]"; } $group .= "
    \n"; $records_output_this_page++; $records_output_this_group++; if ($records_output_this_group >= $set{GROUPSIZE} ) { $nails =~ s/\.JPG"/\.GIF"/g; $page .= "$nails

    \n$group\n"; $group = ""; $nails = ""; $records_output_this_group = 0; } } if ( $page ne "" || $nails ne "" || $group ne "" ) { $nails =~ s/\.JPG"/\.GIF"/g; $page .= "$nails

    \n$group\n"; print PART "

    Entries $firstindex to $lastindex

    \n"; print PART "$page\n"; if ( $set{DIVIDEFIELD} != 0 ) { $extra = "$set{DIVTITLE} @line[$set{DIVIDEFIELD}]: "; } else { $extra = ""; } if ( $firstindex ne $lastindex ) { $lastindex = "to $lastindex"; } else { $lastindex = ""; } $big_index .= "
  • $extra$firstindex $lastindex
  • \n"; close(PART); } &new_index(); #--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- sub new_index { open ( MAININDEX, ">$set{OUTDIR}/index_$this_index".".html") || die "Error, I was unable to open $set{OUTDIR}/index_$this_index".".html"; print MAININDEX " $set{INDEXHEADER}

    $set{INDEXHEADER}


      $big_index
    Index page: "; printf MAININDEX "[First]" if $this_index >1; printf MAININDEX "[Previous]",$this_index-1 if $this_index >2; printf MAININDEX "[Next]",$this_index+1 if $links_indexed == $set{INDEXLENGTH}; print MAININDEX " "; close(MAININDEX); $this_index++; $big_index = ""; $links_indexed = 0; } #--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- sub open_new_part { print PART "
    \nPage: "; printf PART "[First]" if $partnumber >2; printf PART "[Previous]",$partnumber-1 if $partnumber >1; printf PART "[Next]",$partnumber+1; printf PART " [Index]"; close (PART); $partnumber++; open ( PART, ">$set{OUTDIR}/Part$partnumber".".html") || die "Error, I was numable to open $set{OUTDIR}/Part$partnumber".".html"; printf PART " %s

    %s

    Page: $partnumber

    ",$set{RUNNINGHEADER},$set{RUNNINGHEADER}; }