function Form5D1($val, $fill=' ')
{ // Converts a non-negative value to a representation of one
// to five digits with a possible decimal point and a single
// decimal digit, all decimal-point aligned in a string
// field seven characters long with space (or specified
// other character) fill.
$work = floatval(trim($val));
$intpart = intval($work);
$decpart = intval((10.0*$work+0.5)-(10.0*$intpart));
$intstr = substr(str_repeat($fill, 7) . strval($intpart), -5);
$decstr = ($decpart >= 1) ? ".$decpart" : str_repeat($fill, 2);
return $intstr . $decstr;
}
function GetFanData($page)
{
global $gDebug;
debugq("\n
Begin GetFanData with \$page=^q$page^q.\n");
$fanAdd = array();
$fanFileName = FANSDIR . "f$page.htm";
if (file_exists($fanFileName))
{
$fanWork = ExTrim(',', file_get_contents($fanFileName));
$fanAdd[FIELDTITL] = $fanWork[0];
$fanAdd[FIELDCLIS] = $fanWork[1];
}
else
{ $fanAdd[FIELDTITL] = '()';
$fanAdd[FIELDCLIS] = '()';
}
$dbTemp = print_r($fanAdd, true);
debugq("
End GetFanData with $dbTemp.\n");
return $fanAdd;
}
function GlobalParamsIn()
{ // Accept global options by parameter names.
global $gbParamsReady;
global $gDebug;
global $gSearch;
global $gVerbose;
global $gbShowPage;
global $gbFullPage;
global $gbShowTrans;
global $gbAltThumbs;
global $gbEveryThumb;
if (!function_exists('find_opt'))
{
function find_opt($st1=null, $st2=null, $st3=null,
$st4=null, $st5=null, $st6=null )
{ // For a specified group of up to six non-null
// parameter names, find the value of the first of the
// group which is found. The three most ommon patterns
// of uppercase / lowercase letters (aaa, Aaa, AAA)
// are tested in that order. Remember to put the most
// preferred spellings first -- in case of duplicates,
// the first one wins.
$resu = null;
$awork = array();
if ($st1 !== null) $astr[]=$st1;
if ($st2 !== null) $astr[]=$st2;
if ($st3 !== null) $astr[]=$st3;
if ($st4 !== null) $astr[]=$st4;
if ($st5 !== null) $astr[]=$st5;
if ($st6 !== null) $astr[]=$st6;
foreach ($astr as $astrval)
{
$awork[] = strtolower($astrval);
$awork[] = ucwords($astrval);
$awork[] = strtoupper($astrval);
}
foreach ($awork as $val)
{
$work = GetOrDefault($val, null);
if ($work === '')
{ return 1;
}
else if ($work !== null)
{ return $work;
}
}
return null;
}
function find_lc_opt($st1=null, $st2=null, $st3=null,
$st4=null, $st5=null, $st6=null )
{ return strtolower(find_opt($st1, $st2, $st3,
$st4, $st5, $st6) );
}
function one_digit_opt($st1=null, $st2=null, $st3=null,
$st4=null, $st5=null, $st6=null )
{ $temp = find_opt($st1, $st2, $st3,
$st4, $st5, $st6);
if ( ($temp === null) or (empty($temp)) )
{ return intval(0);
}
else
{ $tempI = intval($temp);
if ($tempI < 1)
{ return intval(0);
}
else if ($tempI > 9)
{ return intval(9);
}
else
{ return $tempI;
}
}
}
function one_bit_opt($st1=null, $st2=null, $st3=null,
$st4=null, $st5=null, $st6=null )
{ $temp = find_opt($st1, $st2, $st3,
$st4, $st5, $st6);
if ( ($temp === null) or (empty($temp)) )
{ return 0;
}
else
{ return intval(1);
}
}
}
// Recognize keywords for debug level ($gDebug).
$gDebug = one_digit_opt('d', 'db', 'debug');
// Recognize keyword for Search.
$gSearch = find_opt('s', 'search');
// Recognize keyword for Web publication.
$gbShowPage = one_bit_opt('webcomic', 'web', 'comic', 'w');
// Recognize keyword for transcript.
$gbShowTrans = one_bit_opt('transcript', 'trans','tran', 't');
// Adjust global for comic and transcript to recognize
// keyword for "both" and to always set global for comic
// when transcript is false.
if (one_bit_opt('both', 'b'))
{ $gbShowPage = 1;
$gbShowTrans = 1;
}
if (!$gbShowTrans)
{ $gbShowPage = 1;
}
// Recognize keyword for alternate (large) thumbnail size.
$gbAltThumbs =
boolval(one_digit_opt('l', 'large', 'big', 'alternate'));
// Recognize keyword to show every thumbnail.
$gbEveryThumb =
boolval(one_digit_opt('e', 'et', 'eth', 'every',
'everythumb', 'everythumbnail'));
// Recognize keyword to specify one or more verbose types.
$gVerbose = find_opt('v', 'verbose');
if ($gVerbose === null)
{ $gVerbose = '';
}
// Recognize keyword to display full-sized pages,
// but only if the value equals the code.
$tFP = find_lc_opt('full', 'fullpage' );
$gbFullPage = boolval($tFP === FULLPAGECODE);
// Set flag to catch accidental double-call.
$gbParamsReady = true;
$show = GlobalParamsOut(true);
$show = GlobalParamsOut(false);
// echoq("
[s8rq]Parameters: $show.\n");
return;
}
function GlobalParamsOut($bShowAll = false)
{
global $gbParamsReady;
global $gDebug;
global $gSearch;
global $gVerbose;
global $gbShowPage;
global $gbFullPage;
global $gbShowTrans;
global $gbAltThumbs;
global $gbEveryThumb;
if (!$gbParamsReady)
{ die("\nError--Parameters not ready in function " .
"GlobalParamsOut().\n");
}
$total = "";
$prefix = "?";
if ($gDebug or $bShowAll)
{ // Non-zero Debug level or verbose mode.
if ($gDebug == 1)
{ $out = 'd';
}
else
{ $out = "d=$gDebug";
}
$total .= $prefix . "$out";
$prefix = "&";
}
if (strlen($gSearch) or $bShowAll)
{ // Non-empty Search string or verbose mode.
$out = "s=$gSearch";
$total .= $prefix . "$out";
$prefix = "&";
}
if ($gbShowPage and (!$gbShowTrans) and (!$bShowAll))
{ // Default case of Webcomic without Transcript
// is unmarked when not verbose.
}
else
{ if ($gbShowPage and $gbShowTrans)
{ // Both Transcript and Webcomic.
$out = 'b';
}
else if ($gbShowTrans)
{ // Transcript but not Webcomic.
$out = 't';
}
else
{ // Web source but not Transcript.
$out = 'w';
}
$total .= $prefix . "$out";
$prefix = "&";
}
if ($gbAltThumbs or $bShowAll)
{ // Alternate Thumbnail true or verbose mode.
if ($gbAltThumbs)
{ $out = 'l';
}
else
{ $out = "l=0";
}
$total .= $prefix . "$out";
$prefix = "&";
}
if ($gbEveryThumb or $bShowAll)
{ // Alternate Thumbnail true or verbose mode.
if ($gbEveryThumb == 1)
{ $out = 'e';
}
else
{ $out = "e=$gbEveryThumb";
}
$total .= $prefix . "$out";
$prefix = "&";
}
if ($gbFullPage or $bShowAll)
{ // Full Page mode requested.
if ($gbFullPage)
{ $out = 'full=' . FULLPAGECODE;
}
else
{ $out = "full=0";
}
$total .= $prefix . "$out";
$prefix = "&";
}
if ((strlen($gVerbose) >= 1) or $bShowAll)
{ // At least one Verbose option specified.
if (strlen($gVerbose) >= 1)
{ $out = "v=$gVerbose";
}
else
{ $out = "v=";
}
$total .= $prefix . "$out";
$prefix = "&";
}
return $total;
}
function Hdate8($date)
{ // Hyphenated 8-digit date from unkyphenated 6 or 8 digits.
global $gDebug;
debugq6("
Begin function Hdate8($date).\n");
if (strlen($date == 6))
{ $date = "20$date";
}
if (strlen($date) == 8)
{
$date0to3 = substr($date, 0, 4);
$date4to5 = substr($date, 4, 2);
$date6to7 = substr($date, 6, 2);
$date = "$date0to3-$date4to5-$date6to7";
}
else if (strlen($date) != 10)
{ $date = "????-??-??";
}
debugq6("
End function Hdate8() as $date.");
return $date;
}