]>
git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSUnserializeXML.cpp
2 * Copyright (c) 1999-2002 Apple Computer, 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!
58 /* A Bison parser, made from OSUnserializeXML.y
59 by GNU Bison version 1.28 */
61 #define YYBISON 1 /* Identify Bison output. */
63 #define yyparse OSUnserializeXMLparse
64 #define yylex OSUnserializeXMLlex
65 #define yyerror OSUnserializeXMLerror
66 #define yylval OSUnserializeXMLlval
67 #define yychar OSUnserializeXMLchar
68 #define yydebug OSUnserializeXMLdebug
69 #define yynerrs OSUnserializeXMLnerrs
73 #define DICTIONARY 260
79 #define SYNTAX_ERROR 266
81 #line 55 "OSUnserializeXML.y"
84 #include <libkern/c++/OSMetaClass.h>
85 #include <libkern/c++/OSContainers.h>
86 #include <libkern/c++/OSLib.h>
88 #define YYSTYPE object_t *
89 #define YYPARSE_PARAM state
90 #define YYLEX_PARAM (parser_state_t *)state
92 // this is the internal struct used to hold objects on parser stack
93 // it represents objects both before and after they have been created
94 typedef struct object
{
97 struct object
* elements
;
99 OSString
* key
; // for dictionary
101 void * data
; // for data
102 char * string
; // for string & symbol
103 long long number
; // for number
107 // this code is reentrant, this structure contains all
108 // state information for the parsing of a single buffer
109 typedef struct parser_state
{
110 const char * parseBuffer
; // start of text to be parsed
111 int parseBufferIndex
; // current index into text
112 int lineNumber
; // current line number
113 object_t
* objects
; // internal objects in use
114 object_t
* freeObjects
; // internal objects that are free
115 OSDictionary
* tags
; // used to remember "ID" tags
116 OSString
** errorString
; // parse error with line
117 OSObject
* parsedObject
; // resultant object of parsed text
120 #define STATE ((parser_state_t *)state)
123 #define yyerror(s) OSUnserializeerror(STATE, (s))
124 static int OSUnserializeerror ( parser_state_t
* state
, char * s
);
126 static int yylex ( YYSTYPE
* lvalp
, parser_state_t
* state
);
127 static int yyparse ( void * state
);
129 static object_t
* newObject ( parser_state_t
* state
);
130 static void freeObject ( parser_state_t
* state
, object_t
* o
);
131 static void rememberObject ( parser_state_t
* state
, int tag
, OSObject
* o
);
132 static object_t
* retrieveObject ( parser_state_t
* state
, int tag
);
133 static void cleanupObjects ( parser_state_t
* state
);
135 static object_t
* buildDictionary ( parser_state_t
* state
, object_t
* o
);
136 static object_t
* buildArray ( parser_state_t
* state
, object_t
* o
);
137 static object_t
* buildSet ( parser_state_t
* state
, object_t
* o
);
138 static object_t
* buildString ( parser_state_t
* state
, object_t
* o
);
139 static object_t
* buildData ( parser_state_t
* state
, object_t
* o
);
140 static object_t
* buildNumber ( parser_state_t
* state
, object_t
* o
);
141 static object_t
* buildBoolean ( parser_state_t
* state
, object_t
* o
);
144 extern void * kern_os_malloc ( size_t size
);
145 extern void * kern_os_realloc ( void * addr
, size_t size
);
146 extern void kern_os_free ( void * addr
);
148 //XXX shouldn't have to define these
149 extern long strtol ( const char *, char **, int );
150 extern unsigned long strtoul ( const char *, char **, int );
154 #define malloc(s) kern_os_malloc(s)
155 #define realloc(a, s) kern_os_realloc(a, s)
156 #define free(a) kern_os_free((void *)a)
172 #define YYFLAG -32768
175 #define YYTRANSLATE(x) ((unsigned)(x) <= 266 ? yytranslate[x] : 33)
177 static const char yytranslate
[] = { 0 ,
178 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
179 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
180 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
181 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 15 ,
182 16 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
183 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
184 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
185 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
186 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
187 17 , 2 , 18 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
188 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
189 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
190 2 , 2 , 13 , 2 , 14 , 2 , 2 , 2 , 2 , 2 ,
191 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
192 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
193 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
194 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
195 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
196 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
197 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
198 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
199 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
200 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
201 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
202 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
203 2 , 2 , 2 , 2 , 2 , 1 , 3 , 4 , 5 , 6 ,
208 static const short yyprhs
[] = { 0 ,
209 0 , 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 , 17 ,
210 19 , 21 , 24 , 28 , 30 , 32 , 35 , 38 , 40 , 43 ,
211 47 , 49 , 52 , 56 , 58 , 60 , 63 , 65 , 67 , 69 ,
215 static const short yyrhs
[] = { - 1 ,
216 20 , 0 , 12 , 0 , 21 , 0 , 25 , 0 , 26 , 0 ,
217 32 , 0 , 29 , 0 , 31 , 0 , 28 , 0 , 30 , 0 ,
218 13 , 14 , 0 , 13 , 22 , 14 , 0 , 6 , 0 , 23 ,
219 0 , 22 , 23 , 0 , 24 , 20 , 0 , 8 , 0 , 15 ,
220 16 , 0 , 15 , 27 , 16 , 0 , 3 , 0 , 17 , 18 ,
221 0 , 17 , 27 , 18 , 0 , 10 , 0 , 20 , 0 , 27 ,
222 20 , 0 , 4 , 0 , 5 , 0 , 7 , 0 , 9 , 0 ,
229 static const short yyrline
[] = { 0 ,
230 144 , 147 , 152 , 157 , 158 , 159 , 160 , 161 , 162 , 163 ,
231 164 , 177 , 180 , 183 , 186 , 187 , 192 , 201 , 206 , 209 ,
232 212 , 215 , 218 , 221 , 224 , 227 , 234 , 237 , 240 , 243 ,
238 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
240 static const char * const yytname
[] = { "$" , "error" , "$undefined." , "ARRAY" ,
241 "BOOLEAN" , "DATA" , "DICTIONARY" , "IDREF" , "KEY" , "NUMBER" , "SET" , "STRING" , "SYNTAX_ERROR" ,
242 "'{'" , "'}'" , "'('" , "')'" , "'['" , "']'" , "input" , "object" , "dict" , "pairs" , "pair" , "key" ,
243 "array" , "set" , "elements" , "boolean" , "data" , "idref" , "number" , "string" , NULL
247 static const short yyr1
[] = { 0 ,
248 19 , 19 , 19 , 20 , 20 , 20 , 20 , 20 , 20 , 20 ,
249 20 , 21 , 21 , 21 , 22 , 22 , 23 , 24 , 25 , 25 ,
250 25 , 26 , 26 , 26 , 27 , 27 , 28 , 29 , 30 , 31 ,
254 static const short yyr2
[] = { 0 ,
255 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
256 1 , 2 , 3 , 1 , 1 , 2 , 2 , 1 , 2 , 3 ,
257 1 , 2 , 3 , 1 , 1 , 2 , 1 , 1 , 1 , 1 ,
261 static const short yydefact
[] = { 1 ,
262 21 , 27 , 28 , 14 , 29 , 30 , 24 , 31 , 3 , 0 ,
263 0 , 0 , 2 , 4 , 5 , 6 , 10 , 8 , 11 , 9 ,
264 7 , 18 , 12 , 0 , 15 , 0 , 19 , 25 , 0 , 22 ,
265 0 , 13 , 16 , 17 , 20 , 26 , 23 , 0 , 0 , 0
268 static const short yydefgoto
[] = { 38 ,
269 28 , 14 , 24 , 25 , 26 , 15 , 16 , 29 , 17 , 18 ,
273 static const short yypact
[] = { 45 ,
274 - 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 4 ,
275 60 , - 2 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,
276 - 32768 ,- 32768 ,- 32768 , 6 ,- 32768 , 90 ,- 32768 ,- 32768 , 75 ,- 32768 ,
277 29 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 10 , 17 ,- 32768
280 static const short yypgoto
[] = {- 32768 ,
281 0 ,- 32768 ,- 32768 , - 18 ,- 32768 ,- 32768 ,- 32768 , 7 ,- 32768 ,- 32768 ,
289 static const short yytable
[] = { 13 ,
290 1 , 2 , 3 , 4 , 5 , 33 , 6 , 7 , 8 , 39 ,
291 10 , 22 , 11 , 22 , 12 , 30 , 40 , 23 , 31 , 32 ,
292 0 , 0 , 0 , 0 , 0 , 34 , 0 , 0 , 36 , 0 ,
293 36 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 , 8 ,
294 0 , 10 , 0 , 11 , 0 , 12 , 37 , 1 , 2 , 3 ,
295 4 , 5 , 0 , 6 , 7 , 8 , 9 , 10 , 0 , 11 ,
296 0 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
297 8 , 0 , 10 , 0 , 11 , 27 , 12 , 1 , 2 , 3 ,
298 4 , 5 , 0 , 6 , 7 , 8 , 0 , 10 , 0 , 11 ,
299 35 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
300 8 , 0 , 10 , 0 , 11 , 0 , 12
303 static const short yycheck
[] = { 0 ,
304 3 , 4 , 5 , 6 , 7 , 24 , 9 , 10 , 11 , 0 ,
305 13 , 8 , 15 , 8 , 17 , 18 , 0 , 14 , 12 , 14 ,
306 - 1 , - 1 , - 1 , - 1 , - 1 , 26 , - 1 , - 1 , 29 , - 1 ,
307 31 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 , 11 ,
308 - 1 , 13 , - 1 , 15 , - 1 , 17 , 18 , 3 , 4 , 5 ,
309 6 , 7 , - 1 , 9 , 10 , 11 , 12 , 13 , - 1 , 15 ,
310 - 1 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
311 11 , - 1 , 13 , - 1 , 15 , 16 , 17 , 3 , 4 , 5 ,
312 6 , 7 , - 1 , 9 , 10 , 11 , - 1 , 13 , - 1 , 15 ,
313 16 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
314 11 , - 1 , 13 , - 1 , 15 , - 1 , 17
318 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
319 #line 3 "/usr/share/bison.simple"
320 /* This file comes from bison-1.28. */
322 /* Skeleton output parser for bison,
323 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
325 This program is free software; you can redistribute it and/or modify
326 it under the terms of the GNU General Public License as published by
327 the Free Software Foundation; either version 2, or (at your option)
330 This program is distributed in the hope that it will be useful,
331 but WITHOUT ANY WARRANTY; without even the implied warranty of
332 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
333 GNU General Public License for more details.
335 You should have received a copy of the GNU General Public License
336 along with this program; if not, write to the Free Software
337 Foundation, Inc., 59 Temple Place - Suite 330,
338 Boston, MA 02111-1307, USA. */
340 /* As a special exception, when this file is copied by Bison into a
341 Bison output file, you may use that output file without restriction.
342 This special exception was added by the Free Software Foundation
343 in version 1.24 of Bison. */
345 /* This is the parser code that is written into each bison parser
346 when the %semantic_parser declaration is not specified in the grammar.
347 It was written by Richard Stallman by simplifying the hairy parser
348 used when %semantic_parser is specified. */
350 #ifndef YYSTACK_USE_ALLOCA
352 #define YYSTACK_USE_ALLOCA
353 #else /* alloca not defined */
355 #define YYSTACK_USE_ALLOCA
356 #define alloca __builtin_alloca
357 #else /* not GNU C. */
358 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
359 #define YYSTACK_USE_ALLOCA
361 #else /* not sparc */
362 /* We think this test detects Watcom and Microsoft C. */
363 /* This used to test MSDOS, but that is a bad idea
364 since that symbol is in the user namespace. */
365 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
366 #if 0 /* No need for malloc.h, which pollutes the namespace;
367 instead, just don't use alloca. */
370 #else /* not MSDOS, or __TURBOC__ */
372 /* I don't know what this was needed for, but it pollutes the namespace.
373 So I turned it off. rms, 2 May 1997. */
374 /* #include <malloc.h> */
376 #define YYSTACK_USE_ALLOCA
377 #else /* not MSDOS, or __TURBOC__, or _AIX */
379 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
380 and on HPUX 10. Eventually we can turn this on. */
381 #define YYSTACK_USE_ALLOCA
382 #define alloca __builtin_alloca
385 #endif /* not _AIX */
386 #endif /* not MSDOS, or __TURBOC__ */
387 #endif /* not sparc */
388 #endif /* not GNU C */
389 #endif /* alloca not defined */
390 #endif /* YYSTACK_USE_ALLOCA not defined */
392 #ifdef YYSTACK_USE_ALLOCA
393 #define YYSTACK_ALLOC alloca
395 #define YYSTACK_ALLOC malloc
398 /* Note: there must be only one dollar sign in this file.
399 It is replaced by the list of actions, each action
400 as one case of the switch. */
402 #define yyerrok (yyerrstatus = 0)
403 #define yyclearin (yychar = YYEMPTY)
406 #define YYACCEPT goto yyacceptlab
407 #define YYABORT goto yyabortlab
408 #define YYERROR goto yyerrlab1
409 /* Like YYERROR except do call yyerror.
410 This remains here temporarily to ease the
411 transition to the new meaning of YYERROR, for GCC.
412 Once GCC version 2 has supplanted version 1, this can go. */
413 #define YYFAIL goto yyerrlab
414 #define YYRECOVERING() (!!yyerrstatus)
415 #define YYBACKUP(token, value) \
417 if (yychar == YYEMPTY && yylen == 1) \
418 { yychar = (token), yylval = (value); \
419 yychar1 = YYTRANSLATE (yychar); \
424 { yyerror ( "syntax error: cannot back up" ); YYERROR; } \
428 #define YYERRCODE 256
431 #define YYLEX yylex()
437 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
439 #define YYLEX yylex(&yylval, &yylloc)
441 #else /* not YYLSP_NEEDED */
443 #define YYLEX yylex(&yylval, YYLEX_PARAM)
445 #define YYLEX yylex(&yylval)
447 #endif /* not YYLSP_NEEDED */
450 /* If nonreentrant, generate the variables here */
454 int yychar
; /* the lookahead symbol */
455 YYSTYPE yylval
; /* the semantic value of the */
456 /* lookahead symbol */
459 YYLTYPE yylloc
; /* location data for the lookahead */
463 int yynerrs
; /* number of parse errors so far */
464 #endif /* not YYPURE */
467 int yydebug
; /* nonzero means print parse trace */
468 /* Since this is uninitialized, it does not stop multiple parsers
472 /* YYINITDEPTH indicates the initial size of the parser's stacks */
475 #define YYINITDEPTH 200
478 /* YYMAXDEPTH is the maximum size the stacks can grow to
479 (effective only if the built-in stack extension method is used). */
486 #define YYMAXDEPTH 10000
489 /* Define __yy_memcpy. Note that the size argument
490 should be passed with type unsigned int, because that is what the non-GCC
491 definitions require. With GCC, __builtin_memcpy takes an arg
492 of type size_t, but it can handle unsigned int. */
494 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
495 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
496 #else /* not GNU C or C++ */
499 /* This is the most reliable way to avoid incompatibilities
500 in available built-in functions on various systems. */
502 __yy_memcpy ( to
, from
, count
)
507 register char * f
= from
;
508 register char * t
= to
;
509 register int i
= count
;
515 #else /* __cplusplus */
517 /* This is the most reliable way to avoid incompatibilities
518 in available built-in functions on various systems. */
520 __yy_memcpy ( char * to
, char * from
, unsigned int count
)
522 register char * t
= to
;
523 register char * f
= from
;
524 register int i
= count
;
533 #line 217 "/usr/share/bison.simple"
535 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
536 into yyparse. The argument should have type void *.
537 It should actually point to an object.
538 Grammar actions can access the variable by casting it
539 to the proper pointer type. */
543 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
544 #define YYPARSE_PARAM_DECL
545 #else /* not __cplusplus */
546 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
547 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
548 #endif /* not __cplusplus */
549 #else /* not YYPARSE_PARAM */
550 #define YYPARSE_PARAM_ARG
551 #define YYPARSE_PARAM_DECL
552 #endif /* not YYPARSE_PARAM */
554 /* Prevent warning if -Wstrict-prototypes. */
557 int yyparse ( void *);
564 yyparse ( YYPARSE_PARAM_ARG
)
567 register int yystate
;
569 register short * yyssp
;
570 register YYSTYPE
* yyvsp
;
571 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
572 int yychar1
= 0 ; /* lookahead token as an internal (translated) token number */
574 short yyssa
[ YYINITDEPTH
]; /* the state stack */
575 YYSTYPE yyvsa
[ YYINITDEPTH
]; /* the semantic value stack */
577 short * yyss
= yyssa
; /* refer to the stacks thru separate pointers */
578 YYSTYPE
* yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
581 YYLTYPE yylsa
[ YYINITDEPTH
]; /* the location stack */
582 YYLTYPE
* yyls
= yylsa
;
585 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
587 #define YYPOPSTACK (yyvsp--, yyssp--)
590 int yystacksize
= YYINITDEPTH
;
591 int yyfree_stacks
= 0 ;
602 YYSTYPE yyval
; /* the variable used to return */
603 /* semantic values from the action */
610 fprintf ( stderr
, "Starting parse \n " );
616 yychar
= YYEMPTY
; /* Cause a token to be read. */
618 /* Initialize stack pointers.
619 Waste one element of value and location stack
620 so that they stay on the same level as the state stack.
621 The wasted elements are never initialized. */
629 /* Push a new state, which is found in yystate . */
630 /* In all cases, when you get here, the value and location stacks
631 have just been pushed. so pushing a state here evens the stacks. */
636 if ( yyssp
>= yyss
+ yystacksize
- 1 )
638 /* Give user a chance to reallocate the stack */
639 /* Use copies of these so that the &'s don't force the real ones into memory. */
640 YYSTYPE
* yyvs1
= yyvs
;
643 YYLTYPE
* yyls1
= yyls
;
646 /* Get the current used size of the three stacks, in elements. */
647 int size
= yyssp
- yyss
+ 1 ;
650 /* Each stack pointer address is followed by the size of
651 the data in use in that stack, in bytes. */
653 /* This used to be a conditional around just the two extra args,
654 but that might be undefined if yyoverflow is a macro. */
655 yyoverflow ( "parser stack overflow" ,
656 & yyss1
, size
* sizeof (* yyssp
),
657 & yyvs1
, size
* sizeof (* yyvsp
),
658 & yyls1
, size
* sizeof (* yylsp
),
661 yyoverflow ( "parser stack overflow" ,
662 & yyss1
, size
* sizeof (* yyssp
),
663 & yyvs1
, size
* sizeof (* yyvsp
),
667 yyss
= yyss1
; yyvs
= yyvs1
;
671 #else /* no yyoverflow */
672 /* Extend the stack our own way. */
673 if ( yystacksize
>= YYMAXDEPTH
)
675 yyerror ( "parser stack overflow" );
687 if ( yystacksize
> YYMAXDEPTH
)
688 yystacksize
= YYMAXDEPTH
;
689 #ifndef YYSTACK_USE_ALLOCA
692 yyss
= ( short *) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyssp
));
693 __yy_memcpy (( char *) yyss
, ( char *) yyss1
,
694 size
* ( unsigned int ) sizeof (* yyssp
));
695 yyvs
= ( YYSTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyvsp
));
696 __yy_memcpy (( char *) yyvs
, ( char *) yyvs1
,
697 size
* ( unsigned int ) sizeof (* yyvsp
));
699 yyls
= ( YYLTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yylsp
));
700 __yy_memcpy (( char *) yyls
, ( char *) yyls1
,
701 size
* ( unsigned int ) sizeof (* yylsp
));
703 #endif /* no yyoverflow */
705 yyssp
= yyss
+ size
- 1 ;
706 yyvsp
= yyvs
+ size
- 1 ;
708 yylsp
= yyls
+ size
- 1 ;
713 fprintf ( stderr
, "Stack size increased to %d \n " , yystacksize
);
716 if ( yyssp
>= yyss
+ yystacksize
- 1 )
722 fprintf ( stderr
, "Entering state %d \n " , yystate
);
728 /* Do appropriate processing given the current state. */
729 /* Read a lookahead token if we need one and don't already have one. */
732 /* First try to decide what to do without reference to lookahead token. */
734 yyn
= yypact
[ yystate
];
738 /* Not known => get a lookahead token if don't already have one. */
740 /* yychar is either YYEMPTY or YYEOF
741 or a valid token in external form. */
743 if ( yychar
== YYEMPTY
)
747 fprintf ( stderr
, "Reading a token: " );
752 /* Convert token to internal form (in yychar1) for indexing tables with */
754 if ( yychar
<= 0 ) /* This means end of input. */
757 yychar
= YYEOF
; /* Don't call YYLEX any more */
761 fprintf ( stderr
, "Now at end of input. \n " );
766 yychar1
= YYTRANSLATE ( yychar
);
771 fprintf ( stderr
, "Next token is %d ( %s " , yychar
, yytname
[ yychar1
]);
772 /* Give the individual parser a way to print the precise meaning
773 of a token, for further debugging info. */
775 YYPRINT ( stderr
, yychar
, yylval
);
777 fprintf ( stderr
, ") \n " );
783 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != yychar1
)
788 /* yyn is what to do for this token type in this state.
789 Negative => reduce, -yyn is rule number.
790 Positive => shift, yyn is new state.
791 New state is final state => don't bother to shift,
793 0, or most negative number => error. */
808 /* Shift the lookahead token. */
812 fprintf ( stderr
, "Shifting token %d ( %s ), " , yychar
, yytname
[ yychar1
]);
815 /* Discard the token being shifted unless it is eof. */
824 /* count tokens shifted since error; after three, turn off error status. */
825 if ( yyerrstatus
) yyerrstatus
--;
830 /* Do the default action for the current state. */
833 yyn
= yydefact
[ yystate
];
837 /* Do a reduction. yyn is the number of a rule to reduce with. */
841 yyval
= yyvsp
[ 1 - yylen
]; /* implement default value of the action */
848 fprintf ( stderr
, "Reducing via rule %d (line %d ), " ,
851 /* Print the symbols being reduced, and their result. */
852 for ( i
= yyprhs
[ yyn
]; yyrhs
[ i
] > 0 ; i
++)
853 fprintf ( stderr
, " %s " , yytname
[ yyrhs
[ i
]]);
854 fprintf ( stderr
, " -> %s \n " , yytname
[ yyr1
[ yyn
]]);
862 #line 144 "OSUnserializeXML.y"
863 { yyerror ( "unexpected end of buffer" );
868 #line 147 "OSUnserializeXML.y"
869 { STATE
-> parsedObject
= yyvsp
[ 0 ]-> object
;
870 yyvsp
[ 0 ]-> object
= 0 ;
871 freeObject ( STATE
, yyvsp
[ 0 ]);
876 #line 152 "OSUnserializeXML.y"
877 { yyerror ( "syntax error" );
882 #line 157 "OSUnserializeXML.y"
883 { yyval
= buildDictionary ( STATE
, yyvsp
[ 0 ]); ;
886 #line 158 "OSUnserializeXML.y"
887 { yyval
= buildArray ( STATE
, yyvsp
[ 0 ]); ;
890 #line 159 "OSUnserializeXML.y"
891 { yyval
= buildSet ( STATE
, yyvsp
[ 0 ]); ;
894 #line 160 "OSUnserializeXML.y"
895 { yyval
= buildString ( STATE
, yyvsp
[ 0 ]); ;
898 #line 161 "OSUnserializeXML.y"
899 { yyval
= buildData ( STATE
, yyvsp
[ 0 ]); ;
902 #line 162 "OSUnserializeXML.y"
903 { yyval
= buildNumber ( STATE
, yyvsp
[ 0 ]); ;
906 #line 163 "OSUnserializeXML.y"
907 { yyval
= buildBoolean ( STATE
, yyvsp
[ 0 ]); ;
910 #line 164 "OSUnserializeXML.y"
911 { yyval
= retrieveObject ( STATE
, yyvsp
[ 0 ]-> idref
);
913 yyval
-> object
-> retain ();
915 yyerror ( "forward reference detected" );
918 freeObject ( STATE
, yyvsp
[ 0 ]);
922 #line 177 "OSUnserializeXML.y"
924 yyval
-> elements
= NULL
;
928 #line 180 "OSUnserializeXML.y"
930 yyval
-> elements
= yyvsp
[- 1 ];
934 #line 187 "OSUnserializeXML.y"
936 yyval
-> next
= yyvsp
[- 1 ];
940 #line 192 "OSUnserializeXML.y"
942 yyval
-> key
= ( OSString
*) yyval
-> object
;
943 yyval
-> object
= yyvsp
[ 0 ]-> object
;
945 yyvsp
[ 0 ]-> object
= 0 ;
946 freeObject ( STATE
, yyvsp
[ 0 ]);
950 #line 201 "OSUnserializeXML.y"
951 { yyval
= buildString ( STATE
, yyvsp
[ 0 ]); ;
954 #line 206 "OSUnserializeXML.y"
956 yyval
-> elements
= NULL
;
960 #line 209 "OSUnserializeXML.y"
962 yyval
-> elements
= yyvsp
[- 1 ];
966 #line 215 "OSUnserializeXML.y"
968 yyval
-> elements
= NULL
;
972 #line 218 "OSUnserializeXML.y"
974 yyval
-> elements
= yyvsp
[- 1 ];
978 #line 224 "OSUnserializeXML.y"
984 #line 227 "OSUnserializeXML.y"
986 yyval
-> next
= yyvsp
[- 1 ];
990 /* the action file gets copied in in place of this dollarsign */
991 #line 543 "/usr/share/bison.simple"
1002 short * ssp1
= yyss
- 1 ;
1003 fprintf ( stderr
, "state stack now" );
1004 while ( ssp1
!= yyssp
)
1005 fprintf ( stderr
, " %d " , *++ ssp1
);
1006 fprintf ( stderr
, " \n " );
1016 yylsp
-> first_line
= yylloc
. first_line
;
1017 yylsp
-> first_column
= yylloc
. first_column
;
1018 yylsp
-> last_line
= ( yylsp
- 1 )-> last_line
;
1019 yylsp
-> last_column
= ( yylsp
- 1 )-> last_column
;
1024 yylsp
-> last_line
= ( yylsp
+ yylen
- 1 )-> last_line
;
1025 yylsp
-> last_column
= ( yylsp
+ yylen
- 1 )-> last_column
;
1029 /* Now "shift" the result of the reduction.
1030 Determine what state that goes to,
1031 based on the state we popped back to
1032 and the rule number reduced by. */
1036 yystate
= yypgoto
[ yyn
- YYNTBASE
] + * yyssp
;
1037 if ( yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[ yystate
] == * yyssp
)
1038 yystate
= yytable
[ yystate
];
1040 yystate
= yydefgoto
[ yyn
- YYNTBASE
];
1044 yyerrlab
: /* here on detecting error */
1047 /* If not already recovering from an error, report this error. */
1051 #ifdef YYERROR_VERBOSE
1052 yyn
= yypact
[ yystate
];
1054 if ( yyn
> YYFLAG
&& yyn
< YYLAST
)
1061 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1062 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1063 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1064 if ( yycheck
[ x
+ yyn
] == x
)
1065 size
+= strlen ( yytname
[ x
]) + 15 , count
++;
1066 msg
= ( char *) malloc ( size
+ 15 );
1069 strcpy ( msg
, "parse error" );
1074 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1075 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1076 if ( yycheck
[ x
+ yyn
] == x
)
1078 strcat ( msg
, count
== 0 ? ", expecting `" : " or `" );
1079 strcat ( msg
, yytname
[ x
]);
1088 yyerror ( "parse error; also virtual memory exceeded" );
1091 #endif /* YYERROR_VERBOSE */
1092 yyerror ( "parse error" );
1096 yyerrlab1
: /* here on error raised explicitly by an action */
1098 if ( yyerrstatus
== 3 )
1100 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1102 /* return failure if at end of input */
1103 if ( yychar
== YYEOF
)
1108 fprintf ( stderr
, "Discarding token %d ( %s ). \n " , yychar
, yytname
[ yychar1
]);
1114 /* Else will try to reuse lookahead token
1115 after shifting the error token. */
1117 yyerrstatus
= 3 ; /* Each real token shifted decrements this */
1121 yyerrdefault
: /* current state does not do anything special for the error token. */
1124 /* This is wrong; only states that explicitly want error tokens
1125 should shift them. */
1126 yyn
= yydefact
[ yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1127 if ( yyn
) goto yydefault
;
1130 yyerrpop
: /* pop the current state because it cannot handle the error token */
1132 if ( yyssp
== yyss
) YYABORT
;
1142 short * ssp1
= yyss
- 1 ;
1143 fprintf ( stderr
, "Error: state stack now" );
1144 while ( ssp1
!= yyssp
)
1145 fprintf ( stderr
, " %d " , *++ ssp1
);
1146 fprintf ( stderr
, " \n " );
1152 yyn
= yypact
[ yystate
];
1157 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != YYTERROR
)
1176 fprintf ( stderr
, "Shifting error token, " );
1188 /* YYACCEPT comes here. */
1200 /* YYABORT comes here. */
1211 #line 249 "OSUnserializeXML.y"
1215 OSUnserializeerror ( parser_state_t
* state
, char * s
) /* Called by yyparse on errors */
1217 char tempString
[ 128 ];
1219 if ( state
-> errorString
) {
1220 snprintf ( tempString
, 128 , "OSUnserializeXML: %s near line %d \n " , s
, state
-> lineNumber
);
1221 *( state
-> errorString
) = OSString :: withCString ( tempString
);
1227 #define TAG_MAX_LENGTH 32
1228 #define TAG_MAX_ATTRIBUTES 32
1233 #define TAG_COMMENT 4
1235 #define currentChar() (state->parseBuffer[state->parseBufferIndex])
1236 #define nextChar() (state->parseBuffer[++state->parseBufferIndex])
1237 #define prevChar() (state->parseBuffer[state->parseBufferIndex - 1])
1239 #define isSpace(c) ((c) == ' ' || (c) == ' \t ' )
1240 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z' ) || ((c) >= 'a' && (c) <= 'z' ))
1241 #define isDigit(c) ((c) >= '0' && (c) <= '9' )
1242 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f' )
1243 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
1244 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-' ))
1247 getTag ( parser_state_t
* state
,
1248 char tag
[ TAG_MAX_LENGTH
],
1249 int * attributeCount
,
1250 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
],
1251 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
] )
1254 int c
= currentChar ();
1255 int tagType
= TAG_START
;
1257 * attributeCount
= 0 ;
1259 if ( c
!= '<' ) return TAG_BAD
;
1260 c
= nextChar (); // skip '<'
1262 if ( c
== '?' || c
== '!' ) {
1263 while (( c
= nextChar ()) != 0 ) {
1264 if ( c
== ' \n ' ) state
-> lineNumber
++;
1273 c
= nextChar (); // skip '/'
1276 if (! isAlpha ( c
)) return TAG_BAD
;
1278 /* find end of tag while copying it */
1279 while ( isAlphaNumeric ( c
)) {
1282 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1287 // printf("tag %s, type %d\n", tag, tagType);
1289 // look for attributes of the form attribute = "value" ...
1290 while (( c
!= '>' ) && ( c
!= '/' )) {
1291 while ( isSpace ( c
)) c
= nextChar ();
1294 while ( isAlphaNumeric ( c
)) {
1295 attributes
[* attributeCount
][ length
++] = c
;
1296 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1299 attributes
[* attributeCount
][ length
] = 0 ;
1301 while ( isSpace ( c
)) c
= nextChar ();
1303 if ( c
!= '=' ) return TAG_BAD
;
1306 while ( isSpace ( c
)) c
= nextChar ();
1308 if ( c
!= '"' ) return TAG_BAD
;
1312 values
[* attributeCount
][ length
++] = c
;
1313 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1316 values
[* attributeCount
][ length
] = 0 ;
1318 c
= nextChar (); // skip closing quote
1320 // printf(" attribute '%s' = '%s', nextchar = '%c'\n",
1321 // attributes[*attributeCount], values[*attributeCount], c);
1323 (* attributeCount
)++;
1324 if (* attributeCount
>= TAG_MAX_ATTRIBUTES
) return TAG_BAD
;
1328 c
= nextChar (); // skip '/'
1329 tagType
= TAG_EMPTY
;
1331 if ( c
!= '>' ) return TAG_BAD
;
1332 c
= nextChar (); // skip '>'
1338 getString ( parser_state_t
* state
)
1340 int c
= currentChar ();
1341 int start
, length
, i
, j
;
1344 start
= state
-> parseBufferIndex
;
1345 /* find end of string */
1348 if ( c
== ' \n ' ) state
-> lineNumber
++;
1355 if ( c
!= '<' ) return 0 ;
1357 length
= state
-> parseBufferIndex
- start
;
1359 /* copy to null terminated buffer */
1360 tempString
= ( char *) malloc ( length
+ 1 );
1361 if ( tempString
== 0 ) {
1362 printf ( "OSUnserializeXML: can't alloc temp memory \n " );
1366 // copy out string in tempString
1367 // "&" -> '&', "<" -> '<', ">" -> '>'
1370 while ( i
< length
) {
1371 c
= state
-> parseBuffer
[ start
+ i
++];
1373 tempString
[ j
++] = c
;
1375 if (( i
+ 3 ) > length
) goto error
;
1376 c
= state
-> parseBuffer
[ start
+ i
++];
1378 if ( state
-> parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1379 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1380 tempString
[ j
++] = '<' ;
1384 if ( state
-> parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1385 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1386 tempString
[ j
++] = '>' ;
1389 if (( i
+ 3 ) > length
) goto error
;
1391 if ( state
-> parseBuffer
[ start
+ i
++] != 'm' ) goto error
;
1392 if ( state
-> parseBuffer
[ start
+ i
++] != 'p' ) goto error
;
1393 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1394 tempString
[ j
++] = '&' ;
1402 // printf("string %s\n", tempString);
1407 if ( tempString
) free ( tempString
);
1412 getNumber ( parser_state_t
* state
)
1414 unsigned long long n
= 0 ;
1416 bool negate
= false ;
1417 int c
= currentChar ();
1432 n
= ( n
* base
+ c
- '0' );
1436 n
= ( unsigned long long )(( long long ) n
* ( long long )- 1 );
1439 while ( isHexDigit ( c
)) {
1441 n
= ( n
* base
+ c
- '0' );
1443 n
= ( n
* base
+ 0xa + c
- 'a' );
1448 // printf("number 0x%x\n", (unsigned long)n);
1452 // taken from CFXMLParsing/CFPropertyList.c
1454 static const signed char __CFPLDataDecodeTable
[ 128 ] = {
1455 /* 000 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1456 /* 010 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1457 /* 020 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1458 /* 030 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1459 /* ' ' */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1460 /* '(' */ - 1 , - 1 , - 1 , 62 , - 1 , - 1 , - 1 , 63 ,
1461 /* '0' */ 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 ,
1462 /* '8' */ 60 , 61 , - 1 , - 1 , - 1 , 0 , - 1 , - 1 ,
1463 /* '@' */ - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 ,
1464 /* 'H' */ 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ,
1465 /* 'P' */ 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 ,
1466 /* 'X' */ 23 , 24 , 25 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1467 /* '`' */ - 1 , 26 , 27 , 28 , 29 , 30 , 31 , 32 ,
1468 /* 'h' */ 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 ,
1469 /* 'p' */ 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 ,
1470 /* 'x' */ 49 , 50 , 51 , - 1 , - 1 , - 1 , - 1 , - 1
1473 #define DATA_ALLOC_SIZE 4096
1476 getCFEncodedData ( parser_state_t
* state
, unsigned int * size
)
1478 int numeq
= 0 , acc
= 0 , cntr
= 0 ;
1479 int tmpbufpos
= 0 , tmpbuflen
= 0 ;
1480 unsigned char * tmpbuf
= ( unsigned char *) malloc ( DATA_ALLOC_SIZE
);
1482 int c
= currentChar ();
1491 if ( c
== '=' ) numeq
++; else numeq
= 0 ;
1492 if ( c
== ' \n ' ) state
-> lineNumber
++;
1493 if ( __CFPLDataDecodeTable
[ c
] < 0 ) {
1499 acc
+= __CFPLDataDecodeTable
[ c
];
1500 if ( 0 == ( cntr
& 0x3 )) {
1501 if ( tmpbuflen
<= tmpbufpos
+ 2 ) {
1502 tmpbuflen
+= DATA_ALLOC_SIZE
;
1503 tmpbuf
= ( unsigned char *) realloc ( tmpbuf
, tmpbuflen
);
1505 tmpbuf
[ tmpbufpos
++] = ( acc
>> 16 ) & 0xff ;
1507 tmpbuf
[ tmpbufpos
++] = ( acc
>> 8 ) & 0xff ;
1509 tmpbuf
[ tmpbufpos
++] = acc
& 0xff ;
1522 getHexData ( parser_state_t
* state
, unsigned int * size
)
1525 unsigned char * d
, * start
, * lastStart
;
1527 start
= lastStart
= d
= ( unsigned char *) malloc ( DATA_ALLOC_SIZE
);
1532 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1534 state
-> lineNumber
++;
1541 * d
= ( c
- '0' ) << 4 ;
1542 } else if ( isAlphaDigit ( c
)) {
1543 * d
= ( 0xa + ( c
- 'a' )) << 4 ;
1552 } else if ( isAlphaDigit ( c
)) {
1553 * d
|= 0xa + ( c
- 'a' );
1559 if (( d
- lastStart
) >= DATA_ALLOC_SIZE
) {
1560 int oldsize
= d
- start
;
1561 start
= ( unsigned char *) realloc ( start
, oldsize
+ DATA_ALLOC_SIZE
);
1562 d
= lastStart
= start
+ oldsize
;
1578 yylex ( YYSTYPE
* lvalp
, parser_state_t
* state
)
1582 char tag
[ TAG_MAX_LENGTH
];
1584 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1585 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1591 /* skip white space */
1592 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1594 /* keep track of line number, don't return \n's */
1596 STATE
-> lineNumber
++;
1601 // end of the buffer?
1604 tagType
= getTag ( STATE
, tag
, & attributeCount
, attributes
, values
);
1605 if ( tagType
== TAG_BAD
) return SYNTAX_ERROR
;
1606 if ( tagType
== TAG_COMMENT
) goto top
;
1608 // handle allocation and check for "ID" and "IDREF" tags up front
1609 * lvalp
= object
= newObject ( STATE
);
1611 for ( i
= 0 ; i
< attributeCount
; i
++) {
1612 if ( attributes
[ i
][ 0 ] == 'I' && attributes
[ i
][ 1 ] == 'D' ) {
1613 // check for idref's, note: we ignore the tag, for
1614 // this to work correctly, all idrefs must be unique
1615 // across the whole serialization
1616 if ( attributes
[ i
][ 2 ] == 'R' && attributes
[ i
][ 3 ] == 'E' &&
1617 attributes
[ i
][ 4 ] == 'F' && ! attributes
[ i
][ 5 ]) {
1618 if ( tagType
!= TAG_EMPTY
) return SYNTAX_ERROR
;
1619 object
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1623 if (! attributes
[ i
][ 2 ]) {
1624 object
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1626 return SYNTAX_ERROR
;
1633 if (! strcmp ( tag
, "array" )) {
1634 if ( tagType
== TAG_EMPTY
) {
1635 object
-> elements
= NULL
;
1638 return ( tagType
== TAG_START
) ? '(' : ')' ;
1642 if (! strcmp ( tag
, "dict" )) {
1643 if ( tagType
== TAG_EMPTY
) {
1644 object
-> elements
= NULL
;
1647 return ( tagType
== TAG_START
) ? '{' : '}' ;
1649 if (! strcmp ( tag
, "data" )) {
1651 if ( tagType
== TAG_EMPTY
) {
1652 object
-> data
= NULL
;
1657 bool isHexFormat
= false ;
1658 for ( int i
= 0 ; i
< attributeCount
; i
++) {
1659 if (! strcmp ( attributes
[ i
], "format" ) && ! strcmp ( values
[ i
], "hex" )) {
1664 // CF encoded is the default form
1666 object
-> data
= getHexData ( STATE
, & size
);
1668 object
-> data
= getCFEncodedData ( STATE
, & size
);
1670 object
-> size
= size
;
1671 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "data" )) {
1672 return SYNTAX_ERROR
;
1678 if (! strcmp ( tag
, "false" )) {
1679 if ( tagType
== TAG_EMPTY
) {
1686 if (! strcmp ( tag
, "integer" )) {
1687 object
-> size
= 64 ; // default
1688 for ( i
= 0 ; i
< attributeCount
; i
++) {
1689 if (! strcmp ( attributes
[ i
], "size" )) {
1690 object
-> size
= strtoul ( values
[ i
], NULL
, 0 );
1693 if ( tagType
== TAG_EMPTY
) {
1697 object
-> number
= getNumber ( STATE
);
1698 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "integer" )) {
1699 return SYNTAX_ERROR
;
1705 if (! strcmp ( tag
, "key" )) {
1706 if ( tagType
== TAG_EMPTY
) return SYNTAX_ERROR
;
1707 object
-> string
= getString ( STATE
);
1708 if (! object
-> string
) {
1709 return SYNTAX_ERROR
;
1711 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1712 || strcmp ( tag
, "key" )) {
1713 return SYNTAX_ERROR
;
1719 if (! strcmp ( tag
, "plist" )) {
1720 freeObject ( STATE
, object
);
1725 if (! strcmp ( tag
, "string" )) {
1726 if ( tagType
== TAG_EMPTY
) {
1727 object
-> string
= ( char *) malloc ( 1 );
1728 object
-> string
[ 0 ] = 0 ;
1731 object
-> string
= getString ( STATE
);
1732 if (! object
-> string
) {
1733 return SYNTAX_ERROR
;
1735 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1736 || strcmp ( tag
, "string" )) {
1737 return SYNTAX_ERROR
;
1741 if (! strcmp ( tag
, "set" )) {
1742 if ( tagType
== TAG_EMPTY
) {
1743 object
-> elements
= NULL
;
1746 if ( tagType
== TAG_START
) {
1754 if (! strcmp ( tag
, "true" )) {
1755 if ( tagType
== TAG_EMPTY
) {
1763 return SYNTAX_ERROR
;
1766 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1767 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1768 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1770 // "java" like allocation, if this code hits a syntax error in the
1771 // the middle of the parsed string we just bail with pointers hanging
1772 // all over place, this code helps keeps it all together
1774 //static int object_count = 0;
1777 newObject ( parser_state_t
* state
)
1781 if ( state
-> freeObjects
) {
1782 o
= state
-> freeObjects
;
1783 state
-> freeObjects
= state
-> freeObjects
-> next
;
1785 o
= ( object_t
*) malloc ( sizeof ( object_t
));
1787 bzero ( o
, sizeof ( object_t
));
1788 o
-> free
= state
-> objects
;
1796 freeObject ( parser_state_t
* state
, object_t
* o
)
1798 o
-> next
= state
-> freeObjects
;
1799 state
-> freeObjects
= o
;
1803 cleanupObjects ( parser_state_t
* state
)
1805 object_t
* t
, * o
= state
-> objects
;
1809 // printf("OSUnserializeXML: releasing object o=%x object=%x\n", (int)o, (int)o->object);
1810 o
-> object
-> release ();
1813 // printf("OSUnserializeXML: freeing object o=%x data=%x\n", (int)o, (int)o->data);
1817 // printf("OSUnserializeXML: releasing object o=%x key=%x\n", (int)o, (int)o->key);
1821 // printf("OSUnserializeXML: freeing object o=%x string=%x\n", (int)o, (int)o->string);
1830 // printf("object_count = %d\n", object_count);
1833 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1834 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1835 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1838 rememberObject ( parser_state_t
* state
, int tag
, OSObject
* o
)
1841 snprintf ( key
, 16 , " %u " , tag
);
1843 // printf("remember key %s\n", key);
1845 state
-> tags
-> setObject ( key
, o
);
1849 retrieveObject ( parser_state_t
* state
, int tag
)
1854 snprintf ( key
, 16 , " %u " , tag
);
1856 // printf("retrieve key '%s'\n", key);
1858 ref
= state
-> tags
-> getObject ( key
);
1861 o
= newObject ( state
);
1866 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1867 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1868 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1871 buildDictionary ( parser_state_t
* state
, object_t
* header
)
1877 // get count and reverse order
1878 o
= header
-> elements
;
1879 header
-> elements
= 0 ;
1885 t
-> next
= header
-> elements
;
1886 header
-> elements
= t
;
1889 dict
= OSDictionary :: withCapacity ( count
);
1890 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, dict
);
1892 o
= header
-> elements
;
1894 dict
-> setObject ( o
-> key
, o
-> object
);
1897 o
-> object
-> release ();
1903 freeObject ( state
, t
);
1911 buildArray ( parser_state_t
* state
, object_t
* header
)
1917 // get count and reverse order
1918 o
= header
-> elements
;
1919 header
-> elements
= 0 ;
1925 t
-> next
= header
-> elements
;
1926 header
-> elements
= t
;
1929 array
= OSArray :: withCapacity ( count
);
1930 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, array
);
1932 o
= header
-> elements
;
1934 array
-> setObject ( o
-> object
);
1936 o
-> object
-> release ();
1941 freeObject ( state
, t
);
1949 buildSet ( parser_state_t
* state
, object_t
* header
)
1951 object_t
* o
= buildArray ( state
, header
);
1953 OSArray
* array
= ( OSArray
*) o
-> object
;
1954 OSSet
* set
= OSSet :: withArray ( array
, array
-> getCapacity ());
1956 // write over the reference created in buildArray
1957 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, set
);
1965 buildString ( parser_state_t
* state
, object_t
* o
)
1969 string
= OSString :: withCString ( o
-> string
);
1970 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, string
);
1980 buildData ( parser_state_t
* state
, object_t
* o
)
1985 data
= OSData :: withBytes ( o
-> data
, o
-> size
);
1987 data
= OSData :: withCapacity ( 0 );
1989 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, data
);
1991 if ( o
-> size
) free ( o
-> data
);
1998 buildNumber ( parser_state_t
* state
, object_t
* o
)
2000 OSNumber
* number
= OSNumber :: withNumber ( o
-> number
, o
-> size
);
2002 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, number
);
2009 buildBoolean ( parser_state_t
* state
, object_t
* o
)
2011 o
-> object
= (( o
-> number
== 0 ) ? kOSBooleanFalse
: kOSBooleanTrue
);
2012 o
-> object
-> retain ();
2017 OSUnserializeXML ( const char * buffer
, OSString
** errorString
)
2020 parser_state_t
* state
= ( parser_state_t
*) malloc ( sizeof ( parser_state_t
));
2022 if ((! state
) || (! buffer
)) return 0 ;
2025 if ( errorString
) * errorString
= NULL
;
2027 state
-> parseBuffer
= buffer
;
2028 state
-> parseBufferIndex
= 0 ;
2029 state
-> lineNumber
= 1 ;
2031 state
-> freeObjects
= 0 ;
2032 state
-> tags
= OSDictionary :: withCapacity ( 128 );
2033 state
-> errorString
= errorString
;
2034 state
-> parsedObject
= 0 ;
2036 ( void ) yyparse (( void *) state
);
2038 object
= state
-> parsedObject
;
2040 cleanupObjects ( state
);
2041 state
-> tags
-> release ();
2053 // DO NOT EDIT OSUnserializeXML.cpp!