// File: /workspace/github_c_makefile_star2_O3/simh[P]simtools/converters/fsio/dos11.c
// Function: dos11ParseFilespec
int dos11ParseFilespec(
  char *ptr,
  struct dos11FileSpec *spec,
  unsigned char user,
  unsigned char group,
  int wildcard
)
{
  char term[] = { '\0', '.', '[', ',', ']' };
  char flags[] =
    { 0, DOS11_WC_NAME, DOS11_WC_EXT, DOS11_WC_GROUP, DOS11_WC_USER };
  int state = P_NAME;
  unsigned int uic, i;
  char filename[6], ext[3];

  memset(spec, 0, sizeof(struct dos11FileSpec));
  spec->user = user;
  spec->group = group;

  memset(&filename, ' ', sizeof(filename));
  memset(&ext, ' ', sizeof(ext));

  if (wildcard == DOS11_M_NONAME)
    if ((*ptr == '\0') || (*ptr == '['))
      spec->flags = DOS11_WC_NAME | DOS11_WC_EXT;

  while (state != P_DONE) {
    if (wildcard) {
      if (*ptr == '*') {
        spec->flags |= flags[state];
        ptr++;
        if (*ptr == '\0')
          state = P_DONE;
        else if (*ptr == term[state]) {
          if (state == P_USER)
            state = P_DONE;
          else state++;
        } else return 0;
        ptr++;
        continue;
      }
    }

    i = 0;

    switch (state) {
      case P_NAME:
        while ((*ptr != '\0') &&
               (*ptr != '.') &&
               (strchr(rad50, toupper(*ptr)) != NULL) &&
               (i < sizeof(filename)))
          filename[i++] = toupper(*ptr++);

        switch (*ptr++) {
          case '\0':
            state = P_DONE;
            break;

          case '.':
            state = P_EXT;
            break;

          case '[':
            state = P_GROUP;
            break;

          default:
            return 0;
        }
        break;

      case P_EXT:
        while ((*ptr != '\0') &&
               (strchr(rad50, toupper(*ptr)) != NULL) &&
               (i < sizeof(ext)))
          ext[i++] = toupper(*ptr++);
        
        switch (*ptr++) {
          case '\0':
            state = P_DONE;
            break;

          case '[':
            state = P_GROUP;
            break;

          default:
            return 0;
        }
        break;

      case P_GROUP:
        uic = 0;
        while ((strchr("01234567", *ptr) != NULL) && (i < 3)) {
          uic = (uic << 3) | (*ptr++ - '0');
          i++;
        }
        if ((uic == 0) || (uic > 0377))
          return 0;
        spec->group = uic & 0377;

        if (*ptr++ != ',')
          return 0;

        state = P_USER;
        break;

      case P_USER:
        uic = 0;
        while ((strchr("01234567", *ptr) != NULL) && (i < 3)) {
          uic = (uic << 3) | (*ptr++ - '0');
          i++;
        }
        if ((uic == 0) || (uic > 0377))
          return 0;
        spec->user = uic & 0377;

        if (*ptr++ != ']')
          return 0;

        state = P_DONE;
        break;
    }
  }

  spec->name[0] = ascR50(&filename[0]);
  spec->name[1] = ascR50(&filename[3]);
  spec->ext = ascR50(&ext[0]);
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
movq $0x0, (%rsi)
movb %dl, 0x8(%rsi)
movq %rsi, 0x10(%rsp)
movb %cl, 0x9(%rsi)
movw $0x2020, %ax            # imm = 0x2020
movw %ax, 0xc(%rsp)
movl $0x20202020, 0x8(%rsp)  # imm = 0x20202020
movw %ax, 0x4(%rsp)
movb $0x20, 0x6(%rsp)
movl $0x0, %eax
movl %r8d, 0x1c(%rsp)
cmpl $0x2, %r8d
jne 0x7c6f
movzbl (%r14), %eax
cmpl $0x5b, %eax
je 0x7c61
testl %eax, %eax
jne 0x7c6d
movq 0x10(%rsp), %rax
movb $0x3, (%rax)
movb $0x3, %al
jmp 0x7c6f
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movl $0x1, %eax
leaq 0x9c88(%rip), %r12      # 0x11908
cmpl $0x0, 0x1c(%rsp)
je 0x7cdb
cmpb $0x2a, (%r14)
jne 0x7cdb
movl %eax, %ecx
movq 0x20(%rsp), %rsi
leaq 0x9bca(%rip), %rdx      # 0x11865
orb (%rcx,%rdx), %sil
movq 0x10(%rsp), %rdx
movb %sil, (%rdx)
movb 0x1(%r14), %dl
testb %dl, %dl
movq %rsi, 0x20(%rsp)
je 0x7e36
leaq 0x9ba1(%rip), %rdi      # 0x11860
cmpb (%rcx,%rdi), %dl
jne 0x7f37
cmpl $0x4, %eax
leal 0x1(%rax), %eax
movl $0x0, %ecx
cmovel %ecx, %eax
jmp 0x7e38
decl %eax
leaq 0x9b6c(%rip), %rcx      # 0x11850
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %ebp, %ebp
movzbl (%r14,%rbp), %r15d
movsbq %r15b, %rbx
testl %r15d, %r15d
je 0x7e1d
cmpl $0x2e, %r15d
je 0x7e1d
callq 0x3030
movq (%rax), %rax
movl (%rax,%rbx,4), %r13d
leaq 0x10902(%rip), %rdi     # 0x18620
movl %r13d, %esi
callq 0x3150
testq %rax, %rax
je 0x7e1d
cmpq $0x5, %rbp
ja 0x7e1d
movb %r13b, 0x8(%rsp,%rbp)
incq %rbp
jmp 0x7cef
movsbl (%r14), %r13d
movl $0x9, %edx
movq %r12, %rdi
movl %r13d, %esi
callq 0x31a0
testq %rax, %rax
je 0x7f37
xorl %ebx, %ebx
xorl %ebp, %ebp
movl %ebp, %eax
shll $0x3, %eax
addl $-0x30, %r13d
movl %r13d, %ebp
orl %eax, %ebp
movsbl 0x1(%r14,%rbx), %r13d
movl $0x9, %edx
movq %r12, %rdi
movl %r13d, %esi
callq 0x31a0
leaq 0x1(%rbx), %rcx
testq %rax, %rax
je 0x7d99
cmpl $0x2, %ebx
movq %rcx, %rbx
jb 0x7d64
leal -0x100(%rbp), %edx
xorl %eax, %eax
cmpl $0xffffff01, %edx       # imm = 0xFFFFFF01
jb 0x7e96
movq 0x10(%rsp), %rdx
movb %bpl, 0x9(%rdx)
cmpb $0x2c, (%r14,%rcx)
jne 0x7e96
addq %rcx, %r14
incq %r14
movl $0x4, %eax
jmp 0x7e5a
movb (%r14), %bpl
testb %bpl, %bpl
je 0x7e62
callq 0x3030
movq (%rax), %r15
xorl %ebx, %ebx
movsbq %bpl, %rax
movl (%r15,%rax,4), %r13d
leaq 0x1082a(%rip), %rdi     # 0x18620
movl %r13d, %esi
callq 0x3150
testq %rax, %rax
je 0x7e3e
cmpq $0x2, %rbx
ja 0x7e3e
movb %r13b, 0x4(%rsp,%rbx)
movb 0x1(%r14,%rbx), %bpl
incq %rbx
testb %bpl, %bpl
jne 0x7de7
jmp 0x7e62
addq %rbp, %r14
incq %r14
cmpb $0x2e, %r15b
je 0x7e55
movzbl %bl, %eax
cmpl $0x5b, %eax
je 0x7e4e
jmp 0x7f2f
xorl %eax, %eax
addq $0x2, %r14
jmp 0x7e5a
cmpb $0x5b, %bpl
jne 0x7f37
addq %rbx, %r14
incq %r14
movl $0x3, %eax
jmp 0x7e5a
movl $0x2, %eax
testl %eax, %eax
jne 0x7c80
leaq 0x8(%rsp), %rdi
callq 0x665e
movq 0x10(%rsp), %rbx
movw %ax, 0x2(%rbx)
leaq 0xb(%rsp), %rdi
callq 0x665e
movw %ax, 0x4(%rbx)
leaq 0x4(%rsp), %rdi
callq 0x665e
movw %ax, 0x6(%rbx)
movl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsbl (%r14), %ebp
leaq 0x9a58(%rip), %rdi      # 0x11908
movl $0x9, %edx
movl %ebp, %esi
callq 0x31a0
testq %rax, %rax
je 0x7f37
xorl %r12d, %r12d
leaq 0x9a3d(%rip), %r15      # 0x11908
xorl %r13d, %r13d
movl %r13d, %eax
shll $0x3, %eax
addl $-0x30, %ebp
movl %ebp, %r13d
orl %eax, %r13d
movsbl 0x1(%r14,%r12), %ebp
movl $0x9, %edx
movq %r15, %rdi
movl %ebp, %esi
callq 0x31a0
leaq 0x1(%r12), %rcx
testq %rax, %rax
je 0x7f05
cmpl $0x2, %r12d
movq %rcx, %r12
jb 0x7ece
leal -0x100(%r13), %edx
xorl %eax, %eax
cmpl $0xffffff01, %edx       # imm = 0xFFFFFF01
jb 0x7e96
movq 0x10(%rsp), %rdx
movb %r13b, 0x8(%rdx)
cmpb $0x5d, (%r14,%rcx)
je 0x7e62
jmp 0x7e96
testl %eax, %eax
je 0x7e62
xorl %eax, %eax
jmp 0x7e96