// File: /workspace/github_c_makefile_star2_O3/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 0xad14
movq %rax, %r15
movq %rax, 0x10(%rsp)
leaq 0x70de(%rip), %rsi      # 0x1be8d
movq %rax, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xb0b7
movl %r12d, 0x4(%rsp)
testl %r12d, %r12d
je 0x14de8
leaq 0x70d2(%rip), %rsi      # 0x1be9f
movq %r15, %rdi
callq 0xaf83
testq %r13, %r13
je 0x14e0f
leaq 0x70d6(%rip), %rcx      # 0x1beb7
movq 0x8(%rsp), %r12
jmp 0x14df9
testq %r13, %r13
movq 0x8(%rsp), %r12
je 0x14e23
leaq 0x4ed9(%rip), %rcx      # 0x19cd2
leaq 0x70a9(%rip), %rsi      # 0x1bea9
movq %r15, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xb0b7
jmp 0x14e23
leaq 0x70ab(%rip), %rsi      # 0x1bec1
movq %r15, %rdi
callq 0xaf83
movq 0x8(%rsp), %r12
movq 0x50(%rsp), %rdx
testq %rdx, %rdx
je 0x14e3e
leaq 0x5027(%rip), %rsi      # 0x19e5b
movq %r15, %rdi
xorl %eax, %eax
callq 0xb0b7
leaq 0x6f79(%rip), %rsi      # 0x1bdbe
movq %r15, %rdi
callq 0xaf83
testq %r12, %r12
je 0x14efd
movq %r12, %rdi
movl $0x2c, %esi
callq 0x3260
testq %rax, %rax
je 0x14e8b
movq %r12, %rdi
callq 0x6402
movq %rax, %r12
movq %rax, %rdi
movl $0x2c, %esi
callq 0x3260
movq %rax, %r13
movb $0x0, (%rax)
incq %r13
jmp 0x14e8e
movq %r12, %r13
testq %rbx, %rbx
je 0x14eaf
cmpl $0x0, 0x4(%rsp)
je 0x14eb8
movq %r12, %rdi
movl $0x2c, %esi
movq %rbx, %rdx
callq 0x8110
testq %rax, %rax
je 0x14ec7
leaq 0x6e97(%rip), %rbp      # 0x1bd4d
jmp 0x14ece
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3440
testl %eax, %eax
je 0x14eaf
leaq 0x4e04(%rip), %rbp      # 0x19cd2
movq %r13, %rdi
callq 0x13718
leaq 0x6ff6(%rip), %rsi      # 0x1bed3
movq %r15, %rdi
movq %rbp, %rdx
movq %r12, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xb0b7
cmpq %r12, %r13
je 0x14efd
movq %r12, %rdi
callq 0xeebc
testq %r14, %r14
je 0x14fad
leaq 0x6fc6(%rip), %r12      # 0x1bed3
movq 0x8(%r14), %r13
testq %rbx, %rbx
je 0x14f4a
cmpl $0x0, 0x4(%rsp)
je 0x14f5e
movq %r13, %rdi
movl $0x2c, %esi
movq %rbx, %rdx
callq 0x8110
movq 0x8(%r14), %r13
movq 0x10(%r14), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
leaq 0x4d8f(%rip), %rbp      # 0x19cd2
testq %rax, %rax
jne 0x14f7f
jmp 0x14f86
movq 0x10(%r14), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
leaq 0x4d76(%rip), %rbp      # 0x19cd2
jmp 0x14f86
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3440
movq 0x10(%r14), %rdi
testq %rdi, %rdi
cmoveq %r13, %rdi
leaq 0x4d57(%rip), %rbp      # 0x19cd2
testl %eax, %eax
jne 0x14f86
leaq 0x6dc7(%rip), %rbp      # 0x1bd4d
callq 0x13718
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xb0b7
movq (%r14), %r14
testq %r14, %r14
jne 0x14f0d
leaq 0x6dba(%rip), %rsi      # 0x1bd6e
movq %r15, %rdi
xorl %eax, %eax
callq 0xb0b7
leaq 0x10(%rsp), %rdi
callq 0xad70
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq