|
@@ -3,6 +3,7 @@
|
3
|
3
|
* \brief String handling utilities
|
4
|
4
|
*
|
5
|
5
|
* \author xythobuz
|
|
6
|
+ * \author Mongoose
|
6
|
7
|
*/
|
7
|
8
|
|
8
|
9
|
#include <cstdarg>
|
|
@@ -59,7 +60,6 @@ char *bufferString(const char *string, ...) {
|
59
|
60
|
return text;
|
60
|
61
|
}
|
61
|
62
|
|
62
|
|
-
|
63
|
63
|
char *fullPath(const char *path, char end) {
|
64
|
64
|
unsigned int lenPath, offset;
|
65
|
65
|
wordexp_t word;
|
|
@@ -94,7 +94,10 @@ char *fullPath(const char *path, char end) {
|
94
|
94
|
|
95
|
95
|
wordfree(&word);
|
96
|
96
|
#else
|
97
|
|
-#error Platform not supported!
|
|
97
|
+ printf("WARNING: Tilde expansion not supported on this platform!\n");
|
|
98
|
+ lenPath = strlen(path);
|
|
99
|
+ dir = new char[lenPath + 2]; // space for end char
|
|
100
|
+ strncpy(dir, path, lenPath);
|
98
|
101
|
#endif
|
99
|
102
|
} else {
|
100
|
103
|
lenPath = strlen(path);
|
|
@@ -113,56 +116,18 @@ char *fullPath(const char *path, char end) {
|
113
|
116
|
return dir;
|
114
|
117
|
}
|
115
|
118
|
|
116
|
|
-
|
117
|
|
-char *getFileFromFullPath(char *filename)
|
118
|
|
-{
|
119
|
|
- int i, j, len;
|
120
|
|
- char *str;
|
121
|
|
-
|
122
|
|
-
|
123
|
|
- len = strlen(filename);
|
124
|
|
-
|
125
|
|
- for (i = len, j = 0; i > 0; --i, ++j)
|
126
|
|
- {
|
127
|
|
- if (filename[i] == '/' || filename[i] == '\\')
|
128
|
|
- break;
|
129
|
|
- }
|
130
|
|
-
|
131
|
|
- j--;
|
132
|
|
-
|
133
|
|
- str = new char[len - j + 1];
|
134
|
|
-
|
135
|
|
- for (i = 0; i < len - j; ++i)
|
136
|
|
- {
|
137
|
|
- str[i] = filename[i + len - j];
|
138
|
|
- }
|
139
|
|
-
|
140
|
|
- str[i] = 0;
|
141
|
|
-
|
142
|
|
- return str;
|
143
|
|
-}
|
144
|
|
-
|
145
|
|
-// Mongoose 2002.03.23, Checks command to see if it's same
|
146
|
|
-// as symbol, then returns the arg list in command buffer
|
147
|
|
-bool rc_command(const char *symbol, char *command)
|
148
|
|
-{
|
149
|
|
- int i, j, lens, lenc;
|
150
|
|
-
|
151
|
|
-
|
|
119
|
+bool rc_command(const char *symbol, char *command) {
|
152
|
120
|
if (!symbol || !symbol[0] || !command || !command[0])
|
153
|
|
- {
|
154
|
121
|
return false;
|
155
|
|
- }
|
156
|
122
|
|
157
|
|
- lens = strlen(symbol);
|
|
123
|
+ int lens = strlen(symbol);
|
158
|
124
|
|
159
|
|
- if (strncmp(command, symbol, lens) == 0)
|
160
|
|
- {
|
161
|
|
- lenc = strlen(command);
|
|
125
|
+ if (strncmp(command, symbol, lens) == 0) {
|
|
126
|
+ int lenc = strlen(command);
|
162
|
127
|
|
|
128
|
+ //! \fixme Should ignore whitespace, but only if it is really there...?
|
163
|
129
|
// lens+1 skips '=' or ' '
|
164
|
|
- for (i = 0, j = lens+1; j < lenc; ++i, ++j)
|
165
|
|
- {
|
|
130
|
+ for (int i = 0, j = lens+1; j < lenc; ++i, ++j) {
|
166
|
131
|
command[i] = command[j];
|
167
|
132
|
command[i+1] = 0;
|
168
|
133
|
}
|
|
@@ -173,17 +138,13 @@ bool rc_command(const char *symbol, char *command)
|
173
|
138
|
return false;
|
174
|
139
|
}
|
175
|
140
|
|
176
|
|
-
|
177
|
|
-int rc_get_bool(char *buffer, bool *val)
|
178
|
|
-{
|
|
141
|
+int rc_get_bool(char *buffer, bool *val) {
|
179
|
142
|
if (!buffer || !buffer[0])
|
180
|
|
- {
|
181
|
143
|
return -1;
|
182
|
|
- }
|
183
|
144
|
|
184
|
|
- if ((strncmp(buffer, "true", 4) == 0) || (buffer[0] == '1'))
|
|
145
|
+ if ((buffer[0] == '1') || (strncmp(buffer, "true", 4) == 0))
|
185
|
146
|
*val = true;
|
186
|
|
- else if ((strncmp(buffer, "false", 5) == 0) || (buffer[0] == '0'))
|
|
147
|
+ else if ((buffer[0] == '0') || (strncmp(buffer, "false", 5) == 0))
|
187
|
148
|
*val = false;
|
188
|
149
|
else
|
189
|
150
|
return -2;
|