// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/config.c
// Function: parse_confg
void parse_confg(umConfig *config, char *cfgFile)
{
  FILE * fp ;
  char bufr[MAXCFGLINE];
  char *b_ptr;
  char *indx;

  if( (fp = fopen(cfgFile, "r")) != NULL){
    while(! feof(fp)){
      if (fgets(bufr, MAXCFGLINE, fp) != NULL)
      {
        b_ptr = &bufr[0];
        // Eat leading whitespace
        while(isspace(*b_ptr)) b_ptr++;
        if ( b_ptr[0] != '\0' && b_ptr[0] != '#')
        {
          indx = strchr(b_ptr, '=');  
          if ( indx != NULL) 
          {
            if (strncasecmp (b_ptr, "mqtt_address", 12) == 0) {
              config->mqtt_address = cleanalloc(indx+1);
            } else if (strncasecmp (b_ptr, "mqtt_user", 9) == 0) {
              config->mqtt_user = cleanalloc(indx+1);
            } else if (strncasecmp (b_ptr, "mqtt_passwd", 11) == 0) {
              config->mqtt_passwd = cleanalloc(indx+1);
            } else if (strncasecmp (b_ptr, "mqtt_pub_topic", 13) == 0) {
              config->mqtt_pub_topic = cleanalloc(indx+1);
            } else if (strncasecmp (b_ptr, "log_file", 8) == 0) {
              config->log_file_to_monitor = cleanalloc(indx+1);
            } else if (strncasecmp (b_ptr, "log_regex", 9) == 0) {
              config->regexString = cleanalloc(indx+1);
            } else {
              *indx = 0;
              addMotion(config, cleanwhitespace(b_ptr), cleanwhitespace(indx+1));
            }
          } 
        }
      }
    }
    fclose(fp);
  } else {
    fprintf(stderr, "ERROR reading config file '%s'\n%s\n", cfgFile,strerror (errno));
    exit (EXIT_FAILURE);
  }

  int i;

  for (i=strlen(config->log_file_to_monitor); i > 0; i--) {
    if (config->log_file_to_monitor[i] == '/') {
      config->watchDir = malloc(sizeof(char) * (i+1));
      config->watchFile = malloc(sizeof(char) * ( (strlen(config->log_file_to_monitor)-i)+1 ) );
      strncpy(config->watchDir, config->log_file_to_monitor, i);
      strcpy(config->watchFile, &config->log_file_to_monitor[i+1]);
      config->watchDir[i] = '\0';
      break;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x3384(%rip), %rsi      # 0x16120
movq %r15, %rdi
callq 0x3520
testq %rax, %rax
je 0x12fe2
movq %rax, %r14
leaq -0x1(%rsp), %rbp
movq %rsp, %r15
movq %r14, %rdi
callq 0x3360
testl %eax, %eax
jne 0x12f57
movq %r15, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x32e0
testq %rax, %rax
je 0x12db8
callq 0x3660
movq (%rax), %rax
movq %rbp, %r13
movsbq 0x1(%r13), %rcx
incq %r13
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x12de8
movzbl %cl, %eax
testl %eax, %eax
je 0x12db8
cmpl $0x23, %eax
je 0x12db8
movq %r13, %rdi
pushq $0x3d
popq %rsi
callq 0x31d0
testq %rax, %rax
je 0x12db8
movq %rax, %r12
movq %r13, %rdi
leaq 0x3c27(%rip), %rsi      # 0x16a47
pushq $0xc
popq %rdx
callq 0x33f0
testl %eax, %eax
je 0x12ee0
movq %r13, %rdi
leaq 0x3c1a(%rip), %rsi      # 0x16a54
pushq $0x9
popq %rdx
callq 0x33f0
testl %eax, %eax
je 0x12ef3
movq %r13, %rdi
leaq 0x3c0a(%rip), %rsi      # 0x16a5e
pushq $0xb
popq %rdx
callq 0x33f0
testl %eax, %eax
je 0x12f07
movq %r13, %rdi
leaq 0x3bfc(%rip), %rsi      # 0x16a6a
pushq $0xd
popq %rdx
callq 0x33f0
testl %eax, %eax
je 0x12f1b
movq %r13, %rdi
leaq 0x3bf1(%rip), %rsi      # 0x16a79
pushq $0x8
popq %rdx
callq 0x33f0
testl %eax, %eax
je 0x12f2f
movq %r13, %rdi
leaq 0x3be0(%rip), %rsi      # 0x16a82
pushq $0x9
popq %rdx
callq 0x33f0
testl %eax, %eax
je 0x12f43
movb $0x0, (%r12)
movq %r13, %rdi
callq 0x12cfc
movq %rax, %r13
incq %r12
movq %r12, %rdi
callq 0x12cfc
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x12bf4
jmp 0x12db8
incq %r12
movq %r12, %rdi
callq 0x12d58
movq %rax, (%rbx)
jmp 0x12db8
incq %r12
movq %r12, %rdi
callq 0x12d58
movq %rax, 0x8(%rbx)
jmp 0x12db8
incq %r12
movq %r12, %rdi
callq 0x12d58
movq %rax, 0x10(%rbx)
jmp 0x12db8
incq %r12
movq %r12, %rdi
callq 0x12d58
movq %rax, 0x18(%rbx)
jmp 0x12db8
incq %r12
movq %r12, %rdi
callq 0x12d58
movq %rax, 0x20(%rbx)
jmp 0x12db8
incq %r12
movq %r12, %rdi
callq 0x12d58
movq %rax, 0x28(%rbx)
jmp 0x12db8
movq %r14, %rdi
callq 0x3160
movq 0x20(%rbx), %r14
movq %r14, %rdi
callq 0x3180
leal 0x1(%rax), %r15d
testl %eax, %eax
jle 0x12fd0
movl %eax, %r12d
cmpb $0x2f, (%r14,%r12)
je 0x12f84
decl %eax
decq %r15
jmp 0x12f6f
movq %r15, %rdi
callq 0x33e0
movq %rax, %r13
movq %rax, 0x48(%rbx)
movq %r14, %rdi
callq 0x3180
subq %r12, %rax
leaq 0x1(%rax), %rdi
callq 0x33e0
movq %rax, %rbp
movq %rax, 0x50(%rbx)
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x30b0
addq %r15, %r14
movq %rbp, %rdi
movq %r14, %rsi
callq 0x30e0
movb $0x0, (%r13,%r12)
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb007(%rip), %rax      # 0x1dff0
movq (%rax), %rbx
callq 0x30a0
movl (%rax), %edi
callq 0x3600
leaq 0x3a8d(%rip), %rsi      # 0x16a8c
movq %rbx, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x3340
pushq $0x1
popq %rdi
callq 0x35b0