Oh, that's interesting. I was pretty sure FBNil added the feature in 1.6... but I guess I was wrong then?
char*normalize_path(const char* path, const char* base_dir, char* out_abs_path){ char* game_path = "C:/cowz"; char* norm_path = strdup(path); size_t path_len = strlen(norm_path); for (char* c = norm_path; *c != '\0'; ++c) { if (*c == '\\') *c = '/'; } if (norm_path[0] == '/' || norm_path[1] == ':') // absolute path - not allowed return NULL; bool is_homed = (strstr(norm_path, "~/") == norm_path); if (is_homed) { sprintf(out_abs_path, "%s/%s", game_path, norm_path + 2); } else { sprintf(out_abs_path, "%s/%s/%s", game_path, base_dir, norm_path); } free(norm_path); return out_abs_path;}
Alternatively, just put in some defines or def'ed out functions that adapt snprintf, sprintf+strlen, and sprintf_s depending on what is available to the compiler. That way you can get sprintf_s and snprintf when they are available, and have a safe, if less efficient default when neither exists. I do that for `strdup' in TurboSphere. One define that uses strdup, one with strdup_, an inline function that uses strlen, malloc, and memcpy to replicate it.
./engine -game startup# argv[0] engine# argv[1] -game# argv[2] startup
./engine -game\ startup# argv[0] engine# argv[1] -game startup
./engine "-game startup"# argv[0] engine# argv[1] -game startup
#ifdef _MSC_VER#define STRDUP strdup_#else#define STRDUP strdup#endif
One potential source of incompatibility, though: Duktape doesn't recognize const, it causes a syntax error. I realize it's not standard JS, but SpiderMonkey handles it without issue, so any existing Sphere game that declares things const won't run in minisphere.
static intrfn_render_char(const ALLEGRO_FONT* f, ALLEGRO_COLOR color, int ch, float x, float y){ rfn_font_t* rfn = f->data; rfn_glyph_t* glyph = &rfn->glyphs[ch]; al_draw_tinted_bitmap(glyph->bitmap, color, x, y, 0x0); return glyph->header.height; // <-- see, it's supposed to return the WIDTH of the char...}