2024-03-16 16:25:48 +00:00
|
|
|
|
#include "/Demo/ToHtmlToTXTDemo/ToHtml.HC.Z"
|
|
|
|
|
|
|
|
|
|
U8 *FilenameToURL(U8 *filename, I64 line)
|
|
|
|
|
{
|
2024-03-23 15:27:10 +00:00
|
|
|
|
filename[StrLen(filename) - 2] = NULL;
|
2024-03-16 16:25:48 +00:00
|
|
|
|
|
|
|
|
|
U8 *htmlext = "";
|
|
|
|
|
if (StrMatch(".DD", filename))
|
|
|
|
|
htmlext = ".HTML";
|
|
|
|
|
|
2024-03-23 15:27:10 +00:00
|
|
|
|
return MStrPrint("/Wb%s%s#l%d", filename + 2, htmlext, line);
|
2024-03-16 16:25:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U8 *LinkCvt(U8 *link_st)
|
|
|
|
|
{
|
|
|
|
|
U8 *res = NULL, *filename, *needle;
|
|
|
|
|
I64 i, num;
|
|
|
|
|
|
|
|
|
|
if (link_st) {
|
|
|
|
|
i = EdLinkCvt(link_st, &filename, &needle, &num);
|
|
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
|
case LK_FILE_LINE:
|
|
|
|
|
case LK_PLAIN_LINE:
|
|
|
|
|
case LK_FILE:
|
|
|
|
|
res = FilenameToURL(filename, num);
|
|
|
|
|
break;
|
|
|
|
|
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:
|
|
|
|
|
res = TOSLinkCvt1(link_st);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (DocFileEd(i, filename, needle, &num, EDF_UNCOLLAPSE | EDF_BAIL))
|
|
|
|
|
res = FilenameToURL(filename, num);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Free(filename);
|
|
|
|
|
Free(needle);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2024-03-16 10:26:19 +00:00
|
|
|
|
|
|
|
|
|
CDirEntry *start_entry = FilesFind(
|
2024-03-23 15:27:10 +00:00
|
|
|
|
"/*.HC.Z;*/.HH.Z;*.DD.Z;!/Home/*",
|
2024-03-16 10:26:19 +00:00
|
|
|
|
FUF_RECURSE | FUF_JUST_FILES
|
|
|
|
|
);
|
|
|
|
|
|
2024-03-16 16:25:48 +00:00
|
|
|
|
|
2024-03-16 10:26:19 +00:00
|
|
|
|
CDirEntry *entry = start_entry;
|
|
|
|
|
|
2024-03-23 15:27:10 +00:00
|
|
|
|
U8 *html_header =
|
2024-03-16 16:25:48 +00:00
|
|
|
|
"<!DOCTYPEhtml>\n"
|
|
|
|
|
"<html lang=\"en\">\n"
|
|
|
|
|
"<head>\n"
|
|
|
|
|
"<meta charset=\"UTF-8\">\n"
|
|
|
|
|
"<meta name=\"generator\" content=\"TempleOS V5.03\">\n"
|
2024-03-23 15:27:10 +00:00
|
|
|
|
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
|
2024-03-16 16:25:48 +00:00
|
|
|
|
"<link rel=\"stylesheet\" href=\"/style/templeos.css\">\n"
|
|
|
|
|
"<script src=\"/script/templeos.js\"></script>\n";
|
2024-03-16 10:26:19 +00:00
|
|
|
|
|
2024-03-23 15:27:10 +00:00
|
|
|
|
U8 *body_header =
|
|
|
|
|
"<body>\n"
|
|
|
|
|
"<pre style=\"font-family: courier, monospace; font-size: 10pt;\">\n";
|
|
|
|
|
|
2024-03-16 16:25:48 +00:00
|
|
|
|
Del("C:/Home/Src", FALSE, TRUE);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
2024-03-16 10:26:19 +00:00
|
|
|
|
Print("%s", entry->full_name);
|
|
|
|
|
|
2024-03-16 16:25:48 +00:00
|
|
|
|
U8 *new_name = MAlloc(2 *StrLen(entry->full_name));
|
2024-03-16 10:26:19 +00:00
|
|
|
|
StrPrint(new_name, "/Home/Src%s", entry->full_name + 2);
|
2024-03-16 16:25:48 +00:00
|
|
|
|
|
|
|
|
|
if (StrMatch(".DD", entry->full_name)) {
|
|
|
|
|
FileExtRem(new_name);
|
|
|
|
|
CatPrint(new_name, ".DD.HTML");
|
|
|
|
|
} else {
|
|
|
|
|
new_name[StrLen(new_name) - 2] = NULL;
|
|
|
|
|
}
|
2024-03-16 10:26:19 +00:00
|
|
|
|
|
|
|
|
|
Print(" -> %s\n", new_name);
|
|
|
|
|
|
2024-03-16 16:25:48 +00:00
|
|
|
|
if (StrMatch(".DD", entry->full_name))
|
|
|
|
|
ToHtml(
|
|
|
|
|
entry->full_name,
|
|
|
|
|
new_name,
|
2024-03-23 15:27:10 +00:00
|
|
|
|
html_header,
|
|
|
|
|
body_header,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
80,
|
|
|
|
|
TRUE,
|
2024-03-16 16:25:48 +00:00
|
|
|
|
&LinkCvt,
|
|
|
|
|
);
|
|
|
|
|
else
|
|
|
|
|
Copy(entry->full_name, new_name);
|
|
|
|
|
|
2024-03-16 10:26:19 +00:00
|
|
|
|
} while (entry = entry->next);
|
|
|
|
|
|
2024-03-23 15:27:10 +00:00
|
|
|
|
DirTreeDel(start_entry);
|