OSDN Git Service

Add script to change data types to native C types
authorAndre Eisenbach <eisenbach@google.com>
Wed, 30 Dec 2015 01:49:01 +0000 (17:49 -0800)
committerAndre Eisenbach <eisenbach@google.com>
Thu, 7 Jan 2016 22:20:40 +0000 (22:20 +0000)
Please see source code for usage information and application.

Bug: 22948224
Change-Id: Ia2dbd618ddcdf13abf3c63d4649147f400e00cfe

tools/scripts/change_types.sh [new file with mode: 0755]

diff --git a/tools/scripts/change_types.sh b/tools/scripts/change_types.sh
new file mode 100755 (executable)
index 0000000..f9b7009
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+# This script will recursively search all |FILES| from the current
+# directory and replace all |TYPES| according to the list below.
+
+# NOTE 1:
+# If this script is run from .../system/bt (as it's intended to be),
+# please edit stack/include/bt_types.h next and remove the typedef's
+# near the top and restore the definitions of TRUE and FALSE. These
+# are still used in the vnd_* files and device specific repositories.
+
+# NOTE 2:
+# The list of files to be modified also includes "*.patch", which means
+# this script can be used to help cherry-picking changes from older
+# branches. Follow this workflow outline:
+#  1. git format-patch [-1] <your sha1>
+#  2. Run change_type script on patch[es]
+#  3. git apply / git am
+
+
+# Regular expression matching the file name
+FILES="\.h$|\.c$|\.cpp$|\.cc$|\.patch$"
+
+# Search/replace terms, separated by ":"
+TYPES=(
+  "UINT8:uint8_t"
+  "UINT16:uint16_t"
+  "UINT32:uint32_t"
+  "UINT64:uint64_t"
+  "INT8:int8_t"
+  "INT16:int16_t"
+  "INT32:int32_t"
+  "INT64:int64_t"
+  "BOOLEAN:bool"
+  "TRUE:true"
+  "FALSE:false"
+  "__FUNCTION__:__func__"
+)
+
+function process_file
+{
+  echo -n "Processing file $1 "
+
+  for tt in "${TYPES[@]}" ;
+  do
+    before=${tt%%:*}
+    after=${tt#*:}
+
+    echo -n "."
+    sed -i -e "s/\b${before}\b/${after}/g" "$1"
+  done
+  echo
+}
+
+function process_files
+{
+  until [ -z "$1" ]
+  do
+    process_file "$1"
+    shift
+  done
+}
+
+
+# Let's do this ...
+process_files `find ./ | grep -E "${FILES}"`
+
+# All done ...
+echo
+echo "All done."
+
+# Try to be helpful ...
+PWD=`pwd`
+if [[ "${PWD}" == */system/bt ]]
+then
+  echo "Please edit ${PWD}/stack/include/bt_types.h next."
+fi