// File: /workspace/github_c_makefile_star2_O2/mmayer[P]pcal/src/readfile.c
// Function: read_datefile
void read_datefile (FILE *fp, char *filename)
{
   static int file_level = 0;
   int if_level = 0;
   int line = 0;
   int extra = 0;
   int pptype, ntokens, save_year, expr, (*pfcn) (char *) = NULL;
   char *ptok = NULL;
   char **pword;
   char msg[STRSIZ], incpath[STRSIZ], save_font;

   /* stack for processing nested "if{n}defs" - required for "elif" */
   struct {
      int state;   /* PROCESSING, AWAITING_TRUE, SKIP_TO_ENDIF */
      int else_ok;   /* is "elif" or "else" legal at this point? */
   } if_state[MAX_IF_NESTING+1];
   
   if (fp == NULL) return;   /* whoops, no date file */
      
   /* Note that there is no functional limit on file nesting.  This is mostly
      to catch infinite loops (e.g., a includes b, b includes a).
   */
   if (++file_level > MAX_FILE_NESTING) {
      ERR(E_FILE_NESTING);
      exit(EXIT_FAILURE);
   }
   
   save_year = curr_year;   /* save current year... */
   save_font = fontstyle[0];   /* ... and font style */
   
   if_state[0].state = PROCESSING;   /* set up initial state */
   if_state[0].else_ok = FALSE;
   
   /* read lines until EOF */
   
   while (get_pcal_line(fp, lbuf, &line)) {
      char suffix;
      
      if (DEBUG(DEBUG_PP)) {
         fprintf(stderr, "%s (%d)", filename, line);
         if (if_state[if_level].state == PROCESSING) fprintf(stderr, ": '%s'", lbuf);
         fprintf(stderr, "\n");
      }
      
      ntokens = loadwords(words, lbuf); /* split line into tokens */
      pword = words;   /* point to the first */
      
      /* get token type and pointers to function and name */
      
      suffix = words[0][strlen(words[0])-1];
      if ((pptype = get_token(*pword++)) != PP_OTHER) {
         pfcn = pp_info[pptype].pfcn;
         ptok = pp_info[pptype].name;
         pptype = pp_info[pptype].code;   /* use type code */
      }
      
      /* Perform symbol value substitution, but bypass it for any 'undef'
        preprocessor commands, otherwise there's no way to 'undef' a symbol
        which also had a value defined with it.
      */
      if (pptype != PP_UNDEF) {
         char **ap, *nap;
         for (ap=words; *ap; ap++) {
            if ((nap = find_sym_val(*ap))) *ap=nap;
         }
      }
      
      switch (pptype) {

      case PP_DEFINE:
         if (if_state[if_level].state == PROCESSING) (void) (*pfcn)(*pword);
         if (ntokens == 3) do_define_sym_val(*pword,pword[1]);
         extra = ntokens > 3;
         break;
         
      case PP_UNDEF:
         if (if_state[if_level].state == PROCESSING) (void) (*pfcn)(*pword);
         extra = ntokens > 2;
         break;
         
      case PP_ELIF:
         if (!if_state[if_level].else_ok) {
            ERR(E_ELIF_ERR);
            break;
         }
         
         /* if a true expression has just been processed, disable processing
            and skip to endif; if no true expression has been found yet and
            the current expression is true, enable processing
         */
         switch (if_state[if_level].state) {
         case PROCESSING:
            if_state[if_level].state = SKIP_TO_ENDIF;
            break;
         case AWAITING_TRUE:
            copy_text(lbuf, pword);   /* reconstruct string */
            if ((expr = (*pfcn)(lbuf)) == EXPR_ERR) {
               ERR(E_EXPR_SYNTAX);
               expr = FALSE;
            }
            if (expr) if_state[if_level].state = PROCESSING;
            break;
         }
         
         extra = FALSE;
         break;
         
      case PP_ELSE:
         if (!if_state[if_level].else_ok) {
            ERR(E_ELSE_ERR);
            break;
         }
         
         /* if a true condition has just been processed, disable processing
            and skip to endif; if no true condition has been found yet, enable
            processing
         */
         switch (if_state[if_level].state) {
         case PROCESSING:
            if_state[if_level].state = SKIP_TO_ENDIF;
            break;
         case AWAITING_TRUE:
            if_state[if_level].state = PROCESSING;
            break;
         }
         
         /* subsequent "elif" or "else" forbidden */
         if_state[if_level].else_ok = FALSE;
         extra = ntokens > 1;
         break;
         
      case PP_ENDIF:
         if (if_level < 1) {
            ERR(E_END_ERR);
            break;
         }
         if_level--;
         extra = ntokens > 1;
         break;
         
      case PP_IFDEF:
      case PP_IFNDEF:
         /* "if{n}def"s nested too deeply? */
         if (++if_level > MAX_IF_NESTING) {
            ERR(E_IF_NESTING);
            exit(EXIT_FAILURE);
            break;
         }
         
         /* if processing enabled at outer level, evaluate expression and
            enable/disable processing for following clause; if not, skip to
            matching endif
         */
         if (if_state[if_level-1].state == PROCESSING) {
            copy_text(lbuf, pword);   /* reconstruct string */
            if ((expr = (*pfcn)(lbuf)) == EXPR_ERR) {
               ERR(E_EXPR_SYNTAX);
               expr = FALSE;
            }
            if_state[if_level].state = expr ? PROCESSING : AWAITING_TRUE;
         } 
         else if_state[if_level].state = SKIP_TO_ENDIF;
         
         if_state[if_level].else_ok = TRUE;
         extra = FALSE;
         break;
         
      case PP_INCLUDE:
         if (if_state[if_level].state == PROCESSING) {
            do_include(mk_path(incpath, filename), *pword, suffix == '?');
         }
         extra = ntokens > 2;
         break;
         
      case PP_OTHER:   
         /* None of the above... Parse this configuration file line as a
            non-preprocessor directive.  This could be an event specification,
            an event deletion specification, a 'year' specification, an 'input
            language' specification, an option specification, or a 'note box'
            text specification.
         */
         if (if_state[if_level].state == PROCESSING) {

            switch (parse_as_non_preproc(words, filename)) {

            case PARSE_INVDATE:
               ERR(E_INV_DATE);
               break;
               
            case PARSE_INVLINE:
               ERR(E_INV_LINE);
               break;
               
            case PARSE_NOMATCH:
               ERR(E_NO_MATCH);
               break;
            }
         }
         extra = FALSE;
         break;
         
      } /* end switch */
      
      if (extra) {   /* extraneous data? */
         sprintf(msg, E_GARBAGE, ptok);
         ERR(msg);
      }
      
   } /* end while */
   
   if (if_level > 0) fprintf(stderr, E_UNT_IFDEF, progname, filename);
   
   file_level--;
   curr_year = save_year;   /* restore saved year and font style */
   fontstyle[0] = save_font;

   return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movq %rsi, 0x10(%rsp)
andl $0x0, 0xc(%rsp)
movq %rdi, 0x38(%rsp)
testq %rdi, %rdi
je 0xb0e2
movl 0x22ce9(%rip), %eax     # 0x2d810
leal 0x1(%rax), %ecx
movl %ecx, 0x22ce0(%rip)     # 0x2d810
cmpl $0xa, %eax
jge 0xb14b
leaq 0x22a90(%rip), %rax     # 0x2d5d0
movl (%rax), %eax
movl %eax, 0x2c(%rsp)
leaq 0x1e139(%rip), %rax     # 0x28c86
movb (%rax), %al
movb %al, 0x1b(%rsp)
andq $0x0, 0x40(%rsp)
leaq 0x21dc0(%rip), %r14     # 0x2c920
movq $0x0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x38(%rsp), %rdi
movq %r14, %rsi
leaq 0xc(%rsp), %rdx
callq 0xa785
testl %eax, %eax
je 0xb0b6
leaq 0x21b33(%rip), %rax     # 0x2c6cc
testb $0x20, (%rax)
movslq %r13d, %r15
jne 0xaebc
movl %r12d, 0x1c(%rsp)
movl %r13d, %ebx
leaq 0x21f6c(%rip), %r13     # 0x2cb20
movq %r13, %rdi
movq %r14, %rsi
callq 0xa10d
movl %eax, %r12d
movq (%r13), %rbp
movq %rbp, %rdi
callq 0x5100
movb -0x1(%rbp,%rax), %r13b
movq %rbp, %rdi
callq 0xb174
pushq $-0x1
popq %rcx
movl %ecx, %ebp
cmpl $-0x1, %eax
je 0xac2e
cltq
imulq $0x18, %rax, %rax
leaq 0x1dbfe(%rip), %rcx     # 0x287f0
movq 0x10(%rcx,%rax), %rdx
movq %rdx, 0x20(%rsp)
movq (%rcx,%rax), %rdx
movq %rdx, 0x30(%rsp)
movl 0x8(%rcx,%rax), %ebp
cmpl $0x7, %ebp
jne 0xac2e
cmpl $0x0, 0x40(%rsp,%r15,8)
jne 0xad18
leaq 0x21eff(%rip), %rax     # 0x2cb20
movq 0x8(%rax), %rdi
callq *0x20(%rsp)
jmp 0xad18
leaq 0x21eeb(%rip), %r14     # 0x2cb20
movq (%r14), %rdi
testq %rdi, %rdi
je 0xac50
callq 0xb1c5
testq %rax, %rax
je 0xac4a
movq %rax, (%r14)
addq $0x8, %r14
jmp 0xac35
incl %ebp
cmpl $0x8, %ebp
ja 0xaeac
leaq 0x12fb2(%rip), %rcx     # 0x1dc14
movslq (%rcx,%rbp,4), %rax
addq %rcx, %rax
leaq 0x21cb0(%rip), %r14     # 0x2c920
jmpq *%rax
cmpl $0x14, %ebx
jge 0xb113
movl %ebx, %r13d
cmpl $0x0, 0x40(%rsp,%r15,8)
pushq $0x2
popq %rax
jne 0xacb5
leaq 0x21e90(%rip), %rax     # 0x2cb20
leaq 0x8(%rax), %rsi
movq %r14, %rdi
callq 0xa253
movq %r14, %rdi
callq *0x20(%rsp)
movl %eax, %ebx
cmpl $-0x1, %eax
je 0xaff5
xorl %eax, %eax
testl %ebx, %ebx
sete %al
incl %r13d
movslq %r13d, %rcx
movl %eax, 0x40(%rsp,%rcx,8)
movl $0x1, 0x44(%rsp,%rcx,8)
xorl %r12d, %r12d
jmp 0xab78
movl %ebx, %r13d
testl %ebx, %ebx
jle 0xaf40
decl %r13d
jmp 0xadee
cmpl $0x0, 0x40(%rsp,%r15,8)
jne 0xad18
leaq 0xf0(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xa8a7
leaq 0x21e1d(%rip), %rcx     # 0x2cb20
movq 0x8(%rcx), %rsi
xorl %edx, %edx
cmpb $0x3f, %r13b
sete %dl
movq %rax, %rdi
callq 0xb24a
xorl %ebp, %ebp
cmpl $0x3, %r12d
setge %bpl
movl %ebx, %r13d
movl $0x0, %r12d
testl %ebp, %ebp
je 0xab78
leaq 0x1c0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x1308c(%rip), %rsi     # 0x1ddd1
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x52e0
movq 0x1d2a0(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
leaq 0x12f6d(%rip), %rsi     # 0x1dcd4
leaq 0x21ab2(%rip), %rdx     # 0x2c820
movq %rbx, %rcx
movq 0x10(%rsp), %r8
xorl %eax, %eax
callq 0x5200
movl %ebp, %r12d
jmp 0xab78
cmpl $0x0, 0x44(%rsp,%r15,8)
je 0xaf79
movl 0x40(%rsp,%r15,8), %eax
cmpl $0x1, %eax
je 0xaf00
movl $0x0, %r12d
testl %eax, %eax
movl %ebx, %r13d
jne 0xab78
movl $0x2, 0x40(%rsp,%r15,8)
xorl %r12d, %r12d
jmp 0xab78
cmpl $0x0, 0x44(%rsp,%r15,8)
je 0xaf9f
movl 0x40(%rsp,%r15,8), %ecx
pushq $0x2
popq %rax
testl %ecx, %ecx
movl %ebx, %r13d
je 0xade3
cmpl $0x1, %ecx
jne 0xade8
xorl %eax, %eax
movl %eax, 0x40(%rsp,%r15,8)
andl $0x0, 0x44(%rsp,%r15,8)
xorl %ebp, %ebp
cmpl $0x2, %r12d
setge %bpl
jmp 0xad25
cmpl $0x0, 0x40(%rsp,%r15,8)
movl $0x0, %r12d
movl %ebx, %r13d
jne 0xab78
leaq 0x21d07(%rip), %rdi     # 0x2cb20
movq 0x10(%rsp), %rsi
callq 0xb42c
cmpl $0x3, %eax
je 0xb055
cmpl $0x2, %eax
je 0xb02c
movl $0x0, %r12d
cmpl $0x1, %eax
jne 0xab78
movq 0x1d1ad(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
xorl %r12d, %r12d
leaq 0x12e77(%rip), %rsi     # 0x1dcd4
leaq 0x219bc(%rip), %rdx     # 0x2c820
leaq 0x12f31(%rip), %rcx     # 0x1dd9c
jmp 0xb0a5
cmpl $0x0, 0x40(%rsp,%r15,8)
jne 0xae87
leaq 0x21ca1(%rip), %rax     # 0x2cb20
movq 0x8(%rax), %rdi
callq *0x20(%rsp)
cmpl $0x3, %r12d
jne 0xaea1
leaq 0x21c8c(%rip), %rax     # 0x2cb20
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
callq 0xb1e3
xorl %ebp, %ebp
cmpl $0x4, %r12d
jmp 0xad1e
movl 0x1c(%rsp), %ebp
leaq 0x21a69(%rip), %r14     # 0x2c920
jmp 0xad22
movq 0x1d135(%rip), %r14     # 0x27ff8
movq (%r14), %rdi
movl 0xc(%rsp), %ecx
leaq 0x12e43(%rip), %rsi     # 0x1dd14
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x5200
cmpl $0x0, 0x40(%rsp,%r15,8)
je 0xafd8
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x51b0
leaq 0x21a25(%rip), %r14     # 0x2c920
jmp 0xaba5
leaq 0x21c19(%rip), %rax     # 0x2cb20
leaq 0x8(%rax), %rsi
movq %r14, %rdi
callq 0xa253
movq %r14, %rdi
callq *0x20(%rsp)
movl %eax, %r12d
testl %eax, %eax
movl %ebx, %r13d
je 0xab78
cmpl $-0x1, %r12d
je 0xb07e
andl $0x0, 0x40(%rsp,%r15,8)
xorl %r12d, %r12d
jmp 0xab78
movq 0x1d0b1(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
leaq 0x12d7e(%rip), %rsi     # 0x1dcd4
leaq 0x218c3(%rip), %rdx     # 0x2c820
leaq 0x12dfc(%rip), %rcx     # 0x1dd60
movq 0x10(%rsp), %r8
xorl %eax, %eax
callq 0x5200
movl 0x1c(%rsp), %ebp
jmp 0xad25
movq 0x1d078(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
leaq 0x12d45(%rip), %rsi     # 0x1dcd4
leaq 0x2188a(%rip), %rdx     # 0x2c820
leaq 0x12d86(%rip), %rcx     # 0x1dd23
jmp 0xafc3
movq 0x1d052(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
leaq 0x12d1f(%rip), %rsi     # 0x1dcd4
leaq 0x21864(%rip), %rdx     # 0x2c820
leaq 0x12d8c(%rip), %rcx     # 0x1dd4f
movq 0x10(%rsp), %r8
xorl %eax, %eax
callq 0x5200
movl 0x1c(%rsp), %ebp
jmp 0xad22
movq (%r14), %rdi
leaq 0x12d3a(%rip), %rsi     # 0x1dd1c
leaq 0x21937(%rip), %rdx     # 0x2c920
xorl %eax, %eax
callq 0x5200
jmp 0xaee9
movq 0x1cffc(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
xorl %ebx, %ebx
leaq 0x12cc7(%rip), %rsi     # 0x1dcd4
leaq 0x2180c(%rip), %rdx     # 0x2c820
leaq 0x12d19(%rip), %rcx     # 0x1dd34
movq 0x10(%rsp), %r8
xorl %eax, %eax
callq 0x5200
jmp 0xacae
movq 0x1cfc5(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
xorl %r12d, %r12d
leaq 0x12c8f(%rip), %rsi     # 0x1dcd4
leaq 0x217d4(%rip), %rdx     # 0x2c820
leaq 0x12d56(%rip), %rcx     # 0x1dda9
jmp 0xb0a5
movq 0x1cf9c(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
xorl %r12d, %r12d
leaq 0x12c66(%rip), %rsi     # 0x1dcd4
leaq 0x217ab(%rip), %rdx     # 0x2c820
leaq 0x12d3f(%rip), %rcx     # 0x1ddbb
jmp 0xb0a5
movq 0x1cf73(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
xorl %r12d, %r12d
leaq 0x12c3d(%rip), %rsi     # 0x1dcd4
leaq 0x21782(%rip), %rdx     # 0x2c820
leaq 0x12c8f(%rip), %rcx     # 0x1dd34
movq 0x10(%rsp), %r8
xorl %eax, %eax
callq 0x5200
jmp 0xab78
testl %r13d, %r13d
movq 0x1cf38(%rip), %rax     # 0x27ff8
jg 0xb0f4
decl 0x22748(%rip)           # 0x2d810
leaq 0x22501(%rip), %rax     # 0x2d5d0
movl 0x2c(%rsp), %ecx
movl %ecx, (%rax)
leaq 0x1dbaa(%rip), %rax     # 0x28c86
movb 0x1b(%rsp), %cl
movb %cl, (%rax)
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rax), %rdi
leaq 0x12cf0(%rip), %rsi     # 0x1ddee
leaq 0x2171b(%rip), %rdx     # 0x2c820
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x5200
jmp 0xb0c2
movq 0x1cede(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
leaq 0x12bab(%rip), %rsi     # 0x1dcd4
leaq 0x216f0(%rip), %rdx     # 0x2c820
leaq 0x12c3b(%rip), %rcx     # 0x1dd72
movq 0x10(%rsp), %r8
xorl %eax, %eax
callq 0x5200
pushq $0x1
popq %rdi
callq 0x52f0
movq 0x1cea6(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x12b78(%rip), %rsi     # 0x1dcd4
leaq 0x216bd(%rip), %rdx     # 0x2c820
leaq 0x12b86(%rip), %rcx     # 0x1dcf0
movq 0x10(%rsp), %r8
xorl %r9d, %r9d
jmp 0xb13c