2020-03-27 11:38:54 +01:00
|
|
|
enum { TAG=1, VALUE, TEXT, COMMENT, SCRIPT};
|
2014-03-30 15:51:53 +02:00
|
|
|
|
2020-03-27 11:38:54 +01:00
|
|
|
int opened_font_counter=0;
|
2020-03-25 01:18:19 +01:00
|
|
|
int mode;
|
|
|
|
|
2020-03-27 11:38:54 +01:00
|
|
|
dword source_buf_end;
|
|
|
|
|
2020-03-25 01:18:19 +01:00
|
|
|
void SourceBufAdd(dword _mode, src)
|
2014-03-30 13:57:13 +02:00
|
|
|
{
|
2020-03-25 01:18:19 +01:00
|
|
|
dword font_found_pointer, src_orig = src;
|
2014-03-30 13:57:13 +02:00
|
|
|
|
2020-03-25 01:18:19 +01:00
|
|
|
if (_mode) mode = _mode;
|
2018-10-06 00:10:27 +02:00
|
|
|
|
2020-03-25 01:18:19 +01:00
|
|
|
strcpy(source_buf_end, src);
|
|
|
|
source_buf_end += strlen(source_buf_end);
|
2020-03-22 20:50:16 +01:00
|
|
|
|
2020-03-25 01:18:19 +01:00
|
|
|
if (font_found_pointer = strstr(src, "</font>")) {
|
2020-03-27 11:38:54 +01:00
|
|
|
opened_font_counter--;
|
2020-03-25 01:18:19 +01:00
|
|
|
src = font_found_pointer+2;
|
|
|
|
}
|
2020-03-22 20:50:16 +01:00
|
|
|
|
2020-03-25 01:18:19 +01:00
|
|
|
src = src_orig;
|
|
|
|
if (font_found_pointer = strstr(src, "<font ")) {
|
2020-03-27 11:38:54 +01:00
|
|
|
opened_font_counter++;
|
2020-03-25 01:18:19 +01:00
|
|
|
src = font_found_pointer+2;
|
|
|
|
}
|
|
|
|
}
|
2018-10-06 00:10:27 +02:00
|
|
|
|
2020-03-25 01:18:19 +01:00
|
|
|
void CloseAllOpenedFonts(dword _mode)
|
|
|
|
{
|
2020-03-27 11:38:54 +01:00
|
|
|
while (opened_font_counter) SourceBufAdd(_mode, "</font>");
|
2020-03-25 01:18:19 +01:00
|
|
|
}
|
2018-10-06 00:10:27 +02:00
|
|
|
|
2020-03-27 11:38:54 +01:00
|
|
|
dword ShowSource(dword _bufdata, _in_bufsize)
|
2018-10-06 00:10:27 +02:00
|
|
|
{
|
2020-03-25 01:18:19 +01:00
|
|
|
dword i, j;
|
|
|
|
bool activate_script_mode = false;
|
2020-03-27 11:38:54 +01:00
|
|
|
dword source_buf_start;
|
2020-03-25 01:18:19 +01:00
|
|
|
|
2020-03-27 11:38:54 +01:00
|
|
|
opened_font_counter=0;
|
|
|
|
source_buf_end = malloc(_in_bufsize*5);
|
|
|
|
source_buf_start = source_buf_end;
|
2020-03-25 01:18:19 +01:00
|
|
|
header[strrchr(#header, '-')-2]=0;
|
2018-10-06 00:10:27 +02:00
|
|
|
|
2020-03-25 01:18:19 +01:00
|
|
|
SourceBufAdd(TEXT, "<html><head><title>Source: ");
|
|
|
|
SourceBufAdd(TEXT, #header);
|
|
|
|
SourceBufAdd(TEXT, "</title><body><pre>");
|
2018-10-06 00:10:27 +02:00
|
|
|
|
2020-03-27 11:38:54 +01:00
|
|
|
for (i=_bufdata; i<_bufdata+_in_bufsize; i++) switch (ESBYTE[i])
|
2018-10-06 00:10:27 +02:00
|
|
|
{
|
2020-03-25 01:18:19 +01:00
|
|
|
case '<':
|
|
|
|
if (!strncmp(i+1,"!--", 3)) SourceBufAdd(COMMENT, "<font color=#bbb><");
|
|
|
|
else if (SCRIPT == mode) {
|
|
|
|
if (!strncmp(i+1,"/script>", 8)) {
|
|
|
|
CloseAllOpenedFonts(NULL);
|
|
|
|
SourceBufAdd(TAG, "<font color=#00f><");
|
|
|
|
}
|
|
|
|
else SourceBufAdd(NULL, "<");
|
2018-10-06 00:10:27 +02:00
|
|
|
}
|
2020-03-25 01:18:19 +01:00
|
|
|
else if (COMMENT == mode) {
|
|
|
|
SourceBufAdd(NULL, "<");
|
2018-10-06 00:10:27 +02:00
|
|
|
}
|
2020-03-25 01:18:19 +01:00
|
|
|
else if (TEXT == mode) {
|
|
|
|
if (!strncmp(i+1,"script", 6)) activate_script_mode = true;
|
|
|
|
SourceBufAdd(TAG, "<font color=#00f><");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
if (TAG == mode) && (activate_script_mode) {
|
|
|
|
activate_script_mode = false;
|
|
|
|
SourceBufAdd(SCRIPT, "></font><font color=#994500>");
|
|
|
|
}
|
|
|
|
else if (VALUE == mode) CloseAllOpenedFonts(TEXT);
|
|
|
|
else if (COMMENT == mode) && (!strncmp(i-2,"--", 2)) {
|
|
|
|
SourceBufAdd(TEXT, ">");
|
|
|
|
CloseAllOpenedFonts(TEXT);
|
2018-10-06 00:10:27 +02:00
|
|
|
}
|
2020-03-25 01:18:19 +01:00
|
|
|
else if (COMMENT == mode) || (SCRIPT == mode) SourceBufAdd(NULL, ">");
|
|
|
|
else if (TAG == mode) SourceBufAdd(TEXT, "></font>");
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
SourceBufAdd(NULL, "&");
|
|
|
|
break;
|
|
|
|
case '\"':
|
|
|
|
case '\'':
|
|
|
|
if (TAG == mode) SourceBufAdd(VALUE, "<font color=#F301F2>'");
|
|
|
|
else if (VALUE == mode) SourceBufAdd(TAG, "'</font>");
|
|
|
|
else SourceBufAdd(NULL, "'");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ESBYTE[source_buf_end] = ESBYTE[i];
|
|
|
|
source_buf_end++;
|
2018-10-06 00:10:27 +02:00
|
|
|
}
|
2020-03-25 01:18:19 +01:00
|
|
|
ESBYTE[source_buf_end] = 0;
|
2020-03-27 11:38:54 +01:00
|
|
|
LoadInternalPage(source_buf_start, _in_bufsize);
|
|
|
|
free(source_buf_start);
|
2018-10-06 00:10:27 +02:00
|
|
|
}
|