Thomas Buck 10 anni fa
parent
commit
982261e7aa

+ 1
- 1
data/OpenRaider.ini Vedi File

7
 set datadir    "$(basedir)/data"
7
 set datadir    "$(basedir)/data"
8
 set font       "$(datadir)/test.ttf"
8
 set font       "$(datadir)/test.ttf"
9
 
9
 
10
- # Not needed for Mac OS X
10
+# Not needed for Mac OS X
11
 set gldriver   "/usr/lib/libGL.so.1"
11
 set gldriver   "/usr/lib/libGL.so.1"
12
 
12
 
13
 # Windowing
13
 # Windowing

+ 40
- 0
include/Menu.h Vedi File

1
+/*!
2
+ * \file include/Menu.h
3
+ * \brief Menu 'overlay'
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _MENU_H_
9
+#define _MENU_H_
10
+
11
+#include "Window.h"
12
+
13
+/*!
14
+ * \brief Menu 'overlay'
15
+ */
16
+class Menu {
17
+public:
18
+
19
+    /*!
20
+     * \brief Constructs an object of Menu
21
+     */
22
+    Menu();
23
+
24
+    /*!
25
+     * \brief Deconstructs an object of Menu
26
+     */
27
+    ~Menu();
28
+
29
+    void setVisible(bool visible);
30
+
31
+    bool isVisible();
32
+
33
+    void display();
34
+
35
+private:
36
+    bool mVisible;
37
+    WindowString mainText;
38
+};
39
+
40
+#endif

+ 5
- 3
include/OpenRaider.h Vedi File

10
 
10
 
11
 #include <vector>
11
 #include <vector>
12
 
12
 
13
+#include "Menu.h"
13
 #include "Sound.h"
14
 #include "Sound.h"
14
 #include "Window.h"
15
 #include "Window.h"
15
 
16
 
49
 
50
 
50
     void run();
51
     void run();
51
 
52
 
53
+    Window *mWindow;
54
+    Sound *mSound;
55
+    Menu *mMenu;
56
+
52
 private:
57
 private:
53
     bool mInit;
58
     bool mInit;
54
     bool mRunning;
59
     bool mRunning;
55
-    Window *mWindow;
56
-
57
-    Sound *mSound;
58
 
60
 
59
     char *mBaseDir;
61
     char *mBaseDir;
60
     char *mPakDir;
62
     char *mPakDir;

+ 16
- 2
include/Window.h Vedi File

14
     char *text;
14
     char *text;
15
     unsigned int x;
15
     unsigned int x;
16
     unsigned int y;
16
     unsigned int y;
17
+    int w;
18
+    int h;
17
     float scale;
19
     float scale;
18
     unsigned char color[3];
20
     unsigned char color[3];
19
 } WindowString;
21
 } WindowString;
47
 
49
 
48
     virtual int initializeGL();
50
     virtual int initializeGL();
49
 
51
 
50
-    virtual void resizeGL(unsigned int w, unsigned int h);
52
+    virtual void resizeGL();
51
 
53
 
52
-    virtual void glEnter2D(unsigned int width, unsigned int height);
54
+    virtual void glEnter2D();
53
 
55
 
54
     virtual void glExit2D();
56
     virtual void glExit2D();
55
 
57
 
58
     virtual int initializeFont() = 0;
60
     virtual int initializeFont() = 0;
59
 
61
 
60
     virtual void writeString(WindowString *s) = 0;
62
     virtual void writeString(WindowString *s) = 0;
63
+
64
+    unsigned int mWidth;
65
+    unsigned int mHeight;
66
+
67
+protected:
68
+    bool mInit;
69
+    char *mDriver;
70
+    bool mFullscreen;
71
+    bool mMousegrab;
72
+
73
+    bool mFontInit;
74
+    char *mFontName;
61
 };
75
 };
62
 
76
 
63
 #endif
77
 #endif

+ 1
- 8
include/WindowSDL.h Vedi File

60
     virtual void writeString(WindowString *s);
60
     virtual void writeString(WindowString *s);
61
 
61
 
62
 private:
62
 private:
63
-    bool mInit;
64
-    char *mDriver;
65
-    unsigned int mWidth;
66
-    unsigned int mHeight;
67
-    bool mFullscreen;
68
-    bool mMousegrab;
63
+
69
     SDL_Window *mWindow;      //!< This is the pointer to the SDL surface
64
     SDL_Window *mWindow;      //!< This is the pointer to the SDL surface
70
     SDL_GLContext mGLContext; //!< The OpenGL Context
65
     SDL_GLContext mGLContext; //!< The OpenGL Context
71
 
66
 
72
-    bool mFontInit;
73
-    char *mFontName;
74
     TTF_Font *mFont;
67
     TTF_Font *mFont;
75
     GLuint mFontTexture;
68
     GLuint mFontTexture;
76
 };
69
 };

+ 2
- 0
include/main.h Vedi File

7
 #ifndef _MAIN_H_
7
 #ifndef _MAIN_H_
8
 #define _MAIN_H_
8
 #define _MAIN_H_
9
 
9
 
10
+#include "OpenRaider.h"
11
+
10
 extern OpenRaider *gOpenRaider; //!< Main Game Singleton
12
 extern OpenRaider *gOpenRaider; //!< Main Game Singleton
11
 
13
 
12
 /*!
14
 /*!

+ 2
- 0
include/utils/strings.h Vedi File

12
 #include <cstdarg>
12
 #include <cstdarg>
13
 #include <vector>
13
 #include <vector>
14
 
14
 
15
+char *stringRemoveQuotes(const char *s);
16
+
15
 char *stringReplace(const char *s, const char *search, const char *replace);
17
 char *stringReplace(const char *s, const char *search, const char *replace);
16
 
18
 
17
 void printStringVector(std::vector<char *> *args);
19
 void printStringVector(std::vector<char *> *args);

+ 1
- 0
src/CMakeLists.txt Vedi File

32
 
32
 
33
 # Set Source files
33
 # Set Source files
34
 set (SRCS ${SRCS} "main.cpp")
34
 set (SRCS ${SRCS} "main.cpp")
35
+set (SRCS ${SRCS} "Menu.cpp")
35
 set (SRCS ${SRCS} "OpenRaider.cpp")
36
 set (SRCS ${SRCS} "OpenRaider.cpp")
36
 set (SRCS ${SRCS} "Sound.cpp")
37
 set (SRCS ${SRCS} "Sound.cpp")
37
 set (SRCS ${SRCS} "Window.cpp")
38
 set (SRCS ${SRCS} "Window.cpp")

+ 53
- 0
src/Menu.cpp Vedi File

1
+/*!
2
+ * \file src/Menu.cpp
3
+ * \brief Menu 'overlay'
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifdef __APPLE__
9
+#include <OpenGL/gl.h>
10
+#include <OpenGL/glu.h>
11
+#else
12
+#include <GL/gl.h>
13
+#include <GL/glu.h>
14
+#endif
15
+
16
+#include "config.h"
17
+#include "main.h"
18
+#include "Menu.h"
19
+#include "utils/strings.h"
20
+
21
+Menu::Menu() {
22
+    mVisible = false;
23
+    mainText.text = bufferString(VERSION);
24
+    mainText.color[0] = 0xFF;
25
+    mainText.color[1] = 0xFF;
26
+    mainText.color[2] = 0xFF;
27
+    mainText.scale = 1.2f;
28
+    mainText.w = 0;
29
+    mainText.h = 0;
30
+}
31
+
32
+Menu::~Menu() {
33
+
34
+}
35
+
36
+void Menu::setVisible(bool visible) {
37
+    mVisible = visible;
38
+}
39
+
40
+bool Menu::isVisible() {
41
+    return mVisible;
42
+}
43
+
44
+void Menu::display() {
45
+    Window *window = gOpenRaider->mWindow;
46
+
47
+    if (mVisible) {
48
+        mainText.x = (window->mWidth / 2) - (mainText.w / 2);
49
+        mainText.y = 10;
50
+        window->writeString(&mainText);
51
+    }
52
+}
53
+

+ 52
- 52
src/OpenRaider.cpp Vedi File

26
     mAudioDir = NULL;
26
     mAudioDir = NULL;
27
     mDataDir = NULL;
27
     mDataDir = NULL;
28
 
28
 
29
+    mMenu = new Menu();
29
     mSound = new Sound();
30
     mSound = new Sound();
30
     mWindow = new WindowSDL();
31
     mWindow = new WindowSDL();
31
 }
32
 }
32
 
33
 
33
 OpenRaider::~OpenRaider() {
34
 OpenRaider::~OpenRaider() {
35
+    if (mMenu)
36
+        delete mMenu;
37
+
34
     if (mSound)
38
     if (mSound)
35
         delete mSound;
39
         delete mSound;
36
 
40
 
171
     return NULL;
175
     return NULL;
172
 }
176
 }
173
 
177
 
178
+#define CHANGE_DIR_WITH_EXPANSION(a) do {     \
179
+    char *quotes = stringRemoveQuotes(value); \
180
+    char *tmp = expandDirectoryNames(quotes); \
181
+    if (tmp == NULL) {                        \
182
+        a = fullPath(quotes, 0);              \
183
+    } else {                                  \
184
+        a = fullPath(tmp, 0);                 \
185
+        delete [] tmp;                        \
186
+    }                                         \
187
+    delete [] quotes;                         \
188
+} while(false)
189
+
174
 int OpenRaider::set(const char *var, const char *value) {
190
 int OpenRaider::set(const char *var, const char *value) {
175
     if (strcmp(var, "size") == 0) {
191
     if (strcmp(var, "size") == 0) {
176
         // value has format like "\"1024x768\""
192
         // value has format like "\"1024x768\""
204
         }
220
         }
205
         mSound->setVolume(vol);
221
         mSound->setVolume(vol);
206
     } else if (strcmp(var, "mouse_x") == 0) {
222
     } else if (strcmp(var, "mouse_x") == 0) {
207
-        // TODO mouse support
223
+        float sense = 1.0f;
224
+        if (sscanf(value, "%f", &sense) != 1) {
225
+            printf("set-mouse_x-Error: Invalid value (%s)\n", value);
226
+            return -6;
227
+        }
228
+        //! \todo mouse support
208
     } else if (strcmp(var, "mouse_y") == 0) {
229
     } else if (strcmp(var, "mouse_y") == 0) {
209
-        // TODO mouse support
210
-    } else if (strcmp(var, "basedir") == 0) {
211
-        char *quotes = stringReplace(value, "\"", "");
212
-        char *tmp = expandDirectoryNames(quotes);
213
-        if (tmp == NULL) {
214
-            mBaseDir = fullPath(quotes, 0);
215
-        } else {
216
-            mBaseDir = fullPath(tmp, 0);
217
-            delete [] tmp;
230
+        float sense = 1.0f;
231
+        if (sscanf(value, "%f", &sense) != 1) {
232
+            printf("set-mouse_y-Error: Invalid value (%s)\n", value);
233
+            return -7;
218
         }
234
         }
219
-        delete [] quotes;
235
+        //! \todo mouse support
236
+    } else if (strcmp(var, "basedir") == 0) {
237
+        CHANGE_DIR_WITH_EXPANSION(mBaseDir);
220
     } else if (strcmp(var, "pakdir") == 0) {
238
     } else if (strcmp(var, "pakdir") == 0) {
221
-        char *quotes = stringReplace(value, "\"", "");
222
-        char *tmp = expandDirectoryNames(quotes);
223
-        if (tmp == NULL) {
224
-            mPakDir = fullPath(quotes, 0);
225
-        } else {
226
-            mPakDir = fullPath(tmp, 0);
227
-            delete [] tmp;
228
-        }
229
-        delete [] quotes;
239
+        CHANGE_DIR_WITH_EXPANSION(mPakDir);
230
     } else if (strcmp(var, "audiodir") == 0) {
240
     } else if (strcmp(var, "audiodir") == 0) {
231
-        char *quotes = stringReplace(value, "\"", "");
232
-        char *tmp = expandDirectoryNames(quotes);
233
-        if (tmp == NULL) {
234
-            mAudioDir = fullPath(quotes, 0);
235
-        } else {
236
-            mAudioDir = fullPath(tmp, 0);
237
-            delete [] tmp;
238
-        }
239
-        delete [] quotes;
241
+        CHANGE_DIR_WITH_EXPANSION(mAudioDir);
240
     } else if (strcmp(var, "datadir") == 0) {
242
     } else if (strcmp(var, "datadir") == 0) {
241
-        char *quotes = stringReplace(value, "\"", "");
242
-        char *tmp = expandDirectoryNames(quotes);
243
-        if (tmp == NULL) {
244
-            mDataDir = fullPath(quotes, 0);
245
-        } else {
246
-            mDataDir = fullPath(tmp, 0);
247
-            delete [] tmp;
248
-        }
249
-        delete [] quotes;
243
+        CHANGE_DIR_WITH_EXPANSION(mDataDir);
250
     } else if (strcmp(var, "font") == 0) {
244
     } else if (strcmp(var, "font") == 0) {
251
         char *quotes = stringReplace(value, "\"", "");
245
         char *quotes = stringReplace(value, "\"", "");
252
         char *tmp = expandDirectoryNames(quotes);
246
         char *tmp = expandDirectoryNames(quotes);
266
 }
260
 }
267
 
261
 
268
 int OpenRaider::bind(const char *action, const char *key) {
262
 int OpenRaider::bind(const char *action, const char *key) {
269
-    if (strcmp(action, "console") == 0) {
263
+    const char *tmp = action;
264
+    if (action[0] == '+')
265
+        tmp++;
270
 
266
 
271
-    } else if (strcmp(action, "forward") == 0) {
267
+    if (strcmp(tmp, "console") == 0) {
272
 
268
 
273
-    } else if (strcmp(action, "backward") == 0) {
269
+    } else if (strcmp(tmp, "forward") == 0) {
274
 
270
 
275
-    } else if (strcmp(action, "jump") == 0) {
271
+    } else if (strcmp(tmp, "backward") == 0) {
276
 
272
 
277
-    } else if (strcmp(action, "crouch") == 0) {
273
+    } else if (strcmp(tmp, "jump") == 0) {
278
 
274
 
279
-    } else if (strcmp(action, "left") == 0) {
275
+    } else if (strcmp(tmp, "crouch") == 0) {
280
 
276
 
281
-    } else if (strcmp(action, "right") == 0) {
277
+    } else if (strcmp(tmp, "left") == 0) {
278
+
279
+    } else if (strcmp(tmp, "right") == 0) {
282
 
280
 
283
     } else {
281
     } else {
284
         printf("bind-Error: Unknown action (%s --> %s)\n", key, action);
282
         printf("bind-Error: Unknown action (%s --> %s)\n", key, action);
307
     if (mSound->initialize() != 0)
305
     if (mSound->initialize() != 0)
308
         return -4;
306
         return -4;
309
 
307
 
308
+    mMenu->setVisible(true);
309
+
310
     mInit = true;
310
     mInit = true;
311
 
311
 
312
     return 0;
312
     return 0;
322
 
322
 
323
         mWindow->eventHandling();
323
         mWindow->eventHandling();
324
 
324
 
325
+        // Temp Debug
326
+        glClearColor(0.25f, 0.75f, 0.25f, 1.0f);
325
         glClear(GL_COLOR_BUFFER_BIT);
327
         glClear(GL_COLOR_BUFFER_BIT);
326
 
328
 
327
-        WindowString s;
328
-        s.text = bufferString("This text is not fixed-width...");
329
-        s.x = 100;
330
-        s.y = 100;
331
-        s.scale = 1.5f;
332
-        s.color[0] = s.color[1] = s.color[2] = 0xFF;
333
-        mWindow->writeString(&s);
329
+        mWindow->glEnter2D();
330
+
331
+        mMenu->display();
332
+
333
+        mWindow->glExit2D();
334
 
334
 
335
         mWindow->swapBuffersGL();
335
         mWindow->swapBuffersGL();
336
 
336
 

+ 10
- 12
src/Window.cpp Vedi File

25
 
25
 
26
 int Window::initializeGL() {
26
 int Window::initializeGL() {
27
     // Print driver support information
27
     // Print driver support information
28
-    printf("GL Vendor  : %s\n", glGetString(GL_VENDOR));
29
-    printf("GL Renderer: %s\n", glGetString(GL_RENDERER));
30
-    printf("GL Version : %s\n", glGetString(GL_VERSION));
28
+    //printf("GL Vendor  : %s\n", glGetString(GL_VENDOR));
29
+    //printf("GL Renderer: %s\n", glGetString(GL_RENDERER));
30
+    //printf("GL Version : %s\n", glGetString(GL_VERSION));
31
 
31
 
32
     // Testing for goodies
32
     // Testing for goodies
33
     const char *s = (const char *)glGetString(GL_EXTENSIONS);
33
     const char *s = (const char *)glGetString(GL_EXTENSIONS);
34
     if ((s != NULL) && (s[0] != '\0')) {
34
     if ((s != NULL) && (s[0] != '\0')) {
35
+        //! \todo MultiTexture flag
35
         //if (strstr(s, "GL_ARB_multitexture"))
36
         //if (strstr(s, "GL_ARB_multitexture"))
36
             //mFlags |= Render::fMultiTexture;
37
             //mFlags |= Render::fMultiTexture;
37
     }
38
     }
95
     return 0;
96
     return 0;
96
 }
97
 }
97
 
98
 
98
-void Window::resizeGL(unsigned int w, unsigned int h) {
99
+void Window::resizeGL() {
99
     float fovY = 45.0f;
100
     float fovY = 45.0f;
100
     float clipNear = 4.0f;
101
     float clipNear = 4.0f;
101
     float clipFar = 4000.0f;
102
     float clipFar = 4000.0f;
102
 
103
 
103
-    assert(w > 0);
104
-    assert(h > 0);
105
-
106
-    glViewport(0, 0, w, h);
104
+    glViewport(0, 0, mWidth, mHeight);
107
     glMatrixMode(GL_PROJECTION);
105
     glMatrixMode(GL_PROJECTION);
108
     glLoadIdentity();
106
     glLoadIdentity();
109
 
107
 
110
     // Adjust clipping
108
     // Adjust clipping
111
     GLfloat fH = tanf(fovY * OR_PI / 360.0f) * clipNear;
109
     GLfloat fH = tanf(fovY * OR_PI / 360.0f) * clipNear;
112
-    GLfloat fW = fH * ((GLfloat)w) / ((GLfloat)h);
110
+    GLfloat fW = fH * ((GLfloat)mWidth) / ((GLfloat)mHeight);
113
     glFrustum(-fW, fW, -fH, fH, clipNear, clipFar);
111
     glFrustum(-fW, fW, -fH, fH, clipNear, clipFar);
114
 
112
 
115
     glMatrixMode(GL_MODELVIEW);
113
     glMatrixMode(GL_MODELVIEW);
116
     glLoadIdentity();
114
     glLoadIdentity();
117
 }
115
 }
118
 
116
 
119
-void Window::glEnter2D(unsigned int width, unsigned int height) {
117
+void Window::glEnter2D() {
120
     glPushAttrib(GL_ENABLE_BIT);
118
     glPushAttrib(GL_ENABLE_BIT);
121
     glDisable(GL_DEPTH_TEST);
119
     glDisable(GL_DEPTH_TEST);
122
     glDisable(GL_CULL_FACE);
120
     glDisable(GL_CULL_FACE);
126
     glEnable(GL_BLEND);
124
     glEnable(GL_BLEND);
127
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
125
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
128
 
126
 
129
-    glViewport(0, 0, width, height);
127
+    glViewport(0, 0, mWidth, mHeight);
130
 
128
 
131
     glMatrixMode(GL_PROJECTION);
129
     glMatrixMode(GL_PROJECTION);
132
     glPushMatrix();
130
     glPushMatrix();
133
     glLoadIdentity();
131
     glLoadIdentity();
134
 
132
 
135
-    glOrtho(0.0, (GLdouble)width, (GLdouble)height, 0.0, 0.0, 1.0);
133
+    glOrtho(0.0, (GLdouble)mWidth, (GLdouble)mHeight, 0.0, 0.0, 1.0);
136
 
134
 
137
     glMatrixMode(GL_MODELVIEW);
135
     glMatrixMode(GL_MODELVIEW);
138
     glPushMatrix();
136
     glPushMatrix();

+ 16
- 8
src/WindowSDL.cpp Vedi File

70
 
70
 
71
     if (mInit == true) {
71
     if (mInit == true) {
72
         SDL_SetWindowSize(mWindow, mWidth, mHeight);
72
         SDL_SetWindowSize(mWindow, mWidth, mHeight);
73
-        resizeGL(mWidth, mHeight);
73
+        resizeGL();
74
     }
74
     }
75
 }
75
 }
76
 
76
 
250
         return;
250
         return;
251
     }
251
     }
252
 
252
 
253
+    if (TTF_SizeUTF8(mFont, s->text, &s->w, &s->h) != 0) {
254
+        printf("TTF_SizeUTF8 Error: %s\n", TTF_GetError());
255
+        // Don't need to abort
256
+    }
257
+    s->w = (int)((float)s->w * s->scale);
258
+    s->h = (int)((float)s->h * s->scale);
259
+
253
     GLenum textureFormat;
260
     GLenum textureFormat;
254
     if (surface->format->BytesPerPixel == 4) {
261
     if (surface->format->BytesPerPixel == 4) {
255
         if (surface->format->Rmask == 0x000000FF)
262
         if (surface->format->Rmask == 0x000000FF)
265
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
272
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
266
     glTexImage2D(GL_TEXTURE_2D, 0, surface->format->BytesPerPixel, surface->w, surface->h, 0, textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
273
     glTexImage2D(GL_TEXTURE_2D, 0, surface->format->BytesPerPixel, surface->w, surface->h, 0, textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
267
 
274
 
268
-    glEnter2D(mWidth, mHeight);
275
+    GLuint xMin = s->x;
276
+    GLuint yMin = s->y;
277
+    GLuint xMax = xMin + (int)((float)surface->w * s->scale);
278
+    GLuint yMax = yMin + (int)((float)surface->h * s->scale);
269
 
279
 
270
     glBegin(GL_QUADS);
280
     glBegin(GL_QUADS);
271
         glTexCoord2f(0.0f, 0.0f);
281
         glTexCoord2f(0.0f, 0.0f);
272
-        glVertex2i(s->x, s->y);
282
+        glVertex2i(xMin, yMin);
273
 
283
 
274
         glTexCoord2f(0.0f, 1.0f);
284
         glTexCoord2f(0.0f, 1.0f);
275
-        glVertex2i(s->x, (int)((float)surface->h * s->scale));
285
+        glVertex2i(xMin, yMax);
276
 
286
 
277
         glTexCoord2f(1.0f, 1.0f);
287
         glTexCoord2f(1.0f, 1.0f);
278
-        glVertex2i((int)((float)surface->w * s->scale), (int)((float)surface->h * s->scale));
288
+        glVertex2i(xMax, yMax);
279
 
289
 
280
         glTexCoord2f(1.0f, 0.0f);
290
         glTexCoord2f(1.0f, 0.0f);
281
-        glVertex2i((int)((float)surface->w * s->scale), s->y);
291
+        glVertex2i(xMax, yMin);
282
     glEnd();
292
     glEnd();
283
 
293
 
284
-    glExit2D();
285
-
286
     SDL_FreeSurface(surface);
294
     SDL_FreeSurface(surface);
287
 }
295
 }
288
 
296
 

+ 0
- 1
src/main.cpp Vedi File

10
 #include <cstring>
10
 #include <cstring>
11
 
11
 
12
 #include "config.h"
12
 #include "config.h"
13
-#include "OpenRaider.h"
14
 #include "main.h"
13
 #include "main.h"
15
 
14
 
16
 OpenRaider *gOpenRaider = NULL;
15
 OpenRaider *gOpenRaider = NULL;

+ 13
- 0
src/utils/strings.cpp Vedi File

17
 
17
 
18
 #include "utils/strings.h"
18
 #include "utils/strings.h"
19
 
19
 
20
+char *stringRemoveQuotes(const char *s) {
21
+    size_t length = strlen(s);
22
+    if ((s[0] == '"') && (s[length - 1] == '"')) {
23
+        char *buf = new char[length - 1];
24
+        for (size_t i = 1; i < (length - 1); i++)
25
+            buf[i - 1] = s[i];
26
+        buf[length - 2] = '\0';
27
+        return buf;
28
+    } else {
29
+        return bufferString("%s", s);
30
+    }
31
+}
32
+
20
 char *stringReplace(const char *s, const char *search, const char *replace) {
33
 char *stringReplace(const char *s, const char *search, const char *replace) {
21
     char *tmp = strstr(s, search);
34
     char *tmp = strstr(s, search);
22
     if (tmp == NULL)
35
     if (tmp == NULL)

Loading…
Annulla
Salva