diff --git a/example/C++/OO/Makefile.am b/example/C++/OO/Makefile.am index 7f3d5fc4..5038414c 100644 --- a/example/C++/OO/Makefile.am +++ b/example/C++/OO/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.4 2006/03/06 01:34:22 rocky Exp $ +# $Id: Makefile.am,v 1.5 2006/03/06 04:48:38 rocky Exp $ # # Copyright (C) 2005, 2006 Rocky Bernstein # @@ -20,7 +20,7 @@ # Sample C++ programs using libcdio++ (with C++ OO wrapper) ############################################################ # -noinst_PROGRAMS = cdtext device drives eject iso3 mmc1 mmc2 tracks +noinst_PROGRAMS = cdtext device drives eject iso1 iso3 mmc1 mmc2 tracks INCLUDES = -I$(top_srcdir)/include $(LIBCDIO_CFLAGS) @@ -40,6 +40,10 @@ eject_SOURCES = eject.cpp eject_DEPENDENCIES = $(LIBCDIO_DEPS) eject_LDADD = $(LIBCDIOPP_LIBS) $(LIBCDIO_LIBS) +iso1_SOURCES = iso1.cpp +iso1_LDADD = $(LIBISO966PP0_LIBS) $(LIBISO9660_LIBS) \ + $(LIBCDIOPP_LIBS) $(LIBICONV) + iso3_SOURCES = iso3.cpp iso3_LDADD = $(LIBISO966PP0_LIBS) $(LIBISO9660_LIBS) \ $(LIBCDIOPP_LIBS) $(LIBICONV) diff --git a/example/C++/OO/iso1.cpp b/example/C++/OO/iso1.cpp new file mode 100644 index 00000000..bd559a28 --- /dev/null +++ b/example/C++/OO/iso1.cpp @@ -0,0 +1,120 @@ +/* + $Id: iso1.cpp,v 1.1 2006/03/06 04:48:38 rocky Exp $ + + Copyright (C) 2006 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 +*/ + +/* Simple program to show using libiso9660 to list files in a directory of + an ISO-9660 image and give some iso9660 information. See the code + to iso-info for a more complete example. + + If a single argument is given, it is used as the ISO 9660 image to + use in the listing. Otherwise a compiled-in default ISO 9660 image + name (that comes with the libcdio distribution) will be used. + + This program can be compiled with either a C or C++ compiler. In + the distributuion we perfer C++ just to make sure we haven't broken + things on the C++ side. + */ + +/* Set up a CD-DA image to test on which is in the libcdio distribution. */ +#define ISO9660_IMAGE_PATH "../../../" +#define ISO9660_IMAGE ISO9660_IMAGE_PATH "test/copying.iso" + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include +#include + +#include + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#define print_vd_info(title, fn) \ + if (p_iso->fn(psz_str)) { \ + printf(title ": %s\n", psz_str); \ + } \ + free(psz_str); \ + psz_str = NULL; + + +int +main(int argc, const char *argv[]) +{ + list < ISO9660::Stat > entlist; + ISO9660::IFS *p_iso = new ISO9660::IFS; + char const *psz_fname; + const char *psz_path="/"; + + if (argc > 1) + psz_fname = argv[1]; + else + psz_fname = ISO9660_IMAGE; + + if (!p_iso->open(psz_fname)) { + fprintf(stderr, "Sorry, couldn't open %s as an ISO-9660 image\n", + psz_fname); + return 1; + } + + /* Show basic CD info from the Primary Volume Descriptor. */ + { + char *psz_str = NULL; + print_vd_info("Application", get_application_id); + print_vd_info("Preparer ", get_preparer_id); + print_vd_info("Publisher ", get_publisher_id); + print_vd_info("System ", get_system_id); + print_vd_info("Volume ", get_volume_id); + print_vd_info("Volume Set ", get_volumeset_id); + } + +#if 0 + entlist = p_iso->readdir (psz_path); + + /* Iterate over the list of nodes that iso9660_ifs_readdir gives */ + + { + ISO9660::Stat *p_stat; + for(p_stat=entlist.begin(); p_stat != entlist.end(); ++p_stat) + { + char filename[4096]; + p_stat->iso9660_name_translate(p_statbuf->filename, filename); + printf ("%s [LSN %6d] %8u %s%s\n", + 2 == p_statbuf->type ? "d" : "-", + p_statbuf->lsn, p_statbuf->size, psz_path, filename); + } + + delete(stat); + } +#endif + + delete(p_iso); + return 0; +} + diff --git a/example/C++/OO/iso3.cpp b/example/C++/OO/iso3.cpp index f280d8aa..c2f7787c 100644 --- a/example/C++/OO/iso3.cpp +++ b/example/C++/OO/iso3.cpp @@ -1,5 +1,5 @@ /* - $Id: iso3.cpp,v 1.1 2006/03/06 01:34:22 rocky Exp $ + $Id: iso3.cpp,v 1.2 2006/03/06 04:48:38 rocky Exp $ Copyright (C) 2006 Rocky Bernstein @@ -63,12 +63,14 @@ #define my_exit(rc) \ fclose (p_outfd); \ + delete (p_stat); \ + delete (p_iso); \ return rc; \ int main(int argc, const char *argv[]) { - ISO9660::Stat *stat; + ISO9660::Stat *p_stat; FILE *p_outfd; int i; char const *psz_image; @@ -96,30 +98,32 @@ main(int argc, const char *argv[]) return 1; } - stat = p_iso->stat(psz_fname, true); + p_stat = p_iso->stat(psz_fname, true); - if (!stat) + if (!p_stat) { fprintf(stderr, "Could not get ISO-9660 file information for file %s\n", psz_fname); - p_iso->close(); + delete(p_iso); return 2; } if (!(p_outfd = fopen (psz_fname, "wb"))) { perror ("fopen()"); + delete (p_stat); + delete (p_iso); return 3; } /* Copy the blocks from the ISO-9660 filesystem to the local filesystem. */ { - const unsigned int i_blocks = CEILING(stat->p_stat->size, ISO_BLOCKSIZE); + const unsigned int i_blocks = CEILING(p_stat->p_stat->size, ISO_BLOCKSIZE); for (i = 0; i < i_blocks ; i++) { char buf[ISO_BLOCKSIZE]; - const lsn_t lsn = stat->p_stat->lsn + i; + const lsn_t lsn = p_stat->p_stat->lsn + i; memset (buf, 0, ISO_BLOCKSIZE); @@ -145,7 +149,7 @@ main(int argc, const char *argv[]) /* Make sure the file size has the exact same byte size. Without the truncate below, the file will a multiple of ISO_BLOCKSIZE. */ - if (ftruncate (fileno (p_outfd), stat->p_stat->size)) + if (ftruncate (fileno (p_outfd), p_stat->p_stat->size)) perror ("ftruncate()"); printf("Extraction of file '%s' from %s successful.\n", diff --git a/example/C++/iso1.cpp b/example/C++/iso1.cpp index 14072ab5..36bbaed0 100644 --- a/example/C++/iso1.cpp +++ b/example/C++/iso1.cpp @@ -1,5 +1,5 @@ /* - $Id: iso1.cpp,v 1.5 2006/03/02 18:57:31 rocky Exp $ + $Id: iso1.cpp,v 1.6 2006/03/06 04:48:37 rocky Exp $ Copyright (C) 2004, 2006 Rocky Bernstein @@ -38,8 +38,6 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include -#include #include #include diff --git a/include/cdio++/iso9660.hpp b/include/cdio++/iso9660.hpp index b780e7f6..205b3486 100644 --- a/include/cdio++/iso9660.hpp +++ b/include/cdio++/iso9660.hpp @@ -1,5 +1,5 @@ /* -*- C++ -*- - $Id: iso9660.hpp,v 1.3 2006/03/06 01:34:22 rocky Exp $ + $Id: iso9660.hpp,v 1.4 2006/03/06 04:48:38 rocky Exp $ Copyright (C) 2006 Rocky Bernstein @@ -30,6 +30,7 @@ #include #include #include // list class library +using namespace std; /** ISO 9660 class. */ @@ -370,21 +371,26 @@ public: { return iso9660_ifs_fuzzy_read_superblock (p_iso9660, iso_extension_mask, i_fuzz); - }; -#if 0 /*! Read psz_path (a directory) and return a list of iso9660_stat_t pointers for the files inside that directory. The caller must free the returned result. */ - list::readdir (const char psz_path[]) + list< ISO9660::Stat *> readdir (const char psz_path[]) { CdioList_t *p_stat_list = iso9660_ifs_readdir (p_iso9660, psz_path); - list stat_list; + CdioListNode_t *p_entnode; + list< ISO9660::Stat *> stat_list; + _CDIO_LIST_FOREACH (p_entnode, p_stat_list) { + iso9660_stat_t *p_statbuf = + (iso9660_stat_t *) _cdio_list_node_data (p_entnode); + stat_list.push_back(new ISO9660::Stat(p_statbuf)); + } + _cdio_list_free (p_stat_list, false); + + return stat_list; } -#endif - /*! Seek to a position and then read n bytes. Size read is returned. diff --git a/lib/cdio++/Makefile.am b/lib/cdio++/Makefile.am index ed8b3ec4..1fad3976 100644 --- a/lib/cdio++/Makefile.am +++ b/lib/cdio++/Makefile.am @@ -1,6 +1,6 @@ -# $Id: Makefile.am,v 1.3 2006/03/06 01:34:22 rocky Exp $ +# $Id: Makefile.am,v 1.4 2006/03/06 04:48:38 rocky Exp $ # -# Copyright (C) 2005 Rocky Bernstein +# Copyright (C) 2005, 2006 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