Logo Search packages:      
Sourcecode: cbmlink version File versions  Download package

static int drive_memory_save ( const char *  cmd,
const char *  filename 
) [static]

save the memory of a disk drive of the remote host to a file

Parameters:
cmd the -dms or -dmc command
filename name of the file to be saved, "-" for stdout
Returns:
zero on success, nonzero on error

converted start address

converted end address

output file

address specifier string

first non-numeric character in the address specifier

Definition at line 501 of file cbmlink.c.

References buffer, device, disk_cread(), disk_install(), disk_mread(), disk_remove(), end, and resolve_addr().

Referenced by main().

{
  /** converted start address */
  unsigned start = 0;
  /** converted end address */
  unsigned end = 0;
  /** output file */
  FILE* f;
  /** address specifier string */
  const char* addrspec = 0;
  /** first non-numeric character in the address specifier */
  char* e;

  switch (cmd[4]) {
  case ',':
    if (!cmd[5])
      return -1;
    addrspec = cmd + 5;
    break;
  case 'o': /* save memory to a program file */
    if (cmd[5] == ',' && cmd[6]) {
      addrspec = cmd + 6;
      break;
    }
  default:
    return -1;
  }

  start = resolve_addr (addrspec, &e);
  if (*e != ',') {
  saveAddress:
    fprintf (stderr, "%s %s: invalid address %s\n", cmd, filename, addrspec);
    return -1;
  }
  else
    addrspec = e + 1;

  end = resolve_addr (addrspec, &e);
  if (*e)
    goto saveAddress;

  f = *filename == '-' && !filename[1] ? stdout : fopen (filename, "wb");
  if (!f) {
    fputs (filename, stderr), perror (": fopen(writing)");
    return -2;
  }

  if (cmd[4] == ',') {
    fputc (start & 0xff, f);
    fputc (start >> 8, f);
  }

  if (disk_install (comm, hostinfo, device)) {
    if (f != stdout) fclose (f);
    fputs ("disk: installation failed\n", stderr);
    return 2;
  }

  if (cmd[3] == 'c') {
    if (disk_cread (comm, f, start, end, buffer)) {
      fputs ("disk: cread failed\n", stderr);
    disk_failed:
      if (f != stdout) fclose (f);
      if (disk_remove (comm)) {
      diskRemove:
      fputs ("disk: removal failed\n", stderr);
      return 2;
      }
      return 1;
    }
  }
  else {
    if (disk_mread (comm, f, start, end, buffer)) {
      fputs ("disk: mread failed\n", stderr);
      goto disk_failed;
    }
  }

  if (f != stdout)
    fclose (f);

  if (disk_remove (comm))
    goto diskRemove;
  return 0;
}


Generated by  Doxygen 1.6.0   Back to index