From: David 'Digit' Turner Date: Wed, 7 Apr 2010 01:14:38 +0000 (-0700) Subject: Add two awk scripts that will be used by the ndk debugging helper scripts. X-Git-Tag: android-x86-2.2~34 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=67c22255b157f1945d478b5cc44f603352b0d8b5;p=android-x86%2Fndk.git Add two awk scripts that will be used by the ndk debugging helper scripts. Change-Id: I9b1d6f39fd33f5b7cbc2e875a292f5901780ce26 --- diff --git a/build/core/extract-package-name.awk b/build/core/extract-package-name.awk new file mode 100644 index 0000000..6107ea7 --- /dev/null +++ b/build/core/extract-package-name.awk @@ -0,0 +1,49 @@ +# Copyright (C) 2010 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# A nawk/gawk script used to extract the package name from an application's +# manifest (i.e. AndroidManifest.xml). +# +# The name itself is the value of the 'package' attribute in the +# 'manifest' element. +# + +BEGIN { + FS=" " + in_manifest=0 + package_regex1="package=\"([[:alnum:].]+)\"" + package_regex2="package=\'([[:alnum:].]+)\'" + PACKAGE="" +} + +// { + in_manifest=0 +} + +END { + print PACKAGE +} diff --git a/build/core/extract-package-pid.awk b/build/core/extract-package-pid.awk new file mode 100644 index 0000000..5f5b523 --- /dev/null +++ b/build/core/extract-package-pid.awk @@ -0,0 +1,40 @@ +# Copyright (C) 2010 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Extract the pid of a given package name. This assumes that the +# input is the product of 'adb shell ps' and that the PACKAGE variable +# has been initialized to the package's name. In other words, this should +# be used as: +# +# adb shell ps | awk -f -v PACKAGE= +# +# The printed value will be 0 if the package is not found. +# + +BEGIN { + PID=0 + FS=" " +} + +# We use the fact that the 9th column of the 'ps' output +# contains the package name, while the 2nd one contains the pid +# +$9 == PACKAGE { + PID=$2 +} + +END { + print PID +}