// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
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 0x35020
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x79edc(%rip), %rsi     # 0xe0332
movb $0x0, %al
callq 0x35540
cmpl $0x0, -0x4(%rbp)
je 0x66473
movq -0x38(%rbp), %rdi
leaq 0x79ed6(%rip), %rsi     # 0xe0344
callq 0x353b0
cmpq $0x0, -0x30(%rbp)
je 0x664aa
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rdx
movl -0x4(%rbp), %esi
leaq 0x7ef7a(%rip), %rcx     # 0xe5406
leaq 0x79ec9(%rip), %rax     # 0xe035c
cmpl $0x0, %esi
cmovneq %rax, %rcx
leaq 0x79ead(%rip), %rsi     # 0xe034e
movb $0x0, %al
callq 0x35540
jmp 0x664c2
cmpl $0x0, -0x4(%rbp)
je 0x664c0
movq -0x38(%rbp), %rdi
leaq 0x79eab(%rip), %rsi     # 0xe0366
callq 0x353b0
jmp 0x664c2
movq $0x0, -0x48(%rbp)
cmpq $0x0, 0x18(%rbp)
je 0x664e2
cmpq $0x0, 0x28(%rbp)
jne 0x664e0
movq -0x10(%rbp), %rax
movq %rax, 0x28(%rbp)
jmp 0x664e2
cmpq $0x0, 0x28(%rbp)
je 0x664ff
movq -0x38(%rbp), %rdi
movq 0x28(%rbp), %rdx
leaq 0x79a95(%rip), %rsi     # 0xdff8d
movb $0x0, %al
callq 0x35540
cmpq $0x0, 0x18(%rbp)
je 0x66520
movq 0x10(%rbp), %rdi
movq 0x28(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x627b0
movq -0x48(%rbp), %rdi
callq 0x40d40
cmpq $0x0, 0x20(%rbp)
je 0x6653d
movq -0x38(%rbp), %rdi
movq 0x20(%rbp), %rdx
leaq 0x79cc9(%rip), %rsi     # 0xe01ff
movb $0x0, %al
callq 0x35540
movq -0x38(%rbp), %rdi
leaq 0x7ae53(%rip), %rsi     # 0xe139b
callq 0x353b0
cmpq $0x0, -0x28(%rbp)
je 0x66670
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movl $0x2c, %esi
callq 0x6260
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x665ad
movq -0x28(%rbp), %rdi
callq 0x2a450
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movl $0x2c, %esi
callq 0x6260
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movb $0x0, (%rax)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x665b5
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x1, -0x3c(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x66609
cmpl $0x0, -0x4(%rbp)
je 0x665ec
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x2c, %esi
callq 0x2d610
cmpq $0x0, %rax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
jmp 0x66607
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x6a40
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
jmp 0x66609
movq -0x38(%rbp), %rax
movq %rax, -0x80(%rbp)
movl -0x3c(%rbp), %edx
leaq 0x7edeb(%rip), %rax     # 0xe5406
leaq 0x79be9(%rip), %rcx     # 0xe020b
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rdi
callq 0x63c20
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rdx
movq -0x70(%rbp), %rcx
movq %rax, %r8
leaq 0x79d24(%rip), %rsi     # 0xe0378
movb $0x0, %al
callq 0x35540
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
je 0x6666e
movq -0x50(%rbp), %rdi
callq 0x40d40
jmp 0x66670
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x6677a
movl $0x0, -0x3c(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x666df
cmpl $0x0, -0x4(%rbp)
je 0x666be
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rdx
movl $0x2c, %esi
callq 0x2d610
cmpq $0x0, %rax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
jmp 0x666dd
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x6a40
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
jmp 0x666df
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x66702
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x3c(%rbp), %edx
leaq 0x7ecef(%rip), %rax     # 0xe5406
leaq 0x79aed(%rip), %rcx     # 0xe020b
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rdi
callq 0x63c20
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rdx
movq -0x88(%rbp), %rcx
movq %rax, %r8
leaq 0x79c15(%rip), %rsi     # 0xe0378
movb $0x0, %al
callq 0x35540
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x66678
movq -0x38(%rbp), %rdi
leaq 0x79aa7(%rip), %rsi     # 0xe022c
movb $0x0, %al
callq 0x35540
leaq -0x38(%rbp), %rdi
callq 0x350c0
addq $0xa0, %rsp
popq %rbp
retq
nop