mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Add %e string formatter that auto adjusts whether to display the error number in decimal or in hex
This commit is contained in:
parent
0cdcab1c2a
commit
d602caddde
@ -1278,7 +1278,7 @@ static void PerformRequest(struct HttpRequest* req, cc_string* url) {
|
||||
end = Stopwatch_Measure();
|
||||
|
||||
elapsed = Stopwatch_ElapsedMS(beg, end);
|
||||
Platform_Log4("HTTP: result %i (http %i) in %i ms (%i bytes)",
|
||||
Platform_Log4("HTTP: result %e (http %i) in %i ms (%i bytes)",
|
||||
&req->result, &req->statusCode, &elapsed, &req->size);
|
||||
|
||||
Http_FinishRequest(req);
|
||||
|
@ -65,8 +65,7 @@ void Launcher_DisplayHttpError(struct HttpRequest* req, const char* action, cc_s
|
||||
if (res) {
|
||||
/* Non HTTP error - this is not good */
|
||||
Http_LogError(action, req);
|
||||
String_Format2(dst, res >= 0x80000000 ? "&cError %h when %c" : "&cError %i when %c",
|
||||
&res, action);
|
||||
String_Format2(dst, "&cError %e when %c", &res, action);
|
||||
} else if (status != 200) {
|
||||
String_Format2(dst, "&c%i error when %c", &status, action);
|
||||
} else {
|
||||
|
@ -126,14 +126,12 @@ static void AppendErrorDesc(cc_string* msg, cc_result res, Logger_DescribeError
|
||||
}
|
||||
|
||||
void Logger_FormatWarn(cc_string* msg, cc_result res, const char* action, Logger_DescribeError describeErr) {
|
||||
String_Format2(msg, res < 20000 ? "Error %i when %c" : "Error %h when %c",
|
||||
&res, action);
|
||||
String_Format2(msg, "Error %e when %c", &res, action);
|
||||
AppendErrorDesc(msg, res, describeErr);
|
||||
}
|
||||
|
||||
void Logger_FormatWarn2(cc_string* msg, cc_result res, const char* action, const cc_string* path, Logger_DescribeError describeErr) {
|
||||
String_Format3(msg, res < 20000 ? "Error %i when %c '%s'" : "Error %h when %c '%s'",
|
||||
&res, action, path);
|
||||
String_Format3(msg, "Error %e when %c '%s'", &res, action, path);
|
||||
AppendErrorDesc(msg, res, describeErr);
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,7 @@ void Options_SetSecure(const char* opt, const cc_string* src) {
|
||||
|
||||
String_InitArray(enc, encData);
|
||||
res = Platform_Encrypt(src->buffer, src->length, &enc);
|
||||
if (res) { Platform_Log2("Error %h encrypting option %c", &res, opt); return; }
|
||||
if (res) { Platform_Log2("Error %e encrypting option %c", &res, opt); return; }
|
||||
|
||||
/* base64 encode the data, as user might edit options.txt with a text editor */
|
||||
if (enc.length > 1500) Logger_Abort("too large to base64");
|
||||
@ -223,5 +223,5 @@ void Options_GetSecure(const char* opt, cc_string* dst) {
|
||||
|
||||
dataLen = Convert_FromBase64(raw.buffer, raw.length, data);
|
||||
res = Platform_Decrypt(data, dataLen, dst);
|
||||
if (res) Platform_Log2("Error %h decrypting option %c", &res, opt);
|
||||
if (res) Platform_Log2("Error %e decrypting option %c", &res, opt);
|
||||
}
|
||||
|
@ -839,7 +839,7 @@ cc_bool DynamicLib_DescribeError(cc_string* dst) {
|
||||
dynamicErr = 0; /* Reset error (match posix behaviour) */
|
||||
|
||||
Platform_DescribeError(res, dst);
|
||||
String_Format1(dst, " (error %i)", &res);
|
||||
String_Format1(dst, " (error %e)", &res);
|
||||
|
||||
/* Plugin may have been compiled to load symbols from ClassiCube.exe, */
|
||||
/* but the user might have renamed it to something else */
|
||||
|
@ -358,7 +358,7 @@ static void DisconnectInvalidMap(cc_result res) {
|
||||
cc_string tmp; char tmpBuffer[STRING_SIZE];
|
||||
String_InitArray(tmp, tmpBuffer);
|
||||
|
||||
String_Format1(&tmp, "Server sent corrupted map data (error %h)", &res);
|
||||
String_Format1(&tmp, "Server sent corrupted map data (error %e)", &res);
|
||||
Game_Disconnect(&title, &tmp); return;
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ static void MPConnection_FailConnect(cc_result result) {
|
||||
String_InitArray(msg, msgBuffer);
|
||||
|
||||
if (result) {
|
||||
String_Format3(&msg, "Error connecting to %s:%i: %i" _NL, &Server.Address, &Server.Port, &result);
|
||||
String_Format3(&msg, "Error connecting to %s:%i: %e" _NL, &Server.Address, &Server.Port, &result);
|
||||
Logger_Log(&msg);
|
||||
}
|
||||
MPConnection_Fail(&reason);
|
||||
@ -355,7 +355,7 @@ static void MPConnection_Disconnect(void) {
|
||||
static void DisconnectReadFailed(cc_result res) {
|
||||
cc_string msg; char msgBuffer[STRING_SIZE * 2];
|
||||
String_InitArray(msg, msgBuffer);
|
||||
String_Format3(&msg, "Error reading from %s:%i: %i" _NL, &Server.Address, &Server.Port, &res);
|
||||
String_Format3(&msg, "Error reading from %s:%i: %e" _NL, &Server.Address, &Server.Port, &res);
|
||||
|
||||
Logger_Log(&msg);
|
||||
MPConnection_Disconnect();
|
||||
@ -432,7 +432,7 @@ static void MPConnection_Tick(struct ScheduledTask* task) {
|
||||
}
|
||||
|
||||
if (net_writeFailure) {
|
||||
Platform_Log1("Error from send: %i", &net_writeFailure);
|
||||
Platform_Log1("Error from send: %e", &net_writeFailure);
|
||||
MPConnection_Disconnect(); return;
|
||||
}
|
||||
|
||||
|
43
src/String.c
43
src/String.c
@ -441,33 +441,52 @@ void String_Format4(cc_string* str, const char* format, const void* a1, const vo
|
||||
|
||||
switch (format[++i]) {
|
||||
case 'b':
|
||||
String_AppendInt(str, *((cc_uint8*)arg)); break;
|
||||
String_AppendInt(str, *((cc_uint8*)arg));
|
||||
break;
|
||||
case 'i':
|
||||
String_AppendInt(str, *((int*)arg)); break;
|
||||
String_AppendInt(str, *((int*)arg));
|
||||
break;
|
||||
case 'f':
|
||||
digits = format[++i] - '0';
|
||||
String_AppendFloat(str, *((float*)arg), digits); break;
|
||||
String_AppendFloat(str, *((float*)arg), digits);
|
||||
break;
|
||||
case 'p':
|
||||
digits = format[++i] - '0';
|
||||
String_AppendPaddedInt(str, *((int*)arg), digits); break;
|
||||
String_AppendPaddedInt(str, *((int*)arg), digits);
|
||||
break;
|
||||
case 't':
|
||||
String_AppendBool(str, *((cc_bool*)arg)); break;
|
||||
String_AppendBool(str, *((cc_bool*)arg));
|
||||
break;
|
||||
case 'c':
|
||||
String_AppendConst(str, (char*)arg); break;
|
||||
String_AppendConst(str, (char*)arg);
|
||||
break;
|
||||
case 's':
|
||||
String_AppendString(str, (cc_string*)arg); break;
|
||||
String_AppendString(str, (cc_string*)arg);
|
||||
break;
|
||||
case 'r':
|
||||
String_Append(str, *((char*)arg)); break;
|
||||
String_Append(str, *((char*)arg));
|
||||
break;
|
||||
case 'x':
|
||||
if (sizeof(cc_uintptr) == 4) {
|
||||
String_Hex32(str, *((cc_uint32*)arg)); break;
|
||||
String_Hex32(str, *((cc_uint32*)arg));
|
||||
} else {
|
||||
String_Hex64(str, *((cc_uint64*)arg)); break;
|
||||
String_Hex64(str, *((cc_uint64*)arg));
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
String_Hex32(str, *((cc_uint32*)arg)); break;
|
||||
String_Hex32(str, *((cc_uint32*)arg));
|
||||
break;
|
||||
case 'e':
|
||||
digits = *((int*)arg);
|
||||
if (digits >= -0xFFFF && digits <= 0xFFFF) {
|
||||
String_AppendInt(str, digits);
|
||||
} else {
|
||||
String_Hex32(str, (cc_uint32)digits);
|
||||
}
|
||||
break;
|
||||
case '%':
|
||||
String_Append(str, '%'); break;
|
||||
String_Append(str, '%');
|
||||
break;
|
||||
default:
|
||||
Logger_Abort("Invalid type for string format");
|
||||
}
|
||||
|
@ -443,7 +443,7 @@ int SysFont_TextWidth(struct DrawTextArgs* args) {
|
||||
res = FT_Load_Char(face, uc, 0);
|
||||
|
||||
if (res) {
|
||||
Platform_Log2("Error %i measuring width of %r", &res, &c);
|
||||
Platform_Log2("Error %e measuring width of %r", &res, &c);
|
||||
charWidth = 0;
|
||||
} else {
|
||||
charWidth = face->glyph->advance.x;
|
||||
@ -554,7 +554,7 @@ void SysFont_DrawText(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int
|
||||
res = FT_Load_Char(face, uc, FT_LOAD_RENDER);
|
||||
|
||||
if (res) {
|
||||
Platform_Log2("Error %i drawing %r", &res, &text.buffer[i]);
|
||||
Platform_Log2("Error %e drawing %r", &res, &text.buffer[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ static void DisplayDialog(const char* msg) {
|
||||
msgParam.buttonType = SCE_MSG_DIALOG_BUTTON_TYPE_OK;
|
||||
|
||||
int ret = sceMsgDialogInit(¶m);
|
||||
if (ret) { Platform_Log1("ERROR SHOWING DIALOG: %i", &ret); return; }
|
||||
if (ret) { Platform_Log1("ERROR SHOWING DIALOG: %e", &ret); return; }
|
||||
|
||||
void (*prevCallback)(void* fb);
|
||||
prevCallback = DQ_OnNextFrame;
|
||||
@ -315,7 +315,7 @@ void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) {
|
||||
param.inputTextBuffer = imeBuffer;
|
||||
|
||||
int ret = sceImeDialogInit(¶m);
|
||||
if (ret) { Platform_Log1("ERROR SHOWING IME: %i", &ret); return; }
|
||||
if (ret) { Platform_Log1("ERROR SHOWING IME: %e", &ret); return; }
|
||||
|
||||
void (*prevCallback)(void* fb);
|
||||
prevCallback = DQ_OnNextFrame;
|
||||
|
@ -7,11 +7,11 @@
|
||||
#include "Bitmap.h"
|
||||
#include "Errors.h"
|
||||
#include <SDL2/SDL.h>
|
||||
static SDL_Window* win_handle;
|
||||
|
||||
#ifndef CC_BUILD_OS2
|
||||
#error "Some features are missing from the SDL backend. If possible, it is recommended that you use a native windowing backend instead"
|
||||
#else
|
||||
static SDL_Window* win_handle;
|
||||
#warning "Some features are missing from the SDL backend. If possible, it is recommended that you use a native windowing backend instead"
|
||||
|
||||
#ifdef CC_BUILD_OS2
|
||||
#define INCL_PM
|
||||
#include <os2.h>
|
||||
// Internal OS/2 driver data
|
||||
|
Loading…
x
Reference in New Issue
Block a user