More flexibility: allow any two of start, end, count. If only one or

none are given, we'll supply default values.
This commit is contained in:
rocky
2003-09-22 01:00:10 +00:00
parent 9368735a1c
commit a1494406c1
2 changed files with 35 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.16 2003/09/21 04:21:39 rocky Exp $ # $Id: Makefile.am,v 1.17 2003/09/22 01:00:10 rocky Exp $
# #
# Copyright (C) 2003 Rocky Bernstein <rocky@panix.com> # Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
# #
@@ -22,6 +22,7 @@
CDDB_LIBS=@CDDB_LIBS@ CDDB_LIBS=@CDDB_LIBS@
if BUILD_CDINFO if BUILD_CDINFO
man_MANS = cd-info.1 cd-read.1
cd_info_SOURCES = cd-info.c util.c util.h cd_info_SOURCES = cd-info.c util.c util.h
cd_info_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBPOPT_LIBS) $(CDDB_LIBS) $(VCDINFO_LIBS) cd_info_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBPOPT_LIBS) $(CDDB_LIBS) $(VCDINFO_LIBS)
@@ -34,11 +35,15 @@ cdinfo_linux_LDADD = $(LIBCDIO_LIBS) $(LIBPOPT_LIBS)
bin_PROGRAMS = cd-info cd-read cdinfo-linux bin_PROGRAMS = cd-info cd-read cdinfo-linux
else else
bin_PROGRAMS = cd-info cd-read bin_PROGRAMS = cd-info cd-read
EXTRA_DIST = cdinfo-linux.c EXTRA_DIST = cdinfo-linux.c $(man_MANS)
endif endif
else else
EXTRA_DIST = cdinfo-linux.c cd-info.c cd-read.c EXTRA_DIST = cdinfo-linux.c cd-info.c cd-read.c $(man_MANS)
man_MANS =
endif endif
INCLUDES = -I$(top_srcdir) $(LIBPOPT_CFLAGS) $(LIBCDIO_CFLAGS) $(VCDINFO_CFLAGS) INCLUDES = -I$(top_srcdir) $(LIBPOPT_CFLAGS) $(LIBCDIO_CFLAGS) $(VCDINFO_CFLAGS)
if MAINTAINER_MODE
$(man_MANS): %.1: %
-$(HELP2MAN) --output=$@ ./$<
endif

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cd-read.c,v 1.6 2003/09/21 18:43:36 rocky Exp $ $Id: cd-read.c,v 1.7 2003/09/22 01:00:10 rocky Exp $
Copyright (C) 2003 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003 Rocky Bernstein <rocky@panix.com>
@@ -297,10 +297,29 @@ parse_options (int argc, const char *argv[])
} }
/* Check consistency between start_lsn, end_lsn and num_sectors. */ /* Check consistency between start_lsn, end_lsn and num_sectors. */
if (opts.start_lsn == CDIO_INVALID_LSN) {
/* Maybe we derive the start from the end and num sectors. */
if (opts.end_lsn == CDIO_INVALID_LSN) { if (opts.end_lsn == CDIO_INVALID_LSN) {
if (0 == opts.num_sectors) { /* No start or end LSN, so use 0 for the start */
opts.num_sectors = 1; opts.start_lsn = 0;
if (opts.num_sectors == 0) opts.num_sectors = 1;
} else if (opts.num_sectors != 0) {
if (opts.end_lsn <= opts.num_sectors) {
fprintf(stderr,
"%s: end LSN (%d) needs to be greater than "
" the sector to read (%d)\n",
program_name, opts.end_lsn, opts.num_sectors);
exit(12);
} }
opts.start_lsn = opts.end_lsn - opts.num_sectors + 1;
}
}
/* opts.start_lsn has been set somehow or we've aborted. */
if (opts.end_lsn == CDIO_INVALID_LSN) {
if (0 == opts.num_sectors) opts.num_sectors = 1;
opts.end_lsn = opts.start_lsn + opts.num_sectors - 1; opts.end_lsn = opts.start_lsn + opts.num_sectors - 1;
} else { } else {
/* We were given an end lsn. */ /* We were given an end lsn. */
@@ -308,7 +327,7 @@ parse_options (int argc, const char *argv[])
fprintf(stderr, fprintf(stderr,
"%s: end LSN (%d) needs to be less than start LSN (%d)\n", "%s: end LSN (%d) needs to be less than start LSN (%d)\n",
program_name, opts.start_lsn, opts.end_lsn); program_name, opts.start_lsn, opts.end_lsn);
exit(12); exit(13);
} }
if (opts.num_sectors != opts.end_lsn - opts.start_lsn + 1) if (opts.num_sectors != opts.end_lsn - opts.start_lsn + 1)
if (opts.num_sectors != 0) { if (opts.num_sectors != 0) {
@@ -316,12 +335,11 @@ parse_options (int argc, const char *argv[])
"%s: inconsistency between start LSN (%d), end (%d), " "%s: inconsistency between start LSN (%d), end (%d), "
"and count (%d)\n", "and count (%d)\n",
program_name, opts.start_lsn, opts.end_lsn, opts.num_sectors); program_name, opts.start_lsn, opts.end_lsn, opts.num_sectors);
exit(13); exit(14);
} }
opts.num_sectors = opts.end_lsn - opts.start_lsn + 1; opts.num_sectors = opts.end_lsn - opts.start_lsn + 1;
} }
return true; return true;
} }
@@ -345,7 +363,7 @@ static void
init(void) init(void)
{ {
opts.debug_level = 0; opts.debug_level = 0;
opts.start_lsn = 0; opts.start_lsn = CDIO_INVALID_LSN;
opts.end_lsn = CDIO_INVALID_LSN; opts.end_lsn = CDIO_INVALID_LSN;
opts.num_sectors = 0; opts.num_sectors = 0;
opts.read_mode = READ_MODE_UNINIT; opts.read_mode = READ_MODE_UNINIT;