Listing of program rxcalc.cgi

#! /usr/bin/regina
/*   A rexxlet that evaluates any valid REXX expression */
/* At Entry : args = fontsize bgcolor expression        */
/* Returns  : none                                      */
/* Does     : evaluates and displays the expression     */
/*            as a GIF file                             */
/*------------------------------------------------------*/

trace o
call setdll     /* loads HHNS functions */

parse arg fontsz bgcolor expression

if expression = "" then return 0

/*--- Unfortunately, the UNIX Shell will escape with '\'       */
/*      all the 'magic' shell chars : (, ), \, ...             */
/*--- Fortunately, Dr. HHNS will re-establish the original     */
/*      string by using his 'R4Sh' (Ready for shell) function  */
expression = r4sh(expression)

/* ready now, evaluate the expression    */

interpret "t="expression
/*-------- if result is empty, exit ex-abrupto   -----------------*/

l = length(t); if l = 0 then return 0

/*-------------- process the font size (T,S,M,L,G)   -------------*/
/*--- for each font, there is a pre-fetched pixel size per char --*/

parse upper var fontsz c 2 .          
select
    when c = 'T' then  do; dx = 5; dy = 8 ;  size = 'tiny'   ;  end
    when c = 'S' then  do; dx = 6; dy = 12;  size = 'small'  ;  end
    when c = 'L' then  do; dx = 8; dy = 16;  size = 'large'  ;  end
    when c = 'G' then  do; dx = 9; dy = 15;  size = 'giant'  ;  end
    otherwise          do; dx = 7; dy = 13;  size = 'medium' ;  end
end

/*--- process the BGColor parameter -> 3 numbers 0..255  ----------*/

if \datatype(bgcolor, "X") then bgcolor = lib2hex(bgcolor)
parse var bgcolor 1 red 3 green 5 zblue
r = x2d(red)
g = x2d(green)
z = x2d(zblue)
/*--- Prepare a script file for 'FLY', a great shareware program ---*/
/*--- that builds gif images 'on the fly', ex-nihilo ...         ---*/
/*--- See Martin Gleeson http://www.unimelb.edu.au/fly/           ---*/

f = "/tmp/rxcalc"d2x(getpid())".tmp"         /* the fly script name  */
call lineout f, "new"                        /* 1st FLY directive    */
call lineout f, "size" 4+dx * l","4+dy       /* Img size : we add 4  */
call lineout f, "fill 0,0,"r","g","z         /* Img BGcolor          */
call lineout f, "string 0,0,0,2,2,"size","t  /* the result string    */
call lineout f, "end"                        /* end of script        */
call lineout f                               /* Close the file       */

/*--- fill the result header and call Martin's FLY ---------------*/

say "Content-type: image/gif"
say
"/usr/local/bin/fly -i" f "2>/dev/null"

/*----------- All done : Housekeeping and returns ... --------------*/

"rm -f" f
return 0

lib2hex : procedure /* returns the hex RGB code for a given color */
arg c
select
   when c = 'BLACK'    then return   "000000"
   when c = 'GREEN'    then return   "008000"
   when c = 'LIME'     then return   "00FF00"
   when c = 'SILVER'   then return   "C0C0C0"
   when c = 'GRAY'     then return   "808080"
   when c = 'OLIVE'    then return   "808000"
   when c = 'WHITE'    then return   "FFFFFF"
   when c = 'YELLOW'   then return   "FFFF00"
   when c = 'MAROON'   then return   "800000"
   when c = 'NAVY'     then return   "000080"
   when c = 'RED'      then return   "FF0000"
   when c = 'BLUE'     then return   "0000FF"
   when c = 'PURPLE'   then return   "800080"
   when c = 'TEAL'     then return   "008080"
   when c = 'FUSCHIA'  then return   "FF00FF"
   when c = 'AQUA'     then return   "00FFFF"
   otherwise return "FF00FF"
end
Back   Home