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
125 * know about them. */
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 131071
163 #define MAX_REFED_OBJECTS 65535
165 #define YYSTYPE object_t *
166 #define YYPARSE_PARAM state
167 #define YYLEX_PARAM (parser_state_t *)state
169 // this is the internal struct used to hold objects on parser stack
170 // it represents objects both before and after they have been created
171 typedef struct object
{
174 struct object
*elements
;
176 OSSymbol
*key
; // for dictionary
178 void *data
; // for data
179 char *string
; // for string & symbol
180 long long number
; // for number
184 // this code is reentrant, this structure contains all
185 // state information for the parsing of a single buffer
186 typedef struct parser_state
{
187 const char *parseBuffer
; // start of text to be parsed
188 int parseBufferIndex
; // current index into text
189 int lineNumber
; // current line number
190 object_t
*objects
; // internal objects in use
191 object_t
*freeObjects
; // internal objects that are free
192 OSDictionary
*tags
; // used to remember "ID" tags
193 OSString
**errorString
; // parse error with line
194 OSObject
*parsedObject
; // resultant object of parsed text
195 int parsedObjectCount
;
196 int retrievedObjectCount
;
199 #define STATE ((parser_state_t *)state)
202 #define yyerror(s) OSUnserializeerror(STATE, (s))
203 static int OSUnserializeerror(parser_state_t
*state
, const char *s
);
205 static int yylex(YYSTYPE
*lvalp
, parser_state_t
*state
);
207 static object_t
*newObject(parser_state_t
*state
);
208 static void freeObject(parser_state_t
*state
, object_t
*o
);
209 static void rememberObject(parser_state_t
*state
, int tag
, OSObject
*o
);
210 static object_t
*retrieveObject(parser_state_t
*state
, int tag
);
211 static void cleanupObjects(parser_state_t
*state
);
213 static object_t
*buildDictionary(parser_state_t
*state
, object_t
*o
);
214 static object_t
*buildArray(parser_state_t
*state
, object_t
*o
);
215 static object_t
*buildSet(parser_state_t
*state
, object_t
*o
);
216 static object_t
*buildString(parser_state_t
*state
, object_t
*o
);
217 static object_t
*buildSymbol(parser_state_t
*state
, object_t
*o
);
218 static object_t
*buildData(parser_state_t
*state
, object_t
*o
);
219 static object_t
*buildNumber(parser_state_t
*state
, object_t
*o
);
220 static object_t
*buildBoolean(parser_state_t
*state
, object_t
*o
);
222 #include <libkern/OSRuntime.h>
224 #define malloc(s) kern_os_malloc(s)
225 #define realloc(a, s) kern_os_realloc(a, s)
226 #define free(a) kern_os_free((void *)a)
230 /* Enabling traces. */
235 /* Enabling verbose error messages. */
236 #ifdef YYERROR_VERBOSE
237 # undef YYERROR_VERBOSE
238 # define YYERROR_VERBOSE 1
240 # define YYERROR_VERBOSE 0
243 /* Enabling the token table. */
244 #ifndef YYTOKEN_TABLE
245 # define YYTOKEN_TABLE 0
248 #if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED
250 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
251 # define YYSTYPE_IS_DECLARED 1
252 # define YYSTYPE_IS_TRIVIAL 1
257 /* Copy the second part of user declarations. */
260 /* Line 216 of yacc.c. */
261 #line 215 "OSUnserializeXML.tab.c"
268 typedef YYTYPE_UINT8 yytype_uint8
;
270 typedef unsigned char yytype_uint8
;
274 typedef YYTYPE_INT8 yytype_int8
;
275 #elif (defined __STDC__ || defined __C99__FUNC__ \
276 || defined __cplusplus || defined _MSC_VER)
277 typedef signed char yytype_int8
;
279 typedef short int yytype_int8
;
283 typedef YYTYPE_UINT16 yytype_uint16
;
285 typedef unsigned short int yytype_uint16
;
289 typedef YYTYPE_INT16 yytype_int16
;
291 typedef short int yytype_int16
;
295 # ifdef __SIZE_TYPE__
296 # define YYSIZE_T __SIZE_TYPE__
297 # elif defined size_t
298 # define YYSIZE_T size_t
299 # elif !defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
300 || defined __cplusplus || defined _MSC_VER)
301 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
302 # define YYSIZE_T size_t
304 # define YYSIZE_T unsigned int
308 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
311 # if defined YYENABLE_NLS && YYENABLE_NLS
313 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
314 # define YY_(msgid) dgettext ("bison-runtime", msgid)
318 # define YY_(msgid) msgid
322 /* Suppress unused-variable warnings by "using" E. */
323 #if !defined lint || defined __GNUC__
324 # define YYUSE(e) ((void) (e))
326 # define YYUSE(e) /* empty */
329 /* Identity function, used to suppress warnings about constant conditions. */
333 #if (defined __STDC__ || defined __C99__FUNC__ \
334 || defined __cplusplus || defined _MSC_VER)
347 #if !defined yyoverflow || YYERROR_VERBOSE
349 /* The parser invokes alloca or malloc; define the necessary symbols. */
351 # ifdef YYSTACK_USE_ALLOCA
352 # if YYSTACK_USE_ALLOCA
354 # define YYSTACK_ALLOC __builtin_alloca
355 # elif defined __BUILTIN_VA_ARG_INCR
356 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
358 # define YYSTACK_ALLOC __alloca
359 # elif defined _MSC_VER
360 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
361 # define alloca _alloca
363 # define YYSTACK_ALLOC alloca
364 # if !defined _ALLOCA_H && !defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
365 || defined __cplusplus || defined _MSC_VER)
366 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
375 # ifdef YYSTACK_ALLOC
376 /* Pacify GCC's `empty if-body' warning. */
377 # define YYSTACK_FREE(Ptr) do { /* empty */ ; } while (YYID (0))
378 # ifndef YYSTACK_ALLOC_MAXIMUM
379 /* The OS might guarantee only one guard page at the bottom of the stack,
380 * and a page size can be as small as 4096 bytes. So we cannot safely
381 * invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
382 * to allow for a few compiler-allocated temporary stack slots. */
383 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
386 # define YYSTACK_ALLOC YYMALLOC
387 # define YYSTACK_FREE YYFREE
388 # ifndef YYSTACK_ALLOC_MAXIMUM
389 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
391 # if (defined __cplusplus && !defined _STDLIB_H \
392 && !((defined YYMALLOC || defined malloc) \
393 && (defined YYFREE || defined free)))
394 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
400 # define YYMALLOC malloc
401 # if !defined malloc && !defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
402 || defined __cplusplus || defined _MSC_VER)
403 void *malloc(YYSIZE_T
); /* INFRINGES ON USER NAME SPACE */
408 # if !defined free && !defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
409 || defined __cplusplus || defined _MSC_VER)
410 void free(void *); /* INFRINGES ON USER NAME SPACE */
414 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
417 #if (!defined yyoverflow \
418 && (!defined __cplusplus \
419 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
421 /* A type that is properly aligned for any stack member. */
427 /* The size of the maximum gap between one aligned stack and the next. */
428 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
430 /* The size of an array large to enough to hold all stacks, each with
432 # define YYSTACK_BYTES(N) \
433 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
434 + YYSTACK_GAP_MAXIMUM)
436 /* Copy COUNT objects from FROM to TO. The source and destination do
439 # if defined __GNUC__ && 1 < __GNUC__
440 # define YYCOPY(To, From, Count) \
441 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
443 # define YYCOPY(To, From, Count) \
447 for (yyi = 0; yyi < (Count); yyi++) \
448 (To)[yyi] = (From)[yyi]; \
454 /* Relocate STACK from its old location to the new one. The
455 * local variables YYSIZE and YYSTACKSIZE give the old and new number of
456 * elements in the stack, and YYPTR gives the new location of the
457 * stack. Advance YYPTR to a properly aligned location for the next
459 # define YYSTACK_RELOCATE(Stack) \
462 YYSIZE_T yynewbytes; \
463 YYCOPY (&yyptr->Stack, Stack, yysize); \
464 Stack = &yyptr->Stack; \
465 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
466 yyptr += yynewbytes / sizeof (*yyptr); \
472 /* YYFINAL -- State number of the termination state. */
474 /* YYLAST -- Last index in YYTABLE. */
477 /* YYNTOKENS -- Number of terminals. */
479 /* YYNNTS -- Number of nonterminals. */
481 /* YYNRULES -- Number of rules. */
483 /* YYNRULES -- Number of states. */
486 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
488 #define YYMAXUTOK 267
490 #define YYTRANSLATE(YYX) \
491 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
493 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
494 static const yytype_uint8 yytranslate
[] =
496 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
497 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
498 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
499 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
500 15, 16, 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 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
505 2, 17, 2, 18, 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, 13, 2, 14, 2, 2, 2, 2,
509 2, 2, 2, 2, 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, 2, 2, 2, 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, 1, 2, 3, 4,
522 5, 6, 7, 8, 9, 10, 11, 12
526 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
528 static const yytype_uint8 yyprhs
[] =
530 0, 0, 3, 4, 6, 8, 10, 12, 14, 16,
531 18, 20, 22, 24, 27, 31, 33, 35, 38, 41,
532 43, 46, 50, 52, 55, 59, 61, 63, 66, 68,
536 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
537 static const yytype_int8 yyrhs
[] =
539 20, 0, -1, -1, 21, -1, 12, -1, 22, -1,
540 26, -1, 27, -1, 33, -1, 30, -1, 32, -1,
541 29, -1, 31, -1, 13, 14, -1, 13, 23, 14,
542 -1, 6, -1, 24, -1, 23, 24, -1, 25, 21,
543 -1, 8, -1, 15, 16, -1, 15, 28, 16, -1,
544 3, -1, 17, 18, -1, 17, 28, 18, -1, 10,
545 -1, 21, -1, 28, 21, -1, 4, -1, 5, -1,
549 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
550 static const yytype_uint16 yyrline
[] =
552 0, 149, 149, 152, 157, 162, 174, 186, 198, 210,
553 222, 234, 246, 265, 268, 271, 274, 275, 290, 299,
554 311, 314, 317, 320, 323, 326, 329, 332, 339, 342,
559 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
560 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
561 * First, the terminals, then, starting at YYNTOKENS, nonterminals. */
562 static const char *const yytname
[] =
564 "$end", "error", "$undefined", "ARRAY", "BOOLEAN", "DATA", "DICTIONARY",
565 "IDREF", "KEY", "NUMBER", "SET", "STRING", "SYNTAX_ERROR", "'{'", "'}'",
566 "'('", "')'", "'['", "']'", "$accept", "input", "object", "dict",
567 "pairs", "pair", "key", "array", "set", "elements", "boolean", "data",
568 "idref", "number", "string", 0
573 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
574 * token YYLEX-NUM. */
575 static const yytype_uint16 yytoknum
[] =
577 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
578 265, 266, 267, 123, 125, 40, 41, 91, 93
582 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
583 static const yytype_uint8 yyr1
[] =
585 0, 19, 20, 20, 20, 21, 21, 21, 21, 21,
586 21, 21, 21, 22, 22, 22, 23, 23, 24, 25,
587 26, 26, 26, 27, 27, 27, 28, 28, 29, 30,
591 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
592 static const yytype_uint8 yyr2
[] =
594 0, 2, 0, 1, 1, 1, 1, 1, 1, 1,
595 1, 1, 1, 2, 3, 1, 1, 2, 2, 1,
596 2, 3, 1, 2, 3, 1, 1, 2, 1, 1,
600 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
601 * STATE-NUM when YYTABLE doesn't specify something else to do. Zero
602 * means the default is an error. */
603 static const yytype_uint8 yydefact
[] =
605 2, 22, 28, 29, 15, 30, 31, 25, 32, 4,
606 0, 0, 0, 0, 3, 5, 6, 7, 11, 9,
607 12, 10, 8, 19, 13, 0, 16, 0, 20, 26,
608 0, 23, 0, 1, 14, 17, 18, 21, 27, 24
611 /* YYDEFGOTO[NTERM-NUM]. */
612 static const yytype_int8 yydefgoto
[] =
614 -1, 13, 29, 15, 25, 26, 27, 16, 17, 30,
618 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
620 #define YYPACT_NINF -20
621 static const yytype_int8 yypact
[] =
623 46, -20, -20, -20, -20, -20, -20, -20, -20, -20,
624 4, 61, -2, 10, -20, -20, -20, -20, -20, -20,
625 -20, -20, -20, -20, -20, 6, -20, 91, -20, -20,
626 76, -20, 30, -20, -20, -20, -20, -20, -20, -20
629 /* YYPGOTO[NTERM-NUM]. */
630 static const yytype_int8 yypgoto
[] =
632 -20, -20, 0, -20, -20, -19, -20, -20, -20, 5,
633 -20, -20, -20, -20, -20
636 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
637 * positive, shift that token. If negative, reduce the rule which
638 * number is the opposite. If zero, do what YYDEFACT says.
639 * If YYTABLE_NINF, syntax error. */
640 #define YYTABLE_NINF -1
641 static const yytype_uint8 yytable
[] =
643 14, 1, 2, 3, 4, 5, 35, 6, 7, 8,
644 33, 10, 23, 11, 23, 12, 31, 32, 24, 0,
645 34, 0, 0, 0, 0, 0, 0, 36, 0, 0,
646 38, 0, 38, 1, 2, 3, 4, 5, 0, 6,
647 7, 8, 0, 10, 0, 11, 0, 12, 39, 1,
648 2, 3, 4, 5, 0, 6, 7, 8, 9, 10,
649 0, 11, 0, 12, 1, 2, 3, 4, 5, 0,
650 6, 7, 8, 0, 10, 0, 11, 28, 12, 1,
651 2, 3, 4, 5, 0, 6, 7, 8, 0, 10,
652 0, 11, 37, 12, 1, 2, 3, 4, 5, 0,
653 6, 7, 8, 0, 10, 0, 11, 0, 12
656 static const yytype_int8 yycheck
[] =
658 0, 3, 4, 5, 6, 7, 25, 9, 10, 11,
659 0, 13, 8, 15, 8, 17, 18, 12, 14, -1,
660 14, -1, -1, -1, -1, -1, -1, 27, -1, -1,
661 30, -1, 32, 3, 4, 5, 6, 7, -1, 9,
662 10, 11, -1, 13, -1, 15, -1, 17, 18, 3,
663 4, 5, 6, 7, -1, 9, 10, 11, 12, 13,
664 -1, 15, -1, 17, 3, 4, 5, 6, 7, -1,
665 9, 10, 11, -1, 13, -1, 15, 16, 17, 3,
666 4, 5, 6, 7, -1, 9, 10, 11, -1, 13,
667 -1, 15, 16, 17, 3, 4, 5, 6, 7, -1,
668 9, 10, 11, -1, 13, -1, 15, -1, 17
671 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
672 * symbol of state STATE-NUM. */
673 static const yytype_uint8 yystos
[] =
675 0, 3, 4, 5, 6, 7, 9, 10, 11, 12,
676 13, 15, 17, 20, 21, 22, 26, 27, 29, 30,
677 31, 32, 33, 8, 14, 23, 24, 25, 16, 21,
678 28, 18, 28, 0, 14, 24, 21, 16, 21, 18
681 #define yyerrok (yyerrstatus = 0)
682 #define yyclearin (yychar = YYEMPTY)
686 #define YYACCEPT goto yyacceptlab
687 #define YYABORT goto yyabortlab
688 #define YYERROR goto yyerrorlab
691 /* Like YYERROR except do call yyerror. This remains here temporarily
692 * to ease the transition to the new meaning of YYERROR, for GCC.
693 * Once GCC version 2 has supplanted version 1, this can go. */
695 #define YYFAIL goto yyerrlab
697 #define YYRECOVERING() (!!yyerrstatus)
699 #define YYBACKUP(Token, Value) \
701 if (yychar == YYEMPTY && yylen == 1) \
705 yytoken = YYTRANSLATE (yychar); \
711 yyerror (YY_("syntax error: cannot back up")); \
718 #define YYERRCODE 256
721 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
722 * If N is 0, then set CURRENT to the empty location which ends
723 * the previous symbol: RHS[0] (always defined). */
725 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
726 #ifndef YYLLOC_DEFAULT
727 # define YYLLOC_DEFAULT(Current, Rhs, N) \
731 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
732 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
733 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
734 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
738 (Current).first_line = (Current).last_line = \
739 YYRHSLOC (Rhs, 0).last_line; \
740 (Current).first_column = (Current).last_column = \
741 YYRHSLOC (Rhs, 0).last_column; \
747 /* YY_LOCATION_PRINT -- Print the location on the stream.
748 * This macro was not mandated originally: define only if we know
749 * we won't break user code: when these are the locations we know. */
751 #ifndef YY_LOCATION_PRINT
752 # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
753 # define YY_LOCATION_PRINT(File, Loc) \
754 fprintf (File, "%d.%d-%d.%d", \
755 (Loc).first_line, (Loc).first_column, \
756 (Loc).last_line, (Loc).last_column)
758 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
763 /* YYLEX -- calling `yylex' with the right arguments. */
766 # define YYLEX yylex (&yylval, YYLEX_PARAM)
768 # define YYLEX yylex (&yylval)
771 /* Enable debugging if requested. */
775 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
776 # define YYFPRINTF fprintf
779 # define YYDPRINTF(Args) \
785 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
789 YYFPRINTF (stderr, "%s ", Title); \
790 yy_symbol_print (stderr, \
792 YYFPRINTF (stderr, "\n"); \
797 /*--------------------------------.
798 | Print this symbol on YYOUTPUT. |
799 | `--------------------------------*/
802 #if (defined __STDC__ || defined __C99__FUNC__ \
803 || defined __cplusplus || defined _MSC_VER)
805 yy_symbol_value_print(FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
)
808 yy_symbol_value_print(yyoutput
, yytype
, yyvaluep
)
811 YYSTYPE
const * const yyvaluep
;
818 if (yytype
< YYNTOKENS
) {
819 YYPRINT(yyoutput
, yytoknum
[yytype
], *yyvaluep
);
831 /*--------------------------------.
832 | Print this symbol on YYOUTPUT. |
833 | `--------------------------------*/
835 #if (defined __STDC__ || defined __C99__FUNC__ \
836 || defined __cplusplus || defined _MSC_VER)
838 yy_symbol_print(FILE *yyoutput
, int yytype
, YYSTYPE
const * const yyvaluep
)
841 yy_symbol_print(yyoutput
, yytype
, yyvaluep
)
844 YYSTYPE
const * const yyvaluep
;
847 if (yytype
< YYNTOKENS
) {
848 YYFPRINTF(yyoutput
, "token %s (", yytname
[yytype
]);
850 YYFPRINTF(yyoutput
, "nterm %s (", yytname
[yytype
]);
853 yy_symbol_value_print(yyoutput
, yytype
, yyvaluep
);
854 YYFPRINTF(yyoutput
, ")");
857 /*------------------------------------------------------------------.
858 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
860 | `------------------------------------------------------------------*/
862 #if (defined __STDC__ || defined __C99__FUNC__ \
863 || defined __cplusplus || defined _MSC_VER)
865 yy_stack_print(yytype_int16
*bottom
, yytype_int16
*top
)
868 yy_stack_print(bottom
, top
)
869 yytype_int16
*bottom
;
873 YYFPRINTF(stderr
, "Stack now");
874 for (; bottom
<= top
; ++bottom
) {
875 YYFPRINTF(stderr
, " %d", *bottom
);
877 YYFPRINTF(stderr
, "\n");
880 # define YY_STACK_PRINT(Bottom, Top) \
883 yy_stack_print ((Bottom), (Top)); \
887 /*------------------------------------------------.
888 | Report that the YYRULE is going to be reduced. |
889 | `------------------------------------------------*/
891 #if (defined __STDC__ || defined __C99__FUNC__ \
892 || defined __cplusplus || defined _MSC_VER)
894 yy_reduce_print(YYSTYPE
*yyvsp
, int yyrule
)
897 yy_reduce_print(yyvsp
, yyrule
)
902 int yynrhs
= yyr2
[yyrule
];
904 unsigned long int yylno
= yyrline
[yyrule
];
905 YYFPRINTF(stderr
, "Reducing stack by rule %d (line %lu):\n",
907 /* The symbols being reduced. */
908 for (yyi
= 0; yyi
< yynrhs
; yyi
++) {
909 fprintf(stderr
, " $%d = ", yyi
+ 1);
910 yy_symbol_print(stderr
, yyrhs
[yyprhs
[yyrule
] + yyi
],
911 &(yyvsp
[(yyi
+ 1) - (yynrhs
)])
913 fprintf(stderr
, "\n");
917 # define YY_REDUCE_PRINT(Rule) \
920 yy_reduce_print (yyvsp, Rule); \
923 /* Nonzero means print parse trace. It is left uninitialized so that
924 * multiple parsers can coexist. */
927 # define YYDPRINTF(Args)
928 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
929 # define YY_STACK_PRINT(Bottom, Top)
930 # define YY_REDUCE_PRINT(Rule)
931 #endif /* !YYDEBUG */
934 /* YYINITDEPTH -- initial size of the parser's stacks. */
936 # define YYINITDEPTH 64
939 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
940 * if the built-in stack extension method is used).
942 * Do not make this value too large; the results are undefined if
943 * YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
944 * evaluated with infinite-precision integer arithmetic. */
947 # define YYMAXDEPTH 10000
955 # if defined __GLIBC__ && defined _STRING_H
956 # define yystrlen strlen
958 /* Return the length of YYSTR. */
959 #if (defined __STDC__ || defined __C99__FUNC__ \
960 || defined __cplusplus || defined _MSC_VER)
962 yystrlen(const char *yystr
)
970 for (yylen
= 0; yystr
[yylen
]; yylen
++) {
979 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
980 # define yystpcpy stpcpy
982 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
984 #if (defined __STDC__ || defined __C99__FUNC__ \
985 || defined __cplusplus || defined _MSC_VER)
987 yystpcpy(char *yydest
, const char *yysrc
)
990 yystpcpy(yydest
, yysrc
)
996 const char *yys
= yysrc
;
998 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
1014 * would have been. */
1016 yytnamerr(char *yyres
, const char *yystr
)
1018 if (*yystr
== '"') {
1020 char const *yyp
= yystr
;
1026 goto do_not_strip_quotes
;
1029 if (*++yyp
!= '\\') {
1030 goto do_not_strip_quotes
;
1047 do_not_strip_quotes
:;
1051 return yystrlen(yystr
);
1054 return yystpcpy(yyres
, yystr
) - yyres
;
1058 /* Copy into YYRESULT an error message about the unexpected token
1059 * YYCHAR while in state YYSTATE. Return the number of bytes copied,
1060 * including the terminating null byte. If YYRESULT is null, do not
1061 * copy anything; just return the number of bytes that would be
1062 * copied. As a special case, return 0 if an ordinary "syntax error"
1063 * message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1064 * size calculation. */
1066 yysyntax_error(char *yyresult
, int yystate
, int yychar
)
1068 int yyn
= yypact
[yystate
];
1070 if (!(YYPACT_NINF
< yyn
&& yyn
<= YYLAST
)) {
1073 int yytype
= YYTRANSLATE(yychar
);
1074 YYSIZE_T yysize0
= yytnamerr(0, yytname
[yytype
]);
1075 YYSIZE_T yysize
= yysize0
;
1077 int yysize_overflow
= 0;
1078 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1079 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1083 /* This is so xgettext sees the translatable formats that are
1084 * constructed on the fly. */
1085 YY_("syntax error, unexpected %s");
1086 YY_("syntax error, unexpected %s, expecting %s");
1087 YY_("syntax error, unexpected %s, expecting %s or %s");
1088 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1089 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1093 static char const yyunexpected
[] = "syntax error, unexpected %s";
1094 static char const yyexpecting
[] = ", expecting %s";
1095 static char const yyor
[] = " or %s";
1096 char yyformat
[sizeof yyunexpected
1097 + sizeof yyexpecting
- 1
1098 + ((YYERROR_VERBOSE_ARGS_MAXIMUM
- 2)
1099 * (sizeof yyor
- 1))];
1100 char const *yyprefix
= yyexpecting
;
1102 /* Start YYX at -YYN if negative to avoid negative indexes in
1104 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1106 /* Stay within bounds of both yycheck and yytname. */
1107 int yychecklim
= YYLAST
- yyn
+ 1;
1108 int yyxend
= yychecklim
< YYNTOKENS
? yychecklim
: YYNTOKENS
;
1111 yyarg
[0] = yytname
[yytype
];
1112 yyfmt
= yystpcpy(yyformat
, yyunexpected
);
1114 for (yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
) {
1115 if (yycheck
[yyx
+ yyn
] == yyx
&& yyx
!= YYTERROR
) {
1116 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
);
1131 yyf
= YY_(yyformat
);
1132 yysize1
= yysize
+ yystrlen(yyf
);
1133 yysize_overflow
|= (yysize1
< yysize
);
1136 if (yysize_overflow
) {
1137 return YYSIZE_MAXIMUM
;
1141 /* Avoid sprintf, as that infringes on the user's name space.
1142 * Don't have undefined behavior even if the translation
1143 * produced a string with the wrong number of "%s"s. */
1144 char *yyp
= yyresult
;
1146 while ((*yyp
= *yyf
) != '\0') {
1147 if (*yyp
== '%' && yyf
[1] == 's' && yyi
< yycount
) {
1148 yyp
+= yytnamerr(yyp
, yyarg
[yyi
++]);
1159 #endif /* YYERROR_VERBOSE */
1162 /*-----------------------------------------------.
1163 | Release the memory associated to this symbol. |
1164 | `-----------------------------------------------*/
1167 #if (defined __STDC__ || defined __C99__FUNC__ \
1168 || defined __cplusplus || defined _MSC_VER)
1170 yydestruct(const char *yymsg
, int yytype
, YYSTYPE
*yyvaluep
)
1173 yydestruct(yymsg
, yytype
, yyvaluep
)
1184 YY_SYMBOL_PRINT(yymsg
, yytype
, yyvaluep
, yylocationp
);
1193 /* Prevent warnings from -Wmissing-prototypes. */
1195 #ifdef YYPARSE_PARAM
1196 #if defined __STDC__ || defined __cplusplus
1197 int yyparse(void *YYPARSE_PARAM
);
1201 #else /* ! YYPARSE_PARAM */
1202 #if defined __STDC__ || defined __cplusplus
1207 #endif /* ! YYPARSE_PARAM */
1218 #ifdef YYPARSE_PARAM
1219 #if (defined __STDC__ || defined __C99__FUNC__ \
1220 || defined __cplusplus || defined _MSC_VER)
1222 yyparse(void *YYPARSE_PARAM
)
1225 yyparse(YYPARSE_PARAM
)
1226 void *YYPARSE_PARAM
;
1228 #else /* ! YYPARSE_PARAM */
1229 #if (defined __STDC__ || defined __C99__FUNC__ \
1230 || defined __cplusplus || defined _MSC_VER)
1240 /* The look-ahead symbol. */
1243 /* The semantic value of the look-ahead symbol. */
1246 /* Number of syntax errors so far. */
1252 /* Number of tokens to shift before error messages enabled. */
1254 /* Look-ahead token as an internal (translated) token number. */
1257 /* Buffer for error messages, and its allocated size. */
1259 char *yymsg
= yymsgbuf
;
1260 YYSIZE_T yymsg_alloc
= sizeof yymsgbuf
;
1263 /* Three stacks and their tools:
1264 * `yyss': related to states,
1265 * `yyvs': related to semantic values,
1266 * `yyls': related to locations.
1268 * Refer to the stacks thru separate pointers, to allow yyoverflow
1269 * to reallocate them elsewhere. */
1271 /* The state stack. */
1272 yytype_int16 yyssa
[YYINITDEPTH
];
1273 yytype_int16
*yyss
= yyssa
;
1274 yytype_int16
*yyssp
;
1276 /* The semantic value stack. */
1277 YYSTYPE yyvsa
[YYINITDEPTH
];
1278 YYSTYPE
*yyvs
= yyvsa
;
1283 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1285 YYSIZE_T yystacksize
= YYINITDEPTH
;
1287 /* The variables used to return semantic value and location from the
1288 * action routines. */
1292 /* The number of symbols on the RHS of the reduced rule.
1293 * Keep to zero when no symbol should be popped. */
1296 YYDPRINTF((stderr
, "Starting parse\n"));
1301 yychar
= YYEMPTY
; /* Cause a token to be read. */
1303 /* Initialize stack pointers.
1304 * Waste one element of value and location stack
1305 * so that they stay on the same level as the state stack.
1306 * The wasted elements are never initialized. */
1313 /*------------------------------------------------------------.
1314 | yynewstate -- Push a new state, which is found in yystate. |
1315 | `------------------------------------------------------------*/
1317 /* In all cases, when you get here, the value and location stacks
1318 * have just been pushed. So pushing a state here evens the stacks. */
1324 if (yyss
+ yystacksize
- 1 <= yyssp
) {
1325 /* Get the current used size of the three stacks, in elements. */
1326 YYSIZE_T yysize
= yyssp
- yyss
+ 1;
1330 /* Give user a chance to reallocate the stack. Use copies of
1331 * these so that the &'s don't force the real ones into
1333 YYSTYPE
*yyvs1
= yyvs
;
1334 yytype_int16
*yyss1
= yyss
;
1337 /* Each stack pointer address is followed by the size of the
1338 * data in use in that stack, in bytes. This used to be a
1339 * conditional around just the two extra args, but that might
1340 * be undefined if yyoverflow is a macro. */
1341 yyoverflow(YY_("memory exhausted"),
1342 &yyss1
, yysize
* sizeof(*yyssp
),
1343 &yyvs1
, yysize
* sizeof(*yyvsp
),
1350 #else /* no yyoverflow */
1351 # ifndef YYSTACK_RELOCATE
1352 goto yyexhaustedlab
;
1354 /* Extend the stack our own way. */
1355 if (YYMAXDEPTH
<= yystacksize
) {
1356 goto yyexhaustedlab
;
1359 if (YYMAXDEPTH
< yystacksize
) {
1360 yystacksize
= YYMAXDEPTH
;
1364 yytype_int16
*yyss1
= yyss
;
1365 union yyalloc
*yyptr
=
1366 (union yyalloc
*) YYSTACK_ALLOC(YYSTACK_BYTES(yystacksize
));
1368 goto yyexhaustedlab
;
1370 YYSTACK_RELOCATE(yyss
);
1371 YYSTACK_RELOCATE(yyvs
);
1373 # undef YYSTACK_RELOCATE
1374 if (yyss1
!= yyssa
) {
1375 YYSTACK_FREE(yyss1
);
1379 #endif /* no yyoverflow */
1381 yyssp
= yyss
+ yysize
- 1;
1382 yyvsp
= yyvs
+ yysize
- 1;
1385 YYDPRINTF((stderr
, "Stack size increased to %lu\n",
1386 (unsigned long int) yystacksize
));
1388 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
) {
1411 /* Not known => get a look-ahead token if don't already have one. */
1413 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1414 if (yychar
== YYEMPTY
) {
1415 YYDPRINTF((stderr
, "Reading a token: "));
1419 if (yychar
<= YYEOF
) {
1420 yychar
= yytoken
= YYEOF
;
1421 YYDPRINTF((stderr
, "Now at end of input.\n"));
1423 yytoken
= YYTRANSLATE(yychar
);
1424 YY_SYMBOL_PRINT("Next token is", yytoken
, &yylval
, &yylloc
);
1427 /* If the proper action on seeing token YYTOKEN is to reduce or to
1428 * detect an error, take that action. */
1430 if (yyn
< 0 || YYLAST
< yyn
|| yycheck
[yyn
] != yytoken
) {
1435 if (yyn
== 0 || yyn
== YYTABLE_NINF
) {
1442 if (yyn
== YYFINAL
) {
1446 /* 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
) {
1466 /*-----------------------------------------------------------.
1467 | yydefault -- do the default action for the current state. |
1468 | `-----------------------------------------------------------*/
1470 yyn
= yydefact
[yystate
];
1477 /*-----------------------------.
1478 | yyreduce -- Do a reduction. |
1479 | `-----------------------------*/
1481 /* yyn is the number of a rule to reduce with. */
1484 /* If YYLEN is nonzero, implement the default value of the action:
1487 * Otherwise, the following line sets YYVAL to garbage.
1488 * This behavior is undocumented and Bison
1489 * users should not rely upon it. Assigning to YYVAL
1490 * unconditionally makes the parser a bit smaller, and it avoids a
1491 * GCC warning that YYVAL may be used uninitialized. */
1492 yyval
= yyvsp
[1 - yylen
];
1495 YY_REDUCE_PRINT(yyn
);
1498 #line 149 "OSUnserializeXML.y"
1499 { yyerror("unexpected end of buffer");
1505 #line 152 "OSUnserializeXML.y"
1506 { STATE
->parsedObject
= (yyvsp
[(1) - (1)])->object
;
1507 (yyvsp
[(1) - (1)])->object
= 0;
1508 freeObject(STATE
, (yyvsp
[(1) - (1)]));
1514 #line 157 "OSUnserializeXML.y"
1515 { yyerror("syntax error");
1521 #line 162 "OSUnserializeXML.y"
1522 { (yyval
) = buildDictionary(STATE
, (yyvsp
[(1) - (1)]));
1524 if (!yyval
->object
) {
1525 yyerror("buildDictionary");
1528 STATE
->parsedObjectCount
++;
1529 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1530 yyerror("maximum object count");
1537 #line 174 "OSUnserializeXML.y"
1538 { (yyval
) = buildArray(STATE
, (yyvsp
[(1) - (1)]));
1540 if (!yyval
->object
) {
1541 yyerror("buildArray");
1544 STATE
->parsedObjectCount
++;
1545 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1546 yyerror("maximum object count");
1553 #line 186 "OSUnserializeXML.y"
1554 { (yyval
) = buildSet(STATE
, (yyvsp
[(1) - (1)]));
1556 if (!yyval
->object
) {
1557 yyerror("buildSet");
1560 STATE
->parsedObjectCount
++;
1561 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1562 yyerror("maximum object count");
1569 #line 198 "OSUnserializeXML.y"
1570 { (yyval
) = buildString(STATE
, (yyvsp
[(1) - (1)]));
1572 if (!yyval
->object
) {
1573 yyerror("buildString");
1576 STATE
->parsedObjectCount
++;
1577 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1578 yyerror("maximum object count");
1585 #line 210 "OSUnserializeXML.y"
1586 { (yyval
) = buildData(STATE
, (yyvsp
[(1) - (1)]));
1588 if (!yyval
->object
) {
1589 yyerror("buildData");
1592 STATE
->parsedObjectCount
++;
1593 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1594 yyerror("maximum object count");
1601 #line 222 "OSUnserializeXML.y"
1602 { (yyval
) = buildNumber(STATE
, (yyvsp
[(1) - (1)]));
1604 if (!yyval
->object
) {
1605 yyerror("buildNumber");
1608 STATE
->parsedObjectCount
++;
1609 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1610 yyerror("maximum object count");
1617 #line 234 "OSUnserializeXML.y"
1618 { (yyval
) = buildBoolean(STATE
, (yyvsp
[(1) - (1)]));
1620 if (!yyval
->object
) {
1621 yyerror("buildBoolean");
1624 STATE
->parsedObjectCount
++;
1625 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1626 yyerror("maximum object count");
1633 #line 246 "OSUnserializeXML.y"
1634 { (yyval
) = retrieveObject(STATE
, (yyvsp
[(1) - (1)])->idref
);
1636 STATE
->retrievedObjectCount
++;
1637 (yyval
)->object
->retain();
1638 if (STATE
->retrievedObjectCount
> MAX_REFED_OBJECTS
) {
1639 yyerror("maximum object reference count");
1643 yyerror("forward reference detected");
1646 freeObject(STATE
, (yyvsp
[(1) - (1)]));
1648 STATE
->parsedObjectCount
++;
1649 if (STATE
->parsedObjectCount
> MAX_OBJECTS
) {
1650 yyerror("maximum object count");
1657 #line 265 "OSUnserializeXML.y"
1658 { (yyval
) = (yyvsp
[(1) - (2)]);
1659 (yyval
)->elements
= NULL
;
1664 #line 268 "OSUnserializeXML.y"
1665 { (yyval
) = (yyvsp
[(1) - (3)]);
1666 (yyval
)->elements
= (yyvsp
[(2) - (3)]);
1671 #line 275 "OSUnserializeXML.y"
1672 { (yyval
) = (yyvsp
[(2) - (2)]);
1673 (yyval
)->next
= (yyvsp
[(1) - (2)]);
1678 if (o
->key
== (yyval
)->key
) {
1679 yyerror("duplicate dictionary key");
1688 #line 290 "OSUnserializeXML.y"
1689 { (yyval
) = (yyvsp
[(1) - (2)]);
1690 (yyval
)->key
= (OSSymbol
*)(yyval
)->object
;
1691 (yyval
)->object
= (yyvsp
[(2) - (2)])->object
;
1692 (yyval
)->next
= NULL
;
1693 (yyvsp
[(2) - (2)])->object
= 0;
1694 freeObject(STATE
, (yyvsp
[(2) - (2)]));
1699 #line 299 "OSUnserializeXML.y"
1700 { (yyval
) = buildSymbol(STATE
, (yyvsp
[(1) - (1)]));
1702 // STATE->parsedObjectCount++;
1703 // if (STATE->parsedObjectCount > MAX_OBJECTS) {
1704 // yyerror("maximum object count");
1711 #line 311 "OSUnserializeXML.y"
1712 { (yyval
) = (yyvsp
[(1) - (2)]);
1713 (yyval
)->elements
= NULL
;
1718 #line 314 "OSUnserializeXML.y"
1719 { (yyval
) = (yyvsp
[(1) - (3)]);
1720 (yyval
)->elements
= (yyvsp
[(2) - (3)]);
1725 #line 320 "OSUnserializeXML.y"
1726 { (yyval
) = (yyvsp
[(1) - (2)]);
1727 (yyval
)->elements
= NULL
;
1732 #line 323 "OSUnserializeXML.y"
1733 { (yyval
) = (yyvsp
[(1) - (3)]);
1734 (yyval
)->elements
= (yyvsp
[(2) - (3)]);
1739 #line 329 "OSUnserializeXML.y"
1740 { (yyval
) = (yyvsp
[(1) - (1)]);
1741 (yyval
)->next
= NULL
;
1746 #line 332 "OSUnserializeXML.y"
1747 { (yyval
) = (yyvsp
[(2) - (2)]);
1748 (yyval
)->next
= (yyvsp
[(1) - (2)]);
1753 /* Line 1267 of yacc.c. */
1754 #line 1699 "OSUnserializeXML.tab.c"
1757 YY_SYMBOL_PRINT("-> $$ =", yyr1
[yyn
], &yyval
, &yyloc
);
1761 YY_STACK_PRINT(yyss
, yyssp
);
1766 /* Now `shift' the result of the reduction. Determine what state
1767 * that goes to, based on the state we popped back to and the rule
1768 * number reduced by. */
1772 yystate
= yypgoto
[yyn
- YYNTOKENS
] + *yyssp
;
1773 if (0 <= yystate
&& yystate
<= YYLAST
&& yycheck
[yystate
] == *yyssp
) {
1774 yystate
= yytable
[yystate
];
1776 yystate
= yydefgoto
[yyn
- YYNTOKENS
];
1782 /*------------------------------------.
1783 | yyerrlab -- here on detecting error |
1784 | `------------------------------------*/
1786 /* If not already recovering from an error, report this error. */
1789 #if !YYERROR_VERBOSE
1790 yyerror(YY_("syntax error"));
1793 YYSIZE_T yysize
= yysyntax_error(0, yystate
, yychar
);
1794 if (yymsg_alloc
< yysize
&& yymsg_alloc
< YYSTACK_ALLOC_MAXIMUM
) {
1795 YYSIZE_T yyalloc
= 2 * yysize
;
1796 if (!(yysize
<= yyalloc
&& yyalloc
<= YYSTACK_ALLOC_MAXIMUM
)) {
1797 yyalloc
= YYSTACK_ALLOC_MAXIMUM
;
1799 if (yymsg
!= yymsgbuf
) {
1800 YYSTACK_FREE(yymsg
);
1802 yymsg
= (char *) YYSTACK_ALLOC(yyalloc
);
1804 yymsg_alloc
= yyalloc
;
1807 yymsg_alloc
= sizeof yymsgbuf
;
1811 if (0 < yysize
&& yysize
<= yymsg_alloc
) {
1812 (void) yysyntax_error(yymsg
, yystate
, yychar
);
1815 yyerror(YY_("syntax error"));
1817 goto yyexhaustedlab
;
1826 if (yyerrstatus
== 3) {
1827 /* If just tried and failed to reuse look-ahead token after an
1828 * error, discard it. */
1830 if (yychar
<= YYEOF
) {
1831 /* Return failure if at end of input. */
1832 if (yychar
== YYEOF
) {
1836 yydestruct("Error: discarding",
1842 /* Else will try to reuse look-ahead token after shifting the error
1847 /*---------------------------------------------------.
1848 | yyerrorlab -- error raised explicitly by YYERROR. |
1849 | `---------------------------------------------------*/
1852 /* Pacify compilers like GCC when the user code never invokes
1853 * YYERROR and the label yyerrorlab therefore never appears in user
1855 if (/*CONSTCOND*/ 0) {
1859 /* Do not reclaim the symbols of the rule which action triggered
1863 YY_STACK_PRINT(yyss
, yyssp
);
1868 /*-------------------------------------------------------------.
1869 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1870 | `-------------------------------------------------------------*/
1872 yyerrstatus
= 3; /* Each real token shifted decrements this. */
1875 yyn
= yypact
[yystate
];
1876 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. */
1887 if (yyssp
== yyss
) {
1892 yydestruct("Error: popping",
1893 yystos
[yystate
], yyvsp
);
1896 YY_STACK_PRINT(yyss
, yyssp
);
1899 if (yyn
== YYFINAL
) {
1906 /* Shift the error token. */
1907 YY_SYMBOL_PRINT("Shifting", yystos
[yyn
], yyvsp
, yylsp
);
1913 /*-------------------------------------.
1914 | yyacceptlab -- YYACCEPT comes here. |
1915 | `-------------------------------------*/
1920 /*-----------------------------------.
1921 | yyabortlab -- YYABORT comes here. |
1922 | `-----------------------------------*/
1928 /*-------------------------------------------------.
1929 | yyexhaustedlab -- memory exhaustion comes here. |
1930 | `-------------------------------------------------*/
1932 yyerror(YY_("memory exhausted"));
1938 if (yychar
!= YYEOF
&& yychar
!= YYEMPTY
) {
1939 yydestruct("Cleanup: discarding lookahead",
1942 /* Do not reclaim the symbols of the rule which action triggered
1943 * this YYABORT or YYACCEPT. */
1945 YY_STACK_PRINT(yyss
, yyssp
);
1946 while (yyssp
!= yyss
) {
1947 yydestruct("Cleanup: popping",
1948 yystos
[*yyssp
], yyvsp
);
1952 if (yyss
!= yyssa
) {
1957 if (yymsg
!= yymsgbuf
) {
1958 YYSTACK_FREE(yymsg
);
1961 /* Make sure YYID is used. */
1962 return YYID(yyresult
);
1966 #line 354 "OSUnserializeXML.y"
1970 OSUnserializeerror(parser_state_t
* state
, const char *s
) /* Called by yyparse on errors */
1972 if (state
->errorString
) {
1973 char tempString
[128];
1974 snprintf(tempString
, 128, "OSUnserializeXML: %s near line %d\n", s
, state
->lineNumber
);
1975 *(state
->errorString
) = OSString::withCString(tempString
);
1981 #define TAG_MAX_LENGTH 32
1982 #define TAG_MAX_ATTRIBUTES 32
1987 #define TAG_IGNORE 4
1989 #define currentChar() (state->parseBuffer[state->parseBufferIndex])
1990 #define nextChar() (state->parseBuffer[++state->parseBufferIndex])
1991 #define prevChar() (state->parseBuffer[state->parseBufferIndex - 1])
1993 #define isSpace(c) ((c) == ' ' || (c) == '\t')
1994 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
1995 #define isDigit(c) ((c) >= '0' && (c) <= '9')
1996 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f')
1997 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
1998 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-'))
2001 getTag(parser_state_t
*state
,
2002 char tag
[TAG_MAX_LENGTH
],
2003 int *attributeCount
,
2004 char attributes
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
],
2005 char values
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
] )
2008 int c
= currentChar();
2009 int tagType
= TAG_START
;
2011 *attributeCount
= 0;
2016 c
= nextChar(); // skip '<'
2019 // <!TAG declarations >
2020 // <!-- comments -->
2023 bool isComment
= (c
== '-') && ((c
= nextChar()) != 0) && (c
== '-');
2024 if (!isComment
&& !isAlpha(c
)) {
2025 return TAG_BAD
; // <!1, <!-A, <!eos
2027 while (c
&& (c
= nextChar()) != 0) {
2029 state
->lineNumber
++;
2051 // <? Processing Instructions ?>
2053 while ((c
= nextChar()) != 0) {
2055 state
->lineNumber
++;
2073 c
= nextChar(); // skip '/'
2080 /* find end of tag while copying it */
2081 while (isAlphaNumeric(c
)) {
2084 if (length
>= (TAG_MAX_LENGTH
- 1)) {
2091 // printf("tag %s, type %d\n", tag, tagType);
2093 // look for attributes of the form attribute = "value" ...
2094 while ((c
!= '>') && (c
!= '/')) {
2095 while (isSpace(c
)) {
2100 while (isAlphaNumeric(c
)) {
2101 attributes
[*attributeCount
][length
++] = c
;
2102 if (length
>= (TAG_MAX_LENGTH
- 1)) {
2107 attributes
[*attributeCount
][length
] = 0;
2109 while (isSpace(c
)) {
2118 while (isSpace(c
)) {
2128 values
[*attributeCount
][length
++] = c
;
2129 if (length
>= (TAG_MAX_LENGTH
- 1)) {
2137 values
[*attributeCount
][length
] = 0;
2139 c
= nextChar(); // skip closing quote
2141 // printf(" attribute '%s' = '%s', nextchar = '%c'\n",
2142 // attributes[*attributeCount], values[*attributeCount], c);
2144 (*attributeCount
)++;
2145 if (*attributeCount
>= TAG_MAX_ATTRIBUTES
) {
2151 c
= nextChar(); // skip '/'
2152 tagType
= TAG_EMPTY
;
2157 c
= nextChar(); // skip '>'
2163 getString(parser_state_t
*state
)
2165 int c
= currentChar();
2166 int start
, length
, i
, j
;
2169 start
= state
->parseBufferIndex
;
2170 /* find end of string */
2174 state
->lineNumber
++;
2186 length
= state
->parseBufferIndex
- start
;
2188 /* copy to null terminated buffer */
2189 tempString
= (char *)malloc(length
+ 1);
2190 if (tempString
== 0) {
2191 printf("OSUnserializeXML: can't alloc temp memory\n");
2195 // copy out string in tempString
2196 // "&" -> '&', "<" -> '<', ">" -> '>'
2199 while (i
< length
) {
2200 c
= state
->parseBuffer
[start
+ i
++];
2202 tempString
[j
++] = c
;
2204 if ((i
+ 3) > length
) {
2207 c
= state
->parseBuffer
[start
+ i
++];
2209 if (state
->parseBuffer
[start
+ i
++] != 't') {
2212 if (state
->parseBuffer
[start
+ i
++] != ';') {
2215 tempString
[j
++] = '<';
2219 if (state
->parseBuffer
[start
+ i
++] != 't') {
2222 if (state
->parseBuffer
[start
+ i
++] != ';') {
2225 tempString
[j
++] = '>';
2228 if ((i
+ 3) > length
) {
2232 if (state
->parseBuffer
[start
+ i
++] != 'm') {
2235 if (state
->parseBuffer
[start
+ i
++] != 'p') {
2238 if (state
->parseBuffer
[start
+ i
++] != ';') {
2241 tempString
[j
++] = '&';
2249 // printf("string %s\n", tempString);
2261 getNumber(parser_state_t
*state
)
2263 unsigned long long n
= 0;
2265 bool negate
= false;
2266 int c
= currentChar();
2280 while (isDigit(c
)) {
2281 n
= (n
* base
+ c
- '0');
2285 n
= (unsigned long long)((long long)n
* (long long)-1);
2288 while (isHexDigit(c
)) {
2290 n
= (n
* base
+ c
- '0');
2292 n
= (n
* base
+ 0xa + c
- 'a');
2297 // printf("number 0x%x\n", (unsigned long)n);
2301 // taken from CFXMLParsing/CFPropertyList.c
2303 static const signed char __CFPLDataDecodeTable
[128] = {
2304 /* 000 */ -1, -1, -1, -1, -1, -1, -1, -1,
2305 /* 010 */ -1, -1, -1, -1, -1, -1, -1, -1,
2306 /* 020 */ -1, -1, -1, -1, -1, -1, -1, -1,
2307 /* 030 */ -1, -1, -1, -1, -1, -1, -1, -1,
2308 /* ' ' */ -1, -1, -1, -1, -1, -1, -1, -1,
2309 /* '(' */ -1, -1, -1, 62, -1, -1, -1, 63,
2310 /* '0' */ 52, 53, 54, 55, 56, 57, 58, 59,
2311 /* '8' */ 60, 61, -1, -1, -1, 0, -1, -1,
2312 /* '@' */ -1, 0, 1, 2, 3, 4, 5, 6,
2313 /* 'H' */ 7, 8, 9, 10, 11, 12, 13, 14,
2314 /* 'P' */ 15, 16, 17, 18, 19, 20, 21, 22,
2315 /* 'X' */ 23, 24, 25, -1, -1, -1, -1, -1,
2316 /* '`' */ -1, 26, 27, 28, 29, 30, 31, 32,
2317 /* 'h' */ 33, 34, 35, 36, 37, 38, 39, 40,
2318 /* 'p' */ 41, 42, 43, 44, 45, 46, 47, 48,
2319 /* 'x' */ 49, 50, 51, -1, -1, -1, -1, -1
2322 #define DATA_ALLOC_SIZE 4096
2325 getCFEncodedData(parser_state_t
*state
, unsigned int *size
)
2327 int numeq
= 0, acc
= 0, cntr
= 0;
2328 int tmpbufpos
= 0, tmpbuflen
= 0;
2329 unsigned char *tmpbuf
= (unsigned char *)malloc(DATA_ALLOC_SIZE
);
2331 int c
= currentChar();
2346 state
->lineNumber
++;
2348 if (__CFPLDataDecodeTable
[c
] < 0) {
2354 acc
+= __CFPLDataDecodeTable
[c
];
2355 if (0 == (cntr
& 0x3)) {
2356 if (tmpbuflen
<= tmpbufpos
+ 2) {
2357 tmpbuflen
+= DATA_ALLOC_SIZE
;
2358 tmpbuf
= (unsigned char *)realloc(tmpbuf
, tmpbuflen
);
2360 tmpbuf
[tmpbufpos
++] = (acc
>> 16) & 0xff;
2362 tmpbuf
[tmpbufpos
++] = (acc
>> 8) & 0xff;
2365 tmpbuf
[tmpbufpos
++] = acc
& 0xff;
2379 getHexData(parser_state_t
*state
, unsigned int *size
)
2382 unsigned char *d
, *start
, *lastStart
;
2384 start
= lastStart
= d
= (unsigned char *)malloc(DATA_ALLOC_SIZE
);
2389 while ((c
= nextChar()) != 0 && isSpace(c
)) {
2394 state
->lineNumber
++;
2401 *d
= (c
- '0') << 4;
2402 } else if (isAlphaDigit(c
)) {
2403 *d
= (0xa + (c
- 'a')) << 4;
2412 } else if (isAlphaDigit(c
)) {
2413 *d
|= 0xa + (c
- 'a');
2419 if ((d
- lastStart
) >= DATA_ALLOC_SIZE
) {
2420 int oldsize
= d
- start
;
2421 start
= (unsigned char *)realloc(start
, oldsize
+ DATA_ALLOC_SIZE
);
2422 d
= lastStart
= start
+ oldsize
;
2438 yylex(YYSTYPE
*lvalp
, parser_state_t
*state
)
2442 char tag
[TAG_MAX_LENGTH
];
2444 char attributes
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
];
2445 char values
[TAG_MAX_ATTRIBUTES
][TAG_MAX_LENGTH
];
2451 /* skip white space */
2453 while ((c
= nextChar()) != 0 && isSpace(c
)) {
2458 /* keep track of line number, don't return \n's */
2460 STATE
->lineNumber
++;
2465 // end of the buffer?
2470 tagType
= getTag(STATE
, tag
, &attributeCount
, attributes
, values
);
2471 if (tagType
== TAG_BAD
) {
2472 return SYNTAX_ERROR
;
2474 if (tagType
== TAG_IGNORE
) {
2478 // handle allocation and check for "ID" and "IDREF" tags up front
2479 *lvalp
= object
= newObject(STATE
);
2481 for (i
= 0; i
< attributeCount
; i
++) {
2482 if (attributes
[i
][0] == 'I' && attributes
[i
][1] == 'D') {
2483 // check for idref's, note: we ignore the tag, for
2484 // this to work correctly, all idrefs must be unique
2485 // across the whole serialization
2486 if (attributes
[i
][2] == 'R' && attributes
[i
][3] == 'E' &&
2487 attributes
[i
][4] == 'F' && !attributes
[i
][5]) {
2488 if (tagType
!= TAG_EMPTY
) {
2489 return SYNTAX_ERROR
;
2491 object
->idref
= strtol(values
[i
], NULL
, 0);
2495 if (!attributes
[i
][2]) {
2496 object
->idref
= strtol(values
[i
], NULL
, 0);
2498 return SYNTAX_ERROR
;
2505 if (!strcmp(tag
, "array")) {
2506 if (tagType
== TAG_EMPTY
) {
2507 object
->elements
= NULL
;
2510 return (tagType
== TAG_START
) ? '(' : ')';
2514 if (!strcmp(tag
, "dict")) {
2515 if (tagType
== TAG_EMPTY
) {
2516 object
->elements
= NULL
;
2519 return (tagType
== TAG_START
) ? '{' : '}';
2521 if (!strcmp(tag
, "data")) {
2523 if (tagType
== TAG_EMPTY
) {
2524 object
->data
= NULL
;
2529 bool isHexFormat
= false;
2530 for (i
= 0; i
< attributeCount
; i
++) {
2531 if (!strcmp(attributes
[i
], "format") && !strcmp(values
[i
], "hex")) {
2536 // CF encoded is the default form
2538 object
->data
= getHexData(STATE
, &size
);
2540 object
->data
= getCFEncodedData(STATE
, &size
);
2542 object
->size
= size
;
2543 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
) || strcmp(tag
, "data")) {
2544 return SYNTAX_ERROR
;
2550 if (!strcmp(tag
, "false")) {
2551 if (tagType
== TAG_EMPTY
) {
2558 if (!strcmp(tag
, "integer")) {
2559 object
->size
= 64; // default
2560 for (i
= 0; i
< attributeCount
; i
++) {
2561 if (!strcmp(attributes
[i
], "size")) {
2562 object
->size
= strtoul(values
[i
], NULL
, 0);
2565 if (tagType
== TAG_EMPTY
) {
2569 object
->number
= getNumber(STATE
);
2570 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
) || strcmp(tag
, "integer")) {
2571 return SYNTAX_ERROR
;
2577 if (!strcmp(tag
, "key")) {
2578 if (tagType
== TAG_EMPTY
) {
2579 return SYNTAX_ERROR
;
2581 object
->string
= getString(STATE
);
2582 if (!object
->string
) {
2583 return SYNTAX_ERROR
;
2585 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
)
2586 || strcmp(tag
, "key")) {
2587 return SYNTAX_ERROR
;
2593 if (!strcmp(tag
, "plist")) {
2594 freeObject(STATE
, object
);
2599 if (!strcmp(tag
, "string")) {
2600 if (tagType
== TAG_EMPTY
) {
2601 object
->string
= (char *)malloc(1);
2602 object
->string
[0] = 0;
2605 object
->string
= getString(STATE
);
2606 if (!object
->string
) {
2607 return SYNTAX_ERROR
;
2609 if ((getTag(STATE
, tag
, &attributeCount
, attributes
, values
) != TAG_END
)
2610 || strcmp(tag
, "string")) {
2611 return SYNTAX_ERROR
;
2615 if (!strcmp(tag
, "set")) {
2616 if (tagType
== TAG_EMPTY
) {
2617 object
->elements
= NULL
;
2620 if (tagType
== TAG_START
) {
2628 if (!strcmp(tag
, "true")) {
2629 if (tagType
== TAG_EMPTY
) {
2637 return SYNTAX_ERROR
;
2640 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2641 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2642 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2644 // "java" like allocation, if this code hits a syntax error in the
2645 // the middle of the parsed string we just bail with pointers hanging
2646 // all over place, this code helps keeps it all together
2648 //static int object_count = 0;
2651 newObject(parser_state_t
*state
)
2655 if (state
->freeObjects
) {
2656 o
= state
->freeObjects
;
2657 state
->freeObjects
= state
->freeObjects
->next
;
2659 o
= (object_t
*)malloc(sizeof(object_t
));
2661 bzero(o
, sizeof(object_t
));
2662 o
->free
= state
->objects
;
2670 freeObject(parser_state_t
* state
, object_t
*o
)
2672 o
->next
= state
->freeObjects
;
2673 state
->freeObjects
= o
;
2677 cleanupObjects(parser_state_t
*state
)
2679 object_t
*t
, *o
= state
->objects
;
2683 // printf("OSUnserializeXML: releasing object o=%x object=%x\n", (int)o, (int)o->object);
2684 o
->object
->release();
2687 // printf("OSUnserializeXML: freeing object o=%x data=%x\n", (int)o, (int)o->data);
2691 // printf("OSUnserializeXML: releasing object o=%x key=%x\n", (int)o, (int)o->key);
2695 // printf("OSUnserializeXML: freeing object o=%x string=%x\n", (int)o, (int)o->string);
2704 // printf("object_count = %d\n", object_count);
2707 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2708 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2709 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2712 rememberObject(parser_state_t
*state
, int tag
, OSObject
*o
)
2715 snprintf(key
, 16, "%u", tag
);
2717 // printf("remember key %s\n", key);
2719 state
->tags
->setObject(key
, o
);
2723 retrieveObject(parser_state_t
*state
, int tag
)
2728 snprintf(key
, 16, "%u", tag
);
2730 // printf("retrieve key '%s'\n", key);
2732 ref
= state
->tags
->getObject(key
);
2737 o
= newObject(state
);
2742 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2743 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2744 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
2747 buildDictionary(parser_state_t
*state
, object_t
* header
)
2753 // get count and reverse order
2754 o
= header
->elements
;
2755 header
->elements
= 0;
2761 t
->next
= header
->elements
;
2762 header
->elements
= t
;
2765 dict
= OSDictionary::withCapacity(count
);
2766 if (header
->idref
>= 0) {
2767 rememberObject(state
, header
->idref
, dict
);
2770 o
= header
->elements
;
2772 dict
->setObject(o
->key
, o
->object
);
2775 o
->object
->release();
2781 freeObject(state
, t
);
2789 buildArray(parser_state_t
*state
, object_t
* header
)
2795 // get count and reverse order
2796 o
= header
->elements
;
2797 header
->elements
= 0;
2803 t
->next
= header
->elements
;
2804 header
->elements
= t
;
2807 array
= OSArray::withCapacity(count
);
2808 if (header
->idref
>= 0) {
2809 rememberObject(state
, header
->idref
, array
);
2812 o
= header
->elements
;
2814 array
->setObject(o
->object
);
2816 o
->object
->release();
2821 freeObject(state
, t
);
2829 buildSet(parser_state_t
*state
, object_t
*header
)
2831 object_t
*o
= buildArray(state
, header
);
2833 OSArray
*array
= (OSArray
*)o
->object
;
2834 OSSet
*set
= OSSet::withArray(array
, array
->getCapacity());
2836 // write over the reference created in buildArray
2837 if (header
->idref
>= 0) {
2838 rememberObject(state
, header
->idref
, set
);
2847 buildString(parser_state_t
*state
, object_t
*o
)
2851 string
= OSString::withCString(o
->string
);
2852 if (o
->idref
>= 0) {
2853 rememberObject(state
, o
->idref
, string
);
2864 buildSymbol(parser_state_t
*state
, object_t
*o
)
2868 symbol
= const_cast<OSSymbol
*>(OSSymbol::withCString(o
->string
));
2869 if (o
->idref
>= 0) {
2870 rememberObject(state
, o
->idref
, symbol
);
2881 buildData(parser_state_t
*state
, object_t
*o
)
2886 data
= OSData::withBytes(o
->data
, o
->size
);
2888 data
= OSData::withCapacity(0);
2890 if (o
->idref
>= 0) {
2891 rememberObject(state
, o
->idref
, data
);
2903 buildNumber(parser_state_t
*state
, object_t
*o
)
2905 OSNumber
*number
= OSNumber::withNumber(o
->number
, o
->size
);
2907 if (o
->idref
>= 0) {
2908 rememberObject(state
, o
->idref
, number
);
2916 buildBoolean(parser_state_t
*state __unused
, object_t
*o
)
2918 o
->object
= ((o
->number
== 0) ? kOSBooleanFalse
: kOSBooleanTrue
);
2919 o
->object
->retain();
2924 OSUnserializeXML(const char *buffer
, OSString
**errorString
)
2931 parser_state_t
*state
= (parser_state_t
*)malloc(sizeof(parser_state_t
));
2938 *errorString
= NULL
;
2941 state
->parseBuffer
= buffer
;
2942 state
->parseBufferIndex
= 0;
2943 state
->lineNumber
= 1;
2945 state
->freeObjects
= 0;
2946 state
->tags
= OSDictionary::withCapacity(128);
2947 state
->errorString
= errorString
;
2948 state
->parsedObject
= 0;
2949 state
->parsedObjectCount
= 0;
2950 state
->retrievedObjectCount
= 0;
2952 (void)yyparse((void *)state
);
2954 object
= state
->parsedObject
;
2956 cleanupObjects(state
);
2957 state
->tags
->release();
2963 #include <libkern/OSSerializeBinary.h>
2966 OSUnserializeXML(const char *buffer
, size_t bufferSize
, OSString
**errorString
)
2971 if (bufferSize
< sizeof(kOSSerializeBinarySignature
)) {
2975 if (!strcmp(kOSSerializeBinarySignature
, buffer
)) {
2976 return OSUnserializeBinary(buffer
, bufferSize
, errorString
);
2979 // XML must be null terminated
2980 if (buffer
[bufferSize
- 1]) {
2984 return OSUnserializeXML(buffer
, errorString
);
2993 // DO NOT EDIT OSUnserializeXML.cpp!