// File: /workspace/github_c_makefile_star2_O0/schroeder-lvb[P]sissm/src/api.c
// Function: apiMapcycleRead
int apiMapcycleRead( char *mapcycleFile )
{
    FILE *fpr;
    int   i, j;
    char  tmpLine[256], lastMapName[256], lastReqName[256];
    char  *w, *w2, *v, *u, scenarioName[256];

    strclr( lastMapName );
    for (i = 0; i<API_MAXMAPS; i++) {
        strclr( mapCycleList[i].mapName );
        strclr( mapCycleList[i].reqName );
        strclr( mapCycleList[i].scenario );
        strclr( mapCycleList[i].traveler );
        strclr( mapCycleList[i].gameMode );
        mapCycleList[i].dayNight =  0;
        mapCycleList[i].secIns   = -1;

        strclr( mapNameMerged[i] );
    }

#if DELME
    // mutator meta:  #SISSM.allowmutator, and #SISSM.defaultmutator
    //
    strclr( mutAllowed );
    strclr( mutDefault );
#endif

    i = 0;
    if ( NULL != (fpr = fopen( mapcycleFile, "rt" ))) {
        while ( !feof( fpr ) ) {
            if (NULL != fgets( tmpLine, 255, fpr )) {

                // part 1:  parse the "#SISSM.mapname" line
                //
                // printf("\nDEBUG - reading %s", tmpLine );
                if ( tmpLine == strcasestr( tmpLine, "#SISSM.mapname" )) {
                    if ( NULL != (w = getWord( tmpLine, 1, "= ,;:\015\012" ))) {
                        strlcpy( lastMapName, w, 256 );
                        strlcpy( lastReqName, w, 256 );
                        if ( NULL != (w2 = getWord( tmpLine, 2, "= ,;:\015\012" ))) {
                            if (0 != strlen( w2 )) strlcpy( lastReqName, w2, 256 );
                        }
                        // printf("\nDEBUG - reading map name ::%s::", lastMapName );

                        // create a merged list for "maplist" command
                        //
                        for ( j = 0; j<API_MAXMAPS; j++ ) {
                            if ( 0 == strcasecmp( mapNameMerged[j], lastReqName ) ) 
                                break;
                            if ( 0 == strlen( mapNameMerged[j] ) ) {
                                strlcpy( mapNameMerged[j], lastReqName, 40 ); 
                                break;
                            }
                        }
                    }
                }

                // part 2:  parse the scenario name and the game mode (checkpoint, hardcorecheckpoint, etc.)
                //
                else if ( tmpLine == strcasestr( tmpLine, "(Scenario=\"" )) {

                    strlcpy( scenarioName,  getWord( tmpLine, 1, "=\"" ), 255 );

                    if ( (0 != strlen( scenarioName )) && (0 != strlen( lastMapName )) )  {
                        strlcpy( mapCycleList[i].scenario, scenarioName, 256 );
                        strlcpy( mapCycleList[i].mapName,  lastMapName,  256 );
                        strlcpy( mapCycleList[i].reqName,  lastReqName,  256 );
                        strlcpy( mapCycleList[i].traveler, lastMapName,  256 );
                        strncat( mapCycleList[i].traveler, "?Scenario=", 256 );
                        strncat( mapCycleList[i].traveler, scenarioName, 128 );

                        // parse the gamemode
                        //
                        if ( NULL != ( v = strcasestr( tmpLine, "mode=\"" )  )) {
                            if ( NULL != (u = getWord( v, 1, "\"" )) ) {
                                strncat( mapCycleList[i].traveler, "?Game=", 256 );
                                strncat( mapCycleList[i].traveler, u,        172 );
                                strlcpy( mapCycleList[i].gameMode, u,         40 );
                            }
                        }

                        // parse the day/night
                        //
                        if ( NULL != strcasestr( tmpLine, "lighting=\"night\"" )) { 
                            mapCycleList[i].dayNight = 1;
                            strncat( mapCycleList[i].traveler, "?Lighting=Night", 256 );
                        }
                        else {
                            strncat( mapCycleList[i].traveler, "?Lighting=Day", 256 );
                        }

                        mapCycleList[i].secIns = -1;
                        if ( NULL != strcasestr( scenarioName, "insurgent"  )) 
                            mapCycleList[i].secIns = 1;
                        if ( NULL != strcasestr( scenarioName, "security"   )) 
                            mapCycleList[i].secIns = 0;
 
                        logPrintf( LOG_LEVEL_INFO, "api", "Mapcycle %03d tag %s traveler ::Sec/Ins:%1d Day/Night:%1d ::%s:: GameMode ::%s::", 
                            i,
                            mapCycleList[i].reqName,  mapCycleList[i].secIns,  mapCycleList[i].dayNight, 
                            mapCycleList[i].traveler, mapCycleList[i].gameMode );

                        if ( ++i >= API_MAXMAPS ) break; 

                    }
                }

#if DELME
                else if ( tmpLine == strcasestr( tmpLine, "#SISSM.allowmutator" )) {
                    j = 1;
                    while ( 1 == 1 ) {
                        u = getWord( tmpLine, j++, " ,=:\012\015" );
                        if ( u == NULL )        break;
                        if ( 0 == strlen( u ) ) break;
                        strlcat( mutAllowed, u,   16000 );
                        strlcat( mutAllowed, " ", 16000 );
                    } 
                }
                else if ( tmpLine == strcasestr( tmpLine, "#SISSM.defaultmutator" )) {
                    j = 1;
                    while ( 1 == 1 ) {
                        u = getWord( tmpLine, j++, " ,=:\012\015" );
                        if ( u == NULL )        break;
                        if ( 0 == strlen( u ) ) break;
                        strlcat( mutDefault, u,   256 );
                        strlcat( mutDefault, " ", 256 );
                    } 
                }
#endif
            }
        }
    }
 
#if DELME
    // todo-mut

    // Expand the space-separated single string mutAllowed to list mutAllowedList
    //
    strclr( mutAllowedList[0] );
    for (j = 0; j<API_MUT_MAXLIST; i++ ) { 
        w = getWord( mutAllowed, j, " ," );
        if ( w != NULL ) 
            strlcpy( mutAllowedList[j], w, API_MUT_MAXCHAR );
        else {
            strclr( mutAllowedList[j] );
            break;
        }              
    }
#endif 

#if 0
    if ( i != 0 ) {
        printf("\nMaps ------------------------\n");
        for ( j = 0; j<API_MAXMAPS; j++ ) {
            if ( 0 == strlen( mapNameMerged[j] ) ) break;
            printf("::%s:: ",  mapNameMerged[j] );
        }
        printf("\nMutators ------------------------");
        printf("\nMutAllowed ::%s::",    mutAllowed );
        printf("\nMutDefault ::%s::\n",  mutDefault );
    }
#endif

    return( i );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x8(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x122b0
movl $0x0, -0x14(%rbp)
cmpl $0x200, -0x14(%rbp)     # imm = 0x200
jge 0x16e50
movslq -0x14(%rbp), %rax
leaq 0x169196(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
callq 0x122b0
movslq -0x14(%rbp), %rax
leaq 0x16917c(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x100, %rdi            # imm = 0x100
callq 0x122b0
movslq -0x14(%rbp), %rax
leaq 0x16915b(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x200, %rdi            # imm = 0x200
callq 0x122b0
movslq -0x14(%rbp), %rax
leaq 0x16913a(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x300, %rdi            # imm = 0x300
callq 0x122b0
movslq -0x14(%rbp), %rax
leaq 0x169119(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x408, %rdi            # imm = 0x408
callq 0x122b0
movslq -0x14(%rbp), %rcx
leaq 0x1690f8(%rip), %rax    # 0x17fef0
imulq $0x430, %rcx, %rcx      # imm = 0x430
addq %rcx, %rax
movl $0x0, 0x400(%rax)
movslq -0x14(%rbp), %rcx
leaq 0x1690d9(%rip), %rax    # 0x17fef0
imulq $0x430, %rcx, %rcx      # imm = 0x430
addq %rcx, %rax
movl $0xffffffff, 0x404(%rax) # imm = 0xFFFFFFFF
movslq -0x14(%rbp), %rax
leaq 0x1ef0ba(%rip), %rdi    # 0x205ef0
imulq $0x28, %rax, %rax
addq %rax, %rdi
callq 0x122b0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x16d42
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xd031(%rip), %rsi      # 0x23e93
callq 0x8310
movq %rax, %rcx
movq %rcx, -0x10(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x174c4
jmp 0x16e7b
movq -0x10(%rbp), %rdi
callq 0x8250
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x16e95
jmp 0x174c2
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0xff, %esi
callq 0x81e0
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x174bd
leaq -0x120(%rbp), %rax
movq %rax, -0x448(%rbp)
leaq -0x120(%rbp), %rdi
leaq 0xf6b1(%rip), %rsi      # 0x26585
callq 0x8340
movq %rax, %rcx
movq -0x448(%rbp), %rax
cmpq %rcx, %rax
jne 0x17037
leaq -0x120(%rbp), %rdi
movl $0x1, %esi
leaq 0xf695(%rip), %rdx      # 0x26594
callq 0x122d0
movq %rax, %rcx
movq %rcx, -0x328(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x17032
leaq -0x220(%rbp), %rdi
movq -0x328(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
leaq -0x320(%rbp), %rdi
movq -0x328(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
leaq -0x120(%rbp), %rdi
movl $0x2, %esi
leaq 0xf638(%rip), %rdx      # 0x26594
callq 0x122d0
movq %rax, %rcx
movq %rcx, -0x330(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x16fa2
movq -0x330(%rbp), %rdi
callq 0x8110
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x16fa0
leaq -0x320(%rbp), %rdi
movq -0x330(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
jmp 0x16fa2
movl $0x0, -0x18(%rbp)
cmpl $0x200, -0x18(%rbp)     # imm = 0x200
jge 0x17030
movslq -0x18(%rbp), %rax
leaq 0x1eef33(%rip), %rdi    # 0x205ef0
imulq $0x28, %rax, %rax
addq %rax, %rdi
leaq -0x320(%rbp), %rsi
callq 0x8040
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x16fda
jmp 0x17030
movslq -0x18(%rbp), %rax
leaq 0x1eef0b(%rip), %rdi    # 0x205ef0
imulq $0x28, %rax, %rax
addq %rax, %rdi
callq 0x8110
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x17020
movslq -0x18(%rbp), %rax
leaq 0x1eeeea(%rip), %rdi    # 0x205ef0
imulq $0x28, %rax, %rax
addq %rax, %rdi
leaq -0x320(%rbp), %rsi
movl $0x28, %edx
callq 0x11bc0
jmp 0x17030
jmp 0x17022
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x16fa9
jmp 0x17032
jmp 0x174bb
leaq -0x120(%rbp), %rax
movq %rax, -0x450(%rbp)
leaq -0x120(%rbp), %rdi
leaq 0xf549(%rip), %rsi      # 0x2659c
callq 0x8340
movq %rax, %rcx
movq -0x450(%rbp), %rax
cmpq %rcx, %rax
jne 0x174b9
leaq -0x440(%rbp), %rax
movq %rax, -0x458(%rbp)
leaq -0x120(%rbp), %rdi
movl $0x1, %esi
leaq 0xf52b(%rip), %rdx      # 0x265b7
callq 0x122d0
movq -0x458(%rbp), %rdi
movq %rax, %rsi
movl $0xff, %edx
callq 0x11bc0
leaq -0x440(%rbp), %rdi
callq 0x8110
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x174b7
leaq -0x220(%rbp), %rdi
callq 0x8110
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x174b7
movslq -0x14(%rbp), %rax
leaq 0x168e0c(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x200, %rdi            # imm = 0x200
leaq -0x440(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
movslq -0x14(%rbp), %rax
leaq 0x168ddf(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
leaq -0x220(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
movslq -0x14(%rbp), %rax
leaq 0x168db9(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x100, %rdi            # imm = 0x100
leaq -0x320(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
movslq -0x14(%rbp), %rax
leaq 0x168d8c(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x300, %rdi            # imm = 0x300
leaq -0x220(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x11bc0
movslq -0x14(%rbp), %rax
leaq 0x168d5f(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x300, %rdi            # imm = 0x300
leaq 0xf3ff(%rip), %rsi      # 0x265a8
movl $0x100, %edx            # imm = 0x100
callq 0x81b0
movslq -0x14(%rbp), %rax
leaq 0x168d32(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x300, %rdi            # imm = 0x300
leaq -0x440(%rbp), %rsi
movl $0x80, %edx
callq 0x81b0
leaq -0x120(%rbp), %rdi
leaq 0xf3c5(%rip), %rsi      # 0x265b3
callq 0x8340
movq %rax, %rcx
movq %rcx, -0x338(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x172be
movq -0x338(%rbp), %rdi
movl $0x1, %esi
leaq 0xf39d(%rip), %rdx      # 0x265b8
callq 0x122d0
movq %rax, %rcx
movq %rcx, -0x340(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x172bc
movslq -0x14(%rbp), %rax
leaq 0x168cb0(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x300, %rdi            # imm = 0x300
leaq 0xf362(%rip), %rsi      # 0x265ba
movl $0x100, %edx            # imm = 0x100
callq 0x81b0
movslq -0x14(%rbp), %rax
leaq 0x168c83(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x300, %rdi            # imm = 0x300
movq -0x340(%rbp), %rsi
movl $0xac, %edx
callq 0x81b0
movslq -0x14(%rbp), %rax
leaq 0x168c56(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x408, %rdi            # imm = 0x408
movq -0x340(%rbp), %rsi
movl $0x28, %edx
callq 0x11bc0
jmp 0x172be
leaq -0x120(%rbp), %rdi
leaq 0xf2f5(%rip), %rsi      # 0x265c1
callq 0x8340
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x17329
movslq -0x14(%rbp), %rcx
leaq 0x168c0a(%rip), %rax    # 0x17fef0
imulq $0x430, %rcx, %rcx      # imm = 0x430
addq %rcx, %rax
movl $0x1, 0x400(%rax)
movslq -0x14(%rbp), %rax
leaq 0x168beb(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x300, %rdi            # imm = 0x300
leaq 0xf2b5(%rip), %rsi      # 0x265d2
movl $0x100, %edx            # imm = 0x100
callq 0x81b0
jmp 0x17356
movslq -0x14(%rbp), %rax
leaq 0x168bbc(%rip), %rdi    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %rdi
addq $0x300, %rdi            # imm = 0x300
leaq 0xf296(%rip), %rsi      # 0x265e2
movl $0x100, %edx            # imm = 0x100
callq 0x81b0
movslq -0x14(%rbp), %rcx
leaq 0x168b8f(%rip), %rax    # 0x17fef0
imulq $0x430, %rcx, %rcx      # imm = 0x430
addq %rcx, %rax
movl $0xffffffff, 0x404(%rax) # imm = 0xFFFFFFFF
leaq -0x440(%rbp), %rdi
leaq 0xf26d(%rip), %rsi      # 0x265f0
callq 0x8340
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x173b1
movslq -0x14(%rbp), %rcx
leaq 0x168b53(%rip), %rax    # 0x17fef0
imulq $0x430, %rcx, %rcx      # imm = 0x430
addq %rcx, %rax
movl $0x1, 0x404(%rax)
leaq -0x440(%rbp), %rdi
leaq 0xf23b(%rip), %rsi      # 0x265fa
callq 0x8340
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x173ed
movslq -0x14(%rbp), %rcx
leaq 0x168b17(%rip), %rax    # 0x17fef0
imulq $0x430, %rcx, %rcx      # imm = 0x430
addq %rcx, %rax
movl $0x0, 0x404(%rax)
movl -0x14(%rbp), %ecx
movslq -0x14(%rbp), %rax
leaq 0x168af5(%rip), %r8     # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %r8
addq $0x100, %r8             # imm = 0x100
movslq -0x14(%rbp), %rdx
leaq 0x168ad9(%rip), %rax    # 0x17fef0
imulq $0x430, %rdx, %rdx      # imm = 0x430
addq %rdx, %rax
movl 0x404(%rax), %r9d
movslq -0x14(%rbp), %rdx
leaq 0x168abd(%rip), %rax    # 0x17fef0
imulq $0x430, %rdx, %rdx      # imm = 0x430
addq %rdx, %rax
movl 0x400(%rax), %r11d
movslq -0x14(%rbp), %rax
leaq 0x168aa1(%rip), %r10    # 0x17fef0
imulq $0x430, %rax, %rax      # imm = 0x430
addq %rax, %r10
addq $0x300, %r10            # imm = 0x300
movslq -0x14(%rbp), %rdx
leaq 0x168a85(%rip), %rax    # 0x17fef0
imulq $0x430, %rdx, %rdx      # imm = 0x430
addq %rdx, %rax
addq $0x408, %rax            # imm = 0x408
movl $0x2, %edi
leaq 0xea10(%rip), %rsi      # 0x25e97
leaq 0xf175(%rip), %rdx      # 0x26603
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x21bf0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
cmpl $0x200, %eax            # imm = 0x200
jl 0x174b5
jmp 0x174c2
jmp 0x174b7
jmp 0x174b9
jmp 0x174bb
jmp 0x174bd
jmp 0x16e7b
jmp 0x174c4
movl -0x14(%rbp), %eax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq