File: enums.sh

package info (click to toggle)
adesklets 0.6.1-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,044 kB
  • ctags: 1,325
  • sloc: ansic: 5,939; sh: 3,983; python: 2,344; perl: 333; makefile: 211; yacc: 80; lex: 42
file content (64 lines) | stat: -rwxr-xr-x 2,692 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /bin/ash 
#
# enums.sh
#
#-------------------------------------------------------------------------------
# Copyright (C) 2004, 2005, 2006 Sylvain Fourmanoit <syfou@users.sourceforge.net>
#  
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#  
# The above copyright notice and this permission notice shall be included in
# all copies of the Software and its documentation and acknowledgment shall be
# given in the documentation and software packages that this Software was
# used.
#  
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
#
#-------------------------------------------------------------------------------
# Script used as a base to generate components of enums, 
# as cited in prototypes.sh
#
# Output is a tab-separated two columns of the form:
# 
# item_name	value 
#
# Note: Although this _should_ be portable across UNIXes, 
# it has not been tested (successfully, of course) on anything but:
#
#       - GNU Bourne-Again Shell (GNU bash) 3.00.0 and
#         NetBSD Bourne Shell (ash) 1.6.0
#
# Please also note it will not likely work without GNU sed
# (tested on GNU Streaming EDitor - GNU sed - 4.0.9 ), since
# it makes use of many GNU extensions (characters classes, \U, etc).
#
# Finally, you will need bc (any version: very basic use) to run this
# since we do not use shell arithmetic.
#
#-------------------------------------------------------------------------------
sed -n '/\/\* begin enums \*\//,/\/\* end enums \*\//p' ../src/command.c | \
(
while read LINE; do
    NEW_PREFIX=`echo "$LINE" | \
	sed -n '/\/\* prefix / s/^.*\/\* prefix \([[:alnum:]]\+\) \*\/.*$/\1/p'`
    test "x$NEW_PREFIX" != "x" && { PREFIX=$NEW_PREFIX ; I=0; }
    ITEM=`echo "$LINE" | sed -n 's/^[[:space:]]*"\([[:alnum:]_]\+\)".*/\U\1/p'`
    test "x$ITEM" != "x" && {
	echo $ITEM | sed '/^'"$PREFIX"'/!s/^/'"$PREFIX"'_/;s/$/\t'"$I"'/'
	I=`echo "$I + 1" | bc`
    }
done
)

exit 0