Cube  Check-in [2bc02cf470]

Overview
Comment:Improve clang-format file
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2bc02cf4700f34b37d510b7b9bedf34ff005dd333cb898dbf964a24f6eefa8cb
User & Date: js on 2024-08-03 17:11:40
Other Links: manifest | tags
Context
2024-08-05
00:31
Merge accidental fork check-in: f9d39991c5 user: js tags: trunk
2024-08-03
17:11
Improve clang-format file check-in: 2bc02cf470 user: js tags: trunk
17:02
Make conoutf take an OFString check-in: f8f97851f3 user: js tags: trunk
Changes

Modified src/.clang-format from [36a701b94f] to [c1e6bd9906].

1
2
3
4
5
6











IndentWidth: 8
TabWidth: 8
UseTab: ForIndentation
BreakBeforeBraces: Linux
AlwaysBreakAfterReturnType: AllDefinitions
AlignAfterOpenBracket: DontAlign

















>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
IndentWidth: 8
TabWidth: 8
UseTab: ForIndentation
BreakBeforeBraces: Linux
AlwaysBreakAfterReturnType: AllDefinitions
AlignAfterOpenBracket: DontAlign
ObjCBlockIndentWidth: 8
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
ObjCPropertyAttributeOrder: [
    class, direct,
    readonly, readwrite,
    nullable, nonnull, null_resettable, null_unspecified,
    assign, retain, strong, copy, weak, unsafe_unretained,
    atomic, nonatomic,
    getter, setter
]

Modified src/command.mm from [61c1fa172a] to [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

Modified src/cube.h from [9271127084] to [24088972ed].

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

// nasty macros for registering script functions, abuses globals to avoid
// excessive infrastructure
#define COMMANDN(name, fun, nargs)                                             \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                          \
		  addcommand(#name, (void (*)())fun, nargs);                   \
		});                                                            \
	}
#define COMMAND(name, nargs) COMMANDN(name, name, nargs)
#define VARP(name, min, cur, max)                                              \
	int name;                                                              \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                          \

		  name = variable(#name, min, cur, max, &name, NULL, true);    \
		});                                                            \
	}
#define VAR(name, min, cur, max)                                               \
	int name;                                                              \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                          \

		  name = variable(#name, min, cur, max, &name, NULL, false);   \
		});                                                            \
	}
#define VARF(name, min, cur, max, body)                                        \
	void var_##name();                                                     \
	static int name;                                                       \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                          \
		  name = variable(                                             \
		      #name, min, cur, max, &name, var_##name, false);         \
		});                                                            \
	}                                                                      \
	void var_##name() { body; }
#define VARFP(name, min, cur, max, body)                                       \
	void var_##name();                                                     \
	static int name;                                                       \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                          \
		  name =                                                       \
		      variable(#name, min, cur, max, &name, var_##name, true); \
		});                                                            \
	}                                                                      \
	void var_##name() { body; }

#define ATOI(s) strtol(s, NULL, 0) // supports hexadecimal numbers

#ifdef WIN32







|








>
|







>
|








|
|









|
|







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

// nasty macros for registering script functions, abuses globals to avoid
// excessive infrastructure
#define COMMANDN(name, fun, nargs)                                             \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                          \
			addcommand(#name, (void (*)())fun, nargs);             \
		});                                                            \
	}
#define COMMAND(name, nargs) COMMANDN(name, name, nargs)
#define VARP(name, min, cur, max)                                              \
	int name;                                                              \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                          \
			name =                                                 \
			    variable(#name, min, cur, max, &name, NULL, true); \
		});                                                            \
	}
#define VAR(name, min, cur, max)                                               \
	int name;                                                              \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                          \
			name = variable(                                       \
			    #name, min, cur, max, &name, NULL, false);         \
		});                                                            \
	}
#define VARF(name, min, cur, max, body)                                        \
	void var_##name();                                                     \
	static int name;                                                       \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                          \
			name = variable(                                       \
			    #name, min, cur, max, &name, var_##name, false);   \
		});                                                            \
	}                                                                      \
	void var_##name() { body; }
#define VARFP(name, min, cur, max, body)                                       \
	void var_##name();                                                     \
	static int name;                                                       \
	OF_CONSTRUCTOR()                                                       \
	{                                                                      \
		enqueueInit(#name, ^{                                          \
			name = variable(                                       \
			    #name, min, cur, max, &name, var_##name, true);    \
		});                                                            \
	}                                                                      \
	void var_##name() { body; }

#define ATOI(s) strtol(s, NULL, 0) // supports hexadecimal numbers

#ifdef WIN32