home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / os2 / goserv.zip / gosmenu.cmd < prev    next >
OS/2 REXX Batch file  |  1993-05-03  |  4KB  |  75 lines

  1. /* This sample command converts a Gopher menu template to a 'real' */
  2. /* Gopher menu, where each line is a canonical Gopher reference.   */
  3. /*                                                                 */
  4. /* Call as:  GOSMENU Sourcefilespec Targetfilespec                 */
  5. /*                                                                 */
  6. /* Sourcefilespec and Targetfilespec are any OS/2 file             */
  7. /* specifications without embedded blanks.                         */
  8. /*                                                                 */
  9. /* The Targetfilespec may be omitted if the Sourcefilespec has an  */
  10. /* extension; in this case the extension is changed to "70" for    */
  11. /* the Targetfilespec.                                             */
  12. /*                                                                 */
  13. /* The first line of the menu template file is a comment/title,    */
  14. /*   and is ignored.                                               */
  15. /*                                                                 */
  16. /* The second line of the menu template file has three words:      */
  17. /*                                                                 */
  18. /*   1. The character used in the rest of the file for TAB         */
  19. /*   2. The default server address (if none given)                 */
  20. /*   3. The default server port (if none given)                    */
  21. /*                                                                 */
  22. /* Example:  "; fred.hursley.ibm.com 70"                           */
  23. /*                                                                 */
  24. /* Subsequent lines are Gopher menu lines, which must start with   */
  25. /* the Gopher item type character (e.g., 0, 1, etc.).  Within      */
  26. /* these lines, blanks next to tabs are removed, blanks after the  */
  27. /* first (item type) character are removed, and the server address */
  28. /* and port are added as needed.                                   */
  29. /*                                                                 */
  30. /* Lines whose first character is a blank are ignored; they may be */
  31. /* used as spacers or for commentary.                              */
  32. /*                                                                 */
  33. /* The input and output file names may not have embedded blanks in */
  34. /* this version.                                                   */
  35.  
  36. port=70                               /* default extension */
  37. arg infile outfile .
  38. if outfile='' & infile<>'' then do    /* attempt to default output */
  39.   name=filespec('n',infile); dot=lastpos('.', name)
  40.   if dot>0 then do
  41.     qual=filespec('d',infile)filespec('p',infile)
  42.     outfile=qual''left(name,dot)''port
  43.     end
  44.   end
  45. if outfile='' then do
  46.   say 'This command needs an input filename and an output filename'
  47.   say 'e.g., GOSMENU sample.men sample.70'; exit 1; end
  48. if infile=outfile then do  /* only partial check */
  49.   say 'Input and output filenames are the same!'
  50.   exit 2; end
  51.  
  52. tab='09'x
  53. say 'Converting "'linein(infile)'" into file "'outfile'"...'
  54. parse value linein(infile) with tabchar defaddr defport rest
  55. if length(tabchar)<>1 | rest<>'' | defport='' then do
  56.   say 'Second line of "'infile'" does not have three valid words'
  57.   exit 3; end
  58.  
  59. '@erase' outfile '2>nul' /* quietly erase any old output */
  60. do while lines(infile)>0
  61.   line=translate(linein(infile), tab, tabchar)
  62.   parse var line type +1 descrip (tab) selector (tab),
  63.                  addr . (tab) port . (tab) gplus
  64.   if type=' ' then iterate    /* ignore comments/blank lines */
  65.   descrip=strip(descrip); selector=strip(selector)
  66.   if addr='' then addr=defaddr
  67.   if port='' then port=defport
  68.   if gplus<>'' then gplus=tab||gplus /* Optional Gopher+ information */
  69.   canonical=type||descrip||tab||selector||tab||addr||tab||port||gplus
  70.   call lineout outfile, canonical
  71.   end
  72. call lineout outfile; call lineout infile
  73. say 'Menu file generated'
  74. exit 0
  75.