// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/common/scriplib.cpp
// Function: GetToken(bool)
bool            GetToken(const bool crossline)
{
    char           *token_p;

    if (s_tokenready)                                        // is a g_token allready waiting?
    {
        s_tokenready = false;
        return true;
    }

    if (s_script->script_p >= s_script->end_p)
        return EndOfScript(crossline);

    // skip space
skipspace:
#ifdef ZHLT_TEXNAME_CHARSET
	while (*s_script->script_p <= 32 && *s_script->script_p >= 0)
#else
    while (*s_script->script_p <= 32)
#endif
    {
        if (s_script->script_p >= s_script->end_p)
            return EndOfScript(crossline);

        if (*s_script->script_p++ == '\n')
        {
            if (!crossline)
                Error("Line %i is incomplete (did you place a \" inside an entity string?) \n", s_scriptline);
            s_scriptline = s_script->line++;
        }
    }

    if (s_script->script_p >= s_script->end_p)
        return EndOfScript(crossline);

    // comment fields
    if (*s_script->script_p == ';' || *s_script->script_p == '#' || // semicolon and # is comment field
        (*s_script->script_p == '/' && *((s_script->script_p) + 1) == '/')) // also make // a comment field
    {
        if (!crossline)
            Error("Line %i is incomplete (did you place a \" inside an entity string?) \n", s_scriptline);

        //ets+++
        if (*s_script->script_p == '/')
            s_script->script_p++;
        if (s_script->script_p[1] == 'T' && s_script->script_p[2] == 'X')
            g_TXcommand = s_script->script_p[3];             // AR: "//TX#"-style comment

        //ets---
        while (*s_script->script_p++ != '\n')
        {
            if (s_script->script_p >= s_script->end_p)
                return EndOfScript(crossline);
        }
        //ets+++
        s_scriptline = s_script->line++;                       // AR: this line was missing
        //ets---
        goto skipspace;
    }

    // copy g_token
    token_p = g_token;

    if (*s_script->script_p == '"')
    {
        // quoted token
        s_script->script_p++;
        while (*s_script->script_p != '"')
        {
            *token_p++ = *s_script->script_p++;

            if (s_script->script_p == s_script->end_p)
                break;

            if (token_p == &g_token[MAXTOKEN])
                Error("Token too large on line %i\n", s_scriptline);
        }
        s_script->script_p++;
    }
    else
    {
        // regular token
#ifdef ZHLT_TEXNAME_CHARSET
		while ((*s_script->script_p > 32 || *s_script->script_p < 0) && *s_script->script_p != ';')
#else
        while (*s_script->script_p > 32 && *s_script->script_p != ';')
#endif
        {
            *token_p++ = *s_script->script_p++;

            if (s_script->script_p == s_script->end_p)
                break;

            if (token_p == &g_token[MAXTOKEN])
                Error("Token too large on line %i\n", s_scriptline);
        }
    }

    *token_p = 0;

    if (!strcmp(g_token, "$include"))
    {
        GetToken(false);
        AddScriptToStack(g_token);
        return GetToken(crossline);
    }

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
leaq 0x1246f(%rip), %r14     # 0x1bfca
leaq 0x20b794e(%rip), %r15   # 0x20c14b0
leaq 0x124d3(%rip), %r13     # 0x1c03c
pushq $0x9
popq %rbp
cmpb $0x1, 0x20b8952(%rip)   # 0x20c24c5
je 0x9dd3
movq 0x20b8938(%rip), %rax   # 0x20c24b8
movq 0x1008(%rax), %rcx
cmpq 0x1010(%rax), %rcx
jae 0x9dbd
movq 0x1008(%rax), %rcx
incq %rcx
leaq -0x1(%rcx), %rsi
movzbl -0x1(%rcx), %edx
movq 0x1010(%rax), %rdi
cmpl $0x20, %edx
ja 0x9c01
cmpq %rdi, %rsi
jae 0x9dbd
incq %rsi
movq %rsi, 0x1008(%rax)
cmpb $0xa, -0x1(%rcx)
leaq 0x1(%rcx), %rcx
jne 0x9b9e
testb %bl, %bl
jne 0x9bea
movl 0x20b88e7(%rip), %esi   # 0x20c24c0
movq %r14, %rdi
xorl %eax, %eax
callq 0x8d7b
movq 0x20b88ce(%rip), %rax   # 0x20c24b8
movl 0x1018(%rax), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x1018(%rax)
movl %ecx, 0x20b88c1(%rip)   # 0x20c24c0
jmp 0x9b94
cmpq %rdi, %rsi
jae 0x9dbd
cmpl $0x23, %edx
je 0x9c24
cmpl $0x2f, %edx
je 0x9c1b
cmpl $0x3b, %edx
je 0x9c24
jmp 0x9c8e
cmpb $0x2f, (%rcx)
jne 0x9d0a
testb %bl, %bl
jne 0x9c3f
movl 0x20b8892(%rip), %esi   # 0x20c24c0
movq %r14, %rdi
xorl %eax, %eax
callq 0x8d7b
movq 0x20b8879(%rip), %rax   # 0x20c24b8
movq 0x1008(%rax), %rcx
cmpb $0x2f, (%rcx)
jne 0x9c55
incq %rcx
movq %rcx, 0x1008(%rax)
cmpb $0x54, 0x1(%rcx)
jne 0x9c6a
cmpb $0x58, 0x2(%rcx)
jne 0x9c6a
movb 0x3(%rcx), %dl
movb %dl, 0x20b8846(%rip)    # 0x20c24b0
movq %rcx, %rdx
incq %rcx
movq %rcx, 0x1008(%rax)
cmpb $0xa, (%rdx)
je 0x9bea
cmpq 0x1010(%rax), %rcx
jb 0x9c6a
jmp 0x9dbd
cmpl $0x22, %edx
jne 0x9d0a
movq %rcx, 0x1008(%rax)
xorl %r12d, %r12d
leaq (%r12,%r15), %rcx
incq %rcx
negq %r12
movq 0x1008(%rax), %rdx
cmpb $0x22, (%rdx)
je 0x9d84
leaq 0x1(%rdx), %rsi
movq %rsi, 0x1008(%rax)
movb (%rdx), %dl
movb %dl, -0x1(%rcx)
movq 0x1008(%rax), %rdx
cmpq 0x1010(%rax), %rdx
je 0x9d8a
decq %r12
incq %rcx
cmpq $-0x1000, %r12          # imm = 0xF000
jne 0x9ca7
movl 0x20b87d0(%rip), %esi   # 0x20c24c0
leaq 0x12329(%rip), %rdi     # 0x1c020
xorl %eax, %eax
callq 0x8d7b
movq 0x20b87b3(%rip), %rax   # 0x20c24b8
negq %r12
jmp 0x9c9d
xorl %r12d, %r12d
leaq (%r12,%r15), %rcx
incq %rcx
negq %r12
movq 0x1008(%rax), %rdx
movb (%rdx), %sil
cmpb $0x21, %sil
jb 0x9d7c
cmpb $0x3b, %sil
je 0x9d7c
leaq 0x1(%rdx), %rsi
movq %rsi, 0x1008(%rax)
movb (%rdx), %dl
movb %dl, -0x1(%rcx)
movq 0x1008(%rax), %rdx
cmpq 0x1010(%rax), %rdx
je 0x9d94
decq %r12
incq %rcx
cmpq $-0x1000, %r12          # imm = 0xF000
jne 0x9d17
movl 0x20b875e(%rip), %esi   # 0x20c24c0
leaq 0x122b7(%rip), %rdi     # 0x1c020
xorl %eax, %eax
callq 0x8d7b
movq 0x20b8741(%rip), %rax   # 0x20c24b8
negq %r12
jmp 0x9d0d
movq %r15, %rcx
subq %r12, %rcx
jmp 0x9d94
movq %r15, %rcx
subq %r12, %rcx
incq %rdx
movq %rdx, 0x1008(%rax)
movb $0x0, (%rcx)
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x4330
testl %eax, %eax
jne 0x9dda
xorl %edi, %edi
callq 0x9b47
movq %r15, %rdi
callq 0x99a4
jmp 0x9b6c
movzbl %bl, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9aab
movb $0x0, 0x20b86eb(%rip)   # 0x20c24c5
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq