pro mk_idl_doc, dir, httpdir0, filnam, subdir, outarr, outfil=outfil, path=path
;
;
;
;
;HISTORY:
;	Written Jun-97 by M.Morrison
;	13-Jul-98 (MDM) - Changed ".doc" to ".idoc" to avoid conflicts with MSWord documents
;
;
outarr = ''
outdir = concat_dir(dir, subdir)		;directory for doc HTML files
outdir2 = concat_dir(dir, 'details')
httpdir = concat_dir(httpdir0, subdir)
;;httpdir = subdir
httpdir2= concat_dir(httpdir0, 'details')
httpdir2='details'
if (not file_exist(outdir)) then spawn, ['mkdir', outdir], /noshell
if (n_elements(outfil) eq 0) then outfil = concat_dir(dir, str_replace(filnam, '.tab', '.html'))
;
infil = concat_dir(dir, filnam)

if (keyword_set(path)) then begin
    path_arr = str2arr(!path, delim=':')
    ss = where(strpos(path_arr, path) ne -1)
    path_do = path_arr(ss)
    file_delete, infil
    doc1liners, path_do, infil, /doc
end

if (not file_exist(infil)) then return
;
mat = rd_tfile(infil, nocomment='#')
;
html_basics, outfil, title=strupcase(filnam), /head
file_append, outfil, ['The following is a list of some IDL routines which are commonly used.', $
	'There is a sort description and an indication whether it is a (P)rogram, (S)ubroutine, ', $
	'or a (F)unction.  The link on the file name is to the DOC_LIBRARY portion of the', $
	'documentation found at the top of the file.  The "D&S" link (where present) goes to', $
	'a more detailed description and/or some sample products']
;
file_append, outfil, '<pre>'
;
for i=0,n_elements(mat)-1 do begin
    lin = mat(i)
    remtab, lin, lin
    ;lin = strtrim(lin, 2)
    if (strtrim(lin,2) eq '') then lin = ''	;only if full line is blank
    ;
    case strmid(lin, 0, 1) of
	'*': begin		;category
		out = strmid(lin, 2, 999)
		if (strmid(out, 0, 1) ne '-') then out = '------------ ' + out +      ' ------------
	     end
	'': begin		;blank line
		out = ' '
	     end
	' ': begin		;continuation of a description
		out = string(strtrim(lin,2), format='(16x, 7x, a)')
	     end
	else: begin
		arr = str2arr( strcompress(lin), delim=' ')
		if (n_elements(arr) lt 3) then arr = [arr, ' ', ' ', ' ']
		nam = arr(0)
		nam = str_replace(nam, '()', '')	;MDM 11-Jun-97
		typ0 = arr(1)
		typ = typ0
		desc= arr2str(arr(2:*), delim=' ')
		desc_arr = parse_lines(desc, 50)
		pad = ''
		for iii=strlen(nam),15 do pad = pad + ' '
		;
		;
		pfile = path_lib(nam)
		pfile = pfile(0)
		;
		typ_filnam = strmid(pfile, 1, 99)
		typ_filnam = str_replace(typ_filnam, 'ssw_sxt1', 'ssw')
		;
		if (pfile eq '') then begin
		    p1 = nam
		end else begin
		    pmat = rd_tfile(pfile)
		    s1 = where(strtrim(pmat,2) eq ';+')
		    s2 = where(strtrim(pmat,2) eq ';-')
		    if (s2(0) gt s1(0)) and (s1(0) ne -1) then pmat = pmat(s1(0):s2(0))
		    poutfil = concat_dir(outdir, nam + '.idoc')
		    houtfil = concat_dir(httpdir, nam + '.idoc')
		    prstr, pmat, file=poutfil
		    p1 = str2html(houtfil, link=nam)
		    p1 = p1(1)
		    ;
		    typ = str2html(concat_dir(httpdir0, typ_filnam), link=typ0)
		    typ = typ(1)
		end
		;
		p2 = '   '
		dsfil = concat_dir(outdir2, nam + '.html')
		if (file_exist(dsfil)) then begin
		    p2 = str2html( concat_dir(httpdir2, nam + '.html'), link='D&S')
		    p2 = p2(1)
		end
		;
		out = p1 + pad + ' ' + typ + ' ' + p2 + ' ' + desc_arr(0)
		if (n_elements(desc_arr) gt 1) then out = [out, '                       ' + desc_arr(1:*)]
	    end
    endcase
    ;
    print, out
    file_append, outfil, out
    outarr = [outarr, out]
end
;
file_append, outfil, '</pre>'
html_basics, outfil, /trail
if (keyword_set(qstop)) then stop
end
