mirror of
https://github.com/holub/mame
synced 2025-04-23 00:39:36 +03:00
Merge pull request #1528 from npwoods/modernize_imgtool_image_info
[Imgtool] Changed imgtool::image::info() to use std::stream and std::stringstream
This commit is contained in:
commit
0d1482e04c
@ -1086,15 +1086,16 @@ imgtoolerr_t imgtool::image::create(const std::string &modulename, const char *f
|
||||
// info - returns format specific information about an image
|
||||
//-------------------------------------------------
|
||||
|
||||
imgtoolerr_t imgtool::image::info(char *string, size_t len)
|
||||
std::string imgtool::image::info()
|
||||
{
|
||||
if (len > 0)
|
||||
std::string string;
|
||||
if (module().info)
|
||||
{
|
||||
string[0] = '\0';
|
||||
if (module().info)
|
||||
module().info(*this, string, len);
|
||||
std::stringstream stream;
|
||||
module().info(*this, stream);
|
||||
string = stream.str();
|
||||
}
|
||||
return IMGTOOLERR_SUCCESS;
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
|
@ -106,7 +106,7 @@ namespace imgtool
|
||||
static imgtoolerr_t create(const std::string &modulename, const char *fname, util::option_resolution *opts);
|
||||
static UINT64 rand();
|
||||
|
||||
imgtoolerr_t info(char *string, size_t len);
|
||||
std::string info();
|
||||
imgtoolerr_t get_geometry(UINT32 *tracks, UINT32 *heads, UINT32 *sectors);
|
||||
imgtoolerr_t read_sector(UINT32 track, UINT32 head, UINT32 sector, std::vector<UINT8> &buffer);
|
||||
imgtoolerr_t write_sector(UINT32 track, UINT32 head, UINT32 sector, const void *buffer, size_t len);
|
||||
|
@ -72,7 +72,7 @@ void library::add_class(const imgtool_class *imgclass)
|
||||
module->open = (imgtoolerr_t (*)(imgtool::image &, imgtool::stream::ptr &&)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_OPEN);
|
||||
module->create = (imgtoolerr_t (*)(imgtool::image &, imgtool::stream::ptr &&, util::option_resolution *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CREATE);
|
||||
module->close = (void (*)(imgtool::image &)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CLOSE);
|
||||
module->info = (void (*)(imgtool::image &, char *, size_t)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_INFO);
|
||||
module->info = (void (*)(imgtool::image &, std::ostream &)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_INFO);
|
||||
module->read_sector = (imgtoolerr_t (*)(imgtool::image &, UINT32, UINT32, UINT32, std::vector<UINT8> &)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_READ_SECTOR);
|
||||
module->write_sector = (imgtoolerr_t (*)(imgtool::image &, UINT32, UINT32, UINT32, const void *, size_t)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_WRITE_SECTOR);
|
||||
module->get_geometry = (imgtoolerr_t (*)(imgtool::image &, UINT32 *, UINT32 *, UINT32 *))imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_GET_GEOMETRY);
|
||||
|
@ -273,7 +273,7 @@ union imgtoolinfo
|
||||
void (*close) (imgtool::image &image);
|
||||
imgtoolerr_t (*create) (imgtool::image &image, imgtool::stream::ptr &&stream, util::option_resolution *opts);
|
||||
imgtoolerr_t (*create_partition) (imgtool::image &image, UINT64 first_block, UINT64 block_count);
|
||||
void (*info) (imgtool::image &image, char *string, size_t len);
|
||||
void (*info) (imgtool::image &image, std::ostream &stream);
|
||||
imgtoolerr_t (*begin_enum) (imgtool::directory &enumeration, const char *path);
|
||||
imgtoolerr_t (*next_enum) (imgtool::directory &enumeration, imgtool_dirent &ent);
|
||||
void (*close_enum) (imgtool::directory &enumeration);
|
||||
@ -364,7 +364,7 @@ struct imgtool_module
|
||||
|
||||
imgtoolerr_t (*open) (imgtool::image &image, imgtool::stream::ptr &&stream);
|
||||
void (*close) (imgtool::image &image);
|
||||
void (*info) (imgtool::image &image, char *string, size_t len);
|
||||
void (*info) (imgtool::image &image, std::ostream &stream);
|
||||
imgtoolerr_t (*create) (imgtool::image &image, imgtool::stream::ptr &&stream, util::option_resolution *opts);
|
||||
imgtoolerr_t (*get_geometry) (imgtool::image &image, UINT32 *track, UINT32 *heads, UINT32 *sectors);
|
||||
imgtoolerr_t (*read_sector) (imgtool::image &image, UINT32 track, UINT32 head, UINT32 sector, std::vector<UINT8> &buffer);
|
||||
|
@ -181,6 +181,7 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
|
||||
char last_modified[19];
|
||||
const char *path;
|
||||
int partition_index = 0;
|
||||
std::string info;
|
||||
|
||||
// attempt to open image
|
||||
err = imgtool::image::open(argv[0], argv[1], OSD_FOPEN_READ, image);
|
||||
@ -205,9 +206,9 @@ static int cmd_dir(const struct command *c, int argc, char *argv[])
|
||||
|
||||
fprintf(stdout, "Contents of %s:%s\n", argv[1], path ? path : "");
|
||||
|
||||
image->info(buf, sizeof(buf));
|
||||
if (buf[0])
|
||||
fprintf(stdout, "%s\n", buf);
|
||||
info = image->info();
|
||||
if (!info.empty())
|
||||
fprintf(stdout, "%s\n", info.c_str());
|
||||
fprintf(stdout, "------------------------------ -------- --------------- ------------------\n");
|
||||
|
||||
while (((err = imgenum->get_next(ent)) == 0) && !ent.eof)
|
||||
|
@ -1774,7 +1774,7 @@ static void amiga_image_exit(imgtool::image &img)
|
||||
}
|
||||
|
||||
|
||||
static void amiga_image_info(imgtool::image &img, char *string, size_t len)
|
||||
static void amiga_image_info(imgtool::image &img, std::ostream &stream)
|
||||
{
|
||||
imgtoolerr_t ret;
|
||||
root_block root;
|
||||
@ -1802,7 +1802,7 @@ static void amiga_image_info(imgtool::image &img, char *string, size_t len)
|
||||
strcat(info, "\n Root modified: ");
|
||||
strcat(info, r);
|
||||
|
||||
strncpy(string, info, len);
|
||||
stream << info;
|
||||
}
|
||||
|
||||
|
||||
|
@ -128,7 +128,7 @@ struct concept_iterator
|
||||
|
||||
static imgtoolerr_t concept_image_init(imgtool::image &img, imgtool::stream::ptr &&stream);
|
||||
static void concept_image_exit(imgtool::image &img);
|
||||
static void concept_image_info(imgtool::image &img, char *string, size_t len);
|
||||
static void concept_image_info(imgtool::image &img, std::ostream &stream);
|
||||
static imgtoolerr_t concept_image_beginenum(imgtool::directory &enumeration, const char *path);
|
||||
static imgtoolerr_t concept_image_nextenum(imgtool::directory &enumeration, imgtool_dirent &ent);
|
||||
static void concept_image_closeenum(imgtool::directory &enumeration);
|
||||
@ -309,7 +309,7 @@ static void concept_image_exit(imgtool::image &img)
|
||||
|
||||
Currently returns the volume name
|
||||
*/
|
||||
static void concept_image_info(imgtool::image &img, char *string, size_t len)
|
||||
static void concept_image_info(imgtool::image &img, std::ostream &stream)
|
||||
{
|
||||
concept_image *image = get_concept_image(img);
|
||||
char vol_name[8];
|
||||
@ -317,7 +317,7 @@ static void concept_image_info(imgtool::image &img, char *string, size_t len)
|
||||
memcpy(vol_name, image->dev_dir.vol_hdr.volname + 1, image->dev_dir.vol_hdr.volname[0]);
|
||||
vol_name[image->dev_dir.vol_hdr.volname[0]] = 0;
|
||||
|
||||
snprintf(string, len, "%s", vol_name);
|
||||
stream << vol_name;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -5273,7 +5273,7 @@ static imgtoolerr_t get_comment(struct mac_l2_imgref *l2_img, UINT16 id, mac_str
|
||||
#ifdef UNUSED_FUNCTION
|
||||
static void mac_image_exit(imgtool::image *img);
|
||||
#endif
|
||||
static void mac_image_info(imgtool::image &img, char *string, size_t len);
|
||||
static void mac_image_info(imgtool::image &img, std::ostream &stream);
|
||||
static imgtoolerr_t mac_image_beginenum(imgtool::directory &enumeration, const char *path);
|
||||
static imgtoolerr_t mac_image_nextenum(imgtool::directory &enumeration, imgtool_dirent &ent);
|
||||
static imgtoolerr_t mac_image_freespace(imgtool::partition &partition, UINT64 *size);
|
||||
@ -5297,20 +5297,23 @@ static void mac_image_exit(imgtool::image *img)
|
||||
|
||||
Currently returns the volume name
|
||||
*/
|
||||
static void mac_image_info(imgtool::image &img, char *string, size_t len)
|
||||
static void mac_image_info(imgtool::image &img, std::ostream &stream)
|
||||
{
|
||||
char buffer[256] = { 0, };
|
||||
struct mac_l2_imgref *image = get_imgref(img);
|
||||
|
||||
switch (image->format)
|
||||
{
|
||||
case L2I_MFS:
|
||||
mac_to_c_strncpy(string, len, image->u.mfs.volname);
|
||||
mac_to_c_strncpy(buffer, ARRAY_LENGTH(buffer), image->u.mfs.volname);
|
||||
break;
|
||||
|
||||
case L2I_HFS:
|
||||
mac_to_c_strncpy(string, len, image->u.hfs.volname);
|
||||
mac_to_c_strncpy(buffer, ARRAY_LENGTH(buffer), image->u.hfs.volname);
|
||||
break;
|
||||
}
|
||||
|
||||
stream << buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -850,7 +850,7 @@ static imgtoolerr_t thom_write_sector(imgtool::image &img, UINT32 track,
|
||||
/* returns floopy name */
|
||||
/* actually, each side has its own name, but we only return the one on side 0.
|
||||
*/
|
||||
static void thom_info(imgtool::image &img, char *string, size_t len)
|
||||
static void thom_info(imgtool::image &img, std::ostream &stream)
|
||||
{
|
||||
thom_floppy* f = get_thom_floppy(img);
|
||||
UINT8* base = thom_get_sector( f, 0, 20, 1 );
|
||||
@ -858,7 +858,7 @@ static void thom_info(imgtool::image &img, char *string, size_t len)
|
||||
memcpy( buf, base, 8 );
|
||||
buf[8] = 0;
|
||||
thom_stringify( buf );
|
||||
strncpy( string, buf, len );
|
||||
stream << buf;
|
||||
}
|
||||
|
||||
/* each side of a floppy has its own filesystem, we treat them as'partitions'
|
||||
|
@ -3859,7 +3859,7 @@ static imgtoolerr_t dsk_image_init_pc99_fm(imgtool::image &image, imgtool::strea
|
||||
static imgtoolerr_t dsk_image_init_pc99_mfm(imgtool::image &image, imgtool::stream::ptr &&stream);
|
||||
static imgtoolerr_t win_image_init(imgtool::image &image, imgtool::stream::ptr &&stream);
|
||||
static void ti99_image_exit(imgtool::image &img);
|
||||
static void ti99_image_info(imgtool::image &img, char *string, size_t len);
|
||||
static void ti99_image_info(imgtool::image &img, std::ostream &stream);
|
||||
static imgtoolerr_t dsk_image_beginenum(imgtool::directory &enumeration, const char *path);
|
||||
static imgtoolerr_t dsk_image_nextenum(imgtool::directory &enumeration, imgtool_dirent &ent);
|
||||
static imgtoolerr_t win_image_beginenum(imgtool::directory &enumeration, const char *path);
|
||||
@ -4201,14 +4201,14 @@ static void ti99_image_exit(imgtool::image &img)
|
||||
|
||||
Currently returns the volume name
|
||||
*/
|
||||
static void ti99_image_info(imgtool::image &img, char *string, size_t len)
|
||||
static void ti99_image_info(imgtool::image &img, std::ostream &stream)
|
||||
{
|
||||
struct ti99_lvl2_imgref *image = get_lvl2_imgref(img);
|
||||
char vol_name[11];
|
||||
|
||||
fname_to_str(vol_name, image->vol_name, 11);
|
||||
|
||||
snprintf(string, len, "%s", vol_name);
|
||||
stream << vol_name;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -393,7 +393,7 @@ static ti990_image *get_ti990_image(imgtool::image &image)
|
||||
|
||||
static imgtoolerr_t ti990_image_init(imgtool::image &img, imgtool::stream::ptr &&stream);
|
||||
static void ti990_image_exit(imgtool::image &img);
|
||||
static void ti990_image_info(imgtool::image &img, char *string, size_t len);
|
||||
static void ti990_image_info(imgtool::image &img, std::ostream &stream);
|
||||
static imgtoolerr_t ti990_image_beginenum(imgtool::directory &enumeration, const char *path);
|
||||
static imgtoolerr_t ti990_image_nextenum(imgtool::directory &enumeration, imgtool_dirent &ent);
|
||||
static void ti990_image_closeenum(imgtool::directory &enumeration);
|
||||
@ -1179,14 +1179,14 @@ static void ti990_image_exit(imgtool::image &img)
|
||||
|
||||
Currently returns the volume name
|
||||
*/
|
||||
static void ti990_image_info(imgtool::image &img, char *string, size_t len)
|
||||
static void ti990_image_info(imgtool::image &img, std::ostream &stream)
|
||||
{
|
||||
ti990_image *image = get_ti990_image(img);
|
||||
char vol_name[9];
|
||||
|
||||
fname_to_str(vol_name, image->sec0.vnm, 9);
|
||||
|
||||
snprintf(string, len, "%s", vol_name);
|
||||
stream << vol_name;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user