templeos-info/Copy.HC

107 lines
2.3 KiB
HolyC
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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