From 4ce2a5fe578609b2dfb54f2bdec86621358d2acf Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 9 Jan 2005 00:10:48 +0000 Subject: [PATCH] Create open_input() for common input open routines. Input error messages have been gone over. cd-read is a little more like the rest. Regression output now has NO-WARRANTY. --- src/cd-drive.c | 20 ++++---- src/cd-info.c | 103 ++++++--------------------------------- src/cd-read.c | 77 ++++++----------------------- src/util.c | 87 ++++++++++++++++++++++++++++++++- src/util.h | 34 +++++++++---- test/cdda-read.right | 3 ++ test/check_common_fn.in | 6 +-- test/isofs-m1-read.right | 3 ++ 8 files changed, 158 insertions(+), 175 deletions(-) diff --git a/src/cd-drive.c b/src/cd-drive.c index a9447625..f3e378e1 100644 --- a/src/cd-drive.c +++ b/src/cd-drive.c @@ -1,7 +1,7 @@ /* - $Id: cd-drive.c,v 1.12 2005/01/02 22:49:31 rocky Exp $ + $Id: cd-drive.c,v 1.13 2005/01/09 00:10:48 rocky Exp $ - Copyright (C) 2004 Rocky Bernstein + Copyright (C) 2004, 2005 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 @@ -86,14 +86,14 @@ parse_options (int argc, const char *argv[]) switch (opt) { case OP_SOURCE_DEVICE: - if (opts.source_image != IMAGE_UNKNOWN) { + if (opts.source_image != DRIVER_UNKNOWN) { report( stderr, "%s: another source type option given before.\n", program_name ); report( stderr, "%s: give only one source type option.\n", program_name ); break; } else { - opts.source_image = IMAGE_DEVICE; + opts.source_image = DRIVER_DEVICE; source_name = fillout_device_name(source_name); break; } @@ -107,7 +107,7 @@ parse_options (int argc, const char *argv[]) { const char *remaining_arg = poptGetArg(optCon); if ( remaining_arg != NULL) { - if (opts.source_image != IMAGE_UNKNOWN) { + if (opts.source_image != DRIVER_UNKNOWN) { report( stderr, "%s: Source specified in option %s and as %s\n", program_name, source_name, remaining_arg); poptFreeContext(optCon); @@ -115,7 +115,7 @@ parse_options (int argc, const char *argv[]) exit (EXIT_FAILURE); } - if (opts.source_image == IMAGE_DEVICE) + if (opts.source_image == DRIVER_DEVICE) source_name = fillout_device_name(remaining_arg); else source_name = strdup(remaining_arg); @@ -163,7 +163,7 @@ init(void) /* Default option values. */ opts.silent = false; opts.debug_level = 0; - opts.source_image = IMAGE_UNKNOWN; + opts.source_image = DRIVER_UNKNOWN; } int @@ -188,9 +188,11 @@ main(int argc, const char *argv[]) if (NULL == source_name) { char *default_device; - p_cdio = cdio_open (NULL, DRIVER_UNKNOWN); + p_cdio = cdio_open (NULL, DRIVER_DEVICE); - if (NULL != p_cdio) { + if (NULL == p_cdio) { + printf("No *loaded* CD-ROM device found.\n"); + } else { default_device = cdio_get_default_device(p_cdio); printf("The driver selected is %s\n", cdio_get_driver_name(p_cdio)); diff --git a/src/cd-info.c b/src/cd-info.c index e6ef14b5..fbbbe10b 100644 --- a/src/cd-info.c +++ b/src/cd-info.c @@ -1,7 +1,7 @@ /* - $Id: cd-info.c,v 1.107 2005/01/02 22:49:31 rocky Exp $ + $Id: cd-info.c,v 1.108 2005/01/09 00:10:49 rocky Exp $ - Copyright (C) 2003, 2004 Rocky Bernstein + Copyright (C) 2003, 2004, 2005 Rocky Bernstein Copyright (C) 1996, 1997, 1998 Gerd Knorr and Heiko Eißfeldt @@ -238,7 +238,7 @@ parse_options (int argc, const char *argv[]) case OP_SOURCE_CDRDAO: case OP_SOURCE_NRG: case OP_SOURCE_DEVICE: - if (opts.source_image != IMAGE_UNKNOWN) { + if (opts.source_image != INPUT_UNKNOWN) { report(stderr, "%s: another source type option given before.\n", program_name); report(stderr, "%s: give only one source type option.\n", @@ -255,22 +255,22 @@ parse_options (int argc, const char *argv[]) switch (opt) { case OP_SOURCE_BIN: - opts.source_image = IMAGE_BIN; + opts.source_image = INPUT_BIN; break; case OP_SOURCE_CUE: - opts.source_image = IMAGE_CUE; + opts.source_image = INPUT_CUE; break; case OP_SOURCE_CDRDAO: - opts.source_image = IMAGE_CDRDAO; + opts.source_image = INPUT_CDRDAO; break; case OP_SOURCE_NRG: - opts.source_image = IMAGE_NRG; + opts.source_image = INPUT_NRG; break; case OP_SOURCE_AUTO: - opts.source_image = IMAGE_AUTO; + opts.source_image = INPUT_AUTO; break; case OP_SOURCE_DEVICE: - opts.source_image = IMAGE_DEVICE; + opts.source_image = INPUT_DEVICE; source_name = fillout_device_name(source_name); break; } @@ -284,7 +284,7 @@ parse_options (int argc, const char *argv[]) { const char *remaining_arg = poptGetArg(optCon); if ( remaining_arg != NULL) { - if (opts.source_image != IMAGE_UNKNOWN) { + if (opts.source_image != INPUT_UNKNOWN) { report(stderr, "%s: Source '%s' given as an argument of an option and as " "unnamed option '%s'\n", program_name, psz_my_source, remaining_arg); @@ -293,7 +293,7 @@ parse_options (int argc, const char *argv[]) exit (EXIT_FAILURE); } - if (opts.source_image == IMAGE_DEVICE) + if (opts.source_image == INPUT_DEVICE) source_name = fillout_device_name(remaining_arg); else source_name = strdup(remaining_arg); @@ -827,7 +827,7 @@ init(void) #endif opts.no_ioctl = 0; opts.no_analysis = 0; - opts.source_image = IMAGE_UNKNOWN; + opts.source_image = INPUT_UNKNOWN; opts.access_mode = NULL; } @@ -874,83 +874,8 @@ main(int argc, const char *argv[]) #endif } - switch (opts.source_image) { - case IMAGE_UNKNOWN: - case IMAGE_AUTO: - p_cdio = cdio_open_am (source_name, DRIVER_UNKNOWN, opts.access_mode); - if (p_cdio==NULL) { - if (source_name) { - err_exit("%s: Error in automatically selecting driver for input %s.\n", - program_name, source_name); - } else { - err_exit("%s: Error in automatically selecting driver.\n", - program_name); - } - } - break; - case IMAGE_DEVICE: - p_cdio = cdio_open_am (source_name, DRIVER_DEVICE, opts.access_mode); - if (p_cdio==NULL) { - if (source_name) { - err_exit("%s: Error in automatically selecting CD-image driver for input %s\n", - program_name, source_name); - } else { - err_exit("%s: Error in automatically selecting CD-image driver.\n", - program_name); - } - } - break; - case IMAGE_BIN: - p_cdio = cdio_open_am (source_name, DRIVER_BINCUE, opts.access_mode); - if (p_cdio==NULL) { - if (source_name) { - err_exit("%s: Error in opening bin/cue for input %s\n", - program_name, source_name); - } else { - err_exit("%s: Error in opening bin/cue for unspecified input.\n", - program_name); - } - } - break; - case IMAGE_CUE: - p_cdio = cdio_open_cue(source_name); - if (p_cdio==NULL) { - if (source_name) { - err_exit("%s: Error in opening cue/bin with input %s\n", - program_name, source_name); - } else { - err_exit("%s: Error in opening cue/bin for unspeicified input.\n", - program_name); - } - } - break; - case IMAGE_NRG: - p_cdio = cdio_open_am (source_name, DRIVER_NRG, opts.access_mode); - if (p_cdio==NULL) { - if (source_name) { - err_exit("%s: Error in opening NRG with input %s\n", - program_name, source_name); - } else { - err_exit("%s: Error in opening NRG for unspecified input.\n", - program_name); - } - } - break; - - case IMAGE_CDRDAO: - p_cdio = cdio_open_am (source_name, DRIVER_CDRDAO, opts.access_mode); - if (p_cdio==NULL) { - if (source_name) { - err_exit("%s: Error in opening TOC with input %s.\n", - program_name, source_name); - } else { - err_exit("%s: Error in opening TOC for unspecified input.\n", - program_name); - } - } - break; - } - + p_cdio = open_input(source_name, opts.source_image, opts.access_mode); + if (p_cdio==NULL) { if (source_name) { err_exit("%s: Error in opening device driver for input %s.\n", diff --git a/src/cd-read.c b/src/cd-read.c index 232eac9c..bbaa908b 100644 --- a/src/cd-read.c +++ b/src/cd-read.c @@ -1,7 +1,7 @@ /* - $Id: cd-read.c,v 1.22 2004/11/04 10:08:23 rocky Exp $ + $Id: cd-read.c,v 1.23 2005/01/09 00:10:49 rocky Exp $ - Copyright (C) 2003, 2004 Rocky Bernstein + Copyright (C) 2003, 2004, 2005 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 @@ -202,6 +202,9 @@ parse_options (int argc, const char *argv[]) "Show output as a hex dump. The default is a hex dump when " "output goes to stdout and no hex dump when output is to a file."}, + {"no-header", '\0', POPT_ARG_NONE, &opts.no_header, + 0, "Don't display header and copyright (for regression testing)"}, + {"no-hexdump", '\0', POPT_ARG_NONE, &opts.nohexdump, 0, "Don't show output as a hex dump."}, @@ -257,7 +260,7 @@ parse_options (int argc, const char *argv[]) case OP_SOURCE_CUE: case OP_SOURCE_NRG: case OP_SOURCE_DEVICE: - if (opts.source_image != IMAGE_UNKNOWN) { + if (opts.source_image != INPUT_UNKNOWN) { report( stderr, "%s: another source type option given before.\n", program_name ); report( stderr, "%s: give only one source type option.\n", @@ -274,19 +277,19 @@ parse_options (int argc, const char *argv[]) switch (opt) { case OP_SOURCE_BIN: - opts.source_image = IMAGE_BIN; + opts.source_image = INPUT_BIN; break; case OP_SOURCE_CUE: - opts.source_image = IMAGE_CUE; + opts.source_image = INPUT_CUE; break; case OP_SOURCE_NRG: - opts.source_image = IMAGE_NRG; + opts.source_image = INPUT_NRG; break; case OP_SOURCE_AUTO: - opts.source_image = IMAGE_AUTO; + opts.source_image = INPUT_AUTO; break; case OP_SOURCE_DEVICE: - opts.source_image = IMAGE_DEVICE; + opts.source_image = INPUT_DEVICE; source_name = fillout_device_name(source_name); break; } @@ -317,7 +320,7 @@ parse_options (int argc, const char *argv[]) { const char *remaining_arg = poptGetArg(optCon); if ( remaining_arg != NULL) { - if (opts.source_image != IMAGE_UNKNOWN) { + if (opts.source_image != INPUT_UNKNOWN) { report( stderr, "%s: Source specified in option %s and as %s\n", program_name, source_name, remaining_arg ); poptFreeContext(optCon); @@ -445,7 +448,7 @@ init(void) opts.end_lsn = CDIO_INVALID_LSN; opts.num_sectors = 0; opts.read_mode = READ_MODE_UNINIT; - opts.source_image = IMAGE_UNKNOWN; + opts.source_image = INPUT_UNKNOWN; opts.hexdump = 2; /* Not set. */ gl_default_cdio_log_handler = cdio_log_set_handler (log_handler); @@ -466,59 +469,9 @@ main(int argc, const char *argv[]) be reflected in `arguments'. */ parse_options(argc, argv); - /* end of local declarations */ + print_version(program_name, VERSION, opts.no_header, opts.version_only); - switch (opts.source_image) { - case IMAGE_UNKNOWN: - case IMAGE_AUTO: - p_cdio = cdio_open (source_name, DRIVER_UNKNOWN); - if (p_cdio==NULL) { - err_exit("Error in automatically selecting driver with input %s\n", - source_name); - } - break; - case IMAGE_DEVICE: - p_cdio = cdio_open (source_name, DRIVER_DEVICE); - if (p_cdio==NULL) { - err_exit("Error in automatically selecting device with input %s\n", - source_name ? source_name : "(null)"); - - } - break; - case IMAGE_BIN: - p_cdio = cdio_open (source_name, DRIVER_BINCUE); - if (p_cdio==NULL) { - err_exit("Error in opening bin/cue file %s\n", - source_name ? source_name : "(null)"); - } - break; - case IMAGE_CUE: - p_cdio = cdio_open_cue(source_name); - if (p_cdio==NULL) { - err_exit("Error in opening cue/bin file %s with input\n", - source_name ? source_name : "(null)"); - } - break; - case IMAGE_NRG: - p_cdio = cdio_open (source_name, DRIVER_NRG); - if (p_cdio==NULL) { - err_exit("Error in opening NRG file %s for input\n", - source_name ? source_name : "(null)"); - } - break; - - case IMAGE_CDRDAO: - p_cdio = cdio_open (source_name, DRIVER_CDRDAO); - if (p_cdio==NULL) { - err_exit("Error in opening TOC file %s for input\n", - source_name ? source_name : "(null)"); - } - break; - } - - if (opts.access_mode!=NULL) { - cdio_set_arg(p_cdio, "access-mode", opts.access_mode); - } + p_cdio = open_input(source_name, opts.source_image, opts.access_mode); if (opts.output_file!=NULL) { diff --git a/src/util.c b/src/util.c index 6ecc1808..bd4ce05e 100644 --- a/src/util.c +++ b/src/util.c @@ -1,5 +1,5 @@ /* - $Id: util.c,v 1.29 2005/01/04 04:42:17 rocky Exp $ + $Id: util.c,v 1.30 2005/01/09 00:10:49 rocky Exp $ Copyright (C) 2003, 2004, 2005 Rocky Bernstein @@ -44,7 +44,8 @@ print_version (char *program_name, const char *version, driver_id_t driver_id; if (no_header == 0) - report( stdout, "%s version %s\nCopyright (c) 2003, 2004 R. Bernstein\n", + report( stdout, + "%s version %s\nCopyright (c) 2003, 2004, 2005 R. Bernstein\n", program_name, version); report( stdout, _("This is free software; see the source for copying conditions.\n\ @@ -70,6 +71,87 @@ PARTICULAR PURPOSE.\n\ } +/*! Device input routine. If successful we return an open CdIo_t + pointer. On error the program exits. + */ +CdIo_t * +open_input(const char *psz_source, source_image_t source_image, + const char *psz_access_mode) +{ + CdIo_t *p_cdio = NULL; + switch (source_image) { + case INPUT_UNKNOWN: + case INPUT_AUTO: + p_cdio = cdio_open_am (psz_source, DRIVER_UNKNOWN, psz_access_mode); + if (!p_cdio) { + if (psz_source) { + err_exit("Error in automatically selecting driver for input %s.\n", + psz_source); + } else { + err_exit("Error in automatically selecting driver.\n"); + } + } + break; + case INPUT_DEVICE: + p_cdio = cdio_open_am (psz_source, DRIVER_DEVICE, psz_access_mode); + if (!p_cdio) { + if (psz_source) { + err_exit("Cannot use CD-ROM device %s. Is a CD loaded?\n", + psz_source); + } else { + err_exit("Cannot find a CD-ROM with a CD loaded.\n"); + } + } + break; + case INPUT_BIN: + p_cdio = cdio_open_am (psz_source, DRIVER_BINCUE, psz_access_mode); + if (!p_cdio) { + if (psz_source) { + err_exit("%s: Error in opening CDRWin BIN/CUE image for BIN" + " input %s\n", psz_source); + } else { + err_exit("Cannot find CDRWin BIN/CUE image.\n"); + } + } + break; + case INPUT_CUE: + p_cdio = cdio_open_cue(psz_source); + if (p_cdio==NULL) { + if (psz_source) { + err_exit("%s: Error in opening CDRWin BIN/CUE image for CUE" + " input %s\n", psz_source); + } else { + err_exit("Cannot find CDRWin BIN/CUE image.\n"); + } + } + break; + case INPUT_NRG: + p_cdio = cdio_open_am (psz_source, DRIVER_NRG, psz_access_mode); + if (p_cdio==NULL) { + if (psz_source) { + err_exit("Error in opening Nero NRG image for input %s\n", + psz_source); + } else { + err_exit("Cannot find Nero NRG image.\n"); + } + } + break; + + case INPUT_CDRDAO: + p_cdio = cdio_open_am (psz_source, DRIVER_CDRDAO, psz_access_mode); + if (p_cdio==NULL) { + if (psz_source) { + err_exit("Error in opening cdrdao TOC with input %s.\n", psz_source); + } else { + err_exit("Cannot find cdrdao TOC image.\n"); + } + } + break; + } + return p_cdio; +} + + #define DEV_PREFIX "/dev/" char * fillout_device_name(const char *device_name) @@ -78,6 +160,7 @@ fillout_device_name(const char *device_name) return strdup(device_name); #else unsigned int prefix_len = strlen(DEV_PREFIX); + if (!device_name) return NULL; if (0 == strncmp(device_name, DEV_PREFIX, prefix_len)) return strdup(device_name); else { diff --git a/src/util.h b/src/util.h index f99667da..738a692d 100644 --- a/src/util.h +++ b/src/util.h @@ -1,5 +1,5 @@ /* - $Id: util.h,v 1.9 2004/11/06 09:16:04 rocky Exp $ + $Id: util.h,v 1.10 2005/01/09 00:10:49 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein @@ -85,24 +85,38 @@ typedef enum { - IMAGE_AUTO, - IMAGE_DEVICE, - IMAGE_BIN, - IMAGE_CUE, - IMAGE_NRG, - IMAGE_CDRDAO, - IMAGE_UNKNOWN + INPUT_AUTO, + INPUT_DEVICE, + INPUT_BIN, + INPUT_CUE, + INPUT_NRG, + INPUT_CDRDAO, + INPUT_UNKNOWN } source_image_t; extern char *source_name; extern char *program_name; extern cdio_log_handler_t gl_default_cdio_log_handler; -void myexit(CdIo *cdio, int rc); +/*! Common error exit routine which frees p_cdio. rc is the + return code to pass to exit. +*/ +void myexit(CdIo_t *p_cdio, int rc); -void print_version (char *program_name, const char *version, +/*! Print our version string */ +void print_version (char *psz_program, const char *psz_version, int no_header, bool version_only); +/*! Device input routine. If successful we return an open CdIo_t + pointer. On error the program exits. + */ +CdIo_t * +open_input(const char *psz_source, source_image_t source_image, + const char *psz_access_mode); + +/*! On Unixish OS's we fill out the device name, from a short name. + For example cdrom might become /dev/cdrom. +*/ char *fillout_device_name(const char *device_name); /*! Prints out SCSI-MMC drive features */ diff --git a/test/cdda-read.right b/test/cdda-read.right index aa3f218e..4464083f 100644 --- a/test/cdda-read.right +++ b/test/cdda-read.right @@ -1,3 +1,6 @@ +This is free software; see the source for copying conditions. +There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. 0x0000: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0010: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0x0020: 0000 0000 0000 0000 0000 0000 0000 0000 ................ diff --git a/test/check_common_fn.in b/test/check_common_fn.in index 4241e427..77619dcd 100755 --- a/test/check_common_fn.in +++ b/test/check_common_fn.in @@ -1,6 +1,6 @@ -# $Id: check_common_fn.in,v 1.9 2004/10/28 11:13:40 rocky Exp $ +# $Id: check_common_fn.in,v 1.10 2005/01/09 00:10:48 rocky Exp $ # -# Copyright (C) 2003, 2004 Rocky Bernstein +# Copyright (C) 2003, 2004, 2005 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 @@ -161,7 +161,7 @@ test_cd_read() { return 1 fi - if ${CD_READ} ${opts} >${outfile} 2>&1 ; then + if ${CD_READ} --no-header ${opts} >${outfile} 2>&1 ; then if test "@DIFF@" != no; then if @DIFF@ @DIFF_OPTS@ ${outfile} ${rightfile} ; then rm -f $outfile diff --git a/test/isofs-m1-read.right b/test/isofs-m1-read.right index 96c50a7b..3cbf0442 100644 --- a/test/isofs-m1-read.right +++ b/test/isofs-m1-read.right @@ -1,3 +1,6 @@ +This is free software; see the source for copying conditions. +There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. 0x0000: 0909 2020 2020 474e 5520 4745 4e45 5241 .. GNU GENERA 0x0010: 4c20 5055 424c 4943 204c 4943 454e 5345 L PUBLIC LICENSE 0x0020: 0a09 0920 2020 2020 2020 5665 7273 696f ... Versio