Subversion Repositories HelenOS

Rev

Rev 3425 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3425 Rev 4377
Line 44... Line 44...
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)
-
 
50
                     (def: module is both, builtin is interactive only)
-
 
51
  -t, --type         Type of command (module or builtin) (def: module)
49
  -t, --type         Type of command (module or builtin) (def: module)
52
  -H, --help         This help summary
50
  -H, --help         This help summary
53
  -V, --version      Print $PROGNAME version and exit normally
51
  -V, --version      Print $PROGNAME version and exit normally
54
 
52
 
55
Notes:
53
Notes:
Line 65... Line 63...
65
 
63
 
66
  This script is intended only to be a convenience for developers. Example use:
64
  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
65
    $PROGNAME -n foo -d "Foo power" -a bar -r both -t module modules/foo
68
 
66
 
69
  The example would generate a modular command named 'foo', which is also
67
  The example would generate a modular command named 'foo', which is also
70
  reached by typing 'bar' and available in either interactive or noninteractive
68
  reached by typing 'bar'.
71
  mode.
-
 
72
 
69
 
73
  Skeletal files do *not* depend on the autoconf generated "config.h" unless you
70
  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.
71
  include it. This may or may not be desirable depending on your use.
75
 
72
 
76
Report bugs to $PROGMAINT
73
Report bugs to $PROGMAINT
Line 95... Line 92...
95
{
92
{
96
	"${CMDNAME}",
93
	"${CMDNAME}",
97
	"${CMDDESC}",
94
	"${CMDDESC}",
98
	&${CMDENTRY},
95
	&${CMDENTRY},
99
	&${HELPENTRY},
96
	&${HELPENTRY},
100
	${CMDRESTRICT}
-
 
101
},
97
},
102
 
98
 
103
EOF
99
EOF
104
	[ -n "${CMDALIAS}" ] && cat << EOF >> ${OUTDIR}/${CMDNAME}_def.h
100
	[ -n "${CMDALIAS}" ] && cat << EOF >> ${OUTDIR}/${CMDNAME}_def.h
105
{
101
{
106
	"${CMDALIAS}",
102
	"${CMDALIAS}",
107
	NULL,
103
	NULL,
108
	&${CMDENTRY},
104
	&${CMDENTRY},
109
	&${HELPENTRY},
105
	&${HELPENTRY},
110
	${CMDRESTRICT}
-
 
111
},
106
},
112
 
107
 
113
EOF
108
EOF
114
	local defname=$(toupper "${CMDNAME}")
109
	local defname=$(toupper "${CMDNAME}")
115
	echo "Creating ${OUTDIR}/entry.h ..."
110
	echo "Creating ${OUTDIR}/entry.h ..."
Line 165... Line 160...
165
#include "errors.h"
160
#include "errors.h"
166
#include "entry.h"
161
#include "entry.h"
167
#include "${CMDNAME}.h"
162
#include "${CMDNAME}.h"
168
#include "cmds.h"
163
#include "cmds.h"
169
 
164
 
170
static char *cmdname = "${CMDNAME}";
165
static const char *cmdname = "${CMDNAME}";
171
 
166
 
172
/* Dispays help for ${CMDNAME} in various levels */
167
/* Dispays help for ${CMDNAME} in various levels */
173
void ${HELPENTRY}(unsigned int level)
168
void ${HELPENTRY}(unsigned int level)
174
{
169
{
175
	printf("This is the %s help for '%s'.\n",
170
	printf("This is the %s help for '%s'.\n",
Line 232... Line 227...
232
DEFAULT_COMMAND="cmdname"
227
DEFAULT_COMMAND="cmdname"
233
 
228
 
234
# We need at least one
229
# We need at least one
235
[ $# = 0 ] && usage && exit 1;
230
[ $# = 0 ] && usage && exit 1;
236
 
231
 
237
TEMP=$(getopt -o n:d:e:h:a:r:t:HV \
232
TEMP=$(getopt -o n:d:e:h:a:t:HV \
238
--long name:,desc:,entry:,help-entry:,alias:,restrict:,type:,help,version \
233
--long name:,desc:,entry:,help-entry:,alias:,type:,help,version \
239
-- "$@") || {
234
-- "$@") || {
240
	echo "Try $PROGNAME --help for help"
235
	echo "Try $PROGNAME --help for help"
241
}
236
}
242
 
237
 
243
eval set -- "$TEMP"
238
eval set -- "$TEMP"
Line 267... Line 262...
267
	-a | --alias)
262
	-a | --alias)
268
		CMDALIAS="$2"
263
		CMDALIAS="$2"
269
		shift 2
264
		shift 2
270
		continue
265
		continue
271
	;;
266
	;;
272
	-r | --restrict)
-
 
273
		CMDRESTRICT="$2"
-
 
274
		shift 2
-
 
275
		continue
-
 
276
	;;
-
 
277
	-t | --type)
267
	-t | --type)
278
		CMDTYPE="$2"
268
		CMDTYPE="$2"
279
		shift 2
269
		shift 2
280
		continue
270
		continue
281
	;;
271
	;;
Line 303... Line 293...
303
[ -n "$CMDENTRY" ] || CMDENTRY="cmd_${CMDNAME}"
293
[ -n "$CMDENTRY" ] || CMDENTRY="cmd_${CMDNAME}"
304
[ -n "$HELPENTRY" ] || HELPENTRY="help_cmd_${CMDNAME}"
294
[ -n "$HELPENTRY" ] || HELPENTRY="help_cmd_${CMDNAME}"
305
[ -n "$CMDTYPE" ] || CMDTYPE="module"
295
[ -n "$CMDTYPE" ] || CMDTYPE="module"
306
[ -n "$OUTDIR" ] || OUTDIR="${CMDTYPE}s/${CMDNAME}"
296
[ -n "$OUTDIR" ] || OUTDIR="${CMDTYPE}s/${CMDNAME}"
307
 
297
 
308
# Builtins typically only need to be available in interactive mode,
-
 
309
# set the default accordingly.
-
 
310
[ -n "$CMDRESTRICT" ] || {
-
 
311
	[ "$CMDTYPE" = "module" ] && CMDRESTRICT="both"
-
 
312
	[ "$CMDTYPE" = "builtin" ] && CMDRESTRICT="interactive"
-
 
313
}
-
 
314
 
-
 
315
# Set the restriction level as the structure expects to see it
-
 
316
case "$CMDRESTRICT" in
-
 
317
	0 | both)
-
 
318
		CMDRESTRICT="0"
-
 
319
	;;
-
 
320
	1 | non-interactive)
-
 
321
		CMDRESTRICT="1"
-
 
322
	;;
-
 
323
	-1 | interactive)
-
 
324
		CMDRESTRICT="-1"
-
 
325
	;;
-
 
326
	*)
-
 
327
		usage
-
 
328
		exit 1
-
 
329
	;;
-
 
330
esac
-
 
331
 
298
 
332
# Do a little sanity
299
# Do a little sanity
333
[ -d $OUTDIR ] && {
300
[ -d $OUTDIR ] && {
334
	echo "$OUTDIR already exists, remove it to proceed."
301
	echo "$OUTDIR already exists, remove it to proceed."
335
	exit 1
302
	exit 1