// File: tomfunkhouser[P]gaps/pkgs/GSV/GSVScene.cpp
// Function: gaps::GSVScene::ReadFile(char const*, int)
int GSVScene::
ReadFile(const char *filename, RNBoolean read_points)
{
  // Parse input filename extension
  const char *extension;
  if (!(extension = strrchr(filename, '.'))) {
    RNFail("Filename %s has no extension (e.g., .gsv)\n", filename);
    return 0;
  }

  // Read file of appropriate type
  int status = 0;
  if (!strncmp(extension, ".txt", 4)) status = ReadASCIIFile(filename, read_points);
  else if (!strncmp(extension, ".lsr", 4)) status = ReadLaserFile(filename, read_points);
  else if (!strncmp(extension, ".gsf", 4)) status = ReadGSFFile(filename, read_points);
  else if (!strncmp(extension, ".gsv", 4)) status = ReadGSVFile(filename, read_points);
  else RNFail("Unrecognized file extension %s in %s\n", extension, filename); 
  if (status == 0) return 0;

  // Remember filename
  this->filename = RNStrdup(filename);

  // Set raw directory name
  char buffer[2048];
  strcpy(buffer, filename);
  char *bufferp = strrchr(buffer, '/');
  if (bufferp) *bufferp = '\0';
  else strcpy(buffer, ".");
  strcat(buffer, "/raw_data");
  if (RNFileExists(buffer)) {
    SetRawDataDirectoryName(buffer);
  }

  // Set cache directory name
  strcpy(buffer, filename);
  bufferp = strrchr(buffer, '/');
  if (bufferp) *bufferp = '\0';
  else strcpy(buffer, ".");
  strcat(buffer, "/gsv_data");
  if (RNFileExists(buffer)) {
    SetCacheDataDirectoryName(buffer);
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x848, %rsp            # imm = 0x848
movq %rdi, 0x838(%rsp)
movq %rsi, 0x830(%rsp)
movl %edx, 0x82c(%rsp)
movq 0x838(%rsp), %rax
movq %rax, (%rsp)
movq 0x830(%rsp), %rdi
movl $0x2e, %esi
callq 0x2a110
movq %rax, 0x820(%rsp)
cmpq $0x0, %rax
jne 0x3c180
movq 0x830(%rsp), %rsi
leaq 0x22a9f8(%rip), %rdi    # 0x266b61
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x844(%rsp)
jmp 0x3c3e0
movl $0x0, 0x81c(%rsp)
movq 0x820(%rsp), %rdi
leaq 0x22adf6(%rip), %rsi    # 0x266f90
movl $0x4, %edx
callq 0x29440
cmpl $0x0, %eax
jne 0x3c1ce
movq (%rsp), %rdi
movq 0x830(%rsp), %rsi
movl 0x82c(%rsp), %edx
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, 0x81c(%rsp)
jmp 0x3c2b5
movq 0x820(%rsp), %rdi
leaq 0x22a9af(%rip), %rsi    # 0x266b8c
movl $0x4, %edx
callq 0x29440
cmpl $0x0, %eax
jne 0x3c211
movq (%rsp), %rdi
movq 0x830(%rsp), %rsi
movl 0x82c(%rsp), %edx
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, 0x81c(%rsp)
jmp 0x3c2b3
movq 0x820(%rsp), %rdi
leaq 0x22a971(%rip), %rsi    # 0x266b91
movl $0x4, %edx
callq 0x29440
cmpl $0x0, %eax
jne 0x3c251
movq (%rsp), %rdi
movq 0x830(%rsp), %rsi
movl 0x82c(%rsp), %edx
movq (%rdi), %rax
callq *0x38(%rax)
movl %eax, 0x81c(%rsp)
jmp 0x3c2b1
movq 0x820(%rsp), %rdi
leaq 0x22a2dd(%rip), %rsi    # 0x26653d
movl $0x4, %edx
callq 0x29440
cmpl $0x0, %eax
jne 0x3c291
movq (%rsp), %rdi
movq 0x830(%rsp), %rsi
movl 0x82c(%rsp), %edx
movq (%rdi), %rax
callq *0x40(%rax)
movl %eax, 0x81c(%rsp)
jmp 0x3c2af
movq 0x820(%rsp), %rsi
movq 0x830(%rsp), %rdx
leaq 0x22a8ee(%rip), %rdi    # 0x266b96
movb $0x0, %al
callq 0x1cbff0
jmp 0x3c2b1
jmp 0x3c2b3
jmp 0x3c2b5
cmpl $0x0, 0x81c(%rsp)
jne 0x3c2cf
movl $0x0, 0x844(%rsp)
jmp 0x3c3e0
movq 0x830(%rsp), %rdi
callq 0x1cbcf0
movq %rax, %rcx
movq (%rsp), %rax
movq %rcx, 0x18(%rax)
leaq 0x10(%rsp), %rdi
movq 0x830(%rsp), %rsi
callq 0x29780
leaq 0x10(%rsp), %rdi
movl $0x2f, %esi
callq 0x2a110
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
je 0x3c31f
movq 0x8(%rsp), %rax
movb $0x0, (%rax)
jmp 0x3c330
leaq 0x10(%rsp), %rdi
leaq 0x2335c9(%rip), %rsi    # 0x26f8f4
callq 0x29780
leaq 0x10(%rsp), %rdi
leaq 0x22a880(%rip), %rsi    # 0x266bbc
callq 0x29cb0
leaq 0x10(%rsp), %rdi
callq 0x1cadd0
cmpl $0x0, %eax
je 0x3c35e
movq (%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3b9e0
leaq 0x10(%rsp), %rdi
movq 0x830(%rsp), %rsi
callq 0x29780
leaq 0x10(%rsp), %rdi
movl $0x2f, %esi
callq 0x2a110
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
je 0x3c396
movq 0x8(%rsp), %rax
movb $0x0, (%rax)
jmp 0x3c3a7
leaq 0x10(%rsp), %rdi
leaq 0x233552(%rip), %rsi    # 0x26f8f4
callq 0x29780
leaq 0x10(%rsp), %rdi
leaq 0x22a813(%rip), %rsi    # 0x266bc6
callq 0x29cb0
leaq 0x10(%rsp), %rdi
callq 0x1cadd0
cmpl $0x0, %eax
je 0x3c3d5
movq (%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3ba40
movl $0x1, 0x844(%rsp)
movl 0x844(%rsp), %eax
addq $0x848, %rsp            # imm = 0x848
retq
nop