2014-03-30 15:51:53 +02:00
|
|
|
|
2020-03-25 01:18:19 +01:00
|
|
|
dword source_buf_start, source_buf_end;
|
|
|
|
int opened_font=0;
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
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>")) {
|
|
|
|
opened_font--;
|
|
|
|
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 ")) {
|
|
|
|
opened_font++;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
while (opened_font) SourceBufAdd(_mode, "</font>");
|
|
|
|
}
|
2018-10-06 00:10:27 +02:00
|
|
|
|
2020-03-25 01:18:19 +01:00
|
|
|
enum { TAG=1, VALUE, TEXT, COMMENT, SCRIPT};
|
|
|
|
dword ShowSource()
|
2018-10-06 00:10:27 +02:00
|
|
|
{
|
2020-03-25 01:18:19 +01:00
|
|
|
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;
|
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-25 01:18:19 +01:00
|
|
|
for (i=bufpointer; i<bufpointer+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;
|
|
|
|
bufsize = source_buf_end - source_buf_start;
|
2018-10-06 00:10:27 +02:00
|
|
|
free(bufpointer);
|
2020-03-25 01:18:19 +01:00
|
|
|
bufpointer = source_buf_start;
|
2018-10-06 00:10:27 +02:00
|
|
|
}
|