Revert "Replace sprintf with stb version;"

This reverts commit 8f9d24c51f.
This commit is contained in:
bjorn 2019-01-24 17:39:27 -08:00
parent bf19fd5c15
commit cb9f166234
15 changed files with 39 additions and 34 deletions

View File

@ -1,9 +1,8 @@
#include "api.h"
#include "filesystem/filesystem.h"
#include "data/blob.h"
#include "platform.h"
#include "lib/stb/stb_sprintf.h"
#include <stdlib.h>
#include "platform.h"
// Returns a Blob, leaving stack unchanged. The Blob must be released when finished.
Blob* luax_readblob(lua_State* L, int index, const char* debug) {
@ -71,7 +70,7 @@ static int libraryLoader(lua_State* L) {
vec_foreach(lovrFilesystemGetCRequirePath(), path, i) {
for (const char** extension = libraryExtensions; *extension != NULL; extension++) {
char buffer[64];
stb_snprintf(buffer, 63, "%s%s", modulePath, *extension);
snprintf(buffer, 63, "%s%s", modulePath, *extension);
const char* filename = luaL_gsub(L, path, "??", buffer);
filename = luaL_gsub(L, filename, "?", modulePath);
lua_pop(L, 2);
@ -79,7 +78,7 @@ static int libraryLoader(lua_State* L) {
if (lovrFilesystemIsFile(filename)) {
char fullPath[LOVR_PATH_MAX];
const char* realPath = lovrFilesystemGetRealDirectory(filename);
stb_snprintf(fullPath, LOVR_PATH_MAX - 1, "%s%c%s", realPath, lovrDirSep, filename);
snprintf(fullPath, LOVR_PATH_MAX - 1, "%s%c%s", realPath, lovrDirSep, filename);
lua_getglobal(L, "package");
lua_getfield(L, -1, "loadlib");
lua_pushstring(L, fullPath);
@ -254,7 +253,7 @@ static int l_lovrFilesystemLoad(lua_State* L) {
}
char debug[LOVR_PATH_MAX];
stb_snprintf(debug, LOVR_PATH_MAX, "@%s", path);
snprintf(debug, LOVR_PATH_MAX, "@%s", path);
int status = luaL_loadbuffer(L, content, size, debug);
free(content);

View File

@ -103,7 +103,6 @@ int l_lovrShaderBlockGetShaderCode(lua_State* L) {
size_t length;
char* code = lovrShaderBlockGetShaderCode(block, blockName, &length);
lua_pushlstring(L, code, length);
free(code);
return 1;
}

View File

@ -5,6 +5,7 @@
#include <float.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef LOVR_USE_ASSIMP

View File

@ -2,8 +2,8 @@
#include "filesystem/file.h"
#include "platform.h"
#include "util.h"
#include "lib/stb/stb_sprintf.h"
#include <physfs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __APPLE__
@ -90,7 +90,7 @@ int lovrFilesystemGetAppdataDirectory(char* dest, unsigned int size) {
home = getpwuid(getuid())->pw_dir;
}
stb_snprintf(dest, size, "%s/Library/Application Support", home);
snprintf(dest, size, "%s/Library/Application Support", home);
return 0;
#elif _WIN32
PWSTR appData = NULL;
@ -109,7 +109,7 @@ int lovrFilesystemGetAppdataDirectory(char* dest, unsigned int size) {
home = getpwuid(getuid())->pw_dir;
}
stb_snprintf(dest, size, "%s/.config", home);
snprintf(dest, size, "%s/.config", home);
#else
#error "This platform is missing an implementation for lovrFilesystemGetAppdataDirectory"
#endif
@ -271,9 +271,9 @@ int lovrFilesystemSetIdentity(const char* identity) {
lovrThrow("Could not set write directory: %s (%s)", error, state.savePathFull);
}
stb_snprintf(state.savePathRelative, LOVR_PATH_MAX, "LOVR/%s", identity ? identity : "default");
snprintf(state.savePathRelative, LOVR_PATH_MAX, "LOVR/%s", identity ? identity : "default");
char fullPathBuffer[LOVR_PATH_MAX];
stb_snprintf(fullPathBuffer, LOVR_PATH_MAX, "%s/%s", state.savePathFull, state.savePathRelative);
snprintf(fullPathBuffer, LOVR_PATH_MAX, "%s/%s", state.savePathFull, state.savePathRelative);
strncpy(state.savePathFull, fullPathBuffer, LOVR_PATH_MAX);
PHYSFS_mkdir(state.savePathRelative);
if (!PHYSFS_setWriteDir(state.savePathFull)) {

View File

@ -1,4 +1,5 @@
#include "lib/vec/vec.h"
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>

View File

@ -4,9 +4,10 @@
#include "data/rasterizer.h"
#include "data/textureData.h"
#include "util.h"
#include "lib/stb/stb_sprintf.h"
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
static float* lovrFontAlignLine(float* x, float* lineEnd, float width, HorizontalAlign halign) {
while(x < lineEnd) {
@ -223,7 +224,7 @@ void lovrFontSetLineHeight(Font* font, float lineHeight) {
int lovrFontGetKerning(Font* font, unsigned int left, unsigned int right) {
char key[12];
stb_snprintf(key, 12, "%d,%d", left, right);
snprintf(key, 12, "%d,%d", left, right);
int* entry = map_get(&font->kerning, key);
if (entry) {
@ -249,7 +250,7 @@ void lovrFontSetPixelDensity(Font* font, float pixelDensity) {
Glyph* lovrFontGetGlyph(Font* font, uint32_t codepoint) {
char key[6];
stb_snprintf(key, 6, "%d", codepoint);
snprintf(key, 6, "%d", codepoint);
FontAtlas* atlas = &font->atlas;
map_glyph_t* glyphs = &atlas->glyphs;

View File

@ -6,6 +6,7 @@
#include "data/vertexData.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
static void renderNode(Model* model, int nodeIndex, int instances) {
ModelNode* node = &model->modelData->nodes[nodeIndex];

View File

@ -9,11 +9,11 @@
#include "data/modelData.h"
#include "lib/math.h"
#include "lib/vec/vec.h"
#include "lib/stb/stb_sprintf.h"
#include <math.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
// Types
@ -1792,7 +1792,7 @@ static void lovrShaderSetupUniforms(Shader* shader) {
if (uniform.count > 1) {
char name[LOVR_MAX_UNIFORM_LENGTH];
stb_snprintf(name, LOVR_MAX_UNIFORM_LENGTH, "%s[%d]", uniform.name, j);
snprintf(name, LOVR_MAX_UNIFORM_LENGTH, "%s[%d]", uniform.name, j);
location = glGetUniformLocation(program, name);
}
@ -1832,7 +1832,7 @@ Shader* lovrShaderInitGraphics(Shader* shader, const char* vertexSource, const c
size_t maxDraws = MIN(state.limits.blockSize / (20 * sizeof(float)) / 64 * 64, 256);
char maxDrawSource[32];
stb_snprintf(maxDrawSource, 31, "#define MAX_DRAWS %zu\n", maxDraws);
snprintf(maxDrawSource, 31, "#define MAX_DRAWS %zu\n", maxDraws);
// Vertex
vertexSource = vertexSource == NULL ? lovrDefaultVertexShader : vertexSource;

View File

@ -2,8 +2,6 @@
#include "graphics/graphics.h"
#include "math/math.h"
#include "resources/shaders.h"
#include "lib/stb/stb_sprintf.h"
#include <stdlib.h>
#include <math.h>
static size_t getUniformTypeLength(const Uniform* uniform) {
@ -206,6 +204,7 @@ BlockType lovrShaderBlockGetType(ShaderBlock* block) {
return block->type;
}
// TODO use sds!
char* lovrShaderBlockGetShaderCode(ShaderBlock* block, const char* blockName, size_t* length) {
// Calculate
@ -230,16 +229,16 @@ char* lovrShaderBlockGetShaderCode(ShaderBlock* block, const char* blockName, si
// Concatenate
char* s = code;
s += stb_sprintf(s, "layout(std140) %s %s {\n", block->type == BLOCK_UNIFORM ? "uniform" : "buffer", blockName);
s += sprintf(s, "layout(std140) %s %s {\n", block->type == BLOCK_UNIFORM ? "uniform" : "buffer", blockName);
for (int i = 0; i < block->uniforms.length; i++) {
const Uniform* uniform = &block->uniforms.data[i];
if (uniform->count > 1) {
s += stb_sprintf(s, " %s %s[%d];\n", getUniformTypeName(uniform), uniform->name, uniform->count);
s += sprintf(s, " %s %s[%d];\n", getUniformTypeName(uniform), uniform->name, uniform->count);
} else {
s += stb_sprintf(s, " %s %s;\n", getUniformTypeName(uniform), uniform->name);
s += sprintf(s, " %s %s;\n", getUniformTypeName(uniform), uniform->name);
}
}
s += stb_sprintf(s, "};\n");
s += sprintf(s, "};\n");
*s = '\0';
*length = size;

View File

@ -2,9 +2,10 @@
#include "event/event.h"
#include "graphics/graphics.h"
#include "graphics/texture.h"
#include "lib/math.h"
#include "lib/stb/stb_sprintf.h"
#include "lib/vec/vec.h"
#include "math/mat4.h"
#include "math/quat.h"
#include <stdbool.h>
#include <OVR_CAPI.h>
#include <OVR_CAPI_GL.h>
@ -34,7 +35,7 @@ static HeadsetState state;
static Texture* lookupTexture(uint32_t handle) {
char key[4 + 1] = { 0 };
lovrAssert(handle < 9999, "Texture handle overflow");
stb_sprintf(key, "%d", handle);
sprintf(key, "%d", handle);
Texture** texture = map_get(&state.textureLookup, key);
if (!texture) {
map_set(&state.textureLookup, key, lovrTextureCreateFromHandle(handle, TEXTURE_2D));

View File

@ -4,8 +4,8 @@
#include "platform.h"
#include "util.h"
#include "lib/math.h"
#include "lib/stb/stb_sprintf.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifndef WIN32
@ -139,10 +139,10 @@ static bool openvrInit(float offset, int msaa) {
}
char buffer[64];
stb_sprintf(buffer, "FnTable:%s", IVRSystem_Version), state.system = (struct VR_IVRSystem_FnTable*) VR_GetGenericInterface(buffer, &vrError);
stb_sprintf(buffer, "FnTable:%s", IVRCompositor_Version), state.compositor = (struct VR_IVRCompositor_FnTable*) VR_GetGenericInterface(buffer, &vrError);
stb_sprintf(buffer, "FnTable:%s", IVRChaperone_Version), state.chaperone = (struct VR_IVRChaperone_FnTable*) VR_GetGenericInterface(buffer, &vrError);
stb_sprintf(buffer, "FnTable:%s", IVRRenderModels_Version), state.renderModels = (struct VR_IVRRenderModels_FnTable*) VR_GetGenericInterface(buffer, &vrError);
sprintf(buffer, "FnTable:%s", IVRSystem_Version), state.system = (struct VR_IVRSystem_FnTable*) VR_GetGenericInterface(buffer, &vrError);
sprintf(buffer, "FnTable:%s", IVRCompositor_Version), state.compositor = (struct VR_IVRCompositor_FnTable*) VR_GetGenericInterface(buffer, &vrError);
sprintf(buffer, "FnTable:%s", IVRChaperone_Version), state.chaperone = (struct VR_IVRChaperone_FnTable*) VR_GetGenericInterface(buffer, &vrError);
sprintf(buffer, "FnTable:%s", IVRRenderModels_Version), state.renderModels = (struct VR_IVRRenderModels_FnTable*) VR_GetGenericInterface(buffer, &vrError);
if (!state.system || !state.compositor || !state.chaperone || !state.renderModels) {
VR_ShutdownInternal();

View File

@ -7,6 +7,7 @@
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
lua_State* lovrInit(lua_State* L, int argc, char** argv);
void lovrQuit(int status);

View File

@ -1,8 +1,9 @@
#include "math/randomGenerator.h"
#include "lib/stb/stb_sprintf.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
// Thomas Wang's 64-bit integer hashing function:
// https://web.archive.org/web/20110807030012/http://www.cris.com/%7ETtwang/tech/inthash.htm
@ -43,7 +44,7 @@ void lovrRandomGeneratorSetSeed(RandomGenerator* generator, Seed seed) {
}
void lovrRandomGeneratorGetState(RandomGenerator* generator, char* state, size_t length) {
stb_snprintf(state, length, "0x%lld", generator->state.b64);
snprintf(state, length, "0x%" PRIx64, generator->state.b64);
}
int lovrRandomGeneratorSetState(RandomGenerator* generator, const char* state) {

View File

@ -1,6 +1,6 @@
#include <stdint.h>
#include <stdbool.h>
#include "lib/sds/sds.h"
#include <lib/sds/sds.h>
#pragma once

View File

@ -1,5 +1,6 @@
#include "thread/channel.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
Channel* lovrChannelInit(Channel* channel) {