Cube  Diff

Differences From Artifact [61c1fa172a]:

To Artifact [56e5f5018d]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// command.cpp: implements the parsing and execution of a tiny script language
// which is largely backwards compatible with the quake console language.

#include "cube.h"

enum { ID_VAR, ID_COMMAND, ID_ALIAS };

@interface Ident : OFObject
@property(nonatomic) int type; // one of ID_* above
@property(nonatomic) char *name;
@property(nonatomic) int min, max;  // ID_VAR
@property(nonatomic) int *storage;  // ID_VAR
@property(nonatomic) void (*fun)(); // ID_VAR, ID_COMMAND
@property(nonatomic) int narg;      // ID_VAR, ID_COMMAND
@property(nonatomic) char *action;  // ID_ALIAS
@property(nonatomic) bool persist;
@end

@implementation Ident
@end

void
itoa(char *s, int i)








|
|
|
|
|
|
|
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// command.cpp: implements the parsing and execution of a tiny script language
// which is largely backwards compatible with the quake console language.

#include "cube.h"

enum { ID_VAR, ID_COMMAND, ID_ALIAS };

@interface Ident : OFObject
@property (nonatomic) int type; // one of ID_* above
@property (nonatomic) char *name;
@property (nonatomic) int min, max;  // ID_VAR
@property (nonatomic) int *storage;  // ID_VAR
@property (nonatomic) void (*fun)(); // ID_VAR, ID_COMMAND
@property (nonatomic) int narg;      // ID_VAR, ID_COMMAND
@property (nonatomic) char *action;  // ID_ALIAS
@property (nonatomic) bool persist;
@end

@implementation Ident
@end

void
itoa(char *s, int i)
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
	if (!completesize) {
		completesize = (int)strlen(s) - 1;
		completeidx = 0;
	}
	__block int idx = 0;
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
	  if (strncmp(ident.name, s + 1, completesize) == 0 &&
	      idx++ == completeidx) {
		  strcpy_s(s, "/");
		  strcat_s(s, ident.name);
	  }
	}];
	completeidx++;
	if (completeidx >= idx)
		completeidx = 0;
}

bool







|
|
|
|
|







515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
	if (!completesize) {
		completesize = (int)strlen(s) - 1;
		completeidx = 0;
	}
	__block int idx = 0;
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
		if (strncmp(ident.name, s + 1, completesize) == 0 &&
		    idx++ == completeidx) {
			strcpy_s(s, "/");
			strcat_s(s, ident.name);
		}
	}];
	completeidx++;
	if (completeidx >= idx)
		completeidx = 0;
}

bool
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576

577
578
579
580
581
582
583
584
585
	           "this file to have defaults.cfg overwrite these "
	           "settings\n// modify settings in game, or put settings in "
	           "autoexec.cfg to override anything\n\n");
	writeclientinfo(f);
	fprintf(f, "\n");
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
	  if (ident.type == ID_VAR && ident.persist) {
		  fprintf(f, "%s %d\n", ident.name, *ident.storage);
	  }
	}];
	fprintf(f, "\n");
	writebinds(f);
	fprintf(f, "\n");
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
	  if (ident.type == ID_ALIAS && !strstr(ident.name, "nextmap_")) {

		  fprintf(f, "alias \"%s\" [%s]\n", ident.name, ident.action);
	  }
	}];
	fclose(f);
}

COMMAND(writecfg, ARG_NONE);

// below the commands that implement a small imperative language. thanks to the







|
|
|






|
>
|
|







560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
	           "this file to have defaults.cfg overwrite these "
	           "settings\n// modify settings in game, or put settings in "
	           "autoexec.cfg to override anything\n\n");
	writeclientinfo(f);
	fprintf(f, "\n");
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
		if (ident.type == ID_VAR && ident.persist) {
			fprintf(f, "%s %d\n", ident.name, *ident.storage);
		}
	}];
	fprintf(f, "\n");
	writebinds(f);
	fprintf(f, "\n");
	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
		if (ident.type == ID_ALIAS && !strstr(ident.name, "nextmap_")) {
			fprintf(
			    f, "alias \"%s\" [%s]\n", ident.name, ident.action);
		}
	}];
	fclose(f);
}

COMMAND(writecfg, ARG_NONE);

// below the commands that implement a small imperative language. thanks to the