// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x10(%rbp), %rax
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x400, %edi            # imm = 0x400
callq 0xf030
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x8824(%rip), %rsi      # 0x26efe
movb $0x0, %al
callq 0xf550
cmpl $0x0, -0x4(%rbp)
je 0x1e6f7
movq -0x38(%rbp), %rdi
leaq 0x881e(%rip), %rsi      # 0x26f10
callq 0xf3c0
cmpq $0x0, -0x30(%rbp)
je 0x1e72e
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rdx
movl -0x4(%rbp), %esi
leaq 0x65ea(%rip), %rcx      # 0x24cfa
leaq 0x8811(%rip), %rax      # 0x26f28
cmpl $0x0, %esi
cmovneq %rax, %rcx
leaq 0x87f5(%rip), %rsi      # 0x26f1a
movb $0x0, %al
callq 0xf550
jmp 0x1e746
cmpl $0x0, -0x4(%rbp)
je 0x1e744
movq -0x38(%rbp), %rdi
leaq 0x87f3(%rip), %rsi      # 0x26f32
callq 0xf3c0
jmp 0x1e746
cmpq $0x0, 0x10(%rbp)
je 0x1e763
movq -0x38(%rbp), %rdi
movq 0x10(%rbp), %rdx
leaq 0x6727(%rip), %rsi      # 0x24e83
movb $0x0, %al
callq 0xf550
movq -0x38(%rbp), %rdi
leaq 0x86c1(%rip), %rsi      # 0x26e2f
callq 0xf3c0
cmpq $0x0, -0x28(%rbp)
je 0x1e896
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movl $0x2c, %esi
callq 0x3250
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x1e7d3
movq -0x28(%rbp), %rdi
callq 0x7530
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movl $0x2c, %esi
callq 0x3250
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movb $0x0, (%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1e7db
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x1, -0x3c(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1e82f
cmpl $0x0, -0x4(%rbp)
je 0x1e812
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x2c, %esi
callq 0xa670
cmpq $0x0, %rax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1e82d
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3410
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1e82f
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x3c(%rbp), %edx
leaq 0x64b9(%rip), %rax      # 0x24cfa
leaq 0x8576(%rip), %rcx      # 0x26dbe
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rdi
callq 0x1c2e0
movq -0x78(%rbp), %rdi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq %rax, %r8
leaq 0x86ca(%rip), %rsi      # 0x26f44
movb $0x0, %al
callq 0xf550
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x1e894
movq -0x48(%rbp), %rdi
callq 0x153e0
jmp 0x1e896
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x1e99a
movl $0x0, -0x3c(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1e905
cmpl $0x0, -0x4(%rbp)
je 0x1e8e4
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rdx
movl $0x2c, %esi
callq 0xa670
cmpq $0x0, %rax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1e903
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x3410
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1e905
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x1e928
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x3c(%rbp), %edx
leaq 0x63bd(%rip), %rax      # 0x24cfa
leaq 0x847a(%rip), %rcx      # 0x26dbe
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x60(%rbp), %rdi
callq 0x1c2e0
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq %rax, %r8
leaq 0x85c1(%rip), %rsi      # 0x26f44
movb $0x0, %al
callq 0xf550
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x1e89e
movq -0x38(%rbp), %rdi
leaq 0x843a(%rip), %rsi      # 0x26ddf
movb $0x0, %al
callq 0xf550
leaq -0x38(%rbp), %rdi
callq 0xf0d0
addq $0x90, %rsp
popq %rbp
retq
nop