2 * Copyright (c) 1999-2013 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * OSUnserializeXML.y created by rsulack on Tue Oct 12 1999
35 // parser for unserializing OSContainer objects serialized to XML
38 // bison -p OSUnserializeXML OSUnserializeXML.y
39 // head -50 OSUnserializeXML.y > OSUnserializeXML.cpp
40 // sed -e "s/#include <stdio.h>//" < OSUnserializeXML.tab.c >> OSUnserializeXML.cpp
42 // when changing code check in both OSUnserializeXML.y and OSUnserializeXML.cpp
48 // DO NOT EDIT OSUnserializeXML.cpp!
51 /* A Bison parser, made by GNU Bison 2.3. */
53 /* Skeleton implementation for Bison's Yacc-like parsers in C
55 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
56 Free Software Foundation, Inc.
58 This program is free software; you can redistribute it and/or modify
59 it under the terms of the GNU General Public License as published by
60 the Free Software Foundation; either version 2, or (at your option)
63 This program is distributed in the hope that it will be useful,
64 but WITHOUT ANY WARRANTY; without even the implied warranty of
65 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66 GNU General Public License for more details.
68 You should have received a copy of the GNU General Public License
69 along with this program; if not, write to the Free Software
70 Foundation, Inc., 51 Franklin Street, Fifth Floor,
71 Boston, MA 02110-1301, USA. */
73 /* As a special exception, you may create a larger work that contains
74 part or all of the Bison parser skeleton and distribute that work
75 under terms of your choice, so long as that work isn't itself a
76 parser generator using the skeleton or a modified version thereof
77 as a parser skeleton. Alternatively, if you modify or redistribute
78 the parser skeleton itself, you may (at your option) remove this
79 special exception, which will cause the skeleton and the resulting
80 Bison output files to be licensed under the GNU General Public
81 License without this special exception.
83 This special exception was added by the Free Software Foundation in
84 version 2.2 of Bison. */
86 /* C LALR(1) parser skeleton written by Richard Stallman, by
87 simplifying the original so-called "semantic" parser. */
89 /* All symbols defined below should begin with yy or YY, to avoid
90 infringing on user name space. This should be done even for local
91 variables, as they might otherwise be expanded by user macros.
92 There are some unavoidable exceptions within include files to
93 define necessary library symbols; they are noted "INFRINGES ON
94 USER NAME SPACE" below. */
96 /* Identify Bison output. */
100 #define YYBISON_VERSION "2.3"
103 #define YYSKELETON_NAME "yacc.c"
108 /* Using locations. */
109 #define YYLSP_NEEDED 0
111 /* Substitute the variable and function names. */
112 #define yyparse OSUnserializeXMLparse
113 #define yylex OSUnserializeXMLlex
114 #define yyerror OSUnserializeXMLerror
115 #define yylval OSUnserializeXMLlval
116 #define yychar OSUnserializeXMLchar
117 #define yydebug OSUnserializeXMLdebug
118 #define yynerrs OSUnserializeXMLnerrs
124 /* Put the tokens into the symbol table, so that GDB and other debuggers
143 #define DICTIONARY 261
149 #define SYNTAX_ERROR 267
154 /* Copy the first part of user declarations. */
155 #line 61 "OSUnserializeXML.y"
158 #include <libkern/c++/OSMetaClass.h>
159 #include <libkern/c++/OSContainers.h>
160 #include <libkern/c++/OSLib.h>
162 #define MAX_OBJECTS 65535
164 #define YYSTYPE object_t *
165 #define YYPARSE_PARAM state
166 #define YYLEX_PARAM (parser_state_t *)state
168 // this is the internal struct used to hold objects on parser stack
169 // it represents objects both before and after they have been created
170 typedef struct object
{
173 struct object
*elements
;
175 OSSymbol
*key
; // for dictionary
177 void *data
; // for data
178 char *string
; // for string & symbol
179 long long number
; // for number
183 // this code is reentrant, this structure contains all
184 // state information for the parsing of a single buffer
185 typedef struct parser_state
{
186 const char *parseBuffer
; // start of text to be parsed
187 int parseBufferIndex
; // current index into text
188 int lineNumber
; // current line number
189 object_t
*objects
; // internal objects in use
190 object_t
*freeObjects
; // internal objects that are free
191 OSDictionary
*tags
; // used to remember "ID" tags
192 OSString
**errorString
; // parse error with line
193 OSObject
*parsedObject
; // resultant object of parsed text
194 int parsedObjectCount
;
197 #define STATE ((parser_state_t *)state)
200 #define yyerror(s) OSUnserializeerror(STATE, (s))
201 static int OSUnserializeerror(parser_state_t
*state
, const char *s
);
203 static int yylex(YYSTYPE
*lvalp
, parser_state_t
*state
);
205 static object_t
*newObject(parser_state_t
*state
);
206 static void freeObject(parser_state_t
*state
, object_t
*o
);
207 static void rememberObject(parser_state_t
*state
, int tag
, OSObject
*o
);
208 static object_t
*retrieveObject(parser_state_t
*state
, int tag
);
209 static void cleanupObjects(parser_state_t
*state
);
211 static object_t
*buildDictionary(parser_state_t
*state
, object_t
*o
);
212 static object_t
*buildArray(parser_state_t
*state
, object_t
*o
);
213 static object_t
*buildSet(parser_state_t
*state
, object_t
*o
);
214 static object_t
*buildString(parser_state_t
*state
, object_t
*o
);
215 static object_t
*buildSymbol(parser_state_t
*state
, object_t
*o
);
216 static object_t
*buildData(parser_state_t
*state
, object_t
*o
);
217 static object_t
*buildNumber(parser_state_t
*state
, object_t
*o
);
218 static object_t
*buildBoolean(parser_state_t
*state
, object_t
*o
);
221 extern void *kern_os_malloc(size_t size
);
222 extern void *kern_os_realloc(void * addr
, size_t size
);
223 extern void kern_os_free(void * addr
);
227 #define malloc(s) kern_os_malloc(s)
228 #define realloc(a, s) kern_os_realloc(a, s)
229 #define free(a) kern_os_free((void *)a)
233 /* Enabling traces. */
238 /* Enabling verbose error messages. */
239 #ifdef YYERROR_VERBOSE
240 # undef YYERROR_VERBOSE
241 # define YYERROR_VERBOSE 1
243 # define YYERROR_VERBOSE 0
246 /* Enabling the token table. */
247 #ifndef YYTOKEN_TABLE
248 # define YYTOKEN_TABLE 0
251 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
253 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
254 # define YYSTYPE_IS_DECLARED 1
255 # define YYSTYPE_IS_TRIVIAL 1
260 /* Copy the second part of user declarations. */
263 /* Line 216 of yacc.c. */
264 #line 215 "OSUnserializeXML.tab.c"
271 typedef YYTYPE_UINT8 yytype_uint8
;
273 typedef unsigned char yytype_uint8
;
277 typedef YYTYPE_INT8 yytype_int8
;
278 #elif (defined __STDC__ || defined __C99__FUNC__ \
279 || defined __cplusplus || defined _MSC_VER)
280 typedef signed char yytype_int8
;
282 typedef short int yytype_int8
;
286 typedef YYTYPE_UINT16 yytype_uint16
;
288 typedef unsigned short int yytype_uint16
;
292 typedef YYTYPE_INT16 yytype_int16
;
294 typedef short int yytype_int16
;
298 # ifdef __SIZE_TYPE__
299 # define YYSIZE_T __SIZE_TYPE__
300 # elif defined size_t
301 # define YYSIZE_T size_t
302 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
303 || defined __cplusplus || defined _MSC_VER)
304 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
305 # define YYSIZE_T size_t
307 # define YYSIZE_T unsigned int
311 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
314 # if defined YYENABLE_NLS && YYENABLE_NLS
316 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
317 # define YY_(msgid) dgettext ("bison-runtime", msgid)
321 # define YY_(msgid) msgid
325 /* Suppress unused-variable warnings by "using" E. */
326 #if ! defined lint || defined __GNUC__
327 # define YYUSE(e) ((void) (e))
329 # define YYUSE(e) /* empty */
332 /* Identity function, used to suppress warnings about constant conditions. */
336 #if (defined __STDC__ || defined __C99__FUNC__ \
337 || defined __cplusplus || defined _MSC_VER)
350 #if ! defined yyoverflow || YYERROR_VERBOSE
352 /* The parser invokes alloca or malloc; define the necessary symbols. */
354 # ifdef YYSTACK_USE_ALLOCA
355 # if YYSTACK_USE_ALLOCA
357 # define YYSTACK_ALLOC __builtin_alloca
358 # elif defined __BUILTIN_VA_ARG_INCR
359 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
361 # define YYSTACK_ALLOC __alloca
362 # elif defined _MSC_VER
363 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
364 # define alloca _alloca
366 # define YYSTACK_ALLOC alloca
367 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
368 || defined __cplusplus || defined _MSC_VER)
369 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
378 # ifdef YYSTACK_ALLOC
379 /* Pacify GCC's `empty if-body' warning. */
380 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
381 # ifndef YYSTACK_ALLOC_MAXIMUM
382 /* The OS might guarantee only one guard page at the bottom of the stack,
383 and a page size can be as small as 4096 bytes. So we cannot safely
384 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
385 to allow for a few compiler-allocated temporary stack slots. */
386 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
389 # define YYSTACK_ALLOC YYMALLOC
390 # define YYSTACK_FREE YYFREE
391 # ifndef YYSTACK_ALLOC_MAXIMUM
392 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
394 # if (defined __cplusplus && ! defined _STDLIB_H \
395 && ! ((defined YYMALLOC || defined malloc) \
396 && (defined YYFREE || defined free)))
397 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
403 # define YYMALLOC malloc
404 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
405 || defined __cplusplus || defined _MSC_VER)
406 void *malloc (YYSIZE_T
); /* INFRINGES ON USER NAME SPACE */
411 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
412 || defined __cplusplus || defined _MSC_VER)
413 void free (void *); /* INFRINGES ON USER NAME SPACE */
417 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
420 #if (! defined yyoverflow \
421 && (! defined __cplusplus \
422 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
424 /* A type that is properly aligned for any stack member. */
431 /* The size of the maximum gap between one aligned stack and the next. */
432 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
434 /* The size of an array large to enough to hold all stacks, each with
436 # define YYSTACK_BYTES(N) \
437 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
438 + YYSTACK_GAP_MAXIMUM)
440 /* Copy COUNT objects from FROM to TO. The source and destination do
443 # if defined __GNUC__ && 1 < __GNUC__
444 # define YYCOPY(To, From, Count) \
445 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
447 # define YYCOPY(To, From, Count) \
451 for (yyi = 0; yyi < (Count); yyi++) \
452 (To)[yyi] = (From)[yyi]; \
458 /* Relocate STACK from its old location to the new one. The
459 local variables YYSIZE and YYSTACKSIZE give the old and new number of
460 elements in the stack, and YYPTR gives the new location of the
461 stack. Advance YYPTR to a properly aligned location for the next
463 # define YYSTACK_RELOCATE(Stack) \
466 YYSIZE_T yynewbytes; \
467 YYCOPY (&yyptr->Stack, Stack, yysize); \
468 Stack = &yyptr->Stack; \
469 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
470 yyptr += yynewbytes / sizeof (*yyptr); \
476 /* YYFINAL -- State number of the termination state. */
478 /* YYLAST -- Last index in YYTABLE. */
481 /* YYNTOKENS -- Number of terminals. */
483 /* YYNNTS -- Number of nonterminals. */
485 /* YYNRULES -- Number of rules. */
487 /* YYNRULES -- Number of states. */
490 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
492 #define YYMAXUTOK 267
494 #define YYTRANSLATE(YYX) \
495 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
497 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
498 static const yytype_uint8 yytranslate
[] =
500 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
501 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
502 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
503 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
504 15, 16, 2, 2, 2, 2, 2, 2, 2, 2,
505 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
506 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
507 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
508 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
509 2, 17, 2, 18, 2, 2, 2, 2, 2, 2,
510 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
511 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
512 2, 2, 2, 13, 2, 14, 2, 2, 2, 2,
513 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
514 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
515 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
516 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
517 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
518 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
519 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
520 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
521 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
522 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
523 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
524 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
525 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
526 5, 6, 7, 8, 9, 10, 11, 12
530 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
532 static const yytype_uint8 yyprhs
[] =
534 0, 0, 3, 4, 6, 8, 10, 12, 14, 16,
535 18, 20, 22, 24, 27, 31, 33, 35, 38, 41,
536 43, 46, 50, 52, 55, 59, 61, 63, 66, 68,
540 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
541 static const yytype_int8 yyrhs
[] =
543 20, 0, -1, -1, 21, -1, 12, -1, 22, -1,
544 26, -1, 27, -1, 33, -1, 30, -1, 32, -1,
545 29, -1, 31, -1, 13, 14, -1, 13, 23, 14,
546 -1, 6, -1, 24, -1, 23, 24, -1, 25, 21,
547 -1, 8, -1, 15, 16, -1, 15, 28, 16, -1,
548 3, -1, 17, 18, -1, 17, 28, 18, -1, 10,
549 -1, 21, -1, 28, 21, -1, 4, -1, 5, -1,
553 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
554 static const yytype_uint16 yyrline
[] =
556 0, 149, 149, 152, 157, 162, 170, 178, 186, 194,
557 202, 210, 218, 237, 240, 243, 246, 247, 262, 271,
558 283, 286, 289, 292, 295, 298, 301, 304, 311, 314,
563 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
564 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
565 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
566 static const char *const yytname
[] =
568 "$end", "error", "$undefined", "ARRAY", "BOOLEAN", "DATA", "DICTIONARY",
569 "IDREF", "KEY", "NUMBER", "SET", "STRING", "SYNTAX_ERROR", "'{'", "'}'",
570 "'('", "')'", "'['", "']'", "$accept", "input", "object", "dict",
571 "pairs", "pair", "key", "array", "set", "elements", "boolean", "data",
572 "idref", "number", "string", 0
577 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
579 static const yytype_uint16 yytoknum
[] =
581 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
582 265, 266, 267, 123, 125, 40, 41, 91, 93
586 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
587 static const yytype_uint8 yyr1
[] =
589 0, 19, 20, 20, 20, 21, 21, 21, 21, 21,
590 21, 21, 21, 22, 22, 22, 23, 23, 24, 25,
591 26, 26, 26, 27, 27, 27, 28, 28, 29, 30,
595 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
596 static const yytype_uint8 yyr2
[] =
598 0, 2, 0, 1, 1, 1, 1, 1, 1, 1,
599 1, 1, 1, 2, 3, 1, 1, 2, 2, 1,
600 2, 3, 1, 2, 3, 1, 1, 2, 1, 1,
604 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
605 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
606 means the default is an error. */
607 static const yytype_uint8 yydefact
[] =
609 2, 22, 28, 29, 15, 30, 31, 25, 32, 4,
610 0, 0, 0, 0, 3, 5, 6, 7, 11, 9,
611 12, 10, 8, 19, 13, 0, 16, 0, 20, 26,
612 0, 23, 0, 1, 14, 17, 18, 21, 27, 24
615 /* YYDEFGOTO[NTERM-NUM]. */
616 static const yytype_int8 yydefgoto
[] =
618 -1, 13, 29, 15, 25, 26, 27, 16, 17, 30,
622 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
624 #define YYPACT_NINF -20
625 static const yytype_int8 yypact
[] =
627 46, -20, -20, -20, -20, -20, -20, -20, -20, -20,
628 4, 61, -2, 10, -20, -20, -20, -20, -20, -20,
629 -20, -20, -20, -20, -20, 6, -20, 91, -20, -20,
630 76, -20, 30, -20, -20, -20, -20, -20, -20, -20
633 /* YYPGOTO[NTERM-NUM]. */
634 static const yytype_int8 yypgoto
[] =
636 -20, -20, 0, -20, -20, -19, -20, -20, -20, 5,
637 -20, -20, -20, -20, -20
640 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
641 positive, shift that token. If negative, reduce the rule which
642 number is the opposite. If zero, do what YYDEFACT says.
643 If YYTABLE_NINF, syntax error. */
644 #define YYTABLE_NINF -1
645 static const yytype_uint8 yytable
[] =
647 14, 1, 2, 3, 4, 5, 35, 6, 7, 8,
648 33, 10, 23, 11, 23, 12, 31, 32, 24, 0,
649 34, 0, 0, 0, 0, 0, 0, 36, 0, 0,
650 38, 0, 38, 1, 2, 3, 4, 5, 0, 6,
651 7, 8, 0, 10, 0, 11, 0, 12, 39, 1,
652 2, 3, 4, 5, 0, 6, 7, 8, 9, 10,
653 0, 11, 0, 12, 1, 2, 3, 4, 5, 0,
654 6, 7, 8, 0, 10, 0, 11, 28, 12, 1,
655 2, 3, 4, 5, 0, 6, 7, 8, 0, 10,
656 0, 11, 37, 12, 1, 2, 3, 4, 5, 0,
657 6, 7, 8, 0, 10, 0, 11, 0, 12
660 static const yytype_int8 yycheck
[] =
662 0, 3, 4, 5, 6, 7, 25, 9, 10, 11,
663 0, 13, 8, 15, 8, 17, 18, 12, 14, -1,
664 14, -1, -1, -1, -1, -1, -1, 27, -1, -1,
665 30, -1, 32, 3, 4, 5, 6, 7, -1, 9,
666 10, 11, -1, 13, -1, 15, -1, 17, 18, 3,
667 4, 5, 6, 7, -1, 9, 10, 11, 12, 13,
668 -1, 15, -1, 17, 3, 4, 5, 6, 7, -1,
669 9, 10, 11, -1, 13, -1, 15, 16, 17, 3,
670 4, 5, 6, 7, -1, 9, 10, 11, -1, 13,
671 -1, 15, 16, 17, 3, 4, 5, 6, 7, -1,
672 9, 10, 11, -1, 13, -1, 15, -1, 17
675 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
676 symbol of state STATE-NUM. */
677 static const yytype_uint8 yystos
[] =
679 0, 3, 4, 5, 6, 7, 9, 10, 11, 12,
680 13, 15, 17, 20, 21, 22, 26, 27, 29, 30,
681 31, 32, 33, 8, 14, 23, 24, 25, 16, 21,
682 28, 18, 28, 0, 14, 24, 21, 16, 21, 18
685 #define yyerrok (yyerrstatus = 0)
686 #define yyclearin (yychar = YYEMPTY)
690 #define YYACCEPT goto yyacceptlab
691 #define YYABORT goto yyabortlab
692 #define YYERROR goto yyerrorlab
695 /* Like YYERROR except do call yyerror. This remains here temporarily
696 to ease the transition to the new meaning of YYERROR, for GCC.
697 Once GCC version 2 has supplanted version 1, this can go. */
699 #define YYFAIL goto yyerrlab
701 #define YYRECOVERING() (!!yyerrstatus)
703 #define YYBACKUP(Token, Value) \
705 if (yychar == YYEMPTY && yylen == 1) \
709 yytoken = YYTRANSLATE (yychar); \
715 yyerror (YY_("syntax error: cannot back up")); \
722 #define YYERRCODE 256
725 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
726 If N is 0, then set CURRENT to the empty location which ends
727 the previous symbol: RHS[0] (always defined). */
729 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
730 #ifndef YYLLOC_DEFAULT
731 # define YYLLOC_DEFAULT(Current, Rhs, N) \
735 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
736 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
737 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
738 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
742 (Current).first_line = (Current).last_line = \
743 YYRHSLOC (Rhs, 0).last_line; \
744 (Current).first_column = (Current).last_column = \
745 YYRHSLOC (Rhs, 0).last_column; \
751 /* YY_LOCATION_PRINT -- Print the location on the stream.
752 This macro was not mandated originally: define only if we know
753 we won't break user code: when these are the locations we know. */
755 #ifndef YY_LOCATION_PRINT
756 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
757 # define YY_LOCATION_PRINT(File, Loc) \
758 fprintf (File, "%d.%d-%d.%d", \
759 (Loc).first_line, (Loc).first_column, \
760 (Loc).last_line, (Loc).last_column)
762 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
767 /* YYLEX -- calling `yylex' with the right arguments. */
770 # define YYLEX yylex (&yylval, YYLEX_PARAM)
772 # define YYLEX yylex (&yylval)
775 /* Enable debugging if requested. */
779 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
780 # define YYFPRINTF fprintf
783 # define YYDPRINTF(Args) \
789 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
793 YYFPRINTF (stderr, "%s ", Title); \
794 yy_symbol_print (stderr, \
796 YYFPRINTF (stderr, "\n"); \
801 /*--------------------------------.
802 | Print this symbol on YYOUTPUT. |
803 `--------------------------------*/
806 #if (defined __STDC__ || defined __C99__FUNC__ \
807 || defined __cplusplus || defined _MSC_VER)
809 yy_symbol_value_print (FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
)
812 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
)
815 YYSTYPE
const * const yyvaluep
;
821 if (yytype
< YYNTOKENS
)
822 YYPRINT (yyoutput
, yytoknum
[yytype
], *yyvaluep
);
834 /*--------------------------------.
835 | Print this symbol on YYOUTPUT. |
836 `--------------------------------*/
838 #if (defined __STDC__ || defined __C99__FUNC__ \
839 || defined __cplusplus || defined _MSC_VER)
841 yy_symbol_print (FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
)
844 yy_symbol_print (yyoutput
, yytype
, yyvaluep
)
847 YYSTYPE
const * const yyvaluep
;
850 if (yytype
< YYNTOKENS
)
851 YYFPRINTF (yyoutput
, "token %s (", yytname
[yytype
]);
853 YYFPRINTF (yyoutput
, "nterm %s (", yytname
[yytype
]);
855 yy_symbol_value_print (yyoutput
, yytype
, yyvaluep
);
856 YYFPRINTF (yyoutput
, ")");
859 /*------------------------------------------------------------------.
860 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
862 `------------------------------------------------------------------*/
864 #if (defined __STDC__ || defined __C99__FUNC__ \
865 || defined __cplusplus || defined _MSC_VER)
867 yy_stack_print (yytype_int16
*bottom
, yytype_int16
*top
)
870 yy_stack_print (bottom
, top
)
871 yytype_int16
*bottom
;
875 YYFPRINTF (stderr
, "Stack now");
876 for (; bottom
<= top
; ++bottom
)
877 YYFPRINTF (stderr
, " %d", *bottom
);
878 YYFPRINTF (stderr
, "\n");
881 # define YY_STACK_PRINT(Bottom, Top) \
884 yy_stack_print ((Bottom), (Top)); \
888 /*------------------------------------------------.
889 | Report that the YYRULE is going to be reduced. |
890 `------------------------------------------------*/
892 #if (defined __STDC__ || defined __C99__FUNC__ \
893 || defined __cplusplus || defined _MSC_VER)
895 yy_reduce_print (YYSTYPE
*yyvsp
, int yyrule
)
898 yy_reduce_print (yyvsp
, yyrule
)
903 int yynrhs
= yyr2
[yyrule
];
905 unsigned long int yylno
= yyrline
[yyrule
];
906 YYFPRINTF (stderr
, "Reducing stack by rule %d (line %lu):\n",
908 /* The symbols being reduced. */
909 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
911 fprintf (stderr
, " $%d = ", yyi
+ 1);
912 yy_symbol_print (stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
913 &(yyvsp
[(yyi
+ 1) - (yynrhs
)])
915 fprintf (stderr
, "\n");
919 # define YY_REDUCE_PRINT(Rule) \
922 yy_reduce_print (yyvsp, Rule); \
925 /* Nonzero means print parse trace. It is left uninitialized so that
926 multiple parsers can coexist. */
929 # define YYDPRINTF(Args)
930 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
931 # define YY_STACK_PRINT(Bottom, Top)
932 # define YY_REDUCE_PRINT(Rule)
933 #endif /* !YYDEBUG */
936 /* YYINITDEPTH -- initial size of the parser's stacks. */
938 # define YYINITDEPTH 200
941 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
942 if the built-in stack extension method is used).
944 Do not make this value too large; the results are undefined if
945 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
946 evaluated with infinite-precision integer arithmetic. */
949 # define YYMAXDEPTH 10000
957 # if defined __GLIBC__ && defined _STRING_H
958 # define yystrlen strlen
960 /* Return the length of YYSTR. */
961 #if (defined __STDC__ || defined __C99__FUNC__ \
962 || defined __cplusplus || defined _MSC_VER)
964 yystrlen (const char *yystr
)
972 for (yylen
= 0; yystr
[yylen
]; yylen
++)
980 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
981 # define yystpcpy stpcpy
983 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
985 #if (defined __STDC__ || defined __C99__FUNC__ \
986 || defined __cplusplus || defined _MSC_VER)
988 yystpcpy (char *yydest
, const char *yysrc
)
991 yystpcpy (yydest
, yysrc
)
997 const char *yys
= yysrc
;
999 while ((*yyd
++ = *yys
++) != '\0')
1008 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1009 quotes and backslashes, so that it's suitable for yyerror. The
1010 heuristic is that double-quoting is unnecessary unless the string
1011 contains an apostrophe, a comma, or backslash (other than
1012 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1013 null, do not copy; instead, return the length of what the result
1016 yytnamerr (char *yyres
, const char *yystr
)
1021 char const *yyp
= yystr
;
1028 goto do_not_strip_quotes
;
1032 goto do_not_strip_quotes
;
1045 do_not_strip_quotes
: ;
1049 return yystrlen (yystr
);
1051 return yystpcpy (yyres
, yystr
) - yyres
;
1055 /* Copy into YYRESULT an error message about the unexpected token
1056 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1057 including the terminating null byte. If YYRESULT is null, do not
1058 copy anything; just return the number of bytes that would be
1059 copied. As a special case, return 0 if an ordinary "syntax error"
1060 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1061 size calculation. */
1063 yysyntax_error (char *yyresult
, int yystate
, int yychar
)
1065 int yyn
= yypact
[yystate
];
1067 if (! (YYPACT_NINF
< yyn
&& yyn
<= YYLAST
))
1071 int yytype
= YYTRANSLATE (yychar
);
1072 YYSIZE_T yysize0
= yytnamerr (0, yytname
[yytype
]);
1073 YYSIZE_T yysize
= yysize0
;
1075 int yysize_overflow
= 0;
1076 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1077 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1081 /* This is so xgettext sees the translatable formats that are
1082 constructed on the fly. */
1083 YY_("syntax error, unexpected %s");
1084 YY_("syntax error, unexpected %s, expecting %s");
1085 YY_("syntax error, unexpected %s, expecting %s or %s");
1086 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1087 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1091 static char const yyunexpected
[] = "syntax error, unexpected %s";
1092 static char const yyexpecting
[] = ", expecting %s";
1093 static char const yyor
[] = " or %s";
1094 char yyformat
[sizeof yyunexpected
1095 + sizeof yyexpecting
- 1
1096 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1097 * (sizeof yyor
- 1))];
1098 char const *yyprefix
= yyexpecting
;
1100 /* Start YYX at -YYN if negative to avoid negative indexes in
1102 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1104 /* Stay within bounds of both yycheck and yytname. */
1105 int yychecklim
= YYLAST
- yyn
+ 1;
1106 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1109 yyarg
[0] = yytname
[yytype
];
1110 yyfmt
= yystpcpy (yyformat
, yyunexpected
);
1112 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1113 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
)
1115 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1119 yyformat
[sizeof yyunexpected
- 1] = '\0';
1122 yyarg
[yycount
++] = yytname
[yyx
];
1123 yysize1
= yysize
+ yytnamerr (0, yytname
[yyx
]);
1124 yysize_overflow
|= (yysize1
< yysize
);
1126 yyfmt
= yystpcpy (yyfmt
, yyprefix
);
1130 yyf
= YY_(yyformat
);
1131 yysize1
= yysize
+ yystrlen (yyf
);
1132 yysize_overflow
|= (yysize1
< yysize
);
1135 if (yysize_overflow
)
1136 return YYSIZE_MAXIMUM
;
1140 /* Avoid sprintf, as that infringes on the user's name space.
1141 Don't have undefined behavior even if the translation
1142 produced a string with the wrong number of "%s"s. */
1143 char *yyp
= yyresult
;
1145 while ((*yyp
= *yyf
) != '\0')
1147 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
)
1149 yyp
+= yytnamerr (yyp
, yyarg
[yyi
++]);
1162 #endif /* YYERROR_VERBOSE */
1165 /*-----------------------------------------------.
1166 | Release the memory associated to this symbol. |
1167 `-----------------------------------------------*/
1170 #if (defined __STDC__ || defined __C99__FUNC__ \
1171 || defined __cplusplus || defined _MSC_VER)
1173 yydestruct (const char *yymsg
, int yytype
, YYSTYPE
*yyvaluep
)
1176 yydestruct (yymsg
, yytype
, yyvaluep
)
1186 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
1197 /* Prevent warnings from -Wmissing-prototypes. */
1199 #ifdef YYPARSE_PARAM
1200 #if defined __STDC__ || defined __cplusplus
1201 int yyparse (void *YYPARSE_PARAM
);
1205 #else /* ! YYPARSE_PARAM */
1206 #if defined __STDC__ || defined __cplusplus
1211 #endif /* ! YYPARSE_PARAM */
1222 #ifdef YYPARSE_PARAM
1223 #if (defined __STDC__ || defined __C99__FUNC__ \
1224 || defined __cplusplus || defined _MSC_VER)
1226 yyparse (void *YYPARSE_PARAM
)
1229 yyparse (YYPARSE_PARAM
)
1230 void *YYPARSE_PARAM
;
1232 #else /* ! YYPARSE_PARAM */
1233 #if (defined __STDC__ || defined __C99__FUNC__ \
1234 || defined __cplusplus || defined _MSC_VER)
1244 /* The look-ahead symbol. */
1247 /* The semantic value of the look-ahead symbol. */
1250 /* Number of syntax errors so far. */
1256 /* Number of tokens to shift before error messages enabled. */
1258 /* Look-ahead token as an internal (translated) token number. */
1261 /* Buffer for error messages, and its allocated size. */
1263 char *yymsg
= yymsgbuf
;
1264 YYSIZE_T yymsg_alloc
= sizeof yymsgbuf
;
1267 /* Three stacks and their tools:
1268 `yyss': related to states,
1269 `yyvs': related to semantic values,
1270 `yyls': related to locations.
1272 Refer to the stacks thru separate pointers, to allow yyoverflow
1273 to reallocate them elsewhere. */
1275 /* The state stack. */
1276 yytype_int16 yyssa
[YYINITDEPTH
];
1277 yytype_int16
*yyss
= yyssa
;
1278 yytype_int16
*yyssp
;
1280 /* The semantic value stack. */
1281 YYSTYPE yyvsa
[YYINITDEPTH
];
1282 YYSTYPE
*yyvs
= yyvsa
;
1287 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1289 YYSIZE_T yystacksize
= YYINITDEPTH
;
1291 /* The variables used to return semantic value and location from the
1296 /* The number of symbols on the RHS of the reduced rule.
1297 Keep to zero when no symbol should be popped. */
1300 YYDPRINTF ((stderr
, "Starting parse\n"));
1305 yychar
= YYEMPTY
; /* Cause a token to be read. */
1307 /* Initialize stack pointers.
1308 Waste one element of value and location stack
1309 so that they stay on the same level as the state stack.
1310 The wasted elements are never initialized. */
1317 /*------------------------------------------------------------.
1318 | yynewstate -- Push a new state, which is found in yystate. |
1319 `------------------------------------------------------------*/
1321 /* In all cases, when you get here, the value and location stacks
1322 have just been pushed. So pushing a state here evens the stacks. */
1328 if (yyss
+ yystacksize
- 1 <= yyssp
)
1330 /* Get the current used size of the three stacks, in elements. */
1331 YYSIZE_T yysize
= yyssp
- yyss
+ 1;
1335 /* Give user a chance to reallocate the stack. Use copies of
1336 these so that the &'s don't force the real ones into
1338 YYSTYPE
*yyvs1
= yyvs
;
1339 yytype_int16
*yyss1
= yyss
;
1342 /* Each stack pointer address is followed by the size of the
1343 data in use in that stack, in bytes. This used to be a
1344 conditional around just the two extra args, but that might
1345 be undefined if yyoverflow is a macro. */
1346 yyoverflow (YY_("memory exhausted"),
1347 &yyss1
, yysize
* sizeof (*yyssp
),
1348 &yyvs1
, yysize
* sizeof (*yyvsp
),
1355 #else /* no yyoverflow */
1356 # ifndef YYSTACK_RELOCATE
1357 goto yyexhaustedlab
;
1359 /* Extend the stack our own way. */
1360 if (YYMAXDEPTH
<= yystacksize
)
1361 goto yyexhaustedlab
;
1363 if (YYMAXDEPTH
< yystacksize
)
1364 yystacksize
= YYMAXDEPTH
;
1367 yytype_int16
*yyss1
= yyss
;
1368 union yyalloc
*yyptr
=
1369 (union yyalloc
*) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize
));
1371 goto yyexhaustedlab
;
1372 YYSTACK_RELOCATE (yyss
);
1373 YYSTACK_RELOCATE (yyvs
);
1375 # undef YYSTACK_RELOCATE
1377 YYSTACK_FREE (yyss1
);
1380 #endif /* no yyoverflow */
1382 yyssp
= yyss
+ yysize
- 1;
1383 yyvsp
= yyvs
+ yysize
- 1;
1386 YYDPRINTF ((stderr
, "Stack size increased to %lu\n",
1387 (unsigned long int) yystacksize
));
1389 if (yyss
+ yystacksize
- 1 <= yyssp
)
1393 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1402 /* Do appropriate processing given the current state. Read a
1403 look-ahead token if we need one and don't already have one. */
1405 /* First try to decide what to do without reference to look-ahead token. */
1406 yyn
= yypact
[yystate
];
1407 if (yyn
== YYPACT_NINF
)
1410 /* Not known => get a look-ahead token if don't already have one. */
1412 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1413 if (yychar
== YYEMPTY
)
1415 YYDPRINTF ((stderr
, "Reading a token: "));
1419 if (yychar
<= YYEOF
)
1421 yychar
= yytoken
= YYEOF
;
1422 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1426 yytoken
= YYTRANSLATE (yychar
);
1427 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1430 /* If the proper action on seeing token YYTOKEN is to reduce or to
1431 detect an error, take that action. */
1433 if (yyn
< 0 || YYLAST
< yyn
|| yycheck
[yyn
] != yytoken
)
1438 if (yyn
== 0 || yyn
== YYTABLE_NINF
)
1447 /* Count tokens shifted since error; after three, turn off error
1452 /* Shift the look-ahead token. */
1453 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
1455 /* Discard the shifted token unless it is eof. */
1456 if (yychar
!= YYEOF
)
1465 /*-----------------------------------------------------------.
1466 | yydefault -- do the default action for the current state. |
1467 `-----------------------------------------------------------*/
1469 yyn
= yydefact
[yystate
];
1475 /*-----------------------------.
1476 | yyreduce -- Do a reduction. |
1477 `-----------------------------*/
1479 /* yyn is the number of a rule to reduce with. */
1482 /* If YYLEN is nonzero, implement the default value of the action:
1485 Otherwise, the following line sets YYVAL to garbage.
1486 This behavior is undocumented and Bison
1487 users should not rely upon it. Assigning to YYVAL
1488 unconditionally makes the parser a bit smaller, and it avoids a
1489 GCC warning that YYVAL may be used uninitialized. */
1490 yyval
= yyvsp
[1-yylen
];
1493 YY_REDUCE_PRINT (yyn
);
1497 #line 149 "OSUnserializeXML.y"
1498 { yyerror("unexpected end of buffer");
1504 #line 152 "OSUnserializeXML.y"
1505 { STATE
->parsedObject
= (yyvsp
[(1) - (1)])->object
;
1506 (yyvsp
[(1) - (1)])->object
= 0;
1507 freeObject(STATE
, (yyvsp
[(1) - (1)]));
1513 #line 157 "OSUnserializeXML.y"
1514 { yyerror("syntax error");
1520 #line 162 "OSUnserializeXML.y"
1521 { (yyval
) = buildDictionary(STATE
, (yyvsp
[(1) - (1)]));
1523 STATE
->parsedObjectCount
++;
1524 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1525 yyerror("maximum object count");
1532 #line 170 "OSUnserializeXML.y"
1533 { (yyval
) = buildArray(STATE
, (yyvsp
[(1) - (1)]));
1535 STATE
->parsedObjectCount
++;
1536 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1537 yyerror("maximum object count");
1544 #line 178 "OSUnserializeXML.y"
1545 { (yyval
) = buildSet(STATE
, (yyvsp
[(1) - (1)]));
1547 STATE
->parsedObjectCount
++;
1548 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1549 yyerror("maximum object count");
1556 #line 186 "OSUnserializeXML.y"
1557 { (yyval
) = buildString(STATE
, (yyvsp
[(1) - (1)]));
1559 STATE
->parsedObjectCount
++;
1560 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1561 yyerror("maximum object count");
1568 #line 194 "OSUnserializeXML.y"
1569 { (yyval
) = buildData(STATE
, (yyvsp
[(1) - (1)]));
1571 STATE
->parsedObjectCount
++;
1572 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1573 yyerror("maximum object count");
1580 #line 202 "OSUnserializeXML.y"
1581 { (yyval
) = buildNumber(STATE
, (yyvsp
[(1) - (1)]));
1583 STATE
->parsedObjectCount
++;
1584 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1585 yyerror("maximum object count");
1592 #line 210 "OSUnserializeXML.y"
1593 { (yyval
) = buildBoolean(STATE
, (yyvsp
[(1) - (1)]));
1595 STATE
->parsedObjectCount
++;
1596 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1597 yyerror("maximum object count");
1604 #line 218 "OSUnserializeXML.y"
1605 { (yyval
) = retrieveObject(STATE
, (yyvsp
[(1) - (1)])->idref
);
1607 (yyval
)->object
->retain();
1609 yyerror("forward reference detected");
1612 freeObject(STATE
, (yyvsp
[(1) - (1)]));
1614 STATE
->parsedObjectCount
++;
1615 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1616 yyerror("maximum object count");
1623 #line 237 "OSUnserializeXML.y"
1624 { (yyval
) = (yyvsp
[(1) - (2)]);
1625 (yyval
)->elements
= NULL
;
1630 #line 240 "OSUnserializeXML.y"
1631 { (yyval
) = (yyvsp
[(1) - (3)]);
1632 (yyval
)->elements
= (yyvsp
[(2) - (3)]);
1637 #line 247 "OSUnserializeXML.y"
1638 { (yyval
) = (yyvsp
[(2) - (2)]);
1639 (yyval
)->next
= (yyvsp
[(1) - (2)]);
1644 if (o
->key
== (yyval
)->key
) {
1645 yyerror("duplicate dictionary key");
1654 #line 262 "OSUnserializeXML.y"
1655 { (yyval
) = (yyvsp
[(1) - (2)]);
1656 (yyval
)->key
= (OSSymbol
*)(yyval
)->object
;
1657 (yyval
)->object
= (yyvsp
[(2) - (2)])->object
;
1658 (yyval
)->next
= NULL
;
1659 (yyvsp
[(2) - (2)])->object
= 0;
1660 freeObject(STATE
, (yyvsp
[(2) - (2)]));
1665 #line 271 "OSUnserializeXML.y"
1666 { (yyval
) = buildSymbol(STATE
, (yyvsp
[(1) - (1)]));
1668 // STATE->parsedObjectCount++;
1669 // if (STATE->parsedObjectCount > MAX_OBJECTS) {
1670 // yyerror("maximum object count");
1677 #line 283 "OSUnserializeXML.y"
1678 { (yyval
) = (yyvsp
[(1) - (2)]);
1679 (yyval
)->elements
= NULL
;
1684 #line 286 "OSUnserializeXML.y"
1685 { (yyval
) = (yyvsp
[(1) - (3)]);
1686 (yyval
)->elements
= (yyvsp
[(2) - (3)]);
1691 #line 292 "OSUnserializeXML.y"
1692 { (yyval
) = (yyvsp
[(1) - (2)]);
1693 (yyval
)->elements
= NULL
;
1698 #line 295 "OSUnserializeXML.y"
1699 { (yyval
) = (yyvsp
[(1) - (3)]);
1700 (yyval
)->elements
= (yyvsp
[(2) - (3)]);
1705 #line 301 "OSUnserializeXML.y"
1706 { (yyval
) = (yyvsp
[(1) - (1)]);
1707 (yyval
)->next
= NULL
;
1712 #line 304 "OSUnserializeXML.y"
1713 { (yyval
) = (yyvsp
[(2) - (2)]);
1714 (yyval
)->next
= (yyvsp
[(1) - (2)]);
1719 /* Line 1267 of yacc.c. */
1720 #line 1671 "OSUnserializeXML.tab.c"
1723 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyn
], &yyval
, &yyloc
);
1727 YY_STACK_PRINT (yyss
, yyssp
);
1732 /* Now `shift' the result of the reduction. Determine what state
1733 that goes to, based on the state we popped back to and the rule
1734 number reduced by. */
1738 yystate
= yypgoto
[yyn
- YYNTOKENS
] + *yyssp
;
1739 if (0 <= yystate
&& yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1740 yystate
= yytable
[yystate
];
1742 yystate
= yydefgoto
[yyn
- YYNTOKENS
];
1747 /*------------------------------------.
1748 | yyerrlab -- here on detecting error |
1749 `------------------------------------*/
1751 /* If not already recovering from an error, report this error. */
1755 #if ! YYERROR_VERBOSE
1756 yyerror (YY_("syntax error"));
1759 YYSIZE_T yysize
= yysyntax_error (0, yystate
, yychar
);
1760 if (yymsg_alloc
< yysize
&& yymsg_alloc
< YYSTACK_ALLOC_MAXIMUM
)
1762 YYSIZE_T yyalloc
= 2 * yysize
;
1763 if (! (yysize
<= yyalloc
&& yyalloc
<= YYSTACK_ALLOC_MAXIMUM
))
1764 yyalloc
= YYSTACK_ALLOC_MAXIMUM
;
1765 if (yymsg
!= yymsgbuf
)
1766 YYSTACK_FREE (yymsg
);
1767 yymsg
= (char *) YYSTACK_ALLOC (yyalloc
);
1769 yymsg_alloc
= yyalloc
;
1773 yymsg_alloc
= sizeof yymsgbuf
;
1777 if (0 < yysize
&& yysize
<= yymsg_alloc
)
1779 (void) yysyntax_error (yymsg
, yystate
, yychar
);
1784 yyerror (YY_("syntax error"));
1786 goto yyexhaustedlab
;
1794 if (yyerrstatus
== 3)
1796 /* If just tried and failed to reuse look-ahead token after an
1797 error, discard it. */
1799 if (yychar
<= YYEOF
)
1801 /* Return failure if at end of input. */
1802 if (yychar
== YYEOF
)
1807 yydestruct ("Error: discarding",
1813 /* Else will try to reuse look-ahead token after shifting the error
1818 /*---------------------------------------------------.
1819 | yyerrorlab -- error raised explicitly by YYERROR. |
1820 `---------------------------------------------------*/
1823 /* Pacify compilers like GCC when the user code never invokes
1824 YYERROR and the label yyerrorlab therefore never appears in user
1826 if (/*CONSTCOND*/ 0)
1829 /* Do not reclaim the symbols of the rule which action triggered
1833 YY_STACK_PRINT (yyss
, yyssp
);
1838 /*-------------------------------------------------------------.
1839 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1840 `-------------------------------------------------------------*/
1842 yyerrstatus
= 3; /* Each real token shifted decrements this. */
1846 yyn
= yypact
[yystate
];
1847 if (yyn
!= YYPACT_NINF
)
1850 if (0 <= yyn
&& yyn
<= YYLAST
&& yycheck
[yyn
] == YYTERROR
)
1858 /* Pop the current state because it cannot handle the error token. */
1863 yydestruct ("Error: popping",
1864 yystos
[yystate
], yyvsp
);
1867 YY_STACK_PRINT (yyss
, yyssp
);
1876 /* Shift the error token. */
1877 YY_SYMBOL_PRINT ("Shifting", yystos
[yyn
], yyvsp
, yylsp
);
1883 /*-------------------------------------.
1884 | yyacceptlab -- YYACCEPT comes here. |
1885 `-------------------------------------*/
1890 /*-----------------------------------.
1891 | yyabortlab -- YYABORT comes here. |
1892 `-----------------------------------*/
1898 /*-------------------------------------------------.
1899 | yyexhaustedlab -- memory exhaustion comes here. |
1900 `-------------------------------------------------*/
1902 yyerror (YY_("memory exhausted"));
1908 if (yychar
!= YYEOF
&& yychar
!= YYEMPTY
)
1909 yydestruct ("Cleanup: discarding lookahead",
1911 /* Do not reclaim the symbols of the rule which action triggered
1912 this YYABORT or YYACCEPT. */
1914 YY_STACK_PRINT (yyss
, yyssp
);
1915 while (yyssp
!= yyss
)
1917 yydestruct ("Cleanup: popping",
1918 yystos
[*yyssp
], yyvsp
);
1923 YYSTACK_FREE (yyss
);
1926 if (yymsg
!= yymsgbuf
)
1927 YYSTACK_FREE (yymsg
);
1929 /* Make sure YYID is used. */
1930 return YYID (yyresult
);
1934 #line 326 "OSUnserializeXML.y"
1938 OSUnserializeerror(parser_state_t
* state
, const char *s
) /* Called by yyparse on errors */
1940 if (state
->errorString
) {
1941 char tempString
[128];
1942 snprintf(tempString
, 128, "OSUnserializeXML: %s near line %d\n", s
, state
->lineNumber
);
1943 *(state
->errorString
) = OSString::withCString(tempString
);
1949 #define TAG_MAX_LENGTH 32
1950 #define TAG_MAX_ATTRIBUTES 32
1955 #define TAG_IGNORE 4
1957 #define currentChar() (state->parseBuffer[state->parseBufferIndex])
1958 #define nextChar() (state->parseBuffer[++state->parseBufferIndex])
1959 #define prevChar() (state->parseBuffer[state->parseBufferIndex - 1])
1961 #define isSpace(c) ((c) == ' ' || (c) == '\t')
1962 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
1963 #define isDigit(c) ((c) >= '0' && (c) <= '9')
1964 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f')
1965 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
1966 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-'))
1969 getTag(parser_state_t
*state
,
1970 char tag
[TAG_MAX_LENGTH
],
1971 int *attributeCount
,
1972 char attributes
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
],
1973 char values
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
] )
1976 int c
= currentChar();
1977 int tagType
= TAG_START
;
1979 *attributeCount
= 0;
1981 if (c
!= '<') return TAG_BAD
;
1982 c
= nextChar(); // skip '<'
1985 // <!TAG declarations >
1986 // <!-- comments -->
1989 bool isComment
= (c
== '-') && ((c
= nextChar()) != 0) && (c
== '-');
1990 if (!isComment
&& !isAlpha(c
)) return TAG_BAD
; // <!1, <!-A, <!eos
1992 while (c
&& (c
= nextChar()) != 0) {
1993 if (c
== '\n') state
->lineNumber
++;
1995 if (c
!= '-') continue;
1997 if (c
!= '-') continue;
2004 if (isComment
) break;
2011 // <? Processing Instructions ?>
2013 while ((c
= nextChar()) != 0) {
2014 if (c
== '\n') state
->lineNumber
++;
2015 if (c
!= '?') continue;
2017 if (!c
) return TAG_IGNORE
;
2030 c
= nextChar(); // skip '/'
2033 if (!isAlpha(c
)) return TAG_BAD
;
2035 /* find end of tag while copying it */
2036 while (isAlphaNumeric(c
)) {
2039 if (length
>= (TAG_MAX_LENGTH
- 1)) return TAG_BAD
;
2044 // printf("tag %s, type %d\n", tag, tagType);
2046 // look for attributes of the form attribute = "value" ...
2047 while ((c
!= '>') && (c
!= '/')) {
2048 while (isSpace(c
)) c
= nextChar();
2051 while (isAlphaNumeric(c
)) {
2052 attributes
[*attributeCount
][length
++] = c
;
2053 if (length
>= (TAG_MAX_LENGTH
- 1)) return TAG_BAD
;
2056 attributes
[*attributeCount
][length
] = 0;
2058 while (isSpace(c
)) c
= nextChar();
2060 if (c
!= '=') return TAG_BAD
;
2063 while (isSpace(c
)) c
= nextChar();
2065 if (c
!= '"') return TAG_BAD
;
2069 values
[*attributeCount
][length
++] = c
;
2070 if (length
>= (TAG_MAX_LENGTH
- 1)) return TAG_BAD
;
2072 if (!c
) return TAG_BAD
;
2074 values
[*attributeCount
][length
] = 0;
2076 c
= nextChar(); // skip closing quote
2078 // printf(" attribute '%s' = '%s', nextchar = '%c'\n",
2079 // attributes[*attributeCount], values[*attributeCount], c);
2081 (*attributeCount
)++;
2082 if (*attributeCount
>= TAG_MAX_ATTRIBUTES
) return TAG_BAD
;
2086 c
= nextChar(); // skip '/'
2087 tagType
= TAG_EMPTY
;
2089 if (c
!= '>') return TAG_BAD
;
2090 c
= nextChar(); // skip '>'
2096 getString(parser_state_t
*state
)
2098 int c
= currentChar();
2099 int start
, length
, i
, j
;
2102 start
= state
->parseBufferIndex
;
2103 /* find end of string */
2106 if (c
== '\n') state
->lineNumber
++;
2113 if (c
!= '<') return 0;
2115 length
= state
->parseBufferIndex
- start
;
2117 /* copy to null terminated buffer */
2118 tempString
= (char *)malloc(length
+ 1);
2119 if (tempString
== 0) {
2120 printf("OSUnserializeXML: can't alloc temp memory\n");
2124 // copy out string in tempString
2125 // "&" -> '&', "<" -> '<', ">" -> '>'
2128 while (i
< length
) {
2129 c
= state
->parseBuffer
[start
+ i
++];
2131 tempString
[j
++] = c
;
2133 if ((i
+3) > length
) goto error
;
2134 c
= state
->parseBuffer
[start
+ i
++];
2136 if (state
->parseBuffer
[start
+ i
++] != 't') goto error
;
2137 if (state
->parseBuffer
[start
+ i
++] != ';') goto error
;
2138 tempString
[j
++] = '<';
2142 if (state
->parseBuffer
[start
+ i
++] != 't') goto error
;
2143 if (state
->parseBuffer
[start
+ i
++] != ';') goto error
;
2144 tempString
[j
++] = '>';
2147 if ((i
+3) > length
) goto error
;
2149 if (state
->parseBuffer
[start
+ i
++] != 'm') goto error
;
2150 if (state
->parseBuffer
[start
+ i
++] != 'p') goto error
;
2151 if (state
->parseBuffer
[start
+ i
++] != ';') goto error
;
2152 tempString
[j
++] = '&';
2160 // printf("string %s\n", tempString);
2165 if (tempString
) free(tempString
);
2170 getNumber(parser_state_t
*state
)
2172 unsigned long long n
= 0;
2174 bool negate
= false;
2175 int c
= currentChar();
2190 n
= (n
* base
+ c
- '0');
2194 n
= (unsigned long long)((long long)n
* (long long)-1);
2197 while(isHexDigit(c
)) {
2199 n
= (n
* base
+ c
- '0');
2201 n
= (n
* base
+ 0xa + c
- 'a');
2206 // printf("number 0x%x\n", (unsigned long)n);
2210 // taken from CFXMLParsing/CFPropertyList.c
2212 static const signed char __CFPLDataDecodeTable
[128] = {
2213 /* 000 */ -1, -1, -1, -1, -1, -1, -1, -1,
2214 /* 010 */ -1, -1, -1, -1, -1, -1, -1, -1,
2215 /* 020 */ -1, -1, -1, -1, -1, -1, -1, -1,
2216 /* 030 */ -1, -1, -1, -1, -1, -1, -1, -1,
2217 /* ' ' */ -1, -1, -1, -1, -1, -1, -1, -1,
2218 /* '(' */ -1, -1, -1, 62, -1, -1, -1, 63,
2219 /* '0' */ 52, 53, 54, 55, 56, 57, 58, 59,
2220 /* '8' */ 60, 61, -1, -1, -1, 0, -1, -1,
2221 /* '@' */ -1, 0, 1, 2, 3, 4, 5, 6,
2222 /* 'H' */ 7, 8, 9, 10, 11, 12, 13, 14,
2223 /* 'P' */ 15, 16, 17, 18, 19, 20, 21, 22,
2224 /* 'X' */ 23, 24, 25, -1, -1, -1, -1, -1,
2225 /* '`' */ -1, 26, 27, 28, 29, 30, 31, 32,
2226 /* 'h' */ 33, 34, 35, 36, 37, 38, 39, 40,
2227 /* 'p' */ 41, 42, 43, 44, 45, 46, 47, 48,
2228 /* 'x' */ 49, 50, 51, -1, -1, -1, -1, -1
2231 #define DATA_ALLOC_SIZE 4096
2234 getCFEncodedData(parser_state_t
*state
, unsigned int *size
)
2236 int numeq
= 0, acc
= 0, cntr
= 0;
2237 int tmpbufpos
= 0, tmpbuflen
= 0;
2238 unsigned char *tmpbuf
= (unsigned char *)malloc(DATA_ALLOC_SIZE
);
2240 int c
= currentChar();
2249 if (c
== '=') numeq
++; else numeq
= 0;
2250 if (c
== '\n') state
->lineNumber
++;
2251 if (__CFPLDataDecodeTable
[c
] < 0) {
2257 acc
+= __CFPLDataDecodeTable
[c
];
2258 if (0 == (cntr
& 0x3)) {
2259 if (tmpbuflen
<= tmpbufpos
+ 2) {
2260 tmpbuflen
+= DATA_ALLOC_SIZE
;
2261 tmpbuf
= (unsigned char *)realloc(tmpbuf
, tmpbuflen
);
2263 tmpbuf
[tmpbufpos
++] = (acc
>> 16) & 0xff;
2265 tmpbuf
[tmpbufpos
++] = (acc
>> 8) & 0xff;
2267 tmpbuf
[tmpbufpos
++] = acc
& 0xff;
2280 getHexData(parser_state_t
*state
, unsigned int *size
)
2283 unsigned char *d
, *start
, *lastStart
;
2285 start
= lastStart
= d
= (unsigned char *)malloc(DATA_ALLOC_SIZE
);
2290 if (isSpace(c
)) while ((c
= nextChar()) != 0 && isSpace(c
)) {};
2292 state
->lineNumber
++;
2299 *d
= (c
- '0') << 4;
2300 } else if (isAlphaDigit(c
)) {
2301 *d
= (0xa + (c
- 'a')) << 4;
2310 } else if (isAlphaDigit(c
)) {
2311 *d
|= 0xa + (c
- 'a');
2317 if ((d
- lastStart
) >= DATA_ALLOC_SIZE
) {
2318 int oldsize
= d
- start
;
2319 start
= (unsigned char *)realloc(start
, oldsize
+ DATA_ALLOC_SIZE
);
2320 d
= lastStart
= start
+ oldsize
;
2336 yylex(YYSTYPE
*lvalp
, parser_state_t
*state
)
2340 char tag
[TAG_MAX_LENGTH
];
2342 char attributes
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
];
2343 char values
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
];
2349 /* skip white space */
2350 if (isSpace(c
)) while ((c
= nextChar()) != 0 && isSpace(c
)) {};
2352 /* keep track of line number, don't return \n's */
2354 STATE
->lineNumber
++;
2359 // end of the buffer?
2362 tagType
= getTag(STATE
, tag
, &attributeCount
, attributes
, values
);
2363 if (tagType
== TAG_BAD
) return SYNTAX_ERROR
;
2364 if (tagType
== TAG_IGNORE
) goto top
;
2366 // handle allocation and check for "ID" and "IDREF" tags up front
2367 *lvalp
= object
= newObject(STATE
);
2369 for (i
=0; i
< attributeCount
; i
++) {
2370 if (attributes
[i
][0] == 'I' && attributes
[i
][1] == 'D') {
2371 // check for idref's, note: we ignore the tag, for
2372 // this to work correctly, all idrefs must be unique
2373 // across the whole serialization
2374 if (attributes
[i
][2] == 'R' && attributes
[i
][3] == 'E' &&
2375 attributes
[i
][4] == 'F' && !attributes
[i
][5]) {
2376 if (tagType
!= TAG_EMPTY
) return SYNTAX_ERROR
;
2377 object
->idref
= strtol(values
[i
], NULL
, 0);
2381 if (!attributes
[i
][2]) {
2382 object
->idref
= strtol(values
[i
], NULL
, 0);
2384 return SYNTAX_ERROR
;
2391 if (!strcmp(tag
, "array")) {
2392 if (tagType
== TAG_EMPTY
) {
2393 object
->elements
= NULL
;
2396 return (tagType
== TAG_START
) ? '(' : ')';
2400 if (!strcmp(tag
, "dict")) {
2401 if (tagType
== TAG_EMPTY
) {
2402 object
->elements
= NULL
;
2405 return (tagType
== TAG_START
) ? '{' : '}';
2407 if (!strcmp(tag
, "data")) {
2409 if (tagType
== TAG_EMPTY
) {
2410 object
->data
= NULL
;
2415 bool isHexFormat
= false;
2416 for (i
=0; i
< attributeCount
; i
++) {
2417 if (!strcmp(attributes
[i
], "format") && !strcmp(values
[i
], "hex")) {
2422 // CF encoded is the default form
2424 object
->data
= getHexData(STATE
, &size
);
2426 object
->data
= getCFEncodedData(STATE
, &size
);
2428 object
->size
= size
;
2429 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
) || strcmp(tag
, "data")) {
2430 return SYNTAX_ERROR
;
2436 if (!strcmp(tag
, "false")) {
2437 if (tagType
== TAG_EMPTY
) {
2444 if (!strcmp(tag
, "integer")) {
2445 object
->size
= 64; // default
2446 for (i
=0; i
< attributeCount
; i
++) {
2447 if (!strcmp(attributes
[i
], "size")) {
2448 object
->size
= strtoul(values
[i
], NULL
, 0);
2451 if (tagType
== TAG_EMPTY
) {
2455 object
->number
= getNumber(STATE
);
2456 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
) || strcmp(tag
, "integer")) {
2457 return SYNTAX_ERROR
;
2463 if (!strcmp(tag
, "key")) {
2464 if (tagType
== TAG_EMPTY
) return SYNTAX_ERROR
;
2465 object
->string
= getString(STATE
);
2466 if (!object
->string
) {
2467 return SYNTAX_ERROR
;
2469 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
)
2470 || strcmp(tag
, "key")) {
2471 return SYNTAX_ERROR
;
2477 if (!strcmp(tag
, "plist")) {
2478 freeObject(STATE
, object
);
2483 if (!strcmp(tag
, "string")) {
2484 if (tagType
== TAG_EMPTY
) {
2485 object
->string
= (char *)malloc(1);
2486 object
->string
[0] = 0;
2489 object
->string
= getString(STATE
);
2490 if (!object
->string
) {
2491 return SYNTAX_ERROR
;
2493 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
)
2494 || strcmp(tag
, "string")) {
2495 return SYNTAX_ERROR
;
2499 if (!strcmp(tag
, "set")) {
2500 if (tagType
== TAG_EMPTY
) {
2501 object
->elements
= NULL
;
2504 if (tagType
== TAG_START
) {
2512 if (!strcmp(tag
, "true")) {
2513 if (tagType
== TAG_EMPTY
) {
2521 return SYNTAX_ERROR
;
2524 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2525 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2526 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2528 // "java" like allocation, if this code hits a syntax error in the
2529 // the middle of the parsed string we just bail with pointers hanging
2530 // all over place, this code helps keeps it all together
2532 //static int object_count = 0;
2535 newObject(parser_state_t
*state
)
2539 if (state
->freeObjects
) {
2540 o
= state
->freeObjects
;
2541 state
->freeObjects
= state
->freeObjects
->next
;
2543 o
= (object_t
*)malloc(sizeof(object_t
));
2545 bzero(o
, sizeof(object_t
));
2546 o
->free
= state
->objects
;
2554 freeObject(parser_state_t
* state
, object_t
*o
)
2556 o
->next
= state
->freeObjects
;
2557 state
->freeObjects
= o
;
2561 cleanupObjects(parser_state_t
*state
)
2563 object_t
*t
, *o
= state
->objects
;
2567 // printf("OSUnserializeXML: releasing object o=%x object=%x\n", (int)o, (int)o->object);
2568 o
->object
->release();
2571 // printf("OSUnserializeXML: freeing object o=%x data=%x\n", (int)o, (int)o->data);
2575 // printf("OSUnserializeXML: releasing object o=%x key=%x\n", (int)o, (int)o->key);
2579 // printf("OSUnserializeXML: freeing object o=%x string=%x\n", (int)o, (int)o->string);
2588 // printf("object_count = %d\n", object_count);
2591 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2592 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2593 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2596 rememberObject(parser_state_t
*state
, int tag
, OSObject
*o
)
2599 snprintf(key
, 16, "%u", tag
);
2601 // printf("remember key %s\n", key);
2603 state
->tags
->setObject(key
, o
);
2607 retrieveObject(parser_state_t
*state
, int tag
)
2612 snprintf(key
, 16, "%u", tag
);
2614 // printf("retrieve key '%s'\n", key);
2616 ref
= state
->tags
->getObject(key
);
2619 o
= newObject(state
);
2624 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2625 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2626 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2629 buildDictionary(parser_state_t
*state
, object_t
* header
)
2635 // get count and reverse order
2636 o
= header
->elements
;
2637 header
->elements
= 0;
2643 t
->next
= header
->elements
;
2644 header
->elements
= t
;
2647 dict
= OSDictionary::withCapacity(count
);
2648 if (header
->idref
>= 0) rememberObject(state
, header
->idref
, dict
);
2650 o
= header
->elements
;
2652 dict
->setObject(o
->key
, o
->object
);
2655 o
->object
->release();
2661 freeObject(state
, t
);
2669 buildArray(parser_state_t
*state
, object_t
* header
)
2675 // get count and reverse order
2676 o
= header
->elements
;
2677 header
->elements
= 0;
2683 t
->next
= header
->elements
;
2684 header
->elements
= t
;
2687 array
= OSArray::withCapacity(count
);
2688 if (header
->idref
>= 0) rememberObject(state
, header
->idref
, array
);
2690 o
= header
->elements
;
2692 array
->setObject(o
->object
);
2694 o
->object
->release();
2699 freeObject(state
, t
);
2707 buildSet(parser_state_t
*state
, object_t
*header
)
2709 object_t
*o
= buildArray(state
, header
);
2711 OSArray
*array
= (OSArray
*)o
->object
;
2712 OSSet
*set
= OSSet::withArray(array
, array
->getCapacity());
2714 // write over the reference created in buildArray
2715 if (header
->idref
>= 0) rememberObject(state
, header
->idref
, set
);
2723 buildString(parser_state_t
*state
, object_t
*o
)
2727 string
= OSString::withCString(o
->string
);
2728 if (o
->idref
>= 0) rememberObject(state
, o
->idref
, string
);
2738 buildSymbol(parser_state_t
*state
, object_t
*o
)
2742 symbol
= (OSSymbol
*)OSSymbol::withCString(o
->string
);
2743 if (o
->idref
>= 0) rememberObject(state
, o
->idref
, symbol
);
2753 buildData(parser_state_t
*state
, object_t
*o
)
2758 data
= OSData::withBytes(o
->data
, o
->size
);
2760 data
= OSData::withCapacity(0);
2762 if (o
->idref
>= 0) rememberObject(state
, o
->idref
, data
);
2764 if (o
->size
) free(o
->data
);
2771 buildNumber(parser_state_t
*state
, object_t
*o
)
2773 OSNumber
*number
= OSNumber::withNumber(o
->number
, o
->size
);
2775 if (o
->idref
>= 0) rememberObject(state
, o
->idref
, number
);
2782 buildBoolean(parser_state_t
*state __unused
, object_t
*o
)
2784 o
->object
= ((o
->number
== 0) ? kOSBooleanFalse
: kOSBooleanTrue
);
2785 o
->object
->retain();
2790 OSUnserializeXML(const char *buffer
, OSString
**errorString
)
2794 if (!buffer
) return 0;
2795 parser_state_t
*state
= (parser_state_t
*)malloc(sizeof(parser_state_t
));
2796 if (!state
) return 0;
2799 if (errorString
) *errorString
= NULL
;
2801 state
->parseBuffer
= buffer
;
2802 state
->parseBufferIndex
= 0;
2803 state
->lineNumber
= 1;
2805 state
->freeObjects
= 0;
2806 state
->tags
= OSDictionary::withCapacity(128);
2807 state
->errorString
= errorString
;
2808 state
->parsedObject
= 0;
2809 state
->parsedObjectCount
= 0;
2811 (void)yyparse((void *)state
);
2813 object
= state
->parsedObject
;
2815 cleanupObjects(state
);
2816 state
->tags
->release();
2822 #include <libkern/OSSerializeBinary.h>
2825 OSUnserializeXML(const char *buffer
, size_t bufferSize
, OSString
**errorString
)
2827 if (!buffer
) return (0);
2828 if (bufferSize
< sizeof(kOSSerializeBinarySignature
)) return (0);
2830 if (!strcmp(kOSSerializeBinarySignature
, buffer
)) return OSUnserializeBinary(buffer
, bufferSize
, errorString
);
2832 // XML must be null terminated
2833 if (buffer
[bufferSize
- 1]) return 0;
2835 return OSUnserializeXML(buffer
, errorString
);
2844 // DO NOT EDIT OSUnserializeXML.cpp!