2 # $NetBSD: mkinit.sh,v 1.2 2004/06/15 23:09:54 dsl Exp $
4 # Copyright (c) 2003 The NetBSD Foundation, Inc.
7 # This code is derived from software contributed to The NetBSD Foundation
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
18 # 3. Neither the name of The NetBSD Foundation nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
22 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
41 includes=' "shell.h" "mystring.h" "init.h" '
51 while IFS=; read -r line; do
54 INIT["{ "]* ) event=init;;
55 RESET["{ "]* ) event=reset;;
56 SHELLPROC["{ "]* ) event=shellproc;;
61 [ "${includes}" != "${includes%* $2 }" ] && continue
62 includes="$includes$2 "
70 decles="${decles}${line}${nl}"
82 def="${def%;$comment}"
85 decles="${decles}${decnl}extern${def};${comment}${nl}"
92 # Ignore those with arguments
93 [ "$2" = "${2##*$openparen}" ] || continue
94 # and multiline definitions
95 [ "$line" = "${line%$backslash}" ] || continue
96 defines="${defines}#undef $2${nl}${line}${nl}"
102 ev="${nl} /* from $src: */${nl} {${nl}"
107 # The C program indented by an extra 6 chars using
108 # tabs then spaces. I need to compare the output :-(
114 indent=$(($indent + 8))
121 indent=$(($indent + 1))
124 [ -z "$line" -o "$line" != "${line###}" ] && indent=0
129 indent="$(($indent - 8))"
135 indent="$(($indent - 1))"
137 ev="${ev}${line}${nl}"
140 eval event_$event=\"\$event_$event\$ev\"
147 echo " * This file was generated by the mkinit program."
152 for f in $includes; do
165 echo " * Initialization code."
170 echo "${event_init%$nl}"
176 echo " * This routine is called when an error or an interrupt occurs in an"
177 echo " * interactive shell and control is returned to the main command loop."
182 echo "${event_reset%$nl}"
188 echo " * This routine is called to initialize the shell to run a shell procedure."
192 echo "initshellproc() {"
193 echo "${event_shellproc%$nl}"