<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

#
$version = "fixcounter 0.0.1";

# variables
$debug=0;
# absolute path to the counter file on the website.
$logpath = "/Library/WebServer/Documents/count.shtml";
$logpath1 = "/Library/WebServer/Documents/count1.shtml";

$line = "";
# maximum number of dots printed to the screen in one line
$maxdots = 64;
# global storage for where the dot is
$dotposition = 0;
# indent each row of dots
$indentation = "     ";
# what will the dot look like, will it be an at sign, peroid, comma, dash ...
$step = ".";
$marker = "*";
$dot = ".";

@counterdata = ();
$pads = join ("", "%0", $pad, "d");

# refresh how often?
$refreshhours = 24;
$refreshminutes = 0;
$refreshseconds = 0;
$refreshtime = ((($refreshhours*60)+$refreshminutes)*60)+$refreshseconds;

# open up the counter file
open ($countfile, "$logpath");
@counterdata = &lt;$countfile&gt;;
close($countfile);

@sortarray = ();
blippr("getting the data to sort", $indentation);
$dot = $step;
foreach $linevalue(@counterdata) {
  blip;
  $checkline1 = join("", $linevalue);
  if ($checkline1 =~ m/^&lt;tr.*/) {
    $sortarray[++$#sortarray] = $checkline1;
    };
  };
  

#&lt;tr&gt;&lt;td&gt;&lt;a href="/images/spinningapple.gif"&gt;/images/spinningapple.gif&lt;/a&gt;:&lt;/td&gt;&lt;td&gt;18516&lt;/td&gt;&lt;/tr&gt;

blippr("sorting the file according to the most accessed", $indentation);
for ($i=0; $i&lt;$#sortarray; $i++) {
  $dot = $marker;
  &amp;blip;
  $dot = $step;
  $indentation = join("",$i,"/",$#sortarray,"  ");
  $checkline1 = $sortarray[$i];
  $url1 = join( "", $checkline1);
  $url1 =~ s/^&lt;tr&gt;&lt;td&gt;&lt;a href=\"//;
  $count1 = join( "", $url1);
  $url1 =~ s/\"&gt;.*$//;
  $url1 =~ s/&lt;.*&gt;//;
  $count1 =~ s/^.*&lt;td&gt;//;
  $count1 =~ s/&lt;.*$//;
  $count1 =~ s/\r//;
  $count1 =~ s/\n//;
  $url1 =~ s/\r//;
  $url1 =~ s/\n//;
  $url1 =~ s/lower/upper/;
  for ($j=$i; $j&lt;=$#sortarray; $j++) {
    &amp;blip;
    $checkline2 = $sortarray[$j];
    $url2 = join( "", $checkline2);
    $url2 =~ s/^&lt;tr&gt;&lt;td&gt;&lt;a href=\"//;
    $count2 = join( "", $url2);
    $url2 =~ s/\"&gt;.*$//;
    $url2 =~ s/&lt;.*//;
    $count2 =~ s/^.*&lt;td&gt;//;
    $count2 =~ s/&lt;.*$//;
    $count2 =~ s/\r//;
    $count2 =~ s/\n//;
    $url2 =~ s/\r//;
    $url2 =~ s/\n//;
    $url2 =~ s/lower/upper/;
    if ($count2 &gt; $count1) {
      $sortarray[$j] = $checkline1;
      $sortarray[$i] = $checkline2;
      $url1 = $url2;
      $count1 = $count2;
      $checkline1 = $checkline2;
      }
    elsif ($count2 == $count1) {
#      print "$count2/$count1,$url2 / $url1\n";
#      print "$i/$#sortarray  count2=count1 $url2 $url1\n";
      if (lc($url2) lt lc($url1)) {
#        print "url2&lt;url1\n";
        $sortarray[$j] = $checkline1;
        $sortarray[$i] = $checkline2;
        $url1 = $url2;
        $count1 = $count2;
        $checkline1 = $checkline2;
        }
#      print "$count2/$count1,$url2 / $url1\n\n";
      };
    }
  };

for ($i=0; $i&lt;$#sortarray; $i++) {
  print $sortarray[$i];
  };

$indentation = "     ";
blippr("storing the sorted data", $indentation);
$i=0;
foreach $linevalue(@counterdata) {
  &amp;blip;
  if ($linevalue =~ m/^&lt;tr.*/) {
    $linevalue = $sortarray[$i];
    $i++;
    };
  };

$counterdata[4] = "  &lt;title&gt; Sorted Counter &lt;/title&gt;\r\n";
&amp;savecounters;

############ all done ############
print "\n\n";
exit 0 ;




# save the counter html file
sub savecounters {
  open ($countfile, "&gt;$logpath1");
  foreach $myarray_line(@counterdata) {
    &amp;blip;
    print $countfile "$myarray_line";
    };
  close($countfile);
  };

  

# this is an old message routine from the old adventure game
sub blip {
  print $dot;
  $dotposition++;
  # for some reason perl doesn't handle global variables correctly in an if statement
  # so we localize them for that purpose.
  my $position = $dotposition;
  my $max = $maxdots;
  if ($position &gt;= $max) {
    print "\n",$indentation;
    $dotposition = 0;
    };
  };
  
sub blippr {
  ($msg, $msg2) = @_;
  print "\n\n&lt;",$msg,"&gt;\n",$msg2;
  $dotposition = 0;
  };

</pre></body></html>