Browse code

core: snexpr.h - declare iterators out of for() statements

- support non-C99 compilers

Daniel-Constantin Mierla authored on 28/09/2022 07:19:58
Showing 1 changed files
... ...
@@ -269,7 +269,8 @@ static struct
269 269
 
270 270
 static enum snexpr_type snexpr_op(const char *s, size_t len, int unary)
271 271
 {
272
-	for(unsigned int i = 0; i < sizeof(OPS) / sizeof(OPS[0]); i++) {
272
+	unsigned int i;
273
+	for(i = 0; i < sizeof(OPS) / sizeof(OPS[0]); i++) {
273 274
 		if(strlen(OPS[i].s) == len && strncmp(OPS[i].s, s, len) == 0
274 275
 				&& (unary == -1 || snexpr_is_unary(OPS[i].op) == unary)) {
275 276
 			return OPS[i].op;
... ...
@@ -283,7 +284,8 @@ static float snexpr_parse_number(const char *s, size_t len)
283 284
 	float num = 0;
284 285
 	unsigned int frac = 0;
285 286
 	unsigned int digits = 0;
286
-	for(unsigned int i = 0; i < len; i++) {
287
+	unsigned int i;
288
+	for(i = 0; i < len; i++) {
287 289
 		if(s[i] == '.' && frac == 0) {
288 290
 			frac++;
289 291
 			continue;
... ...
@@ -319,7 +321,8 @@ struct snexpr_func
319 321
 static struct snexpr_func *snexpr_func_find(
320 322
 		struct snexpr_func *funcs, const char *s, size_t len)
321 323
 {
322
-	for(struct snexpr_func *f = funcs; f->name; f++) {
324
+	struct snexpr_func *f;
325
+	for(f = funcs; f->name; f++) {
323 326
 		if(strlen(f->name) == len && strncmp(f->name, s, len) == 0) {
324 327
 			return f;
325 328
 		}
... ...
@@ -1190,7 +1193,8 @@ static struct snexpr *snexpr_create(const char *s, size_t len,
1190 1193
 						sne_vec_free(&arg.args);
1191 1194
 						goto cleanup; /* first argument is not a variable */
1192 1195
 					}
1193
-					for(struct snexpr_var *v = vars->head; v; v = v->next) {
1196
+					struct snexpr_var *v;
1197
+					for(v = vars->head; v; v = v->next) {
1194 1198
 						if(v == u->param.var.vref) {
1195 1199
 							struct macro m = {v->name, arg.args};
1196 1200
 							sne_vec_push(&macros, m);
... ...
@@ -1213,8 +1217,9 @@ static struct snexpr *snexpr_create(const char *s, size_t len,
1213 1217
 						m = sne_vec_nth(&macros, found);
1214 1218
 						struct snexpr root = snexpr_constnum(0);
1215 1219
 						struct snexpr *p = &root;
1220
+						int j;
1216 1221
 						/* Assign macro parameters */
1217
-						for(int j = 0; j < sne_vec_len(&arg.args); j++) {
1222
+						for(j = 0; j < sne_vec_len(&arg.args); j++) {
1218 1223
 							char varname[4];
1219 1224
 							snprintf(varname, sizeof(varname) - 1, "$%d",
1220 1225
 									(j + 1));
... ...
@@ -1228,7 +1233,7 @@ static struct snexpr *snexpr_create(const char *s, size_t len,
1228 1233
 							p = &sne_vec_nth(&p->param.op.args, 1);
1229 1234
 						}
1230 1235
 						/* Expand macro body */
1231
-						for(int j = 1; j < sne_vec_len(&m.body); j++) {
1236
+						for(j = 1; j < sne_vec_len(&m.body); j++) {
1232 1237
 							if(j < sne_vec_len(&m.body) - 1) {
1233 1238
 								*p = snexpr_binary(SNE_OP_COMMA, snexpr_constnum(0),
1234 1239
 										snexpr_constnum(0));
... ...
@@ -1402,6 +1407,7 @@ static void snexpr_destroy_args(struct snexpr *e)
1402 1407
 
1403 1408
 static void snexpr_destroy(struct snexpr *e, struct snexpr_var_list *vars)
1404 1409
 {
1410
+	struct snexpr_var *v;
1405 1411
 	_snexternval_cbf = NULL;
1406 1412
 
1407 1413
 	if(e != NULL) {
... ...
@@ -1409,7 +1415,7 @@ static void snexpr_destroy(struct snexpr *e, struct snexpr_var_list *vars)
1409 1415
 		free(e);
1410 1416
 	}
1411 1417
 	if(vars != NULL) {
1412
-		for(struct snexpr_var *v = vars->head; v;) {
1418
+		for(v = vars->head; v;) {
1413 1419
 			struct snexpr_var *next = v->next;
1414 1420
 			if(v->evflags & SNEXPR_VALALLOC) {
1415 1421
 				free(v->v.sval);