home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Rice_CMS / gopher24 / gopsrvmb.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1993-01-25  |  6.6 KB  |  218 lines

  1. /*
  2.  *        Name: GOPSRVMB REXX
  3.  *              CMS Gopher Server menu builder pipeline stage
  4.  *              Based on the older GOPHERDM REXX stage from 2.3.
  5.  *      Author: Rick Troth, Rice University, Information Systems
  6.  *        Date: 1993-Jan-15
  7.  */
  8.  
  9. /*
  10.  *      Copyright 1993 Richard M. Troth.   This software was developed
  11.  *      with resources provided by Rice University and is intended
  12.  *      to serve Rice's user community.   Rice has benefitted greatly
  13.  *      from the free distribution of software,  therefore distribution
  14.  *      of unmodified copies of this material is not restricted.
  15.  *      You may change your own copy as needed.   Neither Rice
  16.  *      University nor any of its employees or students shall be held
  17.  *      liable for damages resulting from the use of this software.
  18.  */
  19.  
  20. uc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  21. lc = "abcdefghijklmnopqrstuvwxyz"
  22.  
  23. /*  sync with input  */
  24. 'PEEKTO'
  25. If rc ^= 0 Then Exit rc * (rc ^= 12)
  26.  
  27. /*  experience shows that sometimes GLOBALV SELECT        *
  28.  *  doesn't work unless you explicitly sync with PEEKTO   */
  29. Address "COMMAND" 'GLOBALV SELECT GOPHERD GET HOST PORT PATH MENU'
  30. localhost = host
  31. localport = port
  32. localpath = path
  33. Say "Global PATH =" path
  34.  
  35. Do Forever
  36.  
  37.     'PEEKTO RECORD'
  38.     If rc ^= 0 Then Leave
  39.  
  40.     key = Left(record,1)
  41.     Select  /*  key  */
  42.         When key = "*" Then nop
  43.         When Strip(record) = "" Then nop
  44.         When key = " " Then Call FILELIST
  45.         Otherwise           Call PREFAB
  46.         End  /*  Select  key  */
  47.     If rc ^= 0 Then Leave
  48.  
  49.     'READTO'
  50.     If rc ^= 0 Then Leave
  51.  
  52.     End  /*  Do  For  */
  53.  
  54. Exit rc * (rc ^= 12)
  55.  
  56.  
  57.  
  58. /* ------------------------------------------------------------ FILELIST
  59.  *  We're apparently reading a plain FILELIST or LISTFILE output.
  60.  */
  61. FILELIST:
  62.  
  63. q1 = Index(record,"'")
  64. q2 = Index(record,'"')
  65. Select
  66.     When  q1 = 0  & q2 = 0  Then
  67.         Parse Var record fn ft fm fp '05'x name '05'x type '05'x .
  68.     When  q1 = 0  Then
  69.         Parse Var record fn ft fm fp '"'name'"' type .
  70.     When  q2 = 0  Then
  71.         Parse Var record fn ft fm fp "'"name"'" type .
  72.     When  q1 > q2 Then
  73.         Parse Var record fn ft fm fp '"'name'"' type .
  74.     When  q2 > 0  Then
  75.         Parse Var record fn ft fm fp "'"name"'" type .
  76.     End  /*  Select  */
  77.  
  78. If ft = "" Then ft = "*"
  79. If fm = "" Then fm = "*"
  80. If ft = "GOPHER" | ft = "GOPLINK" Then Do
  81.     /*  read gopher link information  */
  82.     'CALLPIPE <' fn ft fm '| GOPSRVGL | *:'
  83.     Return
  84.     End
  85.  
  86. /*  this is for Yossie:  hide filemode zero  */
  87. If Length(fm) > 1 Then If Substr(fm,2,1) = '0' Then Return
  88.  
  89. fp = Strip(fp)
  90. If fp = "" Then Do
  91.     If  Index(fn ft, '*') > 0   | ,
  92.         ft = "FILELIST"         Then fp = Translate(fn,lc,uc)
  93.     Else  fp = Translate(fn||'.'||ft,lc,uc)
  94.     End  /*  If  ..  Do  */
  95.  
  96. If name = "" Then name = fp     /*  default name is relative path  */
  97. fp = Translate(fp,"%","/")        /*  no slashes in partial path!  */
  98. If type = "" Then type = gtype(ft)
  99. host = localhost
  100. port = localport
  101. path = type || localpath || '/' || fp
  102.  
  103. /* read overrides from the NAMES file, if any */
  104. If menu ^= "" Then Call GOVER
  105.  
  106. 'OUTPUT' type || name || '05'x || ,
  107.       /* type */ path || '05'x || ,
  108.                  host || '05'x || port
  109.  
  110. Return
  111.  
  112.  
  113.  
  114. /* -------------------------------------------------------------- PREFAB
  115.  *  Preceeding stage has supplied some of the parameters.  (thank you)
  116.  */
  117. PREFAB:
  118.  
  119. Parse Var record name '05'x path '05'x host '05'x port '05'x rest
  120. Parse Var path 1 type 2 path
  121. path = type || localpath || '/' || path
  122. If host = "" Then host = localhost
  123. If port = "" Then port = localport
  124. 'OUTPUT' name || '05'x || path || '05'x || ,
  125.          host || '05'x || port || '05'x || rest
  126. Return
  127.  
  128.  
  129.  
  130. /* --------------------------------------------------------------- GOVER
  131.  *  Read the specified NAMES file for menu data overrides, if any.
  132.  */
  133. GOVER:
  134.  
  135. Address "COMMAND" 'STATE' menu 'NAMES *'
  136. If rc ^= 0 Then Return
  137.  
  138. 'CALLPIPE COMMAND NAMEFIND :NICK' fp ,
  139.         ':TYPE :NAME :PATH :HOST :PORT (FILE' menu ,
  140.         '| VAR _TYPE | DROP | VAR _NAME | DROP | VAR _PATH | DROP' ,
  141.         '| VAR _HOST | DROP | VAR _PORT'
  142. If rc ^= 0 Then
  143. 'CALLPIPE COMMAND NAMEFIND :FN' fn ':FT' ft ,
  144.         ':TYPE :NAME :PATH :HOST :PORT (FILE' menu ,
  145.         '| VAR _TYPE | DROP | VAR _NAME | DROP | VAR _PATH | DROP' ,
  146.         '| VAR _HOST | DROP | VAR _PORT'
  147. If rc ^= 0 Then Return
  148.  
  149. /*      defaults for  type, name, path, host, port    *
  150.  *      are supplied by the calling routine           */
  151.  
  152. If _host ^= "" Then host = _host
  153. If _port ^= "" Then port = _port
  154. If _path ^= "" Then path = _path
  155. If _name ^= "" Then name = _name
  156. If _type ^= "" Then type = _type
  157.  
  158. Select
  159.     When _host ^= "" & _port = "" Then port = 70
  160.     When _host = "" & _port ^= "" Then host = localhost
  161.     Otherwise nop
  162.     End  /*  When  Select  */
  163.  
  164. If _host ^= "" | _port ^= "" Then Do
  165.     path = _path
  166.     type = _type
  167.     If type = "" Then type = "1"
  168.     End  /*  If  ..  Do  */
  169. Else If _type ^= "" & _path = "" Then
  170.     path = _type || localpath || '/' || fp
  171.  
  172. Return
  173.  
  174.  
  175.  
  176. /* --------------------------------------------------------------- GTYPE
  177.  * Returns the default Gopher type character for CMS filetype specified.
  178.  */
  179. GTYPE:    Procedure
  180. Parse Arg ft
  181. Select  /*  ft  */
  182.     When ft = "*"        Then Return '1'
  183.     When ft = "-"        Then Return '1'
  184.     When ft = ""         Then Return '1'
  185.     When ft = "FILELIST" Then Return '1'
  186.     When ft = "GOPHER"   Then Return '1'
  187. /*  When ft = "CSO"      Then Return '2'  */
  188. /*  When ft = ?          Then Return '3'  */
  189. /*  When ft = "MAC"      Then Return '4'  */
  190. /*  When ft = "DOS"      Then Return '5'  */
  191.     When ft = "UUE"      Then Return '6'
  192. /*  When ft = "SEARCH"   Then Return '7'  */
  193. /*  When ft = "TELNET"   Then Return '8'  */
  194.     When ft = "TXT"      Then Return '0'    /*  plain text  */
  195.     When ft = "TEXT"     Then Return '9'    /*  deck; not plain text  */
  196.     When ft = "TXTLIB"   Then Return '9'
  197.     When Left(ft,3) = "TXT" Then Return '9'
  198.     When ft = "CARDDUMP" Then Return '9'
  199.     When ft = "TAR"      Then Return '9'
  200.     When ft = "EXE"      Then Return '9'
  201.     When ft = "DVI"      Then Return '9'
  202.     When ft = "TFM"      Then Return '9'
  203.     When ft = "FMT"      Then Return '9'
  204.     When ft = "ADMGDF"   Then Return '9'
  205.     When ft = "ADMSYMBL" Then Return '9'
  206.     When ft = "SASUSER"  Then Return '9'
  207.     When ft = "SAS6USER" Then Return '9'
  208.     When ft = "SND"      Then Return 's'
  209. /*  When ft = "EPS"      Then Return 'p'  */
  210. /*  When ft = "PS"       Then Return 'p'  */
  211.     When ft = "MODULE"   Then Return 'v'
  212.     When ft = "LOADLIB"  Then Return 'v'
  213.     When ft = "XRX"      Then Return 'v'
  214.     When ft = "GIF"      Then Return 'I'
  215.     Otherwise                 Return '0'
  216.     End  /*  Select  ft  */
  217.  
  218.