home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / wwwos2.zip / asc2bkmk.cmd next >
OS/2 REXX Batch file  |  1998-07-31  |  11KB  |  266 lines

  1. /* Copyright (c)1997 Kari Jackson for InnoVal Systems Solutions, Inc. */
  2.  
  3. /*----------------------------------------------*/
  4. /* Create NetExtra or WebWilly bookmarks        */
  5. /* from the ASCII output of BKMK2ASC.CMD        */
  6. /*----------------------------------------------*/
  7. /* Instructions:                                */
  8. /* Execute without command line arguments while */
  9. /* the BOOKMARK.ASC file is in the session's    */
  10. /* current directory.  ASC2BKMK.CMD will prompt */
  11. /* you for which type of bookmarks you want to  */
  12. /* create, and where you want to create the     */
  13. /* bookmark folders.  If you create them in a   */
  14. /* directory which already exists, that folder  */
  15. /* title will be changed to the title you       */
  16. /* specify, and the bookmarks will be added but */
  17. /* the existing bookmarks will not be touched.  */
  18. /* If you create them in any directory outside  */
  19. /* the program's BOOKS subdirectory structure,  */
  20. /* you will also have to create an entry for    */
  21. /* that new folder, in your FLDINDEX.NIX file,  */
  22. /* in order for WebWilly or NetExtra to know    */
  23. /* that the new directory belongs to the        */
  24. /* bookmark area.  See the end of this          */
  25. /* ASC2BKMK.CMD file for the format of the      */
  26. /* BOOKMARK.ASC file, if you need to edit it.   */
  27. /*----------------------------------------------*/
  28. call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  29. signal on syntax name NoREXX
  30. call SysLoadFuncs
  31. signal on syntax name Syntax
  32. "@ECHO OFF"
  33. infile="bookmark.asc"
  34. if stream(infile,"c","query exists")="" then do
  35.    say ""
  36.    say "Input file ("infile") not found."
  37.    exit
  38. end
  39. say ""
  40. say "Please select an output format (1-5):"
  41. say "1.  NetExtra 1.x"
  42. say "2.  NetExtra 2.0"
  43. say "3.  WebWilly for OS/2 3.0"
  44. say "4.  WebWilly for Windows 2.0x"
  45. say "5.  WebWilly for Windows 3.0"
  46. do until answer="1" | answer="2" | answer="3" | answer="4" | answer="5"
  47.    answer=sysgetkey()
  48. end
  49. if answer<4 then toprog="NETEXTRA"
  50. else toprog="WEBWILLY"
  51. if answer=2 | answer=3 |answer=5 then longdate=1
  52. else longdate=0
  53. do while lines(infile)
  54.    line=linein(infile)
  55.    select
  56.       when strip(line)="" then do
  57.          foldername=strip(linein(infile))
  58.          directoryname=translate(strip(linein(infile)))
  59.          if strip(linein(infile))<>copies("-",60) then do
  60.             say ""
  61.             say "Bookmark.asc file has been corrupted."
  62.             exit
  63.          end
  64.          say ""
  65.          say "The next folder's name was" foldername"."
  66.          say "Press Enter to keep this name or type a new one:"
  67.          parse pull answer
  68.          answer=strip(answer)
  69.          if answer<>"" then foldername=answer
  70.          parse var directoryname . "\BOOKS\" subdirname
  71.          if subdirname="" then subdirname=substr(directoryname,4)
  72.          if subdirname="" then subdirname=left(space(foldername,0),8)
  73.          drive=left(directory(),2)
  74.          suggest=drive||"\"||toprog||"\BOOKS\"||subdirname
  75.          say ""
  76.          say "Press Enter to create these bookmarks in the"
  77.          say suggest
  78.          say "directory, or type a new directory name:"
  79.          do forever
  80.             parse pull answer
  81.             answer=strip(answer)
  82.             if answer<>"" then directoryname=answer
  83.             else directoryname=suggest
  84.             root=left(directoryname,3)
  85.             if pos(":\",root)<>2 | length(directoryname)<4 then do
  86.                say ""
  87.                say "Please specify a full pathname which is not the root directory"
  88.                say "of a drive....such as C:\"||toprog||"\BOOKS\DIRNAME"
  89.                iterate
  90.             end
  91.             stepping=directoryname
  92.             error=0
  93.             do until stepping=""
  94.                if error=1 then leave
  95.                parse var stepping before "\" stepping
  96.                if length(before)=2 & pos(":",before)=2 then iterate
  97.                if right(root,1)<>"\" then root=root||"\"
  98.                root=root||before
  99.                call sysfiletree root,"EXISTS.","DO"
  100.                if exists.0>1 then do
  101.                   say ""
  102.                   say "Directory name" root "not understood....Multiple"
  103.                   say "directories by that name exist!  Please specify a"
  104.                   say "non-ambiguous directory name."
  105.                   error=1
  106.                end
  107.                if error=1 then leave
  108.                if exists.0=1 then iterate
  109.                if exists.0=0 then do
  110.                   rc=sysmkdir(root)
  111.                   if rc>0 then do
  112.                      say ""
  113.                      say "Unable to create" root "directory.  Please specify"
  114.                      say "another target directory name."
  115.                      error=1
  116.                   end
  117.                end
  118.                if error=1 then leave
  119.             end
  120.             if error=0 then leave
  121.          end
  122.          if toprog="NETEXTRA" then call SysPutEA directoryname,"WEBEXFOLDERNAME",foldername
  123.          else do
  124.             titlefile=directoryname"\"substr(directoryname,lastpos("\",directoryname)+1)".ES"
  125.             call sysfiledelete titlefile
  126.             call charout titlefile,foldername
  127.             call lineout titlefile
  128.          end
  129.       end
  130.       otherwise do
  131.          title="" ; url="" ; sticky="20"x ; userid="" ; password=""
  132.          parse var line title "09"x url "09"x date "09"x time "09"x sticky "09"x userid "09"x password "09"x stickydate "09"x stickyfollowup "09"x stickytext
  133.          if time="" then time=time("C")
  134.          if length(time)=6 then time=0||time
  135.          if date="" then date=insert("/",insert("/",date("S"),4),7)
  136.          if longdate=0 then date=right(date,5)
  137.          else if toprog="WEBWILLY" then do
  138.             parse var date yy "/" mm "/" dd
  139.             yy=right(yy,2)
  140.             date=mm"/"dd"/"yy
  141.          end
  142.          string="17"x||title||"09"x||url||"09"x||date||"09"x||time||"09"x||sticky||"09"x||"09"x||userid||"09"x||password||"09"x
  143.          if directoryname="DIRECTORYNAME" then directoryname=directory()
  144.          filename=GetPopName(directoryname,"URL")
  145.          if toprog="WEBWILLY" then do
  146.             call lineout filename,string
  147.             if result=0 then say "Created bookmark" filename "for" url
  148.             else say "Error on" url
  149.          end
  150.          call lineout filename
  151.          if toprog="NETEXTRA" then do
  152.             if SysPutEA(filename,"URLFILEBUFFER",string)=0 then say "Created bookmark" filename "for" url
  153.             else say "Error on" url
  154.          end
  155.          if sticky="01"x then do
  156.             convert=stickytext
  157.             final=""
  158.             if toprog="NETEXTRA" then combine="0D0A"x
  159.             else combine="0D0D0A"x
  160.             do until convert=""
  161.                parse var convert check "09"x convert
  162.                if final="" then final=check
  163.                else final=final || combine || check
  164.             end
  165.             stickytext=final
  166.             if toprog="NETEXTRA" then do
  167.                call SysPutEA filename,"STICKEYDATE",stickydate
  168.                call SysPutEA filename,"STICKEYFOLLOWUP",stickyfollowup
  169.                call SysPutEa filename,"STICKEYTEXT",stickytext
  170.             end
  171.             else do
  172.                parse var filename root "." .
  173.                filename=root||".STK"
  174.                call lineout filename, stickydate||stickytext
  175.                call lineout filename
  176.             end
  177.          end
  178.          if stream(filename)<>"UNKNOWN" then call lineout filename
  179.       end
  180.    end
  181. end
  182. exit
  183. GetPopName:procedure
  184. /* Copyright (c)1996,1997 Kari Jackson for InnoVal Systems Solutions, Inc. */
  185. /* Subroutine to produce a *.POP-style filename */
  186. /* Returns d:\dirname\filename.ext or "error" */
  187. parse arg directory,extension
  188. if right(directory,1)='\' then directory=substr(directory,1,length(directory)-1)
  189. if left(extension,1)='.' then extension=substr(extension,2)
  190. characters='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  191. parse value date("O") with . 2 year "/" month "/" day
  192. parse value time() with hour ":" minute ":" second
  193. month=substr(characters,month+1,1)
  194. day=substr(characters,day+1,1)
  195. hour=substr(characters,hour+1,1)
  196. fifth=minute%36
  197. sixth=substr(characters,minute//36+1,1)
  198. test=second//36
  199. string=year||month||day||hour||fifth||sixth
  200. do j=1 to 36
  201.    test2=(test+j)//36
  202.    if test2=0 then seventh=substr(characters,36,1)
  203.    else seventh=substr(characters,test2,1)
  204.    do i=1 to 36
  205.       tryit=string||seventh||substr(characters,i,1)
  206.       filename=directory||"\"||tryit||'.'||extension
  207.       if stream(filename,'c','query exists')='' then return filename
  208.    end
  209. end
  210. return "error"
  211. Syntax:
  212.   say "Error" rc": " errortext(rc)
  213.   say "Line" sigl": " sourceline(sigl)
  214.   exit
  215. return
  216. NoREXX:
  217.    say "Unable to load the REXXUtil functions.  Either the REXXUTIL.DLL file"
  218.    say "is not on the LIBPATH or REXX support is not installed on this system."
  219.    exit
  220. return
  221. /*
  222.                           The BOOKMARK.ASC file format
  223.  
  224. If you want to modify this file, you must use an ASCII text editor which does
  225. not convert tab characters to spaces the way so many editors do!  OS/2's E.EXE
  226. is safe for this purpose, as is Windows Notepad.
  227.  
  228. First folder in file:
  229.  
  230.   Line one:    blank
  231.   Line two:    folder name
  232.   Line three:  full pathname to the directory which is (was) that folder
  233.   Line four:   ------------------------------------------------------------
  234.   Line five:   the rest of the lines are the bookmark information, one
  235.                   bookmark per line
  236.  
  237. Repeat, starting with the blank line, for any other folders.  Do not end the
  238. file with a blank line.
  239.  
  240. The blank line is what tells the program that a new folder is starting.  Do not
  241. leave out the blank line between one folder and the next, and do not leave any
  242. blank lines anywhere else in the file.
  243.  
  244. The bookmark information lines contain the following items:
  245.  
  246.   Title of the web page
  247.   a tab character
  248.   The web page's URL (such as http://www.innoval.com/netextra)
  249.   a tab character
  250.   The date the bookmark was created (such as 1997/01/13)
  251.   a tab character
  252.   The time the bookmark was created (such as 09:26am)
  253.   a tab character
  254.   A hex 01 character if there is a sticky note, or hex 20 if there isn't
  255.   a tab character
  256.   Your userid if the web page is password-protected
  257.   a tab character
  258.   Your encrypted password if the web page is password-protected
  259.   If the bookmark has a sticky note, its date (such as 01/13/97)
  260.   a tab character
  261.   If the bookmark has a sticky note, a 0 character
  262.   a tab character
  263.   If the bookmark has a sticky note, the text of the sticky note, with tab
  264.      characters where the carriage returns belong
  265. */
  266.