Add archFromString function and simplity arch to string conversion

This commit is contained in:
Nathan Fisher 2024-02-10 12:02:18 -05:00
parent 7076777277
commit cfe1f4d3f2
2 changed files with 26 additions and 17 deletions

View file

@ -91,3 +91,4 @@ u128 u128FromVersion(Version *self);
Comparison compareVersion(Version *self, Version *other);
int parseVersion(Version *self, const char *s);
char *versionToString(Version *self);

View file

@ -3,6 +3,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
u128 u128FromVersion(Version *self) {
u128 out = 0;
@ -78,24 +79,31 @@ Comparison compareVersion(Version *self, Version *other) {
return CompNone;
}
char *archToString(Arch self) {
switch (self) {
case any: return "any";
case arm: return "arm";
case arm64: return "aarch64";
case loongson: return "loongson";
case mips32: return "mips32";
case mips64: return "mips64";
case powerepc: return "ppc";
case powerpc64: return "ppc64";
case riscv64: return "riscv64";
case s390x: return "s390x";
case sparc: return "sparc";
case sparc64: return "sparc64";
case x86: return "x86";
case x86_64: return "x86_64";
const char *ArchNames[] = { "any", "arm", "aarch64", "loongson", "mips32", "mips64",
"ppc", "ppc64", "riscv64", "s390x", "sparc", "sparc64", "x86", "x86_64" };
const char *archToString(Arch self) {
return ArchNames[self];
}
int archFromString(char *s) {
int i;
for (i = 0; i < 14; i++) {
if (strncasecmp(s, ArchNames[i], 10) == 0)
return i;
}
return NULL;
if (strncasecmp(s, "arm64", 5) == 0)
return arm64;
else if (strncasecmp(s, "i386", 4) == 0)
return x86;
else if (strncasecmp(s, "i486", 4) == 0)
return x86;
else if (strncasecmp(s, "i586", 4) == 0)
return x86;
else if (strncasecmp(s, "i686", 4) == 0)
return x86;
else
return -1;
}
char *versionToString(Version *self) {