Cube  Diff

Differences From Artifact [ccec6a17e5]:

To Artifact [61c1fa172a]:


50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64







-
+








			idents[@(name)] = b;
		} else {
			if (b.type == ID_ALIAS)
				b.action = exchangestr(b.action, action);
			else
				conoutf(
				    "cannot redefine builtin %s with an alias",
				    @"cannot redefine builtin %s with an alias",
				    name);
		}
	}
}

COMMAND(alias, ARG_2STR)

148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162







-
+







			*(p - 1) = ' '; // hack
		if (c == left)
			brak++;
		else if (c == right)
			brak--;
		else if (!c) {
			p--;
			conoutf("missing \"%c\"", right);
			conoutf(@"missing \"%c\"", right);
			return NULL;
		}
	}
	char *s = newstring(word, p - word - 1);
	if (left == '(') {
		string t;
		itoa(t,
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221







-
+







				return exchangestr(n, t);
			case ID_ALIAS:
				return exchangestr(n, ID.action);
			}
		}
	}

	conoutf("unknown alias lookup: %s", n + 1);
	conoutf(@"unknown alias lookup: %s", n + 1);
	return n;
}

int
execute(char *p, bool isdown) // all evaluation happens here, recursively
{
	const int MAXWORDS = 25; // limit, remove
250
251
252
253
254
255
256
257

258
259
260
261
262
263
264
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264







-
+








		@autoreleasepool {
			Ident *ID = idents[@(c)];

			if (ID == nil) {
				val = ATOI(c);
				if (!val && *c != '0')
					conoutf("unknown command: %s", c);
					conoutf(@"unknown command: %s", c);
			} else {
				switch (ID.type) {
				// game defined commands
				case ID_COMMAND:
					// use very ad-hoc function signature,
					// and just call it
					switch (ID.narg) {
391
392
393
394
395
396
397
398

399
400
401
402
403
404
405





406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436




























437
438
439
440
441
442
443
391
392
393
394
395
396
397

398
399
400
401




402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422















423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457







-
+



-
-
-
-
+
+
+
+
+
















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				// game defined variables
				case ID_VAR:
					if (isdown) {
						if (!w[1][0])
							// var with no value
							// just prints its
							// current value
							conoutf("%s = %d", c,
							conoutf(@"%s = %d", c,
							    *ID.storage);
						else {
							if (ID.min > ID.max) {
								conoutf("variab"
								        "le is "
								        "read-"
								        "only");
								conoutf(
								    @"variable "
								    @"is "
								    @"read-"
								    @"only");
							} else {
								int i1 =
								    ATOI(w[1]);
								if (i1 <
								        ID.min ||
								    i1 >
								        ID.max) {
									// clamp
									// to
									// valid
									// range
									i1 =
									    i1 < ID.min
									        ? ID.min
									        : ID.max;
									conoutf(
									    "va"
									    "li"
									    "d "
									    "ra"
									    "ng"
									    "e "
									    "fo"
									    "r "
									    "%s"
									    " i"
									    "s "
									    "%d"
									    ".."
									    "%"
									    "d",
									    @"v"
									    @"a"
									    @"l"
									    @"i"
									    @"d"
									    @" "
									    @"r"
									    @"a"
									    @"n"
									    @"g"
									    @"e"
									    @" "
									    @"f"
									    @"o"
									    @"r"
									    @" "
									    @"%"
									    @"s"
									    @" "
									    @"i"
									    @"s"
									    @" "
									    @"%"
									    @"d"
									    @"."
									    @"."
									    @"%"
									    @"d",
									    c,
									    ID.min,
									    ID.max);
								}
								*ID.storage =
								    i1;
							}
529
530
531
532
533
534
535
536

537
538
539
540
541
542
543
543
544
545
546
547
548
549

550
551
552
553
554
555
556
557







-
+







	return true;
}

void
exec(char *cfgfile)
{
	if (!execfile(cfgfile))
		conoutf("could not read \"%s\"", cfgfile);
		conoutf(@"could not read \"%s\"", cfgfile);
}

void
writecfg()
{
	FILE *f = fopen("config.cfg", "w");
	if (!f)