mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-25 22:01:33 +00:00
[gatest] Allow specifying the algebra on the command line
Saves having to recompile for a different algebra. Right now, just `-a p,m,z` is supported.
This commit is contained in:
parent
65764a06c0
commit
d0e2c0a9d9
3 changed files with 51 additions and 0 deletions
|
@ -15,6 +15,7 @@
|
|||
BasisLayout *layout;
|
||||
int num_components;
|
||||
int dimension;
|
||||
int plus, minus, zero;
|
||||
}
|
||||
+(Algebra *) R:(int)p, int m, int z;
|
||||
+(Algebra *) PGA:(int)n;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "algebra.h"
|
||||
#include "metric.h"
|
||||
|
@ -14,6 +15,9 @@
|
|||
Algebra *a = [[[Algebra alloc] init] autorelease];
|
||||
a.metric = [[Metric R:p, m, z] retain];
|
||||
|
||||
a.plus = p;
|
||||
a.minus = m;
|
||||
a.zero = z;
|
||||
int d = p + m + z;
|
||||
a.dimension = d;
|
||||
a.num_components = 1 << d;
|
||||
|
@ -153,4 +157,9 @@
|
|||
}
|
||||
}
|
||||
|
||||
-(string) describe
|
||||
{
|
||||
return sprintf ("R(%d,%d,%d)", plus, minus, zero);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -396,6 +396,35 @@ get_symtab_key (void *var, void *unused)
|
|||
return ((var_t *) var).name;
|
||||
}
|
||||
|
||||
static Algebra *
|
||||
parse_algebra (string spec)
|
||||
{
|
||||
ivec3 R = {};
|
||||
string s = spec;
|
||||
if (is_digit (str_mid (spec, 0, 1))) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int end = 0;
|
||||
R[i] = strtol (s, &end, 0);
|
||||
string e = str_mid (s, end, end + 1);
|
||||
if (!e) {
|
||||
break;
|
||||
}
|
||||
if (e != ",") {
|
||||
goto bad_spec;
|
||||
}
|
||||
s = str_mid (s, end + 1);
|
||||
}
|
||||
if (!R[0] && !R[1] && !R[2]) {
|
||||
goto bad_spec;
|
||||
}
|
||||
return [Algebra R:R[0], R[1], R[2]];
|
||||
} else {
|
||||
}
|
||||
bad_spec:
|
||||
printf ("bad algebra spec: %s\n", spec);
|
||||
return nil;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, string *argv)
|
||||
{
|
||||
|
@ -412,10 +441,22 @@ main (int argc, string *argv)
|
|||
arp_end ();
|
||||
arp_start ();
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (argv[i] == "-a") {
|
||||
Algebra *a = [parse_algebra (argv[++i]) retain];
|
||||
if (!a) {
|
||||
return 1;
|
||||
}
|
||||
[algebra release];
|
||||
algebra = a;
|
||||
[minus_one release];
|
||||
minus_one = [[algebra ofGrade:0 values:&m1] retain];
|
||||
continue;
|
||||
}
|
||||
QFile file = Qopen (argv[i], "rt");
|
||||
if (file) {
|
||||
arp_end ();
|
||||
arp_start ();
|
||||
printf ("Using algebra %@\n", algebra);
|
||||
int res = parse_script (argv[i], file);
|
||||
Qclose (file);
|
||||
if (!res) {
|
||||
|
|
Loading…
Reference in a new issue