home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / gohttp.zip / DoIncl.Rxx < prev    next >
Text File  |  1995-07-11  |  4KB  |  86 lines

  1. /*  Mike Cowlishaw's Server-side includes parser, excerpted from GoRemote.80.   */
  2. /*  ...slightly modified by D.L. Meyer...            */
  3.  
  4. /*  Upon call from GoHTTP.v20, the current directory will have been changed     */
  5. /*   to the REXX script directory.   Subsequent calls to scripts located there     */
  6. /*   need not change directory...                */
  7.  
  8. /* ---------------------------------------------------------------- */
  9. /* DOINCL: process a block of html for server-side includes   */
  10. /* ---------------------------------------------------------------- */
  11. /* ARG(1) is block of data                                 */
  12. /*DoIncl: procedure        */
  13.   parse arg data, _filename, _ServerAdmin
  14.   out=''                                     /* result */
  15.   do forever
  16.     parse var data pre '{' expr '}' data     /* find expression */
  17.     out=out''pre                             /* pre-stuff */
  18.     if expr='' then if data='' then leave    /* no more '{' */
  19.     out=out''eval(expr, '')             /* add evaluation */
  20.     end
  21.   return out                                  /* [called as function] */
  22.  
  23. /* ---------------------------------------------------------------- */
  24. /* EVAL: return an expression evaluation [protected]                */
  25. /* ---------------------------------------------------------------- */
  26. /* ARG(1) is expression to evaluate                                 */
  27. /* ARG(2) is passed from PAGE, usually an arbitrary text message    */
  28. /* An expression starting with '?' is a direct EXTRACT, special-    */
  29. /* cased for simplicity.  ({?foo} == {extract(foo)})                */
  30. /*eval: procedure                         / * no variables visible */
  31. eval: procedure expose _filename _ServerAdmin                       /* few variables visible */
  32.   if left(strip(arg(1)),1)='?' then return extract(substr(strip(arg(1)),2))
  33.   /* arbitrary expression expected -- assume CRLF and tabs are whitespace */
  34.   signal on syntax name evaloops                       /* handle errors */
  35.   interpret 'result='translate(arg(1),' ','0d0a09'x)   /* evaluate */
  36.   return result                                        /* done */
  37.  
  38. evaloops: return '[?]'
  39.  
  40. /* ---------------------------------------------------------------- */
  41. /* FILENAME: return the name of the file being processed.           */
  42. /* ---------------------------------------------------------------- */
  43. /* Rather like C's "?" operation */
  44. filename: return _filename
  45.  
  46. /* ---------------------------------------------------------------- */
  47. /* LASTMODIFIED: return the modification time & date of the file.           */
  48. /* ---------------------------------------------------------------- */
  49. LastModified: procedure expose _filename
  50.    parse arg filename
  51.    if (filename == '') then filename = _filename
  52.    call SysFileTree translate(filename,'\','/'),'files.'
  53.    if (files.0 \= 1) then return '[?]'
  54.    parse var files.1 date time .
  55.    return time'm on 'date
  56.  
  57. /* ---------------------------------------------------------------- */
  58. /* FOOTER: a link to an external footer routine.        */
  59. /* ---------------------------------------------------------------- */
  60. Footer: procedure expose _filename _ServerAdmin
  61.    parse arg filename
  62.    if (filename == '') then filename = _filename
  63.    contents = ''
  64.    interpret 'contents = Footer.Rxx(filename, contents, _ServerAdmin)'
  65.    return contents
  66.  
  67. /* ---------------------------------------------------------------- */
  68. /* IF: select string based on ARG(1)                                */
  69. /* ---------------------------------------------------------------- */
  70. /* Rather like C's "?" operation */
  71. if: if arg(1) then return arg(2); else return arg(3)
  72.  
  73. /* ---------------------------------------------------------------- */
  74. /* QFLAG:  return 'checked' for a flag that's ON,  null otherwise   */
  75. /* QFLAGN: return 'checked' for a flag that's OFF, null otherwise   */
  76. /* ---------------------------------------------------------------- */
  77. qflag:  if extract(arg(1))='ON'  then return 'checked'; else return ''
  78. qflagn: if extract(arg(1))='OFF' then return 'checked'; else return ''
  79.  
  80. /* ---------------------------------------------------------------- */
  81. /* GMTWARN: return warning if GMT unavailable, null otherwise       */
  82. /* ---------------------------------------------------------------- */
  83. gmtwarn: if extract('GMTSET')='ON' then return ''
  84. return '[TZ was not set - GMT is <strong>not</strong> available]'
  85.  
  86.