// File: /workspace/github_c_makefile_star2_O2/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), %rax
movq %rax, %rbx
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x5310
movl %eax, %ebp
cmpl $0x23, %eax
je 0xa7cf
cmpl $-0x1, %ebp
je 0xa86c
cmpl $0xa, %ebp
jne 0xa7d3
jmp 0xa833
pushq $0x1
popq %r14
movq %rbx, %r12
leaq 0x10(%rsp), %rax
subq %rax, %r12
sete %r13b
callq 0x5330
movq (%rax), %rax
movslq %ebp, %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0xa7f7
pushq $0x20
popq %rbp
cmpl $0x20, %ebp
sete %al
testl %r14d, %r14d
jne 0xa7b0
andb %al, %r13b
jne 0xa7b0
cmpl $0x5c, %ebp
jne 0xa855
movq %r15, %rdi
callq 0x5310
cmpl $0xa, %eax
je 0xa84c
movl %eax, %ebp
cmpl $0x23, %eax
je 0xa855
cmpl $-0x1, %ebp
je 0xa893
movl %ebp, %edi
movq %r15, %rsi
callq 0x5250
pushq $0x5c
jmp 0xa854
movq (%rsp), %rax
incl (%rax)
leaq 0x10(%rsp), %rcx
movq %rcx, %rax
cmpq %rcx, %rbx
je 0xa7aa
jmp 0xa87c
movq (%rsp), %rax
incl (%rax)
pushq $0x20
popq %rbp
cmpq $0x1fe, %r12            # imm = 0x1FE
jg 0xa893
movb %bpl, (%rbx)
incq %rbx
movq %rbx, %rax
jmp 0xa7aa
leaq 0x10(%rsp), %rax
cmpq %rax, %rbx
je 0xa893
movq (%rsp), %rax
incl (%rax)
movb $0x0, (%rbx)
leaq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0xa364
pushq $0x1
popq %rax
jmp 0xa895
xorl %eax, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq