summaryrefslogtreecommitdiff
path: root/bin/ACE-casts-convert
blob: 0b158ea1afa1db3ba7f5076b624d1849554eb8dd (plain)
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
#! /bin/sh

# =============================================================================
#
#  @file  ACE-casts-convert
#
#  $Id$
#
#  Script to convert all ACE cast macro calls (e.g.
#  ACE_static_cast (foo, bar)) to their standard C++ counterparts (e.g.
#  static_cast<foo> (bar)).
#
#  Use this script at your own risk.  It appears to work correctly for
#  most cases, but verify the results "just in case".
#
#  @note Wildcards may be supplied as the "FILE" arguments to this
#        script since the shell should expand the wildcards before
#        executing the script.
#
#  @bug The sed program used in this script may loop indefinitely on
#       ACE casts with arguments split across multiple lines
#       containing patterns it doesn't recognize.
#
#  @author Ossama Othman
#
# =============================================================================


if test "$#" -eq 0; then
  echo "Usage: $0 FILE [FILE2] ..."
  echo ""
  exit 1
fi

echo ""
echo "Converting ACE cast macro calls to standard C++ syntax in:"

while test "$#" -gt 0
do
  arg="$1"
  shift

  if grep "ACE_\(static\|dynamic\|const\|reinterpret\)_cast" $arg > /dev/null 2>&1; then
    echo "  $arg"
   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' \
       -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' \
       -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
    mv ${arg}.new $arg
  fi
done