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, 174, 186, 198, 210,
557 222, 234, 246, 265, 268, 271, 274, 275, 290, 299,
558 311, 314, 317, 320, 323, 326, 329, 332, 339, 342,
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 64
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 if (!yyval
->object
) {
1524 yyerror("buildDictionary");
1527 STATE
->parsedObjectCount
++;
1528 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1529 yyerror("maximum object count");
1536 #line 174 "OSUnserializeXML.y"
1537 { (yyval
) = buildArray(STATE
, (yyvsp
[(1) - (1)]));
1539 if (!yyval
->object
) {
1540 yyerror("buildArray");
1543 STATE
->parsedObjectCount
++;
1544 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1545 yyerror("maximum object count");
1552 #line 186 "OSUnserializeXML.y"
1553 { (yyval
) = buildSet(STATE
, (yyvsp
[(1) - (1)]));
1555 if (!yyval
->object
) {
1556 yyerror("buildSet");
1559 STATE
->parsedObjectCount
++;
1560 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1561 yyerror("maximum object count");
1568 #line 198 "OSUnserializeXML.y"
1569 { (yyval
) = buildString(STATE
, (yyvsp
[(1) - (1)]));
1571 if (!yyval
->object
) {
1572 yyerror("buildString");
1575 STATE
->parsedObjectCount
++;
1576 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1577 yyerror("maximum object count");
1584 #line 210 "OSUnserializeXML.y"
1585 { (yyval
) = buildData(STATE
, (yyvsp
[(1) - (1)]));
1587 if (!yyval
->object
) {
1588 yyerror("buildData");
1591 STATE
->parsedObjectCount
++;
1592 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1593 yyerror("maximum object count");
1600 #line 222 "OSUnserializeXML.y"
1601 { (yyval
) = buildNumber(STATE
, (yyvsp
[(1) - (1)]));
1603 if (!yyval
->object
) {
1604 yyerror("buildNumber");
1607 STATE
->parsedObjectCount
++;
1608 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1609 yyerror("maximum object count");
1616 #line 234 "OSUnserializeXML.y"
1617 { (yyval
) = buildBoolean(STATE
, (yyvsp
[(1) - (1)]));
1619 if (!yyval
->object
) {
1620 yyerror("buildBoolean");
1623 STATE
->parsedObjectCount
++;
1624 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1625 yyerror("maximum object count");
1632 #line 246 "OSUnserializeXML.y"
1633 { (yyval
) = retrieveObject(STATE
, (yyvsp
[(1) - (1)])->idref
);
1635 (yyval
)->object
->retain();
1637 yyerror("forward reference detected");
1640 freeObject(STATE
, (yyvsp
[(1) - (1)]));
1642 STATE
->parsedObjectCount
++;
1643 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1644 yyerror("maximum object count");
1651 #line 265 "OSUnserializeXML.y"
1652 { (yyval
) = (yyvsp
[(1) - (2)]);
1653 (yyval
)->elements
= NULL
;
1658 #line 268 "OSUnserializeXML.y"
1659 { (yyval
) = (yyvsp
[(1) - (3)]);
1660 (yyval
)->elements
= (yyvsp
[(2) - (3)]);
1665 #line 275 "OSUnserializeXML.y"
1666 { (yyval
) = (yyvsp
[(2) - (2)]);
1667 (yyval
)->next
= (yyvsp
[(1) - (2)]);
1672 if (o
->key
== (yyval
)->key
) {
1673 yyerror("duplicate dictionary key");
1682 #line 290 "OSUnserializeXML.y"
1683 { (yyval
) = (yyvsp
[(1) - (2)]);
1684 (yyval
)->key
= (OSSymbol
*)(yyval
)->object
;
1685 (yyval
)->object
= (yyvsp
[(2) - (2)])->object
;
1686 (yyval
)->next
= NULL
;
1687 (yyvsp
[(2) - (2)])->object
= 0;
1688 freeObject(STATE
, (yyvsp
[(2) - (2)]));
1693 #line 299 "OSUnserializeXML.y"
1694 { (yyval
) = buildSymbol(STATE
, (yyvsp
[(1) - (1)]));
1696 // STATE->parsedObjectCount++;
1697 // if (STATE->parsedObjectCount > MAX_OBJECTS) {
1698 // yyerror("maximum object count");
1705 #line 311 "OSUnserializeXML.y"
1706 { (yyval
) = (yyvsp
[(1) - (2)]);
1707 (yyval
)->elements
= NULL
;
1712 #line 314 "OSUnserializeXML.y"
1713 { (yyval
) = (yyvsp
[(1) - (3)]);
1714 (yyval
)->elements
= (yyvsp
[(2) - (3)]);
1719 #line 320 "OSUnserializeXML.y"
1720 { (yyval
) = (yyvsp
[(1) - (2)]);
1721 (yyval
)->elements
= NULL
;
1726 #line 323 "OSUnserializeXML.y"
1727 { (yyval
) = (yyvsp
[(1) - (3)]);
1728 (yyval
)->elements
= (yyvsp
[(2) - (3)]);
1733 #line 329 "OSUnserializeXML.y"
1734 { (yyval
) = (yyvsp
[(1) - (1)]);
1735 (yyval
)->next
= NULL
;
1740 #line 332 "OSUnserializeXML.y"
1741 { (yyval
) = (yyvsp
[(2) - (2)]);
1742 (yyval
)->next
= (yyvsp
[(1) - (2)]);
1747 /* Line 1267 of yacc.c. */
1748 #line 1699 "OSUnserializeXML.tab.c"
1751 YY_SYMBOL_PRINT ("-> $$ =", yyr1
[yyn
], &yyval
, &yyloc
);
1755 YY_STACK_PRINT (yyss
, yyssp
);
1760 /* Now `shift' the result of the reduction. Determine what state
1761 that goes to, based on the state we popped back to and the rule
1762 number reduced by. */
1766 yystate
= yypgoto
[yyn
- YYNTOKENS
] + *yyssp
;
1767 if (0 <= yystate
&& yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
)
1768 yystate
= yytable
[yystate
];
1770 yystate
= yydefgoto
[yyn
- YYNTOKENS
];
1775 /*------------------------------------.
1776 | yyerrlab -- here on detecting error |
1777 `------------------------------------*/
1779 /* If not already recovering from an error, report this error. */
1783 #if ! YYERROR_VERBOSE
1784 yyerror (YY_("syntax error"));
1787 YYSIZE_T yysize
= yysyntax_error (0, yystate
, yychar
);
1788 if (yymsg_alloc
< yysize
&& yymsg_alloc
< YYSTACK_ALLOC_MAXIMUM
)
1790 YYSIZE_T yyalloc
= 2 * yysize
;
1791 if (! (yysize
<= yyalloc
&& yyalloc
<= YYSTACK_ALLOC_MAXIMUM
))
1792 yyalloc
= YYSTACK_ALLOC_MAXIMUM
;
1793 if (yymsg
!= yymsgbuf
)
1794 YYSTACK_FREE (yymsg
);
1795 yymsg
= (char *) YYSTACK_ALLOC (yyalloc
);
1797 yymsg_alloc
= yyalloc
;
1801 yymsg_alloc
= sizeof yymsgbuf
;
1805 if (0 < yysize
&& yysize
<= yymsg_alloc
)
1807 (void) yysyntax_error (yymsg
, yystate
, yychar
);
1812 yyerror (YY_("syntax error"));
1814 goto yyexhaustedlab
;
1822 if (yyerrstatus
== 3)
1824 /* If just tried and failed to reuse look-ahead token after an
1825 error, discard it. */
1827 if (yychar
<= YYEOF
)
1829 /* Return failure if at end of input. */
1830 if (yychar
== YYEOF
)
1835 yydestruct ("Error: discarding",
1841 /* Else will try to reuse look-ahead token after shifting the error
1846 /*---------------------------------------------------.
1847 | yyerrorlab -- error raised explicitly by YYERROR. |
1848 `---------------------------------------------------*/
1851 /* Pacify compilers like GCC when the user code never invokes
1852 YYERROR and the label yyerrorlab therefore never appears in user
1854 if (/*CONSTCOND*/ 0)
1857 /* Do not reclaim the symbols of the rule which action triggered
1861 YY_STACK_PRINT (yyss
, yyssp
);
1866 /*-------------------------------------------------------------.
1867 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1868 `-------------------------------------------------------------*/
1870 yyerrstatus
= 3; /* Each real token shifted decrements this. */
1874 yyn
= yypact
[yystate
];
1875 if (yyn
!= YYPACT_NINF
)
1878 if (0 <= yyn
&& yyn
<= YYLAST
&& yycheck
[yyn
] == YYTERROR
)
1886 /* Pop the current state because it cannot handle the error token. */
1891 yydestruct ("Error: popping",
1892 yystos
[yystate
], yyvsp
);
1895 YY_STACK_PRINT (yyss
, yyssp
);
1904 /* Shift the error token. */
1905 YY_SYMBOL_PRINT ("Shifting", yystos
[yyn
], yyvsp
, yylsp
);
1911 /*-------------------------------------.
1912 | yyacceptlab -- YYACCEPT comes here. |
1913 `-------------------------------------*/
1918 /*-----------------------------------.
1919 | yyabortlab -- YYABORT comes here. |
1920 `-----------------------------------*/
1926 /*-------------------------------------------------.
1927 | yyexhaustedlab -- memory exhaustion comes here. |
1928 `-------------------------------------------------*/
1930 yyerror (YY_("memory exhausted"));
1936 if (yychar
!= YYEOF
&& yychar
!= YYEMPTY
)
1937 yydestruct ("Cleanup: discarding lookahead",
1939 /* Do not reclaim the symbols of the rule which action triggered
1940 this YYABORT or YYACCEPT. */
1942 YY_STACK_PRINT (yyss
, yyssp
);
1943 while (yyssp
!= yyss
)
1945 yydestruct ("Cleanup: popping",
1946 yystos
[*yyssp
], yyvsp
);
1951 YYSTACK_FREE (yyss
);
1954 if (yymsg
!= yymsgbuf
)
1955 YYSTACK_FREE (yymsg
);
1957 /* Make sure YYID is used. */
1958 return YYID (yyresult
);
1962 #line 354 "OSUnserializeXML.y"
1966 OSUnserializeerror(parser_state_t
* state
, const char *s
) /* Called by yyparse on errors */
1968 if (state
->errorString
) {
1969 char tempString
[128];
1970 snprintf(tempString
, 128, "OSUnserializeXML: %s near line %d\n", s
, state
->lineNumber
);
1971 *(state
->errorString
) = OSString::withCString(tempString
);
1977 #define TAG_MAX_LENGTH 32
1978 #define TAG_MAX_ATTRIBUTES 32
1983 #define TAG_IGNORE 4
1985 #define currentChar() (state->parseBuffer[state->parseBufferIndex])
1986 #define nextChar() (state->parseBuffer[++state->parseBufferIndex])
1987 #define prevChar() (state->parseBuffer[state->parseBufferIndex - 1])
1989 #define isSpace(c) ((c) == ' ' || (c) == '\t')
1990 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
1991 #define isDigit(c) ((c) >= '0' && (c) <= '9')
1992 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f')
1993 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
1994 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-'))
1997 getTag(parser_state_t
*state
,
1998 char tag
[TAG_MAX_LENGTH
],
1999 int *attributeCount
,
2000 char attributes
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
],
2001 char values
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
] )
2004 int c
= currentChar();
2005 int tagType
= TAG_START
;
2007 *attributeCount
= 0;
2009 if (c
!= '<') return TAG_BAD
;
2010 c
= nextChar(); // skip '<'
2013 // <!TAG declarations >
2014 // <!-- comments -->
2017 bool isComment
= (c
== '-') && ((c
= nextChar()) != 0) && (c
== '-');
2018 if (!isComment
&& !isAlpha(c
)) return TAG_BAD
; // <!1, <!-A, <!eos
2020 while (c
&& (c
= nextChar()) != 0) {
2021 if (c
== '\n') state
->lineNumber
++;
2023 if (c
!= '-') continue;
2025 if (c
!= '-') continue;
2032 if (isComment
) break;
2039 // <? Processing Instructions ?>
2041 while ((c
= nextChar()) != 0) {
2042 if (c
== '\n') state
->lineNumber
++;
2043 if (c
!= '?') continue;
2045 if (!c
) return TAG_IGNORE
;
2058 c
= nextChar(); // skip '/'
2061 if (!isAlpha(c
)) return TAG_BAD
;
2063 /* find end of tag while copying it */
2064 while (isAlphaNumeric(c
)) {
2067 if (length
>= (TAG_MAX_LENGTH
- 1)) return TAG_BAD
;
2072 // printf("tag %s, type %d\n", tag, tagType);
2074 // look for attributes of the form attribute = "value" ...
2075 while ((c
!= '>') && (c
!= '/')) {
2076 while (isSpace(c
)) c
= nextChar();
2079 while (isAlphaNumeric(c
)) {
2080 attributes
[*attributeCount
][length
++] = c
;
2081 if (length
>= (TAG_MAX_LENGTH
- 1)) return TAG_BAD
;
2084 attributes
[*attributeCount
][length
] = 0;
2086 while (isSpace(c
)) c
= nextChar();
2088 if (c
!= '=') return TAG_BAD
;
2091 while (isSpace(c
)) c
= nextChar();
2093 if (c
!= '"') return TAG_BAD
;
2097 values
[*attributeCount
][length
++] = c
;
2098 if (length
>= (TAG_MAX_LENGTH
- 1)) return TAG_BAD
;
2100 if (!c
) return TAG_BAD
;
2102 values
[*attributeCount
][length
] = 0;
2104 c
= nextChar(); // skip closing quote
2106 // printf(" attribute '%s' = '%s', nextchar = '%c'\n",
2107 // attributes[*attributeCount], values[*attributeCount], c);
2109 (*attributeCount
)++;
2110 if (*attributeCount
>= TAG_MAX_ATTRIBUTES
) return TAG_BAD
;
2114 c
= nextChar(); // skip '/'
2115 tagType
= TAG_EMPTY
;
2117 if (c
!= '>') return TAG_BAD
;
2118 c
= nextChar(); // skip '>'
2124 getString(parser_state_t
*state
)
2126 int c
= currentChar();
2127 int start
, length
, i
, j
;
2130 start
= state
->parseBufferIndex
;
2131 /* find end of string */
2134 if (c
== '\n') state
->lineNumber
++;
2141 if (c
!= '<') return 0;
2143 length
= state
->parseBufferIndex
- start
;
2145 /* copy to null terminated buffer */
2146 tempString
= (char *)malloc(length
+ 1);
2147 if (tempString
== 0) {
2148 printf("OSUnserializeXML: can't alloc temp memory\n");
2152 // copy out string in tempString
2153 // "&" -> '&', "<" -> '<', ">" -> '>'
2156 while (i
< length
) {
2157 c
= state
->parseBuffer
[start
+ i
++];
2159 tempString
[j
++] = c
;
2161 if ((i
+3) > length
) goto error
;
2162 c
= state
->parseBuffer
[start
+ i
++];
2164 if (state
->parseBuffer
[start
+ i
++] != 't') goto error
;
2165 if (state
->parseBuffer
[start
+ i
++] != ';') goto error
;
2166 tempString
[j
++] = '<';
2170 if (state
->parseBuffer
[start
+ i
++] != 't') goto error
;
2171 if (state
->parseBuffer
[start
+ i
++] != ';') goto error
;
2172 tempString
[j
++] = '>';
2175 if ((i
+3) > length
) goto error
;
2177 if (state
->parseBuffer
[start
+ i
++] != 'm') goto error
;
2178 if (state
->parseBuffer
[start
+ i
++] != 'p') goto error
;
2179 if (state
->parseBuffer
[start
+ i
++] != ';') goto error
;
2180 tempString
[j
++] = '&';
2188 // printf("string %s\n", tempString);
2193 if (tempString
) free(tempString
);
2198 getNumber(parser_state_t
*state
)
2200 unsigned long long n
= 0;
2202 bool negate
= false;
2203 int c
= currentChar();
2218 n
= (n
* base
+ c
- '0');
2222 n
= (unsigned long long)((long long)n
* (long long)-1);
2225 while(isHexDigit(c
)) {
2227 n
= (n
* base
+ c
- '0');
2229 n
= (n
* base
+ 0xa + c
- 'a');
2234 // printf("number 0x%x\n", (unsigned long)n);
2238 // taken from CFXMLParsing/CFPropertyList.c
2240 static const signed char __CFPLDataDecodeTable
[128] = {
2241 /* 000 */ -1, -1, -1, -1, -1, -1, -1, -1,
2242 /* 010 */ -1, -1, -1, -1, -1, -1, -1, -1,
2243 /* 020 */ -1, -1, -1, -1, -1, -1, -1, -1,
2244 /* 030 */ -1, -1, -1, -1, -1, -1, -1, -1,
2245 /* ' ' */ -1, -1, -1, -1, -1, -1, -1, -1,
2246 /* '(' */ -1, -1, -1, 62, -1, -1, -1, 63,
2247 /* '0' */ 52, 53, 54, 55, 56, 57, 58, 59,
2248 /* '8' */ 60, 61, -1, -1, -1, 0, -1, -1,
2249 /* '@' */ -1, 0, 1, 2, 3, 4, 5, 6,
2250 /* 'H' */ 7, 8, 9, 10, 11, 12, 13, 14,
2251 /* 'P' */ 15, 16, 17, 18, 19, 20, 21, 22,
2252 /* 'X' */ 23, 24, 25, -1, -1, -1, -1, -1,
2253 /* '`' */ -1, 26, 27, 28, 29, 30, 31, 32,
2254 /* 'h' */ 33, 34, 35, 36, 37, 38, 39, 40,
2255 /* 'p' */ 41, 42, 43, 44, 45, 46, 47, 48,
2256 /* 'x' */ 49, 50, 51, -1, -1, -1, -1, -1
2259 #define DATA_ALLOC_SIZE 4096
2262 getCFEncodedData(parser_state_t
*state
, unsigned int *size
)
2264 int numeq
= 0, acc
= 0, cntr
= 0;
2265 int tmpbufpos
= 0, tmpbuflen
= 0;
2266 unsigned char *tmpbuf
= (unsigned char *)malloc(DATA_ALLOC_SIZE
);
2268 int c
= currentChar();
2277 if (c
== '=') numeq
++; else numeq
= 0;
2278 if (c
== '\n') state
->lineNumber
++;
2279 if (__CFPLDataDecodeTable
[c
] < 0) {
2285 acc
+= __CFPLDataDecodeTable
[c
];
2286 if (0 == (cntr
& 0x3)) {
2287 if (tmpbuflen
<= tmpbufpos
+ 2) {
2288 tmpbuflen
+= DATA_ALLOC_SIZE
;
2289 tmpbuf
= (unsigned char *)realloc(tmpbuf
, tmpbuflen
);
2291 tmpbuf
[tmpbufpos
++] = (acc
>> 16) & 0xff;
2293 tmpbuf
[tmpbufpos
++] = (acc
>> 8) & 0xff;
2295 tmpbuf
[tmpbufpos
++] = acc
& 0xff;
2308 getHexData(parser_state_t
*state
, unsigned int *size
)
2311 unsigned char *d
, *start
, *lastStart
;
2313 start
= lastStart
= d
= (unsigned char *)malloc(DATA_ALLOC_SIZE
);
2318 if (isSpace(c
)) while ((c
= nextChar()) != 0 && isSpace(c
)) {};
2320 state
->lineNumber
++;
2327 *d
= (c
- '0') << 4;
2328 } else if (isAlphaDigit(c
)) {
2329 *d
= (0xa + (c
- 'a')) << 4;
2338 } else if (isAlphaDigit(c
)) {
2339 *d
|= 0xa + (c
- 'a');
2345 if ((d
- lastStart
) >= DATA_ALLOC_SIZE
) {
2346 int oldsize
= d
- start
;
2347 start
= (unsigned char *)realloc(start
, oldsize
+ DATA_ALLOC_SIZE
);
2348 d
= lastStart
= start
+ oldsize
;
2364 yylex(YYSTYPE
*lvalp
, parser_state_t
*state
)
2368 char tag
[TAG_MAX_LENGTH
];
2370 char attributes
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
];
2371 char values
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
];
2377 /* skip white space */
2378 if (isSpace(c
)) while ((c
= nextChar()) != 0 && isSpace(c
)) {};
2380 /* keep track of line number, don't return \n's */
2382 STATE
->lineNumber
++;
2387 // end of the buffer?
2390 tagType
= getTag(STATE
, tag
, &attributeCount
, attributes
, values
);
2391 if (tagType
== TAG_BAD
) return SYNTAX_ERROR
;
2392 if (tagType
== TAG_IGNORE
) goto top
;
2394 // handle allocation and check for "ID" and "IDREF" tags up front
2395 *lvalp
= object
= newObject(STATE
);
2397 for (i
=0; i
< attributeCount
; i
++) {
2398 if (attributes
[i
][0] == 'I' && attributes
[i
][1] == 'D') {
2399 // check for idref's, note: we ignore the tag, for
2400 // this to work correctly, all idrefs must be unique
2401 // across the whole serialization
2402 if (attributes
[i
][2] == 'R' && attributes
[i
][3] == 'E' &&
2403 attributes
[i
][4] == 'F' && !attributes
[i
][5]) {
2404 if (tagType
!= TAG_EMPTY
) return SYNTAX_ERROR
;
2405 object
->idref
= strtol(values
[i
], NULL
, 0);
2409 if (!attributes
[i
][2]) {
2410 object
->idref
= strtol(values
[i
], NULL
, 0);
2412 return SYNTAX_ERROR
;
2419 if (!strcmp(tag
, "array")) {
2420 if (tagType
== TAG_EMPTY
) {
2421 object
->elements
= NULL
;
2424 return (tagType
== TAG_START
) ? '(' : ')';
2428 if (!strcmp(tag
, "dict")) {
2429 if (tagType
== TAG_EMPTY
) {
2430 object
->elements
= NULL
;
2433 return (tagType
== TAG_START
) ? '{' : '}';
2435 if (!strcmp(tag
, "data")) {
2437 if (tagType
== TAG_EMPTY
) {
2438 object
->data
= NULL
;
2443 bool isHexFormat
= false;
2444 for (i
=0; i
< attributeCount
; i
++) {
2445 if (!strcmp(attributes
[i
], "format") && !strcmp(values
[i
], "hex")) {
2450 // CF encoded is the default form
2452 object
->data
= getHexData(STATE
, &size
);
2454 object
->data
= getCFEncodedData(STATE
, &size
);
2456 object
->size
= size
;
2457 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
) || strcmp(tag
, "data")) {
2458 return SYNTAX_ERROR
;
2464 if (!strcmp(tag
, "false")) {
2465 if (tagType
== TAG_EMPTY
) {
2472 if (!strcmp(tag
, "integer")) {
2473 object
->size
= 64; // default
2474 for (i
=0; i
< attributeCount
; i
++) {
2475 if (!strcmp(attributes
[i
], "size")) {
2476 object
->size
= strtoul(values
[i
], NULL
, 0);
2479 if (tagType
== TAG_EMPTY
) {
2483 object
->number
= getNumber(STATE
);
2484 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
) || strcmp(tag
, "integer")) {
2485 return SYNTAX_ERROR
;
2491 if (!strcmp(tag
, "key")) {
2492 if (tagType
== TAG_EMPTY
) return SYNTAX_ERROR
;
2493 object
->string
= getString(STATE
);
2494 if (!object
->string
) {
2495 return SYNTAX_ERROR
;
2497 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
)
2498 || strcmp(tag
, "key")) {
2499 return SYNTAX_ERROR
;
2505 if (!strcmp(tag
, "plist")) {
2506 freeObject(STATE
, object
);
2511 if (!strcmp(tag
, "string")) {
2512 if (tagType
== TAG_EMPTY
) {
2513 object
->string
= (char *)malloc(1);
2514 object
->string
[0] = 0;
2517 object
->string
= getString(STATE
);
2518 if (!object
->string
) {
2519 return SYNTAX_ERROR
;
2521 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
)
2522 || strcmp(tag
, "string")) {
2523 return SYNTAX_ERROR
;
2527 if (!strcmp(tag
, "set")) {
2528 if (tagType
== TAG_EMPTY
) {
2529 object
->elements
= NULL
;
2532 if (tagType
== TAG_START
) {
2540 if (!strcmp(tag
, "true")) {
2541 if (tagType
== TAG_EMPTY
) {
2549 return SYNTAX_ERROR
;
2552 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2553 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2554 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2556 // "java" like allocation, if this code hits a syntax error in the
2557 // the middle of the parsed string we just bail with pointers hanging
2558 // all over place, this code helps keeps it all together
2560 //static int object_count = 0;
2563 newObject(parser_state_t
*state
)
2567 if (state
->freeObjects
) {
2568 o
= state
->freeObjects
;
2569 state
->freeObjects
= state
->freeObjects
->next
;
2571 o
= (object_t
*)malloc(sizeof(object_t
));
2573 bzero(o
, sizeof(object_t
));
2574 o
->free
= state
->objects
;
2582 freeObject(parser_state_t
* state
, object_t
*o
)
2584 o
->next
= state
->freeObjects
;
2585 state
->freeObjects
= o
;
2589 cleanupObjects(parser_state_t
*state
)
2591 object_t
*t
, *o
= state
->objects
;
2595 // printf("OSUnserializeXML: releasing object o=%x object=%x\n", (int)o, (int)o->object);
2596 o
->object
->release();
2599 // printf("OSUnserializeXML: freeing object o=%x data=%x\n", (int)o, (int)o->data);
2603 // printf("OSUnserializeXML: releasing object o=%x key=%x\n", (int)o, (int)o->key);
2607 // printf("OSUnserializeXML: freeing object o=%x string=%x\n", (int)o, (int)o->string);
2616 // printf("object_count = %d\n", object_count);
2619 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2620 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2621 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2624 rememberObject(parser_state_t
*state
, int tag
, OSObject
*o
)
2627 snprintf(key
, 16, "%u", tag
);
2629 // printf("remember key %s\n", key);
2631 state
->tags
->setObject(key
, o
);
2635 retrieveObject(parser_state_t
*state
, int tag
)
2640 snprintf(key
, 16, "%u", tag
);
2642 // printf("retrieve key '%s'\n", key);
2644 ref
= state
->tags
->getObject(key
);
2647 o
= newObject(state
);
2652 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2653 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2654 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2657 buildDictionary(parser_state_t
*state
, object_t
* header
)
2663 // get count and reverse order
2664 o
= header
->elements
;
2665 header
->elements
= 0;
2671 t
->next
= header
->elements
;
2672 header
->elements
= t
;
2675 dict
= OSDictionary::withCapacity(count
);
2676 if (header
->idref
>= 0) rememberObject(state
, header
->idref
, dict
);
2678 o
= header
->elements
;
2680 dict
->setObject(o
->key
, o
->object
);
2683 o
->object
->release();
2689 freeObject(state
, t
);
2697 buildArray(parser_state_t
*state
, object_t
* header
)
2703 // get count and reverse order
2704 o
= header
->elements
;
2705 header
->elements
= 0;
2711 t
->next
= header
->elements
;
2712 header
->elements
= t
;
2715 array
= OSArray::withCapacity(count
);
2716 if (header
->idref
>= 0) rememberObject(state
, header
->idref
, array
);
2718 o
= header
->elements
;
2720 array
->setObject(o
->object
);
2722 o
->object
->release();
2727 freeObject(state
, t
);
2735 buildSet(parser_state_t
*state
, object_t
*header
)
2737 object_t
*o
= buildArray(state
, header
);
2739 OSArray
*array
= (OSArray
*)o
->object
;
2740 OSSet
*set
= OSSet::withArray(array
, array
->getCapacity());
2742 // write over the reference created in buildArray
2743 if (header
->idref
>= 0) rememberObject(state
, header
->idref
, set
);
2751 buildString(parser_state_t
*state
, object_t
*o
)
2755 string
= OSString::withCString(o
->string
);
2756 if (o
->idref
>= 0) rememberObject(state
, o
->idref
, string
);
2766 buildSymbol(parser_state_t
*state
, object_t
*o
)
2770 symbol
= (OSSymbol
*)OSSymbol::withCString(o
->string
);
2771 if (o
->idref
>= 0) rememberObject(state
, o
->idref
, symbol
);
2781 buildData(parser_state_t
*state
, object_t
*o
)
2786 data
= OSData::withBytes(o
->data
, o
->size
);
2788 data
= OSData::withCapacity(0);
2790 if (o
->idref
>= 0) rememberObject(state
, o
->idref
, data
);
2792 if (o
->size
) free(o
->data
);
2799 buildNumber(parser_state_t
*state
, object_t
*o
)
2801 OSNumber
*number
= OSNumber::withNumber(o
->number
, o
->size
);
2803 if (o
->idref
>= 0) rememberObject(state
, o
->idref
, number
);
2810 buildBoolean(parser_state_t
*state __unused
, object_t
*o
)
2812 o
->object
= ((o
->number
== 0) ? kOSBooleanFalse
: kOSBooleanTrue
);
2813 o
->object
->retain();
2818 OSUnserializeXML(const char *buffer
, OSString
**errorString
)
2822 if (!buffer
) return 0;
2823 parser_state_t
*state
= (parser_state_t
*)malloc(sizeof(parser_state_t
));
2824 if (!state
) return 0;
2827 if (errorString
) *errorString
= NULL
;
2829 state
->parseBuffer
= buffer
;
2830 state
->parseBufferIndex
= 0;
2831 state
->lineNumber
= 1;
2833 state
->freeObjects
= 0;
2834 state
->tags
= OSDictionary::withCapacity(128);
2835 state
->errorString
= errorString
;
2836 state
->parsedObject
= 0;
2837 state
->parsedObjectCount
= 0;
2839 (void)yyparse((void *)state
);
2841 object
= state
->parsedObject
;
2843 cleanupObjects(state
);
2844 state
->tags
->release();
2850 #include <libkern/OSSerializeBinary.h>
2853 OSUnserializeXML(const char *buffer
, size_t bufferSize
, OSString
**errorString
)
2855 if (!buffer
) return (0);
2856 if (bufferSize
< sizeof(kOSSerializeBinarySignature
)) return (0);
2858 if (!strcmp(kOSSerializeBinarySignature
, buffer
)) return OSUnserializeBinary(buffer
, bufferSize
, errorString
);
2860 // XML must be null terminated
2861 if (buffer
[bufferSize
- 1]) return 0;
2863 return OSUnserializeXML(buffer
, errorString
);
2872 // DO NOT EDIT OSUnserializeXML.cpp!