// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heather.cpp
// Function: read_config_file(char*, unsigned char, unsigned char)
int read_config_file(char *name, u08 local_flag, u08 add_path)
{
char fn[MAX_PATH+1];
char msg[MAX_PATH+80];
char buf[SLEN+1];
char *dot;
FILE *file;
int error;
int i;

   // read command line options from a .CFG file
   if(name == 0) return 0;

printf("read_config_file(name:%s  local:%d  add:%d)  path:%s\n", name,(int) local_flag, (int) add_path, heather_path);
   fn[0] = 0;
   if(add_path) {
      strcat(fn, heather_path);
   }
   strcat(fn, name);

   dot = strstr(&fn[1], ".");
   if(dot) {   // file name has a .EXTension
               // replace with .CFG,  unless user gave the name on the command line
      if(local_flag == 1) {  // cfg file name is based upon the .EXE file name
         strcpy(dot, ".cfg");
      }
      else if(local_flag == 2) {
         strcpy(dot, ".cal");
      }
   }
   else {
      if(local_flag == 1) strcat(fn, ".cfg");  // no extension given,  use .CFG
      else                strcat(fn, ".cal");  // no extension given,  use .CAL
   }

   if(local_flag) {  // cfg file name is based upon the .EXE file name
      dot = strstr(fn, ".");
      while(dot >= &fn[0]) {  // look in current directory first
#ifdef WINDOWS
         if(*dot == '\\') break;
#else  // __linux__  __MACH__  __FreeBSD__
         if(*dot == '/') break;
#endif
         --dot;
      }
printf("Attempting to open config file(%s):(%s)\n", fn, dot+1);
      file = topen(dot+1, "r");
      if(file) {
         if(local_flag == 2) printf("Reading calendar file:%s\n", dot+1);
         else                printf("Reading config file:%s\n", dot+1);
      }
   }
   else file = 0;

   if(file == 0) {  // now look in .EXE file directory
      file = topen(fn, "r");
printf("Attempting to open config file::%s\n", fn);
      if(file == 0) { // config file not found
         if(local_flag) return 1;
         sprintf(msg, "\nConfig file %s not found!", fn);
         buf[0] = 0;
         command_help(msg, buf, 0);
         return 1;
//qqq    exit(10);
      }
      printf("Reading config file: %s\n", fn);
   }

   if(local_flag == 2) {
      fclose(file);
      #ifdef GREET_STUFF
         read_calendar(fn, 1);
      #endif
      return 0;
   }
#ifdef WINDOWS
   else
   {
   memset(heather_cfg_path, 0, sizeof(heather_cfg_path));
   _snprintf(heather_cfg_path,sizeof(heather_cfg_path)-1,"%s", fn);
   }
#endif

   while(fgets(buf, sizeof buf, file) != NULL) {
      if(buf[0] == '@') {       // @keyboard command - copy to temp script file
         if(local_flag != 2) {  // it's not from a calendar file
            if(temp_script == 0) {
               temp_script = topen(TEMP_SCRIPT, "w");
            }
            if(temp_script && buf[0] && buf[1]) {  // copy line to temporary script file for later execution
               fputs(&buf[1], temp_script);
            }
         }
      }
      else {
         if((buf[0] != '/') && (buf[0] != '-') && (buf[0] != '=') && (buf[0] != '$')) continue;
         for(i=strlen(buf)-1; i>=0; i--) {       // trim trailing garbage from line
            if     (buf[i] == 0x0A) buf[i] = 0;
            else if(buf[i] == 0x0D) buf[i] = 0;
            else if(buf[i] == ' ')  buf[i] = 0;
            else if(buf[i] == '\t') buf[i] = 0;
            else break;
         }

         error = option_switch(buf);

         if(error) {
            sprintf(blanks, "in config file %s: ", fn);
            command_help(blanks, buf, 0);
            return 1;
//qqq       exit(10);
         }
      }
   }

   fclose(file);
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x368, %rsp            # imm = 0x368
testq %rdi, %rdi
je 0x1c4e6
movl %esi, %r14d
movq %rdi, %r12
movzbl %r14b, %r15d
movzbl %dl, %ebx
leaq 0xd8a88(%rip), %rdi     # 0xf4cd4
leaq 0x13ea3d(%rip), %r8     # 0x15ac90
movq %r12, %rsi
movl %r15d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x9030
movb $0x0, -0x130(%rbp)
testb %bl, %bl
je 0x1c280
leaq 0x13ea1c(%rip), %rsi    # 0x15ac90
leaq -0x130(%rbp), %rdi
callq 0x96c0
leaq -0x130(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x96c0
leaq -0x12f(%rbp), %rdi
pushq $0x2e
popq %rsi
callq 0x9100
testq %rax, %rax
je 0x1c2b9
testb %r14b, %r14b
je 0x1c2ef
cmpl $0x2, %r15d
je 0x1c2f4
cmpl $0x1, %r15d
je 0x1c2d4
jmp 0x1c2fe
leaq -0x130(%rbp), %rdi
callq 0x9120
addq %rbp, %rax
addq $-0x130, %rax           # imm = 0xFED0
cmpb $0x1, %r14b
jne 0x1c2e0
movb $0x0, 0x4(%rax)
movl $0x6766632e, (%rax)     # imm = 0x6766632E
jmp 0x1c2fe
movb $0x0, 0x4(%rax)
movl $0x6c61632e, (%rax)     # imm = 0x6C61632E
testb %r14b, %r14b
jne 0x1c2fe
movb $0x1, %r12b
jmp 0x1c36a
movb $0x0, 0x4(%rax)
movl $0x6c61632e, (%rax)     # imm = 0x6C61632E
pushq $0x2e
popq %rsi
movq %rbx, %rdi
callq 0x9100
movq %rax, %r15
cmpq %rbx, %r15
jb 0x1c31c
cmpb $0x2f, (%r15)
je 0x1c31c
decq %r15
jmp 0x1c30c
incq %r15
leaq 0xd89e9(%rip), %rdi     # 0xf4d0f
xorl %r12d, %r12d
leaq -0x130(%rbp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x9030
leaq 0xee994(%rip), %rsi     # 0x10acd5
movq %r15, %rdi
callq 0x9a22
testq %rax, %rax
je 0x1c36a
movq %rax, %rbx
cmpb $0x2, %r14b
jne 0x1c3d4
leaq 0xd89da(%rip), %rdi     # 0xf4d38
movq %r15, %rsi
xorl %eax, %eax
callq 0x9030
jmp 0x1c3b8
leaq 0xee964(%rip), %rsi     # 0x10acd5
leaq -0x130(%rbp), %r15
movq %r15, %rdi
callq 0x9a22
movq %rax, %rbx
leaq 0xd89e0(%rip), %rdi     # 0xf4d6a
movq %r15, %rsi
xorl %eax, %eax
callq 0x9030
testq %rbx, %rbx
je 0x1c4fc
leaq 0xd8a05(%rip), %rdi     # 0xf4da9
leaq -0x130(%rbp), %rsi
xorl %eax, %eax
callq 0x9030
cmpb $0x2, %r14b
jne 0x1c3e5
movq %rbx, %rdi
callq 0x9360
leaq -0x130(%rbp), %rdi
pushq $0x1
popq %rsi
callq 0xc9331
jmp 0x1c4e6
leaq 0xd8977(%rip), %rdi     # 0xf4d52
movq %r15, %rsi
xorl %eax, %eax
callq 0x9030
leaq -0x22f(%rbp), %r14
leaq -0x230(%rbp), %r15
movl $0x2000a01, %r12d       # imm = 0x2000A01
movabsq $0x100002600, %r13      # imm = 0x100002600
movq %r15, %rdi
movl $0xfb, %esi
movq %rbx, %rdx
callq 0x9600
testq %rax, %rax
je 0x1c4de
movzbl -0x230(%rbp), %eax
addl $-0x24, %eax
cmpl $0x1c, %eax
ja 0x1c403
btl %eax, %r12d
jae 0x1c479
movq %r15, %rdi
callq 0x9120
movl %eax, %eax
decq %rax
testl %eax, %eax
js 0x1c468
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movzbl -0x230(%rbp,%rcx), %edx
cmpq $0x20, %rdx
ja 0x1c468
btq %rdx, %r13
jae 0x1c468
movb $0x0, -0x230(%rbp,%rcx)
jmp 0x1c43b
movq %r15, %rdi
callq 0x2f9d5
testl %eax, %eax
je 0x1c403
jmp 0x1c539
cmpl $0x1c, %eax
jne 0x1c403
movq 0x20bf2b(%rip), %rsi    # 0x2283b0
movb $0x1, %al
testq %rsi, %rsi
jne 0x1c4b3
leaq 0xd892f(%rip), %rdi     # 0xf4dc2
leaq 0xeee69(%rip), %rsi     # 0x10b303
callq 0x9a22
movq %rax, %rsi
movq %rax, 0x20bf07(%rip)    # 0x2283b0
cmpb $0x0, -0x230(%rbp)
setne %al
testq %rsi, %rsi
je 0x1c403
testb %al, %al
je 0x1c403
cmpb $0x0, -0x22f(%rbp)
je 0x1c403
movq %r14, %rdi
callq 0x9400
jmp 0x1c403
movq %rbx, %rdi
callq 0x9360
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x368, %rsp            # imm = 0x368
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rbx
testb %r12b, %r12b
je 0x1c4e8
leaq 0xd8883(%rip), %rsi     # 0xf4d8e
leaq -0x390(%rbp), %r14
leaq -0x130(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
leaq -0x230(%rbp), %rsi
movb $0x0, (%rsi)
movq %r14, %rdi
xorl %edx, %edx
callq 0x1c571
jmp 0x1c4e8
leaq 0x309ad0(%rip), %rbx    # 0x326010
leaq 0xd8888(%rip), %rsi     # 0xf4dcf
leaq -0x130(%rbp), %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
leaq -0x230(%rbp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1c571
pushq $0x1
popq %rbx
jmp 0x1c4e8