// File: /workspace/github_c_makefile_star2_O1/mmayer[P]pcal/src/pcalutil.c
// Function: get_pcal_line
int get_pcal_line (FILE *fp, char *buf, int *pline)
{
   register char *cp;
   register int c, c2;
   int in_comment;   /* comments: from '#' to end-of-line */
   char tmpbuf[LINSIZ];   /* temporary buffer to accumulate line */

   cp = tmpbuf;
   *buf = '\0';   /* in case of premature EOF */
   
   do {
      in_comment = FALSE;
      while ((c = getc(fp)) != '\n' && c != EOF) {
         if (c == COMMENT_CHAR) in_comment = TRUE;
         
         if (isspace(c)) c = ' ';   /* whitespace => blank */
         
         /* ignore comments and leading white space */
         if (in_comment || (cp == tmpbuf && c == ' ')) continue;
         
         /* only handle escape newlines and '#' here; other escapes are now
            handled by cvt_escape() or loadwords() (q.v.)
         */
         if (c == '\\') {
            if ((c2 = getc(fp)) == EOF) return FALSE;

            if (c2 == '\n') {
               c = ' ';
               (*pline)++;
            }
            else if (c2 == COMMENT_CHAR) c = '#';
            else ungetc(c2, fp);
         }
         
         /* 
            Crudely prevent buffer overflow to prevent exploit by malicious
            calendar input file.
         */
         if ((cp - tmpbuf) < (LINSIZ - 1)) *cp++ = c;
         else return FALSE;
      }

      if (c == EOF) {
         /* 
            15 Dec 2007: 

            Prior to the 4.11.0 release, the code just returned 'FALSE' here,
            with no other test being performed.

            That was causing a bug whereby the last line of a configuration
            file was silently ignored if it ended without a 'line feed' (ASCII
            10 character).

            Adding a test, as done below, to see if anything is in the line
            buffer (before deciding to return 'FALSE') fixes this bug.

         */
         if ((cp - tmpbuf) == 0) return FALSE;    /* no more input lines */
      }

      (*pline)++;   /* bump line number */
      
   } while (cp == tmpbuf);   /* ignore empty lines */

   *cp = '\0';
   cvt_escape(buf, tmpbuf);   /* convert escape sequences */
   return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdx, (%rsp)
movq %rdi, %r15
movq %rsi, 0x8(%rsp)
movb $0x0, (%rsi)
leaq 0x10(%rsp), %r13
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x5320
movl %eax, %ebp
cmpl $0x23, %eax
je 0xb107
cmpl $-0x1, %ebp
je 0xb170
cmpl $0xa, %ebp
jne 0xb10d
jmp 0xb17a
movl $0x1, %r14d
movq %r13, %r12
leaq 0x10(%rsp), %rax
subq %rax, %r12
sete %bl
callq 0x5340
movq (%rax), %rax
movslq %ebp, %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0xb132
movl $0x20, %ebp
cmpl $0x20, %ebp
sete %al
testl %r14d, %r14d
jne 0xb0ec
andb %al, %bl
jne 0xb0ec
cmpl $0x5c, %ebp
jne 0xb19b
movq %r15, %rdi
callq 0x5320
cmpl $0xa, %eax
je 0xb190
movl %eax, %ebp
cmpl $0x23, %eax
je 0xb19b
cmpl $-0x1, %ebp
je 0xb1b0
movl %ebp, %edi
movq %r15, %rsi
callq 0x5260
movl $0x5c, %ebp
jmp 0xb19b
leaq 0x10(%rsp), %rax
cmpq %rax, %r13
je 0xb1b0
movq (%rsp), %rax
incl (%rax)
leaq 0x10(%rsp), %rax
cmpq %rax, %r13
je 0xb0e9
jmp 0xb1b4
movq (%rsp), %rax
incl (%rax)
movl $0x20, %ebp
cmpq $0x1fe, %r12            # imm = 0x1FE
jg 0xb1b0
movb %bpl, (%r13)
incq %r13
jmp 0xb0e9
xorl %eax, %eax
jmp 0xb1cd
movb $0x0, (%r13)
leaq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0xabff
movl $0x1, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq