Module Name:    src
Committed By:   christos
Date:           Sat Feb  5 16:10:17 UTC 2011

Added Files:
        src/usr.bin/xlint/lint1: mkops

Log Message:
oops forgot to commit the script.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/usr.bin/xlint/lint1/mkops

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/usr.bin/xlint/lint1/mkops
diff -u /dev/null src/usr.bin/xlint/lint1/mkops:1.1
--- /dev/null	Sat Feb  5 11:10:17 2011
+++ src/usr.bin/xlint/lint1/mkops	Sat Feb  5 11:10:17 2011
@@ -0,0 +1,106 @@
+#!/bin/sh -
+#	$NetBSD: mkops,v 1.1 2011/02/05 16:10:17 christos Exp $
+#
+# Copyright (c) 2003 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 overriden
+: ${AWK:=awk}
+
+
+while getopts ch f
+do
+	case $f in
+	c)
+		v=c;;
+	h)
+		v=h;;
+	*)
+		echo "Usage: $0 -c|-h";;
+	esac
+done
+
+shift $(expr ${OPTIND} - 1)
+
+$AWK -F'	' -v v=$v '
+function display(fmt, last, comment)
+{
+	printf(fmt, last);
+	if (comment != "")
+		printf("\t%s", comment);
+	printf("\n");
+}
+
+BEGIN {
+	print "/* Automatically generated file; do not edit */";
+	if (v == "h") {
+		printf("typedef enum {\n");
+		FIRST = "";
+		LAST = "";
+		LASTCOMMENT= "";
+	}
+	if (v == "c") {
+		printf("#include <sys/types.h>\n");
+		printf("#include \"op.h\"\n");
+		printf("static const char *opnames[] = {\n");
+	}
+}
+
+{
+	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 = $3;
+	}
+	if (v == "c") {
+		printf("\t\"%s\",\t/* %s */\n", $1, $2);
+	}
+}
+
+END {
+	if (v == "h") {
+		display("\t%s,", LAST, LASTCOMMENT);
+		printf("#define\tNOPS\t((int)%s + 1)\n", LAST);
+		printf("} op_t;\n");
+		printf("const char *getopname(op_t);\n");
+	} 
+	if (v == "c") {
+		printf("};\n");
+		printf("const char *\n");
+		printf("getopname(op_t op) {\n");
+		printf("\treturn opnames[op];\n");
+		printf("}\n");
+	}
+}
+' "$@"

Reply via email to