; define the types of TtH reference
tth_types = 'tth' + ['_sEc','FtNt','Fref','_fIg','_tAb','xxxx']
source = ''
read,'* Enter Source name: ',source
break_file,source,aa,ab,ac,ad,ae
outname = ac
; read in the source .html file
;if n_elements(qq) lt 10 then begin
print,'** Reading Source file: ',source
qq = rd_tfile(source)
help,qq
;endif else box_message,'*** Set qq=0 to force a Read ***'
nl = n_elements(qq)
print,' '
; get TtH version the info embedded at the start
pt2h = strpos(qq(2),'TtH ')+4
t2h_ver = strmid(qq(2),pt2h,strpos(strmid(qq(2),pt2h,10),'"'))
;---------------------------------------------------------------
; go through looking for section divisions and names
;---------------------------------------------------------------
add_seg = intarr(4,50) & k=1
name_pos = intarr(2,1000) & name_text = strarr(1000) & kname=0
IsIndex = 0
IsAppendix = 0
flag_tab_fig = 0
tab_fig = strarr(2,1000) & ktbfg=0
for j=0,nl-1 do begin
nww = strpos(qq(j),'!www---')
if nww gt 0 then begin
print,j,qq(j:j+1),format='(i6,3x,2a)'
add_seg(0,k)=j & k=k+1
if strpos(qq(j),'!www---INDEX') gt 0 then IsIndex=k-1
if strpos(qq(j),'!www---APPENDIX') gt 0 then begin
IsAppendix = k-1
endif
endif
nNAM = strpos(qq(j),'')
cc1 = strmid(contents,0,pc1+5) ;Contents H1 statement
contents = '
'+strmid(contents,pc1+5,strlen(contents)+100)
contents = str_sep(contents,'')+''
contents = [qqseg(0),cc1,contents]
qqseg = contents & nstat = n_elements(qqseg)
contents_qsec = strarr(nstat)
end
(IsAppendix gt 0) and (jseg eq IsAppendix): begin ;Appendix (was nset+2)
section = outname+'_appendix.html'
; append the footnotes to the Appendices
; check in case only footnote is in the appendix
IsFootnote = 0
if jfoot eq 0 then qfoot = where(strpos(qqseg,'FtNt') gt 0)
if qfoot(0) gt 0 then IsFootnote = 1
print,'>>>>>>Footnotes: ',jfoot, IsFootnote
if (jfoot gt 0) or IsFootnote then begin
help,qqseg,nstat
footnotes = qq(add_seg(0,nsect+4)+1:add_seg(1,nsect+4))
qqseg = [qqseg,footnotes]
nstat = n_elements(qqseg)
qqseg = qqseg(0:nstat-3) ;drop TtH translation statements
nstat = n_elements(qqseg)
help,qqseg,nstat
endif
end
(IsIndex gt 0) and (jseg eq IsIndex): begin ;Index (was nsect+3)
section = outname+'_index.html'
bgcolor='ivory'
qqseg = qqseg(1:*) ;drop 1st line, contents not prepended
nstat = n_elements(qqseg)
end
else: section = outname+'_sec'+strtrim(string(jseg-1,format='(i2)'),2)+'.html'
endcase
;---------------------------------------------------------------
; modify any references found in the section
;---------------------------------------------------------------
if jseg ge 1 then begin
print,'** Re-jig href statements'
for jline = 0,nstat-1 do begin
jpoint = 0
rescan:
cline = qqseg(jline)
; any hypertext link begins with "href"
phref = strpos(strmid(cline,jpoint,5000),'href')
if phref gt 0 then begin
phref = phref + jpoint
; print,jline,qqseg(jline),format='(i6,3x,a)'
print,strmid(cline,phref,50)
; if there is a "#", it is a names reference of som type
phash = strpos(strmid(cline,phref,50),'#')
;; phash = strpos(cline,'#')
if phash gt 0 then begin
phash = phash + phref
ttype = strmid(cline,phash+1,7)
wtype = (where(ttype eq tth_types))(0)
case 1 of
;>>> first consider the case of a TtH reference; treat accordingly
(wtype eq 0) or (wtype eq 1): begin ;section or footnote
qsec = strmid(cline,phash+8,5)
pdot = strpos(qsec,'.')
if pdot le 0 then pdot = strpos(qsec,'"')
qsec = strmid(qsec,0,pdot)
print,qsec,' <<** #tth REFERENCE: ',tth_types(wtype),jline,jpoint,phash
if (wtype eq 1) then begin ;(footnote)
;; tref = strmid(cline,phash+8,3)
;; if jseg lt nseg-1 then begin
ftnt_refs(0,jfoot) = strtrim(string(jseg-1),2)
ftnt_refs(1,jfoot) = qsec ;tref
jfoot = jfoot+1
;; endif
endif
end
(wtype eq 2): begin ;back-link from footnote
tref = strmid(cline,phash+8,3)
qfoot = (where(tref eq ftnt_refs(1,0:jfoot-1)))(0)
print,'******',ftnt_refs(0,qfoot),'+++',ftnt_refs(1,qfoot),format='(4a)'
print,tref,' <<** #tth REFERENCE: ',tth_types(wtype),jline,jpoint,phash
qsec = ftnt_refs(0,qfoot) ;back reference
end
(wtype eq 3): begin ;figure (fIg)
tref = strmid(cline,phash+8,1)
qsec = strtrim(string(jseg-1),2)
print,tref,' <<<<** #tth FIGURE: ',tth_types(wtype),jline,jpoint,phash
end
(wtype eq 4): begin ;table (tAb) ??????????
tref = strmid(cline,phash+8,1)
qsec = strtrim(string(jseg-1),2)
print,tref,' <<<<** #tth TABLE: ',tth_types(wtype),jline,jpoint,phash
end
;>>> Not a listed type - must be a LaTeX reference (\ref to a \label)
else: begin ;LaTeX reference
qsec = strmid(cline,phash,100)
pchev = strpos(strmid(cline,phash,100),'>')+phash
qsec = strmid(cline,pchev+1,100)
if jseg lt nsect+2 then pdot = strpos(qsec,'.') $
else pdot = strpos(qsec,'-')
if pdot le 0 then pdot = strpos(qsec,'<')
qsec = strmid(qsec,0,pdot)
print,qsec,' <<** LaTeX',jline,jpoint,phash
qhref = strmid(strmid(cline,phash+1,100),0,strpos(strmid(cline,phash+1,100),'"'))
wname = (where(qhref eq name_text))(0)
print,'<<< qhref: ',qhref,wname
if wname ge 0 then begin
print,name_text(wname),name_pos(*,wname)
qsec = strtrim(string(name_pos(1,wname)),2)
qnew_name = (where(strpos(tab_fig,name_text(wname)) eq 0))(0)
if qnew_name ge 0 then begin
print,'Tab_fig: ',tab_fig(*,qnew_name/2)
new_name = tab_fig(0,qnew_name/2)
print,'Replace: ',name_text(wname),' with ',new_name
cline = str_replace(cline,name_text(wname),new_name)
print,'???? ',cline
endif
endif
end
endcase
; construct the revised reference including the outfile name
nwhref = outname+'_sec'+qsec+'.html' & len_nwhref = strlen(nwhref)
qx = where(qsec eq sect_nos)
if qx(0) lt 0 then nwhref = outname+'_appendix.html'
nwhref = nwhref+strmid(cline,phash,10000)
print,nwhref
ncline = strmid(cline,0,phash)+nwhref
qqseg(jline) = ncline
if jseg eq 1 then contents_qsec(jline) = qsec
; allow for multiple references on the same line
print,jpoint,phash,len_nwhref,strlen(ncline),' <<<<<<<<<'
jpoint = phash + 7 + len_nwhref
if jpoint lt strlen(ncline) then goto, rescan
;>>> href without a #; and EXTERNAL link?
endif else begin
print,'************ EXTERNAL LINK ************'
phash = phref+5
;; qsec = strmid(cline,phash,100)
pchev = strpos(strmid(cline,phash,100),'>')+phash
;; qsec = strmid(cline,pchev+1,100)
;; pdot = strpos(qsec,'.')
;; if pdot le 0 then pdot = strpos(qsec,'<')
;; qsec = strmid(qsec,0,pdot)
;; qsec = strtrim(string(jseg-1),2) ;!!!!!!!!!!!!!!
kref = ' target="_top"' ;;+strmid(cline,pchev,100)
ncline = strmid(cline,0,pchev) + kref + strmid(cline,pchev,100)
qqseg(jline) = ncline
print,qsec,' <<<<<<** LaTeX',jline,phash,pchev,pdot
; allow for several references on a line
jpoint = strpos(strmid(ncline,pchev+strlen(kref),100),'>')+pchev+strlen(kref)
;; print,jpoint,strlen(ncline)
if jpoint lt strlen(ncline) then goto, rescan
endelse
newline:
; ??? how to decide on which section if appendices named wrongly!!!
endif
; fix a bug????????????????
qqseg(jline) = str_replace(qqseg(jline),'symbol> ~ ~'
printf,lunw,'