/* $Id: cd-read.c,v 1.4 2003/09/21 03:35:40 rocky Exp $ Copyright (C) 2003 Rocky Bernstein This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Program to debug read routines audio, mode1, mode2 forms 1 & 2. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif #include #include /* Accomodate to older popt that doesn't support the "optional" flag */ #ifndef POPT_ARGFLAG_OPTIONAL #define POPT_ARGFLAG_OPTIONAL 0 #endif #ifdef ENABLE_NLS #include # include # define _(String) dgettext ("cdinfo", String) #else /* Stubs that do something close enough. */ # define _(String) (String) #endif /* The following test is to work around the gross typo in systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE is defined to 0, not 1. */ #if !EXIT_FAILURE # undef EXIT_FAILURE # define EXIT_FAILURE 1 #endif #ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 #endif #define err_exit(fmt, args...) \ fprintf(stderr, "%s: "fmt, program_name, ##args); \ myexit(cdio, EXIT_FAILURE) char *source_name = NULL; char *program_name; typedef enum { IMAGE_AUTO, IMAGE_DEVICE, IMAGE_BIN, IMAGE_CUE, IMAGE_NRG, IMAGE_UNKNOWN } source_image_t; /* Configuration option codes */ enum { /* These correspond to driver_id_t in cdio.h and have to MATCH! */ OP_SOURCE_UNDEF = DRIVER_UNKNOWN, OP_SOURCE_AUTO, OP_SOURCE_BIN, OP_SOURCE_CUE, OP_SOURCE_NRG = DRIVER_NRG, OP_SOURCE_DEVICE = DRIVER_DEVICE, /* These are the remaining configuration options */ OP_READ_MODE, OP_VERSION, }; typedef enum { READ_MODE_UNINIT, READ_AUDIO, READ_M1F1, READ_M1F2, READ_M2F1, READ_M2F2 } read_mode_t; /* Structure used so we can binary sort and set the --mode switch. */ typedef struct { char name[30]; read_mode_t read_mode; lsn_t start_lsn; } subopt_entry_t; /* Sub-options for --mode. Note: entries must be sorted! */ subopt_entry_t modes_sublist[] = { {"audio", READ_AUDIO}, {"m1f1", READ_M1F1}, {"m1f2", READ_M1F2}, {"m2f1", READ_M2F1}, {"m2f2", READ_M2F2}, {"mode1form1", READ_M1F1}, {"mode1form2", READ_M1F2}, {"mode2form1", READ_M2F1}, {"mode2form2", READ_M2F2}, {"red", READ_AUDIO}, }; /* Used by `main' to communicate with `parse_opt'. And global options */ struct arguments { int debug_level; read_mode_t read_mode; int version_only; int no_header; int print_iso9660; source_image_t source_image; lsn_t start_lsn; } opts; /* Comparison function called by bearch() to find sub-option record. */ static int compare_subopts(const void *key1, const void *key2) { subopt_entry_t *a = (subopt_entry_t *) key1; subopt_entry_t *b = (subopt_entry_t *) key2; return (strncmp(a->name, b->name, 30)); } /* CDIO logging routines */ static cdio_log_handler_t gl_default_cdio_log_handler = NULL; static void _log_handler (cdio_log_level_t level, const char message[]) { if (level == CDIO_LOG_DEBUG && opts.debug_level < 3) return; if (level == CDIO_LOG_INFO && opts.debug_level < 2) return; if (level == CDIO_LOG_WARN && opts.debug_level < 1) return; gl_default_cdio_log_handler (level, message); } static void hexdump (uint8_t * buffer, unsigned int len) { unsigned int i; for (i = 0; i < len; i++, buffer++) { if (i % 16 == 0) printf ("0x%04x: ", i); printf ("%02x", *buffer); if (i % 2 == 1) printf (" "); if (i % 16 == 15) { printf (" "); uint8_t *p; for (p=buffer-15; p <= buffer; p++) { printf("%c", isprint(*p) ? *p : '.'); } printf ("\n"); } } printf ("\n"); } /* Do processing of a --mode sub option. Basically we find the option in the array, set it's corresponding flag variable to true as well as the "show.all" false. */ static void process_suboption(const char *subopt, subopt_entry_t *sublist, const int num, const char *subopt_name) { subopt_entry_t *subopt_rec = bsearch(subopt, sublist, num, sizeof(subopt_entry_t), &compare_subopts); if (subopt_rec != NULL) { opts.read_mode = subopt_rec->read_mode; return; } else { unsigned int i; bool is_help=strcmp(subopt, "help")==0; if (is_help) { fprintf (stderr, "The list of sub options for \"%s\" are:\n", subopt_name); } else { fprintf (stderr, "Invalid option following \"%s\": %s.\n", subopt_name, subopt); fprintf (stderr, "Should be one of: "); } for (i=0; i