");
} else //Keep same underline status.
u32_attr=u32_attr&~DOCET_UNDERLINE | *_old_u32_attr&DOCET_UNDERLINE;
*_old_u32_attr=u32_attr | *_old_u32_attr&DOCET_LINK_UNDERLINE;
while (ch=*st++) {
switch (ch) {
case '\t':
do {
DocPutKey(doc,CH_SPACE,0);
*_col=*_col+1;
} while (*_col&7);
break;
start:
case 'ã': ptr="pi"; break;
case 'é': ptr="theta"; break;
case 'è': ptr="phi"; break;
case 'ê': ptr="omega"; break;
case 'ì': ptr="inf"; break;
case 'æ': ptr="u"; break;
end:
DocPrint(doc,ptr);
*_col=*_col+StrLen(ptr);
break;
start:
case CH_SHIFT_SPACE: ptr=""; break;
case '&': ptr="&"; break;
case '<': ptr="<"; break;
case '>': ptr=">"; break;
case '"': ptr="""; break;
end:
DocPrint(doc,ptr);
*_col=*_col+1;
break;
default:
if (CH_SPACE<=ch<0x7F || ch=='\n')
DocPutKey(doc,ch,0);
else
DocPrint(doc,".");
*_col=*_col+1;
}
}
}
U8 *TOSLinkCvt2(U8 *filename,I64 line_num)
{// ::/ --> http://www.templeos.org/Wb/
//Make your own LinkCvt routine
U8 *res=NULL,*st;
if (filename) {
st=ExtChg(filename,"html");
if (st && StrLen(st)>3 && !StrNCmp(st+1,":/",2))
res=MStrPrint("http://www.templeos.org/Wb/%s#l%d",st+3,line_num);
Free(st);
}
return res;
}
U8 *URLBibleGateway(U8 *src)
{
U8 buf[STR_LEN],*dst=buf;
if (!MemCmp(src,"BF:",3))
src+=3;
while (*src) {
if (*src==CH_SPACE || *src==',')
*dst++='+';
else
*dst++=*src;
src++;
}
*dst=0;
if (StrOcc(buf,'-'))
return MStrPrint(
"http://www.biblegateway.com/passage/?search=%s&version=NIV",buf);
else
return MStrPrint(
"http://www.biblegateway.com/verse/en/%s",buf);
}
U8 *TOSLinkCvt1(U8 *link_st)
{
static CDoc *bible=NULL;
static I64 locks=0;
U8 *res=NULL,*filename,*needle;
I64 i,num;
if (link_st) {
switch (i=EdLinkCvt(link_st,&filename,&needle,&num)) {
case LK_FILE_LINE:
case LK_PLAIN_LINE:
case LK_FILE:
res=TOSLinkCvt2(filename,num);
break;
case -1:
case LK_DEF:
case LK_HELP_INDEX:
case LK_DOC:
case LK_DOC_ANCHOR:
case LK_DOC_FIND:
case LK_DOC_LINE:
break;
case LK_BIBLE_FIND:
while (LBts(&locks,0))
Yield;
if (!bible)
bible=Adam("DocRead(\"%s\");",filename);
if (DocFind(bible,num,needle))
res=URLBibleGateway(link_st);
LBtr(&locks,0);
break;
default:
if (DocFileEd(i,filename,needle,&num,EDF_UNCOLLAPSE|EDF_BAIL))
res=TOSLinkCvt2(filename,num);
}
Free(filename);
Free(needle);
}
return res;
}
public CDoc *Doc2Html(CDoc *doc_in,U8 *html_header=NULL,U8 *body_header=NULL,
U8 *body_footer=NULL,U8 *html_footer=NULL,Bool line_anchors=TRUE,
U8 (*link_cvt)(U8 *link_st)=&TOSLinkCvt1,Bool line_nums=FALSE)
{//Cvt $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.DD"$doc to HTML file.
CDocEntry *doc_e,*style,*doc_e2;
I64 i,y,old_y=I64_MIN,col,old_u32_attr=DOCET_UNDEF_COLOR,old_attr,digits;
U32 *hl,*src;
U8 *st,st_2[2],*link_st,*style_bitmap=CAlloc(256/8);
CBGR48 p[COLORS_NUM];
GrPaletteGet(p);
CDoc *doc_out=DocNew;
Bool unlock_doc_in=DocLock(doc_in),no_bwd;
old_attr=doc_in->win_task->text_attr;
doc_in->win_task->text_attr=DOC_ATTR_DFT_TEXT;
for (i=0xF0;i<=0xFF;i++)
LBts(style_bitmap,i);
DocRecalc(doc_in,RECALCt_NORMAL|RECALCF_TO_HTML);
digits=Log10(doc_in->head.last->y+1)+1;
st_2[0]=0; st_2[1]=0;
doc_out->flags|=DOCF_PLAIN_TEXT|DOCF_NO_CURSOR;
if (!html_header) html_header=
"\n"
"\n"
"\n"
"\n"
"\n";
if (!body_header) body_header=
"\n"
"\n";
if (!body_footer) body_footer=
"
\n";
if (!html_footer) html_footer=
"\n";
DocPrint(doc_out,"%s",html_header);
DocPrint(doc_out,"\n"
"\n");
DocPrint(doc_out,"%s",body_header);
doc_e=doc_in->head.next;
col=doc_e->x;
y=doc_e->y;
while (doc_e!=doc_in) {
if (!(doc_e->de_flags&DOCEF_SKIP)) {
if (y!=old_y) {
if (line_anchors)
DocPrint(doc_out,"",y+1);
if (line_nums)
DocPrint(doc_out,"%0*d",digits,y+1);
old_y=y;
}
while (yy) {
HtmlPutS(doc_out,doc_e->settings.final_u32_attr,&old_u32_attr,FALSE,
"\n",&col,style_bitmap);
if (++y!=old_y) {
if (line_anchors)
DocPrint(doc_out,"",y+1);
if (line_nums)
DocPrint(doc_out,"%0*d",digits,y+1);
old_y=y;
}
col=0;
}
no_bwd=TRUE;
doc_e2=doc_e->next;
while (doc_e2!=doc_in && doc_e2->y==doc_e->y) {
if (doc_e2->xx) {
no_bwd=FALSE;
break;
}
doc_e2=doc_e2->next;
}
if (no_bwd)
while (colx)
HtmlPutS(doc_out,doc_e->settings.final_u32_attr&~DOCET_UNDERLINE,
&old_u32_attr,TRUE,"",&col,style_bitmap);
link_st=NULL;
if (doc_e->de_flags&DOCEF_HTML_LINK)
link_st=StrNew(doc_e->html_link);
else if (st=DocEntryLink(doc_in,doc_e)) {
link_st=link_cvt(st);
Free(st);
}
if (link_st) {
if (old_u32_attr&DOCET_UNDERLINE &&!(old_u32_attr&DOCET_LINK_UNDERLINE))
DocPrint(doc_out,"");
if (old_u32_attr&DOCET_BLINK)
DocPrint(doc_out,"