Cube  Diff

Differences From Artifact [931e4eb08f]:

To Artifact [c9d2804930]:


581
582
583
584
585
586
587



588
589




590



591
592
593
594
595
596









597
598
599
600
601


602
603

604
605
606




607
608
609
610
611
612



613
614

615

616
617
618
619
620
621
622
581
582
583
584
585
586
587
588
589
590


591
592
593
594
595
596
597
598






599
600
601
602
603
604
605
606
607
608
609
610


611
612
613
614
615



616
617
618
619
620
621
622



623
624
625

626
627

628
629
630
631
632
633
634
635







+
+
+
-
-
+
+
+
+

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



-
-
+
+


+
-
-
-
+
+
+
+



-
-
-
+
+
+
-

+
-
+







		}
	}
}

void
writecfg()
{
	OFStream *stream;
	@try {
		OFIRI *IRI = [Cube.sharedInstance.userDataIRI
	FILE *f = fopen("config.cfg", "w");
	if (!f)
		    IRIByAppendingPathComponent:@"config.cfg"];
		stream = [[OFIRIHandler handlerForIRI:IRI] openItemAtIRI:IRI
		                                                    mode:@"w"];
	} @catch (id e) {
		return;
	}

	[stream writeString:
	fprintf(f, "// automatically written on exit, do not modify\n// delete "
	           "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");
	            @"// automatically written on exit, do not modify\n"
	            @"// delete 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(stream);
	[stream writeString:@"\n"];

	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
		if (ident.type == ID_VAR && ident.persist) {
			fprintf(f, "%s %d\n", ident.name.UTF8String,
			    *ident.storage);
			[stream
			    writeFormat:@"%@ %d\n", ident.name, *ident.storage];
		}
	}];
	[stream writeString:@"\n"];
	fprintf(f, "\n");
	writebinds(f);
	fprintf(f, "\n");

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

	[idents enumerateKeysAndObjectsUsingBlock:^(
	    OFString *name, Ident *ident, bool *stop) {
		if (ident.type == ID_ALIAS &&
		    !strstr(ident.name.UTF8String, "nextmap_")) {
			fprintf(f, "alias \"%s\" [%s]\n", ident.name.UTF8String,
			    ident.action.UTF8String);
		    ![ident.name hasPrefix:@"nextmap_"])
			[stream writeFormat:@"alias \"%@\" [%@]\n", ident.name,
			        ident.action];
		}
	}];

	fclose(f);
	[stream close];
}

COMMAND(writecfg, ARG_NONE)

// below the commands that implement a small imperative language. thanks to the
// semantics of
// () and [] expressions, any control construct can be defined trivially.