// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rdi, %rbx
leaq 0x220(%rsp), %rdi
callq 0xf829
leaq 0x1eb352(%rip), %r14    # 0x1fdef0
xorl %r12d, %r12d
leaq 0x165348(%rip), %rbp    # 0x177ef0
movabsq $-0x100000000, %r13     # imm = 0xFFFFFFFF00000000
leaq (%r12,%rbp), %rdi
callq 0xf829
leaq (%r12,%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
callq 0xf829
leaq (%r12,%rbp), %rdi
addq $0x200, %rdi            # imm = 0x200
callq 0xf829
leaq (%r12,%rbp), %rdi
addq $0x300, %rdi            # imm = 0x300
callq 0xf829
leaq (%r12,%rbp), %r15
addq $0x408, %r15            # imm = 0x408
movq %r15, %rdi
callq 0xf829
movq %r13, -0x8(%r15)
movq %r14, %rdi
callq 0xf829
addq $0x28, %r14
addq $0x430, %r12            # imm = 0x430
cmpq $0x86000, %r12          # imm = 0x86000
jne 0x12bb2
leaq 0x9266(%rip), %rsi      # 0x1be8b
movq %rbx, %rdi
callq 0x8320
movq $0x0, 0x8(%rsp)
testq %rax, %rax
je 0x1301f
movq %rax, %rbx
movq %rax, %rdi
callq 0x8270
testl %eax, %eax
jne 0x1301f
leaq 0x320(%rsp), %r14
leaq 0xb904(%rip), %r13      # 0x1e565
leaq 0xb90c(%rip), %r12      # 0x1e574
movq $0x0, 0x8(%rsp)
movq %r14, %rdi
movl $0xff, %esi
movq %rbx, %rdx
callq 0x8200
testq %rax, %rax
je 0x1300f
movq %r14, %rdi
movq %r13, %rsi
callq 0x8350
movq %r14, %rdi
cmpq %rax, %r14
je 0x12e5b
leaq 0xb8d4(%rip), %rsi      # 0x1e57c
callq 0x8350
cmpq %rax, %r14
jne 0x1300f
movq %r14, %rdi
movl $0x1, %esi
leaq 0xb8d2(%rip), %rdx      # 0x1e597
callq 0xf82d
movl $0xff, %edx
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0xf384
cmpb $0x0, 0x20(%rsp)
je 0x1300f
cmpb $0x0, 0x220(%rsp)
je 0x1300f
movslq 0x8(%rsp), %rax
imulq $0x430, %rax, %r15      # imm = 0x430
leaq (%r15,%rbp), %r12
leaq (%r15,%rbp), %rdi
addq $0x200, %rdi            # imm = 0x200
movl $0x100, %edx            # imm = 0x100
leaq 0x20(%rsp), %rsi
callq 0xf384
movl $0x100, %edx            # imm = 0x100
movq %r12, %rdi
leaq 0x220(%rsp), %r13
movq %r13, %rsi
callq 0xf384
leaq (%r15,%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
movl $0x100, %edx            # imm = 0x100
movq %rdi, 0x18(%rsp)
leaq 0x120(%rsp), %rsi
callq 0xf384
addq %rbp, %r15
addq $0x300, %r15            # imm = 0x300
movl $0x100, %edx            # imm = 0x100
movq %r15, %rdi
movq %r13, %rsi
callq 0xf384
movq %r15, %rdi
callq 0x8120
movabsq $0x6972616e6563533f, %rcx # imm = 0x6972616E6563533F
movq %rcx, 0x300(%rax,%r12)
movl $0x3d6f69, 0x307(%rax,%r12) # imm = 0x3D6F69
movl $0x80, %edx
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
callq 0x81c0
movq %r14, %rdi
leaq 0xb7de(%rip), %rsi      # 0x1e593
callq 0x8350
testq %rax, %rax
je 0x12e19
movq %rax, %rdi
movl $0x1, %esi
leaq 0xb7ca(%rip), %rdx      # 0x1e598
callq 0xf82d
testq %rax, %rax
je 0x12e19
movq %rax, %r13
movq %r15, %rdi
callq 0x8120
movl $0x6d61473f, (%r15,%rax) # imm = 0x6D61473F
movl $0x3d656d, 0x3(%r15,%rax) # imm = 0x3D656D
movl $0xac, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x81c0
leaq 0x408(%r12), %rdi
movl $0x28, %edx
movq %r13, %rsi
callq 0xf384
movq %r14, %rdi
leaq 0xb77e(%rip), %rsi      # 0x1e5a1
callq 0x8350
testq %rax, %rax
movq %r15, 0x10(%rsp)
je 0x12f25
movl $0x1, 0x400(%r12)
movq %r15, %rdi
callq 0x8120
movups 0xb761(%rip), %xmm0     # 0x1e5b2
movups %xmm0, (%r15,%rax)
jmp 0x12f4a
movl $0x1, %esi
movq %r12, %rdx
callq 0xf82d
testq %rax, %rax
je 0x1300f
movq %rax, %r15
movl $0x100, %edx            # imm = 0x100
leaq 0x220(%rsp), %rdi
movq %rax, %rsi
callq 0xf384
movl $0x100, %edx            # imm = 0x100
leaq 0x120(%rsp), %rdi
movq %r15, %rsi
callq 0xf384
movq %r14, %rdi
movl $0x2, %esi
movq %r12, %rdx
callq 0xf82d
testq %rax, %rax
je 0x12ecd
cmpb $0x0, (%rax)
je 0x12ecd
movl $0x100, %edx            # imm = 0x100
leaq 0x120(%rsp), %rdi
movq %rax, %rsi
callq 0xf384
xorl %r12d, %r12d
leaq 0x1eb019(%rip), %rax    # 0x1fdef0
leaq (%rax,%r12), %r15
movq %r15, %rdi
leaq 0x120(%rsp), %rsi
callq 0x8060
testl %eax, %eax
je 0x12f19
cmpb $0x0, (%r15)
je 0x12f04
addq $0x28, %r12
cmpq $0x5000, %r12           # imm = 0x5000
jne 0x12ed0
jmp 0x12f19
movl $0x28, %edx
movq %r15, %rdi
leaq 0x120(%rsp), %rsi
callq 0xf384
leaq 0xb654(%rip), %r12      # 0x1e574
jmp 0x1300f
movq %r15, %rdi
callq 0x8120
movabsq $0x6e69746867694c3f, %rcx # imm = 0x6E69746867694C3F
movq %rcx, (%r15,%rax)
movabsq $0x7961443d676e69, %rcx # imm = 0x7961443D676E69
movq %rcx, 0x6(%r15,%rax)
movl $0xffffffff, 0x404(%r12) # imm = 0xFFFFFFFF
leaq 0x20(%rsp), %r15
movq %r15, %rdi
leaq 0xb66b(%rip), %rsi      # 0x1e5d0
callq 0x8350
cmpq $0x1, %rax
movl $0x0, %r13d
sbbl %r13d, %r13d
orl $0x1, %r13d
movl %r13d, 0x404(%r12)
movq %r15, %rdi
leaq 0xb64d(%rip), %rsi      # 0x1e5da
callq 0x8350
testq %rax, %rax
movl $0x0, %eax
cmovnel %eax, %r13d
movl %r13d, 0x404(%r12)
movl 0x400(%r12), %r10d
addq $0x408, %r12            # imm = 0x408
subq $0x8, %rsp
movl $0x2, %edi
leaq 0xaeba(%rip), %rsi      # 0x1de7f
leaq 0xb617(%rip), %rdx      # 0x1e5e3
movq 0x10(%rsp), %r15
movl %r15d, %ecx
movq 0x20(%rsp), %r8
movl %r13d, %r9d
xorl %eax, %eax
pushq %r12
pushq 0x20(%rsp)
pushq %r10
callq 0x1a3e3
addq $0x20, %rsp
leal 0x1(%r15), %eax
cmpl $0x1fe, %r15d           # imm = 0x1FE
movq %rax, 0x8(%rsp)
leaq 0xb55f(%rip), %r13      # 0x1e565
leaq 0xb567(%rip), %r12      # 0x1e574
jg 0x1301f
movq %rbx, %rdi
callq 0x8270
testl %eax, %eax
je 0x12c71
movq 0x8(%rsp), %rax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq