// File: /workspace/github_c_makefile_star2_O2/JimKent[P]linearSat/lib/cheapcgi.c
// Function: cgiMakeSelectDropList
char *cgiMakeSelectDropList(boolean multiple, char *name, struct slPair *valsAndLabels,
                            char *selected, char *anyAll,char *extraClasses, char *extraHtml)
// 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
// extraHtml: if not NULL contains id, javascript calls and style.
//            It does NOT contain class definitions
{
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'");

if (extraHtml != NULL)
    dyStringPrintf(output," %s",extraHtml);
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, %r13
movq %r8, 0x8(%rsp)
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %rbp
movl %edi, %r12d
movl $0x400, %edi            # imm = 0x400
callq 0x9df0
movq %rax, %r15
movq %rax, 0x10(%rsp)
leaq 0x6c32(%rip), %rsi      # 0x19e8d
movq %rax, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xa0eb
movl %r12d, 0x4(%rsp)
testl %r12d, %r12d
je 0x13294
leaq 0x6c26(%rip), %rsi      # 0x19e9f
movq %r15, %rdi
callq 0x9ffe
testq %r13, %r13
je 0x132bb
leaq 0x6c2a(%rip), %rcx      # 0x19eb7
movq 0x8(%rsp), %r12
jmp 0x132a5
testq %r13, %r13
movq 0x8(%rsp), %r12
je 0x132cf
leaq 0x4a2d(%rip), %rcx      # 0x17cd2
leaq 0x6bfd(%rip), %rsi      # 0x19ea9
movq %r15, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xa0eb
jmp 0x132cf
leaq 0x6bff(%rip), %rsi      # 0x19ec1
movq %r15, %rdi
callq 0x9ffe
movq 0x8(%rsp), %r12
movq 0x50(%rsp), %rdx
testq %rdx, %rdx
je 0x132ea
leaq 0x4b7b(%rip), %rsi      # 0x17e5b
movq %r15, %rdi
xorl %eax, %eax
callq 0xa0eb
leaq 0x6acd(%rip), %rsi      # 0x19dbe
movq %r15, %rdi
callq 0x9ffe
testq %r12, %r12
je 0x13396
pushq $0x2c
popq %rsi
movq %r12, %rdi
callq 0x3260
testq %rax, %rax
je 0x13333
movq %r12, %rdi
callq 0x5ede
movq %rax, %r12
pushq $0x2c
popq %rsi
movq %rax, %rdi
callq 0x3260
movq %rax, %r13
movb $0x0, (%rax)
incq %r13
jmp 0x13336
movq %r12, %r13
testq %rbx, %rbx
je 0x13360
leaq 0x4990(%rip), %rbp      # 0x17cd2
cmpl $0x0, 0x4(%rsp)
je 0x13441
pushq $0x2c
popq %rsi
movq %r12, %rdi
movq %rbx, %rdx
callq 0x7771
testq %rax, %rax
je 0x13367
leaq 0x69e6(%rip), %rbp      # 0x19d4d
movq %r13, %rdi
callq 0x11d87
leaq 0x6b5d(%rip), %rsi      # 0x19ed3
movq %r15, %rdi
movq %rbp, %rdx
movq %r12, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xa0eb
cmpq %r12, %r13
je 0x13396
movq %r12, %rdi
callq 0xd8f9
leaq 0x6b36(%rip), %r12      # 0x19ed3
testq %r14, %r14
je 0x13417
testq %rbx, %rbx
je 0x133c5
movq 0x8(%r14), %rdi
cmpl $0x0, 0x4(%rsp)
je 0x133c9
pushq $0x2c
popq %rsi
movq %rbx, %rdx
callq 0x7771
testq %rax, %rax
setne %al
jmp 0x133d6
xorl %eax, %eax
jmp 0x133d6
movq %rbx, %rsi
callq 0x3440
testl %eax, %eax
sete %al
movq 0x8(%r14), %r13
movq 0x10(%r14), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
leaq 0x6961(%rip), %rbp      # 0x19d4d
testb $0x1, %al
jne 0x133f7
leaq 0x48db(%rip), %rbp      # 0x17cd2
callq 0x11d87
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xa0eb
movq (%r14), %r14
jmp 0x1339d
leaq 0x6950(%rip), %rsi      # 0x19d6e
movq %r15, %rdi
xorl %eax, %eax
callq 0xa0eb
leaq 0x10(%rsp), %rdi
callq 0x9e4a
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3440
testl %eax, %eax
jne 0x13367
jmp 0x13360