123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- /*
- * Copyright (C) 2008 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.
- */
- #ifndef ANDROID_XML_H
- #define ANDROID_XML_H
- #include <stdint.h>
- extern uint32_t g_lineno;
- /**
- * Header that appears at the front of every data chunk in a resource.
- */
- struct ResChunk_header
- {
- // Type identifier for this chunk. The meaning of this value depends
- // on the containing chunk.
- uint16_t type;
- // Size of the chunk header (in bytes). Adding this value to
- // the address of the chunk allows you to find its associated data
- // (if any).
- uint16_t headerSize;
- // Total size of this chunk (in bytes). This is the chunkSize plus
- // the size of any data associated with the chunk. Adding this value
- // to the chunk allows you to completely skip its contents (including
- // any child chunks). If this value is the same as chunkSize, there is
- // no data associated with the chunk.
- uint32_t size;
- };
- enum {
- RES_NULL_TYPE = 0x0000,
- RES_STRING_POOL_TYPE = 0x0001,
- RES_TABLE_TYPE = 0x0002,
- RES_XML_TYPE = 0x0003,
- // Chunk types in RES_XML_TYPE
- RES_XML_FIRST_CHUNK_TYPE = 0x0100,
- RES_XML_START_NAMESPACE_TYPE= 0x0100,
- RES_XML_END_NAMESPACE_TYPE = 0x0101,
- RES_XML_START_ELEMENT_TYPE = 0x0102,
- RES_XML_END_ELEMENT_TYPE = 0x0103,
- RES_XML_CDATA_TYPE = 0x0104,
- RES_XML_LAST_CHUNK_TYPE = 0x017f,
- // This contains a uint32_t array mapping strings in the string
- // pool back to resource identifiers. It is optional.
- RES_XML_RESOURCE_MAP_TYPE = 0x0180,
- // Chunk types in RES_TABLE_TYPE
- RES_TABLE_PACKAGE_TYPE = 0x0200,
- RES_TABLE_TYPE_TYPE = 0x0201,
- RES_TABLE_TYPE_SPEC_TYPE = 0x0202,
- RES_TABLE_LIBRARY_TYPE = 0x0203
- };
- /**
- * Definition for a pool of strings. The data of this chunk is an
- * array of uint32_t providing indices into the pool, relative to
- * stringsStart. At stringsStart are all of the UTF-16 strings
- * concatenated together; each starts with a uint16_t of the string's
- * length and each ends with a 0x0000 terminator. If a string is >
- * 32767 characters, the high bit of the length is set meaning to take
- * those 15 bits as a high word and it will be followed by another
- * uint16_t containing the low word.
- *
- * If styleCount is not zero, then immediately following the array of
- * uint32_t indices into the string table is another array of indices
- * into a style table starting at stylesStart. Each entry in the
- * style table is an array of ResStringPool_span structures.
- */
- struct ResStringPool_header
- {
- struct ResChunk_header header;
- // Number of strings in this pool (number of uint32_t indices that follow
- // in the data).
- uint32_t stringCount;
- // Number of style span arrays in the pool (number of uint32_t indices
- // follow the string indices).
- uint32_t styleCount;
- // Flags.
- enum {
- // If set, the string index is sorted by the string values (based
- // on strcmp16()).
- SORTED_FLAG = 1<<0,
- // String pool is encoded in UTF-8
- UTF8_FLAG = 1<<8
- };
- uint32_t flags;
- // Index from header of the string data.
- uint32_t stringsStart;
- // Index from header of the style data.
- uint32_t stylesStart;
- };
- /**
- * Reference to a string in a string pool.
- */
- struct ResStringPool_ref
- {
- // Index into the string pool table (uint32_t-offset from the indices
- // immediately after ResStringPool_header) at which to find the location
- // of the string data in the pool.
- uint32_t index;
- };
- /**
- * Extended XML tree node for element start/end nodes.
- * Appears header.headerSize bytes after a ResXMLTree_node.
- */
- struct ResXMLTree_endElementExt
- {
- // String of the full namespace of this element.
- struct ResStringPool_ref ns;
-
- // String name of this node if it is an ELEMENT; the raw
- // character data if this is a CDATA node.
- struct ResStringPool_ref name;
- };
- /**
- * Basic XML tree node. A single item in the XML document. Extended info
- * about the node can be found after header.headerSize.
- */
- struct ResXMLTree_node
- {
- struct ResChunk_header header;
- // Line number in original source file at which this element appeared.
- uint32_t lineNumber;
- // Optional XML comment that was associated with this element; -1 if none.
- struct ResStringPool_ref comment;
- };
- /**
- * Representation of a value in a resource, supplying type
- * information.
- */
- struct Res_value
- {
- // Number of bytes in this structure.
- uint16_t size;
- // Always set to 0.
- uint8_t res0;
-
- // Type of the data value.
- enum : uint8_t {
- // The 'data' is either 0 or 1, specifying this resource is either
- // undefined or empty, respectively.
- TYPE_NULL = 0x00,
- // The 'data' holds a ResTable_ref, a reference to another resource
- // table entry.
- TYPE_REFERENCE = 0x01,
- // The 'data' holds an attribute resource identifier.
- TYPE_ATTRIBUTE = 0x02,
- // The 'data' holds an index into the containing resource table's
- // global value string pool.
- TYPE_STRING = 0x03,
- // The 'data' holds a single-precision floating point number.
- TYPE_FLOAT = 0x04,
- // The 'data' holds a complex number encoding a dimension value,
- // such as "100in".
- TYPE_DIMENSION = 0x05,
- // The 'data' holds a complex number encoding a fraction of a
- // container.
- TYPE_FRACTION = 0x06,
- // The 'data' holds a dynamic ResTable_ref, which needs to be
- // resolved before it can be used like a TYPE_REFERENCE.
- TYPE_DYNAMIC_REFERENCE = 0x07,
- // The 'data' holds an attribute resource identifier, which needs to be resolved
- // before it can be used like a TYPE_ATTRIBUTE.
- TYPE_DYNAMIC_ATTRIBUTE = 0x08,
- // Beginning of integer flavors...
- TYPE_FIRST_INT = 0x10,
- // The 'data' is a raw integer value of the form n..n.
- TYPE_INT_DEC = 0x10,
- // The 'data' is a raw integer value of the form 0xn..n.
- TYPE_INT_HEX = 0x11,
- // The 'data' is either 0 or 1, for input "false" or "true" respectively.
- TYPE_INT_BOOLEAN = 0x12,
- // Beginning of color integer flavors...
- TYPE_FIRST_COLOR_INT = 0x1c,
- // The 'data' is a raw integer value of the form #aarrggbb.
- TYPE_INT_COLOR_ARGB8 = 0x1c,
- // The 'data' is a raw integer value of the form #rrggbb.
- TYPE_INT_COLOR_RGB8 = 0x1d,
- // The 'data' is a raw integer value of the form #argb.
- TYPE_INT_COLOR_ARGB4 = 0x1e,
- // The 'data' is a raw integer value of the form #rgb.
- TYPE_INT_COLOR_RGB4 = 0x1f,
- // ...end of integer flavors.
- TYPE_LAST_COLOR_INT = 0x1f,
- // ...end of integer flavors.
- TYPE_LAST_INT = 0x1f
- };
- uint8_t dataType;
- // Structure of complex data values (TYPE_UNIT and TYPE_FRACTION)
- enum {
- // Where the unit type information is. This gives us 16 possible
- // types, as defined below.
- COMPLEX_UNIT_SHIFT = 0,
- COMPLEX_UNIT_MASK = 0xf,
- // TYPE_DIMENSION: Value is raw pixels.
- COMPLEX_UNIT_PX = 0,
- // TYPE_DIMENSION: Value is Device Independent Pixels.
- COMPLEX_UNIT_DIP = 1,
- // TYPE_DIMENSION: Value is a Scaled device independent Pixels.
- COMPLEX_UNIT_SP = 2,
- // TYPE_DIMENSION: Value is in points.
- COMPLEX_UNIT_PT = 3,
- // TYPE_DIMENSION: Value is in inches.
- COMPLEX_UNIT_IN = 4,
- // TYPE_DIMENSION: Value is in millimeters.
- COMPLEX_UNIT_MM = 5,
- // TYPE_FRACTION: A basic fraction of the overall size.
- COMPLEX_UNIT_FRACTION = 0,
- // TYPE_FRACTION: A fraction of the parent size.
- COMPLEX_UNIT_FRACTION_PARENT = 1,
- // Where the radix information is, telling where the decimal place
- // appears in the mantissa. This give us 4 possible fixed point
- // representations as defined below.
- COMPLEX_RADIX_SHIFT = 4,
- COMPLEX_RADIX_MASK = 0x3,
- // The mantissa is an integral number -- i.e., 0xnnnnnn.0
- COMPLEX_RADIX_23p0 = 0,
- // The mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn
- COMPLEX_RADIX_16p7 = 1,
- // The mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn
- COMPLEX_RADIX_8p15 = 2,
- // The mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn
- COMPLEX_RADIX_0p23 = 3,
- // Where the actual value is. This gives us 23 bits of
- // precision. The top bit is the sign.
- COMPLEX_MANTISSA_SHIFT = 8,
- COMPLEX_MANTISSA_MASK = 0xffffff
- };
- // Possible data values for TYPE_NULL.
- enum {
- // The value is not defined.
- DATA_NULL_UNDEFINED = 0,
- // The value is explicitly defined as empty.
- DATA_NULL_EMPTY = 1
- };
- // The data for this item, as interpreted according to dataType.
- typedef uint32_t data_type;
- data_type data;
- void copyFrom_dtoh(const Res_value& src);
- };
- /**
- * Extended XML tree node for start tags -- includes attribute
- * information.
- * Appears header.headerSize bytes after a ResXMLTree_node.
- */
- struct ResXMLTree_attrExt
- {
- // String of the full namespace of this element.
- struct ResStringPool_ref ns;
-
- // String name of this node if it is an ELEMENT; the raw
- // character data if this is a CDATA node.
- struct ResStringPool_ref name;
-
- // Byte offset from the start of this structure where the attributes start.
- uint16_t attributeStart;
-
- // Size of the ResXMLTree_attribute structures that follow.
- uint16_t attributeSize;
-
- // Number of attributes associated with an ELEMENT. These are
- // available as an array of ResXMLTree_attribute structures
- // immediately following this node.
- uint16_t attributeCount;
-
- // Index (1-based) of the "id" attribute. 0 if none.
- uint16_t idIndex;
-
- // Index (1-based) of the "class" attribute. 0 if none.
- uint16_t classIndex;
-
- // Index (1-based) of the "style" attribute. 0 if none.
- uint16_t styleIndex;
- };
- struct ResXMLTree_attribute
- {
- // Namespace of this attribute.
- struct ResStringPool_ref ns;
-
- // Name of this attribute.
- struct ResStringPool_ref name;
- // The original raw string value of this attribute.
- struct ResStringPool_ref rawValue;
-
- // Processesd typed value of this attribute.
- struct Res_value typedValue;
- };
- /**
- * Extended XML tree node for namespace start/end nodes.
- * Appears header.headerSize bytes after a ResXMLTree_node.
- */
- struct ResXMLTree_namespaceExt
- {
- // The prefix of the namespace.
- struct ResStringPool_ref prefix;
-
- // The URI of the namespace.
- struct ResStringPool_ref uri;
- };
- #endif
|