www/lib
directory:
Usage:
require "/www/lib/browser-features.pl"; $feature = $browser_features{"feature"};The features currently available for testing are:
"Netscape"
"Scale GIFs"
"Multiple Scaled GIFs"
"Scale GIFs"
if your page has more than a couple GIFs which need to be scaled. If you fail to test for this in particular, the browser may crash!"Tables"
"Backgrounds"
"Dynamic Documents"
You may also specify whether the histogram to be plotted takes advantage of browsers which can scale multiple GIFs. See "Multiple Scaled GIFs"
in the browser-features.pl library. Output will also be compatible (of a fashion) with Lynx.
Usage:
require "/www/lib/hist.pl"; sub lookup { # optional my ($tag, $key, @order) = @_; do lookup functions here; ($total, $val1, $val2 etc.); } sub rewrite { # optional my ($tag, $key) = @_; do rewriting here; ($string, $printable_length); } $histogram = &hist ($tag, \&lookup, \&rewrite, \@order, $canscale, @keys);
&hist
will return a string containing the histogram. The actual format of this string is described below.
\&
lookup and \&
rewrite. Never evaluated, so can be used to pass flags and/or state to those callbacks.&lookup ($tag, $key, @orders);The arguments are:
$
tag&hist
.$
key@
orders\@
orders passed to &hist
.Returned values should be:
($total, $val1, $val2 etc.);Where:
$
total$
val1 etc.@
orders.If \&
lookup is undef
, then the value which would have been passed into $
key is assumed to be a plottable value and will be used.
&rewrite ($tag, $key);Arguments are:
$
tag&hist
.$
keyReturned values should be:
($string, $printable_length);Where:
$
string$
printable_lengthNote that length $
string is not necessarily the same as $
printable_length, since $
string could have an HTML reference associated with it.
If \&
lookup is undef
then the value which would have been passed in as $
key will be used as the label, and length $
key as the length.
undef
are ignored, both in the legend and the histogram plot.If @
order is undef
then only one value per bucket to be plotted is assumed, and no legend will be printed.
$
key in calling both &
lookup and &
rewrite.&hist
returns a string divided into a legend and a histogram. The legend consists of an unordered list of color bars, one for each key in @
keys which is not the undef
value.
The histogram is formatted so that the label for each line is right-justified, followed by the total count for this item, followed by a series of stacked color bars representing the value of each item passed in through \@
orders. The label section has a maximum width of $hist::namewid
characters (default 20, but can be changed before calling &hist
). If the label is too wide to fit within $hist::namewid
characters but can fit if squeezed into the extra spaces before the number representing the total for that item, then those spaces are utilized. Otherwise, the label is printed on a line of its own and all other information on the following line.
The width of the histogram field itself is limited to $hist::barmax
pixels (default 400), or $hist::prewid
ascii characters (default 50).
The order of the colors used is defined in @hist::color_order
, and the colors themselves are defined in %hist::colors
, with each color's value being a reference to an associative array containing "dir"
(the directory within /www/world/cbars containing .gif
files for that color in addition to a dir.gif
file containing a one-pixel-wide gif) and "char"
, which is the character used to plot an ASCII histogram. Each set of stacked color bars is followed by a one-pixel-width black bar. This is to both give a better visual indication of the end of the bar and to have an indication that there are no missing parts of the bar for plotted items wich have a value of 0 (or close enough to 0 to be unplottable).
Immediately after the number representing the total value for the given item is an HTML comment consisting of numbers separated by /
characters. These are the values (in order)for the different bars which are plotted, including values of 0. For example, if an entry has a total of 10, with individual item values of 5, 2, 0, and 3, the value and comment would be:
10<!--5/2/0/3-->
www/world/cbars
contains a set of directories which themselves contain GIF files of color bars with a height of 10 pixels. Given:
%hist::colors
arraythen the path to that image is
www/world/cbars/color/d/n.gifIn addition, a one-pixel-width GIF image exists for each color as:
www/world/cbars/color.gif
Images exist up to 500 pixels wide for each color. The defined colors and directories are:
Usage:
require "/www/lib/date.pl"; $datestr = &date::eval (format, time); $gmtdatestr = &date::gmteval (format, time);The format string can be any string with date fields represented by escape sequences beginning with
%
. The defined sequences are shown below, with example fields for Sunday, January 1, 1995 at 1:45:00pm.
Option Description Example
%a Short weekday name Sun
%A Full weekday name Sunday
%b Short month name Jan
%B Full month name January
%d Day of month between 1 and 31 1
%D Day of month between 01 and 31 01
%H Hour as decimal between 00 and 23 13
%I Hour as decimal between 1 and 12 1
%m Number of month between 1 and 12 1
%M Minute between 00 and 59 45
%n Number of month between 01 and 12 01
%S Second between 00 and 59 00
%p Lowercase am or pm pm
%P Uppercase AM or PM PM
%y Year without century 95
%Y Year with century 1995
%% Literal % %
Usage:
require "/www/lib/date.pl"; $retval = &geturl::http (url, localfile);$retval is positive if the contents of url have been successfully received and written into localfile, negative if the file in localfile has not changed, and zero if there was an error (the remote system was unreachable, the file isn't there or requires authentication, or there was an error in writing localfile).
This library provides a mechanism with which you can lock a file to ensure no other process is also using the file.
Usage:
require "/www/lib/lockfile.pl"; unless (lockfile (filename)) { unable to lock file } process the file unlockfile (filename);