xref: /openbsd/usr.bin/mandoc/arch.c (revision d415bd75)
1 /*	$OpenBSD: arch.c,v 1.14 2021/05/01 16:11:17 visa Exp $ */
2 /*
3  * Copyright (c) 2017, 2019 Ingo Schwarze <schwarze@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 #include <string.h>
18 
19 #include "roff.h"
20 
21 int
22 arch_valid(const char *arch, enum mandoc_os os)
23 {
24 	const char *openbsd_arch[] = {
25 		"alpha", "amd64", "arm64", "armv7", "hppa", "i386",
26 		"landisk", "loongson", "luna88k", "macppc", "mips64",
27 		"octeon", "powerpc64", "riscv64", "sparc64", NULL
28 	};
29 	const char *netbsd_arch[] = {
30 		"acorn26", "acorn32", "algor", "alpha", "amiga",
31 		"arc", "atari",
32 		"bebox", "cats", "cesfic", "cobalt", "dreamcast",
33 		"emips", "evbarm", "evbmips", "evbppc", "evbsh3", "evbsh5",
34 		"hp300", "hpcarm", "hpcmips", "hpcsh", "hppa",
35 		"i386", "ibmnws", "luna68k",
36 		"mac68k", "macppc", "mipsco", "mmeye", "mvme68k", "mvmeppc",
37 		"netwinder", "news68k", "newsmips", "next68k",
38 		"pc532", "playstation2", "pmax", "pmppc", "prep",
39 		"sandpoint", "sbmips", "sgimips", "shark",
40 		"sparc", "sparc64", "sun2", "sun3",
41 		"vax", "walnut", "x68k", "x86", "x86_64", "xen", NULL
42 	};
43 	const char **arches[] = { NULL, netbsd_arch, openbsd_arch };
44 	const char **arch_p;
45 
46 	if ((arch_p = arches[os]) == NULL)
47 		return 1;
48 	for (; *arch_p != NULL; arch_p++)
49 		if (strcmp(*arch_p, arch) == 0)
50 			return 1;
51 	return 0;
52 }
53