Change list of files from a list to a vector. read_pvd() for

ISO9660::FS works. iso4.cpp: show ISO 9660 info for CD-images (like
iso1 for ISO images).
This commit is contained in:
rocky
2006-03-07 19:55:11 +00:00
parent 6001f4e818
commit 29d414594d
5 changed files with 167 additions and 31 deletions

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.8 2006/03/07 10:46:36 rocky Exp $
# $Id: Makefile.am,v 1.9 2006/03/07 19:55:11 rocky Exp $
#
# Copyright (C) 2005, 2006 Rocky Bernstein <rocky@panix.com>
#
@@ -20,7 +20,8 @@
# Sample C++ programs using libcdio++ (with C++ OO wrapper)
############################################################
#
noinst_PROGRAMS = cdtext device drives eject iso1 iso2 iso3 mmc1 mmc2 tracks
noinst_PROGRAMS = cdtext device drives eject \
iso1 iso2 iso3 iso4 mmc1 mmc2 tracks
INCLUDES = -I$(top_srcdir)/include $(LIBCDIO_CFLAGS)
@@ -52,6 +53,10 @@ iso3_SOURCES = iso3.cpp
iso3_LDADD = $(LIBISO9660PP_LIBS) $(LIBISO9660_LIBS) \
$(LIBCDIOPP_LIBS) $(LIBICONV)
iso4_SOURCES = iso4.cpp
iso4_LDADD = $(LIBISO9660PP_LIBS) $(LIBISO9660_LIBS) \
$(LIBCDIOPP_LIBS) $(LIBICONV)
mmc1_SOURCES = mmc1.cpp
mmc1_DEPENDENCIES = $(LIBCDIO_DEPS)
mmc1_LDADD = $(LIBCDIOPP_LIBS) $(LIBCDIO_LIBS)

View File

@@ -1,5 +1,5 @@
/*
$Id: iso1.cpp,v 1.2 2006/03/06 19:39:35 rocky Exp $
$Id: iso1.cpp,v 1.3 2006/03/07 19:55:11 rocky Exp $
Copyright (C) 2006 Rocky Bernstein <rocky@panix.com>
@@ -67,7 +67,7 @@
int
main(int argc, const char *argv[])
{
list < ISO9660::Stat *> stat_list;
stat_vector_t stat_vector;
ISO9660::IFS *p_iso = new ISO9660::IFS;
char const *psz_fname;
const char *psz_path="/";
@@ -94,11 +94,11 @@ main(int argc, const char *argv[])
print_vd_info("Volume Set ", get_volumeset_id);
}
if (p_iso->readdir (psz_path, stat_list))
if (p_iso->readdir (psz_path, stat_vector))
{
/* Iterate over the list of files. */
list <ISO9660::Stat *>::iterator i;
for(i=stat_list.begin(); i != stat_list.end(); ++i)
stat_vector_iterator_t i;
for(i=stat_vector.begin(); i != stat_vector.end(); ++i)
{
char filename[4096];
ISO9660::Stat *p_s = *i;
@@ -109,7 +109,7 @@ main(int argc, const char *argv[])
delete(p_s);
}
stat_list.clear();
stat_vector.clear();
}
delete(p_iso);

119
example/C++/OO/iso4.cpp Normal file
View File

@@ -0,0 +1,119 @@
/*
$Id: iso4.cpp,v 1.1 2006/03/07 19:55:11 rocky Exp $
Copyright (C) 2006 Rocky Bernstein <rocky@panix.com>
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/isofs-m1.cue"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <sys/types.h>
#include <cdio++/iso9660.hpp>
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#define print_vd_info(title, fn) \
psz_str = p_pvd->fn(); \
if (psz_str) { \
printf(title ": %s\n", psz_str); \
free(psz_str); \
psz_str = NULL; \
}
int
main(int argc, const char *argv[])
{
stat_vector_t stat_vector;
ISO9660::FS *p_iso = new ISO9660::FS;
char const *psz_fname;
const char *psz_path="/";
ISO9660::PVD *p_pvd;
if (argc > 1)
psz_fname = argv[1];
else
psz_fname = ISO9660_IMAGE;
if (!p_iso->open(psz_fname, DRIVER_UNKNOWN)) {
fprintf(stderr, "Sorry, couldn't open %s as a CD or CD image.\n",
psz_fname);
return 1;
}
p_pvd = p_iso->read_pvd();
if (p_pvd) {
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 (p_iso->readdir (psz_path, stat_vector))
{
/* Iterate over the list of files. */
stat_vector_iterator_t i;
for(i=stat_vector.begin(); i != stat_vector.end(); ++i)
{
char filename[4096];
ISO9660::Stat *p_s = *i;
iso9660_name_translate(p_s->p_stat->filename, filename);
printf ("%s [LSN %6d] %8u %s%s\n",
2 == p_s->p_stat->type ? "d" : "-",
p_s->p_stat->lsn, p_s->p_stat->size, psz_path, filename);
delete(p_s);
}
stat_vector.clear();
}
delete(p_iso);
return 0;
}

View File

@@ -1,5 +1,5 @@
/* -*- C++ -*-
$Id: iso9660.hpp,v 1.7 2006/03/07 10:46:36 rocky Exp $
$Id: iso9660.hpp,v 1.8 2006/03/07 19:55:11 rocky Exp $
Copyright (C) 2006 Rocky Bernstein <rocky@panix.com>
@@ -30,7 +30,7 @@
#include <cdio/iso9660.h>
#include <cdio++/cdio.hpp>
#include <string.h>
#include <list> // list class library
#include <vector> // vector class library
using namespace std;
/** ISO 9660 class.
@@ -46,6 +46,11 @@ public:
iso9660_pvd_t pvd; // Make private?
PVD()
{
memset(&pvd, 0, sizeof(pvd));
}
PVD(iso9660_pvd_t *p_new_pvd)
{
memcpy(&pvd, p_new_pvd, sizeof(pvd));
@@ -112,7 +117,7 @@ public:
public:
iso9660_stat_t *p_stat;
typedef list< ISO9660::Stat *> stat_list_t;
typedef vector< ISO9660::Stat *> stat_vector_t;
Stat(iso9660_stat_t *p_new_stat)
{
@@ -146,7 +151,7 @@ public:
{
public:
typedef list< ISO9660::Stat *> stat_list_t;
typedef vector< ISO9660::Stat *> stat_vector_t;
/*!
Given a directory pointer, find the filesystem entry that contains
@@ -157,11 +162,10 @@ public:
*/
Stat *find_lsn(lsn_t i_lsn);
/*!
Read the Primary Volume Descriptor for a CD.
True is returned if read, and false if there was an error.
/*! Read the Primary Volume Descriptor for a CD. A
PVD object is returned if read, and NULL if there was an error.
*/
bool read_pvd (/*out*/ iso9660_pvd_t *p_pvd);
PVD *read_pvd ();
/*!
Read the Super block of an ISO 9660 image. This is the
@@ -170,12 +174,12 @@ public:
*/
bool read_superblock (iso_extension_mask_t iso_extension_mask);
/*! Read psz_path (a directory) and return a list of iso9660_stat_t
/*! Read psz_path (a directory) and return a vector of iso9660_stat_t
pointers for the files inside that directory. The caller must free the
returned result.
*/
bool readdir (const char psz_path[], bool b_mode2,
stat_list_t& stat_list);
bool readdir (const char psz_path[], stat_vector_t& stat_vector,
bool b_mode2=false);
/*!
Return file status for path name psz_path. NULL is returned on
@@ -200,7 +204,7 @@ public:
{
public:
typedef list< ISO9660::Stat *> stat_list_t;
typedef vector< ISO9660::Stat *> stat_vector_t;
IFS()
{
@@ -338,11 +342,11 @@ public:
=ISO_EXTENSION_NONE,
uint16_t i_fuzz=20);
/*! Read psz_path (a directory) and return a list of iso9660_stat_t
/*! Read psz_path (a directory) and return a vector of iso9660_stat_t
pointers for the files inside that directory. The caller must free
the returned result.
*/
bool readdir (const char psz_path[], stat_list_t& stat_list);
bool readdir (const char psz_path[], stat_vector_t& stat_vector);
/*!
Seek to a position and then read n bytes. Size read is returned.
@@ -360,4 +364,7 @@ public:
};
typedef vector< ISO9660::Stat *> stat_vector_t;
typedef vector <ISO9660::Stat *>::iterator stat_vector_iterator_t;
#endif /* __ISO9660_HPP__ */

View File

@@ -1,5 +1,5 @@
/* -*- C++ -*-
$Id: iso9660.cpp,v 1.1 2006/03/07 10:46:37 rocky Exp $
$Id: iso9660.cpp,v 1.2 2006/03/07 19:55:11 rocky Exp $
Copyright (C) 2006 Rocky Bernstein <rocky@panix.com>
@@ -36,10 +36,15 @@ ISO9660::FS::find_lsn(lsn_t i_lsn)
Read the Primary Volume Descriptor for a CD.
True is returned if read, and false if there was an error.
*/
bool
ISO9660::FS::read_pvd ( /*out*/ iso9660_pvd_t *p_pvd )
ISO9660::PVD *
ISO9660::FS::read_pvd ()
{
return iso9660_fs_read_pvd ( p_cdio, p_pvd );
iso9660_pvd_t pvd;
bool b_okay = iso9660_fs_read_pvd (p_cdio, &pvd);
if (b_okay) {
return new PVD(&pvd);
}
return (PVD *) NULL;
}
/*!
@@ -58,8 +63,8 @@ ISO9660::FS::read_superblock (iso_extension_mask_t iso_extension_mask)
returned result.
*/
bool
ISO9660::FS::readdir (const char psz_path[], bool b_mode2,
stat_list_t& stat_list)
ISO9660::FS::readdir (const char psz_path[], stat_vector_t& stat_vector,
bool b_mode2)
{
CdioList_t * p_stat_list = iso9660_fs_readdir (p_cdio, psz_path,
b_mode2);
@@ -68,7 +73,7 @@ ISO9660::FS::readdir (const char psz_path[], bool b_mode2,
_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));
stat_vector.push_back(new ISO9660::Stat(p_statbuf));
}
_cdio_list_free (p_stat_list, false);
return true;
@@ -301,7 +306,7 @@ ISO9660::IFS::read_superblock_fuzzy (iso_extension_mask_t iso_extension_mask,
*/
bool
ISO9660::IFS::readdir (const char psz_path[],
stat_list_t& stat_list)
stat_vector_t& stat_vector)
{
CdioList_t *p_stat_list = iso9660_ifs_readdir (p_iso9660, psz_path);
@@ -310,7 +315,7 @@ ISO9660::IFS::readdir (const char psz_path[],
_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));
stat_vector.push_back(new ISO9660::Stat(p_statbuf));
}
_cdio_list_free (p_stat_list, false);
return true;