[BACK]Return to mknodes.sh CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / bin / sh

File: [cvs.NetBSD.org] / src / bin / sh / mknodes.sh (download)

Revision 1.2, Tue Apr 29 06:53:00 2008 UTC (15 years, 11 months ago) by martin
Branch: MAIN
CVS Tags: yamt-pf42-base4, yamt-pf42-base3, yamt-pf42-base2, yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, wrstuden-revivesa-base-3, wrstuden-revivesa-base-2, wrstuden-revivesa-base-1, wrstuden-revivesa-base, wrstuden-revivesa, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-base, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-8-base, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, netbsd-5-base, netbsd-5-2-RELEASE, netbsd-5-2-RC1, netbsd-5-2-3-RELEASE, netbsd-5-2-2-RELEASE, netbsd-5-2-1-RELEASE, netbsd-5-2, netbsd-5-1-RELEASE, netbsd-5-1-RC4, netbsd-5-1-RC3, netbsd-5-1-RC2, netbsd-5-1-RC1, netbsd-5-1-5-RELEASE, netbsd-5-1-4-RELEASE, netbsd-5-1-3-RELEASE, netbsd-5-1-2-RELEASE, netbsd-5-1-1-RELEASE, netbsd-5-1, netbsd-5-0-RELEASE, netbsd-5-0-RC4, netbsd-5-0-RC3, netbsd-5-0-RC2, netbsd-5-0-RC1, netbsd-5-0-2-RELEASE, netbsd-5-0-1-RELEASE, netbsd-5-0, netbsd-5, matt-premerge-20091211, matt-nb8-mediatek-base, matt-nb8-mediatek, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-nb5-pq3-base, matt-nb5-pq3, matt-nb5-mips64-u2-k2-k4-k7-k8-k9, matt-nb5-mips64-u1-k1-k5, matt-nb5-mips64-premerge-20101231, matt-nb5-mips64-premerge-20091211, matt-nb5-mips64-k15, matt-nb5-mips64, matt-nb4-mips64-k7-u2a-k9b, matt-mips64-premerge-20101231, matt-mips64-base2, localcount-20160914, khorben-n900, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, hpcarm-cleanup-nbase, cherry-xenmp-base, cherry-xenmp, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver
Branch point for: pgoyette-compat, netbsd-8
Changes since 1.1: +1 -4 lines

Convert to new 2 clause license

#! /bin/sh
#	$NetBSD: mknodes.sh,v 1.2 2008/04/29 06:53:00 martin Exp $

# Copyright (c) 2003 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by David Laight.
#
# 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.

nodetypes=$1
nodes_pat=$2
objdir="$3"

exec <$nodetypes
exec >$objdir/nodes.h.tmp

echo "/*"
echo " * This file was generated by mknodes.sh"
echo " */"
echo

tagno=0
while IFS=; read -r line; do
	line="${line%%#*}"
	IFS=' 	'
	set -- $line
	IFS=
	[ -z "$2" ] && continue
	case "$line" in
	[" 	"]* )
		IFS=' '
		[ $field = 0 ] && struct_list="$struct_list $struct"
		eval field_${struct}_$field=\"\$*\"
		eval numfld_$struct=\$field
		field=$(($field + 1))
		;;
	* )
		define=$1
		struct=$2
		echo "#define $define $tagno"
		tagno=$(($tagno + 1))
		eval define_$struct=\"\$define_$struct \$define\"
		struct_define="$struct_define $struct"
		field=0
		;;
	esac
done

echo

IFS=' '
for struct in $struct_list; do
	echo
	echo
	echo "struct $struct {"
	field=0
	while
		eval line=\"\$field_${struct}_$field\"
		field=$(($field + 1))
		[ -n "$line" ]
	do
		IFS=' '
		set -- $line
		name=$1
		case $2 in
		nodeptr ) type="union node *";;
		nodelist ) type="struct nodelist *";;
		string ) type="char *";;
		int ) type="int ";;
		* ) name=; shift 2; type="$*";;
		esac
		echo "      $type$name;"
	done
	echo "};"
done

echo
echo
echo "union node {"
echo "      int type;"
for struct in $struct_list; do
	echo "      struct $struct $struct;"
done
echo "};"
echo
echo
echo "struct nodelist {"
echo "	struct nodelist *next;"
echo "	union node *n;"
echo "};"
echo
echo
echo "union node *copyfunc(union node *);"
echo "void freefunc(union node *);"

mv $objdir/nodes.h.tmp $objdir/nodes.h || exit 1

exec <$nodes_pat
exec >$objdir/nodes.c.tmp

echo "/*"
echo " * This file was generated by mknodes.sh"
echo " */"
echo

while IFS=; read -r line; do
	IFS=' 	'
	set -- $line
	IFS=
	case "$1" in
	'%SIZES' )
		echo "static const short nodesize[$tagno] = {"
		IFS=' '
		for struct in $struct_define; do
			echo "      SHELL_ALIGN(sizeof (struct $struct)),"
		done
		echo "};"
		;;
	'%CALCSIZE' )
		echo "      if (n == NULL)"
		echo "	    return;"
		echo "      funcblocksize += nodesize[n->type];"
		echo "      switch (n->type) {"
		IFS=' '
		for struct in $struct_list; do
			eval defines=\"\$define_$struct\"
			for define in $defines; do
				echo "      case $define:"
			done
			eval field=\$numfld_$struct
			while
				[ $field != 0 ]
			do
				eval line=\"\$field_${struct}_$field\"
				field=$(($field - 1))
				IFS=' '
				set -- $line
				name=$1
				cl=")"
				case $2 in
				nodeptr ) fn=calcsize;;
				nodelist ) fn=sizenodelist;;
				string ) fn="funcstringsize += strlen"
					cl=") + 1";;
				* ) continue;;
				esac
				echo "	    ${fn}(n->$struct.$name${cl};"
			done
			echo "	    break;"
		done
		echo "      };"
		;;
	'%COPY' )
		echo "      if (n == NULL)"
		echo "	    return NULL;"
		echo "      new = funcblock;"
		echo "      funcblock = (char *) funcblock + nodesize[n->type];"
		echo "      switch (n->type) {"
		IFS=' '
		for struct in $struct_list; do
			eval defines=\"\$define_$struct\"
			for define in $defines; do
				echo "      case $define:"
			done
			eval field=\$numfld_$struct
			while
				[ $field != 0 ]
			do
				eval line=\"\$field_${struct}_$field\"
				field=$(($field - 1))
				IFS=' '
				set -- $line
				name=$1
				case $2 in
				nodeptr ) fn="copynode(";;
				nodelist ) fn="copynodelist(";;
				string ) fn="nodesavestr(";;
				int ) fn=;;
				* ) continue;;
				esac
				f="$struct.$name"
				echo "	    new->$f = ${fn}n->$f${fn:+)};"
			done
			echo "	    break;"
		done
		echo "      };"
		echo "      new->type = n->type;"
		;;
	* ) echo "$line";;
	esac
done

mv $objdir/nodes.c.tmp $objdir/nodes.c || exit 1