;+
; NAME:
; www_help_crosslinks
; PURPOSE:
; Reads links of links to other www_help collections in the same
; destination directory.
; CATEGORY:
; www_help
; CALLING SEQUENCE:
PRO www_help_crosslinks, destination, style, crosslinks, list, files, $
incl_sets =incl_sets , excl_sets=excl_sets, keep_style=keep_style
; INPUTS:
; destination scalar; type: string
; destination directory of html files
; style array[1]; type: structure
; www_help_style structure
; OPTIONAL INPUT PARAMETERS:
; incl_sets = incl_sets
; list of catalogues to be read
; if not specified all catalogues are read
; excl_sets = excl_sets
; list of catalogues to be excludee
;
; /keep_style by default the current catalogue is not read.
; Override this by setting this keyword.
; OUTPUTS:
; crosslinks array[2,n]; type: string
; array of links read from the catalogues
; array[0,*]: names of all routines
; array[1,*]: corresponding html links
; If no catalogues were read the array doesn't exist
; OPTIONAL OUTPUT PARAMETERS:
; list=list array[n]; type: string
; names of all catalogues (similar to entries
; style.html_name) read
; If no catalogues were read the array doesn't exist
; files=files array[n]; type: string
; fully-qualified files of all catalogue files read
; If no catalogues were read the array doesn't exist
; INCLUDE:
@compile_opt.pro ; On error, return to caller
; CALLS:
; SetFileSpec, GetFileSpec, strposn, where_common, destroyvar, IsType
; hide_env
; PROCEDURE:
; > Information is collected from files in the destination directory
; matching the template '*_list.htm'.
;
; > By default all files are read except for the master list
; 'master_list.htm' and the list associated with the current list
; style.html_name+'_list.htm'.
;
; > Set 'include_sets' to read a specific subset of lists
; Note that the return crosslinks array respects the order specified
; in 'include_sets'.
;
; > Set 'excl_sets' to exclude specific lists
;
; > Keyword /keep_style puts the current list back into the mix.
;
; > Information is collected by reading all lines starting with
from
; the *_list.htm files.
; MODIFICATION HISTORY:
; FEB-2002, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
;-
ditch_style = 1-keyword_set(keep_style )
; Find all _list.htm files
list = filepath(root=destination, '*_list'+style.html_type)
files = file_search(list, count=count)
IF count EQ 0 THEN BEGIN ; No _list.htm files found
message, /info, 'no files found: '+list
destroyvar, files, list
RETURN
ENDIF
SetFileSpec, files
i = strposn(GetFileSpec(from='name',upto='type'),'_list'+style.html_type,list)
; 'list' contains all prefixes
; 'files' contains all file names
IF IsType(incl_sets, /defined) THEN BEGIN
; Reduce 'list' and 'files' to only those entries also in 'include_sets'
iset = where_common(incl_sets, list, count=count)
CASE count OF
0 : BEGIN
destroyvar, files, list
RETURN
END
ELSE: BEGIN
iset = incl_sets[iset]
lset = where_common(list, incl_sets)
list = list [lset]
files = files[lset]
; This respects the order of arguments in the original incl_sets
count = (where(iset[0] eq list))[0]
FOR i=1,n_elements(iset)-1 DO count = [count, (where(iset[i] EQ list))[0]]
files = files[count]
END
ENDCASE
ENDIF
; Drop the current style and master lists
IF n_elements(excl_sets) EQ 0 THEN excl_sets = style.master ELSE excl_sets = [excl_sets,style.master]
IF ditch_style THEN $
IF n_elements(excl_sets) EQ 0 THEN excl_sets = style.html_name ELSE excl_sets = [excl_sets,style.html_name]
; Comparing the remaining list to excl_sets. Retain only
; the subset in list not present in excl_sets
i = where_common(list, excl_sets, absent=iset)
CASE iset[0] OF
-1 : BEGIN
destroyvar, files, list
RETURN
END
ELSE: BEGIN
files = files[iset]
list = list [iset]
END
ENDCASE
nfile = n_elements(files)
record = ''
ul_beg = ''
a_beg = ''
a_len = strlen(a_end)
count = 0
FOR i=0,nfile-1 DO BEGIN
on_ioerror, close_file1
openr, /get_lun, iu, files[i]
readf, iu, record
WHILE NOT eof(iu) DO BEGIN
IF strmid(record,0,4) EQ '' THEN count = count+1
readf, iu, record
ENDWHILE
on_ioerror, null
close_file1:
IF IsType(iu, /defined) THEN free_lun, iu
ENDFOR
crosslinks = strarr(2,count)
n = -1
FOR i=0,nfile-1 DO BEGIN
on_ioerror, close_file2
openr, /get_lun, iu, files[i]
REPEAT readf, iu, record UNTIL strpos(record, ul_beg) NE -1
REPEAT BEGIN
p0 = strpos(record, a_beg)
IF p0 NE -1 THEN BEGIN
p1 = strpos(record, a_end, p0)
entry = strmid(record, p0, p1+a_len-p0)
p0 = strpos(entry,'>' )
p1 = strpos(entry,'<',p0)
name = strmid(entry,p0+1,p1-p0-1)
IF n LT count-1 THEN BEGIN
n = n+1
crosslinks[*,n] = [name,entry]
ENDIF
ENDIF
readf, iu, record
ENDREP UNTIL strpos(record, ul_end) NE -1
on_ioerror, null
message, /info, hide_env(files[i])
close_file2:
IF n_elements(iu) NE 0 THEN free_lun, iu
ENDFOR
n = n+1
IF n LT count THEN i = temporary(crosslinks)
RETURN & END