mcst-linux-kernel/patches-2024.06.26/gl4es-1.1.4/0232-Renamed-all-the-string...

1231 lines
64 KiB
Diff

From bf2fbaef0d6de3d12d9a61307516d87005eca46b Mon Sep 17 00:00:00 2001
From: ptitSeb <sebastien.chev@gmail.com>
Date: Thu, 5 Jan 2023 17:20:56 +0100
Subject: [PATCH 232/233] Renamed all the string utils function to make them
less likely to colide with other function (for #410)
---
src/gl/fpe_shader.c | 52 +++----
src/gl/shader_hacks.c | 14 +-
src/gl/shaderconv.c | 376 +++++++++++++++++++++++++-------------------------
src/gl/string_utils.c | 62 ++++-----
src/gl/string_utils.h | 36 ++---
5 files changed, 270 insertions(+), 270 deletions(-)
diff --git a/src/gl/fpe_shader.c b/src/gl/fpe_shader.c
index 86611d8d..8f959a9c 100644
--- a/src/gl/fpe_shader.c
+++ b/src/gl/fpe_shader.c
@@ -20,7 +20,7 @@ static int shad_cap = 0;
static int comments = 1;
-#define ShadAppend(S) shad = Append(shad, &shad_cap, S)
+#define ShadAppend(S) shad = gl4es_append(shad, &shad_cap, S)
// 2D Rectangle 3D CubeMap Stream
const char* texvecsize[] = {"vec4", "vec2", "vec2", "vec3", "vec2"};
@@ -204,11 +204,11 @@ const char* const* fpe_VertexShader(shaderconv_need_t* need, fpe_state_t *state)
sprintf(buff, "// ** Vertex Shader **\n// ligthting=%d (twosided=%d, separate=%d, color_material=%d)\n// secondary=%d, planes=%s\n// point=%d%s\n",
lighting, twosided, light_separate, color_material, secondary, fpe_binary(planes, 6), point, need?" with need":"");
ShadAppend(buff);
- headers+=CountLine(buff);
+ headers+=gl4es_countline(buff);
if(need) {
sprintf(buff, "// need: color=%d, texs=%s, fogcoord=%d\n", need->need_color, fpe_binary(need->need_texs, 16), need->need_fogcoord);
ShadAppend(buff);
- headers+=CountLine(buff);
+ headers+=gl4es_countline(buff);
}
}
if(!is_default) {
@@ -247,7 +247,7 @@ const char* const* fpe_VertexShader(shaderconv_need_t* need, fpe_state_t *state)
: ""
);
ShadAppend(buff);
- headers += CountLine(buff);
+ headers += gl4es_countline(buff);
sprintf(buff,
"struct _gl4es_FPELightSourceParameters0\n"
"{\n"
@@ -264,7 +264,7 @@ const char* const* fpe_VertexShader(shaderconv_need_t* need, fpe_state_t *state)
: ""
);
ShadAppend(buff);
- headers += CountLine(buff);
+ headers += gl4es_countline(buff);
sprintf(buff,
"struct _gl4es_LightProducts\n"
@@ -275,7 +275,7 @@ const char* const* fpe_VertexShader(shaderconv_need_t* need, fpe_state_t *state)
"};\n"
);
ShadAppend(buff);
- headers += CountLine(buff);
+ headers += gl4es_countline(buff);
if(!(cm_front_nullexp && color_material)) {
ShadAppend("uniform highp float _gl4es_FrontMaterial_shininess;\n");
@@ -365,7 +365,7 @@ const char* const* fpe_VertexShader(shaderconv_need_t* need, fpe_state_t *state)
// let's start
ShadAppend("\nvoid main() {\n");
int need_normal = 0;
- int normal_line = CountLine(shad) - headers;
+ int normal_line = gl4es_countline(shad) - headers;
if(planes) {
for (int i=0; i<hardext.maxplanes; i++) {
if((planes>>i)&1) {
@@ -722,8 +722,8 @@ const char* const* fpe_VertexShader(shaderconv_need_t* need, fpe_state_t *state)
if(need_vertex==1)
strcat(buff, "vec4 ");
strcat(buff, "vertex = gl_ModelViewMatrix * gl_Vertex;\n");
- shad = InplaceInsert(GetLine(shad, normal_line + headers), buff, shad, &shad_cap);
- normal_line += CountLine(buff);
+ shad = gl4es_inplace_insert(gl4es_getline(shad, normal_line + headers), buff, shad, &shad_cap);
+ normal_line += gl4es_countline(buff);
}
if(need_normal) {
#if 0
@@ -741,7 +741,7 @@ const char* const* fpe_VertexShader(shaderconv_need_t* need, fpe_state_t *state)
//strcpy(buff, "vec3 normal = (vec4(gl_Normal, (gl_Vertex.w==0.0)?0.0:(-dot(gl_Normal, gl_Vertex.xyz)/gl_Vertex.w))*gl_ModelViewMatrixInverse).xyz;\n");
strcpy(buff, "vec3 normal = gl_NormalMatrix * gl_Normal;\n");
#endif
- shad = InplaceInsert(GetLine(shad, normal_line + headers), buff, shad, &shad_cap);
+ shad = gl4es_inplace_insert(gl4es_getline(shad, normal_line + headers), buff, shad, &shad_cap);
}
buff[0] = '\0';
for (int i=0; i<MAX_TEX; i++) {
@@ -762,8 +762,8 @@ const char* const* fpe_VertexShader(shaderconv_need_t* need, fpe_state_t *state)
}
}
if(buff[0]!='\0') {
- shad = InplaceInsert(GetLine(shad, headers), buff, shad, &shad_cap);
- headers += CountLine(buff);
+ shad = gl4es_inplace_insert(gl4es_getline(shad, headers), buff, shad, &shad_cap);
+ headers += gl4es_countline(buff);
}
if(fog) {
if(comments) {
@@ -862,7 +862,7 @@ const char* const* fpe_FragmentShader(shaderconv_need_t* need, fpe_state_t *stat
if(comments) {
sprintf(buff, "// ** Fragment Shader **\n// lighting=%d, alpha=%d, secondary=%d, planes=%s, texturing=%d point=%d\n", lighting, alpha_test, secondary, fpe_binary(planes, 6), texturing, point);
ShadAppend(buff);
- headers+=CountLine(buff);
+ headers+=gl4es_countline(buff);
}
ShadAppend("varying vec4 Color;\n");
headers++;
@@ -1029,8 +1029,8 @@ const char* const* fpe_FragmentShader(shaderconv_need_t* need, fpe_state_t *stat
case FPE_BLEND:
// create the Uniform for TexEnv Constant color
sprintf(buff, "uniform lowp vec4 _gl4es_TextureEnvColor_%d;\n", i);
- shad = InplaceInsert(GetLine(shad, headers), buff, shad, &shad_cap);
- headers+=CountLine(buff);
+ shad = gl4es_inplace_insert(gl4es_getline(shad, headers), buff, shad, &shad_cap);
+ headers+=gl4es_countline(buff);
needclamp=0;
if(texformat!=FPE_TEX_ALPHA) {
sprintf(buff, "fColor.rgb = mix(fColor.rgb, _gl4es_TextureEnvColor_%d.rgb, texColor%d.rgb);\n", i, i);
@@ -1140,8 +1140,8 @@ const char* const* fpe_FragmentShader(shaderconv_need_t* need, fpe_state_t *stat
if(constant) {
// yep, create the Uniform
sprintf(buff, "uniform lowp vec4 _gl4es_TextureEnvColor_%d;\n", i);
- shad = InplaceInsert(GetLine(shad, headers), buff, shad, &shad_cap);
- headers+=CountLine(buff);
+ shad = gl4es_inplace_insert(gl4es_getline(shad, headers), buff, shad, &shad_cap);
+ headers+=gl4es_countline(buff);
}
for (int j=0; j<4; j++) {
if(src_r[j]==src_a[j] && op_r[j]==FPE_OP_SRCCOLOR && op_a[j]==FPE_OP_ALPHA) {
@@ -1633,7 +1633,7 @@ const char* const* fpe_CustomVertexShader(const char* initial, fpe_state_t* stat
char buff[1024];
if(!shad_cap) shad_cap = 1024;
if(!shad) shad = (char*)malloc(shad_cap);
- int headline = GetLineFor(initial, "main");
+ int headline = gl4es_getline_for(initial, "main");
if(headline) --headline;
strcpy(shad, "");
@@ -1665,7 +1665,7 @@ if(default_fragment) printf("fpe_CustomVertexShader(%p, %p, %d)\n%s\ncolor=%d\n"
// wrap main if needed
if(planes || color) {
// wrap real main...
- shad = InplaceReplace(shad, &shad_cap, "main", "_gl4es_main");
+ shad = gl4es_inplace_replace(shad, &shad_cap, "main", "_gl4es_main");
}
// let's start
@@ -1702,7 +1702,7 @@ const char* const* fpe_CustomFragmentShader(const char* initial, fpe_state_t* st
int alpha_func = state->alphafunc;
int shaderblend = state->blend_enable;
char buff[1024];
- int headline = GetLineFor(initial, "main");
+ int headline = gl4es_getline_for(initial, "main");
if(headline) --headline;
strcpy(shad, "");
@@ -1732,11 +1732,11 @@ const char* const* fpe_CustomFragmentShader(const char* initial, fpe_state_t* st
int is_fragcolor = (strstr(shad, "gl_FragColor")!=NULL)?1:0;
if(alpha_test || planes || shaderblend) {
// wrap real main...
- shad = InplaceReplace(shad, &shad_cap, "main", "_gl4es_main");
+ shad = gl4es_inplace_replace(shad, &shad_cap, "main", "_gl4es_main");
if(is_fragcolor) {
- int l_main = GetLineFor(shad, PrevStr(shad, strstr(shad, "_gl4es_main"))) - 1;
- shad = InplaceInsert(GetLine(shad, l_main), "lowp vec4 _gl4es_FragColor;\n", shad, &shad_cap);
- shad = InplaceReplace(shad, &shad_cap, "gl_FragColor", "_gl4es_FragColor");
+ int l_main = gl4es_getline_for(shad, gl4es_prev_str(shad, strstr(shad, "_gl4es_main"))) - 1;
+ shad = gl4es_inplace_insert(gl4es_getline(shad, l_main), "lowp vec4 _gl4es_FragColor;\n", shad, &shad_cap);
+ shad = gl4es_inplace_replace(shad, &shad_cap, "gl_FragColor", "_gl4es_FragColor");
}
}
if(strstr(shad, "_gl4es_main")) {
@@ -1760,8 +1760,8 @@ const char* const* fpe_CustomFragmentShader(const char* initial, fpe_state_t* st
//*** Alpha Test
if(alpha_test) {
if(alpha_test && alpha_func>FPE_NEVER) {
- shad = InplaceInsert(GetLine(shad, headline), gl4es_alphaRefSource, shad, &shad_cap);
- headline+=CountLine(gl4es_alphaRefSource);
+ shad = gl4es_inplace_insert(gl4es_getline(shad, headline), gl4es_alphaRefSource, shad, &shad_cap);
+ headline+=gl4es_countline(gl4es_alphaRefSource);
}
if(comments) {
sprintf(buff, "// Alpha Test, fct=%X\n", alpha_func);
diff --git a/src/gl/shader_hacks.c b/src/gl/shader_hacks.c
index 35b39497..a5561555 100644
--- a/src/gl/shader_hacks.c
+++ b/src/gl/shader_hacks.c
@@ -509,8 +509,8 @@ static char* ShaderHacks_1(char* shader, char* Tmp, int* tmpsize)
// Do the replace
for (int i=0; i<sizeof(gl4es_hacks_1)/sizeof(gl4es_hacks_1[0]); i+=2)
if(strstr(Tmp, gl4es_hacks_1[i])) {
- if(Tmp==shader) {Tmp = malloc(*tmpsize); strcpy(Tmp, shader);} // hacking!
- Tmp = InplaceReplaceSimple(Tmp, tmpsize, gl4es_hacks_1[i], gl4es_hacks_1[i+1]);
+ if(Tmp==shader) {Tmp = (char*)malloc(*tmpsize); strcpy(Tmp, shader);} // hacking!
+ Tmp = gl4es_inplace_replace_simple(Tmp, tmpsize, gl4es_hacks_1[i], gl4es_hacks_1[i+1]);
}
return Tmp;
}
@@ -523,10 +523,10 @@ static char* ShaderHacks_2_1(char* shader, char* Tmp, int* tmpsize, int i)
if(!m) return Tmp; // main signature not found
if((uintptr_t)p > (uintptr_t)m) return Tmp; // main is before, aborting...
// ok, instance found, insert main line...
- if(Tmp==shader) {Tmp = malloc(*tmpsize); strcpy(Tmp, shader); m = strstr(Tmp, gl4es_sign_2_main);} // hacking!
+ if(Tmp==shader) {Tmp = (char*)malloc(*tmpsize); strcpy(Tmp, shader); m = strstr(Tmp, gl4es_sign_2_main);} // hacking!
m += strlen(gl4es_sign_2_main);
- Tmp = InplaceInsert(m, gl4es_hacks_2_2[i], Tmp, tmpsize);
- Tmp = InplaceReplaceSimple(Tmp, tmpsize, gl4es_sign_2[i], gl4es_hacks_2_1[i]);
+ Tmp = gl4es_inplace_insert(m, gl4es_hacks_2_2[i], Tmp, tmpsize);
+ Tmp = gl4es_inplace_replace_simple(Tmp, tmpsize, gl4es_sign_2[i], gl4es_hacks_2_1[i]);
return Tmp;
}
@@ -550,10 +550,10 @@ char* ShaderHacks(char* shader)
char* f = gl4es_hacks[i].sign;
int n = gl4es_hacks[i].n;
if(strstr(Tmp, f)) {
- if(Tmp==shader) {Tmp = malloc(tmpsize); strcpy(Tmp, shader);} // hacking!
+ if(Tmp==shader) {Tmp = (char*)malloc(tmpsize); strcpy(Tmp, shader);} // hacking!
for (int j=0; j<n; j+=2) {
if(j) f = gl4es_hacks[i].next[j-1];
- Tmp = InplaceReplaceSimple(Tmp, &tmpsize, f, gl4es_hacks[i].next[j]);
+ Tmp = gl4es_inplace_replace_simple(Tmp, &tmpsize, f, gl4es_hacks[i].next[j]);
}
}
}
diff --git a/src/gl/shaderconv.c b/src/gl/shaderconv.c
index 3ad9026b..42225ccb 100644
--- a/src/gl/shaderconv.c
+++ b/src/gl/shaderconv.c
@@ -439,7 +439,7 @@ char gl4es_VA[MAX_VATTRIB][32] = {0};
char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
{
- #define ShadAppend(S) Tmp = Append(Tmp, &tmpsize, S)
+ #define ShadAppend(S) Tmp = gl4es_append(Tmp, &tmpsize, S)
if(gl_VA[0][0]=='\0') {
for (int i=0; i<MAX_VATTRIB; ++i) {
@@ -472,7 +472,7 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
// now comment all line starting with precision...
if(strstr(pBuffer, "\nprecision")) {
int sz = strlen(pBuffer);
- pBuffer = InplaceReplace(pBuffer, &sz, "\nprecision", "\n//precision");
+ pBuffer = gl4es_inplace_replace(pBuffer, &sz, "\nprecision", "\n//precision");
}
// should do something with the extension list...
if(exts.ext)
@@ -517,16 +517,16 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
char* newptr;
newptr=strstr(Tmp, "#version");
if (!newptr) {
- Tmp = InplaceInsert(Tmp, GLESFullHeader, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(Tmp, GLESFullHeader, Tmp, &tmpsize);
} else {
while(*newptr!=0x0a) newptr++;
newptr++;
memmove(Tmp, newptr, strlen(newptr)+1);
- Tmp = InplaceInsert(Tmp, GLESFullHeader, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(Tmp, GLESFullHeader, Tmp, &tmpsize);
}
int headline = 3;
// move all "#extension in header zone"
- while (strstr(Tmp, "#extension") && strstr(Tmp, "#extension")>GetLine(Tmp, headline-2)) {
+ while (strstr(Tmp, "#extension") && strstr(Tmp, "#extension")>gl4es_getline(Tmp, headline-2)) {
char* ext = strstr(Tmp, "#extension");
size_t l = (uintptr_t)strstr(ext, "\n")-(uintptr_t)ext + sizeof("\n");
#ifndef _MSC_VER
@@ -536,8 +536,8 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
#endif
memset(e, 0, l);
strncpy(e, ext, l-1);
- Tmp = InplaceReplaceSimple(Tmp, &tmpsize, e, "");
- Tmp = InplaceInsert(GetLine(Tmp, headline-2), e, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_replace_simple(Tmp, &tmpsize, e, "");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline-2), e, Tmp, &tmpsize);
++headline;
}
// check if gl_FragDepth is used
@@ -547,9 +547,9 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
if (fragdepth) {
/* If #extension is used, it should be placed before the second line of the header. */
if(hardext.fragdepth)
- Tmp = InplaceInsert(GetLine(Tmp, 1), GLESUseFragDepth, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, 1), GLESUseFragDepth, Tmp, &tmpsize);
else
- Tmp = InplaceInsert(GetLine(Tmp, headline-1), GLESFakeFragDepth, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline-1), GLESFakeFragDepth, Tmp, &tmpsize);
headline++;
}
int derivatives = (strstr(pBuffer, "dFdx(") || strstr(pBuffer, "dFdy(") || strstr(pBuffer, "fwidth("))?1:0;
@@ -562,89 +562,89 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
if (derivatives) {
/* If #extension is used, it should be placed before the second line of the header. */
if(hardext.derivatives)
- Tmp = InplaceInsert(GetLine(Tmp, 1), GLESUseDerivative, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, 1), GLESUseDerivative, Tmp, &tmpsize);
else
- Tmp = InplaceInsert(GetLine(Tmp, headline-1), GLESFakeDerivative, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline-1), GLESFakeDerivative, Tmp, &tmpsize);
headline++;
}
// check if draw_buffers may be used (no fallback here :( )
if(hardext.maxdrawbuffers>1 && strstr(pBuffer, "gl_FragData[")) {
- Tmp = InplaceInsert(GetLine(Tmp, 1), useEXTDrawBuffers, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, 1), useEXTDrawBuffers, Tmp, &tmpsize);
}
// if some functions are used, add some int/float alternative
if(!fpeShader && !globals4es.nointovlhack) {
if(strstr(Tmp, "pow(") || strstr(Tmp, "pow (")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), HackAltPow, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), HackAltPow, Tmp, &tmpsize);
}
if(strstr(Tmp, "max(") || strstr(Tmp, "max (")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), HackAltMax, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), HackAltMax, Tmp, &tmpsize);
}
if(strstr(Tmp, "min(") || strstr(Tmp, "min (")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), HackAltMin, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), HackAltMin, Tmp, &tmpsize);
}
if(strstr(Tmp, "clamp(") || strstr(Tmp, "clamp (")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), HackAltClamp, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), HackAltClamp, Tmp, &tmpsize);
}
if(strstr(Tmp, "mod(") || strstr(Tmp, "mod (")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), HackAltMod, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), HackAltMod, Tmp, &tmpsize);
}
}
if(!isVertex && hardext.shaderlod &&
- (FindString(Tmp, "texture2DLod") || FindString(Tmp, "texture2DProjLod")
- || FindString(Tmp, "textureCubeLod")
- || FindString(Tmp, "texture2DGradARB") || FindString(Tmp, "texture2DProjGradARB")|| FindString(Tmp, "textureCubeGradARB")
+ (gl4es_find_string(Tmp, "texture2DLod") || gl4es_find_string(Tmp, "texture2DProjLod")
+ || gl4es_find_string(Tmp, "textureCubeLod")
+ || gl4es_find_string(Tmp, "texture2DGradARB") || gl4es_find_string(Tmp, "texture2DProjGradARB")|| gl4es_find_string(Tmp, "textureCubeGradARB")
)) {
const char* GLESUseShaderLod = "#extension GL_EXT_shader_texture_lod : enable\n";
- Tmp = InplaceInsert(GetLine(Tmp, 1), GLESUseShaderLod, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, 1), GLESUseShaderLod, Tmp, &tmpsize);
}
- if(!isVertex && (FindString(Tmp, "texture2DLod"))) {
+ if(!isVertex && (gl4es_find_string(Tmp, "texture2DLod"))) {
if(hardext.shaderlod) {
- Tmp = InplaceReplace(Tmp, &tmpsize, "texture2DLod", "texture2DLodEXT");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "texture2DLod", "texture2DLodEXT");
} else {
- Tmp = InplaceReplace(Tmp, &tmpsize, "texture2DLod", "_gl4es_texture2DLod");
- Tmp = InplaceInsert(GetLine(Tmp, headline), texture2DLodAlt, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "texture2DLod", "_gl4es_texture2DLod");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), texture2DLodAlt, Tmp, &tmpsize);
}
}
- if(!isVertex && (FindString(Tmp, "texture2DProjLod"))) {
+ if(!isVertex && (gl4es_find_string(Tmp, "texture2DProjLod"))) {
if(hardext.shaderlod) {
- Tmp = InplaceReplace(Tmp, &tmpsize, "texture2DProjLod", "texture2DProjLodEXT");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "texture2DProjLod", "texture2DProjLodEXT");
} else {
- Tmp = InplaceReplace(Tmp, &tmpsize, "texture2DProjLod", "_gl4es_texture2DProjLod");
- Tmp = InplaceInsert(GetLine(Tmp, headline), texture2DProjLodAlt, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "texture2DProjLod", "_gl4es_texture2DProjLod");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), texture2DProjLodAlt, Tmp, &tmpsize);
}
}
- if(!isVertex && (FindString(Tmp, "textureCubeLod"))) {
+ if(!isVertex && (gl4es_find_string(Tmp, "textureCubeLod"))) {
if(hardext.shaderlod) {
if(!hardext.cubelod)
- Tmp = InplaceReplace(Tmp, &tmpsize, "textureCubeLod", "textureCubeLodEXT");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "textureCubeLod", "textureCubeLodEXT");
} else {
- Tmp = InplaceReplace(Tmp, &tmpsize, "textureCubeLod", "_gl4es_textureCubeLod");
- Tmp = InplaceInsert(GetLine(Tmp, headline), textureCubeLodAlt, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "textureCubeLod", "_gl4es_textureCubeLod");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), textureCubeLodAlt, Tmp, &tmpsize);
}
}
- if(!isVertex && (FindString(Tmp, "texture2DGradARB"))) {
+ if(!isVertex && (gl4es_find_string(Tmp, "texture2DGradARB"))) {
if(hardext.shaderlod) {
- Tmp = InplaceReplace(Tmp, &tmpsize, "texture2DGradARB", "texture2DGradEXT");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "texture2DGradARB", "texture2DGradEXT");
} else {
- Tmp = InplaceReplace(Tmp, &tmpsize, "texture2DGradARB", "_gl4es_texture2DGrad");
- Tmp = InplaceInsert(GetLine(Tmp, headline), texture2DGradAlt, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "texture2DGradARB", "_gl4es_texture2DGrad");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), texture2DGradAlt, Tmp, &tmpsize);
}
}
- if(!isVertex && (FindString(Tmp, "texture2DProjGradARB"))) {
+ if(!isVertex && (gl4es_find_string(Tmp, "texture2DProjGradARB"))) {
if(hardext.shaderlod) {
- Tmp = InplaceReplace(Tmp, &tmpsize, "texture2DProjGradARB", "texture2DProjGradEXT");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "texture2DProjGradARB", "texture2DProjGradEXT");
} else {
- Tmp = InplaceReplace(Tmp, &tmpsize, "texture2DProjGradARB", "_gl4es_texture2DProjGrad");
- Tmp = InplaceInsert(GetLine(Tmp, headline), texture2DProjGradAlt, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "texture2DProjGradARB", "_gl4es_texture2DProjGrad");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), texture2DProjGradAlt, Tmp, &tmpsize);
}
}
- if(!isVertex && (FindString(Tmp, "textureCubeGradARB"))) {
+ if(!isVertex && (gl4es_find_string(Tmp, "textureCubeGradARB"))) {
if(hardext.shaderlod) {
if(!hardext.cubelod)
- Tmp = InplaceReplace(Tmp, &tmpsize, "textureCubeGradARB", "textureCubeGradEXT");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "textureCubeGradARB", "textureCubeGradEXT");
} else {
- Tmp = InplaceReplace(Tmp, &tmpsize, "textureCubeGradARB", "_gl4es_textureCubeGrad");
- Tmp = InplaceInsert(GetLine(Tmp, headline), textureCubeGradAlt, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "textureCubeGradARB", "_gl4es_textureCubeGrad");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), textureCubeGradAlt, Tmp, &tmpsize);
}
}
@@ -712,12 +712,12 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
}
newptr++;
}
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FragDepth", (hardext.fragdepth)?"gl_FragDepthEXT":"fakeFragDepth");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_FragDepth", (hardext.fragdepth)?"gl_FragDepthEXT":"fakeFragDepth");
// builtin attribs
if(isVertex) {
// check for ftransform function
if(strstr(Tmp, "ftransform(")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_ftransformSource, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_ftransformSource, Tmp, &tmpsize);
// don't increment headline count, as all variying and attributes should be created before
}
// check for builtin OpenGL attributes...
@@ -726,21 +726,21 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
if(strstr(Tmp, builtin_attrib[i].glname)) {
// ok, this attribute is used
// replace gl_name by _gl4es_ one
- Tmp = InplaceReplace(Tmp, &tmpsize, builtin_attrib[i].glname, builtin_attrib[i].name);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, builtin_attrib[i].glname, builtin_attrib[i].name);
// insert a declaration of it
char def[100];
sprintf(def, "attribute %s %s %s;\n", builtin_attrib[i].prec, builtin_attrib[i].type, builtin_attrib[i].name);
- Tmp = InplaceInsert(GetLine(Tmp, headline++), def, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline++), def, Tmp, &tmpsize);
}
}
if(strstr(Tmp, gl_VertexAttrib)) {
// Generic VA from Old Programs
for (int i=0; i<MAX_VATTRIB; ++i) {
char A[100];
- if(FindString(Tmp, gl_VA[i])) {
+ if(gl4es_find_string(Tmp, gl_VA[i])) {
sprintf(A, "attribute highp vec4 %s%d;\n", gl4es_VertexAttrib, i);
- Tmp = InplaceReplace(Tmp, &tmpsize, gl_VA[i], gl4es_VA[i]);
- Tmp = InplaceInsert(GetLine(Tmp, headline++), A, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, gl_VA[i], gl4es_VA[i]);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline++), A, Tmp, &tmpsize);
}
}
}
@@ -749,46 +749,46 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
int nvarying = 0;
if(strstr(Tmp, "gl_Color") || need->need_color) {
if(need->need_color<1) need->need_color = 1;
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_Color", (need->need_color==1)?"gl_FrontColor":"(gl_FrontFacing?gl_FrontColor:gl_BackColor)");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_Color", (need->need_color==1)?"gl_FrontColor":"(gl_FrontFacing?gl_FrontColor:gl_BackColor)");
}
if(strstr(Tmp, "gl_FrontColor") || need->need_color) {
if(need->need_color<1) need->need_color = 1;
nvarying+=1;
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_frontColorSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_frontColorSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FrontColor", "_gl4es_FrontColor");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_frontColorSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_frontColorSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_FrontColor", "_gl4es_FrontColor");
}
if(strstr(Tmp, "gl_BackColor") || (need->need_color==2)) {
need->need_color = 2;
nvarying+=1;
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_backColorSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_backColorSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_BackColor", "_gl4es_BackColor");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_backColorSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_backColorSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_BackColor", "_gl4es_BackColor");
}
if(strstr(Tmp, "gl_SecondaryColor") || need->need_secondary) {
if(need->need_secondary<1) need->need_secondary = 1;
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_SecondaryColor", (need->need_secondary==1)?"gl_FrontSecondaryColor":"(gl_FrontFacing?gl_FrontSecondaryColor:gl_BackSecondaryColor)");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_SecondaryColor", (need->need_secondary==1)?"gl_FrontSecondaryColor":"(gl_FrontFacing?gl_FrontSecondaryColor:gl_BackSecondaryColor)");
}
if(strstr(Tmp, "gl_FrontSecondaryColor") || need->need_secondary) {
if(need->need_secondary<1) need->need_secondary = 1;
nvarying+=1;
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_frontSecondaryColorSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_frontSecondaryColorSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FrontSecondaryColor", "_gl4es_FrontSecondaryColor");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_frontSecondaryColorSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_frontSecondaryColorSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_FrontSecondaryColor", "_gl4es_FrontSecondaryColor");
}
if(strstr(Tmp, "gl_BackSecondaryColor") || (need->need_secondary==2)) {
need->need_secondary = 2;
nvarying+=1;
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_backSecondaryColorSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_backSecondaryColorSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_BackSecondaryColor", "_gl4es_BackSecondaryColor");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_backSecondaryColorSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_backSecondaryColorSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_BackSecondaryColor", "_gl4es_BackSecondaryColor");
}
if(strstr(Tmp, "gl_FogFragCoord") || need->need_fogcoord) {
need->need_fogcoord = 1;
nvarying+=1;
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_fogcoordSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_fogcoordSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FogFragCoord", "_gl4es_FogFragCoord");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_fogcoordSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_fogcoordSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_FogFragCoord", "_gl4es_FogFragCoord");
}
// Get the max_texunit and the calc notexarray
if(strstr(Tmp, "gl_TexCoord") || need->need_texcoord!=-1) {
@@ -828,10 +828,10 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
sprintf(d2, "gl_TexCoord[%d]", k);
if(strstr(Tmp, d2)) {
sprintf(d, gl4es_texcoordSourceAlt, k);
- Tmp = InplaceInsert(GetLine(Tmp, headline), d, Tmp, &tmpsize);
- headline+=CountLine(d);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), d, Tmp, &tmpsize);
+ headline+=gl4es_countline(d);
sprintf(d, "_gl4es_TexCoord_%d", k);
- Tmp = InplaceReplace(Tmp, &tmpsize, d2, d);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, d2, d);
}
// check if texture is there
sprintf(d2, "_gl4es_TexCoord_%d", k);
@@ -840,9 +840,9 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
}
} else {
sprintf(d, gl4es_texcoordSource, ntex+1);
- Tmp = InplaceInsert(GetLine(Tmp, headline), d, Tmp, &tmpsize);
- headline+=CountLine(d);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_TexCoord", "_gl4es_TexCoord");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), d, Tmp, &tmpsize);
+ headline+=gl4es_countline(d);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_TexCoord", "_gl4es_TexCoord");
// set textures as all ntex used
for (int k=0; k<ntex+1; k++)
need->need_texs |= (1<<k);
@@ -852,8 +852,8 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
// builtin matrices work
{
if(strstr(Tmp, "transpose(") || strstr(Tmp, "transpose ") || strstr(Tmp, "transpose\t")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_transpose, Tmp, &tmpsize);
- InplaceReplace(Tmp, &tmpsize, "transpose", "gl4es_transpose");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_transpose, Tmp, &tmpsize);
+ gl4es_inplace_replace(Tmp, &tmpsize, "transpose", "gl4es_transpose");
// don't increment headline count, as all variying and attributes should be created before
}
// check for builtin matrix uniform...
@@ -896,7 +896,7 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
sprintf(d2, "gl_TextureMatrix[%d]", k);
if(strstr(Tmp, d2)) {
sprintf(d, "gl_TextureMatrix_%d", k);
- Tmp = InplaceReplace(Tmp, &tmpsize, d2, d);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, d2, d);
}
}
}
@@ -906,7 +906,7 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
if(strstr(Tmp, builtin_matrix[i].glname)) {
// ok, this matrix is used
// replace gl_name by _gl4es_ one
- Tmp = InplaceReplace(Tmp, &tmpsize, builtin_matrix[i].glname, builtin_matrix[i].name);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, builtin_matrix[i].glname, builtin_matrix[i].name);
// insert a declaration of it
char def[100];
int ishighp = (isVertex || hardext.highp)?1:0;
@@ -932,7 +932,7 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
sprintf(def, "uniform %s%s %s[%d];\n", (ishighp)?"highp ":"mediump ", builtin_matrix[i].type, builtin_matrix[i].name, ntex);
else
sprintf(def, "uniform %s%s %s;\n", (ishighp)?"highp ":"mediump ", builtin_matrix[i].type, builtin_matrix[i].name);
- Tmp = InplaceInsert(GetLine(Tmp, headline++), def, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline++), def, Tmp, &tmpsize);
}
}
}
@@ -950,7 +950,7 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
char p4[500], p5[500];
sprintf(p4, "%s.halfVector", p3);
sprintf(p5, "normalize(normalize(%s.position.xyz) + vec3(0., 0., 1.))", p3);
- Tmp = InplaceReplace(Tmp, &tmpsize, p4, p5);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, p4, p5);
p = Tmp;
} else
++p;
@@ -963,7 +963,7 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
while((p=strstr(p, "centroid"))!=NULL)
{
if(p[8]==' ' || p[8]=='\t') { // what next...
- const char* p2 = GetNextStr(p+8);
+ const char* p2 = gl4es_get_next_str(p+8);
if(strcmp(p2, "uniform")==0 || strcmp(p2, "varying")==0) {
memset(p, ' ', 8); // erase the keyword...
}
@@ -975,172 +975,172 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
// check for builtin OpenGL gl_LightSource & friends
if(strstr(Tmp, "gl_LightSourceParameters") || strstr(Tmp, "gl_LightSource"))
{
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_LightSourceParametersSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_LightSourceParametersSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_LightSourceParameters", "_gl4es_LightSourceParameters");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_LightSourceParametersSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_LightSourceParametersSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_LightSourceParameters", "_gl4es_LightSourceParameters");
}
if(strstr(Tmp, "gl_LightModelParameters") || strstr(Tmp, "gl_LightModel"))
{
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_LightModelParametersSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_LightModelParametersSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_LightModelParameters", "_gl4es_LightModelParameters");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_LightModelParametersSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_LightModelParametersSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_LightModelParameters", "_gl4es_LightModelParameters");
}
if(strstr(Tmp, "gl_LightModelProducts") || strstr(Tmp, "gl_FrontLightModelProduct") || strstr(Tmp, "gl_BackLightModelProduct"))
{
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_LightModelProductsSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_LightModelProductsSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_LightModelProducts", "_gl4es_LightModelProducts");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_LightModelProductsSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_LightModelProductsSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_LightModelProducts", "_gl4es_LightModelProducts");
}
if(strstr(Tmp, "gl_LightProducts") || strstr(Tmp, "gl_FrontLightProduct") || strstr(Tmp, "gl_BackLightProduct"))
{
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_LightProductsSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_LightProductsSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_LightProducts", "_gl4es_LightProducts");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_LightProductsSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_LightProductsSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_LightProducts", "_gl4es_LightProducts");
}
if(strstr(Tmp, "gl_MaterialParameters ") || (strstr(Tmp, "gl_FrontMaterial")) || strstr(Tmp, "gl_BackMaterial"))
{
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_MaterialParametersSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_MaterialParametersSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_MaterialParameters", "_gl4es_MaterialParameters");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_MaterialParametersSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_MaterialParametersSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_MaterialParameters", "_gl4es_MaterialParameters");
}
if(strstr(Tmp, "gl_LightSource")) {
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_LightSource", "_gl4es_LightSource");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_LightSource", "_gl4es_LightSource");
}
if(strstr(Tmp, "gl_LightModel"))
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_LightModel", "_gl4es_LightModel");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_LightModel", "_gl4es_LightModel");
if(strstr(Tmp, "gl_FrontLightModelProduct"))
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FrontLightModelProduct", "_gl4es_FrontLightModelProduct");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_FrontLightModelProduct", "_gl4es_FrontLightModelProduct");
if(strstr(Tmp, "gl_BackLightModelProduct"))
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_BackLightModelProduct", "_gl4es_BackLightModelProduct");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_BackLightModelProduct", "_gl4es_BackLightModelProduct");
if(strstr(Tmp, "gl_FrontLightProduct"))
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FrontLightProduct", "_gl4es_FrontLightProduct");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_FrontLightProduct", "_gl4es_FrontLightProduct");
if(strstr(Tmp, "gl_BackLightProduct"))
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_BackLightProduct", "_gl4es_BackLightProduct");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_BackLightProduct", "_gl4es_BackLightProduct");
if(strstr(Tmp, "gl_FrontMaterial"))
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FrontMaterial", "_gl4es_FrontMaterial");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_FrontMaterial", "_gl4es_FrontMaterial");
if(strstr(Tmp, "gl_BackMaterial"))
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_BackMaterial", "_gl4es_BackMaterial");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_BackMaterial", "_gl4es_BackMaterial");
if(strstr(Tmp, "gl_MaxLights"))
{
- Tmp = InplaceInsert(GetLine(Tmp, 2), gl4es_MaxLightsSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_MaxLightsSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_MaxLights", "_gl4es_MaxLights");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, 2), gl4es_MaxLightsSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_MaxLightsSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_MaxLights", "_gl4es_MaxLights");
}
if(strstr(Tmp, "gl_NormalScale")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_normalscaleSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_normalscaleSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_NormalScale", "_gl4es_NormalScale");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_normalscaleSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_normalscaleSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_NormalScale", "_gl4es_NormalScale");
}
if(strstr(Tmp, "gl_InstanceID") || strstr(Tmp, "gl_InstanceIDARB")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_instanceID, Tmp, &tmpsize);
- headline+=CountLine(gl4es_instanceID);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_InstanceIDARB", "_gl4es_InstanceID");
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_InstanceID", "_gl4es_InstanceID");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_instanceID, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_instanceID);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_InstanceIDARB", "_gl4es_InstanceID");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_InstanceID", "_gl4es_InstanceID");
}
if(strstr(Tmp, "gl_ClipPlane")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_clipplanesSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_clipplanesSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_ClipPlane", "_gl4es_ClipPlane");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_clipplanesSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_clipplanesSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_ClipPlane", "_gl4es_ClipPlane");
}
if(strstr(Tmp, "gl_MaxClipPlanes")) {
- Tmp = InplaceInsert(GetLine(Tmp, 2), gl4es_MaxClipPlanesSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_MaxClipPlanesSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_MaxClipPlanes", "_gl4es_MaxClipPlanes");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, 2), gl4es_MaxClipPlanesSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_MaxClipPlanesSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_MaxClipPlanes", "_gl4es_MaxClipPlanes");
}
if(strstr(Tmp, "gl_PointParameters") || strstr(Tmp, "gl_Point"))
{
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_PointSpriteSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_PointSpriteSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_PointParameters", "_gl4es_PointParameters");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_PointSpriteSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_PointSpriteSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_PointParameters", "_gl4es_PointParameters");
}
if(strstr(Tmp, "gl_Point"))
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_Point", "_gl4es_Point");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_Point", "_gl4es_Point");
if(strstr(Tmp, "gl_FogParameters") || strstr(Tmp, "gl_Fog"))
{
- Tmp = InplaceInsert(GetLine(Tmp, headline), hardext.highp?gl4es_FogParametersSourceHighp:gl4es_FogParametersSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_FogParametersSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_FogParameters", "_gl4es_FogParameters");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), hardext.highp?gl4es_FogParametersSourceHighp:gl4es_FogParametersSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_FogParametersSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_FogParameters", "_gl4es_FogParameters");
}
if(strstr(Tmp, "gl_Fog"))
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_Fog", "_gl4es_Fog");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_Fog", "_gl4es_Fog");
if(strstr(Tmp, "gl_TextureEnvColor")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_texenvcolorSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_texenvcolorSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_TextureEnvColor", "_gl4es_TextureEnvColor");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_texenvcolorSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_texenvcolorSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_TextureEnvColor", "_gl4es_TextureEnvColor");
}
if(strstr(Tmp, "gl_EyePlaneS")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_texgeneyeSource[0], Tmp, &tmpsize);
- headline+=CountLine(gl4es_texgeneyeSource[0]);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_EyePlaneS", "_gl4es_EyePlaneS");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_texgeneyeSource[0], Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_texgeneyeSource[0]);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_EyePlaneS", "_gl4es_EyePlaneS");
}
if(strstr(Tmp, "gl_EyePlaneT")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_texgeneyeSource[1], Tmp, &tmpsize);
- headline+=CountLine(gl4es_texgeneyeSource[1]);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_EyePlaneT", "_gl4es_EyePlaneT");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_texgeneyeSource[1], Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_texgeneyeSource[1]);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_EyePlaneT", "_gl4es_EyePlaneT");
}
if(strstr(Tmp, "gl_EyePlaneR")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_texgeneyeSource[2], Tmp, &tmpsize);
- headline+=CountLine(gl4es_texgeneyeSource[2]);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_EyePlaneR", "_gl4es_EyePlaneR");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_texgeneyeSource[2], Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_texgeneyeSource[2]);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_EyePlaneR", "_gl4es_EyePlaneR");
}
if(strstr(Tmp, "gl_EyePlaneQ")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_texgeneyeSource[3], Tmp, &tmpsize);
- headline+=CountLine(gl4es_texgeneyeSource[3]);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_EyePlaneQ", "_gl4es_EyePlaneQ");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_texgeneyeSource[3], Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_texgeneyeSource[3]);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_EyePlaneQ", "_gl4es_EyePlaneQ");
}
if(strstr(Tmp, "gl_ObjectPlaneS")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_texgenobjSource[0], Tmp, &tmpsize);
- headline+=CountLine(gl4es_texgenobjSource[0]);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_ObjectPlaneS", "_gl4es_ObjectPlaneS");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_texgenobjSource[0], Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_texgenobjSource[0]);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_ObjectPlaneS", "_gl4es_ObjectPlaneS");
}
if(strstr(Tmp, "gl_ObjectPlaneT")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_texgenobjSource[1], Tmp, &tmpsize);
- headline+=CountLine(gl4es_texgenobjSource[1]);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_ObjectPlaneT", "_gl4es_ObjectPlaneT");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_texgenobjSource[1], Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_texgenobjSource[1]);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_ObjectPlaneT", "_gl4es_ObjectPlaneT");
}
if(strstr(Tmp, "gl_ObjectPlaneR")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_texgenobjSource[2], Tmp, &tmpsize);
- headline+=CountLine(gl4es_texgenobjSource[2]);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_ObjectPlaneR", "_gl4es_ObjectPlaneR");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_texgenobjSource[2], Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_texgenobjSource[2]);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_ObjectPlaneR", "_gl4es_ObjectPlaneR");
}
if(strstr(Tmp, "gl_ObjectPlaneQ")) {
- Tmp = InplaceInsert(GetLine(Tmp, headline), gl4es_texgenobjSource[3], Tmp, &tmpsize);
- headline+=CountLine(gl4es_texgenobjSource[3]);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_ObjectPlaneQ", "_gl4es_ObjectPlaneQ");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_texgenobjSource[3], Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_texgenobjSource[3]);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_ObjectPlaneQ", "_gl4es_ObjectPlaneQ");
}
if(strstr(Tmp, "gl_MaxTextureUnits")) {
- Tmp = InplaceInsert(GetLine(Tmp, 2), gl4es_MaxTextureUnitsSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_MaxTextureUnitsSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_MaxTextureUnits", "_gl4es_MaxTextureUnits");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, 2), gl4es_MaxTextureUnitsSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_MaxTextureUnitsSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_MaxTextureUnits", "_gl4es_MaxTextureUnits");
}
if(strstr(Tmp, "gl_MaxTextureCoords")) {
- Tmp = InplaceInsert(GetLine(Tmp, 2), gl4es_MaxTextureCoordsSource, Tmp, &tmpsize);
- headline+=CountLine(gl4es_MaxTextureCoordsSource);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_MaxTextureCoords", "_gl4es_MaxTextureCoords");
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, 2), gl4es_MaxTextureCoordsSource, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_MaxTextureCoordsSource);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_MaxTextureCoords", "_gl4es_MaxTextureCoords");
}
if(strstr(Tmp, "gl_ClipVertex")) {
- Tmp = InplaceInsert(GetLine(Tmp, 2), gl4es_ClipVertex, Tmp, &tmpsize);
- headline+=CountLine(gl4es_ClipVertex);
- Tmp = InplaceReplace(Tmp, &tmpsize, "gl_ClipVertex", gl4es_ClipVertexSource);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, 2), gl4es_ClipVertex, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_ClipVertex);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "gl_ClipVertex", gl4es_ClipVertexSource);
need->need_clipvertex = 1;
} else if(isVertex && need && need->need_clipvertex) {
- Tmp = InplaceInsert(GetLine(Tmp, 2), gl4es_ClipVertex, Tmp, &tmpsize);
- headline+=CountLine(gl4es_ClipVertex);
- char *p = strchr(FindStringNC(Tmp, "main"), '{'); // find the openning curly bracket of main
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, 2), gl4es_ClipVertex, Tmp, &tmpsize);
+ headline+=gl4es_countline(gl4es_ClipVertex);
+ char *p = strchr(gl4es_find_string_nc(Tmp, "main"), '{'); // find the openning curly bracket of main
if(p) {
// add regular clipping at start of main
- Tmp = InplaceInsert(p+1, gl4es_ClipVertex_clip, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(p+1, gl4es_ClipVertex_clip, Tmp, &tmpsize);
}
}
//oldprogram uniforms...
- if(FindString(Tmp, gl_ProgramEnv)) {
+ if(gl4es_find_string(Tmp, gl_ProgramEnv)) {
// check if array can be removed
int maxind = -1;
int noarray_ok = 1;
char* p = Tmp;
- while(noarray_ok && (p=FindStringNC(p, gl_ProgramEnv))) {
+ while(noarray_ok && (p=gl4es_find_string_nc(p, gl_ProgramEnv))) {
p+=strlen(gl_ProgramEnv);
if(*p=='[') {
++p;
@@ -1160,11 +1160,11 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
for(int i=0; i<=maxind; ++i) {
sprintf(F, "%s[%d]", gl_ProgramEnv, i);
sprintf(T, "_gl4es_%s_ProgramEnv_%d", isVertex?"Vertex":"Fragment", i);
- Tmp = InplaceReplace(Tmp, &tmpsize, F, T);
- if(FindString(Tmp, T)) {
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, F, T);
+ if(gl4es_find_string(Tmp, T)) {
// add the uniform declaration if needed
sprintf(U, "uniform vec4 %s;\n", T);
- Tmp = InplaceInsert(GetLine(Tmp, headline), U, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), U, Tmp, &tmpsize);
headline += 1;
}
}
@@ -1173,17 +1173,17 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
char T[60], U[300];
sprintf(T, "_gl4es_%s_ProgramEnv", isVertex?"Vertex":"Fragment");
sprintf(U, "uniform vec4 %s[%d];\n", T, isVertex?MAX_VTX_PROG_ENV_PARAMS:MAX_FRG_PROG_ENV_PARAMS);
- Tmp = InplaceInsert(GetLine(Tmp, headline), U, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), U, Tmp, &tmpsize);
headline += 1;
- Tmp = InplaceReplace(Tmp, &tmpsize, gl_ProgramEnv, T);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, gl_ProgramEnv, T);
}
}
- if(FindString(Tmp, gl_ProgramLocal)) {
+ if(gl4es_find_string(Tmp, gl_ProgramLocal)) {
// check if array can be removed
int maxind = -1;
int noarray_ok = 1;
char* p = Tmp;
- while(noarray_ok && (p=FindStringNC(p, gl_ProgramLocal))) {
+ while(noarray_ok && (p=gl4es_find_string_nc(p, gl_ProgramLocal))) {
p+=strlen(gl_ProgramLocal);
if(*p=='[') {
++p;
@@ -1203,11 +1203,11 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
for(int i=0; i<=maxind; ++i) {
sprintf(F, "%s[%d]", gl_ProgramLocal, i);
sprintf(T, "_gl4es_%s_ProgramLocal_%d", isVertex?"Vertex":"Fragment", i);
- Tmp = InplaceReplace(Tmp, &tmpsize, F, T);
- if(FindString(Tmp, T)) {
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, F, T);
+ if(gl4es_find_string(Tmp, T)) {
// add the uniform declaration if needed
sprintf(U, "uniform vec4 %s;\n", T);
- Tmp = InplaceInsert(GetLine(Tmp, headline), U, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), U, Tmp, &tmpsize);
headline += 1;
}
}
@@ -1216,9 +1216,9 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
char T[60], U[300];
sprintf(T, "_gl4es_%s_ProgramLocal", isVertex?"Vertex":"Fragment");
sprintf(U, "uniform vec4 %s[%d];\n", T, isVertex?MAX_VTX_PROG_LOC_PARAMS:MAX_FRG_PROG_LOC_PARAMS);
- Tmp = InplaceInsert(GetLine(Tmp, headline), U, Tmp, &tmpsize);
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), U, Tmp, &tmpsize);
headline += 1;
- Tmp = InplaceReplace(Tmp, &tmpsize, gl_ProgramLocal, T);
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, gl_ProgramLocal, T);
}
}
#define GO(A) \
@@ -1226,11 +1226,11 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
char S[60], D[60], U[60]; \
for(int i=0; i<MAX_TEX; ++i) { \
sprintf(S, "%s%d", gl_Samplers ## A, i); \
- if(FindString(Tmp, S)) { \
+ if(gl4es_find_string(Tmp, S)) { \
sprintf(D, "%s%d", gl4es_Samplers ## A, i); \
sprintf(U, "%s%d;\n", gl4es_Samplers ## A ## _uniform, i); \
- Tmp = InplaceReplace(Tmp, &tmpsize, S, D); \
- Tmp = InplaceInsert(GetLine(Tmp, headline), U, Tmp, &tmpsize); \
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, S, D); \
+ Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), U, Tmp, &tmpsize); \
headline += 1; \
} \
} \
@@ -1245,11 +1245,11 @@ char* ConvertShader(const char* pEntry, int isVertex, shaderconv_need_t *need)
// the square one first
if(strstr(Tmp, "mat2x2")) {
// better to use #define ?
- Tmp = InplaceReplace(Tmp, &tmpsize, "mat2x2", "mat2");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "mat2x2", "mat2");
}
if(strstr(Tmp, "mat3x3")) {
// better to use #define ?
- Tmp = InplaceReplace(Tmp, &tmpsize, "mat3x3", "mat3");
+ Tmp = gl4es_inplace_replace(Tmp, &tmpsize, "mat3x3", "mat3");
}
// finish
diff --git a/src/gl/string_utils.c b/src/gl/string_utils.c
index e8579e9b..e5e2850e 100644
--- a/src/gl/string_utils.c
+++ b/src/gl/string_utils.c
@@ -6,12 +6,12 @@
const char* AllSeparators = " \t\n\r.,;()[]{}-<>+*/%&\\\"'^$=!:?";
-char* ResizeIfNeeded(char* pBuffer, int *size, int addsize);
+char* gl4es_resize_if_needed(char* pBuffer, int *size, int addsize);
-char* InplaceReplace(char* pBuffer, int* size, const char* S, const char* D)
+char* gl4es_inplace_replace(char* pBuffer, int* size, const char* S, const char* D)
{
int lS = strlen(S), lD = strlen(D);
- pBuffer = ResizeIfNeeded(pBuffer, size, (lD-lS)*CountString(pBuffer, S));
+ pBuffer = gl4es_resize_if_needed(pBuffer, size, (lD-lS)*gl4es_count_string(pBuffer, S));
char* p = pBuffer;
while((p = strstr(p, S)))
{
@@ -30,9 +30,9 @@ char* InplaceReplace(char* pBuffer, int* size, const char* S, const char* D)
return pBuffer;
}
-char* InplaceInsert(char* pBuffer, const char* S, char* master, int* size)
+char* gl4es_inplace_insert(char* pBuffer, const char* S, char* master, int* size)
{
- char* m = ResizeIfNeeded(master, size, strlen(S));
+ char* m = gl4es_resize_if_needed(master, size, strlen(S));
if(m!=master) {
pBuffer += (m-master);
master = m;
@@ -45,14 +45,14 @@ char* InplaceInsert(char* pBuffer, const char* S, char* master, int* size)
return master;
}
-char* GetLine(char* pBuffer, int num)
+char* gl4es_getline(char* pBuffer, int num)
{
char *p = pBuffer;
while(num-- && (p=strstr(p, "\n"))) p+=strlen("\n");
return (p)?p:pBuffer;
}
-int CountLine(const char* pBuffer)
+int gl4es_countline(const char* pBuffer)
{
int n=0;
const char* p = pBuffer;
@@ -63,11 +63,11 @@ int CountLine(const char* pBuffer)
return n;
}
-int GetLineFor(const char* pBuffer, const char* S)
+int gl4es_getline_for(const char* pBuffer, const char* S)
{
int n=0;
const char* p = pBuffer;
- const char* end = FindString(pBuffer, S);
+ const char* end = gl4es_find_string(pBuffer, S);
if(!end)
return 0;
while((p=strstr(p, "\n"))) {
@@ -79,7 +79,7 @@ int GetLineFor(const char* pBuffer, const char* S)
return n;
}
-int CountString(const char* pBuffer, const char* S)
+int gl4es_count_string(const char* pBuffer, const char* S)
{
const char* p = pBuffer;
int lS = strlen(S);
@@ -95,7 +95,7 @@ int CountString(const char* pBuffer, const char* S)
return n;
}
-const char* FindString(const char* pBuffer, const char* S)
+const char* gl4es_find_string(const char* pBuffer, const char* S)
{
const char* p = pBuffer;
int lS = strlen(S);
@@ -110,7 +110,7 @@ const char* FindString(const char* pBuffer, const char* S)
return NULL;
}
-char* FindStringNC(char* pBuffer, const char* S)
+char* gl4es_findstring_nc(char* pBuffer, const char* S)
{
char* p = pBuffer;
int lS = strlen(S);
@@ -125,7 +125,7 @@ char* FindStringNC(char* pBuffer, const char* S)
return NULL;
}
-char* ResizeIfNeeded(char* pBuffer, int *size, int addsize) {
+char* gl4es_resize_if_needed(char* pBuffer, int *size, int addsize) {
char* p = pBuffer;
int newsize = strlen(pBuffer)+addsize+1;
if (newsize>*size) {
@@ -136,14 +136,14 @@ char* ResizeIfNeeded(char* pBuffer, int *size, int addsize) {
return p;
}
-char* Append(char* pBuffer, int* size, const char* S) {
+char* gl4es_append(char* pBuffer, int* size, const char* S) {
char* p =pBuffer;
- p = ResizeIfNeeded(pBuffer, size, strlen(S));
+ p = gl4es_resize_if_needed(pBuffer, size, strlen(S));
strcat(p, S);
return p;
}
-int isBlank(char c) {
+static int gl4es_is_blank(char c) {
switch(c) {
case ' ':
case '\t':
@@ -158,54 +158,54 @@ int isBlank(char c) {
return 0;
}
}
-char* StrNext(char *pBuffer, const char* S) {
+char* gl4es_str_next(char *pBuffer, const char* S) {
if(!pBuffer) return NULL;
char *p = strstr(pBuffer, S);
return (p)?p:(p+strlen(S));
}
-char* NextStr(char* pBuffer) {
+char* gl4es_next_str(char* pBuffer) {
if(!pBuffer) return NULL;
- while(isBlank(*pBuffer))
+ while(gl4es_is_blank(*pBuffer))
++pBuffer;
return pBuffer;
}
-char* PrevStr(char* Str, char* pBuffer) {
+char* gl4es_prev_str(char* Str, char* pBuffer) {
if(!pBuffer) return NULL;
if(pBuffer == Str)
return Str;
// go to previous non blank
do {
--pBuffer;
- } while(isBlank(*pBuffer) && (pBuffer!=Str));
+ } while(gl4es_is_blank(*pBuffer) && (pBuffer!=Str));
// go to blank
- while((pBuffer!=Str) && !isBlank(*(pBuffer-1)));
+ while((pBuffer!=Str) && !gl4es_is_blank(*(pBuffer-1)));
--pBuffer;
return pBuffer;
}
-char* NextBlank(char* pBuffer) {
+char* gl4es_next_blank(char* pBuffer) {
if(!pBuffer) return NULL;
- while(!isBlank(*pBuffer))
+ while(!gl4es_is_blank(*pBuffer))
++pBuffer;
return pBuffer;
}
-char* NextLine(char* pBuffer) {
+char* gl4es_next_line(char* pBuffer) {
if(!pBuffer) return NULL;
while(*pBuffer && *pBuffer!='\n')
++pBuffer;
return pBuffer;
}
-const char* GetNextStr(char* pBuffer) {
+const char* gl4es_get_next_str(char* pBuffer) {
static char buff[100] = {0};
buff[0] = '\0';
if(!pBuffer) return NULL;
- char* p1 = NextStr(pBuffer);
+ char* p1 = gl4es_next_str(pBuffer);
if(!p1) return buff;
- char* p2 = NextBlank(p1);
+ char* p2 = gl4es_next_blank(p1);
if(!p2) return buff;
int i=0;
while(p1!=p2 && i<99)
@@ -214,7 +214,7 @@ const char* GetNextStr(char* pBuffer) {
return buff;
}
-int CountStringSimple(char* pBuffer, const char* S)
+int gl4es_countstring_simple(char* pBuffer, const char* S)
{
char* p = pBuffer;
int lS = strlen(S);
@@ -228,10 +228,10 @@ int CountStringSimple(char* pBuffer, const char* S)
return n;
}
-char* InplaceReplaceSimple(char* pBuffer, int* size, const char* S, const char* D)
+char* gl4es_inplace_replace_simple(char* pBuffer, int* size, const char* S, const char* D)
{
int lS = strlen(S), lD = strlen(D);
- pBuffer = ResizeIfNeeded(pBuffer, size, (lD-lS)*CountStringSimple(pBuffer, S));
+ pBuffer = gl4es_resize_if_needed(pBuffer, size, (lD-lS)*gl4es_countstring_simple(pBuffer, S));
char* p = pBuffer;
while((p = strstr(p, S)))
{
diff --git a/src/gl/string_utils.h b/src/gl/string_utils.h
index 008fd419..ed018908 100644
--- a/src/gl/string_utils.h
+++ b/src/gl/string_utils.h
@@ -3,28 +3,28 @@
extern const char* AllSeparators;
-const char* FindString(const char* pBuffer, const char* S);
-char* FindStringNC(char* pBuffer, const char* S);
-int CountString(const char* pBuffer, const char* S);
-char* ResizeIfNeeded(char* pBuffer, int *size, int addsize);
-char* InplaceReplace(char* pBuffer, int* size, const char* S, const char* D);
-char* Append(char* pBuffer, int* size, const char* S);
-char* InplaceInsert(char* pBuffer, const char* S, char* master, int* size);
-char* GetLine(char* pBuffer, int num);
-int CountLine(const char* pBuffer);
-int GetLineFor(const char* pBuffer, const char* S); // get the line number for 1st occurent of S in pBuffer
-char* StrNext(char *pBuffer, const char* S); // mostly as strstr, but go after the substring if found
+const char* gl4es_find_string(const char* pBuffer, const char* S);
+char* gl4es_find_string_nc(char* pBuffer, const char* S);
+int gl4es_count_string(const char* pBuffer, const char* S);
+char* gl4es_resize_if_needed(char* pBuffer, int *size, int addsize);
+char* gl4es_inplace_replace(char* pBuffer, int* size, const char* S, const char* D);
+char* gl4es_append(char* pBuffer, int* size, const char* S);
+char* gl4es_inplace_insert(char* pBuffer, const char* S, char* master, int* size);
+char* gl4es_getline(char* pBuffer, int num);
+int gl4es_countline(const char* pBuffer);
+int gl4es_getline_for(const char* pBuffer, const char* S); // get the line number for 1st occurent of S in pBuffer
+char* gl4es_str_next(char *pBuffer, const char* S); // mostly as strstr, but go after the substring if found
//"blank" (space, tab, cr, lf,":", ",", ";", ".", "/")
-char* NextStr(char* pBuffer); // go to next non "blank"
-char* PrevStr(char* Str, char* pBuffer); // go to previous non "blank"
-char* NextBlank(char* pBuffer); // go to next "blank"
-char* NextLine(char* pBuffer); // go to next new line (crlf not included)
+char* gl4es_next_str(char* pBuffer); // go to next non "blank"
+char* gl4es_prev_str(char* Str, char* pBuffer); // go to previous non "blank"
+char* gl4es_next_blank(char* pBuffer); // go to next "blank"
+char* gl4es_next_line(char* pBuffer); // go to next new line (crlf not included)
-const char* GetNextStr(char* pBuffer); // get a (static) copy of next str (until next separator), can be a simple number or separator also
+const char* gl4es_get_next_str(char* pBuffer); // get a (static) copy of next str (until next separator), can be a simple number or separator also
// those function don't try to be smart with separators...
-int CountStringSimple(char* pBuffer, const char* S);
-char* InplaceReplaceSimple(char* pBuffer, int* size, const char* S, const char* D);
+int gl4es_countstring_simple(char* pBuffer, const char* S);
+char* gl4es_inplace_replace_simple(char* pBuffer, int* size, const char* S, const char* D);
#endif // _GL4ES_STRING_UTILS_H_
--
2.11.0