Cube  Diff

Differences From Artifact [116e44fb5b]:

To Artifact [45797ae2bc]:


14
15
16
17
18
19
20
21

22
23
24
25
26



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82

83
84
85
86
87
88
89
14
15
16
17
18
19
20

21
22
23



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39













40
41
42

43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59
60
61
62

63
64
65
66
67
68

69
70
71
72
73
74
75
76







-
+


-
-
-
+
+
+













-
-
-
-
-
-
-
-
-
-
-
-
-



-
+








-
+










-
+





-
+







{
	free(*string);
}

void
alias(OFString *name, OFString *action)
{
	Alias *alias = [Identifier identifierForName:name];
	Alias *alias = Identifier.identifiers[name];

	if (alias == nil)
		[Identifier addIdentifier:[Alias aliasWithName:name
		                                        action:action
		                                     persisted:true]];
		Identifier.identifiers[name] = [Alias aliasWithName:name
		                                             action:action
		                                          persisted:true];
	else {
		if ([alias isKindOfClass:Alias.class])
			alias.action = action;
		else
			conoutf(
			    @"cannot redefine builtin %@ with an alias", name);
	}
}

COMMAND(alias, ARG_2STR, ^(OFString *name, OFString *action) {
	alias(name, action);
})

int
variable(OFString *name, int min, int cur, int max, int *storage,
    void (*function)(), bool persisted)
{
	[Identifier addIdentifier:[Variable variableWithName:name
	                                                 min:min
	                                                 max:max
	                                             storage:storage
	                                            function:function
	                                           persisted:persisted]];
	return cur;
}

void
setvar(OFString *name, int i)
{
	Variable *variable = [Identifier identifierForName:name];
	Variable *variable = Identifier.identifiers[name];

	if ([variable isKindOfClass:Variable.class])
		*variable.storage = i;
}

int
getvar(OFString *name)
{
	Variable *variable = [Identifier identifierForName:name];
	Variable *variable = Identifier.identifiers[name];

	if ([variable isKindOfClass:Variable.class])
		return *variable.storage;

	return 0;
}

bool
identexists(OFString *name)
{
	return ([Identifier identifierForName:name] != nil);
	return (Identifier.identifiers[name] != nil);
}

OFString *
getalias(OFString *name)
{
	Alias *alias = [Identifier identifierForName:name];
	Alias *alias = Identifier.identifiers[name];

	if ([alias isKindOfClass:Alias.class])
		return alias.action;

	return nil;
}

149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
136
137
138
139
140
141
142

143
144
145
146
147
148
149
150







-
+







}

// find value of ident referenced with $ in exp
OFString *
lookup(OFString *n)
{
	__kindof Identifier *identifier =
	    [Identifier identifierForName:[n substringFromIndex:1]];
	    Identifier.identifiers[[n substringFromIndex:1]];

	if ([identifier isKindOfClass:Variable.class]) {
		return [OFString stringWithFormat:@"%d", *[identifier storage]];
	} else if ([identifier isKindOfClass:Alias.class])
		return [identifier action];

	conoutf(@"unknown alias lookup: %@", [n substringFromIndex:1]);
256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
243
244
245
246
247
248
249

250
251
252
253
254
255
256
257







-
+







			c = [c substringFromIndex:1];
			w[0] = c;
		}
		// empty statement
		if (c.length == 0)
			continue;

		val = executeIdentifier([Identifier identifierForName:c],
		val = executeIdentifier(Identifier.identifiers[c],
		    [OFArray arrayWithObjects:w count:numargs], isDown);
	}

	return val;
}

// tab-completion of all identifiers
288
289
290
291
292
293
294
295
296


297
298
299
300
301
302
303
275
276
277
278
279
280
281


282
283
284
285
286
287
288
289
290







-
-
+
+








	if (!completesize) {
		completesize = s.length - 1;
		completeidx = 0;
	}

	__block int idx = 0;
	[Identifier enumerateIdentifiersUsingBlock:^(
	    __kindof Identifier *identifier) {
	[Identifier.identifiers enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, __kindof Identifier *identifier, bool *stop) {
		if (strncmp(identifier.name.UTF8String, s.UTF8String + 1,
		        completesize) == 0 &&
		    idx++ == completeidx)
			[s replaceCharactersInRange:OFMakeRange(1, s.length - 1)
			                 withString:identifier.name];
	}];

355
356
357
358
359
360
361
362
363
364
365
366





367
368
369
370



371
372
373
374
375
376
377
378
379
380





381
382
383
384



385
386
387
388
389
390
391
342
343
344
345
346
347
348





349
350
351
352
353
354



355
356
357
358
359
360
361
362





363
364
365
366
367
368



369
370
371
372
373
374
375
376
377
378







-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+





-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+







	                    @"overwrite these settings\n"
	                    @"// modify settings in game, or put settings in "
	                    @"autoexec.cfg to override anything\n"
	                    @"\n"];
	writeclientinfo(stream);
	[stream writeString:@"\n"];

	[Identifier
	    enumerateIdentifiersUsingBlock:^(__kindof Identifier *identifier) {
		    if (![identifier isKindOfClass:Variable.class] ||
		        ![identifier persisted])
			    return;
	[Identifier.identifiers enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, __kindof Identifier *identifier, bool *stop) {
		if (![identifier isKindOfClass:Variable.class] ||
		    ![identifier persisted])
			return;

		    [stream writeFormat:@"%@ %d\n", identifier.name,
		            *[identifier storage]];
	    }];
		[stream writeFormat:@"%@ %d\n", identifier.name,
		        *[identifier storage]];
	}];
	[stream writeString:@"\n"];

	writebinds(stream);
	[stream writeString:@"\n"];

	[Identifier
	    enumerateIdentifiersUsingBlock:^(__kindof Identifier *identifier) {
		    if (![identifier isKindOfClass:Alias.class] ||
		        [identifier.name hasPrefix:@"nextmap_"])
			    return;
	[Identifier.identifiers enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, __kindof Identifier *identifier, bool *stop) {
		if (![identifier isKindOfClass:Alias.class] ||
		    [identifier.name hasPrefix:@"nextmap_"])
			return;

		    [stream writeFormat:@"alias \"%@\" [%@]\n", identifier.name,
		            [identifier action]];
	    }];
		[stream writeFormat:@"alias \"%@\" [%@]\n", identifier.name,
		        [identifier action]];
	}];

	[stream close];
}

COMMAND(writecfg, ARG_NONE, ^{
	writecfg();
})