Subversion Repositories HelenOS

Rev

Rev 3276 | Rev 3284 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3276 Rev 3283
1
#!/bin/sh
1
#!/bin/sh
2
# Copyright (C) 2008 Tim Post - All Rights Reserved
2
# Copyright (C) 2008 Tim Post - All Rights Reserved
3
# Redistribution and use in source and binary forms, with or without
3
# Redistribution and use in source and binary forms, with or without
4
# modification, are permitted provided that the following conditions are met:
4
# modification, are permitted provided that the following conditions are met:
5
#
5
#
6
# Redistributions of source code must retain the above copyright notice, this
6
# Redistributions of source code must retain the above copyright notice, this
7
# list of conditions and the following disclaimer.
7
# list of conditions and the following disclaimer.
8
#
8
#
9
# Redistributions in binary form must reproduce the above copyright notice,
9
# Redistributions in binary form must reproduce the above copyright notice,
10
# this list of conditions and the following disclaimer in the documentation
10
# this list of conditions and the following disclaimer in the documentation
11
# and/or other materials provided with the distribution.
11
# and/or other materials provided with the distribution.
12
#
12
#
13
# Neither the name of the original program's authors nor the names of its
13
# Neither the name of the original program's authors nor the names of its
14
# contributors may be used to endorse or promote products derived from this
14
# contributors may be used to endorse or promote products derived from this
15
# software without specific prior written permission.
15
# software without specific prior written permission.
16
#
16
#
17
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
27
# POSSIBILITY OF SUCH DAMAGE.
28
 
28
 
29
# Script to generate skeletal files for a new command
29
# Script to generate skeletal files for a new command
30
# Uses `getopt', not quite a bash-ism but might be
30
# Uses `getopt', not quite a bash-ism but might be
31
# lacking on some legacy systems.
31
# lacking on some legacy systems.
32
 
32
 
33
# If your shell does not support eval, shift (x) or
33
# If your shell does not support eval, shift (x) or
34
# here-now documents, sorry :) 
34
# here-now documents, sorry :) 
35
 
35
 
36
usage()
36
usage()
37
{
37
{
38
	def="$DEFAULT_COMMAND"
38
	def="$DEFAULT_COMMAND"
39
	cat << EOF
39
	cat << EOF
40
\`$PROGNAME' generates skeletal command files to simplify adding commands
40
\`$PROGNAME' generates skeletal command files to simplify adding commands
41
Usage: $PROGNAME [options] <location>
41
Usage: $PROGNAME [options] <location>
42
Options:
42
Options:
43
  -n, --name         Name of the command (default: ${def})
43
  -n, --name         Name of the command (default: ${def})
44
  -d, --desc         Short (20 30 chars) description of the command
44
  -d, --desc         Short (20 30 chars) description of the command
45
                     (def: "The $def command")
45
                     (def: "The $def command")
46
  -e, --entry        Entry function of the command (def: cmd_${def})
46
  -e, --entry        Entry function of the command (def: cmd_${def})
47
  -h, --help-entry   Entry function for command help (def: help_cmd_${def})
47
  -h, --help-entry   Entry function for command help (def: help_cmd_${def})
48
  -a, --alias        Alias (nickname) for this command (def: none)
48
  -a, --alias        Alias (nickname) for this command (def: none)
49
  -r, --restrict     Restriction level (interactive, non-interactive, both)
49
  -r, --restrict     Restriction level (interactive, non-interactive, both)
50
                     (def: module is both, builtin is interactive only)
50
                     (def: module is both, builtin is interactive only)
51
  -t, --type         Type of command (module or builtin) (def: module)
51
  -t, --type         Type of command (module or builtin) (def: module)
52
  -H, --help         This help summary
52
  -H, --help         This help summary
53
  -V, --version      Print $PROGNAME version and exit normally
53
  -V, --version      Print $PROGNAME version and exit normally
54
 
54
 
55
Notes:
55
Notes:
56
  You must supply at least the name of the command.
56
  You must supply at least the name of the command.
57
 
57
 
58
  If you do not specify a location (i.e. modules/foo), the command will be
58
  If you do not specify a location (i.e. modules/foo), the command will be
59
  created in modules/command_name or builtins/command_name depending on your
59
  created in modules/command_name or builtins/command_name depending on your
60
  selection.
60
  selection.
61
 
61
 
62
  This script will only create skeletal files and inform you what headers
62
  This script will only create skeletal files and inform you what headers
63
  need to be modified to incorporate the command. You will also have to
63
  need to be modified to incorporate the command. You will also have to
64
  manually update the main Makefile.
64
  manually update the main Makefile.
65
 
65
 
66
  This script is intended only to be a convenience for developers. Example use:
66
  This script is intended only to be a convenience for developers. Example use:
67
    $PROGNAME -n foo -d "Foo power" -a bar -r both -t module modules/foo
67
    $PROGNAME -n foo -d "Foo power" -a bar -r both -t module modules/foo
68
 
68
 
69
  The example would generate a modular command named 'foo', which is also
69
  The example would generate a modular command named 'foo', which is also
70
  reached by typing 'bar' and available in either interactive or noninteractive
70
  reached by typing 'bar' and available in either interactive or noninteractive
71
  mode.
71
  mode.
72
 
72
 
73
  Skeletal files do *not* depend on the autoconf generated "config.h" unless you
73
  Skeletal files do *not* depend on the autoconf generated "config.h" unless you
74
  include it. This may or may not be desirable depending on your use.
74
  include it. This may or may not be desirable depending on your use.
75
 
75
 
76
Report bugs to $PROGMAINT
76
Report bugs to $PROGMAINT
77
 
77
 
78
EOF
78
EOF
79
}
79
}
80
 
80
 
81
# Convert a string to all uppercase
81
# Convert a string to all uppercase
82
toupper()
82
toupper()
83
{
83
{
84
	local str="$1"
84
	local str="$1"
85
 
85
 
86
	echo "${str}" | tr 'a-z' 'A-Z'
86
	echo "${str}" | tr 'a-z' 'A-Z'
87
}
87
}
88
 
88
 
89
# Template stored `here-now' style, this generates all files needed
89
# Template stored `here-now' style, this generates all files needed
90
# for a new command according to arguments passed.
90
# for a new command according to arguments passed.
91
generate_code()
91
generate_code()
92
{
92
{
93
	echo "Creating ${OUTDIR}/${CMDNAME}.def ..."
93
	echo "Creating ${OUTDIR}/${CMDNAME}.def ..."
94
	cat << EOF > ${OUTDIR}/${CMDNAME}.def
94
	cat << EOF > ${OUTDIR}/${CMDNAME}.def
95
{
95
{
96
	"${CMDNAME}",
96
	"${CMDNAME}",
97
	"${CMDDESC}",
97
	"${CMDDESC}",
98
	&${CMDENTRY},
98
	&${CMDENTRY},
99
	&${HELPENTRY},
99
	&${HELPENTRY},
100
	${CMDRESTRICT}
100
	${CMDRESTRICT}
101
},
101
},
102
 
102
 
103
EOF
103
EOF
104
	[ -n "${CMDALIAS}" ] && cat << EOF >> ${OUTDIR}/${CMDNAME}.def
104
	[ -n "${CMDALIAS}" ] && cat << EOF >> ${OUTDIR}/${CMDNAME}.def
105
{
105
{
106
	"${CMDALIAS}",
106
	"${CMDALIAS}",
107
	NULL,
107
	NULL,
108
	&${CMDENTRY},
108
	&${CMDENTRY},
109
	&${HELPENTRY},
109
	&${HELPENTRY},
110
	${CMDRESTRICT}
110
	${CMDRESTRICT}
111
},
111
},
112
 
112
 
113
EOF
113
EOF
114
	local defname=$(toupper "${CMDNAME}")
114
	local defname=$(toupper "${CMDNAME}")
115
	echo "Creating ${OUTDIR}/entry.h ..."
115
	echo "Creating ${OUTDIR}/entry.h ..."
116
	cat << EOF > ${OUTDIR}/entry.h
116
	cat << EOF > ${OUTDIR}/entry.h
117
#ifndef ${defname}_ENTRY_H
117
#ifndef ${defname}_ENTRY_H
118
#define ${defname}_ENTRY_H
118
#define ${defname}_ENTRY_H
119
 
119
 
120
EOF
120
EOF
121
	[ "${CMDTYPE}" = "module" ] && cat << EOF >> ${OUTDIR}/entry.h
121
	[ "${CMDTYPE}" = "module" ] && cat << EOF >> ${OUTDIR}/entry.h
122
/* Entry points for the ${CMDNAME} command */
122
/* Entry points for the ${CMDNAME} command */
123
extern int * ${CMDENTRY}(char **);
123
extern int * ${CMDENTRY}(char **);
124
extern void * ${HELPENTRY}(unsigned int);
124
extern void * ${HELPENTRY}(unsigned int);
125
 
125
 
126
#endif /* ${defname}_ENTRY_H */
126
#endif /* ${defname}_ENTRY_H */
127
 
127
 
128
EOF
128
EOF
129
	[ "${CMDTYPE}" = "builtin" ] && cat << EOF >> ${OUTDIR}/entry.h
129
	[ "${CMDTYPE}" = "builtin" ] && cat << EOF >> ${OUTDIR}/entry.h
130
/* Pick up cliuser_t */
130
/* Pick up cliuser_t */
131
#include "scli.h"
131
#include "scli.h"
132
 
132
 
133
/* Entry points for the ${CMDNAME} command */
133
/* Entry points for the ${CMDNAME} command */
134
extern int * ${CMDENTRY}(char **, cliuser_t *);
134
extern int * ${CMDENTRY}(char **, cliuser_t *);
135
extern void * ${HELPENTRY}(unsigned int);
135
extern void * ${HELPENTRY}(unsigned int);
136
 
136
 
137
#endif /* ${defname}_ENTRY_H */
137
#endif /* ${defname}_ENTRY_H */
138
 
138
 
139
EOF
139
EOF
140
	echo "Creating ${OUTDIR}/${CMDNAME}.h ..."
140
	echo "Creating ${OUTDIR}/${CMDNAME}.h ..."
141
	cat << EOF > ${OUTDIR}/${CMDNAME}.h
141
	cat << EOF > ${OUTDIR}/${CMDNAME}.h
142
#ifndef ${defname}_H
142
#ifndef ${defname}_H
143
#define ${defname}_H
143
#define ${defname}_H
144
 
144
 
145
/* Prototypes for the ${CMDNAME} command, excluding entry points */
145
/* Prototypes for the ${CMDNAME} command, excluding entry points */
146
 
146
 
147
 
147
 
148
#endif /* ${defname}_H */
148
#endif /* ${defname}_H */
149
 
149
 
150
EOF
150
EOF
151
	echo "Creating ${OUTDIR}/${CMDNAME}.c ..."
151
	echo "Creating ${OUTDIR}/${CMDNAME}.c ..."
152
	cat << EOF > ${OUTDIR}/${CMDNAME}.c
152
	cat << EOF > ${OUTDIR}/${CMDNAME}.c
153
/* Automatically generated by ${PROGNAME} on ${TIMESTAMP}
153
/* Automatically generated by ${PROGNAME} on ${TIMESTAMP}
154
 * This is machine generated output. The author of ${PROGNAME} claims no
154
 * This is machine generated output. The author of ${PROGNAME} claims no
155
 * copyright over the contents of this file. Where legally permitted, the
155
 * copyright over the contents of this file. Where legally permitted, the
156
 * contents herein are donated to the public domain.
156
 * contents herein are donated to the public domain.
157
 *
157
 *
158
 * You should apply any license and copyright that you wish to this file,
158
 * You should apply any license and copyright that you wish to this file,
159
 * replacing this header in its entirety. */
159
 * replacing this header in its entirety. */
160
 
160
 
161
#include <stdio.h>
161
#include <stdio.h>
162
#include <stdlib.h>
162
#include <stdlib.h>
163
#include "entry.h"
163
#include "entry.h"
164
#include "${CMDNAME}.h"
164
#include "${CMDNAME}.h"
165
#include "cmds.h"
165
#include "cmds.h"
166
 
166
 
167
static char *cmdname = "${CMDNAME}";
167
static char *cmdname = "${CMDNAME}";
168
 
168
 
169
/* Dispays help for ${CMDNAME} in various levels */
169
/* Dispays help for ${CMDNAME} in various levels */
170
void * ${HELPENTRY}(unsigned int level)
170
void * ${HELPENTRY}(unsigned int level)
171
{
171
{
172
	printf("This is the %s help for '%s'.\n",
172
	printf("This is the %s help for '%s'.\n",
173
		level ? EXT_HELP : SHORT_HELP, cmdname);
173
		level ? EXT_HELP : SHORT_HELP, cmdname);
174
	return 0;
174
	return CMD_VOID;
175
}
175
}
176
 
176
 
177
EOF
177
EOF
178
	[ "${CMDTYPE}" = "module" ] && cat << EOF >> ${OUTDIR}/${CMDNAME}.c
178
	[ "${CMDTYPE}" = "module" ] && cat << EOF >> ${OUTDIR}/${CMDNAME}.c
179
/* Main entry point for ${CMDNAME}, accepts an array of arguments */
179
/* Main entry point for ${CMDNAME}, accepts an array of arguments */
180
int * ${CMDENTRY}(char **argv)
180
int * ${CMDENTRY}(char **argv)
181
EOF
181
EOF
182
	[ "${CMDTYPE}" = "builtin" ] && cat << EOF >> ${OUTDIR}/${CMDNAME}.c
182
	[ "${CMDTYPE}" = "builtin" ] && cat << EOF >> ${OUTDIR}/${CMDNAME}.c
183
/* Main entry point for ${CMDNAME}, accepts an array of arguments and a
183
/* Main entry point for ${CMDNAME}, accepts an array of arguments and a
184
 * pointer to the cliuser_t structure */
184
 * pointer to the cliuser_t structure */
185
int * ${CMDENTRY}(char **argv, cliuser_t *usr)
185
int * ${CMDENTRY}(char **argv, cliuser_t *usr)
186
EOF
186
EOF
187
	cat << EOF >> ${OUTDIR}/${CMDNAME}.c
187
	cat << EOF >> ${OUTDIR}/${CMDNAME}.c
188
{
188
{
189
	unsigned int argc;
189
	unsigned int argc;
190
	unsigned int i;
190
	unsigned int i;
191
 
191
 
192
	/* Count the arguments */
192
	/* Count the arguments */
193
	for (argc = 0; argv[argc] != NULL; argc ++);
193
	for (argc = 0; argv[argc] != NULL; argc ++);
194
 
194
 
195
	printf("%s %s\n", TEST_ANNOUNCE, cmdname);
195
	printf("%s %s\n", TEST_ANNOUNCE, cmdname);
196
	printf("%d arguments passed to %s", argc - 1, cmdname);
196
	printf("%d arguments passed to %s", argc - 1, cmdname);
197
 
197
 
198
	if (argc < 2) {
198
	if (argc < 2) {
199
		printf("\n");
199
		printf("\n");
200
		return 0;
200
		return CMD_SUCCESS;
201
	}
201
	}
202
 
202
 
203
	printf(":\n");
203
	printf(":\n");
204
	for (i = 1; i < argc; i++)
204
	for (i = 1; i < argc; i++)
205
		printf("[%d] -> %s\n", i, argv[i]);
205
		printf("[%d] -> %s\n", i, argv[i]);
206
 
206
 
207
	return 0;
207
	return CMD_SUCCESS;
208
}
208
}
209
 
209
 
210
EOF
210
EOF
211
	printf "Done.\n\nYou should now modify %ss/%ss.h and ../Makefile" \
211
	printf "Done.\n\nYou should now modify %ss/%ss.h and ../Makefile" \
212
		"${CMDTYPE}" "${CMDTYPE}"
212
		"${CMDTYPE}" "${CMDTYPE}"
213
	printf " to include your new command.\n"
213
	printf " to include your new command.\n"
214
	[ -n "$CMDALIAS" ] &&  {
214
	[ -n "$CMDALIAS" ] &&  {
215
		printf "\nYou should also modify %ss/%s_aliases.h and " \
215
		printf "\nYou should also modify %ss/%s_aliases.h and " \
216
			"${CMDTYPE}" "${CMDTYPE}"
216
			"${CMDTYPE}" "${CMDTYPE}"
217
		printf "add %s as an alias for %s\n" \
217
		printf "add %s as an alias for %s\n" \
218
			"${CMDALIAS}" "${CMDNAME}"
218
			"${CMDALIAS}" "${CMDNAME}"
219
	}
219
	}
220
	printf "\nOnce completed, re-run make\n\n"
220
	printf "\nOnce completed, re-run make\n\n"
221
}
221
}
222
 
222
 
223
# Main program
223
# Main program
224
 
224
 
225
TIMESTAMP="$(date)"
225
TIMESTAMP="$(date)"
226
PROGNAME=$(basename $0)
226
PROGNAME=$(basename $0)
227
PROGVER="0.0.1"
227
PROGVER="0.0.1"
228
PROGMAINT="Tim Post <echo@echoreply.us>"
228
PROGMAINT="Tim Post <echo@echoreply.us>"
229
DEFAULT_COMMAND="cmdname"
229
DEFAULT_COMMAND="cmdname"
230
 
230
 
231
# We need at least one
231
# We need at least one
232
[ $# = 0 ] && usage && exit 1;
232
[ $# = 0 ] && usage && exit 1;
233
 
233
 
234
TEMP=$(getopt -o n:d:e:h:a:r:t:HV \
234
TEMP=$(getopt -o n:d:e:h:a:r:t:HV \
235
--long name:,desc:,entry:,help-entry:,alias:,restrict:,type:,help,version \
235
--long name:,desc:,entry:,help-entry:,alias:,restrict:,type:,help,version \
236
-- "$@") || {
236
-- "$@") || {
237
	echo "Try $PROGNAME --help for help"
237
	echo "Try $PROGNAME --help for help"
238
}
238
}
239
 
239
 
240
eval set -- "$TEMP"
240
eval set -- "$TEMP"
241
 
241
 
242
while true; do
242
while true; do
243
	case "$1" in
243
	case "$1" in
244
	-n | --name)
244
	-n | --name)
245
		CMDNAME="$2"
245
		CMDNAME="$2"
246
		shift 2
246
		shift 2
247
		continue
247
		continue
248
	;;
248
	;;
249
	-d | --desc)
249
	-d | --desc)
250
		CMDDESC="$2"
250
		CMDDESC="$2"
251
		shift 2
251
		shift 2
252
		continue
252
		continue
253
	;;
253
	;;
254
	-e | --entry)
254
	-e | --entry)
255
		CMDENTRY="$2"
255
		CMDENTRY="$2"
256
		shift 2
256
		shift 2
257
		continue
257
		continue
258
	;;
258
	;;
259
	-h | --help-entry)
259
	-h | --help-entry)
260
		HELPENTRY="$2"
260
		HELPENTRY="$2"
261
		shift 2
261
		shift 2
262
		continue
262
		continue
263
	;;
263
	;;
264
	-a | --alias)
264
	-a | --alias)
265
		CMDALIAS="$2"
265
		CMDALIAS="$2"
266
		shift 2
266
		shift 2
267
		continue
267
		continue
268
	;;
268
	;;
269
	-r | --restrict)
269
	-r | --restrict)
270
		CMDRESTRICT="$2"
270
		CMDRESTRICT="$2"
271
		shift 2
271
		shift 2
272
		continue
272
		continue
273
	;;
273
	;;
274
	-t | --type)
274
	-t | --type)
275
		CMDTYPE="$2"
275
		CMDTYPE="$2"
276
		shift 2
276
		shift 2
277
		continue
277
		continue
278
	;;
278
	;;
279
	-H | --help)
279
	-H | --help)
280
		usage
280
		usage
281
		exit 0
281
		exit 0
282
	;;
282
	;;
283
	-V | --version)
283
	-V | --version)
284
		echo "$PROGVER"
284
		echo "$PROGVER"
285
		exit 0
285
		exit 0
286
	;;
286
	;;
287
	--)
287
	--)
288
		break
288
		break
289
	;;
289
	;;
290
	esac
290
	esac
291
done
291
done
292
 
292
 
293
# Pick up a location if one was specified
293
# Pick up a location if one was specified
294
eval set -- "$*"
294
eval set -- "$*"
295
[ -n "$2" ] && OUTDIR="$2"
295
[ -n "$2" ] && OUTDIR="$2"
296
 
296
 
297
# Fill in defaults for whatever was not specified
297
# Fill in defaults for whatever was not specified
298
[ -n "$CMDNAME" ] || CMDNAME="$DEFAULT_COMMAND"
298
[ -n "$CMDNAME" ] || CMDNAME="$DEFAULT_COMMAND"
299
[ -n "$CMDDESC" ] || CMDDESC="The $CMDNAME command"
299
[ -n "$CMDDESC" ] || CMDDESC="The $CMDNAME command"
300
[ -n "$CMDENTRY" ] || CMDENTRY="cmd_${CMDNAME}"
300
[ -n "$CMDENTRY" ] || CMDENTRY="cmd_${CMDNAME}"
301
[ -n "$HELPENTRY" ] || HELPENTRY="help_cmd_${CMDNAME}"
301
[ -n "$HELPENTRY" ] || HELPENTRY="help_cmd_${CMDNAME}"
302
[ -n "$CMDTYPE" ] || CMDTYPE="module"
302
[ -n "$CMDTYPE" ] || CMDTYPE="module"
303
[ -n "$OUTDIR" ] || OUTDIR="${CMDTYPE}s/${CMDNAME}"
303
[ -n "$OUTDIR" ] || OUTDIR="${CMDTYPE}s/${CMDNAME}"
304
 
304
 
305
# Builtins typically only need to be available in interactive mode,
305
# Builtins typically only need to be available in interactive mode,
306
# set the default accordingly.
306
# set the default accordingly.
307
[ -n "$CMDRESTRICT" ] || {
307
[ -n "$CMDRESTRICT" ] || {
308
	[ "$CMDTYPE" = "module" ] && CMDRESTRICT="both"
308
	[ "$CMDTYPE" = "module" ] && CMDRESTRICT="both"
309
	[ "$CMDTYPE" = "builtin" ] && CMDRESTRICT="interactive"
309
	[ "$CMDTYPE" = "builtin" ] && CMDRESTRICT="interactive"
310
}
310
}
311
 
311
 
312
# Set the restriction level as the structure expects to see it
312
# Set the restriction level as the structure expects to see it
313
case "$CMDRESTRICT" in
313
case "$CMDRESTRICT" in
314
	0 | both)
314
	0 | both)
315
		CMDRESTRICT="0"
315
		CMDRESTRICT="0"
316
	;;
316
	;;
317
	1 | non-interactive)
317
	1 | non-interactive)
318
		CMDRESTRICT="1"
318
		CMDRESTRICT="1"
319
	;;
319
	;;
320
	-1 | interactive)
320
	-1 | interactive)
321
		CMDRESTRICT="-1"
321
		CMDRESTRICT="-1"
322
	;;
322
	;;
323
	*)
323
	*)
324
		usage
324
		usage
325
		exit 1
325
		exit 1
326
	;;
326
	;;
327
esac
327
esac
328
 
328
 
329
# Do a little sanity
329
# Do a little sanity
330
[ -d $OUTDIR ] && {
330
[ -d $OUTDIR ] && {
331
	echo "$OUTDIR already exists, remove it to proceed."
331
	echo "$OUTDIR already exists, remove it to proceed."
332
	exit 1
332
	exit 1
333
}
333
}
334
 
334
 
335
mkdir -p ${OUTDIR} >/dev/null 2>&1 || {
335
mkdir -p ${OUTDIR} >/dev/null 2>&1 || {
336
	echo "Could not create ${OUTDIR}, aborting!"
336
	echo "Could not create ${OUTDIR}, aborting!"
337
	exit 1
337
	exit 1
338
}
338
}
339
 
339
 
340
# Generate the files and inform on how to include them based on options
340
# Generate the files and inform on how to include them based on options
341
generate_code
341
generate_code
342
 
342
 
343
exit 0
343
exit 0
344
 
344
 
345
 
345