| 1 | |
| 2 |
|
| 3 | if test "$#" -lt 1 || test "$#" -gt 2
|
| 4 | then
|
| 5 | echo "Usage: extract-syscall-ranges.sh FILENAME [abiname_regex]"
|
| 6 | exit 1
|
| 7 | fi
|
| 8 |
|
| 9 | numbers_to_ranges()
|
| 10 | {
|
| 11 | if ! read number
|
| 12 | then
|
| 13 | printf '{}\n'
|
| 14 | return
|
| 15 | fi
|
| 16 | low="$number"
|
| 17 | high="$number"
|
| 18 | while true
|
| 19 | do
|
| 20 | if read number
|
| 21 | then
|
| 22 | if test "$number" -eq "$((high + 1))"
|
| 23 | then
|
| 24 | high="$number"
|
| 25 | else
|
| 26 | break
|
| 27 | fi
|
| 28 | else
|
| 29 | printf '{ {%d, %d} }\n' "$low" "$high"
|
| 30 | return
|
| 31 | fi
|
| 32 | done
|
| 33 | printf '{ {%d, %d}' "$low" "$high"
|
| 34 | low="$number"
|
| 35 | high="$number"
|
| 36 | while true
|
| 37 | do
|
| 38 | if read number
|
| 39 | then
|
| 40 | if test "$number" -eq "$((high + 1))"
|
| 41 | then
|
| 42 | high="$number"
|
| 43 | else
|
| 44 | printf ', {%d, %d}' "$low" "$high"
|
| 45 | low="$number"
|
| 46 | high="$number"
|
| 47 | fi
|
| 48 | else
|
| 49 | printf ', {%d, %d} }\n' "$low" "$high"
|
| 50 | return
|
| 51 | fi
|
| 52 | done
|
| 53 | }
|
| 54 |
|
| 55 | if test "$#" -eq 2
|
| 56 | then
|
| 57 | abi_regex="$2"
|
| 58 | getnumbers()
|
| 59 | {
|
| 60 | |
| 61 | sed -e '/^[[:space:]]*#/d ; /^[[:space:]]*$/d' |
|
| 62 | |
| 63 | grep -E "^[0-9]+[[:space:]]+(common|(${abi_regex}))[[:space:]]" |
|
| 64 | |
| 65 | sed -e 's/\([0-9]\+\).*/\1/g'
|
| 66 | }
|
| 67 | else
|
| 68 | getnumbers()
|
| 69 | {
|
| 70 | |
| 71 | sed -e '/^[[:space:]]*#/d ; /^[[:space:]]*$/d ; s/\([0-9]\+\).*/\1/g'
|
| 72 | }
|
| 73 | fi
|
| 74 |
|
| 75 | getnumbers < "$1" |
|
| 76 | sort -n |
|
| 77 | uniq | |
| 78 | numbers_to_ranges
|
| 79 |
|
| 80 |
|