// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: open_log_file(char*)
FILE *open_log_file(char *mode)
{
u32 color;
int i;
char *s;

   if(log_file) return 0;  // log already open
   if(mode == 0) return 0;

   s = strchr(log_name, FLUSH_CHAR);
   if(s) {
      *s = 0;
      log_flush_mode = 1;
   }
   else log_flush_mode = 0;

   log_file = topen(log_name, mode);
   if(log_file == 0) return 0;
   if(debug_file) fprintf(debug_file, "! log file %s opened\n", log_name);

   if(log_header) log_written = 0;
   log_loaded = 0;
   show_log_state();
   log_file_time = (log_interval+1);

   if     (strstr(log_name, ".xml")) log_fmt = XML;
   else if(strstr(log_name, ".XML")) log_fmt = XML;
   else if(strstr(log_name, ".gpx")) log_fmt = GPX;
   else if(strstr(log_name, ".GPX")) log_fmt = GPX;
   else if(strstr(log_name, ".kml")) log_fmt = KML;
   else if(strstr(log_name, ".KML")) log_fmt = KML;
   else if(strstr(log_name, ".obs")) log_fmt = RINEX;
   else if(strstr(log_name, ".OBS")) log_fmt = RINEX;
   else log_fmt = HEATHER;

   if(log_fmt != HEATHER) {
      last_log_hours = hours;
      if(log_fmt == GPX) {
         fprintf(log_file, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\n");
         fprintf(log_file, "<gpx version=\"1.0\"  creator=\"Lady Heather V%s - %s\" >\n", VERSION, date_string);
         log_rcvr_type();
         start_log_track();
      }
      else if(log_fmt == KML) {
         fprintf(log_file, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
         fprintf(log_file, "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n");
         fprintf(log_file, "\n"); 
         fprintf(log_file, "  <Document>\n");
         fprintf(log_file, "  "); log_rcvr_type();
         fprintf(log_file, "    <visibility>1</visibility>\n"); 
         fprintf(log_file, "    <open>1</open>\n"); 
         fprintf(log_file, "\n"); 

         for(i=0; i<16; i++) {
            color = get_bgr_palette(i);
            color = (color & 0x00FF00) | ((color & 0xFF) << 16) | ((color & 0xFF0000) >> 16); 
            color |= 0x64000000;

            fprintf(log_file, "    <Style id=\"color%d\">\n", i);
            fprintf(log_file, "      <LineStyle>\n");
            fprintf(log_file, "        <color>%08X</color>\n", color);  // opacity(0..100) BB GG RR
            fprintf(log_file, "        <width>1</width>\n");
            fprintf(log_file, "      </LineStyle>\n");
            fprintf(log_file, "    </Style>\n");
            fprintf(log_file, "\n");
         }
         start_log_track();
      }
      else if(log_fmt == RINEX) {
      }
      else if(log_fmt == XML) {
         fprintf(log_file, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\n");
         fprintf(log_file, "<gpx version=\"1.1\"  creator=\"Lady Heather V%s - %s\" >\n", VERSION, date_string);
         log_rcvr_type();
         start_log_track();
      }
   }
   if(log_flush_mode && log_file) fflush(log_file);

   return log_file;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
leaq 0x19072d(%rip), %rax    # 0x29d540
cmpq $0x0, (%rax)
je 0x10ce26
movq $0x0, -0x8(%rbp)
jmp 0x10d387
cmpq $0x0, -0x10(%rbp)
jne 0x10ce3a
movq $0x0, -0x8(%rbp)
jmp 0x10d387
leaq 0x18f1ff(%rip), %rdi    # 0x29c040
movl $0x2a, %esi
callq 0x9100
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x10ce6c
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
leaq 0x19079c(%rip), %rax    # 0x29d600
movl $0x1, (%rax)
jmp 0x10ce79
leaq 0x19078d(%rip), %rax    # 0x29d600
movl $0x0, (%rax)
movq -0x10(%rbp), %rsi
leaq 0x18f1bc(%rip), %rdi    # 0x29c040
callq 0x9b20
movq %rax, %rcx
leaq 0x1906ad(%rip), %rax    # 0x29d540
movq %rcx, (%rax)
leaq 0x1906a3(%rip), %rax    # 0x29d540
cmpq $0x0, (%rax)
jne 0x10ceb0
movq $0x0, -0x8(%rbp)
jmp 0x10d387
leaq 0x1906b9(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x10cedc
leaq 0x1906ac(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x83150(%rip), %rsi     # 0x19001e
leaq 0x18f16b(%rip), %rdx    # 0x29c040
movb $0x0, %al
callq 0x9550
leaq 0x1906f5(%rip), %rax    # 0x29d5d8
cmpb $0x0, (%rax)
je 0x10cef2
leaq 0x1906db(%rip), %rax    # 0x29d5ca
movb $0x0, (%rax)
leaq 0x1906e1(%rip), %rax    # 0x29d5da
movb $0x0, (%rax)
callq 0x10ae40
leaq 0x16d680(%rip), %rax    # 0x27a588
movq (%rax), %rcx
addq $0x1, %rcx
leaq 0x1906ca(%rip), %rax    # 0x29d5e0
movq %rcx, (%rax)
leaq 0x18f120(%rip), %rdi    # 0x29c040
leaq 0x75b8e(%rip), %rsi     # 0x182ab5
callq 0x9090
cmpq $0x0, %rax
je 0x10cf44
leaq 0x1906ef(%rip), %rax    # 0x29d628
movl $0xa, (%rax)
jmp 0x10d083
leaq 0x18f0f5(%rip), %rdi    # 0x29c040
leaq 0x830e2(%rip), %rsi     # 0x190034
callq 0x9090
cmpq $0x0, %rax
je 0x10cf6f
leaq 0x1906c4(%rip), %rax    # 0x29d628
movl $0xa, (%rax)
jmp 0x10d081
leaq 0x18f0ca(%rip), %rdi    # 0x29c040
leaq 0x830bc(%rip), %rsi     # 0x190039
callq 0x9090
cmpq $0x0, %rax
je 0x10cf9a
leaq 0x190699(%rip), %rax    # 0x29d628
movl $0x14, (%rax)
jmp 0x10d07f
leaq 0x18f09f(%rip), %rdi    # 0x29c040
leaq 0x83096(%rip), %rsi     # 0x19003e
callq 0x9090
cmpq $0x0, %rax
je 0x10cfc5
leaq 0x19066e(%rip), %rax    # 0x29d628
movl $0x14, (%rax)
jmp 0x10d07d
leaq 0x18f074(%rip), %rdi    # 0x29c040
leaq 0x83070(%rip), %rsi     # 0x190043
callq 0x9090
cmpq $0x0, %rax
je 0x10cff0
leaq 0x190643(%rip), %rax    # 0x29d628
movl $0x1e, (%rax)
jmp 0x10d07b
leaq 0x18f049(%rip), %rdi    # 0x29c040
leaq 0x8304a(%rip), %rsi     # 0x190048
callq 0x9090
cmpq $0x0, %rax
je 0x10d018
leaq 0x190618(%rip), %rax    # 0x29d628
movl $0x1e, (%rax)
jmp 0x10d079
leaq 0x18f021(%rip), %rdi    # 0x29c040
leaq 0x83027(%rip), %rsi     # 0x19004d
callq 0x9090
cmpq $0x0, %rax
je 0x10d040
leaq 0x1905f0(%rip), %rax    # 0x29d628
movl $0x12e, (%rax)          # imm = 0x12E
jmp 0x10d077
leaq 0x18eff9(%rip), %rdi    # 0x29c040
leaq 0x83004(%rip), %rsi     # 0x190052
callq 0x9090
cmpq $0x0, %rax
je 0x10d068
leaq 0x1905c8(%rip), %rax    # 0x29d628
movl $0x12e, (%rax)          # imm = 0x12E
jmp 0x10d075
leaq 0x1905b9(%rip), %rax    # 0x29d628
movl $0x0, (%rax)
jmp 0x10d077
jmp 0x10d079
jmp 0x10d07b
jmp 0x10d07d
jmp 0x10d07f
jmp 0x10d081
jmp 0x10d083
leaq 0x19059e(%rip), %rax    # 0x29d628
cmpl $0x0, (%rax)
je 0x10d351
leaq 0x25f616(%rip), %rax    # 0x36c6b0
movl (%rax), %ecx
leaq 0x25f841(%rip), %rax    # 0x36c8e4
movl %ecx, (%rax)
leaq 0x19057c(%rip), %rax    # 0x29d628
cmpl $0x14, (%rax)
jne 0x10d0fe
leaq 0x190488(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82f95(%rip), %rsi     # 0x190057
movb $0x0, %al
callq 0x9550
leaq 0x190470(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82fa7(%rip), %rsi     # 0x190081
leaq 0x653c9(%rip), %rdx     # 0x1724aa
leaq 0x175648(%rip), %rcx    # 0x282730
movb $0x0, %al
callq 0x9550
callq 0x10c210
callq 0x10bde0
jmp 0x10d34f
leaq 0x190523(%rip), %rax    # 0x29d628
cmpl $0x1e, (%rax)
jne 0x10d2e4
leaq 0x19042b(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82f99(%rip), %rsi     # 0x1900b8
movb $0x0, %al
callq 0x9550
leaq 0x190413(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82faa(%rip), %rsi     # 0x1900e1
movb $0x0, %al
callq 0x9550
leaq 0x1903fb(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x8b4d7(%rip), %rsi     # 0x198626
movb $0x0, %al
callq 0x9550
leaq 0x1903e3(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82fa8(%rip), %rsi     # 0x19010f
movb $0x0, %al
callq 0x9550
leaq 0x1903cb(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x78c64(%rip), %rsi     # 0x185de3
movb $0x0, %al
callq 0x9550
callq 0x10c210
leaq 0x1903ae(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x8257d(%rip), %rsi     # 0x18f719
movb $0x0, %al
callq 0x9550
leaq 0x190396(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82f69(%rip), %rsi     # 0x19011d
movb $0x0, %al
callq 0x9550
leaq 0x19037e(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x8b45a(%rip), %rsi     # 0x198626
movb $0x0, %al
callq 0x9550
movl $0x0, -0x18(%rbp)
cmpl $0x10, -0x18(%rbp)
jge 0x10d2dd
movl -0x18(%rbp), %edi
callq 0x12290
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
movl -0x14(%rbp), %ecx
andl $0xff, %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl -0x14(%rbp), %ecx
andl $0xff0000, %ecx         # imm = 0xFF0000
shrl $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
orl $0x64000000, %eax       # imm = 0x64000000
movl %eax, -0x14(%rbp)
leaq 0x190318(%rip), %rax    # 0x29d540
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x82efc(%rip), %rsi     # 0x190131
movb $0x0, %al
callq 0x9550
leaq 0x1902fd(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82efe(%rip), %rsi     # 0x19014b
movb $0x0, %al
callq 0x9550
leaq 0x1902e5(%rip), %rax    # 0x29d540
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x82ef6(%rip), %rsi     # 0x19015e
movb $0x0, %al
callq 0x9550
leaq 0x1902ca(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82efb(%rip), %rsi     # 0x19017b
movb $0x0, %al
callq 0x9550
leaq 0x1902b2(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82efd(%rip), %rsi     # 0x190195
movb $0x0, %al
callq 0x9550
leaq 0x19029a(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82ef9(%rip), %rsi     # 0x1901a9
movb $0x0, %al
callq 0x9550
leaq 0x190282(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x8b35e(%rip), %rsi     # 0x198626
movb $0x0, %al
callq 0x9550
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x10d1da
callq 0x10bde0
jmp 0x10d34d
leaq 0x19033d(%rip), %rax    # 0x29d628
cmpl $0x12e, (%rax)          # imm = 0x12E
jne 0x10d2f5
jmp 0x10d34b
leaq 0x19032c(%rip), %rax    # 0x29d628
cmpl $0xa, (%rax)
jne 0x10d349
leaq 0x190238(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82d45(%rip), %rsi     # 0x190057
movb $0x0, %al
callq 0x9550
leaq 0x190220(%rip), %rax    # 0x29d540
movq (%rax), %rdi
leaq 0x82e8d(%rip), %rsi     # 0x1901b7
leaq 0x65179(%rip), %rdx     # 0x1724aa
leaq 0x1753f8(%rip), %rcx    # 0x282730
movb $0x0, %al
callq 0x9550
callq 0x10c210
callq 0x10bde0
jmp 0x10d34b
jmp 0x10d34d
jmp 0x10d34f
jmp 0x10d351
leaq 0x1902a8(%rip), %rax    # 0x29d600
cmpl $0x0, (%rax)
je 0x10d379
leaq 0x1901dc(%rip), %rax    # 0x29d540
cmpq $0x0, (%rax)
je 0x10d379
leaq 0x1901cf(%rip), %rax    # 0x29d540
movq (%rax), %rdi
callq 0x9430
leaq 0x1901c0(%rip), %rax    # 0x29d540
movq (%rax), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)