| 1 | #! /bin/sh |
| 2 | |
| 3 | # ============================================================================= |
| 4 | # |
| 5 | # @file ACE-casts-convert |
| 6 | # |
| 7 | # Script to convert all ACE cast macro calls (e.g. |
| 8 | # ACE_static_cast (foo, bar)) to their standard C++ counterparts (e.g. |
| 9 | # static_cast<foo> (bar)). |
| 10 | # |
| 11 | # Use this script at your own risk. It appears to work correctly for |
| 12 | # most cases, but verify the results "just in case". |
| 13 | # |
| 14 | # @note Wildcards may be supplied as the "FILE" arguments to this |
| 15 | # script since the shell should expand the wildcards before |
| 16 | # executing the script. |
| 17 | # |
| 18 | # @bug The sed program used in this script may loop indefinitely on |
| 19 | # ACE casts with arguments split across multiple lines |
| 20 | # containing patterns it doesn't recognize. |
| 21 | # |
| 22 | # @author Ossama Othman |
| 23 | # |
| 24 | # ============================================================================= |
| 25 | |
| 26 | |
| 27 | if test "$#" -eq 0; then |
| 28 | echo "Usage: $0 FILE [FILE2] ..." |
| 29 | echo "" |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | echo "" |
| 34 | echo "Converting ACE cast macro calls to standard C++ syntax in:" |
| 35 | |
| 36 | while test "$#" -gt 0 |
| 37 | do |
| 38 | arg="$1" |
| 39 | shift |
| 40 | |
| 41 | if grep "ACE_\(static\|dynamic\|const\|reinterpret\)_cast" $arg > /dev/null 2>&1; then |
| 42 | echo " $arg" |
| 43 | sed -e :a -e 's/ACE_\(const\|static\|reinterpret\|dynamic\)_cast[ \t]*([ \t]*\([^,]*\)[ \t]*,[ \t]*\([^ \t].*\)/\1_cast<\2> (\3/g; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast[ \t]*([ \t]*\([^,]*\)[ \t]*,[ \t]*$/{N;s/\n//;ba;}; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast[ \t]*([ \t]*$/{N;s/\n//;ba;}; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast[ \t]*$/{N;s/\n//;ba;}; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast[ \t]*(/ba' \ |
| 44 | -e :aa -e 's/ACE_\(const\|static\|reinterpret\|dynamic\)_cast_[1-5]_ref[ \t]*([ \t]*\([^,]*\)[ \t]*,\(.*\),[ \t]*\([^,]*\)/\1_cast<\2<\3> \&> (\4/g; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast_[1-5]_ref[ \t]*([ \t]*\([^,]*\)[ \t]*,[ \t]*$/{N;s/\n//;baa;}; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast_[1-5]_ref[ \t]*([ \t]*$/{N;s/\n//;baa;}; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast_[1-5]_ref[ \t]*$/{N;s/\n//;baa;}; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast_[1-5]_ref[ \t]*(/baa' \ |
| 45 | -e :aaa -e 's/ACE_\(const\|static\|reinterpret\|dynamic\)_cast_[1-5]_ptr[ \t]*([ \t]*\([^,]*\)[ \t]*,\(.*\),[ \t]*\([^,]*\)/\1_cast<\2<\3> \*> (\4/g; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast_[1-5]_ptr[ \t]*([ \t]*\([^,]*\)[ \t]*,[ \t]*$/{N;s/\n//;baaa;}; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast_[1-5]_ptr[ \t]*([ \t]*$/{N;s/\n//;baaa;}; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast_[1-5]_ptr[ \t]*$/{N;s/\n//;baaa;}; /ACE_\(const\|static\|reinterpret\|dynamic\)_cast_[1-5]_ptr[ \t]*(/baaa' $arg > ${arg}.new |
| 46 | mv ${arg}.new $arg |
| 47 | fi |
| 48 | done |