fbeb97dcac
One less backslash per line of code.
139 lines
3.5 KiB
Bash
Executable File
139 lines
3.5 KiB
Bash
Executable File
#!/bin/sh -
|
|
# $NetBSD: mkops,v 1.11 2020/12/31 16:19:05 rillig Exp $
|
|
#
|
|
# Copyright (c) 2011 The NetBSD Foundation, Inc.
|
|
# All rights reserved.
|
|
#
|
|
# This code is derived from software contributed to The NetBSD Foundation
|
|
# by Christos Zoulas.
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without
|
|
# modification, are permitted provided that the following conditions
|
|
# are met:
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions and the following disclaimer.
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
# documentation and/or other materials provided with the distribution.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
# allow AWK to be overridden
|
|
: "${AWK:=awk}"
|
|
|
|
|
|
while getopts ch f
|
|
do
|
|
case $f in
|
|
c)
|
|
v=c;;
|
|
h)
|
|
v=h;;
|
|
*)
|
|
echo "Usage: $0 -c|-h";;
|
|
esac
|
|
done
|
|
|
|
# shellcheck disable=SC2003
|
|
shift "$(expr ${OPTIND} - 1)"
|
|
|
|
# shellcheck disable=SC2016
|
|
$AWK -F' ' -v v=$v '
|
|
function println(s)
|
|
{
|
|
printf("%s\n", s);
|
|
}
|
|
|
|
function display(fmt, last, comment)
|
|
{
|
|
printf(fmt, last);
|
|
if (comment != "")
|
|
printf("\t/* pseudo op not used in trees */");
|
|
println("");
|
|
}
|
|
|
|
BEGIN {
|
|
print "/* Automatically generated file; do not edit */";
|
|
if (v == "h") {
|
|
println("typedef enum {");
|
|
FIRST = "";
|
|
LAST = "";
|
|
LASTCOMMENT= "";
|
|
}
|
|
if (v == "c") {
|
|
println("#include <sys/types.h>");
|
|
println("#include \"op.h\"");
|
|
println("#include \"param.h\"");
|
|
println("#ifndef __arraycount");
|
|
println("#define __arraycount(a) (sizeof(a) / sizeof(a[0]))");
|
|
println("#endif /* __arraycount */");
|
|
println("mod_t modtab[NOPS];");
|
|
println("static const struct {");
|
|
println("\tmod_t\tm;");
|
|
println("\tunsigned char\tok;");
|
|
println("} imods[] = {");
|
|
}
|
|
}
|
|
|
|
{
|
|
if (v == "h") {
|
|
if (LAST != "") {
|
|
if (FIRST == "") {
|
|
display("\t%s\t= 0,", LAST, LASTCOMMENT);
|
|
} else {
|
|
display("\t%s,", LAST, LASTCOMMENT);
|
|
}
|
|
}
|
|
FIRST = LAST;
|
|
LAST = $2;
|
|
LASTCOMMENT = $4;
|
|
}
|
|
if (v == "c") {
|
|
if ($3 == "X") {
|
|
m = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,";
|
|
act = 0;
|
|
} else {
|
|
m = $3;
|
|
act = 1;
|
|
}
|
|
printf("\t{ /* %s */\t{ %s \"%s\" }, %d },\n", $2, m, $1, act);
|
|
}
|
|
}
|
|
|
|
END {
|
|
if (v == "h") {
|
|
display("\t%s,", LAST, LASTCOMMENT);
|
|
printf("#define\tNOPS\t((int)%s + 1)\n", LAST);
|
|
println("} op_t;");
|
|
println("const char *getopname(op_t);");
|
|
println("void initmtab(void);");
|
|
}
|
|
if (v == "c") {
|
|
println("};");
|
|
println("const char *");
|
|
println("getopname(op_t op) {");
|
|
println("\treturn imods[op].m.m_name;");
|
|
println("}");
|
|
println("void");
|
|
println("initmtab(void)");
|
|
println("{");
|
|
println("\tsize_t i;");
|
|
println("");
|
|
println("\tfor (i = 0; i < __arraycount(imods); i++)");
|
|
println("\t\tif (imods[i].ok)");
|
|
println("\t\t\tmodtab[i] = imods[i].m;");
|
|
println("}");
|
|
}
|
|
}
|
|
' "$@"
|