// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: dump_log(char*, unsigned char)
void dump_log(char *name, u08 dump_size)
{
FILE *file;
FILE *lock_file;
char temp_name[128];
long temp_interval;
u08 temp_flags;
u08 temp_pause;
u08 temp_info;
u08 temp_written;
FILE *temp_file;
int temp_fmt;
long i;
long counter;
long val;
int row;
char *s;
char filter[32];

   if(queue_interval <= 0) return;

   doing_log_dump = 1;
   lock_file = topen(lock_name, "w");  // create file tblock to signify dump file is being written
   if(lock_file) {
      fprintf(lock_file, "2");
      fclose(lock_file);
   }

   row = PLOT_TEXT_ROW+4;
   if(dump_size == 'p') s = "plot area";
   else                 s = "queue";

   filter[0] = 0;
   if(filter_log && filter_count) sprintf(filter, "%ld point filtered ", disp_filter_size()); 

   temp_interval = log_interval;
   temp_flags = time_flags;
   temp_pause = pause_data;
   temp_info = have_info;
   temp_written = log_written;
   temp_fmt = log_fmt;
   temp_file = log_file;

   log_written = 0;
   strcpy(temp_name, log_name);

   log_interval = queue_interval;
   strcpy(log_name, name);
   if(!strstr(log_name, ".")) strcat(log_name, ".log");

   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;  // cannot write RINEX file from queue data
//   else if(strstr(log_name, ".OBS")) log_fmt = RINEX;
   else log_fmt = HEATHER;

   erase_help();
   if(log_fmt != HEATHER) {
      log_file = 0;
      file = open_log_file(log_mode);
   }
   else {
      file = topen(log_name, log_mode);
   }

   if(file == 0) {
      sprintf(out, "Cannot dump log file: %s", log_name);
      edit_error(out);
      goto dump_exit;
   }

   log_file = file;
write_log_header(file, 2);
   if(log_comments) {
      sprintf(log_text, "#TITLE: From log file %s (%s%s data)", log_name, filter, s);
      write_log_comment(1);

      if((luxor == 0) && have_gain) {
         sprintf(log_text, "#OSC_GAIN %f", osc_gain);
         write_log_comment(1);
      }
   }

if(log_fmt != HEATHER) {
   log_file = 0;
}

   if(log_mode[0] == 'a') sprintf(out, "Appending %s%s data to file: %s", filter, s, log_name);
   else                   sprintf(out, "Writing %s%s data to file: %s", filter, s, log_name);
   vidstr(row, PLOT_TEXT_COL, PROMPT_COLOR, out);

   pause_data = 1;
   counter = 0;
   if(dump_size == 'p') {
      i = plot_q_col0;  // dumping the plot area's data
   }
   else {
      i = plot_q_out;   // dumping the full queue
//plot_q_col0 = plot_q_out;

   }
   while((i != plot_q_in) || (dump_size == 'p')) {
      write_q_entry(file, i);
      have_info |= INFO_LOGGED;
      update_pwm();   // if doing pwm temperature control

      ++counter;
      if((counter % LOG_GPS_CHECK) == 0) {   // keep serial data from overruning
         get_pending_gps(10);  //!!!! possible recursion
      }
//    if((counter % 1000L) == 1L) {
      if((counter % LOG_SCREEN_RFSH) == 1L) {
         sprintf(out, "Line %ld", counter-1L);
         vidstr(row+2, PLOT_TEXT_COL, PROMPT_COLOR, out);
         refresh_page();
      }

      if(dump_size == 'p') {
         val = view_interval * (long) PLOT_WIDTH;
         val /= (long) plot_mag;
         if(counter >= val) break;
         if(counter >= (plot_q_count-1)) break;
      }
      if(++i >= plot_q_size) i = 0;
   }

   #ifdef SCI_LOG
      if(sci_file) fclose(sci_file);
      sci_file = 0;
   #endif

   log_file = file;
   #ifdef ADEV_STUFF
      log_adevs();
   #endif

   log_stats();

   if(log_fmt != HEATHER) {
      close_log_file();
   }
   else {
      fclose(file);      // close this log and restore original one
   }

   dump_exit:
   log_interval = temp_interval;
   log_written = temp_written;
   time_flags = temp_flags;
   pause_data = temp_pause;
   have_info = temp_info;
have_info |= INFO_LOGGED;
   log_fmt = temp_fmt;
   log_file = temp_file;
   strcpy(log_name, temp_name);
   show_log_state();

   doing_log_dump = 0;
   path_unlink(lock_name);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
leaq 0x15be7c(%rip), %rax    # 0x27a578
cmpq $0x0, (%rax)
jg 0x11e707
jmp 0x11ee50
leaq 0x17eeda(%rip), %rax    # 0x29d5e8
movl $0x1, (%rax)
leaq 0x24eb85(%rip), %rdi    # 0x36d2a0
leaq 0x65f29(%rip), %rsi     # 0x18464b
callq 0x9b20
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x11e74d
movq -0x20(%rbp), %rdi
leaq 0x5afe8(%rip), %rsi     # 0x179725
movb $0x0, %al
callq 0x9550
movq -0x20(%rbp), %rdi
callq 0x9380
leaq 0x15931c(%rip), %rax    # 0x277a70
movl (%rax), %eax
addl $0x4, %eax
movl %eax, -0xdc(%rbp)
movzbl -0x9(%rbp), %eax
cmpl $0x70, %eax
jne 0x11e778
leaq 0x6110c(%rip), %rax     # 0x17f87b
movq %rax, -0xe8(%rbp)
jmp 0x11e786
leaq 0x54e25(%rip), %rax     # 0x1735a4
movq %rax, -0xe8(%rbp)
movb $0x0, -0x110(%rbp)
leaq 0x15bec8(%rip), %rax    # 0x27a65c
cmpb $0x0, (%rax)
je 0x11e7d1
leaq 0x15beb0(%rip), %rax    # 0x27a650
cmpq $0x0, (%rax)
je 0x11e7d1
leaq -0x110(%rbp), %rax
movq %rax, -0x118(%rbp)
callq 0x15430
movq -0x118(%rbp), %rdi
movq %rax, %rdx
leaq 0x762db(%rip), %rsi     # 0x194aa5
movb $0x0, %al
callq 0x9060
leaq 0x15bdb0(%rip), %rax    # 0x27a588
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
leaq 0x24de9b(%rip), %rax    # 0x36c684
movl (%rax), %eax
movb %al, -0xa9(%rbp)
leaq 0x15bc1c(%rip), %rax    # 0x27a414
movb (%rax), %al
movb %al, -0xaa(%rbp)
leaq 0x24e34d(%rip), %rax    # 0x36cb54
movl (%rax), %eax
movb %al, -0xab(%rbp)
leaq 0x17edb4(%rip), %rax    # 0x29d5ca
movb (%rax), %al
movb %al, -0xac(%rbp)
leaq 0x17ee03(%rip), %rax    # 0x29d628
movl (%rax), %eax
movl %eax, -0xbc(%rbp)
leaq 0x17ed0c(%rip), %rax    # 0x29d540
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
leaq 0x17ed85(%rip), %rax    # 0x29d5ca
movb $0x0, (%rax)
leaq -0xa0(%rbp), %rdi
leaq 0x17d7ea(%rip), %rsi    # 0x29c040
callq 0x9350
leaq 0x15bd16(%rip), %rax    # 0x27a578
movq (%rax), %rcx
leaq 0x15bd1c(%rip), %rax    # 0x27a588
movq %rcx, (%rax)
movq -0x8(%rbp), %rsi
leaq 0x17d7c6(%rip), %rdi    # 0x29c040
callq 0x9350
leaq 0x17d7ba(%rip), %rdi    # 0x29c040
leaq 0x7753b(%rip), %rsi     # 0x195dc8
callq 0x9090
cmpq $0x0, %rax
jne 0x11e8ab
leaq 0x17d7a1(%rip), %rdi    # 0x29c040
leaq 0x524dd(%rip), %rsi     # 0x170d83
callq 0x96a0
leaq 0x17d78e(%rip), %rdi    # 0x29c040
leaq 0x641fc(%rip), %rsi     # 0x182ab5
callq 0x9090
cmpq $0x0, %rax
je 0x11e8d6
leaq 0x17ed5d(%rip), %rax    # 0x29d628
movl $0xa, (%rax)
jmp 0x11e9bb
leaq 0x17d763(%rip), %rdi    # 0x29c040
leaq 0x71750(%rip), %rsi     # 0x190034
callq 0x9090
cmpq $0x0, %rax
je 0x11e901
leaq 0x17ed32(%rip), %rax    # 0x29d628
movl $0xa, (%rax)
jmp 0x11e9b9
leaq 0x17d738(%rip), %rdi    # 0x29c040
leaq 0x7172a(%rip), %rsi     # 0x190039
callq 0x9090
cmpq $0x0, %rax
je 0x11e92c
leaq 0x17ed07(%rip), %rax    # 0x29d628
movl $0x14, (%rax)
jmp 0x11e9b7
leaq 0x17d70d(%rip), %rdi    # 0x29c040
leaq 0x71704(%rip), %rsi     # 0x19003e
callq 0x9090
cmpq $0x0, %rax
je 0x11e954
leaq 0x17ecdc(%rip), %rax    # 0x29d628
movl $0x14, (%rax)
jmp 0x11e9b5
leaq 0x17d6e5(%rip), %rdi    # 0x29c040
leaq 0x716e1(%rip), %rsi     # 0x190043
callq 0x9090
cmpq $0x0, %rax
je 0x11e97c
leaq 0x17ecb4(%rip), %rax    # 0x29d628
movl $0x1e, (%rax)
jmp 0x11e9b3
leaq 0x17d6bd(%rip), %rdi    # 0x29c040
leaq 0x716be(%rip), %rsi     # 0x190048
callq 0x9090
cmpq $0x0, %rax
je 0x11e9a4
leaq 0x17ec8c(%rip), %rax    # 0x29d628
movl $0x1e, (%rax)
jmp 0x11e9b1
leaq 0x17ec7d(%rip), %rax    # 0x29d628
movl $0x0, (%rax)
jmp 0x11e9b3
jmp 0x11e9b5
jmp 0x11e9b7
jmp 0x11e9b9
jmp 0x11e9bb
callq 0x117a0
leaq 0x17ec61(%rip), %rax    # 0x29d628
cmpl $0x0, (%rax)
je 0x11e9ef
leaq 0x17eb6d(%rip), %rax    # 0x29d540
movq $0x0, (%rax)
leaq 0x17eb57(%rip), %rax    # 0x29d538
movq (%rax), %rdi
callq 0x10ce00
movq %rax, -0x18(%rbp)
jmp 0x11ea09
leaq 0x17eb42(%rip), %rax    # 0x29d538
movq (%rax), %rsi
leaq 0x17d640(%rip), %rdi    # 0x29c040
callq 0x9b20
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x11ea3d
leaq 0x27c9e9(%rip), %rdi    # 0x39b400
leaq 0x7609b(%rip), %rsi     # 0x194ab9
leaq 0x17d61b(%rip), %rdx    # 0x29c040
movb $0x0, %al
callq 0x9060
leaq 0x27c9cd(%rip), %rdi    # 0x39b400
callq 0x30d60
jmp 0x11ed98
movq -0x18(%rbp), %rcx
leaq 0x17eaf8(%rip), %rax    # 0x29d540
movq %rcx, (%rax)
movq -0x18(%rbp), %rdi
movl $0x2, %esi
callq 0x110390
leaq 0x17eb94(%rip), %rax    # 0x29d5f4
cmpb $0x0, (%rax)
je 0x11eae0
leaq -0x110(%rbp), %rcx
movq -0xe8(%rbp), %r8
leaq 0x17e0c6(%rip), %rdi    # 0x29cb40
leaq 0x76051(%rip), %rsi     # 0x194ad2
leaq 0x17d5b8(%rip), %rdx    # 0x29c040
movb $0x0, %al
callq 0x9060
movl $0x1, %edi
callq 0x10cbe0
leaq 0x17f67e(%rip), %rax    # 0x29e11e
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x11eade
leaq 0x24da29(%rip), %rax    # 0x36c4d8
cmpl $0x0, (%rax)
je 0x11eade
leaq 0x24d82d(%rip), %rax    # 0x36c2e8
movsd (%rax), %xmm0
leaq 0x17e07a(%rip), %rdi    # 0x29cb40
leaq 0x7602a(%rip), %rsi     # 0x194af7
movb $0x1, %al
callq 0x9060
movl $0x1, %edi
callq 0x10cbe0
jmp 0x11eae0
leaq 0x17eb41(%rip), %rax    # 0x29d628
cmpl $0x0, (%rax)
je 0x11eafa
leaq 0x17ea4d(%rip), %rax    # 0x29d540
movq $0x0, (%rax)
leaq 0x17ea37(%rip), %rax    # 0x29d538
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x61, %eax
jne 0x11eb38
leaq -0x110(%rbp), %rdx
movq -0xe8(%rbp), %rcx
leaq 0x27c8df(%rip), %rdi    # 0x39b400
leaq 0x75fdc(%rip), %rsi     # 0x194b04
leaq 0x17d511(%rip), %r8     # 0x29c040
movb $0x0, %al
callq 0x9060
jmp 0x11eb62
leaq -0x110(%rbp), %rdx
movq -0xe8(%rbp), %rcx
leaq 0x27c8b3(%rip), %rdi    # 0x39b400
leaq 0x75fd0(%rip), %rsi     # 0x194b24
leaq 0x17d4e5(%rip), %r8     # 0x29c040
movb $0x0, %al
callq 0x9060
movl -0xdc(%rbp), %edi
leaq 0x158efd(%rip), %rax    # 0x277a6c
movl (%rax), %esi
movl $0xb, %edx
leaq 0x27c883(%rip), %rcx    # 0x39b400
callq 0x10ee0
leaq 0x15b88b(%rip), %rax    # 0x27a414
movb $0x1, (%rax)
movq $0x0, -0xd0(%rbp)
movzbl -0x9(%rbp), %eax
cmpl $0x70, %eax
jne 0x11ebb3
leaq 0x15b8a1(%rip), %rax    # 0x27a448
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
jmp 0x11ebc4
leaq 0x15b956(%rip), %rax    # 0x27a510
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
jmp 0x11ebc6
movq -0xc8(%rbp), %rcx
movb $0x1, %al
leaq 0x15b932(%rip), %rdx    # 0x27a508
cmpq (%rdx), %rcx
movb %al, -0x119(%rbp)
jne 0x11ebf1
movzbl -0x9(%rbp), %eax
cmpl $0x70, %eax
sete %al
movb %al, -0x119(%rbp)
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x11ec00
jmp 0x11ed62
movq -0x18(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x11b7e0
leaq 0x24df3d(%rip), %rax    # 0x36cb54
movl (%rax), %ecx
orl $0x200, %ecx            # imm = 0x200
leaq 0x24df2e(%rip), %rax    # 0x36cb54
movl %ecx, (%rax)
callq 0x11ee60
movq -0xd0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movl $0x1388, %ecx           # imm = 0x1388
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x11ec60
movl $0xa, %edi
callq 0x29240
movq -0xd0(%rbp), %rax
movl $0x2710, %ecx           # imm = 0x2710
cqto
idivq %rcx
cmpq $0x1, %rdx
jne 0x11ecbf
movq -0xd0(%rbp), %rdx
subq $0x1, %rdx
leaq 0x27c777(%rip), %rdi    # 0x39b400
leaq 0x75eb2(%rip), %rsi     # 0x194b42
movb $0x0, %al
callq 0x9060
movl -0xdc(%rbp), %edi
addl $0x2, %edi
leaq 0x158dc5(%rip), %rax    # 0x277a6c
movl (%rax), %esi
movl $0xb, %edx
leaq 0x27c74b(%rip), %rcx    # 0x39b400
callq 0x10ee0
callq 0xb0d0
movzbl -0x9(%rbp), %eax
cmpl $0x70, %eax
jne 0x11ed34
leaq 0x15b8b1(%rip), %rax    # 0x27a580
movq (%rax), %rax
leaq 0x158d8b(%rip), %rcx    # 0x277a64
movslq (%rcx), %rcx
imulq %rcx, %rax
movq %rax, -0xd8(%rbp)
leaq 0x15b8c2(%rip), %rax    # 0x27a5b0
movslq (%rax), %rcx
movq -0xd8(%rbp), %rax
cqto
idivq %rcx
movq %rax, -0xd8(%rbp)
movq -0xd0(%rbp), %rax
cmpq -0xd8(%rbp), %rax
jl 0x11ed16
jmp 0x11ed62
movq -0xd0(%rbp), %rax
leaq 0x15b7f4(%rip), %rcx    # 0x27a518
movq (%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jl 0x11ed32
jmp 0x11ed62
jmp 0x11ed34
movq -0xc8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc8(%rbp)
leaq 0x15b7b3(%rip), %rcx    # 0x27a500
cmpq (%rcx), %rax
jl 0x11ed5d
movq $0x0, -0xc8(%rbp)
jmp 0x11ebc6
movq -0x18(%rbp), %rcx
leaq 0x17e7d3(%rip), %rax    # 0x29d540
movq %rcx, (%rax)
callq 0x11f0a0
callq 0x11e0b0
leaq 0x17e8a7(%rip), %rax    # 0x29d628
cmpl $0x0, (%rax)
je 0x11ed8d
callq 0x10d3a0
jmp 0x11ed96
movq -0x18(%rbp), %rdi
callq 0x9380
jmp 0x11ed98
movq -0xa8(%rbp), %rcx
leaq 0x15b7e2(%rip), %rax    # 0x27a588
movq %rcx, (%rax)
movb -0xac(%rbp), %cl
leaq 0x17e814(%rip), %rax    # 0x29d5ca
movb %cl, (%rax)
movzbl -0xa9(%rbp), %ecx
leaq 0x24d8be(%rip), %rax    # 0x36c684
movl %ecx, (%rax)
movb -0xaa(%rbp), %cl
leaq 0x15b63f(%rip), %rax    # 0x27a414
movb %cl, (%rax)
movzbl -0xab(%rbp), %ecx
leaq 0x24dd6f(%rip), %rax    # 0x36cb54
movl %ecx, (%rax)
leaq 0x24dd66(%rip), %rax    # 0x36cb54
movl (%rax), %ecx
orl $0x200, %ecx            # imm = 0x200
leaq 0x24dd57(%rip), %rax    # 0x36cb54
movl %ecx, (%rax)
movl -0xbc(%rbp), %ecx
leaq 0x17e81c(%rip), %rax    # 0x29d628
movl %ecx, (%rax)
movq -0xb8(%rbp), %rcx
leaq 0x17e724(%rip), %rax    # 0x29d540
movq %rcx, (%rax)
leaq -0xa0(%rbp), %rsi
leaq 0x17d213(%rip), %rdi    # 0x29c040
callq 0x9350
callq 0x10ae40
leaq 0x17e7aa(%rip), %rax    # 0x29d5e8
movl $0x0, (%rax)
leaq 0x24e455(%rip), %rdi    # 0x36d2a0
callq 0xa430
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax)