kolibrios/programs/cmm/browser/show_src.h
Kirill Lipatov (Leency) e7484ebe37 WebView 1.94: code refactoring and bugfixing; also
- rework source code view, open it in a new tab
- fix tagparm parsing for case: src=./images/KolibriOS_logo2.jpg?sid=e8ece8b38b
- fix: show image text in multiple lines if need

git-svn-id: svn://kolibrios.org@7750 a494cfbc-eb01-0410-851d-a64ba20cac60
2020-03-25 00:18:19 +00:00

96 lines
2.5 KiB
C

dword source_buf_start, source_buf_end;
int opened_font=0;
int mode;
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--;
src = font_found_pointer+2;
}
src = src_orig;
if (font_found_pointer = strstr(src, "<font ")) {
opened_font++;
src = font_found_pointer+2;
}
}
void CloseAllOpenedFonts(dword _mode)
{
while (opened_font) SourceBufAdd(_mode, "</font>");
}
enum { TAG=1, VALUE, TEXT, COMMENT, SCRIPT};
dword ShowSource()
{
dword i, j;
bool activate_script_mode = false;
opened_font=0;
source_buf_start = source_buf_end = malloc(bufsize*5);
header[strrchr(#header, '-')-2]=0;
SourceBufAdd(TEXT, "<html><head><title>Source: ");
SourceBufAdd(TEXT, #header);
SourceBufAdd(TEXT, "</title><body><pre>");
for (i=bufpointer; i<bufpointer+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;
bufsize = source_buf_end - source_buf_start;
free(bufpointer);
bufpointer = source_buf_start;
}