File: asmdef.sh

package info (click to toggle)
allegro4.4 2:4.4.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 20,744 kB
  • sloc: ansic: 164,458; asm: 17,620; cpp: 3,848; objc: 1,687; sh: 1,107; python: 676; pascal: 179; makefile: 55; perl: 29; lisp: 1
file content (86 lines) | stat: -rwxr-xr-x 1,708 bytes parent folder | download | duplicates (7)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh

# This script, by Neil Townsend, is for cross-compilers to parse the `asmdef.s'
# file and generate `asmdef.inc'.
# Updated by Peter Wang.

# Parse command-line arguments
if [ $# != 2 ]; then
  echo "usage: $0 asmdef.s asmdef.inc"
  exit 1
fi
s_file=$1
inc_file=$2

# 1. Get the comments
grep "/\*" $s_file | cut -f 2 -d '"' | cut -f 1 -d \\ > $inc_file
echo >> $inc_file

# 2. Get the real stuff
list=`grep "\.long" $s_file | sed -e 's/.*\.long//'`
if [ -z "$list" ]; then
  list=`grep "\.word" $s_file | sed -e 's/.*\.word//'`
fi
if [ -z "$list" ]; then
  echo "$0: unable to parse assembly file $s_file"
  exit 1
fi

# `list' is now a list of label-value pairs, terminated by a "0" label.
#
#   LC0 0 LC1 0 LC2 42 ... LCn v ... 0 0

# Set the positional parameters to `list'.
set -- $list

# Keep looping until we reach the "0" label.
while [ $1 != "0" ]; do
    label=$1:
    value=$2
    shift 2

    # Get the string corresponding to the label.
    # Remove quote marks and NUL terminator.
    n=`awk /$label/,/ascii\|string/ $s_file |\
       grep 'ascii\|string' |\
       cut -f 2 -d '"' |\
       cut -f 1 -d '\\'`

    if [ -z "$n" ]; then
      echo "$0: unable to parse assembly file $s_file"
      exit 1
    fi

    # The string is one of:
    #
    #	##FOO
    #	#ifdef BAR
    #	#endif BAR
    #	BAZ 
    #	NEWLINE (literally)
    #
    case $n in
      '##'*)
        n=`echo $n | cut -b 3-`
	echo "#ifndef $n" >> $inc_file
	echo "#define $n" >> $inc_file
	echo "#endif" >> $inc_file
	echo >> $inc_file
	;;

      '#'*)
        echo $n >> $inc_file
	;;

      NEWLINE)
	echo >> $inc_file
	;;

      *)
	echo "#define $n $value" >> $inc_file
	;;
    esac
done

echo >> $inc_file