// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/lib/htmshell.c
// Function: htmlVaWarn
void htmlVaWarn(char *format, va_list args)
/* Write an error message. */
{
va_list argscp;
va_copy(argscp, args);
htmlWarnBoxSetup(stdout); // sets up the warnBox if it hasn't already been done.
char warning[1024];

// html-encode arguments to fight XSS
struct dyString *ds = newDyString(1024);
vaHtmlDyStringPrintf(ds, format, args);
int n = ds->stringSize;
int nLimit = sizeof(warning) - 1;
if (ds->stringSize > nLimit)
    n = nLimit;
safencpy(warning, sizeof warning, ds->string, n);
if (ds->stringSize > nLimit)
    strcpy(warning+n-5,"[...]"); // show truncation
freeDyString(&ds);

// Replace newlines with BR tag
char *warningBR = htmlWarnEncode(warning); 

// Javascript-encode the entire message because it is
// going to appear as a javascript string literal
// as it gets appended to the warnList html.
// JS-encoding here both allows us to use any character in the message
// and keeps js-encodings in events like onmouseover="stuff %s|js| stuff" secure.
char *jsEncodedMessage = javascriptEncode (warningBR); 
freeMem(warningBR);
struct dyString *dy = dyStringNew(2048);
dyStringPrintf(dy,
    "showWarnBox();"
    "var warnList=document.getElementById('warnList');"
    "warnList.innerHTML += '<li>%s</li>';\n", jsEncodedMessage);
jsInline(dy->string);  
// TODO GALT does --ERROR -- tag still work?
printf("<!-- ERROR -->\n");
// NOTE that "--ERROR --" is needed at the end of this print!!
dyStringFree(&dy);
freeMem(jsEncodedMessage);

/* Log useful CGI info to stderr */
logCgiToStderr();

/* write warning/error message to stderr so they get logged. */
vfprintf(stderr, format, argscp);
fprintf(stderr, "\n");
fflush(stderr);
va_end(argscp);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movq %rsi, %r14
movq %rdi, %rbx
movq 0x10(%rsi), %rax
movq %rax, 0x20(%rsp)
movups (%rsi), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x70d5c(%rip), %rax     # 0xb2fb0
movq (%rax), %rdi
callq 0x4217d
movl $0x400, %edi            # imm = 0x400
callq 0x21bcc
movq %rax, %r15
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x41743
movl 0x14(%r15), %eax
movl $0x3ff, %ecx            # imm = 0x3FF
cmpl %ecx, %eax
cmovll %eax, %ecx
movq 0x8(%r15), %rdx
movslq %ecx, %r14
leaq 0x30(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rcx
callq 0x1fb32
cmpl $0x400, 0x14(%r15)      # imm = 0x400
jl 0x422be
movw $0x5d, 0x2f(%rsp,%r14)
movl $0x2e2e2e5b, 0x2b(%rsp,%r14) # imm = 0x2E2E2E5B
leaq 0x8(%rsp), %rdi
callq 0x21c07
leaq 0x30(%rsp), %rdi
callq 0x41c14
movq %rax, %r15
movq %rax, %rdi
callq 0x420c3
movq %rax, %r14
movq %r15, %rdi
callq 0x28c2d
movl $0x800, %edi            # imm = 0x800
callq 0x21bcc
movq %rax, %r15
leaq 0x28(%rsp), %r12
movq %rax, (%r12)
leaq 0x43ae8(%rip), %rsi     # 0x85ded
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x21ec7
movq 0x8(%r15), %rdi
callq 0x3db72
leaq 0x44488(%rip), %rdi     # 0x867aa
callq 0x6bb0
movq %r12, %rdi
callq 0x21c07
movq %r14, %rdi
callq 0x28c2d
xorl %eax, %eax
callq 0x40c23
movq 0x70c93(%rip), %r14     # 0xb2fd8
movq (%r14), %rdi
leaq 0x10(%rsp), %rdx
movq %rbx, %rsi
callq 0x69e0
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x6930
movq (%r14), %rdi
callq 0x6870
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r14
popq %r15
retq