/*     B o o t h W a r e   P r e s e n t s    */
/*                                            */
/*        G I F   S p e c   V i e w e r       */
/*                                            */
/*             Written by  Le Chat            */
/*                                            */
/*             Copyright  (c) 1994            */
/*             All rights reserved            */
/*                                            */
/*     Contact Gate Keeper on Future World    */
/*                      or                    */
/*           Call The Phone Booth BBS         */
/*           (504)272-2000 3/12/24/144        */
/*  for more C-Net secondary program support! */

options results
signal on error
signal on syntax

if show("L","rexxsupport.library") then
  SLib = 1
  else if addlib("rexxsupport.library",0,-30,0) then
         SLib = 1
       else SLib = 0

echo ""
echo "   T h e   G I F   S p e c   V i e w e r      by Le Chat"
echo "   From Phone Booth BBS  (504)272-2000 3/12/24/144 24hrs"
echo ""
if arg() = 0 then
  do
    echo "  No filename passed!"
    exit
  end
filename = arg(1)
if left(filename,1) = '"' then filename = right(filename,length(filename)-1)
if right(filename,1) = '"' then filename = left(filename,length(filename)-1)
if exists(filename) then nop
  else do
    echo "  Unable to locate file."
    exit
  end

if filename = "" then exit

call open(giffile,filename,"R")

header = readch(giffile,6)
if header = "GIF87a" | header = "GIF89a" then nop
  else do
    echo "  Unrecognized GIF header or filetype."
    exit
  end

if SLib then
  do
    line = statef(filename)
    parse var line type bytes null
    if type = "FILE" then nop
      else SLib = 0
  end

lsb    = c2d(readch(giffile,1))
msbyte = c2d(readch(giffile,1))
width  = msbyte * 256 + lsb
lsb    = c2d(readch(giffile,1))
msbyte = c2d(readch(giffile,1))
height = msbyte * 256 + lsb

colorhex = c2x(readch(giffile,1))
colorhex = value(right(colorhex,1))
colors = 2 ** (colorhex+1)
len = length(filename)
j = lastpos("/",filename,len-1)
if j = 0 then j = lastpos(":",filename)
if j = 0 then path = filename
  else path = right(filename,len-j)

line1 = "  Filename                 Width Height Colors Signature"
line2 = "  ------------------------ ----- ------ ------ ---------"
if SLib then
  do
    line1 = line1||" Total Bytes"
    line2 = line2||" -----------"
  end
echo line1
echo line2
line = "  "||path
line = overlay(width,line,28)
line = overlay(height,line,34)
line = overlay(colors,line,41)
line = overlay(header,line,48)
if SLib then line = overlay(bytes,line,58)
echo line

call close(giffile)
exit

SYNTAX:
ERROR:
line = sigl
etype = rc
echo "Error in "line" type "etype" "errortext(etype)
exit
