Better support for option cleanup in python package
[adesklets.git] / src / command_enum.sh
blob3986a3473074c1f1ee5d867b984898dbc9f95998
1 #! /bin/sh
3 # command_enum.sh
5 #-------------------------------------------------------------------------------
6 # Copyright (C) 2004, 2005 Sylvain Fourmanoit <syfou@users.sourceforge.net>
7 #
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
9 # of this software and associated documentation files (the "Software"), to
10 # deal in the Software without restriction, including without limitation the
11 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 # sell copies of the Software, and to permit persons to whom the Software is
13 # furnished to do so, subject to the following conditions:
15 # The above copyright notice and this permission notice shall be included in
16 # all copies of the Software and its documentation and acknowledgment shall be
17 # given in the documentation and software packages that this Software was
18 # used.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 # THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #-------------------------------------------------------------------------------
28 # Quick and dirty but hopefully portable script to generate
29 # command list from const COMMAND COMMANDS[] in command.c
31 # Usage: command_enum.sh [--with-help]
33 # Note: Only tested with GNU sed 4.0.9. Will anyway probably only work
34 # with it, since we make use of many GNU extensions.
36 #-------------------------------------------------------------------------------
38 name_and_description () {
39 sed -n '/const COMMAND/,/NULL, NULL/p' command.c | \
40 sed '1d;$d' | \
41 sed 's/[^"]*"\([^"]\+\)"[^"]*/\1\n/g' | \
42 sed '/^$/d' | \
43 sed '/^[a-z]/{s/.*/CMD_\U&/;h;d};/^[A-Z]/{x;G;s/\n/\t/}'
46 if test "x$1" != "x--with-help" ; then
47 cat<<EOF
48 /* Automatically generated by `basename $0`
49 on `date` */
50 EOF
51 name_and_description | sed 's/\(.*\)\t.*/\1/;1s/$/=0/;s/$/,/'
52 echo "CMD_UNKNOWN"
53 else
54 name_and_description