Site update, preparation for adesklets 0.4.11.
[adesklets.git] / scripting / enums.sh
blob54e324d092964e2e29f6992b0e84a5aee6b871bd
1 #! /bin/ash
3 # enums.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 # Script used as a base to generate components of enums,
29 # as cited in prototypes.sh
31 # Output is a tab-separated two columns of the form:
33 # item_name value
35 # Note: Although this _should_ be portable across UNIXes,
36 # it has not been tested (successfully, of course) on anything but:
38 # - GNU Bourne-Again Shell (GNU bash) 3.00.0 and
39 # NetBSD Bourne Shell (ash) 1.6.0
41 # Please also note it will not likely work without GNU sed
42 # (tested on GNU Streaming EDitor - GNU sed - 4.0.9 ), since
43 # it makes use of many GNU extensions (characters classes, \U, etc).
45 # Finally, you will need bc (any version: very basic use) to run this
46 # since we do not use shell arithmetic.
48 #-------------------------------------------------------------------------------
49 sed -n '/\/\* begin enums \*\//,/\/\* end enums \*\//p' ../src/command.c | \
51 while read LINE; do
52 NEW_PREFIX=`echo "$LINE" | \
53 sed -n '/\/\* prefix / s/^.*\/\* prefix \([[:alnum:]]\+\) \*\/.*$/\1/p'`
54 test "x$NEW_PREFIX" != "x" && { PREFIX=$NEW_PREFIX ; I=0; }
55 ITEM=`echo "$LINE" | sed -n 's/^[[:space:]]*"\([[:alnum:]_]\+\)".*/\U\1/p'`
56 test "x$ITEM" != "x" && {
57 echo $ITEM | sed '/^'"$PREFIX"'/!s/^/'"$PREFIX"'_/;s/$/\t'"$I"'/'
58 I=`echo "$I + 1" | bc`
60 done
63 exit 0