From aec01e740736db267e452f0ed5947649f79e3408 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sun, 28 Feb 2016 11:09:00 +1100 Subject: Replace strformat, strprintf and strcatprintf with type-safe steam_format and string_format Update MAME to use new function Instantiate ODR-used static constant members Make some of the UI code more localisable Remove use of retired functions in tools --- src/tools/src2html.cpp | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'src/tools/src2html.cpp') diff --git a/src/tools/src2html.cpp b/src/tools/src2html.cpp index e5d2f8f496c..a93d7de73b8 100644 --- a/src/tools/src2html.cpp +++ b/src/tools/src2html.cpp @@ -332,7 +332,7 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std: // create an index file std::string indexname; - strprintf(indexname,"%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], "index.html"); + 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); // output the directory navigation @@ -402,7 +402,7 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std: // build the source filename std::string srcfile; - strprintf(srcfile, "%s%c%s", srcdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str()); + srcfile = string_format("%s%c%s", srcdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str()); // if we have a file, output it std::string dstfile; @@ -420,7 +420,7 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std: // if we got a valid file, process it if (type != FILE_TYPE_INVALID) { - strprintf(dstfile, "%s%c%s.html", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str()); + dstfile = string_format("%s%c%s.html", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str()); if (indexfile != nullptr) core_fprintf(indexfile, "\t
  • %s
  • \n", curlist->name.c_str(), curlist->name.c_str()); result = output_file(type, srcrootlen, dstrootlen, srcfile, dstfile, srcdir.compare(dstdir) == 0, tempheader, tempfooter); @@ -430,7 +430,7 @@ static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std: // if we have a directory, recurse else { - strprintf(dstfile, "%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str()); + dstfile = string_format("%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str()); if (indexfile != nullptr) core_fprintf(indexfile, "\t
  • %s/
  • \n", curlist->name.c_str(), curlist->name.c_str()); result = recurse_dir(srcrootlen, dstrootlen, srcfile, dstfile, tempheader, tempfooter); @@ -544,11 +544,12 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri int linenum = 1; bool in_comment = false; char srcline[4096]; + std::ostringstream dstline; while (core_fgets(srcline, ARRAY_LENGTH(srcline), src) != nullptr) { // start with the line number - std::string dstline; - strcatprintf(dstline, "%5d  ", linenum++); + dstline.str(""); + stream_format(dstline, "%5d  ", linenum++); // iterate over characters in the source line bool escape = false; @@ -568,7 +569,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri { if (!in_comment && ch == comment_start[0] && strncmp(srcptr - 1, comment_start, strlen(comment_start)) == 0) { - strcatprintf(dstline, "%s", comment_start_esc); + stream_format(dstline, "%s", comment_start_esc); curcol += strlen(comment_start); srcptr += strlen(comment_start) - 1; ch = 0; @@ -576,7 +577,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri } else if (in_comment && ch == comment_end[0] && strncmp(srcptr - 1, comment_end, strlen(comment_end)) == 0) { - strcatprintf(dstline, "%s", comment_end_esc); + stream_format(dstline, "%s", comment_end_esc); curcol += strlen(comment_end); srcptr += strlen(comment_end) - 1; ch = 0; @@ -587,7 +588,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri // track whether or not we are within an inline (C++-style) comment if (!in_quotes && !in_comment && !in_inline_comment && ch == comment_inline[0] && strncmp(srcptr - 1, comment_inline, strlen(comment_inline)) == 0) { - strcatprintf(dstline, "%s", comment_inline_esc); + stream_format(dstline, "%s", comment_inline_esc); curcol += strlen(comment_inline); srcptr += strlen(comment_inline) - 1; ch = 0; @@ -611,7 +612,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri for (curtoken = token_table; curtoken->token != nullptr; curtoken++) if (strncmp(srcptr - 1, curtoken->token, toklength) == 0 && strlen(curtoken->token) == toklength) { - strcatprintf(dstline, "%s", curtoken->color, curtoken->token); + stream_format(dstline, "%s", curtoken->color, curtoken->token); curcol += strlen(curtoken->token); srcptr += strlen(curtoken->token) - 1; ch = 0; @@ -631,7 +632,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri int spaces = 4 - curcol % 4; while (spaces--) { - dstline.push_back(' '); + dstline.put(' '); curcol++; } } @@ -643,9 +644,9 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri if (!in_comment && !in_inline_comment && !in_quotes && (ch == '"' || ch == '\'')) { if (color_quotes) - strcatprintf(dstline, "%c", ch); + stream_format(dstline, "%c", ch); else - dstline.push_back(ch); + dstline.put(ch); in_quotes = true; curquote = ch; @@ -659,7 +660,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri std::string target; if (find_include_file(target, srcrootlen, dstrootlen, srcfile, dstfile, filename)) { - strcatprintf(dstline, "", target.c_str()); + stream_format(dstline, "", target.c_str()); quotes_are_linked = true; } } @@ -670,11 +671,11 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri else if (!in_comment && !in_inline_comment && in_quotes && (ch == curquote) && !escape) { if (quotes_are_linked) - dstline.append(""); + dstline << ""; if (color_quotes) - strcatprintf(dstline, "%c", ch); + stream_format(dstline, "%c", ch); else - dstline.push_back(ch); + dstline.put(ch); in_quotes = false; curquote = 0; quotes_are_linked = false; @@ -682,13 +683,13 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri // else just output the current character else if (ch == '&') - dstline.append("&"); + dstline << "&"; else if (ch == '<') - dstline.append("<"); + dstline << "<"; else if (ch == '>') - dstline.append(">"); + dstline << ">"; else - dstline.push_back(ch); + dstline.put(ch); curcol++; } @@ -700,13 +701,13 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, std::stri // finish inline comments if (in_inline_comment) { - dstline.append(""); + dstline << ""; in_inline_comment = false; } // append a break and move on - dstline.append("\n"); - core_fputs(dst, dstline.c_str()); + dstline.put('\n'); + core_fputs(dst, dstline.str().c_str()); } // close tags -- cgit v1.2.3-70-g09d2