Add options to download only the memory dump or the dives.

This commit is contained in:
Jef Driesen 2009-11-16 08:09:57 +00:00
parent 71d8da4f04
commit 8eb3e53b44

View File

@ -158,6 +158,8 @@ usage (const char *filename)
fprintf (stderr, " -b name Set backend name (required).\n"); fprintf (stderr, " -b name Set backend name (required).\n");
fprintf (stderr, " -l logfile Set logfile.\n"); fprintf (stderr, " -l logfile Set logfile.\n");
fprintf (stderr, " -o output Set output filename.\n"); fprintf (stderr, " -o output Set output filename.\n");
fprintf (stderr, " -d Download dives only.\n");
fprintf (stderr, " -m Download memory dump only.\n");
fprintf (stderr, " -h Show this help message.\n\n"); fprintf (stderr, " -h Show this help message.\n\n");
#else #else
fprintf (stderr, "Usage:\n\n"); fprintf (stderr, "Usage:\n\n");
@ -177,7 +179,7 @@ usage (const char *filename)
static device_status_t static device_status_t
dowork (device_type_t backend, const char *devname, const char *filename) dowork (device_type_t backend, const char *devname, const char *filename, int memory, int dives)
{ {
device_status_t rc = DEVICE_STATUS_SUCCESS; device_status_t rc = DEVICE_STATUS_SUCCESS;
@ -256,36 +258,40 @@ dowork (device_type_t backend, const char *devname, const char *filename)
return rc; return rc;
} }
// Allocate a memory buffer. if (memory) {
dc_buffer_t *buffer = dc_buffer_new (0); // Allocate a memory buffer.
dc_buffer_t *buffer = dc_buffer_new (0);
// Download the memory dump. // Download the memory dump.
message ("Downloading the memory dump.\n"); message ("Downloading the memory dump.\n");
rc = device_dump (device, buffer); rc = device_dump (device, buffer);
if (rc != DEVICE_STATUS_SUCCESS) { if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error downloading the memory dump."); WARNING ("Error downloading the memory dump.");
dc_buffer_free (buffer);
device_close (device);
return rc;
}
// Write the memory dump to disk.
FILE* fp = fopen (filename, "wb");
if (fp != NULL) {
fwrite (dc_buffer_get_data (buffer), 1, dc_buffer_get_size (buffer), fp);
fclose (fp);
}
// Free the memory buffer.
dc_buffer_free (buffer); dc_buffer_free (buffer);
device_close (device);
return rc;
} }
// Write the memory dump to disk. if (dives) {
FILE* fp = fopen (filename, "wb"); // Download the dives.
if (fp != NULL) { message ("Downloading the dives.\n");
fwrite (dc_buffer_get_data (buffer), 1, dc_buffer_get_size (buffer), fp); rc = device_foreach (device, dive_cb, NULL);
fclose (fp); if (rc != DEVICE_STATUS_SUCCESS) {
} WARNING ("Error downloading the dives.");
device_close (device);
// Free the memory buffer. return rc;
dc_buffer_free (buffer); }
// Download the dives.
message ("Downloading the dives.\n");
rc = device_foreach (device, dive_cb, NULL);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error downloading the dives.");
device_close (device);
return rc;
} }
// Close the device. // Close the device.
@ -308,11 +314,12 @@ main (int argc, char *argv[])
const char *logfile = "output.log"; const char *logfile = "output.log";
const char *filename = "output.bin"; const char *filename = "output.bin";
const char *devname = NULL; const char *devname = NULL;
int memory = 1, dives = 1;
#ifndef _MSC_VER #ifndef _MSC_VER
// Parse command-line options. // Parse command-line options.
int opt = 0; int opt = 0;
while ((opt = getopt (argc, argv, "b:l:o:h")) != -1) { while ((opt = getopt (argc, argv, "b:l:o:mdh")) != -1) {
switch (opt) { switch (opt) {
case 'b': case 'b':
backend = lookup_type (optarg); backend = lookup_type (optarg);
@ -323,6 +330,12 @@ main (int argc, char *argv[])
case 'o': case 'o':
filename = optarg; filename = optarg;
break; break;
case 'm':
dives = 0;
break;
case 'd':
memory = 0;
break;
case '?': case '?':
case 'h': case 'h':
default: default:
@ -349,7 +362,7 @@ main (int argc, char *argv[])
message_set_logfile (logfile); message_set_logfile (logfile);
device_status_t rc = dowork (backend, devname, filename); device_status_t rc = dowork (backend, devname, filename, memory, dives);
message ("Result: %s\n", errmsg (rc)); message ("Result: %s\n", errmsg (rc));
message_set_logfile (NULL); message_set_logfile (NULL);