mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-17 10:44:48 +00:00
Eliminate calls to sprintf
Apple Xcode has started giving `-Wdeprecated-declarations` warnings for `sprintf`, and suggesting that people migrate to `snprintf` instead. This is silly, but the warnings are spam and need to be silenced somehow. Migrating to `snprintf` and/or `hr::format` is the path of least resistance.
This commit is contained in:
parent
ced3bbcad4
commit
10d0ed8900
@ -1318,9 +1318,7 @@ EX void set_crystal(int sides) {
|
||||
set_variation(eVariation::pure);
|
||||
ginf[gCrystal].sides = sides;
|
||||
ginf[gCrystal].vertex = 4;
|
||||
static char buf[20];
|
||||
sprintf(buf, "{%d,4}", sides);
|
||||
ginf[gCrystal].tiling_name = buf;
|
||||
ginf[gCrystal].tiling_name = hr::format("{%d,4}", sides);
|
||||
ginf[gCrystal].distlimit = distlimit_table[min(sides, MAX_EDGE_CRYSTAL-1)];
|
||||
}
|
||||
|
||||
|
@ -308,8 +308,6 @@ struct debugScreen {
|
||||
#if CAP_SHAPES
|
||||
queuepoly(gmatrix[what], cgi.shAsymmetric, 0x80808080);
|
||||
#endif
|
||||
char buf[200];
|
||||
sprintf(buf, "%p", hr::voidp(what));
|
||||
dialog::addSelItem("mpdist", its(what->mpdist), 'd');
|
||||
dialog::add_action([what] () {
|
||||
bitfield_editor(what->mpdist, [what] (int i) { what->mpdist = 0; }, "generation level");
|
||||
@ -390,7 +388,7 @@ struct debugScreen {
|
||||
dialog::addBreak(50);
|
||||
|
||||
if(show_debug_data) {
|
||||
dialog::addSelItem("pointer", s0+buf+"/"+index_pointer(what), 0);
|
||||
dialog::addSelItem("pointer", s0+hr::format("%p", hr::voidp(what))+"/"+index_pointer(what), 0);
|
||||
dialog::addSelItem("cpdist", its(what->cpdist), 0);
|
||||
dialog::addSelItem("celldist", its(celldist(what)), 0);
|
||||
dialog::addSelItem("celldistance", its(celldistance(cwt.at, what)), 0);
|
||||
|
5
help.cpp
5
help.cpp
@ -586,8 +586,7 @@ EX string generateHelpForWall(eWall w) {
|
||||
void buteol(string& s, int current, int req) {
|
||||
int siz = isize(s);
|
||||
if(s[siz-1] == '\n') s.resize(siz-1);
|
||||
char buf[100]; sprintf(buf, " (%d/%d)", current, req);
|
||||
s += buf; s += "\n";
|
||||
s += hr::format(" (%d/%d)\n", current, req);
|
||||
}
|
||||
|
||||
EX string generateHelpForMonster(eMonster m) {
|
||||
@ -930,7 +929,7 @@ EX void describeMouseover() {
|
||||
}
|
||||
|
||||
if(buggyGeneration) {
|
||||
char buf[80]; sprintf(buf, " %p H=%d M=%d", hr::voidp(c), c->landparam, c->mpdist); out += buf;
|
||||
out += hr::format(" %p H=%d M=%d", hr::voidp(c), c->landparam, c->mpdist);
|
||||
}
|
||||
|
||||
if(randomPatternsMode)
|
||||
|
@ -498,10 +498,7 @@ EX namespace history {
|
||||
|
||||
pushScreen(progress_screen);
|
||||
|
||||
char buf[128];
|
||||
sprintf(buf, "#%03d", segid);
|
||||
|
||||
progress(s0 + buf + " ("+its(j+bonus)+"/"+its(siz+bonus+bonus-1)+")"); */
|
||||
progress(s0 + hr::format("#%03d (%d/%d)", segid, j+bonus, siz+bonus+bonus-1)); */
|
||||
|
||||
// calcparam(); current_display->radius = bandhalf;
|
||||
phase = j; movetophase();
|
||||
|
14
hprint.cpp
14
hprint.cpp
@ -33,9 +33,9 @@ EX int debugflags = DF_INIT | DF_ERROR | DF_WARN | DF_MSG | DF_TIME | DF_LOG;
|
||||
|
||||
EX string s0;
|
||||
|
||||
EX string its(int i) { char buf[64]; sprintf(buf, "%d", i); return buf; }
|
||||
EX string its(int i) { return hr::format("%d", i); }
|
||||
|
||||
EX string itsh8(int i) {static char buf[16]; sprintf(buf, "%08X", i); return buf; }
|
||||
EX string itsh8(int i) { return hr::format("%08X", i); }
|
||||
|
||||
EX string fts(ld x, int prec IS(6)) {
|
||||
std::stringstream ss;
|
||||
@ -399,9 +399,9 @@ EX string llts(long long i) {
|
||||
if(i < 10) return its((int) i);
|
||||
return llts(i/10) + its(i%10);
|
||||
}
|
||||
EX string itsh(unsigned int i) {static char buf[16]; sprintf(buf, "%03X", i); return buf; }
|
||||
EX string itsh(int i) {static char buf[16]; sprintf(buf, "%03X", i); return buf; }
|
||||
EX string itsh2(int i) {static char buf[16]; sprintf(buf, "%02X", i); return buf; }
|
||||
EX string itsh(unsigned int i) { return hr::format("%03X", i); }
|
||||
EX string itsh(int i) { return hr::format("%03X", i); }
|
||||
EX string itsh2(int i) { return hr::format("%02X", i); }
|
||||
|
||||
EX string itsh(unsigned long long i) {
|
||||
int i0 = int(i);
|
||||
@ -483,9 +483,7 @@ template<class T> T deserialize(const string& s) {
|
||||
EX string as_hexstring(string o) {
|
||||
string res;
|
||||
for(char x: o) {
|
||||
char buf[4];
|
||||
sprintf(buf, "%02X", (unsigned char)(x));
|
||||
res += buf;
|
||||
res += hr::format("%02X", (unsigned char)(x));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -26,15 +26,13 @@ string buildScoreDescription() {
|
||||
|
||||
for(int i=0; i<ittypes; i++) if(items[i]) {
|
||||
string t = XLATN(iinf[i].name);
|
||||
sprintf(buf2, " %s (%d)", t.c_str(), items[i]);
|
||||
s += buf2;
|
||||
s += hr::format(" %s (%d)", t.c_str(), items[i]);
|
||||
}
|
||||
s += "\n";
|
||||
s += XLAT("Kills: ") + its(tkills());
|
||||
for(int i=1; i<motypes; i++) if(kills[i]) {
|
||||
string t = XLATN(minf[i].name);
|
||||
sprintf(buf2, " %s (%d)", t.c_str(), kills[i]);
|
||||
s += buf2;
|
||||
s += hr::format(" %s (%d)", t.c_str(), kills[i]);
|
||||
}
|
||||
s += "\n";
|
||||
|
||||
|
@ -439,9 +439,7 @@ EX namespace netgen {
|
||||
for(int ix=0; ix<PX; ix++) {
|
||||
for(int y=0; y<qy; y++) for(int x=0; x<qx; x++)
|
||||
qpixel(quarter,x,y) = qpixel(net, x+qx*ix, y+qy*iy);
|
||||
char buf[64];
|
||||
sprintf(buf, "papermodel-page%d%d" IMAGEEXT, iy, ix);
|
||||
IMAGESAVE(quarter, buf);
|
||||
IMAGESAVE(quarter, hr::format("papermodel-page%d%d" IMAGEEXT, iy, ix).c_str());
|
||||
}
|
||||
|
||||
SDL_FreeSurface(net);
|
||||
|
4
quit.cpp
4
quit.cpp
@ -27,9 +27,7 @@ EX int getgametime() {
|
||||
}
|
||||
|
||||
EX string getgametime_s(int timespent IS(getgametime())) {
|
||||
char buf[20];
|
||||
sprintf(buf, "%d:%02d", timespent/60, timespent % 60);
|
||||
return buf;
|
||||
return hr::format("%d:%02d", timespent/60, timespent % 60);
|
||||
}
|
||||
|
||||
EX bool display_yasc_codes;
|
||||
|
@ -274,7 +274,7 @@ struct storydata { int s; int e; const char *text; } story[] = {
|
||||
#undef T
|
||||
#endif
|
||||
|
||||
string its05(int i) { char buf[64]; sprintf(buf, "%05d", i); return buf; }
|
||||
string its05(int i) { return hr::format("%05d", i); }
|
||||
|
||||
int dimid(char x) {
|
||||
if(x >= 'a' && x < 'a' + GDIM) return x - 'a';
|
||||
|
@ -29,13 +29,12 @@ void show_likelihood() {
|
||||
for(int i=0; i<MAXDIST; i++) bonus_tally[i] = 0;
|
||||
|
||||
for(int u=0; u<MAXDIST; u++) if(tally[u] || bonus_tally[u]) {
|
||||
char buf[20];
|
||||
sprintf(buf, "%.6lf", lc_type == 'R' ? current_logistic.yes(u) : double(edgetally[u] * 1. / tally[u]));
|
||||
string value = hr::format("%.6lf", lc_type == 'R' ? current_logistic.yes(u) : double(edgetally[u] * 1. / tally[u]));
|
||||
string s = its(u);
|
||||
if(isize(s) == 1) s = "0" + s;
|
||||
s += ": " + its(edgetally[u]) + " / " + its(tally[u]);
|
||||
if(bonus_tally[u]) s += " [" + its(bonus_edgetally[u]) + "/" + its(bonus_tally[u]) + "]";
|
||||
dialog::addSelItem(s, buf, 0);
|
||||
dialog::addSelItem(s, value, 0);
|
||||
}
|
||||
|
||||
char letters[3] = {'O', 'R', 'M'};
|
||||
|
@ -53,13 +53,13 @@ EX always_false in;
|
||||
static int id;
|
||||
id++; id %= 10;
|
||||
if(divby == 1) {
|
||||
sprintf(buf[id], "%d", val); return buf[id];
|
||||
snprintf(buf[id], 20, "%d", val); return buf[id];
|
||||
}
|
||||
else if(divby <= 10) {
|
||||
sprintf(buf[id], "%.1f", val*1./divby); return buf[id];
|
||||
snprintf(buf[id], 20, "%.1f", val*1./divby); return buf[id];
|
||||
}
|
||||
else {
|
||||
sprintf(buf[id], "%.2f", val*1./divby); return buf[id];
|
||||
snprintf(buf[id], 20, "%.2f", val*1./divby); return buf[id];
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ EX always_false in;
|
||||
else fill = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
sprintf(buf, "style=\"stroke:#%06x;stroke-opacity:%.3" PLDF ";stroke-width:%" PLDF "px;fill:#%06x;fill-opacity:%.3" PLDF "\"",
|
||||
snprintf(buf, 600, "style=\"stroke:#%06x;stroke-opacity:%.3" PLDF ";stroke-width:%" PLDF "px;fill:#%06x;fill-opacity:%.3" PLDF "\"",
|
||||
(stroke>>8) & 0xFFFFFF, cta(stroke),
|
||||
width/divby,
|
||||
(fill>>8) & 0xFFFFFF, cta(fill)
|
||||
|
Loading…
Reference in New Issue
Block a user