diff options
Diffstat (limited to 'src/tools/regrep.cpp')
-rw-r--r-- | src/tools/regrep.cpp | 173 |
1 files changed, 89 insertions, 84 deletions
diff --git a/src/tools/regrep.cpp b/src/tools/regrep.cpp index 91dcaecd518..316ef805f5a 100644 --- a/src/tools/regrep.cpp +++ b/src/tools/regrep.cpp @@ -6,14 +6,21 @@ ****************************************************************************/ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <new> -#include <assert.h> -#include "osdcore.h" +#include "corefile.h" +#include "corestr.h" +#include "path.h" #include "png.h" +#include "strformat.h" + +#include "osdcomm.h" + +#include <algorithm> +#include <cassert> +#include <cctype> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <new> /*************************************************************************** @@ -61,8 +68,8 @@ struct summary_file summary_file * next; char name[20]; char source[100]; - uint8_t status[MAX_COMPARES]; - uint8_t matchbitmap[MAX_COMPARES]; + uint8_t status[MAX_COMPARES]; + uint8_t matchbitmap[MAX_COMPARES]; std::string text[MAX_COMPARES]; }; @@ -148,15 +155,15 @@ static int CLIB_DECL compare_file(const void *file0ptr, const void *file1ptr); static summary_file *sort_file_list(void); /* HTML helpers */ -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); +static util::core_file::ptr create_file_and_output_header(std::string_view filename, std::string_view templatefile, const std::string &title); +static void output_footer_and_close_file(util::write_stream::ptr &&file, std::string_view templatefile, const std::string &title); /* report generators */ -static void output_report(std::string &dirname, std::string &tempheader, std::string &tempfooter, summary_file *filelist); +static void output_report(std::string_view dirname, std::string_view tempheader, std::string_view 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, util::core_file &indexfile, const summary_file *listhead, std::string &tempheader, std::string &tempfooter); +static int generate_png_diff(const summary_file *curfile, std::string_view destdir, std::string_view destname); +static void create_linked_file(std::string_view dirname, const summary_file *curfile, const summary_file *prevfile, const summary_file *nextfile, std::string_view pngfile, std::string_view tempheader, std::string_view tempfooter); +static void append_driver_list_table(const char *header, std::string_view dirname, util::core_file &indexfile, const summary_file *listhead, std::string_view tempheader, std::string_view tempfooter); @@ -218,7 +225,7 @@ static inline int get_unique_index(const summary_file *curfile, int index) int main(int argc, char *argv[]) { - uint32_t bufsize; + size_t bufsize; void *buffer; int listnum; int result; @@ -235,7 +242,7 @@ int main(int argc, char *argv[]) /* read the template file into an astring */ std::string tempheader; - if (util::core_file::load(tempfilename.c_str(), &buffer, bufsize) == osd_file::error::NONE) + if (!util::core_file::load(tempfilename, &buffer, bufsize)) { tempheader.assign((const char *)buffer, bufsize); free(buffer); @@ -284,7 +291,7 @@ int main(int argc, char *argv[]) static summary_file *get_file(const char *filename) { - summary_file *file; + summary_file *file = nullptr; /* use the first two characters as a lookup */ for (file = filehash[filename[0] & 0x7f][filename[1] & 0x7f]; file != nullptr; file = file->next) @@ -292,10 +299,14 @@ static summary_file *get_file(const char *filename) return file; /* didn't find one -- allocate */ - file = (summary_file *)malloc(sizeof(*file)); + file = new (std::nothrow) summary_file; if (file == nullptr) return nullptr; - memset(file, 0, sizeof(*file)); + file->next = nullptr; + std::fill(std::begin(file->name), std::end(file->name), '\0'); + std::fill(std::begin(file->source), std::end(file->source), '\0'); + std::fill(std::begin(file->status), std::end(file->status), 0); + std::fill(std::begin(file->matchbitmap), std::end(file->matchbitmap), 0); /* set the name so we find it in the future */ strcpy(file->name, filename); @@ -504,7 +515,7 @@ static int CLIB_DECL compare_file(const void *file0ptr, const void *file1ptr) into a single, sorted list -------------------------------------------------*/ -static summary_file *sort_file_list(void) +static summary_file *sort_file_list() { summary_file *listhead, **tailptr, *curfile, **filearray; int numfiles, filenum; @@ -560,18 +571,18 @@ static summary_file *sort_file_list(void) HTML file with a standard header -------------------------------------------------*/ -static util::core_file::ptr 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_view filename, std::string_view templatefile, const std::string &title) { util::core_file::ptr file; /* create the indexfile */ - if (util::core_file::open(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, file) != osd_file::error::NONE) + if (util::core_file::open(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, file)) return util::core_file::ptr(); /* print a header */ std::string modified(templatefile); - strreplace(modified, "<!--TITLE-->", title.c_str()); - file->write(modified.c_str(), modified.length()); + strreplace(modified, "<!--TITLE-->", title); + /*auto const [err, written] =*/ write(*file, modified.c_str(), modified.length()); // FIXME: check for errors /* return the file */ return file; @@ -583,11 +594,11 @@ static util::core_file::ptr create_file_and_output_header(std::string &filename, standard footer to an HTML file and close it -------------------------------------------------*/ -static void output_footer_and_close_file(util::core_file::ptr &&file, std::string &templatefile, std::string &title) +static void output_footer_and_close_file(util::write_stream::ptr &&file, std::string_view templatefile, const std::string &title) { std::string modified(templatefile); - strreplace(modified, "<!--TITLE-->", title.c_str()); - file->write(modified.c_str(), modified.length()); + strreplace(modified, "<!--TITLE-->", title); + /*auto const [err, written] =*/ write(*file, modified.c_str(), modified.length()); // FIXME: check for errors file.reset(); } @@ -602,12 +613,11 @@ static void output_footer_and_close_file(util::core_file::ptr &&file, std::strin report HTML files -------------------------------------------------*/ -static void output_report(std::string &dirname, std::string &tempheader, std::string &tempfooter, summary_file *filelist) +static void output_report(std::string_view dirname, std::string_view tempheader, std::string_view tempfooter, summary_file *filelist) { summary_file *buckethead[BUCKET_COUNT], **buckettailptr[BUCKET_COUNT]; summary_file *curfile; std::string title("MAME Regressions"); - std::string tempname; int listnum, bucknum; util::core_file::ptr indexfile; int count = 0, total; @@ -686,7 +696,7 @@ static void output_report(std::string &dirname, std::string &tempheader, std::st *buckettailptr[bucknum] = nullptr; /* output header */ - tempname = string_format("%s" PATH_SEPARATOR "%s", dirname.c_str(), "index.html"); + std::string tempname = util::path_concat(dirname, "index.html"); indexfile = create_file_and_output_header(tempname, tempheader, title); if (!indexfile) { @@ -695,7 +705,7 @@ static void output_report(std::string &dirname, std::string &tempheader, std::st } /* iterate over buckets and output them */ - for (bucknum = 0; bucknum < ARRAY_LENGTH(bucket_output_order); bucknum++) + for (bucknum = 0; bucknum < std::size(bucket_output_order); bucknum++) { int curbucket = bucket_output_order[bucknum]; @@ -719,43 +729,43 @@ static void output_report(std::string &dirname, std::string &tempheader, std::st static int compare_screenshots(summary_file *curfile) { bitmap_argb32 bitmaps[MAX_COMPARES]; - int unique[MAX_COMPARES]; + int unique[MAX_COMPARES]{}; int numunique = 0; - int listnum; /* iterate over all files and load their bitmaps */ - for (listnum = 0; listnum < list_count; listnum++) + for (int listnum = 0; listnum < list_count; listnum++) if (curfile->status[listnum] == STATUS_SUCCESS) { std::string fullname; - osd_file::error filerr; + std::error_condition filerr; 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); + fullname = util::path_concat(lists[listnum].dir, "snap", curfile->name, "final.png"); /* open the file */ filerr = util::core_file::open(fullname, OPEN_FLAG_READ, file); /* if that failed, look in the old location */ - if (filerr != osd_file::error::NONE) + if (filerr) { /* get the filename for the image */ - fullname = string_format("%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "_%s.png", lists[listnum].dir, curfile->name); + fullname = util::path_concat(lists[listnum].dir, "snap", util::string_format("_%s.png", curfile->name)); /* open the file */ filerr = util::core_file::open(fullname, OPEN_FLAG_READ, file); } /* if that worked, load the file */ - if (filerr == osd_file::error::NONE) + if (!filerr) { - png_read_bitmap(*file, bitmaps[listnum]); + util::png_read_bitmap(*file, bitmaps[listnum]); file.reset(); } } /* now find all the different bitmap types */ + int listnum; for (listnum = 0; listnum < list_count; listnum++) { curfile->matchbitmap[listnum] = 0xff; @@ -774,8 +784,8 @@ static int compare_screenshots(summary_file *curfile) /* compare scanline by scanline */ for (int y = 0; y < this_bitmap.height() && !bitmaps_differ; y++) { - uint32_t *base = &base_bitmap.pix32(y); - uint32_t *curr = &this_bitmap.pix32(y); + uint32_t const *base = &base_bitmap.pix(y); + uint32_t const *curr = &this_bitmap.pix(y); /* scan the scanline */ int x; @@ -826,41 +836,38 @@ static int compare_screenshots(summary_file *curfile) side with a third set of differences -------------------------------------------------*/ -static int generate_png_diff(const summary_file *curfile, std::string &destdir, const char *destname) +static int generate_png_diff(const summary_file *curfile, std::string_view destdir, std::string_view destname) { bitmap_argb32 bitmaps[MAX_COMPARES]; std::string srcimgname; std::string dstfilename; - std::string tempname; bitmap_argb32 finalbitmap; int width, height, maxwidth; int bitmapcount = 0; - int listnum, bmnum; util::core_file::ptr file; - osd_file::error filerr; - png_error pngerr; + std::error_condition filerr; int error = -1; int starty; /* generate the common source filename */ - dstfilename = string_format("%s" PATH_SEPARATOR "%s", destdir.c_str(), destname); - srcimgname = string_format("snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", curfile->name); + dstfilename = util::path_concat(destdir, destname); + srcimgname = util::path_concat("snap", curfile->name, "final.png"); /* open and load all unique bitmaps */ - for (listnum = 0; listnum < list_count; listnum++) + for (int listnum = 0; listnum < list_count; listnum++) if (curfile->matchbitmap[listnum] == listnum) { - tempname = string_format("%s" PATH_SEPARATOR "%s", lists[listnum].dir, srcimgname.c_str()); + std::string tempname = util::path_concat(lists[listnum].dir, srcimgname); /* open the source image */ filerr = util::core_file::open(tempname, OPEN_FLAG_READ, file); - if (filerr != osd_file::error::NONE) + if (filerr) goto error; /* load the source image */ - pngerr = png_read_bitmap(*file, bitmaps[bitmapcount++]); + filerr = util::png_read_bitmap(*file, bitmaps[bitmapcount++]); file.reset(); - if (pngerr != PNGERR_NONE) + if (filerr) goto error; } @@ -871,7 +878,7 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir, /* determine the size of the final bitmap */ height = width = 0; maxwidth = bitmaps[0].width(); - for (bmnum = 1; bmnum < bitmapcount; bmnum++) + for (int bmnum = 1; bmnum < bitmapcount; bmnum++) { int curwidth; @@ -891,24 +898,23 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir, /* now copy and compare each set of bitmaps */ starty = 0; - for (bmnum = 1; bmnum < bitmapcount; bmnum++) + for (int bmnum = 1; bmnum < bitmapcount; bmnum++) { - bitmap_argb32 &bitmap1 = bitmaps[0]; - bitmap_argb32 &bitmap2 = bitmaps[bmnum]; + bitmap_argb32 const &bitmap1 = bitmaps[0]; + bitmap_argb32 const &bitmap2 = bitmaps[bmnum]; int curheight = std::max(bitmap1.height(), bitmap2.height()); - int x, y; /* iterate over rows in these bitmaps */ - for (y = 0; y < curheight; y++) + for (int y = 0; y < curheight; y++) { - uint32_t *src1 = (y < bitmap1.height()) ? &bitmap1.pix32(y) : nullptr; - uint32_t *src2 = (y < bitmap2.height()) ? &bitmap2.pix32(y) : nullptr; - uint32_t *dst1 = &finalbitmap.pix32(starty + y, 0); - uint32_t *dst2 = &finalbitmap.pix32(starty + y, bitmap1.width() + BITMAP_SPACE); - uint32_t *dstdiff = &finalbitmap.pix32(starty + y, bitmap1.width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE); + uint32_t const *src1 = (y < bitmap1.height()) ? &bitmap1.pix(y) : nullptr; + uint32_t const *src2 = (y < bitmap2.height()) ? &bitmap2.pix(y) : nullptr; + uint32_t *dst1 = &finalbitmap.pix(starty + y, 0); + uint32_t *dst2 = &finalbitmap.pix(starty + y, bitmap1.width() + BITMAP_SPACE); + uint32_t *dstdiff = &finalbitmap.pix(starty + y, bitmap1.width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE); /* now iterate over columns */ - for (x = 0; x < maxwidth; x++) + for (int x = 0; x < maxwidth; x++) { int pix1 = -1, pix2 = -2; @@ -926,11 +932,11 @@ static int generate_png_diff(const summary_file *curfile, std::string &destdir, /* write the final PNG */ filerr = util::core_file::open(dstfilename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, file); - if (filerr != osd_file::error::NONE) + if (filerr) goto error; - pngerr = png_write_bitmap(*file, nullptr, finalbitmap, 0, nullptr); + filerr = util::png_write_bitmap(*file, nullptr, finalbitmap, 0, nullptr); file.reset(); - if (pngerr != PNGERR_NONE) + if (filerr) goto error; /* if we get here, we are error free */ @@ -948,7 +954,7 @@ error: file between differing versions -------------------------------------------------*/ -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 create_linked_file(std::string_view dirname, const summary_file *curfile, const summary_file *prevfile, const summary_file *nextfile, std::string_view pngfile, std::string_view tempheader, std::string_view tempfooter) { std::string linkname; std::string filename; @@ -957,11 +963,11 @@ static void create_linked_file(std::string &dirname, const summary_file *curfile int listnum; /* create the filename */ - filename = string_format("%s.html", curfile->name); + filename = util::string_format("%s.html", curfile->name); /* output header */ - title = string_format("%s Regressions (%s)", curfile->name, curfile->source); - linkname = string_format("%s" PATH_SEPARATOR "%s", dirname.c_str(), filename.c_str()); + title = util::string_format("%s Regressions (%s)", curfile->name, curfile->source); + linkname = util::path_concat(dirname, filename); linkfile = create_file_and_output_header(linkname, tempheader, title); if (linkfile == nullptr) { @@ -993,7 +999,7 @@ static void create_linked_file(std::string &dirname, const summary_file *curfile 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) + if (!pngfile.empty()) imageindex = get_unique_index(curfile, listnum); if (imageindex != -1) linkfile->printf(" [%d]", imageindex); @@ -1002,13 +1008,13 @@ static void create_linked_file(std::string &dirname, const summary_file *curfile { 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<pre>%s</pre>\n", curfile->text[listnum]); linkfile->printf("\t</p>\n"); } } /* output link to the image */ - if (pngfile != nullptr) + if (!pngfile.empty()) { linkfile->printf("\n\t<h2>Screenshot Comparisons</h2>\n"); linkfile->printf("\t<p>\n"); @@ -1026,7 +1032,7 @@ 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, util::core_file &indexfile, const summary_file *listhead, std::string &tempheader, std::string &tempfooter) +static void append_driver_list_table(const char *header, std::string_view dirname, util::core_file &indexfile, const summary_file *listhead, std::string_view tempheader, std::string_view tempfooter) { const summary_file *curfile, *prevfile; int width = 100 / (2 + list_count); @@ -1054,7 +1060,6 @@ static void append_driver_list_table(const char *header, std::string &dirname, u for (prevfile = nullptr, curfile = listhead; curfile != nullptr; prevfile = curfile, curfile = curfile->next) { int rowspan = 0, uniqueshots = 0; - char pngdiffname[40]; /* if this is the first entry in this source file, count how many rows we need to span */ if (prevfile == nullptr || strcmp(prevfile->source, curfile->source) != 0) @@ -1068,19 +1073,19 @@ static void append_driver_list_table(const char *header, std::string &dirname, u } /* create screenshots if necessary */ - pngdiffname[0] = 0; + std::string pngdiffname; for (listnum = 0; listnum < list_count; listnum++) if (curfile->matchbitmap[listnum] == listnum) uniqueshots++; if (uniqueshots > 1) { - sprintf(pngdiffname, "compare_%s.png", curfile->name); + pngdiffname = util::string_format("compare_%s.png", curfile->name); if (generate_png_diff(curfile, dirname, pngdiffname) != 0) - pngdiffname[0] = 0; + pngdiffname.clear(); } /* create a linked file */ - create_linked_file(dirname, curfile, prevfile, curfile->next, (pngdiffname[0] == 0) ? nullptr : pngdiffname, tempheader, tempfooter); + create_linked_file(dirname, curfile, prevfile, curfile->next, pngdiffname, tempheader, tempfooter); /* create a row */ indexfile.printf("\t\t<tr>\n\t\t\t"); @@ -1091,7 +1096,7 @@ static void append_driver_list_table(const char *header, std::string &dirname, u { int unique_index = -1; - if (pngdiffname[0] != 0) + if (!pngdiffname.empty()) unique_index = get_unique_index(curfile, listnum); if (unique_index != -1) indexfile.printf("<td><span style=\"%s\"> </span> %s [<a href=\"%s\" target=\"blank\">%d</a>]</td>", status_color[curfile->status[listnum]], status_text[curfile->status[listnum]], pngdiffname, unique_index); |