OSDN Git Service

Add two awk scripts that will be used by the ndk debugging helper scripts.
[android-x86/ndk.git] / build / core / extract-package-name.awk
1 # Copyright (C) 2010 The Android Open Source Project
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 # A nawk/gawk script used to extract the package name from an application's
16 # manifest (i.e. AndroidManifest.xml).
17 #
18 # The name itself is the value of the 'package' attribute in the
19 # 'manifest' element.
20 #
21
22 BEGIN {
23     FS=" "
24     in_manifest=0
25     package_regex1="package=\"([[:alnum:].]+)\""
26     package_regex2="package=\'([[:alnum:].]+)\'"
27     PACKAGE="<none>"
28 }
29
30 /<manifest/ {
31     in_manifest=1
32 }
33
34 in_manifest == 1 && /package=/ {
35     if (match($0,package_regex1)) {
36         PACKAGE=substr($0,RSTART+9,RLENGTH-10)
37     }
38     else if (match($0,package_regex2)) {
39         PACKAGE=substr($0,RSTART+9,RLENGTH-10)
40     }
41 }
42
43 in_manifest == 1 && />/ {
44     in_manifest=0
45 }
46
47 END {
48     print PACKAGE
49 }