// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/lib/cheapcgi.c
// Function: cgiMakeSelectDropList
char *cgiMakeSelectDropList(boolean multiple, char *name, struct slPair *valsAndLabels,
                            char *selected, char *anyAll,char *extraClasses, char *event, char *javascript, char *style, char *id)
// Returns allocated string of HTML defining a drop-down select
// (if multiple, REQUIRES ui-dropdownchecklist.js)
// valsAndLabels: val (pair->name) must be filled in but label (pair->val) may be NULL.
// selected: if not NULL is a val found in the valsAndLabels (multiple then comma delimited list).
//           If null and anyAll not NULL, that will be selected
// anyAll: if not NULL is the string for an initial option. It can contain val and label,
//         delimited by a comma
// event: click, etc.
// javacript: what to execute when the event happens.
// style: inline style
// id is optional
{
struct dyString *output = dyStringNew(1024);
boolean checked = FALSE;

dyStringPrintf(output,"<SELECT name='%s'",name);
if (multiple)
    dyStringAppend(output," MULTIPLE");
if (extraClasses != NULL)
    dyStringPrintf(output," class='%s%s'",extraClasses,(multiple ? " filterBy" : ""));
else if (multiple)
    dyStringAppend(output," class='filterBy'");

char *autoId = NULL;
if (javascript)
    {
    if (!id)
	{
    	id = name;
	}
    }
if (id)
    dyStringPrintf(output, " id='%s'", id);
if (javascript)
    {
    jsOnEventById(event, id, javascript);
    freeMem(autoId);
    }

if (style)
    {
    dyStringPrintf(output, " style='%s'", style);
    }

dyStringAppend(output,">\n");

// Handle initial option "Any" or "All"
if (anyAll != NULL)
    {
    char *val = anyAll;  // Could contain a label after the value
    char *label = strchr(val,',');  // Could contain a label after the value
    if (label != NULL)
        {
        val = cloneString(anyAll);
        label = strchr(val,',');  // again because this is new mem
        *label = '\0';
        label = label+1;
        }
    else
        label = val;
    checked = TRUE; // The default case
    if (selected != NULL)
        {
        if (multiple)
            checked = (findWordByDelimiter(val,',', selected) != NULL);
        else
            checked = sameString(val,selected);
        }
    dyStringPrintf(output, "<OPTION%s VALUE='%s'>%s</OPTION>\n",(checked ? " SELECTED" : ""),
                   val, javaScriptLiteralEncode(label));
    if (label != val)
        freeMem(val);
    }

// All other options
struct slPair *valPair = valsAndLabels;
for (; valPair != NULL; valPair = valPair->next)
    {
    checked = FALSE;
    if (selected != NULL)
        {
        if (multiple)
            checked = (findWordByDelimiter(valPair->name,',', selected) != NULL);
        else
            checked = sameString(valPair->name,selected);
        }
    char *label = valPair->name;
    if (valPair->val != NULL)
        label = valPair->val;
    dyStringPrintf(output, "<OPTION%s VALUE='%s'>%s</OPTION>\n",(checked ? " SELECTED" : ""),
                   (char *)valPair->name, javaScriptLiteralEncode(label));
    }

dyStringPrintf(output,"</SELECT>\n");

return dyStringCannibalize(&output);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r12
movq %r8, 0x8(%rsp)
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r13
movl %edi, %r15d
movl $0x400, %edi            # imm = 0x400
callq 0x21bcc
movq %rax, %rbp
movq %rax, 0x10(%rsp)
leaq 0x45048(%rip), %rsi     # 0x85385
movq %rax, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x21ec7
movl %r15d, 0x4(%rsp)
testl %r15d, %r15d
je 0x40376
leaq 0x4503c(%rip), %rsi     # 0x85397
movq %rbp, %rdi
callq 0x21dda
testq %r12, %r12
je 0x4039d
leaq 0x45040(%rip), %rcx     # 0x853af
movq 0x8(%rsp), %r15
jmp 0x40387
testq %r12, %r12
movq 0x8(%rsp), %r15
je 0x403b1
leaq 0x46ff6(%rip), %rcx     # 0x8737d
leaq 0x45013(%rip), %rsi     # 0x853a1
movq %rbp, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x21ec7
jmp 0x403b1
leaq 0x45015(%rip), %rsi     # 0x853b9
movq %rbp, %rdi
callq 0x21dda
movq 0x8(%rsp), %r15
movq 0x68(%rsp), %rax
testq %rax, %rax
cmovneq %rax, %r13
movq 0x58(%rsp), %rdx
testq %rdx, %rdx
cmoveq %rax, %r13
testq %r13, %r13
je 0x403e7
leaq 0x44c0b(%rip), %rsi     # 0x84fe0
movq %rbp, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x21ec7
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %r12
testq %rdx, %rdx
je 0x40405
movq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x3dd39
xorl %edi, %edi
callq 0x28c2d
testq %r12, %r12
je 0x4041e
leaq 0x44e41(%rip), %rsi     # 0x85252
movq %rbp, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x21ec7
leaq 0x45f6d(%rip), %rsi     # 0x86392
movq %rbp, %rdi
callq 0x21dda
testq %r15, %r15
je 0x404ca
pushq $0x2c
popq %rsi
movq %r15, %rdi
callq 0x6270
testq %rax, %rax
je 0x40467
movq %r15, %rdi
callq 0x1c306
movq %rax, %r15
pushq $0x2c
popq %rsi
movq %rax, %rdi
callq 0x6270
movq %rax, %r13
movb $0x0, (%rax)
incq %r13
jmp 0x4046a
movq %r15, %r13
testq %rbx, %rbx
je 0x40494
leaq 0x46f07(%rip), %r12     # 0x8737d
cmpl $0x0, 0x4(%rsp)
je 0x40578
pushq $0x2c
popq %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x1dc4b
testq %rax, %rax
je 0x4049b
leaq 0x44dc3(%rip), %r12     # 0x8525e
movq %r13, %rdi
callq 0x3ea8f
leaq 0x44f21(%rip), %rsi     # 0x853cb
movq %rbp, %rdi
movq %r12, %rdx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x21ec7
cmpq %r15, %r13
je 0x404ca
movq %r15, %rdi
callq 0x28c2d
movq %rbp, %r15
leaq 0x44ef7(%rip), %r12     # 0x853cb
testq %r14, %r14
je 0x4054e
testq %rbx, %rbx
je 0x404fc
movq 0x8(%r14), %rdi
cmpl $0x0, 0x4(%rsp)
je 0x40500
pushq $0x2c
popq %rsi
movq %rbx, %rdx
callq 0x1dc4b
testq %rax, %rax
setne %al
jmp 0x4050d
xorl %eax, %eax
jmp 0x4050d
movq %rbx, %rsi
callq 0x6a50
testl %eax, %eax
sete %al
movq 0x8(%r14), %r13
movq 0x10(%r14), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
leaq 0x44d3b(%rip), %rbp     # 0x8525e
testb $0x1, %al
jne 0x4052e
leaq 0x46e4f(%rip), %rbp     # 0x8737d
callq 0x3ea8f
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x21ec7
movq (%r14), %r14
jmp 0x404d4
leaq 0x44d2a(%rip), %rsi     # 0x8527f
movq %r15, %rdi
xorl %eax, %eax
callq 0x21ec7
leaq 0x10(%rsp), %rdi
callq 0x21c26
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6a50
testl %eax, %eax
jne 0x4049b
jmp 0x40494