// File: /workspace/github_cpp_makefile_star2_O2/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:
xorl %eax, %eax
testq %rdi, %rdi
je 0xb290a
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x175bcd(%rip), %r15    # 0x228360
cmpq $0x0, (%r15)
jne 0xb28fc
movq %rdi, %rbx
leaq 0x1746b9(%rip), %rdi    # 0x226e60
pushq $0x2a
popq %rsi
callq 0x9100
testq %rax, %rax
je 0xb27bc
movb $0x0, (%rax)
pushq $0x1
popq %rax
jmp 0xb27be
xorl %eax, %eax
leaq 0x175c5b(%rip), %r12    # 0x228420
movl %eax, (%r12)
leaq 0x174690(%rip), %rdi    # 0x226e60
movq %rbx, %rsi
callq 0x9a22
movq %rax, (%r15)
testq %rax, %rax
je 0xb28fa
leaq 0x175ba5(%rip), %rax    # 0x228390
movq (%rax), %rdi
testq %rdi, %rdi
je 0xb2808
leaq 0x64c48(%rip), %rsi     # 0x117442
leaq 0x17465f(%rip), %rdx    # 0x226e60
xorl %eax, %eax
callq 0x9560
leaq 0x175be9(%rip), %rax    # 0x2283f8
cmpb $0x0, (%rax)
je 0xb281e
leaq 0x175bcf(%rip), %rax    # 0x2283ea
movb $0x0, (%rax)
leaq 0x175bd5(%rip), %rax    # 0x2283fa
movb $0x0, (%rax)
callq 0xb1018
leaq 0x152b74(%rip), %rax    # 0x2053a8
movq (%rax), %rax
incq %rax
leaq 0x175bbf(%rip), %rcx    # 0x228400
movq %rax, (%rcx)
leaq 0x174615(%rip), %rdi    # 0x226e60
leaq 0x558c3(%rip), %rsi     # 0x108115
callq 0x9090
testq %rax, %rax
jne 0xb2878
leaq 0x1745fd(%rip), %rdi    # 0x226e60
leaq 0x64bee(%rip), %rsi     # 0x117458
callq 0x9090
testq %rax, %rax
je 0xb290b
leaq 0x175bc9(%rip), %rax    # 0x228448
movl $0xa, (%rax)
leaq 0x244c44(%rip), %rax    # 0x2f74d0
movl (%rax), %eax
leaq 0x244e6f(%rip), %rcx    # 0x2f7704
movl %eax, (%rcx)
movq (%r15), %rcx
leaq 0x64bda(%rip), %rdi     # 0x11747b
pushq $0x29
popq %rsi
pushq $0x1
popq %rdx
callq 0x9750
movq (%r15), %rdi
leaq 0x64d25(%rip), %rsi     # 0x1175db
leaq 0x45310(%rip), %rdx     # 0xf7bcd
leaq 0x15ac8c(%rip), %rcx    # 0x20d550
xorl %eax, %eax
callq 0x9560
callq 0xb1cc3
callq 0xb1947
cmpl $0x0, (%r12)
setne %cl
movq (%r15), %rax
testq %rax, %rax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xb28fc
movq %rax, %rdi
callq 0x9420
movq (%r15), %rax
jmp 0xb28fc
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17454e(%rip), %rdi    # 0x226e60
leaq 0x64b44(%rip), %rsi     # 0x11745d
callq 0x9090
testq %rax, %rax
jne 0xb293b
leaq 0x174536(%rip), %rdi    # 0x226e60
leaq 0x64b31(%rip), %rsi     # 0x117462
callq 0x9090
testq %rax, %rax
je 0xb297e
leaq 0x175b06(%rip), %rax    # 0x228448
movl $0x14, (%rax)
leaq 0x244b81(%rip), %rax    # 0x2f74d0
movl (%rax), %eax
leaq 0x244dac(%rip), %rcx    # 0x2f7704
movl %eax, (%rcx)
movq (%r15), %rcx
leaq 0x64b17(%rip), %rdi     # 0x11747b
pushq $0x29
popq %rsi
pushq $0x1
popq %rdx
callq 0x9750
movq (%r15), %rdi
leaq 0x64b2c(%rip), %rsi     # 0x1174a5
jmp 0xb28b6
leaq 0x1744db(%rip), %rdi    # 0x226e60
leaq 0x64adb(%rip), %rsi     # 0x117467
callq 0x9090
testq %rax, %rax
jne 0xb29b2
leaq 0x1744c3(%rip), %rdi    # 0x226e60
leaq 0x64ac8(%rip), %rsi     # 0x11746c
callq 0x9090
testq %rax, %rax
je 0xb2b3b
leaq 0x175a8f(%rip), %rax    # 0x228448
movl $0x1e, (%rax)
leaq 0x244b0a(%rip), %rax    # 0x2f74d0
movl (%rax), %eax
leaq 0x244d35(%rip), %rcx    # 0x2f7704
movl %eax, (%rcx)
movq (%r15), %rcx
leaq 0x64b01(%rip), %rdi     # 0x1174dc
pushq $0x28
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x9750
movq (%r15), %rcx
leaq 0x64b12(%rip), %rdi     # 0x117505
pushq $0x2d
popq %rsi
movq %rbx, %rdx
callq 0x9750
movq (%r15), %rsi
pushq $0xa
popq %r14
movl %r14d, %edi
callq 0x9480
movq (%r15), %rcx
leaq 0x64b1c(%rip), %rdi     # 0x117533
pushq $0xd
popq %rsi
movq %rbx, %rdx
callq 0x9750
movq (%r15), %rcx
leaq 0x5a06f(%rip), %rdi     # 0x10ca9b
pushq $0x2
popq %rsi
movq %rbx, %rdx
callq 0x9750
callq 0xb1cc3
movq (%r15), %rcx
leaq 0x640f7(%rip), %rdi     # 0x116b3d
pushq $0x1f
popq %rsi
movq %rbx, %rdx
callq 0x9750
movq (%r15), %rcx
leaq 0x64ae6(%rip), %rdi     # 0x117541
pushq $0x13
popq %rsi
movq %rbx, %rdx
callq 0x9750
movq (%r15), %rsi
movl %r14d, %edi
callq 0x9480
xorl %r13d, %r13d
cmpl $0x10, %r13d
je 0xb28d0
movl %r13d, %edi
callq 0xee41
movl %eax, %ecx
andl $0xff00, %ecx           # imm = 0xFF00
movl %eax, %edx
movl $0xff, %esi
andl %esi, %edx
shll $0x10, %edx
orl %ecx, %edx
shrl $0x10, %eax
andl %esi, %eax
leal (%rax,%rdx), %r14d
addl $0x64000000, %r14d      # imm = 0x64000000
movq (%r15), %rdi
leaq 0x64a9f(%rip), %rsi     # 0x117555
movl %r13d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r15), %rcx
leaq 0x64aa5(%rip), %rdi     # 0x11756f
pushq $0x12
popq %rsi
movq %rbx, %rdx
callq 0x9750
movq (%r15), %rdi
leaq 0x64aa3(%rip), %rsi     # 0x117582
movl %r14d, %edx
xorl %eax, %eax
callq 0x9560
movq (%r15), %rcx
leaq 0x64aac(%rip), %rdi     # 0x11759f
pushq $0x19
popq %rsi
movq %rbx, %rdx
callq 0x9750
movq (%r15), %rcx
leaq 0x64ab1(%rip), %rdi     # 0x1175b9
pushq $0x13
popq %rsi
movq %rbx, %rdx
callq 0x9750
movq (%r15), %rcx
leaq 0x64ab0(%rip), %rdi     # 0x1175cd
pushq $0xd
popq %rsi
movq %rbx, %rdx
callq 0x9750
movq (%r15), %rsi
pushq $0xa
popq %rdi
callq 0x9480
incl %r13d
jmp 0xb2a74
leaq 0x17431e(%rip), %rdi    # 0x226e60
leaq 0x64928(%rip), %rsi     # 0x117471
callq 0x9090
testq %rax, %rax
jne 0xb2b6b
leaq 0x174306(%rip), %rdi    # 0x226e60
leaq 0x64915(%rip), %rsi     # 0x117476
callq 0x9090
testq %rax, %rax
je 0xb2b8f
leaq 0x1758d6(%rip), %rax    # 0x228448
movl $0x12e, (%rax)          # imm = 0x12E
leaq 0x244951(%rip), %rax    # 0x2f74d0
movl (%rax), %eax
leaq 0x244b7c(%rip), %rcx    # 0x2f7704
movl %eax, (%rcx)
jmp 0xb28d5
leaq 0x1758b2(%rip), %rax    # 0x228448
andl $0x0, (%rax)
jmp 0xb28d5