summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2016-03-06 18:02:37 +1100
committer Vas Crabb <vas@vastheman.com>2016-03-06 21:49:56 +1100
commit73b44c94291c4d086477167a76fd7db239936c3b (patch)
tree9af214e443878f4b1e6452d63393ca9f9f8a0884 /src/tools
parent00941faaab99d937a32bce4d225ec56951d21020 (diff)
Turn core_file into a proper class that gets cleaned up safely using unique_ptr
Subverted somewhat by chd_file class
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/chdman.cpp178
-rw-r--r--src/tools/imgtool/stream.cpp237
-rw-r--r--src/tools/imgtool/stream.h2
-rw-r--r--src/tools/ldresample.cpp2
-rw-r--r--src/tools/pngcmp.cpp20
-rw-r--r--src/tools/regrep.cpp140
-rw-r--r--src/tools/split.cpp68
-rw-r--r--src/tools/src2html.cpp92
-rw-r--r--src/tools/unidasm.cpp2
9 files changed, 344 insertions, 397 deletions
diff --git a/src/tools/chdman.cpp b/src/tools/chdman.cpp
index 94ea358e825..5c7e88c233e 100644
--- a/src/tools/chdman.cpp
+++ b/src/tools/chdman.cpp
@@ -187,10 +187,10 @@ class chd_rawfile_compressor : public chd_file_compressor
{
public:
// construction/destruction
- chd_rawfile_compressor(core_file *file, UINT64 offset = 0, UINT64 maxoffset = ~0)
+ chd_rawfile_compressor(util::core_file &file, UINT64 offset = 0, UINT64 maxoffset = ~0)
: m_file(file),
m_offset(offset),
- m_maxoffset(MIN(maxoffset, (file != nullptr) ? core_fsize(file) : 0)) { }
+ m_maxoffset((std::min)(maxoffset, file.size())) { }
// read interface
virtual UINT32 read_data(void *dest, UINT64 offset, UINT32 length)
@@ -200,15 +200,15 @@ public:
return 0;
if (offset + length > m_maxoffset)
length = m_maxoffset - offset;
- core_fseek(m_file, offset, SEEK_SET);
- return core_fread(m_file, dest, length);
+ m_file.seek(offset, SEEK_SET);
+ return m_file.read(dest, length);
}
private:
// internal state
- core_file * m_file;
- UINT64 m_offset;
- UINT64 m_maxoffset;
+ util::core_file & m_file;
+ UINT64 m_offset;
+ UINT64 m_maxoffset;
};
@@ -290,14 +290,12 @@ class chd_cd_compressor : public chd_file_compressor
public:
// construction/destruction
chd_cd_compressor(cdrom_toc &toc, chdcd_track_input_info &info)
- : m_file(nullptr),
+ : m_file(),
m_toc(toc),
m_info(info) { }
~chd_cd_compressor()
{
- if (m_file != nullptr)
- core_fclose(m_file);
}
// read interface
@@ -321,12 +319,11 @@ public:
if (offset >= startoffs && offset < endoffs)
{
// if we don't already have this file open, open it now
- if (m_file == nullptr || m_lastfile.compare(m_info.track[tracknum].fname)!=0)
+ if (!m_file || m_lastfile.compare(m_info.track[tracknum].fname)!=0)
{
- if (m_file != nullptr)
- core_fclose(m_file);
+ m_file.reset();
m_lastfile = m_info.track[tracknum].fname;
- file_error filerr = core_fopen(m_lastfile.c_str(), OPEN_FLAG_READ, &m_file);
+ file_error filerr = util::core_file::open(m_lastfile.c_str(), OPEN_FLAG_READ, m_file);
if (filerr != FILERR_NONE)
report_error(1, "Error opening input file (%s)'", m_lastfile.c_str());
}
@@ -349,8 +346,8 @@ public:
}
else
{
- core_fseek(m_file, src_frame_start, SEEK_SET);
- UINT32 count = core_fread(m_file, dest, bytesperframe);
+ m_file->seek(src_frame_start, SEEK_SET);
+ UINT32 count = m_file->read(dest, bytesperframe);
if (count != bytesperframe)
report_error(1, "Error reading input file (%s)'", m_lastfile.c_str());
}
@@ -383,7 +380,7 @@ public:
private:
// internal state
std::string m_lastfile;
- core_file * m_file;
+ util::core_file::ptr m_file;
cdrom_toc & m_toc;
chdcd_track_input_info & m_info;
};
@@ -1008,11 +1005,11 @@ static void check_existing_output_file(const parameters_t &params, const char *f
{
if (params.find(OPTION_OUTPUT_FORCE) == params.end())
{
- core_file *file;
- file_error filerr = core_fopen(filename, OPEN_FLAG_READ, &file);
+ util::core_file::ptr file;
+ file_error filerr = util::core_file::open(filename, OPEN_FLAG_READ, file);
if (filerr == FILERR_NONE)
{
- core_fclose(file);
+ file.reset();
report_error(1, "Error: file already exists (%s)\nUse --force (or -f) to force overwriting", filename);
}
}
@@ -1185,7 +1182,7 @@ static void compress_common(chd_file_compressor &chd)
// to a CUE file
//-------------------------------------------------
-void output_track_metadata(int mode, core_file *file, int tracknum, const cdrom_track_info &info, const char *filename, UINT32 frameoffs, UINT64 discoffs)
+void output_track_metadata(int mode, util::core_file &file, int tracknum, const cdrom_track_info &info, const char *filename, UINT32 frameoffs, UINT64 discoffs)
{
if (mode == MODE_GDI)
{
@@ -1234,13 +1231,13 @@ void output_track_metadata(int mode, core_file *file, int tracknum, const cdrom_
break;
}
bool needquote = strchr(filename, ' ') != nullptr;
- core_fprintf(file, "%d %d %d %d %s%s%s %" I64FMT "d\n", tracknum+1, frameoffs, mode, size, needquote?"\"":"", filename, needquote?"\"":"", discoffs);
+ file.printf("%d %d %d %d %s%s%s %" I64FMT "d\n", tracknum+1, frameoffs, mode, size, needquote?"\"":"", filename, needquote?"\"":"", discoffs);
}
else if (mode == MODE_CUEBIN)
{
// first track specifies the file
if (tracknum == 0)
- core_fprintf(file, "FILE \"%s\" BINARY\n", filename);
+ file.printf("FILE \"%s\" BINARY\n", filename);
// determine submode
std::string tempstr;
@@ -1265,37 +1262,37 @@ void output_track_metadata(int mode, core_file *file, int tracknum, const cdrom_
}
// output TRACK entry
- core_fprintf(file, " TRACK %02d %s\n", tracknum + 1, tempstr.c_str());
+ file.printf(" TRACK %02d %s\n", tracknum + 1, tempstr.c_str());
// output PREGAP tag if pregap sectors are not in the file
if ((info.pregap > 0) && (info.pgdatasize == 0))
{
- core_fprintf(file, " PREGAP %s\n", msf_string_from_frames(tempstr, info.pregap));
- core_fprintf(file, " INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs));
+ file.printf(" PREGAP %s\n", msf_string_from_frames(tempstr, info.pregap));
+ file.printf(" INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs));
}
else if ((info.pregap > 0) && (info.pgdatasize > 0))
{
- core_fprintf(file, " INDEX 00 %s\n", msf_string_from_frames(tempstr, frameoffs));
- core_fprintf(file, " INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs+info.pregap));
+ file.printf(" INDEX 00 %s\n", msf_string_from_frames(tempstr, frameoffs));
+ file.printf(" INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs+info.pregap));
}
// if no pregap at all, output index 01 only
if (info.pregap == 0)
{
- core_fprintf(file, " INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs));
+ file.printf(" INDEX 01 %s\n", msf_string_from_frames(tempstr, frameoffs));
}
// output POSTGAP
if (info.postgap > 0)
- core_fprintf(file, " POSTGAP %s\n", msf_string_from_frames(tempstr, info.postgap));
+ file.printf(" POSTGAP %s\n", msf_string_from_frames(tempstr, info.postgap));
}
// non-CUE mode
else if (mode == MODE_NORMAL)
{
// header on the first track
if (tracknum == 0)
- core_fprintf(file, "CD_ROM\n\n\n");
- core_fprintf(file, "// Track %d\n", tracknum + 1);
+ file.printf("CD_ROM\n\n\n");
+ file.printf("// Track %d\n", tracknum + 1);
// write out the track type
std::string modesubmode;
@@ -1303,32 +1300,32 @@ void output_track_metadata(int mode, core_file *file, int tracknum, const cdrom_
modesubmode = string_format("%s %s", cdrom_get_type_string(info.trktype), cdrom_get_subtype_string(info.subtype));
else
modesubmode = string_format("%s", cdrom_get_type_string(info.trktype));
- core_fprintf(file, "TRACK %s\n", modesubmode.c_str());
+ file.printf("TRACK %s\n", modesubmode.c_str());
// write out the attributes
- core_fprintf(file, "NO COPY\n");
+ file.printf("NO COPY\n");
if (info.trktype == CD_TRACK_AUDIO)
{
- core_fprintf(file, "NO PRE_EMPHASIS\n");
- core_fprintf(file, "TWO_CHANNEL_AUDIO\n");
+ file.printf("NO PRE_EMPHASIS\n");
+ file.printf("TWO_CHANNEL_AUDIO\n");
}
// output pregap
std::string tempstr;
if (info.pregap > 0)
- core_fprintf(file, "ZERO %s %s\n", modesubmode.c_str(), msf_string_from_frames(tempstr, info.pregap));
+ file.printf("ZERO %s %s\n", modesubmode.c_str(), msf_string_from_frames(tempstr, info.pregap));
// all tracks but the first one have a file offset
if (tracknum > 0)
- core_fprintf(file, "DATAFILE \"%s\" #%d %s // length in bytes: %d\n", filename, UINT32(discoffs), msf_string_from_frames(tempstr, info.frames), info.frames * (info.datasize + info.subsize));
+ file.printf("DATAFILE \"%s\" #%d %s // length in bytes: %d\n", filename, UINT32(discoffs), msf_string_from_frames(tempstr, info.frames), info.frames * (info.datasize + info.subsize));
else
- core_fprintf(file, "DATAFILE \"%s\" %s // length in bytes: %d\n", filename, msf_string_from_frames(tempstr, info.frames), info.frames * (info.datasize + info.subsize));
+ file.printf("DATAFILE \"%s\" %s // length in bytes: %d\n", filename, msf_string_from_frames(tempstr, info.frames), info.frames * (info.datasize + info.subsize));
// tracks with pregaps get a START marker too
if (info.pregap > 0)
- core_fprintf(file, "START %s\n", msf_string_from_frames(tempstr, info.pregap));
+ file.printf("START %s\n", msf_string_from_frames(tempstr, info.pregap));
- core_fprintf(file, "\n\n");
+ file.printf("\n\n");
}
}
@@ -1361,9 +1358,9 @@ static void do_info(parameters_t &params)
printf("Unit Size: %s bytes\n", big_int_string(tempstr, input_chd.unit_bytes()));
printf("Total Units: %s\n", big_int_string(tempstr, input_chd.unit_count()));
printf("Compression: %s\n", compression_string(tempstr, compression));
- printf("CHD size: %s bytes\n", big_int_string(tempstr, core_fsize(input_chd)));
+ printf("CHD size: %s bytes\n", big_int_string(tempstr, static_cast<util::core_file &>(input_chd).size()));
if (compression[0] != CHD_CODEC_NONE)
- printf("Ratio: %.1f%%\n", 100.0 * double(core_fsize(input_chd)) / double(input_chd.logical_bytes()));
+ printf("Ratio: %.1f%%\n", 100.0 * double(static_cast<util::core_file &>(input_chd).size()) / double(input_chd.logical_bytes()));
// add SHA1 output
sha1_t overall = input_chd.sha1();
@@ -1570,11 +1567,11 @@ static void do_verify(parameters_t &params)
static void do_create_raw(parameters_t &params)
{
// process input file
- core_file *input_file = nullptr;
+ util::core_file::ptr input_file;
auto input_file_str = params.find(OPTION_INPUT);
if (input_file_str != params.end())
{
- file_error filerr = core_fopen(input_file_str->second->c_str(), OPEN_FLAG_READ, &input_file);
+ file_error filerr = util::core_file::open(input_file_str->second->c_str(), OPEN_FLAG_READ, input_file);
if (filerr != FILERR_NONE)
report_error(1, "Unable to open file (%s)", input_file_str->second->c_str());
}
@@ -1600,7 +1597,7 @@ static void do_create_raw(parameters_t &params)
// process input start/end (needs to know hunk_size)
UINT64 input_start;
UINT64 input_end;
- parse_input_start_end(params, core_fsize(input_file), hunk_size, hunk_size, input_start, input_end);
+ parse_input_start_end(params, input_file->size(), hunk_size, hunk_size, input_start, input_end);
// process compression
chd_codec_type compression[4];
@@ -1616,7 +1613,7 @@ static void do_create_raw(parameters_t &params)
if (output_parent.opened())
printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str());
printf("Input file: %s\n", input_file_str->second->c_str());
- if (input_start != 0 || input_end != core_fsize(input_file))
+ if (input_start != 0 || input_end != input_file->size())
{
printf("Input start: %s\n", big_int_string(tempstr, input_start));
printf("Input length: %s\n", big_int_string(tempstr, input_end - input_start));
@@ -1630,7 +1627,7 @@ static void do_create_raw(parameters_t &params)
try
{
// create the new CHD
- chd = new chd_rawfile_compressor(input_file, input_start, input_end);
+ chd = new chd_rawfile_compressor(*input_file, input_start, input_end);
chd_error err;
if (output_parent.opened())
err = chd->create(output_chd_str->c_str(), input_end - input_start, hunk_size, compression, output_parent);
@@ -1667,11 +1664,11 @@ static void do_create_raw(parameters_t &params)
static void do_create_hd(parameters_t &params)
{
// process input file
- core_file *input_file = nullptr;
+ util::core_file::ptr input_file;
auto input_file_str = params.find(OPTION_INPUT);
if (input_file_str != params.end())
{
- file_error filerr = core_fopen(input_file_str->second->c_str(), OPEN_FLAG_READ, &input_file);
+ file_error filerr = util::core_file::open(input_file_str->second->c_str(), OPEN_FLAG_READ, input_file);
if (filerr != FILERR_NONE)
report_error(1, "Unable to open file (%s)", input_file_str->second->c_str());
}
@@ -1698,9 +1695,9 @@ static void do_create_hd(parameters_t &params)
UINT64 filesize = 0;
UINT64 input_start = 0;
UINT64 input_end = 0;
- if (input_file != nullptr)
+ if (input_file)
{
- parse_input_start_end(params, core_fsize(input_file), hunk_size, hunk_size, input_start, input_end);
+ parse_input_start_end(params, input_file->size(), hunk_size, hunk_size, input_start, input_end);
filesize = input_end - input_start;
}
else
@@ -1716,10 +1713,10 @@ static void do_create_hd(parameters_t &params)
// process compression
chd_codec_type compression[4];
memcpy(compression, s_default_hd_compression, sizeof(compression));
- if (input_file == nullptr)
+ if (!input_file)
compression[0] = compression[1] = compression[2] = compression[3] = CHD_CODEC_NONE;
parse_compression(params, compression);
- if (input_file == nullptr && compression[0] != CHD_CODEC_NONE)
+ if (!input_file && compression[0] != CHD_CODEC_NONE)
report_error(1, "Blank hard disks must be uncompressed");
// process numprocessors
@@ -1746,7 +1743,7 @@ static void do_create_hd(parameters_t &params)
if (ident_str != params.end())
{
// load the file
- file_error filerr = core_fload(ident_str->second->c_str(), identdata);
+ file_error filerr = util::core_file::load(ident_str->second->c_str(), identdata);
if (filerr != FILERR_NONE)
report_error(1, "Error reading ident file (%s)", ident_str->second->c_str());
@@ -1775,7 +1772,7 @@ static void do_create_hd(parameters_t &params)
// if no CHS values, try to guess them
if (cylinders == 0)
{
- if (input_file == nullptr && filesize == 0)
+ if (!input_file && filesize == 0)
report_error(1, "Blank hard drives must specify either a length or a set of CHS values");
guess_chs((input_file_str != params.end()) ? input_file_str->second : nullptr, filesize, sector_size, cylinders, heads, sectors, sector_size);
}
@@ -1786,10 +1783,10 @@ static void do_create_hd(parameters_t &params)
printf("Output CHD: %s\n", output_chd_str->c_str());
if (output_parent.opened())
printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->second->c_str());
- if (input_file != nullptr)
+ if (input_file)
{
printf("Input file: %s\n", input_file_str->second->c_str());
- if (input_start != 0 || input_end != core_fsize(input_file))
+ if (input_start != 0 || input_end != input_file->size())
{
printf("Input start: %s\n", big_int_string(tempstr, input_start));
printf("Input length: %s\n", big_int_string(tempstr, filesize));
@@ -1808,7 +1805,7 @@ static void do_create_hd(parameters_t &params)
try
{
// create the new hard drive
- chd = new chd_rawfile_compressor(input_file, input_start, input_end);
+ chd = new chd_rawfile_compressor(*input_file, input_start, input_end);
chd_error err;
if (output_parent.opened())
err = chd->create(output_chd_str->c_str(), UINT64(totalsectors) * UINT64(sector_size), hunk_size, compression, output_parent);
@@ -1832,7 +1829,7 @@ static void do_create_hd(parameters_t &params)
}
// compress it generically
- if (input_file != nullptr)
+ if (input_file)
compress_common(*chd);
delete chd;
}
@@ -2236,11 +2233,11 @@ static void do_extract_raw(parameters_t &params)
}
// catch errors so we can close & delete the output file
- core_file *output_file = nullptr;
+ util::core_file::ptr output_file;
try
{
// process output file
- file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file);
+ file_error filerr = util::core_file::open(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_file);
if (filerr != FILERR_NONE)
report_error(1, "Unable to open file (%s)", output_file_str->second->c_str());
@@ -2257,7 +2254,7 @@ static void do_extract_raw(parameters_t &params)
report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err));
// write to the output
- UINT32 count = core_fwrite(output_file, &buffer[0], bytes_to_read);
+ UINT32 count = output_file->write(&buffer[0], bytes_to_read);
if (count != bytes_to_read)
report_error(1, "Error writing to file; check disk space (%s)", output_file_str->second->c_str());
@@ -2266,7 +2263,7 @@ static void do_extract_raw(parameters_t &params)
}
// finish up
- core_fclose(output_file);
+ output_file.reset();
printf("Extraction complete \n");
}
catch (...)
@@ -2274,7 +2271,7 @@ static void do_extract_raw(parameters_t &params)
// delete the output file
if (output_file != nullptr)
{
- core_fclose(output_file);
+ output_file.reset();
osd_rmfile(output_file_str->second->c_str());
}
throw;
@@ -2329,8 +2326,8 @@ static void do_extract_cd(parameters_t &params)
printf("Input CHD: %s\n", params.find(OPTION_INPUT)->second->c_str());
// catch errors so we can close & delete the output file
- core_file *output_bin_file = nullptr;
- core_file *output_toc_file = nullptr;
+ util::core_file::ptr output_bin_file;
+ util::core_file::ptr output_toc_file;
try
{
int mode = MODE_NORMAL;
@@ -2345,14 +2342,14 @@ static void do_extract_cd(parameters_t &params)
}
// process output file
- file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &output_toc_file);
+ file_error filerr = util::core_file::open(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, output_toc_file);
if (filerr != FILERR_NONE)
report_error(1, "Unable to open file (%s)", output_file_str->second->c_str());
// process output BIN file
if (mode != MODE_GDI)
{
- filerr = core_fopen(output_bin_file_str->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_bin_file);
+ filerr = util::core_file::open(output_bin_file_str->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_bin_file);
if (filerr != FILERR_NONE)
report_error(1, "Unable to open file (%s)", output_bin_file_str->c_str());
}
@@ -2365,7 +2362,7 @@ static void do_extract_cd(parameters_t &params)
// GDI must start with the # of tracks
if (mode == MODE_GDI)
{
- core_fprintf(output_toc_file, "%d\n", toc->numtrks);
+ output_toc_file->printf("%d\n", toc->numtrks);
}
// iterate over tracks and copy all data
@@ -2386,13 +2383,9 @@ static void do_extract_cd(parameters_t &params)
else
trackbin_name.append(".bin");
- if (output_bin_file)
- {
- core_fclose(output_bin_file);
- output_bin_file = nullptr;
- }
+ output_bin_file.reset();
- filerr = core_fopen(trackbin_name.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_bin_file);
+ filerr = util::core_file::open(trackbin_name.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_bin_file);
if (filerr != FILERR_NONE)
report_error(1, "Unable to open file (%s)", trackbin_name.c_str());
@@ -2403,11 +2396,11 @@ static void do_extract_cd(parameters_t &params)
const cdrom_track_info &trackinfo = toc->tracks[tracknum];
if (mode == MODE_GDI)
{
- output_track_metadata(mode, output_toc_file, tracknum, trackinfo, core_filename_extract_base(trackbin_name.c_str()).c_str(), discoffs, outputoffs);
+ output_track_metadata(mode, *output_toc_file, tracknum, trackinfo, core_filename_extract_base(trackbin_name.c_str()).c_str(), discoffs, outputoffs);
}
else
{
- output_track_metadata(mode, output_toc_file, tracknum, trackinfo, core_filename_extract_base(output_bin_file_str->c_str()).c_str(), discoffs, outputoffs);
+ output_track_metadata(mode, *output_toc_file, tracknum, trackinfo, core_filename_extract_base(output_bin_file_str->c_str()).c_str(), discoffs, outputoffs);
}
// If this is bin/cue output and the CHD contains subdata, warn the user and don't include
@@ -2455,8 +2448,8 @@ static void do_extract_cd(parameters_t &params)
// write it out if we need to
if (bufferoffs == buffer.size() || frame == actualframes - 1)
{
- core_fseek(output_bin_file, outputoffs, SEEK_SET);
- UINT32 byteswritten = core_fwrite(output_bin_file, &buffer[0], bufferoffs);
+ output_bin_file->seek(outputoffs, SEEK_SET);
+ UINT32 byteswritten = output_bin_file->write(&buffer[0], bufferoffs);
if (byteswritten != bufferoffs)
report_error(1, "Error writing frame %d to file (%s): %s\n", frame, output_file_str->second->c_str(), chd_file::error_string(CHDERR_WRITE_ERROR));
outputoffs += bufferoffs;
@@ -2468,17 +2461,15 @@ static void do_extract_cd(parameters_t &params)
}
// finish up
- core_fclose(output_bin_file);
- core_fclose(output_toc_file);
+ output_bin_file.reset();
+ output_toc_file.reset();
printf("Extraction complete \n");
}
catch (...)
{
// delete the output files
- if (output_bin_file != nullptr)
- core_fclose(output_bin_file);
- if (output_toc_file != nullptr)
- core_fclose(output_toc_file);
+ output_bin_file.reset();
+ output_toc_file.reset();
osd_rmfile(output_bin_file_str->c_str());
osd_rmfile(output_file_str->second->c_str());
throw;
@@ -2600,7 +2591,7 @@ static void do_extract_ld(parameters_t &params)
chd_error err = input_chd.read_hunk(framenum, nullptr);
if (err != CHDERR_NONE)
{
- UINT64 filepos = core_ftell(input_chd);
+ UINT64 filepos = static_cast<util::core_file &>(input_chd).tell();
report_error(1, "Error reading hunk %" I64FMT "d at offset %" I64FMT "d from CHD file (%s): %s\n", framenum, filepos, params.find(OPTION_INPUT)->second->c_str(), chd_file::error_string(err));
}
@@ -2678,7 +2669,7 @@ static void do_add_metadata(parameters_t &params)
dynamic_buffer file;
if (file_str != params.end())
{
- file_error filerr = core_fload(file_str->second->c_str(), file);
+ file_error filerr = util::core_file::load(file_str->second->c_str(), file);
if (filerr != FILERR_NONE)
report_error(1, "Error reading metadata file (%s)", file_str->second->c_str());
}
@@ -2796,21 +2787,21 @@ static void do_dump_metadata(parameters_t &params)
report_error(1, "Error reading metadata: %s", chd_file::error_string(err));
// catch errors so we can close & delete the output file
- core_file *output_file = nullptr;
+ util::core_file::ptr output_file;
try
{
// create the file
if (output_file_str != params.end())
{
- file_error filerr = core_fopen(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file);
+ file_error filerr = util::core_file::open(output_file_str->second->c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, output_file);
if (filerr != FILERR_NONE)
report_error(1, "Unable to open file (%s)", output_file_str->second->c_str());
// output the metadata
- UINT32 count = core_fwrite(output_file, &buffer[0], buffer.size());
+ UINT32 count = output_file->write(&buffer[0], buffer.size());
if (count != buffer.size())
report_error(1, "Error writing file (%s)", output_file_str->second->c_str());
- core_fclose(output_file);
+ output_file.reset();
// provide some feedback
std::string tempstr;
@@ -2827,8 +2818,7 @@ static void do_dump_metadata(parameters_t &params)
catch (...)
{
// delete the output file
- if (output_file != nullptr)
- core_fclose(output_file);
+ output_file.reset();
osd_rmfile(output_file_str->second->c_str());
throw;
}
diff --git a/src/tools/imgtool/stream.cpp b/src/tools/imgtool/stream.cpp
index 461d2fd99bd..4cc4c9ec2db 100644
--- a/src/tools/imgtool/stream.cpp
+++ b/src/tools/imgtool/stream.cpp
@@ -24,78 +24,112 @@ enum imgtype_t
struct imgtool_stream
{
- imgtype_t imgtype;
- int write_protect;
- const char *name; // needed for clear
- UINT64 position;
- UINT64 filesize;
+ typedef std::unique_ptr<imgtool_stream> ptr;
+
+ imgtool_stream(bool wp)
+ : imgtype(IMG_FILE)
+ , write_protect(wp)
+ , name(nullptr)
+ , position(0)
+ , filesize(0)
+ , file()
+ , buffer(nullptr)
+ {
+ }
+
+ imgtool_stream(
+ bool wp,
+ util::core_file::ptr &&f)
+ : imgtype(IMG_FILE)
+ , write_protect(wp)
+ , name(nullptr)
+ , position(0)
+ , filesize(f->size())
+ , file(std::move(f))
+ , buffer(nullptr)
+ {
+ }
+
+ imgtool_stream(bool wp, std::size_t size)
+ : imgtype(IMG_MEM)
+ , write_protect(wp)
+ , name(nullptr)
+ , position(0)
+ , filesize(size)
+ , file()
+ , buffer(reinterpret_cast<std::uint8_t *>(malloc(size)))
+ {
+ }
+
+ imgtool_stream(bool wp, std::size_t size, void *buf)
+ : imgtype(IMG_MEM)
+ , write_protect(wp)
+ , name(nullptr)
+ , position(0)
+ , filesize(size)
+ , file()
+ , buffer(reinterpret_cast<std::uint8_t *>(buf))
+ {
+ }
- union
+ ~imgtool_stream()
{
- core_file *file;
- UINT8 *buffer;
- } u;
+ free(buffer);
+ }
+
+ imgtype_t imgtype;
+ bool write_protect;
+ const char *name; // needed for clear
+ std::uint64_t position;
+ std::uint64_t filesize;
+
+ util::core_file::ptr file;
+ std::uint8_t *buffer;
};
static imgtool_stream *stream_open_zip(const char *zipname, const char *subname, int read_or_write)
{
- imgtool_stream *imgfile = nullptr;
-// zip_error ziperr;
- zip_file *z = nullptr;
- const zip_file_header *zipent;
- FILE *f;
-
if (read_or_write)
- goto error;
+ return nullptr;
/* check to see if the file exists */
- f = fopen(zipname, "r");
+ FILE *f = fopen(zipname, "r");
if (!f)
- goto error;
+ return nullptr;
fclose(f);
- imgfile = (imgtool_stream *)malloc(sizeof(imgtool_stream));
- if (!imgfile)
- goto error;
+ imgtool_stream::ptr imgfile(new imgtool_stream(true));
- memset(imgfile, 0, sizeof(*imgfile));
imgfile->imgtype = IMG_MEM;
- imgfile->write_protect = 1;
- imgfile->position = 0;
-// ziperr =
+ zip_file *z = nullptr;
+ const zip_file_header *zipent = nullptr;
zip_file_open(zipname, &z);
if (!z)
goto error;
zipent = zip_file_first_file(z);
- while(zipent && subname && strcmp(subname, zipent->filename))
+ while (zipent && subname && strcmp(subname, zipent->filename))
zipent = zip_file_next_file(z);
if (!zipent)
goto error;
imgfile->filesize = zipent->uncompressed_length;
- imgfile->u.buffer = (UINT8*)malloc(zipent->uncompressed_length);
- if (!imgfile->u.buffer)
+ imgfile->buffer = reinterpret_cast<std::uint8_t *>(malloc(zipent->uncompressed_length));
+ if (!imgfile->buffer)
goto error;
- if (zip_file_decompress(z, imgfile->u.buffer, zipent->uncompressed_length))
+ if (zip_file_decompress(z, imgfile->buffer, zipent->uncompressed_length))
goto error;
zip_file_close(z);
- return imgfile;
+ return imgfile.release();
error:
if (z)
zip_file_close(z);
- if (imgfile)
- {
- if (imgfile->u.buffer)
- free(imgfile->u.buffer);
- free(imgfile);
- }
return nullptr;
}
@@ -103,9 +137,6 @@ error:
imgtool_stream *stream_open(const char *fname, int read_or_write)
{
- file_error filerr;
- const char *ext;
- imgtool_stream *imgfile = nullptr;
static const UINT32 write_modes[] =
{
OPEN_FLAG_READ,
@@ -113,118 +144,70 @@ imgtool_stream *stream_open(const char *fname, int read_or_write)
OPEN_FLAG_READ | OPEN_FLAG_WRITE,
OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE
};
- core_file *f = nullptr;
- char *buf = nullptr;
- int len, i;
imgtool_stream *s = nullptr;
char c;
/* maybe we are just a ZIP? */
- ext = strrchr(fname, '.');
+ const char *ext = strrchr(fname, '.');
if (ext && !core_stricmp(ext, ".zip"))
return stream_open_zip(fname, nullptr, read_or_write);
- filerr = core_fopen(fname, write_modes[read_or_write], &f);
+ util::core_file::ptr f = nullptr;
+ auto const filerr = util::core_file::open(fname, write_modes[read_or_write], f);
if (filerr != FILERR_NONE)
{
if (!read_or_write)
{
- len = strlen(fname);
+ int const len = strlen(fname);
/* can't open the file; try opening ZIP files with other names */
- buf = (char*)malloc(len + 1);
- if (!buf)
- goto error;
- strcpy(buf, fname);
+ std::vector<char> buf(len + 1);
+ strcpy(&buf[0], fname);
- for(i = len-1; !s && (i >= 0); i--)
+ for (int i = len-1; !s && (i >= 0); i--)
{
if ((buf[i] == '\\') || (buf[i] == '/'))
{
c = buf[i];
buf[i] = '\0';
- s = stream_open_zip(buf, buf + i + 1, read_or_write);
+ s = stream_open_zip(&buf[0], &buf[i + 1], read_or_write);
buf[i] = c;
}
}
- free(buf);
- buf = nullptr;
if (s)
return s;
}
/* ah well, it was worth a shot */
- goto error;
+ return nullptr;
}
- imgfile = (imgtool_stream *)malloc(sizeof(imgtool_stream));
- if (!imgfile)
- goto error;
+ imgtool_stream::ptr imgfile(new imgtool_stream(read_or_write ? false : true, std::move(f)));
/* Normal file */
- memset(imgfile, 0, sizeof(*imgfile));
- imgfile->imgtype = IMG_FILE;
- imgfile->position = 0;
- imgfile->filesize = core_fsize(f);
- imgfile->write_protect = read_or_write ? 0 : 1;
- imgfile->u.file = f;
imgfile->name = fname;
- return imgfile;
-
-error:
- if (imgfile != nullptr)
- free((void *) imgfile);
- if (f != nullptr)
- core_fclose(f);
- if (buf)
- free(buf);
- return (imgtool_stream *) nullptr;
+ return imgfile.release();
}
imgtool_stream *stream_open_write_stream(int size)
{
- imgtool_stream *imgfile;
-
- imgfile = (imgtool_stream *)malloc(sizeof(imgtool_stream));
- if (!imgfile)
- return nullptr;
-
- imgfile->imgtype = IMG_MEM;
- imgfile->write_protect = 0;
- imgfile->position = 0;
- imgfile->filesize = size;
- imgfile->u.buffer = (UINT8*)malloc(size);
-
- if (!imgfile->u.buffer)
- {
- free(imgfile);
+ imgtool_stream::ptr imgfile(new imgtool_stream(false, size));
+ if (!imgfile->buffer)
return nullptr;
- }
- return imgfile;
+ return imgfile.release();
}
imgtool_stream *stream_open_mem(void *buf, size_t sz)
{
- imgtool_stream *imgfile;
-
- imgfile = (imgtool_stream *)malloc(sizeof(imgtool_stream));
- if (!imgfile)
- return nullptr;
+ imgtool_stream::ptr imgfile(new imgtool_stream(false, sz, buf));
- memset(imgfile, 0, sizeof(*imgfile));
- imgfile->imgtype = IMG_MEM;
- imgfile->position = 0;
- imgfile->write_protect = 0;
-
- imgfile->filesize = sz;
- imgfile->u.buffer = (UINT8*)buf;
- return imgfile;
+ return imgfile.release();
}
@@ -233,36 +216,14 @@ void stream_close(imgtool_stream *s)
{
assert(s != nullptr);
- switch(s->imgtype)
- {
- case IMG_FILE:
- if (s->u.file != nullptr)
- {
- core_fclose(s->u.file);
- s->u.file = nullptr;
- }
- break;
-
- case IMG_MEM:
- if (s->u.buffer != nullptr)
- {
- free(s->u.buffer);
- s->u.buffer = nullptr;
- }
- break;
-
- default:
- assert(0);
- break;
- }
- free((void *) s);
+ delete s;
}
-core_file *stream_core_file(imgtool_stream *stream)
+util::core_file *stream_core_file(imgtool_stream *stream)
{
- return (stream->imgtype == IMG_FILE) ? stream->u.file : nullptr;
+ return (stream->imgtype == IMG_FILE) ? stream->file.get() : nullptr;
}
@@ -275,8 +236,8 @@ UINT32 stream_read(imgtool_stream *stream, void *buf, UINT32 sz)
{
case IMG_FILE:
assert(sz == (UINT32) sz);
- core_fseek(stream->u.file, stream->position, SEEK_SET);
- result = core_fread(stream->u.file, buf, (UINT32) sz);
+ stream->file->seek(stream->position, SEEK_SET);
+ result = stream->file->read(buf, (UINT32) sz);
break;
case IMG_MEM:
@@ -284,7 +245,7 @@ UINT32 stream_read(imgtool_stream *stream, void *buf, UINT32 sz)
if (sz > (stream->filesize - stream->position))
sz = (UINT32) (stream->filesize - stream->position);
- memcpy(buf, stream->u.buffer + stream->position, sz);
+ memcpy(buf, stream->buffer + stream->position, sz);
result = sz;
break;
@@ -312,11 +273,11 @@ UINT32 stream_write(imgtool_stream *s, const void *buf, UINT32 sz)
if (s->filesize < s->position + sz)
{
/* try to expand the buffer */
- if (s->u.buffer) free(s->u.buffer);
+ if (s->buffer) free(s->buffer);
new_buffer = malloc(s->position + sz);
if (new_buffer)
{
- s->u.buffer = (UINT8*)new_buffer;
+ s->buffer = (UINT8*)new_buffer;
s->filesize = s->position + sz;
}
}
@@ -325,14 +286,14 @@ UINT32 stream_write(imgtool_stream *s, const void *buf, UINT32 sz)
if (sz > (s->filesize - s->position))
sz = (UINT32) (s->filesize - s->position);
- memcpy(s->u.buffer + s->position, buf, sz);
+ memcpy(s->buffer + s->position, buf, sz);
result = sz;
}
break;
case IMG_FILE:
- core_fseek(s->u.file, s->position, SEEK_SET);
- result = core_fwrite(s->u.file, buf, sz);
+ s->file->seek(s->position, SEEK_SET);
+ result = s->file->write(buf, sz);
break;
default:
@@ -365,7 +326,7 @@ void *stream_getptr(imgtool_stream *f)
switch(f->imgtype)
{
case IMG_MEM:
- ptr = f->u.buffer;
+ ptr = f->buffer;
break;
default:
@@ -445,7 +406,7 @@ int stream_crc(imgtool_stream *s, unsigned long *result)
switch(s->imgtype)
{
case IMG_MEM:
- *result = crc32(0, (unsigned char *) s->u.buffer, (size_t) s->filesize);
+ *result = crc32(0, (unsigned char *) s->buffer, (size_t) s->filesize);
break;
default:
diff --git a/src/tools/imgtool/stream.h b/src/tools/imgtool/stream.h
index 13e6e0d727f..ee362c9c32b 100644
--- a/src/tools/imgtool/stream.h
+++ b/src/tools/imgtool/stream.h
@@ -20,7 +20,7 @@ imgtool_stream *stream_open(const char *fname, int read_or_write); /* similar p
imgtool_stream *stream_open_write_stream(int filesize);
imgtool_stream *stream_open_mem(void *buf, size_t sz);
void stream_close(imgtool_stream *stream);
-core_file *stream_core_file(imgtool_stream *stream);
+util::core_file *stream_core_file(imgtool_stream *stream);
UINT32 stream_read(imgtool_stream *stream, void *buf, UINT32 sz);
UINT32 stream_write(imgtool_stream *stream, const void *buf, UINT32 sz);
UINT64 stream_size(imgtool_stream *stream);
diff --git a/src/tools/ldresample.cpp b/src/tools/ldresample.cpp
index 771c4e94676..1f04edac3f0 100644
--- a/src/tools/ldresample.cpp
+++ b/src/tools/ldresample.cpp
@@ -554,7 +554,7 @@ int main(int argc, char *argv[])
// open the destination file
chd_resample_compressor dstfile(srcfile, info, INT64(offset * 65536.0 * 256.0), INT64(slope * 65536.0 * 256.0));
err = create_chd(dstfile, dstfilename, srcfile, info);
- if (dstfile == nullptr)
+ if (!dstfile.opened())
{
fprintf(stderr, "Unable to create file '%s'\n", dstfilename);
return 1;
diff --git a/src/tools/pngcmp.cpp b/src/tools/pngcmp.cpp
index dda54ed7730..5103740389b 100644
--- a/src/tools/pngcmp.cpp
+++ b/src/tools/pngcmp.cpp
@@ -72,7 +72,7 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
bitmap_argb32 bitmap2;
bitmap_argb32 finalbitmap;
int width, height, maxwidth;
- core_file *file = nullptr;
+ util::core_file::ptr file;
file_error filerr;
png_error pngerr;
int error = 100;
@@ -80,7 +80,7 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
int x, y;
/* open the source image */
- filerr = core_fopen(imgfile1.c_str(), OPEN_FLAG_READ, &file);
+ filerr = util::core_file::open(imgfile1.c_str(), OPEN_FLAG_READ, file);
if (filerr != FILERR_NONE)
{
printf("Could not open %s (%d)\n", imgfile1.c_str(), filerr);
@@ -88,8 +88,8 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
}
/* load the source image */
- pngerr = png_read_bitmap(file, bitmap1);
- core_fclose(file);
+ pngerr = png_read_bitmap(*file, bitmap1);
+ file.reset();
if (pngerr != PNGERR_NONE)
{
printf("Could not read %s (%d)\n", imgfile1.c_str(), pngerr);
@@ -97,7 +97,7 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
}
/* open the source image */
- filerr = core_fopen(imgfile2.c_str(), OPEN_FLAG_READ, &file);
+ filerr = util::core_file::open(imgfile2.c_str(), OPEN_FLAG_READ, file);
if (filerr != FILERR_NONE)
{
printf("Could not open %s (%d)\n", imgfile2.c_str(), filerr);
@@ -105,8 +105,8 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
}
/* load the source image */
- pngerr = png_read_bitmap(file, bitmap2);
- core_fclose(file);
+ pngerr = png_read_bitmap(*file, bitmap2);
+ file.reset();
if (pngerr != PNGERR_NONE)
{
printf("Could not read %s (%d)\n", imgfile2.c_str(), pngerr);
@@ -170,14 +170,14 @@ static int generate_png_diff(const std::string& imgfile1, const std::string& img
}
/* write the final PNG */
- filerr = core_fopen(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
+ filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file);
if (filerr != FILERR_NONE)
{
printf("Could not open %s (%d)\n", outfilename.c_str(), filerr);
goto error;
}
- pngerr = png_write_bitmap(file, nullptr, finalbitmap, 0, nullptr);
- core_fclose(file);
+ pngerr = png_write_bitmap(*file, nullptr, finalbitmap, 0, nullptr);
+ file.reset();
if (pngerr != PNGERR_NONE)
{
printf("Could not write %s (%d)\n", outfilename.c_str(), pngerr);
diff --git a/src/tools/regrep.cpp b/src/tools/regrep.cpp
index 16eaa21f7de..b0cad2497ae 100644
--- a/src/tools/regrep.cpp
+++ b/src/tools/regrep.cpp
@@ -148,15 +148,15 @@ static int CLIB_DECL compare_file(const void *file0ptr, const void *file1ptr);
static summary_file *sort_file_list(void);
/* HTML helpers */
-static core_file *create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &title);
-static void output_footer_and_close_file(core_file *file, std::string &templatefile, std::string &title);
+static util::core_file::ptr create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &title);
+static void output_footer_and_close_file(util::core_file::ptr &&file, std::string &templatefile, std::string &title);
/* report generators */
static void output_report(std::string &dirname, std::string &tempheader, std::string &tempfooter, summary_file *filelist);
static int compare_screenshots(summary_file *curfile);
static int generate_png_diff(const summary_file *curfile, std::string &destdir, const char *destname);
static void create_linked_file(std::string &dirname, const summary_file *curfile, const summary_file *prevfile, const summary_file *nextfile, const char *pngfile, std::string &tempheader, std::string &tempfooter);
-static void append_driver_list_table(const char *header, std::string &dirname, core_file *indexfile, const summary_file *listhead, std::string &tempheader, std::string &tempfooter);
+static void append_driver_list_table(const char *header, std::string &dirname, util::core_file &indexfile, const summary_file *listhead, std::string &tempheader, std::string &tempfooter);
@@ -235,7 +235,7 @@ int main(int argc, char *argv[])
/* read the template file into an astring */
std::string tempheader;
- if (core_fload(tempfilename.c_str(), &buffer, &bufsize) == FILERR_NONE)
+ if (util::core_file::load(tempfilename.c_str(), &buffer, bufsize) == FILERR_NONE)
{
tempheader.assign((const char *)buffer, bufsize);
osd_free(buffer);
@@ -560,18 +560,18 @@ static summary_file *sort_file_list(void)
HTML file with a standard header
-------------------------------------------------*/
-static core_file *create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &title)
+static util::core_file::ptr create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &title)
{
- core_file *file;
+ util::core_file::ptr file;
/* create the indexfile */
- if (core_fopen(filename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, &file) != FILERR_NONE)
- return nullptr;
+ if (util::core_file::open(filename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, file) != FILERR_NONE)
+ return util::core_file::ptr();
/* print a header */
std::string modified(templatefile);
strreplace(modified, "<!--TITLE-->", title.c_str());
- core_fwrite(file, modified.c_str(), modified.length());
+ file->write(modified.c_str(), modified.length());
/* return the file */
return file;
@@ -583,12 +583,12 @@ static core_file *create_file_and_output_header(std::string &filename, std::stri
standard footer to an HTML file and close it
-------------------------------------------------*/
-static void output_footer_and_close_file(core_file *file, std::string &templatefile, std::string &title)
+static void output_footer_and_close_file(util::core_file::ptr &&file, std::string &templatefile, std::string &title)
{
std::string modified(templatefile);
strreplace(modified, "<!--TITLE-->", title.c_str());
- core_fwrite(file, modified.c_str(), modified.length());
- core_fclose(file);
+ file->write(modified.c_str(), modified.length());
+ file.reset();
}
@@ -609,7 +609,7 @@ static void output_report(std::string &dirname, std::string &tempheader, std::st
std::string title("MAME Regressions");
std::string tempname;
int listnum, bucknum;
- core_file *indexfile;
+ util::core_file::ptr indexfile;
int count = 0, total;
/* initialize the lists */
@@ -688,7 +688,7 @@ static void output_report(std::string &dirname, std::string &tempheader, std::st
/* output header */
tempname = string_format("%s" PATH_SEPARATOR "%s", dirname.c_str(), "index.html");
indexfile = create_file_and_output_header(tempname, tempheader, title);
- if (indexfile == nullptr)
+ if (!indexfile)
{
fprintf(stderr, "Error creating file '%s'\n", tempname.c_str());
return;
@@ -702,12 +702,12 @@ static void output_report(std::string &dirname, std::string &tempheader, std::st
if (buckethead[curbucket] != nullptr)
{
fprintf(stderr, "Outputting bucket: %s\n", bucket_name[curbucket]);
- append_driver_list_table(bucket_name[curbucket], dirname, indexfile, buckethead[curbucket], tempheader, tempfooter);
+ append_driver_list_table(bucket_name[curbucket], dirname, *indexfile, buckethead[curbucket], tempheader, tempfooter);
}
}
/* output footer */
- output_footer_and_close_file(indexfile, tempfooter, title);
+ output_footer_and_close_file(std::move(indexfile), tempfooter, title);
}
@@ -729,13 +729,13 @@ static int compare_screenshots(summary_file *curfile)
{
std::string fullname;
file_error filerr;
- core_file *file;
+ util::core_file::ptr file;
/* get the filename for the image */
fullname = string_format("%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", lists[listnum].dir, curfile->name);
/* open the file */
- filerr = core_fopen(fullname.c_str(), OPEN_FLAG_READ, &file);
+ filerr = util::core_file::open(fullname.c_str(), OPEN_FLAG_READ, file);
/* if that failed, look in the old location */
if (filerr != FILERR_NONE)
@@ -744,14 +744,14 @@ static int compare_screenshots(summary_file *curfile)
fullname = string_format("%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "_%s.png", lists[listnum].dir, curfile->name);
/* open the file */
- filerr = core_fopen(fullname.c_str(), OPEN_FLAG_READ, &file);
+ filerr = util::core_file::open(fullname.c_str(), OPEN_FLAG_READ, file);
}
/* if that worked, load the file */
if (filerr == FILERR_NONE)
{
- png_read_bitmap(file, bitmaps[listnum]);
- core_fclose(file);
+ png_read_bitmap(*file, bitmaps[listnum]);
+ file.reset();
}
}
@@ -836,7 +836,7 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir,
int width, height, maxwidth;
int bitmapcount = 0;
int listnum, bmnum;
- core_file *file = nullptr;
+ util::core_file::ptr file;
file_error filerr;
png_error pngerr;
int error = -1;
@@ -853,13 +853,13 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir,
tempname = string_format("%s" PATH_SEPARATOR "%s", lists[listnum].dir, srcimgname.c_str());
/* open the source image */
- filerr = core_fopen(tempname.c_str(), OPEN_FLAG_READ, &file);
+ filerr = util::core_file::open(tempname.c_str(), OPEN_FLAG_READ, file);
if (filerr != FILERR_NONE)
goto error;
/* load the source image */
- pngerr = png_read_bitmap(file, bitmaps[bitmapcount++]);
- core_fclose(file);
+ pngerr = png_read_bitmap(*file, bitmaps[bitmapcount++]);
+ file.reset();
if (pngerr != PNGERR_NONE)
goto error;
}
@@ -925,11 +925,11 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir,
}
/* write the final PNG */
- filerr = core_fopen(dstfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
+ filerr = util::core_file::open(dstfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file);
if (filerr != FILERR_NONE)
goto error;
- pngerr = png_write_bitmap(file, nullptr, finalbitmap, 0, nullptr);
- core_fclose(file);
+ pngerr = png_write_bitmap(*file, nullptr, finalbitmap, 0, nullptr);
+ file.reset();
if (pngerr != PNGERR_NONE)
goto error;
@@ -953,7 +953,7 @@ static void create_linked_file(std::string &dirname, const summary_file *curfile
std::string linkname;
std::string filename;
std::string title;
- core_file *linkfile;
+ util::core_file::ptr linkfile;
int listnum;
/* create the filename */
@@ -970,19 +970,19 @@ static void create_linked_file(std::string &dirname, const summary_file *curfile
}
/* link to the previous/next entries */
- core_fprintf(linkfile, "\t<p>\n");
- core_fprintf(linkfile, "\t<table width=\"100%%\">\n");
- core_fprintf(linkfile, "\t\t<td align=\"left\" width=\"40%%\" style=\"border:none\">");
+ linkfile->printf("\t<p>\n");
+ linkfile->printf("\t<table width=\"100%%\">\n");
+ linkfile->printf("\t\t<td align=\"left\" width=\"40%%\" style=\"border:none\">");
if (prevfile != nullptr)
- core_fprintf(linkfile, "<a href=\"%s.html\"><< %s (%s)</a>", prevfile->name, prevfile->name, prevfile->source);
- core_fprintf(linkfile, "</td>\n");
- core_fprintf(linkfile, "\t\t<td align=\"center\" width=\"20%%\" style=\"border:none\"><a href=\"index.html\">Home</a></td>\n");
- core_fprintf(linkfile, "\t\t<td align=\"right\" width=\"40%%\" style=\"border:none\">");
+ linkfile->printf("<a href=\"%s.html\"><< %s (%s)</a>", prevfile->name, prevfile->name, prevfile->source);
+ linkfile->printf("</td>\n");
+ linkfile->printf("\t\t<td align=\"center\" width=\"20%%\" style=\"border:none\"><a href=\"index.html\">Home</a></td>\n");
+ linkfile->printf("\t\t<td align=\"right\" width=\"40%%\" style=\"border:none\">");
if (nextfile != nullptr)
- core_fprintf(linkfile, "<a href=\"%s.html\">%s (%s) >></a>", nextfile->name, nextfile->name, nextfile->source);
- core_fprintf(linkfile, "</td>\n");
- core_fprintf(linkfile, "\t</table>\n");
- core_fprintf(linkfile, "\t</p>\n");
+ linkfile->printf("<a href=\"%s.html\">%s (%s) >></a>", nextfile->name, nextfile->name, nextfile->source);
+ linkfile->printf("</td>\n");
+ linkfile->printf("\t</table>\n");
+ linkfile->printf("\t</p>\n");
/* output data for each one */
for (listnum = 0; listnum < list_count; listnum++)
@@ -990,34 +990,34 @@ static void create_linked_file(std::string &dirname, const summary_file *curfile
int imageindex = -1;
/* generate the HTML */
- core_fprintf(linkfile, "\n\t<h2>%s</h2>\n", lists[listnum].version);
- core_fprintf(linkfile, "\t<p>\n");
- core_fprintf(linkfile, "\t<b>Status:</b> %s\n", status_text[curfile->status[listnum]]);
+ linkfile->printf("\n\t<h2>%s</h2>\n", lists[listnum].version);
+ linkfile->printf("\t<p>\n");
+ linkfile->printf("\t<b>Status:</b> %s\n", status_text[curfile->status[listnum]]);
if (pngfile != nullptr)
imageindex = get_unique_index(curfile, listnum);
if (imageindex != -1)
- core_fprintf(linkfile, " [%d]", imageindex);
- core_fprintf(linkfile, "\t</p>\n");
+ linkfile->printf(" [%d]", imageindex);
+ linkfile->printf("\t</p>\n");
if (curfile->text[listnum].length() != 0)
{
- core_fprintf(linkfile, "\t<p>\n");
- core_fprintf(linkfile, "\t<b>Errors:</b>\n");
- core_fprintf(linkfile, "\t<pre>%s</pre>\n", curfile->text[listnum].c_str());
- core_fprintf(linkfile, "\t</p>\n");
+ linkfile->printf("\t<p>\n");
+ linkfile->printf("\t<b>Errors:</b>\n");
+ linkfile->printf("\t<pre>%s</pre>\n", curfile->text[listnum].c_str());
+ linkfile->printf("\t</p>\n");
}
}
/* output link to the image */
if (pngfile != nullptr)
{
- core_fprintf(linkfile, "\n\t<h2>Screenshot Comparisons</h2>\n");
- core_fprintf(linkfile, "\t<p>\n");
- core_fprintf(linkfile, "\t<img src=\"%s\" />\n", pngfile);
- core_fprintf(linkfile, "\t</p>\n");
+ linkfile->printf("\n\t<h2>Screenshot Comparisons</h2>\n");
+ linkfile->printf("\t<p>\n");
+ linkfile->printf("\t<img src=\"%s\" />\n", pngfile);
+ linkfile->printf("\t</p>\n");
}
/* output footer */
- output_footer_and_close_file(linkfile, tempfooter, title);
+ output_footer_and_close_file(std::move(linkfile), tempfooter, title);
}
@@ -1026,28 +1026,28 @@ static void create_linked_file(std::string &dirname, const summary_file *curfile
of drivers from a list to an HTML file
-------------------------------------------------*/
-static void append_driver_list_table(const char *header, std::string &dirname, core_file *indexfile, const summary_file *listhead, std::string &tempheader, std::string &tempfooter)
+static void append_driver_list_table(const char *header, std::string &dirname, util::core_file &indexfile, const summary_file *listhead, std::string &tempheader, std::string &tempfooter)
{
const summary_file *curfile, *prevfile;
int width = 100 / (2 + list_count);
int listnum;
/* output a header */
- core_fprintf(indexfile, "\t<h2>%s</h2>\n", header);
+ indexfile.printf("\t<h2>%s</h2>\n", header);
/* start the table */
- core_fprintf(indexfile, "\t<p><table width=\"90%%\">\n");
- core_fprintf(indexfile, "\t\t<tr>\n\t\t\t<th width=\"%d%%\">Source</th><th width=\"%d%%\">Driver</th>", width, width);
+ indexfile.printf("\t<p><table width=\"90%%\">\n");
+ indexfile.printf("\t\t<tr>\n\t\t\t<th width=\"%d%%\">Source</th><th width=\"%d%%\">Driver</th>", width, width);
for (listnum = 0; listnum < list_count; listnum++)
- core_fprintf(indexfile, "<th width=\"%d%%\">%s</th>", width, lists[listnum].version);
- core_fprintf(indexfile, "\n\t\t</tr>\n");
+ indexfile.printf("<th width=\"%d%%\">%s</th>", width, lists[listnum].version);
+ indexfile.printf("\n\t\t</tr>\n");
/* if nothing, print a default message */
if (listhead == nullptr)
{
- core_fprintf(indexfile, "\t\t<tr>\n\t\t\t");
- core_fprintf(indexfile, "<td colspan=\"%d\" align=\"center\">(No regressions detected)</td>", list_count + 2);
- core_fprintf(indexfile, "\n\t\t</tr>\n");
+ indexfile.printf("\t\t<tr>\n\t\t\t");
+ indexfile.printf("<td colspan=\"%d\" align=\"center\">(No regressions detected)</td>", list_count + 2);
+ indexfile.printf("\n\t\t</tr>\n");
}
/* iterate over files */
@@ -1083,10 +1083,10 @@ static void append_driver_list_table(const char *header, std::string &dirname, c
create_linked_file(dirname, curfile, prevfile, curfile->next, (pngdiffname[0] == 0) ? nullptr : pngdiffname, tempheader, tempfooter);
/* create a row */
- core_fprintf(indexfile, "\t\t<tr>\n\t\t\t");
+ indexfile.printf("\t\t<tr>\n\t\t\t");
if (rowspan > 0)
- core_fprintf(indexfile, "<td rowspan=\"%d\">%s</td>", rowspan, curfile->source);
- core_fprintf(indexfile, "<td><a href=\"%s.html\">%s</a></td>", curfile->name, curfile->name);
+ indexfile.printf("<td rowspan=\"%d\">%s</td>", rowspan, curfile->source);
+ indexfile.printf("<td><a href=\"%s.html\">%s</a></td>", curfile->name, curfile->name);
for (listnum = 0; listnum < list_count; listnum++)
{
int unique_index = -1;
@@ -1094,16 +1094,16 @@ static void append_driver_list_table(const char *header, std::string &dirname, c
if (pngdiffname[0] != 0)
unique_index = get_unique_index(curfile, listnum);
if (unique_index != -1)
- core_fprintf(indexfile, "<td><span style=\"%s\">&nbsp;&nbsp;&nbsp;</span> %s [<a href=\"%s\" target=\"blank\">%d</a>]</td>", status_color[curfile->status[listnum]], status_text[curfile->status[listnum]], pngdiffname, unique_index);
+ indexfile.printf("<td><span style=\"%s\">&nbsp;&nbsp;&nbsp;</span> %s [<a href=\"%s\" target=\"blank\">%d</a>]</td>", status_color[curfile->status[listnum]], status_text[curfile->status[listnum]], pngdiffname, unique_index);
else
- core_fprintf(indexfile, "<td><span style=\"%s\">&nbsp;&nbsp;&nbsp;</span> %s</td>", status_color[curfile->status[listnum]], status_text[curfile->status[listnum]]);
+ indexfile.printf("<td><span style=\"%s\">&nbsp;&nbsp;&nbsp;</span> %s</td>", status_color[curfile->status[listnum]], status_text[curfile->status[listnum]]);
}
- core_fprintf(indexfile, "\n\t\t</tr>\n");
+ indexfile.printf("\n\t\t</tr>\n");
/* also print the name and source file */
printf("%s %s\n", curfile->name, curfile->source);
}
/* end of table */
- core_fprintf(indexfile, "</table></p>\n");
+ indexfile.printf("</table></p>\n");
}
diff --git a/src/tools/split.cpp b/src/tools/split.cpp
index a6b97e7175d..f942e1481c2 100644
--- a/src/tools/split.cpp
+++ b/src/tools/split.cpp
@@ -64,7 +64,7 @@ static void compute_hash_as_string(std::string &buffer, void *data, UINT32 lengt
static int split_file(const char *filename, const char *basename, UINT32 splitsize)
{
std::string outfilename, basefilename, splitfilename;
- core_file *outfile = nullptr, *infile = nullptr, *splitfile = nullptr;
+ util::core_file::ptr outfile, infile, splitfile;
std::string computedhash;
void *splitbuffer = nullptr;
int index, partnum;
@@ -81,7 +81,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
splitsize *= 1024 * 1024;
// open the file for read
- filerr = core_fopen(filename, OPEN_FLAG_READ, &infile);
+ filerr = util::core_file::open(filename, OPEN_FLAG_READ, infile);
if (filerr != FILERR_NONE)
{
fprintf(stderr, "Fatal error: unable to open file '%s'\n", filename);
@@ -89,7 +89,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
}
// get the total length
- totallength = core_fsize(infile);
+ totallength = infile->size();
if (totallength < splitsize)
{
fprintf(stderr, "Fatal error: file is smaller than the split size\n");
@@ -119,7 +119,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
splitfilename.assign(basename).append(".split");
// create the split file
- filerr = core_fopen(splitfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &splitfile);
+ filerr = util::core_file::open(splitfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, splitfile);
if (filerr != FILERR_NONE)
{
fprintf(stderr, "Fatal error: unable to create split file '%s'\n", splitfilename.c_str());
@@ -127,8 +127,8 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
}
// write the basics out
- core_fprintf(splitfile, "splitfile=%s\n", basefilename.c_str());
- core_fprintf(splitfile, "splitsize=%d\n", splitsize);
+ splitfile->printf("splitfile=%s\n", basefilename.c_str());
+ splitfile->printf("splitsize=%d\n", splitsize);
printf("Split file is '%s'\n", splitfilename.c_str());
printf("Splitting file %s into chunks of %dMB...\n", basefilename.c_str(), splitsize / (1024 * 1024));
@@ -141,7 +141,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
printf("Reading part %d...", partnum);
// read as much as we can from the file
- length = core_fread(infile, splitbuffer, splitsize);
+ length = infile->read(splitbuffer, splitsize);
if (length == 0)
break;
@@ -149,13 +149,13 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
compute_hash_as_string(computedhash, splitbuffer, length);
// write that info to the split file
- core_fprintf(splitfile, "hash=%s file=%s.%03d\n", computedhash.c_str(), basefilename.c_str(), partnum);
+ splitfile->printf("hash=%s file=%s.%03d\n", computedhash.c_str(), basefilename.c_str(), partnum);
// compute the full filename for this guy
outfilename = string_format("%s.%03d", basename, partnum);
// create it
- filerr = core_fopen(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &outfile);
+ filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, outfile);
if (filerr != FILERR_NONE)
{
printf("\n");
@@ -166,15 +166,14 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
printf(" writing %s.%03d...", basefilename.c_str(), partnum);
// write the data
- actual = core_fwrite(outfile, splitbuffer, length);
+ actual = outfile->write(splitbuffer, length);
if (actual != length)
{
printf("\n");
fprintf(stderr, "Fatal error: Error writing output file (out of space?)\n");
goto cleanup;
}
- core_fclose(outfile);
- outfile = nullptr;
+ outfile.reset();
printf(" done\n");
@@ -188,17 +187,17 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
error = 0;
cleanup:
- if (splitfile != nullptr)
+ if (splitfile)
{
- core_fclose(splitfile);
+ splitfile.reset();
if (error != 0)
remove(splitfilename.c_str());
}
- if (infile != nullptr)
- core_fclose(infile);
- if (outfile != nullptr)
+ if (infile)
+ infile.reset();
+ if (outfile)
{
- core_fclose(outfile);
+ outfile.reset();
if (error != 0)
remove(outfilename.c_str());
}
@@ -218,7 +217,7 @@ static int join_file(const char *filename, const char *outname, int write_output
std::string expectedhash, computedhash;
std::string outfilename, infilename;
std::string basepath;
- core_file *outfile = nullptr, *infile = nullptr, *splitfile = nullptr;
+ util::core_file::ptr outfile, infile, splitfile;
void *splitbuffer = nullptr;
file_error filerr;
UINT32 splitsize;
@@ -227,7 +226,7 @@ static int join_file(const char *filename, const char *outname, int write_output
int index;
// open the file for read
- filerr = core_fopen(filename, OPEN_FLAG_READ, &splitfile);
+ filerr = util::core_file::open(filename, OPEN_FLAG_READ, splitfile);
if (filerr != FILERR_NONE)
{
fprintf(stderr, "Fatal error: unable to open file '%s'\n", filename);
@@ -235,7 +234,7 @@ static int join_file(const char *filename, const char *outname, int write_output
}
// read the first line and verify this is a split file
- if (!core_fgets(buffer, sizeof(buffer), splitfile) || strncmp(buffer, "splitfile=", 10) != 0)
+ if (!splitfile->gets(buffer, sizeof(buffer)) || strncmp(buffer, "splitfile=", 10) != 0)
{
fprintf(stderr, "Fatal error: corrupt or incomplete split file at line:\n%s\n", buffer);
goto cleanup;
@@ -258,7 +257,7 @@ static int join_file(const char *filename, const char *outname, int write_output
outfilename.insert(0, basepath);
// read the split size
- if (!core_fgets(buffer, sizeof(buffer), splitfile) || sscanf(buffer, "splitsize=%d", &splitsize) != 1)
+ if (!splitfile->gets(buffer, sizeof(buffer)) || sscanf(buffer, "splitsize=%d", &splitsize) != 1)
{
fprintf(stderr, "Fatal error: corrupt or incomplete split file at line:\n%s\n", buffer);
goto cleanup;
@@ -268,17 +267,16 @@ static int join_file(const char *filename, const char *outname, int write_output
if (write_output)
{
// don't overwrite the original!
- filerr = core_fopen(outfilename.c_str(), OPEN_FLAG_READ, &outfile);
+ filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_READ, outfile);
if (filerr == FILERR_NONE)
{
- core_fclose(outfile);
- outfile = nullptr;
+ outfile.reset();
fprintf(stderr, "Fatal error: output file '%s' already exists\n", outfilename.c_str());
goto cleanup;
}
// open the output for write
- filerr = core_fopen(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &outfile);
+ filerr = util::core_file::open(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, outfile);
if (filerr != FILERR_NONE)
{
fprintf(stderr, "Fatal error: unable to create file '%s'\n", outfilename.c_str());
@@ -289,7 +287,7 @@ static int join_file(const char *filename, const char *outname, int write_output
printf("%s file '%s'...\n", write_output ? "Joining" : "Verifying", outfilename.c_str());
// now iterate through each file
- while (core_fgets(buffer, sizeof(buffer), splitfile))
+ while (splitfile->gets(buffer, sizeof(buffer)))
{
UINT32 length, actual;
@@ -307,7 +305,7 @@ static int join_file(const char *filename, const char *outname, int write_output
// read the file's contents
infilename.insert(0, basepath);
- filerr = core_fload(infilename.c_str(), &splitbuffer, &length);
+ filerr = util::core_file::load(infilename.c_str(), &splitbuffer, length);
if (filerr != FILERR_NONE)
{
printf("\n");
@@ -331,7 +329,7 @@ static int join_file(const char *filename, const char *outname, int write_output
{
printf(" writing...");
- actual = core_fwrite(outfile, splitbuffer, length);
+ actual = outfile->write(splitbuffer, length);
if (actual != length)
{
printf("\n");
@@ -357,13 +355,13 @@ static int join_file(const char *filename, const char *outname, int write_output
error = 0;
cleanup:
- if (splitfile != nullptr)
- core_fclose(splitfile);
- if (infile != nullptr)
- core_fclose(infile);
- if (outfile != nullptr)
+ if (splitfile)
+ splitfile.reset();
+ if (infile)
+ infile.reset();
+ if (outfile)
{
- core_fclose(outfile);
+ outfile.reset();
if (error != 0)
remove(outfilename.c_str());
}
diff --git a/src/tools/src2html.cpp b/src/tools/src2html.cpp
index 557313f1b3e..e95cbe11764 100644
--- a/src/tools/src2html.cpp
+++ b/src/tools/src2html.cpp
@@ -206,12 +206,12 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
static int output_file(file_type type, int srcrootlen, int dstrootlen, std::string &srcfile, std::string &dstfile, bool link_to_file, std::string &tempheader, std::string &tempfooter);
// HTML helpers
-static core_file *create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &path);
-static void output_footer_and_close_file(core_file *file, std::string &templatefile, std::string &path);
+static util::core_file::ptr create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &path);
+static void output_footer_and_close_file(util::core_file::ptr &&file, std::string &templatefile, std::string &path);
// path helpers
static std::string &normalized_subpath(std::string &dest, std::string &path, int start);
-static void output_path_as_links(core_file *file, std::string &path, bool end_is_directory, bool link_to_file);
+static void output_path_as_links(util::core_file &file, std::string &path, bool end_is_directory, bool link_to_file);
static bool find_include_file(std::string &srcincpath, int srcrootlen, int dstrootlen, std::string &srcfile, std::string &dstfile, std::string &filename);
@@ -279,7 +279,7 @@ int main(int argc, char *argv[])
// read the template file into an std::string
UINT32 bufsize;
void *buffer;
- if (core_fload(tempfilename.c_str(), &buffer, &bufsize) == FILERR_NONE)
+ if (util::core_file::load(tempfilename.c_str(), &buffer, bufsize) == FILERR_NONE)
{
tempheader.assign((const char *)buffer, bufsize);
osd_free(buffer);
@@ -333,12 +333,12 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
// create an index file
std::string indexname;
indexname = string_format("%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], "index.html");
- core_file *indexfile = create_file_and_output_header(indexname, tempheader, srcdir_subpath);
+ util::core_file::ptr indexfile = create_file_and_output_header(indexname, tempheader, srcdir_subpath);
// output the directory navigation
- core_fprintf(indexfile, "<h3>Viewing Directory: ");
- output_path_as_links(indexfile, srcdir_subpath, true, false);
- core_fprintf(indexfile, "</h3>");
+ indexfile->printf("<h3>Viewing Directory: ");
+ output_path_as_links(*indexfile, srcdir_subpath, true, false);
+ indexfile->printf("</h3>");
// iterate first over directories, then over files
int result = 0;
@@ -398,7 +398,7 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
{
// add a header
if (curlist == list)
- core_fprintf(indexfile, "\t<h2>%s</h2>\n\t<ul>\n", (entry_type == ENTTYPE_DIR) ? "Directories" : "Files");
+ indexfile->printf("\t<h2>%s</h2>\n\t<ul>\n", (entry_type == ENTTYPE_DIR) ? "Directories" : "Files");
// build the source filename
std::string srcfile;
@@ -422,7 +422,7 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
{
dstfile = string_format("%s%c%s.html", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str());
if (indexfile != nullptr)
- core_fprintf(indexfile, "\t<li><a href=\"%s.html\">%s</a></li>\n", curlist->name.c_str(), curlist->name.c_str());
+ indexfile->printf("\t<li><a href=\"%s.html\">%s</a></li>\n", curlist->name.c_str(), curlist->name.c_str());
result = output_file(type, srcrootlen, dstrootlen, srcfile, dstfile, srcdir.compare(dstdir) == 0, tempheader, tempfooter);
}
}
@@ -432,14 +432,14 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
{
dstfile = string_format("%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str());
if (indexfile != nullptr)
- core_fprintf(indexfile, "\t<li><a href=\"%s/index.html\">%s/</a></li>\n", curlist->name.c_str(), curlist->name.c_str());
+ indexfile->printf("\t<li><a href=\"%s/index.html\">%s/</a></li>\n", curlist->name.c_str(), curlist->name.c_str());
result = recurse_dir(srcrootlen, dstrootlen, srcfile, dstfile, tempheader, tempfooter);
}
}
// close the list if we found some stuff
if (list != nullptr)
- core_fprintf(indexfile, "\t</ul>\n");
+ indexfile->printf("\t</ul>\n");
// free all the allocated entries
while (list != nullptr)
@@ -451,7 +451,7 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std:
}
if (indexfile != nullptr)
- output_footer_and_close_file(indexfile, tempfooter, srcdir_subpath);
+ output_footer_and_close_file(std::move(indexfile), tempfooter, srcdir_subpath);
return result;
}
@@ -516,36 +516,35 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri
is_token[(UINT8)token_chars[toknum]] = true;
// open the source file
- core_file *src;
- if (core_fopen(srcfile.c_str(), OPEN_FLAG_READ, &src) != FILERR_NONE)
+ util::core_file::ptr src;
+ if (util::core_file::open(srcfile.c_str(), OPEN_FLAG_READ, src) != FILERR_NONE)
{
fprintf(stderr, "Unable to read file '%s'\n", srcfile.c_str());
return 1;
}
// open the output file
- core_file *dst = create_file_and_output_header(dstfile, tempheader, srcfile_subpath);
+ util::core_file::ptr dst = create_file_and_output_header(dstfile, tempheader, srcfile_subpath);
if (dst == nullptr)
{
fprintf(stderr, "Unable to write file '%s'\n", dstfile.c_str());
- core_fclose(src);
return 1;
}
// output the directory navigation
- core_fprintf(dst, "<h3>Viewing File: ");
- output_path_as_links(dst, srcfile_subpath, false, link_to_file);
- core_fprintf(dst, "</h3>");
+ dst->printf("<h3>Viewing File: ");
+ output_path_as_links(*dst, srcfile_subpath, false, link_to_file);
+ dst->printf("</h3>");
// start with some tags
- core_fprintf(dst, "\t<pre class=\"source\">\n");
+ dst->printf("\t<pre class=\"source\">\n");
// iterate over lines in the source file
int linenum = 1;
bool in_comment = false;
char srcline[4096];
std::ostringstream dstline;
- while (core_fgets(srcline, ARRAY_LENGTH(srcline), src) != nullptr)
+ while (src->gets(srcline, ARRAY_LENGTH(srcline)) != nullptr)
{
// start with the line number
dstline.str("");
@@ -707,15 +706,14 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri
// append a break and move on
dstline.put('\n');
- core_fputs(dst, dstline.str().c_str());
+ dst->puts(dstline.str().c_str());
}
// close tags
- core_fprintf(dst, "\t</pre>\n");
+ dst->printf("\t</pre>\n");
// close the file
- output_footer_and_close_file(dst, tempfooter, srcfile_subpath);
- core_fclose(src);
+ output_footer_and_close_file(std::move(dst), tempfooter, srcfile_subpath);
return 0;
}
@@ -730,17 +728,17 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri
HTML file with a standard header
-------------------------------------------------*/
-static core_file *create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &path)
+static util::core_file::ptr create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &path)
{
// create the indexfile
- core_file *file;
- if (core_fopen(filename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, &file) != FILERR_NONE)
- return nullptr;
+ util::core_file::ptr file;
+ if (util::core_file::open(filename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, file) != FILERR_NONE)
+ return util::core_file::ptr();
// print a header
std::string modified(templatefile);
strreplace(modified, "<!--PATH-->", path.c_str());
- core_fwrite(file, modified.c_str(), modified.length());
+ file->write(modified.c_str(), modified.length());
// return the file
return file;
@@ -752,12 +750,12 @@ static core_file *create_file_and_output_header(std::string &filename, std::stri
standard footer to an HTML file and close it
-------------------------------------------------*/
-static void output_footer_and_close_file(core_file *file, std::string &templatefile, std::string &path)
+static void output_footer_and_close_file(util::core_file::ptr &&file, std::string &templatefile, std::string &path)
{
std::string modified(templatefile);
strreplace(modified, "<!--PATH-->", path.c_str());
- core_fwrite(file, modified.c_str(), modified.length());
- core_fclose(file);
+ file->write(modified.c_str(), modified.length());
+ file.reset();
}
@@ -783,7 +781,7 @@ static std::string &normalized_subpath(std::string &dest, std::string &path, int
series of links
-------------------------------------------------*/
-static void output_path_as_links(core_file *file, std::string &path, bool end_is_directory, bool link_to_file)
+static void output_path_as_links(util::core_file &file, std::string &path, bool end_is_directory, bool link_to_file)
{
// first count how deep we are
int srcdepth = 0;
@@ -793,10 +791,10 @@ static void output_path_as_links(core_file *file, std::string &path, bool end_is
srcdepth++;
// output a link to the root
- core_fprintf(file, "<a href=\"");
+ file.printf("<a href=\"");
for (int depth = 0; depth < srcdepth; depth++)
- core_fprintf(file, "../");
- core_fprintf(file, "index.html\">&lt;root&gt;</a>/");
+ file.printf("../");
+ file.printf("index.html\">&lt;root&gt;</a>/");
// now output links to each path up the chain
int curdepth = 0;
@@ -806,10 +804,10 @@ static void output_path_as_links(core_file *file, std::string &path, bool end_is
std::string substr(path, lastslash, slashindex - lastslash);
curdepth++;
- core_fprintf(file, "<a href=\"");
+ file.printf("<a href=\"");
for (int depth = curdepth; depth < srcdepth; depth++)
- core_fprintf(file, "../");
- core_fprintf(file, "index.html\">%s</a>/", substr.c_str());
+ file.printf("../");
+ file.printf("index.html\">%s</a>/", substr.c_str());
lastslash = slashindex + 1;
}
@@ -817,11 +815,11 @@ static void output_path_as_links(core_file *file, std::string &path, bool end_is
// and a final link to the current directory
std::string substr(path, lastslash, -1);
if (end_is_directory)
- core_fprintf(file, "<a href=\"index.html\">%s</a>", substr.c_str());
+ file.printf("<a href=\"index.html\">%s</a>", substr.c_str());
else if (link_to_file)
- core_fprintf(file, "<a href=\"%s\">%s</a>", substr.c_str(), substr.c_str());
+ file.printf("<a href=\"%s\">%s</a>", substr.c_str(), substr.c_str());
else
- core_fprintf(file, "<a href=\"%s.html\">%s</a>", substr.c_str(), substr.c_str());
+ file.printf("<a href=\"%s.html\">%s</a>", substr.c_str(), substr.c_str());
}
@@ -866,11 +864,11 @@ static bool find_include_file(std::string &srcincpath, int srcrootlen, int dstro
srcincpath.append(PATH_SEPARATOR).append(filename.substr(lastsepindex, -1));
// see if we can open it
- core_file *testfile;
- if (core_fopen(srcincpath.c_str(), OPEN_FLAG_READ, &testfile) == FILERR_NONE)
+ util::core_file::ptr testfile;
+ if (util::core_file::open(srcincpath.c_str(), OPEN_FLAG_READ, testfile) == FILERR_NONE)
{
// close the file
- core_fclose(testfile);
+ testfile.reset();
// find the longest matching directory substring between the include and source file
lastsepindex = 0;
diff --git a/src/tools/unidasm.cpp b/src/tools/unidasm.cpp
index 13eabe31c59..f69de2b0864 100644
--- a/src/tools/unidasm.cpp
+++ b/src/tools/unidasm.cpp
@@ -512,7 +512,7 @@ int main(int argc, char *argv[])
return 1;
// load the file
- filerr = core_fload(opts.filename, &data, &length);
+ filerr = util::core_file::load(opts.filename, &data, length);
if (filerr != FILERR_NONE)
{
fprintf(stderr, "Error opening file '%s'\n", opts.filename);