home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / internet / gethelp / rexx / gethelp.rexx next >
Encoding:
OS/2 REXX Batch file  |  1999-06-08  |  6.0 KB  |  274 lines

  1. /* GetHelp.rexx - Opens html help file on URL link from a browser
  2. ** $VER: GetHelp.rexx 1.1 (08.6.99) by B.Rogers <bsrogers@cobweb.com.au>
  3. ** Refer to the documentation for usage, version history etc.
  4. */
  5.  
  6. /**************************************
  7. ** Set up constants
  8. */
  9.  
  10. /* Default html file if no arguments */
  11. default_url='file://localhost/Help:Amiga_help.help'
  12.  
  13. /* temporary .help file to unarchive from */
  14. temp_url='T:Help/temp.help'
  15. temp_dir='T:Help/temp'
  16.  
  17. /* Debug flag (1=true) */
  18. DeBug=0
  19.  
  20. /**************************************
  21. ** Main program
  22. */
  23.  
  24. OPTIONS RESULTS
  25. OPTIONS FAILAT 21
  26. ADDRESS COMMAND
  27.  
  28. PARSE ARG help_url
  29.  
  30. /* remove any nastly quotes from help_url
  31. ** ie rx GetHelp "Help:ag2html.help"
  32. */
  33.  
  34. help_url = STRIP(help_url,'B','"')
  35.  
  36. IF debug=1 THEN SAY help_url
  37.  
  38. /*
  39. ** options are:
  40. ** 1.  Initial call for Help (default html page)
  41. ** 2.  Call for a specific help file
  42. ** 3.  Call to exit Help
  43. **
  44. */
  45.  
  46. SELECT
  47.  
  48.   WHEN help_url='QUIT' THEN DO
  49.     IF debug=1 THEN SAY 'Quit Message...'
  50.     CALL Clean_Up
  51.     EXIT
  52.   END
  53.  
  54.   WHEN help_url="" THEN DO
  55.  
  56.    /* prepare to display default html file */
  57.    url=default_url
  58.    first_time=1
  59.  
  60.    /* create T:Help directory
  61.    ** - this also flags that the help function has been called
  62.    */
  63.    IF ~EXISTS("T:Help") THEN DO
  64.      IF debug=1 THEN SAY 'Initialising T:Help directory'
  65.      'makedir' "T:Help"
  66.    END
  67.    IF debug=1 THEN SAY "Displaying default help page..."
  68.  
  69.   END
  70.  
  71.   OTHERWISE url = get_url(help_url)
  72.  
  73. END
  74.  
  75. /*
  76. ** Display url using Openurl
  77. */
  78.  
  79. IF debug=1 THEN SAY 'Displaying file...'url
  80. openurl '"'url'"'
  81.  
  82. /* user has ended help session */
  83. IF first_time=1 THEN DO
  84.   SAY 'All done! Exiting...'
  85.   CALL Clean_up
  86. END
  87.  
  88. /* exit gethelp */
  89. EXIT
  90.  
  91.  
  92. /**********************************************************
  93. ** get a correctly formatted url ready to feed to a browser
  94. */
  95.  
  96. get_url:
  97.  
  98.   PARSE ARG help_url
  99.  
  100.   /*
  101.   ** check for file://localhost/, file:///, http:// or ftp:// paths
  102.   */
  103.   pos_local = INDEX(help_url,"file://localhost/")
  104.   IF pos_local>0 THEN DO
  105.     help_url=RIGHT(help_url,LENGTH(help_url)-17)
  106.     IF ~EXISTS(help_url) THEN DO
  107.       clean_up
  108.       EXIT 10
  109.     END
  110.     IF debug=1 THEN DO
  111.       SAY "Yep, its a local file [file://localhost/]"
  112.       SAY help_url
  113.     END
  114.   END
  115.   ELSE DO
  116.     pos_local = INDEX(help_url,"file:///")
  117.     IF pos_local>0 THEN DO
  118.       help_url=RIGHT(help_url,LENGTH(help_url)-8)
  119.       IF ~EXISTS(help_url) THEN DO
  120.         clean_up
  121.         EXIT 10
  122.       END
  123.       IF debug=1 THEN DO
  124.         SAY "Yep, its a local file [file:///]"
  125.         SAY help_url
  126.       END
  127.     END
  128.     ELSE DO
  129.       pos_http = INDEX(help_url,"http:")
  130.       pos_ftp = INDEX(help_url,"ftp:")
  131.       IF pos_http>0 OR pos_ftp>0 THEN DO
  132.         SAY "Yep, it's online - future capability enhancement!"
  133.         clean_up
  134.         EXIT
  135.       END
  136.     END
  137.   END
  138.  
  139.   /*
  140.   ** end game is to determine help_file_name
  141.   */
  142.  
  143.   /*
  144.   ** parse any assigns or devices in path,
  145.   ** trim assign/device from help_url
  146.   */
  147.   pos_assign = INDEX(help_url,":")
  148.   IF poss_assign>0 THEN DO
  149.     help_path = RIGHT(help_url,LENGTH(help_url)-pos_assign)
  150.   END
  151.   ELSE DO
  152.     /* no : markers! */
  153.     help_path = help_url
  154.   END
  155.  
  156.   /*
  157.   ** now check for / markers,
  158.   ** look past these..
  159.   */
  160.   pos_dir = LASTPOS("/",help_path)
  161.   IF pos_dir>0 THEN DO
  162.     help_file = RIGHT(help_path,LENGTH(help_path)-pos_dir)
  163.   END
  164.   ELSE DO
  165.     /* there were no / markers! */
  166.     help_file = help_path
  167.   END
  168.  
  169.   /* remove .htm(l) suffix */
  170.   help_file_name = SUBSTR(help_file,1,POS('.',help_file)-1)
  171.  
  172.   /*
  173.   ** set up help directory in T: and first file to show
  174.   */
  175.   help_directory = "T:Help/"help_file_name
  176.   help_html = help_file_name".html"
  177.  
  178.   /* debug info */
  179.   IF debug=1 THEN DO
  180.     SAY "help_file="help_file
  181.     SAY "help_file_name="help_file_name
  182.     SAY "help_directory="help_directory
  183.     SAY "help_html="help_html
  184.   END
  185.  
  186.   /*
  187.   ** extract html files if not already cached
  188.   */
  189.   IF ~EXISTS(help_directory) THEN
  190.     DO
  191.       /* confirm we have a T:Help directory */
  192.       IF ~EXISTS("T:Help") THEN DO
  193.         IF debug=1 THEN SAY 'NOTE - a browser has directly accessed a help file!'
  194.         'makedir' "T:Help"
  195.         /* spawn process to monitor Browser quit */
  196.         'RUN >NIL: SYS:Rexxc/rx GetHelp.rexx QUIT'
  197.       END
  198.  
  199.       /* copy url to T: */
  200.       IF debug=1 THEN SAY "copying url to T:"
  201.       'copy QUIET "'help_url'"' temp_url
  202.       IF debug=1 THEN SAY "url copied..."
  203.  
  204.       /* create help topic subdirectory */
  205.       /* NOTE: this variable may need linepunching */
  206.       'makedir' temp_dir
  207.  
  208.       IF debug=1 THEN 'lha -I -X x "'temp_url'"' temp_dir'/'
  209.       ELSE 'lha -I -X -q x "'temp_url'"' temp_dir'/'
  210.  
  211.       /* delete temp_url */
  212.       'delete QUIET' temp_url
  213.  
  214.       /* rename temp directory */
  215.       'rename QUIET' temp_dir '"'help_directory'"'
  216.     END
  217.  
  218.   /*
  219.   ** if no <help_html>.htm(l) or main.html, we have an error!
  220.   */
  221.   IF ~EXISTS(help_directory"/"help_html) THEN DO
  222.  
  223.     /* check for .htm suffix */
  224.     IF EXISTS(help_directory"/"help_file_name".htm") THEN help_html = help_file_name".htm"
  225.     ELSE DO
  226.  
  227.       /* check for main.html (Guide to html conversion?) */
  228.       IF EXISTS(help_directory"/main.html") THEN help_html = "main.html"
  229.       ELSE DO
  230.         ADDRESS COMMAND
  231.         msg = '"Could not find main.html or 'help_html'..."'
  232.         'requestchoice' 'Browser' msg 'Investigate'
  233.         CALL clean_up
  234.         EXIT
  235.       END
  236.  
  237.     END
  238.  
  239.   END
  240.  
  241.   IF debug=1 THEN SAY "final help_html="help_html
  242.  
  243.   /* tell browser where first file will be.. */
  244.   url = "file:///"help_directory"/"help_html
  245.  
  246. RETURN url
  247.  
  248. /************************************************
  249. ** clean up and exit on-line help
  250. */
  251.  
  252. clean_up:
  253.  
  254.   ADDRESS COMMAND
  255.  
  256.   /* give browser time to appear! */
  257.   'WAIT' 5
  258.  
  259.   /* this line is ugly, but with OpenUrl have no identified way of knowing which browser is in use..*/
  260.   DO FOREVER
  261.     IF (~SHOW('P','IBROWSE')&~SHOW('P','VOYAGER')&~SHOW('P','AWEB.1')&~SHOW('P','MOREHTML')) THEN BREAK
  262.     'WAIT' 5
  263.   END
  264.  
  265.   IF debug=1 THEN SAY 'Deleting T: files...'
  266.  
  267.   /* remove T: files */
  268.   'delete' ">NIL: T:Help ALL"
  269.   'delete' ">NIL: T:temp#?"
  270.   'delete' ">NIL: T:Command#?"
  271.   IF debug=1 THEN SAY 'Finished!'
  272.  
  273. RETURN
  274.