kolibrios-gitea/programs/cmm/browser/show_src.h
Kirill Lipatov (Leency) f608182ea2 WebView 2.0 beta 2: WebView.c refactoring
git-svn-id: svn://kolibrios.org@7755 a494cfbc-eb01-0410-851d-a64ba20cac60
2020-03-27 10:38:54 +00:00

98 lines
2.6 KiB
C

enum { TAG=1, VALUE, TEXT, COMMENT, SCRIPT};
int opened_font_counter=0;
int mode;
dword source_buf_end;
void SourceBufAdd(dword _mode, src)
{
dword font_found_pointer, src_orig = src;
if (_mode) mode = _mode;
strcpy(source_buf_end, src);
source_buf_end += strlen(source_buf_end);
if (font_found_pointer = strstr(src, "</font>")) {
opened_font_counter--;
src = font_found_pointer+2;
}
src = src_orig;
if (font_found_pointer = strstr(src, "<font ")) {
opened_font_counter++;
src = font_found_pointer+2;
}
}
void CloseAllOpenedFonts(dword _mode)
{
while (opened_font_counter) SourceBufAdd(_mode, "</font>");
}
dword ShowSource(dword _bufdata, _in_bufsize)
{
dword i, j;
bool activate_script_mode = false;
dword source_buf_start;
opened_font_counter=0;
source_buf_end = malloc(_in_bufsize*5);
source_buf_start = source_buf_end;
header[strrchr(#header, '-')-2]=0;
SourceBufAdd(TEXT, "<html><head><title>Source: ");
SourceBufAdd(TEXT, #header);
SourceBufAdd(TEXT, "</title><body><pre>");
for (i=_bufdata; i<_bufdata+_in_bufsize; i++) switch (ESBYTE[i])
{
case '<':
if (!strncmp(i+1,"!--", 3)) SourceBufAdd(COMMENT, "<font color=#bbb>&lt;");
else if (SCRIPT == mode) {
if (!strncmp(i+1,"/script>", 8)) {
CloseAllOpenedFonts(NULL);
SourceBufAdd(TAG, "<font color=#00f>&lt;");
}
else SourceBufAdd(NULL, "&lt;");
}
else if (COMMENT == mode) {
SourceBufAdd(NULL, "&lt;");
}
else if (TEXT == mode) {
if (!strncmp(i+1,"script", 6)) activate_script_mode = true;
SourceBufAdd(TAG, "<font color=#00f>&lt;");
}
break;
case '>':
if (TAG == mode) && (activate_script_mode) {
activate_script_mode = false;
SourceBufAdd(SCRIPT, "&gt;</font><font color=#994500>");
}
else if (VALUE == mode) CloseAllOpenedFonts(TEXT);
else if (COMMENT == mode) && (!strncmp(i-2,"--", 2)) {
SourceBufAdd(TEXT, "&gt;");
CloseAllOpenedFonts(TEXT);
}
else if (COMMENT == mode) || (SCRIPT == mode) SourceBufAdd(NULL, "&gt;");
else if (TAG == mode) SourceBufAdd(TEXT, "&gt;</font>");
break;
case '&':
SourceBufAdd(NULL, "&amp;");
break;
case '\"':
case '\'':
if (TAG == mode) SourceBufAdd(VALUE, "<font color=#F301F2>&#39;");
else if (VALUE == mode) SourceBufAdd(TAG, "&#39;</font>");
else SourceBufAdd(NULL, "&#39;");
break;
default:
ESBYTE[source_buf_end] = ESBYTE[i];
source_buf_end++;
}
ESBYTE[source_buf_end] = 0;
LoadInternalPage(source_buf_start, _in_bufsize);
free(source_buf_start);
}