// File: /workspace/github_c_makefile_star2_O3/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)
movl $0x0, 0xc(%rsp)
movq %rdi, 0x38(%rsp)
testq %rdi, %rdi
je 0xbf87
movl 0x22e4a(%rip), %eax     # 0x2e820
leal 0x1(%rax), %ecx
movl %ecx, 0x22e41(%rip)     # 0x2e820
cmpl $0xa, %eax
jge 0xbfce
leaq 0x22bf1(%rip), %rbx     # 0x2e5e0
movl (%rbx), %ebp
leaq 0x1e29e(%rip), %r14     # 0x29c96
movb (%r14), %r15b
movq $0x0, 0x40(%rsp)
leaq 0x21f25(%rip), %rsi     # 0x2d930
leaq 0xc(%rsp), %rdx
movq 0x38(%rsp), %rdi
callq 0xb61e
testl %eax, %eax
je 0xbf7c
movb %r15b, 0x1f(%rsp)
movl %ebp, 0x2c(%rsp)
leaq 0x220fe(%rip), %r13     # 0x2db30
leaq 0x21ef7(%rip), %r12     # 0x2d930
xorl %r15d, %r15d
movl $0x0, 0x8(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x21c7f(%rip), %rax     # 0x2d6dc
testb $0x20, (%rax)
jne 0xbcf0
movq %r13, %rdi
movq %r12, %rsi
callq 0xaf3b
movl %eax, %ebp
movq (%r13), %rbx
movq %rbx, %rdi
callq 0x5100
movb -0x1(%rbx,%rax), %r14b
movq %rbx, %rdi
callq 0xbfd8
cmpl $-0x1, %eax
je 0xbad9
cltq
leaq (%rax,%rax,2), %rax
leaq 0x1dd62(%rip), %rcx     # 0x29800
movq 0x10(%rcx,%rax,8), %rdx
movq %rdx, 0x20(%rsp)
movq (%rcx,%rax,8), %rdx
movq %rdx, 0x30(%rsp)
movl 0x8(%rcx,%rax,8), %ebx
cmpl $0x7, %ebx
jne 0xbade
movslq %r15d, %rax
cmpl $0x0, 0x40(%rsp,%rax,8)
jne 0xbacc
movq 0x8(%r13), %rdi
callq *0x20(%rsp)
xorl %eax, %eax
cmpl $0x3, %ebp
setge %al
jmp 0xbcc5
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %r13, %r12
movq (%r13), %rdi
testq %rdi, %rdi
je 0xbb1c
leaq 0x8(%r12), %r13
callq 0xc685
cmpl $-0x1, %eax
je 0xbb0f
cltq
leaq 0x2304e(%rip), %rcx     # 0x2eb50
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0xbb0f
movq %rax, -0x8(%r13)
movq (%r13), %rdi
addq $0x8, %r13
testq %rdi, %rdi
jne 0xbaef
incl %ebx
cmpl $0x8, %ebx
ja 0xbcb7
leaq 0x14136(%rip), %rcx     # 0x1fc64
movslq (%rcx,%rbx,4), %rax
addq %rcx, %rax
movq %r12, %r13
jmpq *%rax
cmpl $0x14, %r15d
jge 0xbfbf
movslq %r15d, %rcx
movl $0x2, %eax
cmpl $0x0, 0x40(%rsp,%rcx,8)
leaq 0x21dd8(%rip), %r12     # 0x2d930
jne 0xbb7f
leaq 0x8(%r13), %rsi
movq %r12, %rdi
callq 0xb09a
movq %r12, %rdi
callq *0x20(%rsp)
movl %eax, %ebp
cmpl $-0x1, %eax
je 0xbe96
xorl %eax, %eax
testl %ebp, %ebp
sete %al
incl %r15d
movslq %r15d, %rcx
movl %eax, 0x40(%rsp,%rcx,8)
movl $0x1, 0x44(%rsp,%rcx,8)
jmp 0xbcc9
testl %r15d, %r15d
jle 0xbe15
decl %r15d
xorl %eax, %eax
cmpl $0x2, %ebp
jmp 0xbc9f
movslq %r15d, %rax
cmpl $0x0, 0x40(%rsp,%rax,8)
jne 0xbbdd
leaq 0xf0(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xb74b
movq 0x8(%r13), %rsi
xorl %edx, %edx
cmpb $0x3f, %r14b
sete %dl
movq %rax, %rdi
callq 0xc0c1
xorl %eax, %eax
cmpl $0x3, %ebp
jmp 0xbc9f
movslq %r15d, %rbx
cmpl $0x0, 0x44(%rsp,%rbx,8)
je 0xbe3b
movl 0x40(%rsp,%rbx,8), %eax
cmpl $0x1, %eax
leaq 0x21d2d(%rip), %r12     # 0x2d930
je 0xbdbc
movl $0x0, 0x8(%rsp)
testl %eax, %eax
jne 0xbcd1
movl $0x2, 0x40(%rsp,%rbx,8)
jmp 0xbcd1
movslq %r15d, %rax
cmpl $0x0, 0x44(%rsp,%rax,8)
je 0xbe61
movl 0x40(%rsp,%rax,8), %ecx
testl %ecx, %ecx
leaq 0x21cef(%rip), %r12     # 0x2d930
je 0xbdf1
cmpl $0x1, %ecx
jne 0xbdfa
xorl %ecx, %ecx
jmp 0xbdf6
movslq %r15d, %rax
movl $0x0, 0x8(%rsp)
cmpl $0x0, 0x40(%rsp,%rax,8)
je 0xbd5f
leaq 0x21cbc(%rip), %r12     # 0x2d930
jmp 0xbcd1
movslq %r15d, %rax
cmpl $0x0, 0x40(%rsp,%rax,8)
jne 0xbc88
movq 0x8(%r13), %rdi
callq *0x20(%rsp)
cmpl $0x3, %ebp
jne 0xbc9a
movq 0x8(%r13), %rdi
movq 0x10(%r13), %rsi
callq 0xc052
xorl %eax, %eax
cmpl $0x4, %ebp
setge %al
leaq 0x21c87(%rip), %r12     # 0x2d930
jmp 0xbcc5
leaq 0x21c7e(%rip), %r12     # 0x2d930
jmp 0xbaba
movq %r12, %r13
leaq 0x21c6f(%rip), %r12     # 0x2d930
movl 0x8(%rsp), %eax
testl %eax, %eax
jne 0xbd0c
movl $0x0, 0x8(%rsp)
movq 0x38(%rsp), %rdi
movq %r12, %rsi
leaq 0xc(%rsp), %rdx
callq 0xb61e
testl %eax, %eax
jne 0xba56
jmp 0xbf60
leaq 0xc(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %r15d, %edx
leaq 0x40(%rsp), %rcx
callq 0x53fa
jmp 0xba66
movl %eax, 0x8(%rsp)
leaq 0x1c0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x140ff(%rip), %rsi     # 0x1fe21
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x52f0
movq 0x1d2bb(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
leaq 0x13fe0(%rip), %rsi     # 0x1fd24
leaq 0x21ae5(%rip), %rdx     # 0x2d830
movq %rbx, %rcx
movq 0x10(%rsp), %r8
xorl %eax, %eax
callq 0x5210
jmp 0xbcd1
movq %r13, %rdi
movq 0x10(%rsp), %rsi
callq 0xc2b9
cmpl $0x3, %eax
leaq 0x21bba(%rip), %r12     # 0x2d930
je 0xbefe
cmpl $0x2, %eax
je 0xbecd
cmpl $0x1, %eax
jne 0xbcd1
movq 0x1d25b(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
movl $0x0, 0x8(%rsp)
leaq 0x13f78(%rip), %rsi     # 0x1fd24
leaq 0x21a7d(%rip), %rdx     # 0x2d830
leaq 0x14032(%rip), %rcx     # 0x1fdec
jmp 0xbd4e
movl $0x0, 0x8(%rsp)
leaq 0x8(%r13), %rsi
movq %r12, %rdi
callq 0xb09a
movq %r12, %rdi
callq *0x20(%rsp)
testl %eax, %eax
je 0xbe0c
cmpl $-0x1, %eax
je 0xbf2f
movl $0x0, 0x40(%rsp,%rbx,8)
jmp 0xbcd1
movl $0x2, %ecx
movl %ecx, 0x40(%rsp,%rax,8)
movl $0x0, 0x44(%rsp,%rax,8)
xorl %eax, %eax
cmpl $0x2, %ebp
jmp 0xbad1
movl %eax, 0x8(%rsp)
jmp 0xbcd1
movq 0x1d1d4(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
leaq 0x13ef9(%rip), %rsi     # 0x1fd24
leaq 0x219fe(%rip), %rdx     # 0x2d830
leaq 0x13f77(%rip), %rcx     # 0x1fdb0
jmp 0xbe85
movq 0x1d1ae(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
leaq 0x13ed3(%rip), %rsi     # 0x1fd24
leaq 0x219d8(%rip), %rdx     # 0x2d830
leaq 0x13f14(%rip), %rcx     # 0x1fd73
jmp 0xbe85
movq 0x1d188(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
leaq 0x13ead(%rip), %rsi     # 0x1fd24
leaq 0x219b2(%rip), %rdx     # 0x2d830
leaq 0x13f1a(%rip), %rcx     # 0x1fd9f
movq 0x10(%rsp), %r8
xorl %eax, %eax
callq 0x5210
jmp 0xbcba
movq 0x1d153(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
xorl %ebp, %ebp
leaq 0x13e76(%rip), %rsi     # 0x1fd24
leaq 0x2197b(%rip), %rdx     # 0x2d830
leaq 0x13ec8(%rip), %rcx     # 0x1fd84
movq 0x10(%rsp), %r8
xorl %eax, %eax
callq 0x5210
jmp 0xbb78
movq 0x1d11c(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
movl $0x0, 0x8(%rsp)
leaq 0x13e39(%rip), %rsi     # 0x1fd24
leaq 0x2193e(%rip), %rdx     # 0x2d830
leaq 0x13f00(%rip), %rcx     # 0x1fdf9
jmp 0xbd4e
movq 0x1d0eb(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
movl $0x0, 0x8(%rsp)
leaq 0x13e08(%rip), %rsi     # 0x1fd24
leaq 0x2190d(%rip), %rdx     # 0x2d830
leaq 0x13ee1(%rip), %rcx     # 0x1fe0b
jmp 0xbd4e
movq 0x1d0ba(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
movl 0xc(%rsp), %r9d
movl $0x0, 0x8(%rsp)
leaq 0x13dd7(%rip), %rsi     # 0x1fd24
leaq 0x218dc(%rip), %rdx     # 0x2d830
leaq 0x13e29(%rip), %rcx     # 0x1fd84
jmp 0xbd4e
testl %r15d, %r15d
leaq 0x22676(%rip), %rbx     # 0x2e5e0
movl 0x2c(%rsp), %ebp
leaq 0x1dd21(%rip), %r14     # 0x29c96
movb 0x1f(%rsp), %r15b
jg 0xbf99
decl 0x2289e(%rip)           # 0x2e820
movl %ebp, (%rbx)
movb %r15b, (%r14)
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1d050(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
leaq 0x13e94(%rip), %rsi     # 0x1fe3e
leaq 0x2187f(%rip), %rdx     # 0x2d830
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x5210
jmp 0xbf7c
leaq 0xc(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x5456
movq 0x10(%rsp), %rdi
callq 0x548e