From 423c655095e66bd1af13782a67bb4bc27df16a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 3 Apr 2017 20:43:57 -0700 Subject: [PATCH] Cleanup. --- src/renderer_d3d11.cpp | 2 +- src/renderer_d3d12.cpp | 2 +- src/renderer_d3d9.cpp | 2 +- tools/geometryc/geometryc.cpp | 14 +++--- tools/shaderc/shaderc.cpp | 85 +++++++++++++++++---------------- tools/shaderc/shaderc_glsl.cpp | 2 +- tools/shaderc/shaderc_hlsl.cpp | 2 +- tools/shaderc/shaderc_spirv.cpp | 4 +- tools/texturev/texturev.cpp | 2 +- 9 files changed, 59 insertions(+), 56 deletions(-) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 2a65c2a2c..ccf84d971 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -945,7 +945,7 @@ namespace bgfx { namespace d3d11 } if (BX_ENABLED(BGFX_CONFIG_DEBUG_PERFHUD) - && 0 != strstr(description, "PerfHUD") ) + && 0 != bx::strnstr(description, "PerfHUD") ) { m_adapter = adapter; m_driverType = D3D_DRIVER_TYPE_REFERENCE; diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index cf001166b..210d7daa0 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -629,7 +629,7 @@ namespace bgfx { namespace d3d12 } if (BX_ENABLED(BGFX_CONFIG_DEBUG_PERFHUD) - && 0 != strstr(description, "PerfHUD") ) + && 0 != bx::strnstr(description, "PerfHUD") ) { m_adapter = adapter; m_driverType = D3D_DRIVER_TYPE_REFERENCE; diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 4f4267be9..e133a3c67 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -463,7 +463,7 @@ namespace bgfx { namespace d3d9 } if (BX_ENABLED(BGFX_CONFIG_DEBUG_PERFHUD) - && 0 != strstr(desc.Description, "PerfHUD") ) + && 0 != bx::strnstr(desc.Description, "PerfHUD") ) { m_adapter = ii; m_deviceType = D3DDEVTYPE_REF; diff --git a/tools/geometryc/geometryc.cpp b/tools/geometryc/geometryc.cpp index c18a39723..14275ba52 100644 --- a/tools/geometryc/geometryc.cpp +++ b/tools/geometryc/geometryc.cpp @@ -524,13 +524,13 @@ int main(int _argc, const char* _argv[]) index.m_vbc = 0; } - char* vertex = argv[edge+1]; - char* texcoord = strchr(vertex, '/'); + const char* vertex = argv[edge+1]; + char* texcoord = const_cast(bx::strnchr(vertex, '/') ); if (NULL != texcoord) { *texcoord++ = '\0'; - char* normal = strchr(texcoord, '/'); + char* normal = const_cast(bx::strnchr(texcoord, '/') ); if (NULL != normal) { *normal++ = '\0'; @@ -860,7 +860,7 @@ int main(int _argc, const char* _argv[]) if (hasTangent) { - calcTangents(vertexData, numVertices, decl, indexData, numIndices); + calcTangents(vertexData, uint16_t(numVertices), decl, indexData, numIndices); } bx::MemoryWriter memWriter(&memBlock); @@ -877,7 +877,7 @@ int main(int _argc, const char* _argv[]) , prim1.m_numIndices , vertexData + prim1.m_startVertex , numVertices - , stride + , uint16_t(stride) ); } } @@ -991,7 +991,7 @@ int main(int _argc, const char* _argv[]) { if (hasTangent) { - calcTangents(vertexData, numVertices, decl, indexData, numIndices); + calcTangents(vertexData, uint16_t(numVertices), decl, indexData, numIndices); } bx::MemoryWriter memWriter(&memBlock); @@ -1008,7 +1008,7 @@ int main(int _argc, const char* _argv[]) , prim1.m_numIndices , vertexData + prim1.m_startVertex , numVertices - , stride + , uint16_t(stride) ); } } diff --git a/tools/shaderc/shaderc.cpp b/tools/shaderc/shaderc.cpp index e19074605..b444bb3eb 100644 --- a/tools/shaderc/shaderc.cpp +++ b/tools/shaderc/shaderc.cpp @@ -141,11 +141,11 @@ namespace bgfx const char* interpolationDx11(const char* _glsl) { - if (0 == strcmp(_glsl, "smooth") ) + if (0 == bx::strncmp(_glsl, "smooth") ) { return "linear"; } - else if (0 == strcmp(_glsl, "flat") ) + else if (0 == bx::strncmp(_glsl, "flat") ) { return "nointerpolation"; } @@ -169,7 +169,7 @@ namespace bgfx for (uint32_t ii = 0; ii < UniformType::Count*2; ++ii) { if (NULL != s_uniformTypeName[ii] - && 0 == strcmp(_name, s_uniformTypeName[ii]) ) + && 0 == bx::strncmp(_name, s_uniformTypeName[ii]) ) { return UniformType::Enum(ii/2); } @@ -517,7 +517,10 @@ namespace bgfx { char* start = scratch(_includeDir); - for (char* split = strchr(start, ';'); NULL != split; split = strchr(start, ';') ) + for (char* split = const_cast(bx::strnchr(start, ';') ) + ; NULL != split + ; split = const_cast(bx::strnchr(start, ';') ) + ) { *split = '\0'; m_tagptr->tag = FPPTAG_INCLUDE_DIR; @@ -811,32 +814,32 @@ namespace bgfx const char* profile = cmdLine.findOption('p', "profile"); if (NULL != profile) { - if (0 == strncmp(&profile[1], "s_4_0_level", 11) ) + if (0 == bx::strncmp(&profile[1], "s_4_0_level", 11) ) { hlsl = 2; } - else if (0 == strncmp(&profile[1], "s_3", 3) ) + else if (0 == bx::strncmp(&profile[1], "s_3", 3) ) { hlsl = 3; d3d = 9; } - else if (0 == strncmp(&profile[1], "s_4", 3) ) + else if (0 == bx::strncmp(&profile[1], "s_4", 3) ) { hlsl = 4; } - else if (0 == strncmp(&profile[1], "s_5", 3) ) + else if (0 == bx::strncmp(&profile[1], "s_5", 3) ) { hlsl = 5; } - else if (0 == strcmp(profile, "metal") ) + else if (0 == bx::strncmp(profile, "metal") ) { metal = 1; } - else if (0 == strcmp(profile, "pssl") ) + else if (0 == bx::strncmp(profile, "pssl") ) { pssl = 1; } - else if (0 == strcmp(profile, "spirv") ) + else if (0 == bx::strncmp(profile, "spirv") ) { spirv = 1; } @@ -909,7 +912,7 @@ namespace bgfx && '\0' != *defines) { defines = bx::strws(defines); - const char* eol = strchr(defines, ';'); + const char* eol = bx::strnchr(defines, ';'); if (NULL == eol) { eol = defines + strlen(defines); @@ -1057,7 +1060,7 @@ namespace bgfx && *parse != '\0') { parse = bx::strws(parse); - const char* eol = strchr(parse, ';'); + const char* eol = bx::strnchr(parse, ';'); if (NULL == eol) { eol = bx::streol(parse); @@ -1069,18 +1072,18 @@ namespace bgfx const char* interpolation = NULL; const char* typen = parse; - if (0 == strncmp(typen, "lowp", 4) - || 0 == strncmp(typen, "mediump", 7) - || 0 == strncmp(typen, "highp", 5) ) + if (0 == bx::strncmp(typen, "lowp", 4) + || 0 == bx::strncmp(typen, "mediump", 7) + || 0 == bx::strncmp(typen, "highp", 5) ) { precision = typen; typen = parse = bx::strws(bx::strword(parse) ); } - if (0 == strncmp(typen, "flat", 4) - || 0 == strncmp(typen, "smooth", 6) - || 0 == strncmp(typen, "noperspective", 13) - || 0 == strncmp(typen, "centroid", 8) ) + if (0 == bx::strncmp(typen, "flat", 4) + || 0 == bx::strncmp(typen, "smooth", 6) + || 0 == bx::strncmp(typen, "noperspective", 13) + || 0 == bx::strncmp(typen, "centroid", 8) ) { interpolation = typen; typen = parse = bx::strws(bx::strword(parse) ); @@ -1184,21 +1187,21 @@ namespace bgfx const char* nl = bx::strnl(eol); input = const_cast(nl); - if (0 == strncmp(str, "input", 5) ) + if (0 == bx::strncmp(str, "input", 5) ) { str += 5; - const char* comment = strstr(str, "//"); + const char* comment = bx::strnstr(str, "//"); eol = NULL != comment && comment < eol ? comment : eol; inputHash = parseInOut(shaderInputs, str, eol); } - else if (0 == strncmp(str, "output", 6) ) + else if (0 == bx::strncmp(str, "output", 6) ) { str += 6; - const char* comment = strstr(str, "//"); + const char* comment = bx::strnstr(str, "//"); eol = NULL != comment && comment < eol ? comment : eol; outputHash = parseInOut(shaderOutputs, str, eol); } - else if (0 == strncmp(str, "raw", 3) ) + else if (0 == bx::strncmp(str, "raw", 3) ) { raw = true; str += 3; @@ -1268,7 +1271,7 @@ namespace bgfx } else if ('c' == shaderType) // Compute { - char* entry = strstr(input, "void main()"); + char* entry = const_cast(bx::strnstr(input, "void main()") ); if (NULL == entry) { fprintf(stderr, "Shader entry point 'void main()' is not found.\n"); @@ -1307,10 +1310,10 @@ namespace bgfx uint32_t arg = 0; - const bool hasLocalInvocationID = NULL != strstr(input, "gl_LocalInvocationID"); - const bool hasLocalInvocationIndex = NULL != strstr(input, "gl_LocalInvocationIndex"); - const bool hasGlobalInvocationID = NULL != strstr(input, "gl_GlobalInvocationID"); - const bool hasWorkGroupID = NULL != strstr(input, "gl_WorkGroupID"); + const bool hasLocalInvocationID = NULL != bx::strnstr(input, "gl_LocalInvocationID"); + const bool hasLocalInvocationIndex = NULL != bx::strnstr(input, "gl_LocalInvocationIndex"); + const bool hasGlobalInvocationID = NULL != bx::strnstr(input, "gl_GlobalInvocationID"); + const bool hasWorkGroupID = NULL != bx::strnstr(input, "gl_WorkGroupID"); if (hasLocalInvocationID) { @@ -1455,7 +1458,7 @@ namespace bgfx } else // Vertex/Fragment { - char* entry = strstr(input, "void main()"); + char* entry = const_cast(bx::strnstr(input, "void main()") ); if (NULL == entry) { fprintf(stderr, "Shader entry point 'void main()' is not found.\n"); @@ -1484,8 +1487,8 @@ namespace bgfx const Varying& var = varyingIt->second; const char* name = var.m_name.c_str(); - if (0 == strncmp(name, "a_", 2) - || 0 == strncmp(name, "i_", 2) ) + if (0 == bx::strncmp(name, "a_", 2) + || 0 == bx::strncmp(name, "i_", 2) ) { preprocessor.writef("attribute %s %s %s %s;\n" , var.m_precision.c_str() @@ -1555,17 +1558,17 @@ namespace bgfx if ('f' == shaderType) { - const char* insert = strstr(entry, "{"); + const char* insert = bx::strnstr(entry, "{"); if (NULL != insert) { insert = strInsert(const_cast(insert+1), "\nvec4 bgfx_VoidFrag = vec4_splat(0.0);\n"); } - const bool hasFragColor = NULL != strstr(input, "gl_FragColor"); - const bool hasFragCoord = NULL != strstr(input, "gl_FragCoord") || hlsl > 3 || hlsl == 2; - const bool hasFragDepth = NULL != strstr(input, "gl_FragDepth"); - const bool hasFrontFacing = NULL != strstr(input, "gl_FrontFacing"); - const bool hasPrimitiveId = NULL != strstr(input, "gl_PrimitiveID"); + const bool hasFragColor = NULL != bx::strnstr(input, "gl_FragColor"); + const bool hasFragCoord = NULL != bx::strnstr(input, "gl_FragCoord") || hlsl > 3 || hlsl == 2; + const bool hasFragDepth = NULL != bx::strnstr(input, "gl_FragDepth"); + const bool hasFrontFacing = NULL != bx::strnstr(input, "gl_FrontFacing"); + const bool hasPrimitiveId = NULL != bx::strnstr(input, "gl_PrimitiveID"); bool hasFragData[8] = {}; uint32_t numFragData = 0; @@ -1573,7 +1576,7 @@ namespace bgfx { char temp[32]; bx::snprintf(temp, BX_COUNTOF(temp), "gl_FragData[%d]", ii); - hasFragData[ii] = NULL != strstr(input, temp); + hasFragData[ii] = NULL != bx::strnstr(input, temp); numFragData += hasFragData[ii]; } @@ -1695,7 +1698,7 @@ namespace bgfx } else if ('v' == shaderType) { - const char* brace = strstr(entry, "{"); + const char* brace = bx::strnstr(entry, "{"); if (NULL != brace) { const char* end = bx::strmb(brace, '{', '}'); diff --git a/tools/shaderc/shaderc_glsl.cpp b/tools/shaderc/shaderc_glsl.cpp index ff0457a36..0b42a2f21 100644 --- a/tools/shaderc/shaderc_glsl.cpp +++ b/tools/shaderc/shaderc_glsl.cpp @@ -149,7 +149,7 @@ namespace bgfx { namespace glsl char uniformType[256]; parse = bx::strword(parse); - if (0 == strncmp(typen, "sampler", 7) ) + if (0 == bx::strncmp(typen, "sampler", 7) ) { bx::strlncpy(uniformType, BX_COUNTOF(uniformType), "int"); } diff --git a/tools/shaderc/shaderc_hlsl.cpp b/tools/shaderc/shaderc_hlsl.cpp index 24bf9dc24..fe74d58c4 100644 --- a/tools/shaderc/shaderc_hlsl.cpp +++ b/tools/shaderc/shaderc_hlsl.cpp @@ -520,7 +520,7 @@ namespace bgfx { namespace hlsl , bindDesc.BindCount ); - const char * end = strstr(bindDesc.Name, "Sampler"); + const char * end = bx::strnstr(bindDesc.Name, "Sampler"); if (NULL != end) { Uniform un; diff --git a/tools/shaderc/shaderc_spirv.cpp b/tools/shaderc/shaderc_spirv.cpp index 517192e20..97a902958 100644 --- a/tools/shaderc/shaderc_spirv.cpp +++ b/tools/shaderc/shaderc_spirv.cpp @@ -495,7 +495,7 @@ namespace bgfx { namespace spirv const SpvReflection::Id& id = it->second; uint32_t num = uint32_t(id.members.size() ); if (0 < num - && 0 != strcmp(id.var.name.c_str(), "gl_PerVertex") ) + && 0 != bx::strncmp(id.var.name.c_str(), "gl_PerVertex") ) { printf("%3d: %s %d %s\n" , it->first @@ -606,7 +606,7 @@ namespace bgfx { namespace spirv int32_t start = 0; int32_t end = INT32_MAX; - const char* err = strstr(log, "ERROR:"); + const char* err = bx::strnstr(log, "ERROR:"); bool found = false; diff --git a/tools/texturev/texturev.cpp b/tools/texturev/texturev.cpp index dadbe1aee..961c9b81b 100644 --- a/tools/texturev/texturev.cpp +++ b/tools/texturev/texturev.cpp @@ -312,7 +312,7 @@ struct View { if (0 == (item->d_type & DT_DIR) ) { - const char* ext = strrchr(item->d_name, '.'); + const char* ext = bx::strnrchr(item->d_name, '.'); if (NULL != ext) { ext += 1;