; $Id: mk_html_help.pro,v 1.6 1995/07/20 15:52:59 griz Exp $ ;+ ; NAME: ; MK_HTML_HELP2 ; ; PURPOSE: ; Creates a html document from a list of IDL procedures. ; Given a list of IDL procedure files (.PRO), VMS text library ; files (.TLB), or directories that contain such files, this procedure ; generates a file in the HTML format that contains the documentation ; for those routines that contain a DOC_LIBRARY style documentation ; template. The output file is compatible with World Wide Web browsers. ; This version is enhanced over the routine supplied by IDL, It will ; also cross reference, print the purpose, and add links to the source ; code. ; ; CATEGORY: ; Help, documentation. ; ; CALLING SEQUENCE: ; MK_HTML_HELP, Sources, Outfile ; ; INPUTS: ; Sources: A string or string array containing the name(s) of the ; .pro or .tlb files (or the names of directories containing ; such files) for which help is desired. If a source file is ; a VMS text library, it must include the .TLB file extension. ; If a source file is an IDL procedure, it must include the .PRO ; file extension. All other source files are assumed to be ; directories. If not provided, searches down directory tree ; from current directory for files. ; ; Outfile: The name of the output file which will be generated without ; HTML extension. ; ; If no inputs are given: All directories in the current directory tree ; are used with the exception of: directories named: 'obsolete' ; or 'SCCS.' (UNIX only) ; ; KEYWORDS: ; TITLE: If present, a string which supplies the name that ; should appear as the Document Title for the help. ; FILENAME: Alternative method of specifying Outfile (see above) ; VERBOSE: Normally, MK_HTML_HELP does its work silently. ; Setting this keyword to a non-zero value causes the procedure ; to issue informational messages that indicate what it ; is currently doing. !QUIET must be 0 for these messages ; to appear. ; STRICT: If this keyword is set to a non-zero value, MK_HTML_HELP will ; adhere strictly to the HTML format by scanning the ; the document headers for characters that are reserved in ; HTML (",&,"). These are then converted to the appropriate ; HTML syntax in the output file. By default, this keyword ; is set to zero (to allow for faster processing). ; CROSSLINK:If this keyword is set MK_HTML_HELP will create a cross ; reference between library files. ; CLTURBO: If this keyword is set to a single character string, then the ; cross reference procedure will only cross reference lines that ; contain the character given in CLTURBO. This greatly increases ; the speed of the routine. By default the double quote (") is ; used ; PRINT_PURPOSE: If this keyword is set then the first line after PURPOSE: ; is printed in the output file. ; MASTLIST: If set, create master list only. Do not create subdirectory ; file listings. ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; A help file with the name given by the Outfile argument is ; created. ; ; RESTRICTIONS: ; The following rules must be followed in formatting the .pro ; files that are to be searched. ; (a) The first line of the documentation block contains ; only the characters ";+", starting in column 1. ; (b) There must be a line which contains the string "NAME:", ; which is immediately followed by a line containing the ; name of the procedure or function being described in ; that documentation block. If this NAME field is not ; present, the name of the source file will be used. ; (c) The last line of the documentation block contains ; only the characters ";-", starting in column 1. ; (d) Every other line in the documentation block contains ; a ";" in column 1. ; ; Note that a single .pro file can contain multiple procedures and/or ; functions, each with their own documentation blocks. If it is desired ; to have "invisible" routines in a file, i.e. routines which are only ; for internal use and should not appear in the help file, simply leave ; out the ";+" and ";-" lines in the documentation block for those ; routines. ; ; No reformatting of the documentation is done. ; ; MODIFICATION HISTORY: ; July 5, 1995, DD, RSI. Original version. ; July 13, 1995, Mark Rivers, University of Chicago. Added support for ; multiple source directories and multiple documentation ; headers per .pro file. ; July 17, 1995, DD, RSI. Added code to alphabetize the subjects; ; At the end of each description block in the HTML file, ; added a reference to the source .pro file. ; July 18, 1995, DD, RSI. Added STRICT keyword to handle angle brackets. ; July 19, 1995, DD, RSI. Updated STRICT to handle & and ". ; Changed calling sequence to accept .pro filenames, .tlb ; text librarie names, and/or directory names. ; Added code to set default subject to name of file if NAME ; field is not present in the doc header. ; September, 1995, D. Larson. SSL Berkeley. Added crosslink, print_purpose ; clturbo. ; October 4, 1995, D. Larson. SSL Berkeley. Added link to source file. ; October 3, 1996, F. Marcoline. SSL Berkeley. Added Alphabet Jumpline. ; October 10, 1996, D. Larson. Added Listing by Directory. ; October 1, 2007, J. McTiernan, allow to work with more than 28 ; directories, dropped obsolete /stream keywords from ; openw calls. ; ;FILE: mk_html_help2.pro ;VERSION 1.26 ;LAST MODIFICATION: 99/04/22 ;- ; forward_function setup_sources function setup_sources,base compile_opt idl2 sources = findfile(base+'*') i = where( strpos(sources,':') gt 0,cnt) if cnt gt 0 then sources = sources[i] else return,'' i = where( strpos(sources,'SCCS') lt 0,cnt) ; ignore all SCCS directories if cnt gt 0 then sources = sources[i] else return,'' i = where( strpos(sources,'obsolete') lt 0,cnt) ; ignore all obsolete direcs if cnt gt 0 then sources = sources[i] else return,'' on_ioerror,cantwrite indx = [-1] for i = 0,n_elements(sources)-1 do begin sepsource = str_sep(sources[i],':') sources[i] = sepsource[0] openw,lun,sources[i]+'/foo',/get_lun,/delete free_lun,lun indx = [indx,i] cantwrite: endfor if n_elements(indx) eq 1 then return,'' sources = sources[indx[1:*]] for i = 0,n_elements(sources)-1 do $ sources = [sources,setup_sources(sources[i]+'/')] i = where(sources ne '',cnt) if cnt gt 0 then sources = sources[i] else return,'' return,sources end ;---------------------------------------------------------------------------- PRO alt_mhh_strict, txtlines ; ; Replaces any occurrence of HTML reserved characters (",&,") in the ; given text lines with the appropriate HTML counterpart. ; ; entry: ; txtlines - String array containing the text line(s) to be altered. ; exit: ; txtlines - Same as input except that reserved characters have been ; replaced with the appropriate HTML syntax. ; compile_opt idl2 count = N_ELEMENTS(txtlines) FOR i=0,count-1 DO BEGIN txt = txtlines[i] ; Ampersands get replaced with &. Must do ampersands first because ; they are used to replace other reserved characters in HTML. spos = STRPOS(txt,'&') WHILE (spos NE -1) DO BEGIN newtxt = STRMID(txt,0,spos)+'&'+STRMID(txt,spos+1,STRLEN(txt)-spos+1) txt = newtxt spos = STRPOS(txt,'&',spos+1) ENDWHILE txtlines[i] = txt ; Left angle brackets get replaced with < spos = STRPOS(txt,'<') WHILE (spos NE -1) DO BEGIN newtxt = STRMID(txt,0,spos)+'<'+STRMID(txt,spos+1,STRLEN(txt)-spos+1) txt = newtxt spos = STRPOS(txt,'<',spos+1) ENDWHILE txtlines[i] = txt ; Right angle brackets get replaced with > spos = STRPOS(txt,'>') WHILE (spos NE -1) DO BEGIN newtxt = STRMID(txt,0,spos)+'>'+STRMID(txt,spos+1,STRLEN(txt)-spos+1) txt = newtxt spos = STRPOS(txt,'>',spos+1) ENDWHILE txtlines[i] = txt ; Double quotes get replaced with " spos = STRPOS(txt,'"') WHILE (spos NE -1) DO BEGIN newtxt = STRMID(txt,0,spos)+'"'+STRMID(txt,spos+1,STRLEN(txt)-spos+1) txt = newtxt spos = STRPOS(txt,'"',spos+1) ENDWHILE txtlines[i] = txt ENDFOR END ;---------------------------------------------------------------------------- PRO alt_mhh_grab_hdr,name,dict,infile_indx,libfile_indx,txt_file,verbose,$ strict, print_purpose=print_purpose,allfiles=allfiles ; ; Searches an input file for all text between the ;+ and ;- comments, and ; updates the scratch text file appropriately. Note that this routine ; will extract multiple comment blocks from a single source file if they are ; present. ; ; entry: ; name - Name of file containing documentation header(s). ; dict[] - Dictionary entries for each documentation block in the .PRO ; file. Each dictionary entry is a structure with an index to ; the source filename, an index to the extracted library ; filename (useful only for VMS text libraries), a subject name, ; scratch file offset, unique id (for duplicate names), and ; number of lines of documentation text. ; This parameter may be originally undefined at entry. ; infile_indx - Index of the source .pro or .tlb filename. ; libfile_indx - Index of extracted library filename. If the source ; filename was not a VMS text library, this value should be ; set to -1L. ; txt_file - Scratch file to which the documentation header will ; be written. ; verbose - TRUE if the routine should output a descriptive message ; when it finds the documentation header. ; strict - If nonzero, the routine will adhere strictly to HTML format. ; The document headers will be scanned for characters that are ; reserved in HTML (",&,"), which are then converted to the ; appropriate HTML syntax in the output file. ; ; exit: ; txt_file - Updated as necessary. Positioned at EOF. ; dict[] - Updated array of new dictionary entries. ; ; Under DOS, formatted output ends up with a carriage return linefeed ; pair at the end of every record. The resulting file would not be ; compatible with Unix. Therefore, we use unformatted output, and ; explicity add the linefeed, which has ASCII value 10. compile_opt idl2 LF=10B on_ioerror,bad IF (libfile_indx NE -1L) THEN $ OPENR, in_file, /GET, FILEPATH('mkhtmlhelp.scr',/TMP), /DELETE $ ELSE $ OPENR, in_file, /GET, name IF (verbose NE 0) THEN dprint, 'File = '+name,dlevel=2 ; IF (verbose NE 0) THEN message,/info, 'File = '+name if keyword_set(allfiles) then docum=0 else docum=1 WHILE (1) DO BEGIN ; Find the opening line of the next header. tmp = '' found = 0 num = 0 header = '' ON_IOERROR, DONE WHILE (NOT found) DO BEGIN READF, in_file, tmp IF (STRMID(tmp,0,2) EQ ';+') THEN found = 1 if eof(in_file) and docum eq 0 then begin found=1 docum=2 endif ENDWHILE IF (found) THEN BEGIN ; Find the matching closing line of the header. if docum eq 2 then begin header = [header,'No Documentation for this routine.'] num = num+1 endif else begin found = 0 WHILE (NOT found) DO BEGIN READF,in_file,tmp IF (STRMID(tmp,0,2) EQ ';-') THEN BEGIN found =1 ENDIF ELSE BEGIN tmp = strmid(tmp, 1, 1000) header = [header, tmp] num = num + 1 ENDELSE ENDWHILE endelse docum=1 IF (strict) THEN alt_mhh_strict,header ; Done with one block of header ; Keep track of current scratch file offset, then write doc text. POINT_LUN,-txt_file,pos FOR i=1, num DO BEGIN WRITEU, txt_file, header[i],LF ENDFOR ; Search for the subject. It is the line following name. index = WHERE(STRTRIM(header, 2) EQ 'NAME:', count) IF (count eq 1) THEN BEGIN sub = STRUPCASE(STRTRIM(header[index[0]+1], 2)) IF (verbose NE 0) THEN dprint, 'Routine = '+sub ; If the NAME field was not present, set the subject to the name of the ; source text file. ENDIF ELSE BEGIN IF (verbose NE 0) THEN dprint,'Properly formatted NAME entry not found...' ifname = name CASE !VERSION.OS_FAMILY OF 'Windows': tok = '\' 'MacOS': tok = ':' ELSE: tok = '/' ENDCASE ; Cut the path. sp0 = 0 spos = STRPOS(ifname,tok,sp0) WHILE (spos NE -1) DO BEGIN sp0 = spos+1 spos = STRPOS(ifname,tok,sp0) ENDWHILE ifname = STRMID(ifname,sp0,(STRLEN(ifname)-sp0)) ; Cut the suffix. spos = STRPOS(ifname,'.') IF (spos NE -1) THEN ifname = STRMID(ifname,0,spos[0]) IF (strict) THEN alt_mhh_strict, ifname sub = STRUPCASE(ifname) IF (verbose NE 0) THEN dprint,' Setting subject to filename: '+sub+'.' ENDELSE ; Search for the Purpose. It is the line following purpose: index = WHERE(STRTRIM(header, 2) EQ 'PURPOSE:', count) IF keyword_set(print_purpose) and (count eq 1) THEN BEGIN purpose = STRTRIM(header[index[0]+1], 2) IF (verbose NE 0) THEN dprint, 'Purpose = '+purpose,dlevel=2 ;IF (verbose NE 0) THEN message,/info, 'Purpose = '+purpose ENDIF ELSE purpose='' ; Calculate unique id in case of duplicate subject names. IF (N_ELEMENTS(dict) EQ 0) THEN $ ndup=0 $ ELSE BEGIN dpos = WHERE(dict.subject EQ sub,ndup) IF (ndup EQ 1) THEN BEGIN dict[dpos[0]].id = 1 ndup = ndup + 1 ENDIF ENDELSE ; Create a dictionary entry for the document header. entry = {DICT_STR,subject:sub,purpose:purpose,indx:infile_indx,lib:libfile_indx,$ id:ndup,offset:pos,nline:num} IF (N_ELEMENTS(dict) EQ 0) THEN dict = [entry] ELSE dict = [dict,entry] ENDIF ENDWHILE DONE: FREE_LUN, in_file BAD: ON_IOERROR, NULL END PRO alt_mhh_dum_file,outfile,title,verbose compile_opt idl2 OPENW,final_file,outfile,/GET_LUN IF (verbose NE 0) THEN dprint,'Building '+outfile+'...',dlevel=2 ;IF (verbose NE 0) THEN message,/info,'Building '+outfile+'...' ; Print a comment indicating how the file was generated. PRINTF,final_file,'' ; Header stuff. PRINTF,final_file,'' PRINTF,final_file,' ' ; Title. PRINTF,final_file,'
' PRINTF,final_file,''
PRINTF,final_file,'This page was created by the IDL library routine '
PRINTF,final_file,'mk_html_help2
.'
PRINTF,final_file,'
'
; PRINTF,final_file,' For more information on '
; PRINTF,final_file,'this routine, refer to the IDL Online Help Navigator '
; PRINTF,final_file,'or type:
' ; PRINTF,final_file,'
? mk_html_help
' ; PRINTF,final_file,'at the IDL command line prompt.' PRINTF,final_file,'
' PRINTF,final_file,'Last modified: ',SYSTIME(),'.
' PRINTF,final_file,' ' PRINTF,final_file,'
'
PRINTF, final_file, 'This page was created by the IDL library routine '
PRINTF, final_file, 'mk_html_help2
.'
PRINTF, final_file, '
'
; PRINTF,final_file,' For more information on '
; PRINTF,final_file,'this routine, refer to the IDL Online Help Navigator '
; PRINTF,final_file,'or type:
' ; PRINTF,final_file,'
? mk_html_help
' ; PRINTF,final_file,'at the IDL command line prompt.' PRINTF, final_file, '
' PRINTF, final_file, 'Last modified: ', SYSTIME(), '.
' PRINTF, final_file, ' ' PRINTF, final_file, '
' PRINTF, final_file, '
' PRINTF, final_file, '
'
PRINTF, templun, 'This page was created by the IDL library routine '
PRINTF, templun, 'mk_html_help2
.'
PRINTF, templun, '
'
PRINTF, templun, '
' PRINTF, templun, 'Last modified: ', SYSTIME(), '.
' PRINTF, templun, ' ' PRINTF, templun, '
' free_lun, templun ;close this file now endfor endif ;stop ; Index. PRINTF, final_file, '
' PRINTF, final_file, '
' PRINTF, final_file, ' ' if not keyword_set(mastlist) then begin for i = 0, n_elements(u)-1 do begin openw, templun, suboutfile[i]+'.html', /get_lun, /append PRINTF, templun, '
' tmp = '' POINT_LUN, txt_file, entry.offset FOR j = 1, entry.nline DO BEGIN READF, txt_file, tmp if keyword_set(crosslink) then begin pos = 0 if keyword_set(clturbo) then pos = strpos(tmp, clturbo) if pos lt 0 then goto, norefsatall for cross = 0, count-1 do begin reference = dict[cross].subject if entry.subject eq reference then goto, noreference refdir = dictwhdir[cross] pos = strpos(strupcase(tmp), reference) if pos lt 0 then goto, noreference reflen = strlen(reference) tmplen = strlen(tmp) refarr = bytarr(tmplen+2) refarr[1:tmplen] = byte(tmp) if is_letter[refarr[pos]] then goto, noreference if is_letter[refarr[pos+reflen+1]] then goto, noreference newref = ''+reference+'' refarr = string(refarr[1:tmplen+1]) tmp = strmid(refarr, 0, pos)+newref+strmid(refarr, pos+reflen, 300) IF (verbose NE 0) THEN $ dprint, reference+' cross linked in '+entry.subject,dlevel=2 ;message,/info, reference+' cross linked in '+entry.subject noreference: endfor norefsatall: endif PRINTF, templun, tmp ENDFOR PRINTF, templun, '
' IF (entry.lib NE -1L) THEN BEGIN fname = libfiles[entry.lib] lname = infiles[entry.indx] IF (strict) THEN BEGIN alt_mhh_strict, fname alt_mhh_strict, lname ENDIF PRINTF, templun, '(See '+fname+' in '+lname+')
' ENDIF ELSE BEGIN fname = strippath(infiles[entry.indx]) dir = fname.dir_name reldir = strippath(fname.dir_name) reldir = reldir.file_name fname = fname.file_name IF (strict) THEN alt_mhh_strict, fname fname = ''+dir+'/'+fname+'' PRINTF, templun, '(See '+fname+')
' ENDELSE PRINTF, templun, '