home *** CD-ROM | disk | FTP | other *** search
- /* GetHelp.rexx - Opens html help file on URL link from a browser
- ** $VER: GetHelp.rexx 1.1 (08.6.99) by B.Rogers <bsrogers@cobweb.com.au>
- ** Refer to the documentation for usage, version history etc.
- */
-
- /**************************************
- ** Set up constants
- */
-
- /* Default html file if no arguments */
- default_url='file://localhost/Help:Amiga_help.help'
-
- /* temporary .help file to unarchive from */
- temp_url='T:Help/temp.help'
- temp_dir='T:Help/temp'
-
- /* Debug flag (1=true) */
- DeBug=0
-
- /**************************************
- ** Main program
- */
-
- OPTIONS RESULTS
- OPTIONS FAILAT 21
- ADDRESS COMMAND
-
- PARSE ARG help_url
-
- /* remove any nastly quotes from help_url
- ** ie rx GetHelp "Help:ag2html.help"
- */
-
- help_url = STRIP(help_url,'B','"')
-
- IF debug=1 THEN SAY help_url
-
- /*
- ** options are:
- ** 1. Initial call for Help (default html page)
- ** 2. Call for a specific help file
- ** 3. Call to exit Help
- **
- */
-
- SELECT
-
- WHEN help_url='QUIT' THEN DO
- IF debug=1 THEN SAY 'Quit Message...'
- CALL Clean_Up
- EXIT
- END
-
- WHEN help_url="" THEN DO
-
- /* prepare to display default html file */
- url=default_url
- first_time=1
-
- /* create T:Help directory
- ** - this also flags that the help function has been called
- */
- IF ~EXISTS("T:Help") THEN DO
- IF debug=1 THEN SAY 'Initialising T:Help directory'
- 'makedir' "T:Help"
- END
- IF debug=1 THEN SAY "Displaying default help page..."
-
- END
-
- OTHERWISE url = get_url(help_url)
-
- END
-
- /*
- ** Display url using Openurl
- */
-
- IF debug=1 THEN SAY 'Displaying file...'url
- openurl '"'url'"'
-
- /* user has ended help session */
- IF first_time=1 THEN DO
- SAY 'All done! Exiting...'
- CALL Clean_up
- END
-
- /* exit gethelp */
- EXIT
-
-
- /**********************************************************
- ** get a correctly formatted url ready to feed to a browser
- */
-
- get_url:
-
- PARSE ARG help_url
-
- /*
- ** check for file://localhost/, file:///, http:// or ftp:// paths
- */
- pos_local = INDEX(help_url,"file://localhost/")
- IF pos_local>0 THEN DO
- help_url=RIGHT(help_url,LENGTH(help_url)-17)
- IF ~EXISTS(help_url) THEN DO
- clean_up
- EXIT 10
- END
- IF debug=1 THEN DO
- SAY "Yep, its a local file [file://localhost/]"
- SAY help_url
- END
- END
- ELSE DO
- pos_local = INDEX(help_url,"file:///")
- IF pos_local>0 THEN DO
- help_url=RIGHT(help_url,LENGTH(help_url)-8)
- IF ~EXISTS(help_url) THEN DO
- clean_up
- EXIT 10
- END
- IF debug=1 THEN DO
- SAY "Yep, its a local file [file:///]"
- SAY help_url
- END
- END
- ELSE DO
- pos_http = INDEX(help_url,"http:")
- pos_ftp = INDEX(help_url,"ftp:")
- IF pos_http>0 OR pos_ftp>0 THEN DO
- SAY "Yep, it's online - future capability enhancement!"
- clean_up
- EXIT
- END
- END
- END
-
- /*
- ** end game is to determine help_file_name
- */
-
- /*
- ** parse any assigns or devices in path,
- ** trim assign/device from help_url
- */
- pos_assign = INDEX(help_url,":")
- IF poss_assign>0 THEN DO
- help_path = RIGHT(help_url,LENGTH(help_url)-pos_assign)
- END
- ELSE DO
- /* no : markers! */
- help_path = help_url
- END
-
- /*
- ** now check for / markers,
- ** look past these..
- */
- pos_dir = LASTPOS("/",help_path)
- IF pos_dir>0 THEN DO
- help_file = RIGHT(help_path,LENGTH(help_path)-pos_dir)
- END
- ELSE DO
- /* there were no / markers! */
- help_file = help_path
- END
-
- /* remove .htm(l) suffix */
- help_file_name = SUBSTR(help_file,1,POS('.',help_file)-1)
-
- /*
- ** set up help directory in T: and first file to show
- */
- help_directory = "T:Help/"help_file_name
- help_html = help_file_name".html"
-
- /* debug info */
- IF debug=1 THEN DO
- SAY "help_file="help_file
- SAY "help_file_name="help_file_name
- SAY "help_directory="help_directory
- SAY "help_html="help_html
- END
-
- /*
- ** extract html files if not already cached
- */
- IF ~EXISTS(help_directory) THEN
- DO
- /* confirm we have a T:Help directory */
- IF ~EXISTS("T:Help") THEN DO
- IF debug=1 THEN SAY 'NOTE - a browser has directly accessed a help file!'
- 'makedir' "T:Help"
- /* spawn process to monitor Browser quit */
- 'RUN >NIL: SYS:Rexxc/rx GetHelp.rexx QUIT'
- END
-
- /* copy url to T: */
- IF debug=1 THEN SAY "copying url to T:"
- 'copy QUIET "'help_url'"' temp_url
- IF debug=1 THEN SAY "url copied..."
-
- /* create help topic subdirectory */
- /* NOTE: this variable may need linepunching */
- 'makedir' temp_dir
-
- IF debug=1 THEN 'lha -I -X x "'temp_url'"' temp_dir'/'
- ELSE 'lha -I -X -q x "'temp_url'"' temp_dir'/'
-
- /* delete temp_url */
- 'delete QUIET' temp_url
-
- /* rename temp directory */
- 'rename QUIET' temp_dir '"'help_directory'"'
- END
-
- /*
- ** if no <help_html>.htm(l) or main.html, we have an error!
- */
- IF ~EXISTS(help_directory"/"help_html) THEN DO
-
- /* check for .htm suffix */
- IF EXISTS(help_directory"/"help_file_name".htm") THEN help_html = help_file_name".htm"
- ELSE DO
-
- /* check for main.html (Guide to html conversion?) */
- IF EXISTS(help_directory"/main.html") THEN help_html = "main.html"
- ELSE DO
- ADDRESS COMMAND
- msg = '"Could not find main.html or 'help_html'..."'
- 'requestchoice' 'Browser' msg 'Investigate'
- CALL clean_up
- EXIT
- END
-
- END
-
- END
-
- IF debug=1 THEN SAY "final help_html="help_html
-
- /* tell browser where first file will be.. */
- url = "file:///"help_directory"/"help_html
-
- RETURN url
-
- /************************************************
- ** clean up and exit on-line help
- */
-
- clean_up:
-
- ADDRESS COMMAND
-
- /* give browser time to appear! */
- 'WAIT' 5
-
- /* this line is ugly, but with OpenUrl have no identified way of knowing which browser is in use..*/
- DO FOREVER
- IF (~SHOW('P','IBROWSE')&~SHOW('P','VOYAGER')&~SHOW('P','AWEB.1')&~SHOW('P','MOREHTML')) THEN BREAK
- 'WAIT' 5
- END
-
- IF debug=1 THEN SAY 'Deleting T: files...'
-
- /* remove T: files */
- 'delete' ">NIL: T:Help ALL"
- 'delete' ">NIL: T:temp#?"
- 'delete' ">NIL: T:Command#?"
- IF debug=1 THEN SAY 'Finished!'
-
- RETURN
-