function pro_list, outfile=outfile, hc=hc, print=print, dirs=dirs, qstop=qstop, land=land
;
;+
;NAME:
;	pro_list
;PURPOSE:
;	To return a list of the IDL procedures (.PRO files)
;	that are in the IDL path (!path)
;SAMPLE CALLING SEQUENCE:
;	pros = pro_list()
;	pros = pro_list(/hc, /land)
;OPTIONAL KEYWORD INPUT:
;	outfile	- If a filename is passed, the results will also
;		  be written to that file
;	hc	- If set, write the results to a temporary file, print
;		  it and delete it.
;OUTPUT:
;	Return a list of procedure/function/program names
;OPTIONAL KEYWORD OUTPUT:
;	dirs	- the directory associated with the IDL procedure
;HISTORY:
;	Written 23-Apr-92 by M.Morrison
;	29-Apr-93 (MDM) - Added sample calling sequence to the header
;-
;
qhc = 0
qout = 0
if (keyword_set(outfile)) then begin
    openw, lunout, outfile, /get_lun
    qout = 1
end
if (keyword_set(hc)) then begin
    openw, lunhc, 'pro_list.temporary', /get_lun
    qhc = 1
end
qprint = keyword_set(print)
;
ff = file_list(str2arr(!path,delim=':'), '*.pro')
ff = reverse(ff)			;reverse the list of the filenames because uniq takes the LAST unique occurance
					;and we want to list the directory for the FIRST occurrance
split_files, ff, dirs, filnam
ss = uniq(filnam, sort(filnam))
out = filnam(ss)			;puts into alphabetical order
dirs = dirs(ss)
;
;--- Now trim off the .pro
;;out = str_replace(out, '.pro', '')		;too slow
;borrowed the following code from "split_files"
;
delimit=str_lastpos(out,'.')
;
; minimize loop count by using strmid for similar cases
case n_elements(delimit) of
   1:    cases=delimit                                  ; scaler
   else: cases=delimit(uniq(delimit,sort(delimit)))     ; array
endcase
;
for i=0, n_elements(cases)-1 do begin
   casen=where(delimit eq cases(i))
   out(casen)=strmid(out(casen),0,cases(i))
endfor
;
if (qhc or qout) then begin
    n = n_elements(out)
    if (keyword_set(land)) then nchar = 132 else nchar = 80
    width = 20	;characters per filename
    ncol = fix(nchar/width)
    nlin = 45
    npp = ncol*nlin	;n per page
    npag = n/npp
    tit1 = 'PRO_LIST.PRO Output made on ' + !stime
    fmt = '(' + strtrim(ncol,2) + 'a' + strtrim(width,2) + ')'
    if ((n mod npp) ne 0) then npag=npag+1
    for ipag=0,npag-1 do begin
	lin = tit1 + '          Page ' + strtrim(ipag+1,2) + ' of ' + strtrim(npag,2) + string(10b,10b)
	if (qhc) then  printf, lunhc, lin
	if (qout) then printf, lunout, lin
	if (qhc) then print, lunhc, '   '
	if (qout) then print, lunout, '   '
	;
	ff = ''
	if (ipag ne npag-1) then ff = string(12b)
	ss = out( ipag*npp: ((ipag+1)*npp-1)<(n-1) ) + '                    '
	if (qhc) then printf, lunhc, ss, ff, format=fmt
	if (qout) then printf, lunout, ss, ff, format=fmt
	if (qprint) then print, ss, ff, format=fmt
    end
end
if (qhc) then begin
    free_lun, lunhc
    dprint, 'pro_list.temporary', /delete, land=land
end
if (qout) then free_lun, lunout
;
if (keyword_set(qstop)) then stop
return, out
end


