home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / urlget10.zip / URLGET.CMD < prev   
OS/2 REXX Batch file  |  1997-05-05  |  4KB  |  160 lines

  1. /*
  2. **                             UrlGet 1.0
  3. **                     copyright 1997 Ed Blackman
  4. **
  5. ** Acknowledgments:
  6. **  Originally by mortenf@login.dknet.dk (Morten Frederiksen)
  7. **  Complete rewrite by edgewood@pobox.com (Ed Blackman)
  8. **
  9. ** Change log:
  10. **  Who:   When:        What was done:
  11. **  EBB    1996/Oct/16  removed requirement of 4OS2
  12. **  EBB    1996/Oct/16  removed use of unnecessary temp files
  13. **  EBB    1996/Nov/05  creates WebEx URL objects instead of writing a text file
  14. **  EBB    1997/Mar/05  added "batch" mode capability
  15. **                      - creates objects for all valid URLs in the input file
  16. **                      - the name of the URL is used as the description: 
  17. **                        the user is not prompted
  18. **  EBB    1997/Mar/31  added install script
  19. **  EBB    1997/Apr/01  added choice of creating Warp 4 URL objects
  20. **  EBB    1997/Apr/15  fixed backspacing bug
  21. */
  22.  
  23. arg msgfile
  24.  
  25. if msgfile == "" then
  26.     call usage
  27.  
  28. app='URLCommander'
  29. urlpath=''
  30. mode=''                      
  31. objclass=''
  32. setupstr=''
  33.  
  34. /* Load RexxUtil functions if not already loaded */
  35. if RxFuncQuery('SysLoadFuncs') then do
  36.     say "Loading RexxUtil functions"
  37.     call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  38.     call SysLoadFuncs
  39. end /* do */
  40.  
  41. call readini
  42.  
  43. prefix.0 = 4                            /* URL prefixes to search for */
  44. prefix.1 = 'http://'
  45. prefix.2 = 'https://'
  46. prefix.3 = 'ftp://'
  47. prefix.4 = 'gopher://'
  48.         
  49. do while lines(msgfile)
  50.     msgline=linein(msgfile)
  51.     do i = 1 to prefix.0
  52.         if pos(prefix.i,msgline)>0 then
  53.         do
  54.             urltmp=substr(msgline,pos(prefix.i,msgline))
  55.             goodurl=1
  56.             n=1
  57.             url=''
  58.             do while goodurl
  59.                 ch=substr(urltmp,n,1)
  60.                 if ch=' ' | ch='>' | ch='<' | ch='"' then
  61.                     goodurl=0
  62.                 else
  63.                     url=url||ch
  64.                 n=n+1
  65.             end
  66.  
  67.             if mode = 'INTERACTIVE' then
  68.                 desc = getdesc(url)
  69.             else
  70.                 desc = url
  71.             
  72.             if desc <> '' then
  73.             do
  74.                 title=desc || d2c(10) || date() time()
  75.                 if SysCreateObject(objclass, title, urlpath,,
  76.                         setupstr || url) == 0 then
  77.                     call create_failed
  78.             end
  79.         end
  80.     end i
  81. end
  82.  
  83. exit
  84.  
  85. create_failed:
  86.     call SysQueryClassList 'class.'
  87.     found = 0
  88.     do i = 1 to class.0
  89.         if left(class.i, length(objclass)) = objclass then
  90.             found = 1
  91.     end i
  92.     if \found then
  93.         say objclass 'is not registered.'
  94.     say 'Cannot create object for url' url
  95.     return
  96.  
  97. getdesc: procedure
  98.     parse arg url .
  99.     call charout ,'['||url||']: '
  100.     desc = ''
  101.     key = SysGetKey("noecho")
  102.     do while key \= d2c(13)
  103.         select
  104.             when key = d2c(8) then /* backspace */
  105.             if length(desc) > 0 then
  106.                 do
  107.                     call erase 1
  108.                     desc = substr(desc, 1, length(desc) - 1)
  109.                 end
  110.             when key = d2c(27) then /* escape */
  111.             do
  112.                 call erase length(desc)
  113.                 desc = ''
  114.             end
  115.             otherwise
  116.             do
  117.                 call charout , key
  118.                 desc = desc || key
  119.             end /* do */
  120.         end /* select */
  121.  
  122.         key = SysGetKey("noecho")
  123.     end /* do while */
  124.     say
  125.     return desc
  126.  
  127. readini: 
  128.     inifile = SysIni("USER", app, "IniFile")
  129.     if inifile == "ERROR:" then
  130.     do
  131.         say "Can't find path to .INI file"
  132.         exit
  133.     end
  134.     urlpath = SysIni(inifile, "URLGet", "URLPath")
  135.     mode = SysIni(inifile, "URLGet", "Mode")
  136.     objclass = SysIni(inifile, "URLGet", "ObjectClass")
  137.     setupstr = SysIni(inifile, "URLGet", "SetupString")
  138.  
  139.     concat = urlpath||mode||objclass||setupstr
  140.     if pos("ERROR:", concat) > 0 then
  141.     do
  142.         say "Missing keys in" inifile
  143.         exit
  144.     end
  145.     drop concat inifile
  146. return
  147.  
  148. usage:
  149.     say "Usage: URLGet <file>"
  150.     say "    where <file> is the name of a text file containing URLs"
  151.     exit
  152.     
  153. erase:              /* erase n characters on screen */
  154.     parse arg n
  155.     if n > 0 then
  156.         do i = 1 to n
  157.             call charout , d2c(8) || ' ' || d2c(8)
  158.         end i
  159.     return
  160.