Add archFromString
function and simplity arch to string conversion
This commit is contained in:
parent
7076777277
commit
cfe1f4d3f2
2 changed files with 26 additions and 17 deletions
|
@ -91,3 +91,4 @@ u128 u128FromVersion(Version *self);
|
||||||
Comparison compareVersion(Version *self, Version *other);
|
Comparison compareVersion(Version *self, Version *other);
|
||||||
int parseVersion(Version *self, const char *s);
|
int parseVersion(Version *self, const char *s);
|
||||||
char *versionToString(Version *self);
|
char *versionToString(Version *self);
|
||||||
|
|
||||||
|
|
42
semver.c
42
semver.c
|
@ -3,6 +3,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
u128 u128FromVersion(Version *self) {
|
u128 u128FromVersion(Version *self) {
|
||||||
u128 out = 0;
|
u128 out = 0;
|
||||||
|
@ -78,24 +79,31 @@ Comparison compareVersion(Version *self, Version *other) {
|
||||||
return CompNone;
|
return CompNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *archToString(Arch self) {
|
const char *ArchNames[] = { "any", "arm", "aarch64", "loongson", "mips32", "mips64",
|
||||||
switch (self) {
|
"ppc", "ppc64", "riscv64", "s390x", "sparc", "sparc64", "x86", "x86_64" };
|
||||||
case any: return "any";
|
|
||||||
case arm: return "arm";
|
const char *archToString(Arch self) {
|
||||||
case arm64: return "aarch64";
|
return ArchNames[self];
|
||||||
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";
|
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
|
int archFromString(char *s) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 14; i++) {
|
||||||
|
if (strncasecmp(s, ArchNames[i], 10) == 0)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
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) {
|
char *versionToString(Version *self) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue