// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: read_calendar(char*, int)
int read_calendar(char *s, int erase)
{
FILE *cal_file;
int i;
int nth, day, month;
char text[128+1];
int len;
char *buf;
int field;
int text_ptr;
int val;
int sign;
int skipping;
char c;

   // Replace default greetings with data from HEATHER.CAL
   cal_file = topen(s, "r");
   if(cal_file == 0) return 1;

   if(erase) clear_calendar();   // clear out the old calendar

   while(fgets(out, sizeof out, cal_file) != NULL) {
      if((out[0] == '*') || (out[0] == ';') || (out[0] == '/') || (out[0] == '#')) {
         if(!strnicmp(out, "#CLEAR", 6)) clear_calendar();
         continue;  // comment line
      }

      field = 0;
      text[0] = 0;
      text_ptr = 0;
      val = 0;
      skipping = 1;
      sign = (+1);

      len = strlen(out);
      for(i=0; i<len; i++) {
         c = out[i];
         if     (c == 0x00) break;
         else if(c == 0x0D) break;
         else if(c == 0x0A) break;
         else if(field < 4) {  // getting a number value
            if     (c == '-') { sign = (-1); skipping=0; }
            else if(c == '+') { sign = (+1);  skipping=0; }
            else if((c >= '0') && (c <= '9')) {
               val = (val*10) + (c-'0');
               skipping = 0;
            }
            else if((c == ' ') || (c == '\t') || (c == ',')) {
               if(skipping) continue;
               ++field;
               if     (field == 1) {
                  nth = val*sign;
               }
               else if(field == 2) day = val*sign;
               else if(field == 3) { month = val*sign; ++field; }
               skipping = 1;
               sign = 1;
               val = 0;
            }
            else {  // invalid char in a number, ignore the line
               break;
            }
         }
         else if(((c == ' ') || (c == '\t')) && skipping) {
            continue;
         }
         else {  // get the text string
            text[text_ptr++] = c;
            text[text_ptr] = 0;
            skipping = 0;
            field = 4;
         }
      }
      if(field != 4) continue;

      buf = (char *) calloc(len+1, 1);
      if(buf == 0) break;

      strcpy(buf, text);
      holiday[calendar_entries].nth = nth;
      holiday[calendar_entries].day = day;
      holiday[calendar_entries].month = month;
      holiday[calendar_entries].text = buf;

      if(++calendar_entries >= MAX_HOLIDAYS) break;
   }

   fclose(cal_file);

   calc_greetings();
   show_greetings();
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x58970(%rip), %rsi     # 0x18400d
callq 0x9b20
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x12b6b9
movl $0x1, -0x4(%rbp)
jmp 0x12badc
cmpl $0x0, -0x14(%rbp)
je 0x12b6c4
callq 0x138fa0
jmp 0x12b6c6
movq -0x20(%rbp), %rdx
leaq 0x26fd2f(%rip), %rdi    # 0x39b400
movl $0x201, %esi            # imm = 0x201
callq 0x95e0
cmpq $0x0, %rax
je 0x12bac2
leaq 0x26fd14(%rip), %rax    # 0x39b400
movsbl (%rax), %eax
cmpl $0x2a, %eax
je 0x12b721
leaq 0x26fd05(%rip), %rax    # 0x39b400
movsbl (%rax), %eax
cmpl $0x3b, %eax
je 0x12b721
leaq 0x26fcf6(%rip), %rax    # 0x39b400
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x12b721
leaq 0x26fce7(%rip), %rax    # 0x39b400
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x12b745
leaq 0x26fcd8(%rip), %rdi    # 0x39b400
leaq 0x6bff7(%rip), %rsi     # 0x197726
movl $0x6, %edx
callq 0x94a0
cmpl $0x0, %eax
jne 0x12b743
callq 0x138fa0
jmp 0x12b6c6
movl $0x0, -0xd4(%rbp)
movb $0x0, -0xc0(%rbp)
movl $0x0, -0xd8(%rbp)
movl $0x0, -0xdc(%rbp)
movl $0x1, -0xe4(%rbp)
movl $0x1, -0xe0(%rbp)
leaq 0x26fc7b(%rip), %rdi    # 0x39b400
callq 0x9120
movl %eax, -0xc4(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0xc4(%rbp), %eax
jge 0x12b9d6
movslq -0x24(%rbp), %rcx
leaq 0x26fc4f(%rip), %rax    # 0x39b400
movb (%rax,%rcx), %al
movb %al, -0xe5(%rbp)
movsbl -0xe5(%rbp), %eax
cmpl $0x0, %eax
jne 0x12b7cb
jmp 0x12b9d6
movsbl -0xe5(%rbp), %eax
cmpl $0xd, %eax
jne 0x12b7dc
jmp 0x12b9d6
movsbl -0xe5(%rbp), %eax
cmpl $0xa, %eax
jne 0x12b7ed
jmp 0x12b9d6
cmpl $0x4, -0xd4(%rbp)
jge 0x12b958
movsbl -0xe5(%rbp), %eax
cmpl $0x2d, %eax
jne 0x12b81f
movl $0xffffffff, -0xe0(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0xe4(%rbp)
jmp 0x12b956
movsbl -0xe5(%rbp), %eax
cmpl $0x2b, %eax
jne 0x12b844
movl $0x1, -0xe0(%rbp)
movl $0x0, -0xe4(%rbp)
jmp 0x12b954
movsbl -0xe5(%rbp), %eax
cmpl $0x30, %eax
jl 0x12b884
movsbl -0xe5(%rbp), %eax
cmpl $0x39, %eax
jg 0x12b884
imull $0xa, -0xdc(%rbp), %eax
movsbl -0xe5(%rbp), %ecx
subl $0x30, %ecx
addl %ecx, %eax
movl %eax, -0xdc(%rbp)
movl $0x0, -0xe4(%rbp)
jmp 0x12b952
movsbl -0xe5(%rbp), %eax
cmpl $0x20, %eax
je 0x12b8ac
movsbl -0xe5(%rbp), %eax
cmpl $0x9, %eax
je 0x12b8ac
movsbl -0xe5(%rbp), %eax
cmpl $0x2c, %eax
jne 0x12b94b
cmpl $0x0, -0xe4(%rbp)
je 0x12b8ba
jmp 0x12b9c8
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
cmpl $0x1, -0xd4(%rbp)
jne 0x12b8e4
movl -0xdc(%rbp), %eax
imull -0xe0(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x12b92b
cmpl $0x2, -0xd4(%rbp)
jne 0x12b8ff
movl -0xdc(%rbp), %eax
imull -0xe0(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x12b929
cmpl $0x3, -0xd4(%rbp)
jne 0x12b927
movl -0xdc(%rbp), %eax
imull -0xe0(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x12b929
jmp 0x12b92b
movl $0x1, -0xe4(%rbp)
movl $0x1, -0xe0(%rbp)
movl $0x0, -0xdc(%rbp)
jmp 0x12b950
jmp 0x12b9d6
jmp 0x12b952
jmp 0x12b954
jmp 0x12b956
jmp 0x12b9c0
movsbl -0xe5(%rbp), %eax
cmpl $0x20, %eax
je 0x12b970
movsbl -0xe5(%rbp), %eax
cmpl $0x9, %eax
jne 0x12b97b
cmpl $0x0, -0xe4(%rbp)
je 0x12b97b
jmp 0x12b9c8
movb -0xe5(%rbp), %cl
movl -0xd8(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0xd8(%rbp)
cltq
movb %cl, -0xc0(%rbp,%rax)
movslq -0xd8(%rbp), %rax
movb $0x0, -0xc0(%rbp,%rax)
movl $0x0, -0xe4(%rbp)
movl $0x4, -0xd4(%rbp)
jmp 0x12b9c0
jmp 0x12b9c2
jmp 0x12b9c4
jmp 0x12b9c6
jmp 0x12b9c8
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x12b797
cmpl $0x4, -0xd4(%rbp)
je 0x12b9e4
jmp 0x12b6c6
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x9230
movq %rax, -0xd0(%rbp)
cmpq $0x0, -0xd0(%rbp)
jne 0x12ba10
jmp 0x12bac2
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x9350
movl -0x28(%rbp), %ecx
leaq 0x14bfa3(%rip), %rax    # 0x2779d0
movslq (%rax), %rdx
leaq 0x9e429(%rip), %rax     # 0x1c9e60
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x2c(%rbp), %ecx
leaq 0x14bf86(%rip), %rax    # 0x2779d0
movslq (%rax), %rdx
leaq 0x9e40c(%rip), %rax     # 0x1c9e60
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl -0x30(%rbp), %ecx
leaq 0x14bf68(%rip), %rax    # 0x2779d0
movslq (%rax), %rdx
leaq 0x9e3ee(%rip), %rax     # 0x1c9e60
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0xd0(%rbp), %rcx
leaq 0x14bf46(%rip), %rax    # 0x2779d0
movslq (%rax), %rdx
leaq 0x9e3cc(%rip), %rax     # 0x1c9e60
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
leaq 0x14bf2a(%rip), %rax    # 0x2779d0
movl (%rax), %eax
addl $0x1, %eax
leaq 0x14bf1e(%rip), %rcx    # 0x2779d0
movl %eax, (%rcx)
cmpl $0x16e, %eax            # imm = 0x16E
jl 0x12babd
jmp 0x12bac2
jmp 0x12b6c6
movq -0x20(%rbp), %rdi
callq 0x9380
callq 0x139020
callq 0x138490
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax,%rax)