]>
git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSUnserializeXML.cpp
7371262f8b81ab4fe7905c7bee92951441b6352c
2 * Copyright (c) 1999-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * OSUnserializeXML.y created by rsulack on Tue Oct 12 1999
30 // parser for unserializing OSContainer objects serialized to XML
33 // bison -p OSUnserializeXML OSUnserializeXML.y
34 // head -50 OSUnserializeXML.y > OSUnserializeXML.cpp
35 // sed -e "s/#include <stdio.h>//" < OSUnserializeXML.tab.c >> OSUnserializeXML.cpp
37 // when changing code check in both OSUnserializeXML.y and OSUnserializeXML.cpp
43 // DO NOT EDIT OSUnserializeXML.cpp!
53 /* A Bison parser, made from OSUnserializeXML.y
54 by GNU Bison version 1.28 */
56 #define YYBISON 1 /* Identify Bison output. */
58 #define yyparse OSUnserializeXMLparse
59 #define yylex OSUnserializeXMLlex
60 #define yyerror OSUnserializeXMLerror
61 #define yylval OSUnserializeXMLlval
62 #define yychar OSUnserializeXMLchar
63 #define yydebug OSUnserializeXMLdebug
64 #define yynerrs OSUnserializeXMLnerrs
68 #define DICTIONARY 260
74 #define SYNTAX_ERROR 266
76 #line 55 "OSUnserializeXML.y"
79 #include <libkern/c++/OSMetaClass.h>
80 #include <libkern/c++/OSContainers.h>
81 #include <libkern/c++/OSLib.h>
83 #define YYSTYPE object_t *
84 #define YYPARSE_PARAM state
85 #define YYLEX_PARAM state
87 // this is the internal struct used to hold objects on parser stack
88 // it represents objects both before and after they have been created
89 typedef struct object
{
92 struct object
* elements
;
94 OSString
* key
; // for dictionary
96 void * data
; // for data
97 char * string
; // for string & symbol
98 long long number
; // for number
102 // this code is reentrant, this structure contains all
103 // state information for the parsing of a single buffer
104 typedef struct parser_state
{
105 const char * parseBuffer
; // start of text to be parsed
106 int parseBufferIndex
; // current index into text
107 int lineNumber
; // current line number
108 object_t
* objects
; // internal objects in use
109 object_t
* freeObjects
; // internal objects that are free
110 OSDictionary
* tags
; // used to remember "ID" tags
111 OSString
** errorString
; // parse error with line
112 OSObject
* parsedObject
; // resultant object of parsed text
115 #define STATE ((parser_state_t *)state)
118 #define yyerror(s) OSUnserializeerror(STATE, (s))
119 static int OSUnserializeerror ( parser_state_t
* state
, char * s
);
121 static int yylex ( YYSTYPE
* lvalp
, parser_state_t
* state
);
122 static int yyparse ( void * state
);
124 static object_t
* newObject ( parser_state_t
* state
);
125 static void freeObject ( parser_state_t
* state
, object_t
* o
);
126 static void rememberObject ( parser_state_t
* state
, int tag
, OSObject
* o
);
127 static object_t
* retrieveObject ( parser_state_t
* state
, int tag
);
128 static void cleanupObjects ( parser_state_t
* state
);
130 static object_t
* buildDictionary ( parser_state_t
* state
, object_t
* o
);
131 static object_t
* buildArray ( parser_state_t
* state
, object_t
* o
);
132 static object_t
* buildSet ( parser_state_t
* state
, object_t
* o
);
133 static object_t
* buildString ( parser_state_t
* state
, object_t
* o
);
134 static object_t
* buildData ( parser_state_t
* state
, object_t
* o
);
135 static object_t
* buildNumber ( parser_state_t
* state
, object_t
* o
);
136 static object_t
* buildBoolean ( parser_state_t
* state
, object_t
* o
);
139 extern void * kern_os_malloc ( size_t size
);
140 extern void * kern_os_realloc ( void * addr
, size_t size
);
141 extern void kern_os_free ( void * addr
);
143 //XXX shouldn't have to define these
144 extern long strtol ( const char *, char **, int );
145 extern unsigned long strtoul ( const char *, char **, int );
149 #define malloc(s) kern_os_malloc(s)
150 #define realloc(a, s) kern_os_realloc(a, s)
151 #define free(a) kern_os_free(a)
167 #define YYFLAG -32768
170 #define YYTRANSLATE(x) ((unsigned)(x) <= 266 ? yytranslate[x] : 33)
172 static const char yytranslate
[] = { 0 ,
173 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
174 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
175 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
176 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 15 ,
177 16 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
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 , 2 ,
182 17 , 2 , 18 , 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 , 13 , 2 , 14 , 2 , 2 , 2 , 2 , 2 ,
186 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
187 2 , 2 , 2 , 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 , 2 , 2 , 2 , 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 , 1 , 3 , 4 , 5 , 6 ,
203 static const short yyprhs
[] = { 0 ,
204 0 , 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 , 17 ,
205 19 , 21 , 24 , 28 , 30 , 32 , 35 , 38 , 40 , 43 ,
206 47 , 49 , 52 , 56 , 58 , 60 , 63 , 65 , 67 , 69 ,
210 static const short yyrhs
[] = { - 1 ,
211 20 , 0 , 12 , 0 , 21 , 0 , 25 , 0 , 26 , 0 ,
212 32 , 0 , 29 , 0 , 31 , 0 , 28 , 0 , 30 , 0 ,
213 13 , 14 , 0 , 13 , 22 , 14 , 0 , 6 , 0 , 23 ,
214 0 , 22 , 23 , 0 , 24 , 20 , 0 , 8 , 0 , 15 ,
215 16 , 0 , 15 , 27 , 16 , 0 , 3 , 0 , 17 , 18 ,
216 0 , 17 , 27 , 18 , 0 , 10 , 0 , 20 , 0 , 27 ,
217 20 , 0 , 4 , 0 , 5 , 0 , 7 , 0 , 9 , 0 ,
224 static const short yyrline
[] = { 0 ,
225 144 , 147 , 152 , 157 , 158 , 159 , 160 , 161 , 162 , 163 ,
226 164 , 177 , 180 , 183 , 186 , 187 , 192 , 201 , 206 , 209 ,
227 212 , 215 , 218 , 221 , 224 , 227 , 234 , 237 , 240 , 243 ,
233 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
235 static const char * const yytname
[] = { "$" , "error" , "$undefined." , "ARRAY" ,
236 "BOOLEAN" , "DATA" , "DICTIONARY" , "IDREF" , "KEY" , "NUMBER" , "SET" , "STRING" , "SYNTAX_ERROR" ,
237 "'{'" , "'}'" , "'('" , "')'" , "'['" , "']'" , "input" , "object" , "dict" , "pairs" , "pair" , "key" ,
238 "array" , "set" , "elements" , "boolean" , "data" , "idref" , "number" , "string" , NULL
242 static const short yyr1
[] = { 0 ,
243 19 , 19 , 19 , 20 , 20 , 20 , 20 , 20 , 20 , 20 ,
244 20 , 21 , 21 , 21 , 22 , 22 , 23 , 24 , 25 , 25 ,
245 25 , 26 , 26 , 26 , 27 , 27 , 28 , 29 , 30 , 31 ,
249 static const short yyr2
[] = { 0 ,
250 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
251 1 , 2 , 3 , 1 , 1 , 2 , 2 , 1 , 2 , 3 ,
252 1 , 2 , 3 , 1 , 1 , 2 , 1 , 1 , 1 , 1 ,
256 static const short yydefact
[] = { 1 ,
257 21 , 27 , 28 , 14 , 29 , 30 , 24 , 31 , 3 , 0 ,
258 0 , 0 , 2 , 4 , 5 , 6 , 10 , 8 , 11 , 9 ,
259 7 , 18 , 12 , 0 , 15 , 0 , 19 , 25 , 0 , 22 ,
260 0 , 13 , 16 , 17 , 20 , 26 , 23 , 0 , 0 , 0
263 static const short yydefgoto
[] = { 38 ,
264 28 , 14 , 24 , 25 , 26 , 15 , 16 , 29 , 17 , 18 ,
268 static const short yypact
[] = { 45 ,
269 - 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 4 ,
270 60 , - 2 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,
271 - 32768 ,- 32768 ,- 32768 , 6 ,- 32768 , 90 ,- 32768 ,- 32768 , 75 ,- 32768 ,
272 29 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 10 , 17 ,- 32768
275 static const short yypgoto
[] = {- 32768 ,
276 0 ,- 32768 ,- 32768 , - 18 ,- 32768 ,- 32768 ,- 32768 , 7 ,- 32768 ,- 32768 ,
284 static const short yytable
[] = { 13 ,
285 1 , 2 , 3 , 4 , 5 , 33 , 6 , 7 , 8 , 39 ,
286 10 , 22 , 11 , 22 , 12 , 30 , 40 , 23 , 31 , 32 ,
287 0 , 0 , 0 , 0 , 0 , 34 , 0 , 0 , 36 , 0 ,
288 36 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 , 8 ,
289 0 , 10 , 0 , 11 , 0 , 12 , 37 , 1 , 2 , 3 ,
290 4 , 5 , 0 , 6 , 7 , 8 , 9 , 10 , 0 , 11 ,
291 0 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
292 8 , 0 , 10 , 0 , 11 , 27 , 12 , 1 , 2 , 3 ,
293 4 , 5 , 0 , 6 , 7 , 8 , 0 , 10 , 0 , 11 ,
294 35 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
295 8 , 0 , 10 , 0 , 11 , 0 , 12
298 static const short yycheck
[] = { 0 ,
299 3 , 4 , 5 , 6 , 7 , 24 , 9 , 10 , 11 , 0 ,
300 13 , 8 , 15 , 8 , 17 , 18 , 0 , 14 , 12 , 14 ,
301 - 1 , - 1 , - 1 , - 1 , - 1 , 26 , - 1 , - 1 , 29 , - 1 ,
302 31 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 , 11 ,
303 - 1 , 13 , - 1 , 15 , - 1 , 17 , 18 , 3 , 4 , 5 ,
304 6 , 7 , - 1 , 9 , 10 , 11 , 12 , 13 , - 1 , 15 ,
305 - 1 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
306 11 , - 1 , 13 , - 1 , 15 , 16 , 17 , 3 , 4 , 5 ,
307 6 , 7 , - 1 , 9 , 10 , 11 , - 1 , 13 , - 1 , 15 ,
308 16 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
309 11 , - 1 , 13 , - 1 , 15 , - 1 , 17
313 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
314 #line 3 "/usr/share/bison.simple"
315 /* This file comes from bison-1.28. */
317 /* Skeleton output parser for bison,
318 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
320 This program is free software; you can redistribute it and/or modify
321 it under the terms of the GNU General Public License as published by
322 the Free Software Foundation; either version 2, or (at your option)
325 This program is distributed in the hope that it will be useful,
326 but WITHOUT ANY WARRANTY; without even the implied warranty of
327 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
328 GNU General Public License for more details.
330 You should have received a copy of the GNU General Public License
331 along with this program; if not, write to the Free Software
332 Foundation, Inc., 59 Temple Place - Suite 330,
333 Boston, MA 02111-1307, USA. */
335 /* As a special exception, when this file is copied by Bison into a
336 Bison output file, you may use that output file without restriction.
337 This special exception was added by the Free Software Foundation
338 in version 1.24 of Bison. */
340 /* This is the parser code that is written into each bison parser
341 when the %semantic_parser declaration is not specified in the grammar.
342 It was written by Richard Stallman by simplifying the hairy parser
343 used when %semantic_parser is specified. */
345 #ifndef YYSTACK_USE_ALLOCA
347 #define YYSTACK_USE_ALLOCA
348 #else /* alloca not defined */
350 #define YYSTACK_USE_ALLOCA
351 #define alloca __builtin_alloca
352 #else /* not GNU C. */
353 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
354 #define YYSTACK_USE_ALLOCA
356 #else /* not sparc */
357 /* We think this test detects Watcom and Microsoft C. */
358 /* This used to test MSDOS, but that is a bad idea
359 since that symbol is in the user namespace. */
360 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
361 #if 0 /* No need for malloc.h, which pollutes the namespace;
362 instead, just don't use alloca. */
365 #else /* not MSDOS, or __TURBOC__ */
367 /* I don't know what this was needed for, but it pollutes the namespace.
368 So I turned it off. rms, 2 May 1997. */
369 /* #include <malloc.h> */
371 #define YYSTACK_USE_ALLOCA
372 #else /* not MSDOS, or __TURBOC__, or _AIX */
374 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
375 and on HPUX 10. Eventually we can turn this on. */
376 #define YYSTACK_USE_ALLOCA
377 #define alloca __builtin_alloca
380 #endif /* not _AIX */
381 #endif /* not MSDOS, or __TURBOC__ */
382 #endif /* not sparc */
383 #endif /* not GNU C */
384 #endif /* alloca not defined */
385 #endif /* YYSTACK_USE_ALLOCA not defined */
387 #ifdef YYSTACK_USE_ALLOCA
388 #define YYSTACK_ALLOC alloca
390 #define YYSTACK_ALLOC malloc
393 /* Note: there must be only one dollar sign in this file.
394 It is replaced by the list of actions, each action
395 as one case of the switch. */
397 #define yyerrok (yyerrstatus = 0)
398 #define yyclearin (yychar = YYEMPTY)
401 #define YYACCEPT goto yyacceptlab
402 #define YYABORT goto yyabortlab
403 #define YYERROR goto yyerrlab1
404 /* Like YYERROR except do call yyerror.
405 This remains here temporarily to ease the
406 transition to the new meaning of YYERROR, for GCC.
407 Once GCC version 2 has supplanted version 1, this can go. */
408 #define YYFAIL goto yyerrlab
409 #define YYRECOVERING() (!!yyerrstatus)
410 #define YYBACKUP(token, value) \
412 if (yychar == YYEMPTY && yylen == 1) \
413 { yychar = (token), yylval = (value); \
414 yychar1 = YYTRANSLATE (yychar); \
419 { yyerror ( "syntax error: cannot back up" ); YYERROR; } \
423 #define YYERRCODE 256
426 #define YYLEX yylex()
432 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
434 #define YYLEX yylex(&yylval, &yylloc)
436 #else /* not YYLSP_NEEDED */
438 #define YYLEX yylex(&yylval, YYLEX_PARAM)
440 #define YYLEX yylex(&yylval)
442 #endif /* not YYLSP_NEEDED */
445 /* If nonreentrant, generate the variables here */
449 int yychar
; /* the lookahead symbol */
450 YYSTYPE yylval
; /* the semantic value of the */
451 /* lookahead symbol */
454 YYLTYPE yylloc
; /* location data for the lookahead */
458 int yynerrs
; /* number of parse errors so far */
459 #endif /* not YYPURE */
462 int yydebug
; /* nonzero means print parse trace */
463 /* Since this is uninitialized, it does not stop multiple parsers
467 /* YYINITDEPTH indicates the initial size of the parser's stacks */
470 #define YYINITDEPTH 200
473 /* YYMAXDEPTH is the maximum size the stacks can grow to
474 (effective only if the built-in stack extension method is used). */
481 #define YYMAXDEPTH 10000
484 /* Define __yy_memcpy. Note that the size argument
485 should be passed with type unsigned int, because that is what the non-GCC
486 definitions require. With GCC, __builtin_memcpy takes an arg
487 of type size_t, but it can handle unsigned int. */
489 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
490 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
491 #else /* not GNU C or C++ */
494 /* This is the most reliable way to avoid incompatibilities
495 in available built-in functions on various systems. */
497 __yy_memcpy ( to
, from
, count
)
502 register char * f
= from
;
503 register char * t
= to
;
504 register int i
= count
;
510 #else /* __cplusplus */
512 /* This is the most reliable way to avoid incompatibilities
513 in available built-in functions on various systems. */
515 __yy_memcpy ( char * to
, char * from
, unsigned int count
)
517 register char * t
= to
;
518 register char * f
= from
;
519 register int i
= count
;
528 #line 217 "/usr/share/bison.simple"
530 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
531 into yyparse. The argument should have type void *.
532 It should actually point to an object.
533 Grammar actions can access the variable by casting it
534 to the proper pointer type. */
538 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
539 #define YYPARSE_PARAM_DECL
540 #else /* not __cplusplus */
541 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
542 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
543 #endif /* not __cplusplus */
544 #else /* not YYPARSE_PARAM */
545 #define YYPARSE_PARAM_ARG
546 #define YYPARSE_PARAM_DECL
547 #endif /* not YYPARSE_PARAM */
549 /* Prevent warning if -Wstrict-prototypes. */
552 int yyparse ( void *);
559 yyparse ( YYPARSE_PARAM_ARG
)
562 register int yystate
;
564 register short * yyssp
;
565 register YYSTYPE
* yyvsp
;
566 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
567 int yychar1
= 0 ; /* lookahead token as an internal (translated) token number */
569 short yyssa
[ YYINITDEPTH
]; /* the state stack */
570 YYSTYPE yyvsa
[ YYINITDEPTH
]; /* the semantic value stack */
572 short * yyss
= yyssa
; /* refer to the stacks thru separate pointers */
573 YYSTYPE
* yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
576 YYLTYPE yylsa
[ YYINITDEPTH
]; /* the location stack */
577 YYLTYPE
* yyls
= yylsa
;
580 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
582 #define YYPOPSTACK (yyvsp--, yyssp--)
585 int yystacksize
= YYINITDEPTH
;
586 int yyfree_stacks
= 0 ;
597 YYSTYPE yyval
; /* the variable used to return */
598 /* semantic values from the action */
605 fprintf ( stderr
, "Starting parse \n " );
611 yychar
= YYEMPTY
; /* Cause a token to be read. */
613 /* Initialize stack pointers.
614 Waste one element of value and location stack
615 so that they stay on the same level as the state stack.
616 The wasted elements are never initialized. */
624 /* Push a new state, which is found in yystate . */
625 /* In all cases, when you get here, the value and location stacks
626 have just been pushed. so pushing a state here evens the stacks. */
631 if ( yyssp
>= yyss
+ yystacksize
- 1 )
633 /* Give user a chance to reallocate the stack */
634 /* Use copies of these so that the &'s don't force the real ones into memory. */
635 YYSTYPE
* yyvs1
= yyvs
;
638 YYLTYPE
* yyls1
= yyls
;
641 /* Get the current used size of the three stacks, in elements. */
642 int size
= yyssp
- yyss
+ 1 ;
645 /* Each stack pointer address is followed by the size of
646 the data in use in that stack, in bytes. */
648 /* This used to be a conditional around just the two extra args,
649 but that might be undefined if yyoverflow is a macro. */
650 yyoverflow ( "parser stack overflow" ,
651 & yyss1
, size
* sizeof (* yyssp
),
652 & yyvs1
, size
* sizeof (* yyvsp
),
653 & yyls1
, size
* sizeof (* yylsp
),
656 yyoverflow ( "parser stack overflow" ,
657 & yyss1
, size
* sizeof (* yyssp
),
658 & yyvs1
, size
* sizeof (* yyvsp
),
662 yyss
= yyss1
; yyvs
= yyvs1
;
666 #else /* no yyoverflow */
667 /* Extend the stack our own way. */
668 if ( yystacksize
>= YYMAXDEPTH
)
670 yyerror ( "parser stack overflow" );
682 if ( yystacksize
> YYMAXDEPTH
)
683 yystacksize
= YYMAXDEPTH
;
684 #ifndef YYSTACK_USE_ALLOCA
687 yyss
= ( short *) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyssp
));
688 __yy_memcpy (( char *) yyss
, ( char *) yyss1
,
689 size
* ( unsigned int ) sizeof (* yyssp
));
690 yyvs
= ( YYSTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyvsp
));
691 __yy_memcpy (( char *) yyvs
, ( char *) yyvs1
,
692 size
* ( unsigned int ) sizeof (* yyvsp
));
694 yyls
= ( YYLTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yylsp
));
695 __yy_memcpy (( char *) yyls
, ( char *) yyls1
,
696 size
* ( unsigned int ) sizeof (* yylsp
));
698 #endif /* no yyoverflow */
700 yyssp
= yyss
+ size
- 1 ;
701 yyvsp
= yyvs
+ size
- 1 ;
703 yylsp
= yyls
+ size
- 1 ;
708 fprintf ( stderr
, "Stack size increased to %d \n " , yystacksize
);
711 if ( yyssp
>= yyss
+ yystacksize
- 1 )
717 fprintf ( stderr
, "Entering state %d \n " , yystate
);
723 /* Do appropriate processing given the current state. */
724 /* Read a lookahead token if we need one and don't already have one. */
727 /* First try to decide what to do without reference to lookahead token. */
729 yyn
= yypact
[ yystate
];
733 /* Not known => get a lookahead token if don't already have one. */
735 /* yychar is either YYEMPTY or YYEOF
736 or a valid token in external form. */
738 if ( yychar
== YYEMPTY
)
742 fprintf ( stderr
, "Reading a token: " );
747 /* Convert token to internal form (in yychar1) for indexing tables with */
749 if ( yychar
<= 0 ) /* This means end of input. */
752 yychar
= YYEOF
; /* Don't call YYLEX any more */
756 fprintf ( stderr
, "Now at end of input. \n " );
761 yychar1
= YYTRANSLATE ( yychar
);
766 fprintf ( stderr
, "Next token is %d ( %s " , yychar
, yytname
[ yychar1
]);
767 /* Give the individual parser a way to print the precise meaning
768 of a token, for further debugging info. */
770 YYPRINT ( stderr
, yychar
, yylval
);
772 fprintf ( stderr
, ") \n " );
778 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != yychar1
)
783 /* yyn is what to do for this token type in this state.
784 Negative => reduce, -yyn is rule number.
785 Positive => shift, yyn is new state.
786 New state is final state => don't bother to shift,
788 0, or most negative number => error. */
803 /* Shift the lookahead token. */
807 fprintf ( stderr
, "Shifting token %d ( %s ), " , yychar
, yytname
[ yychar1
]);
810 /* Discard the token being shifted unless it is eof. */
819 /* count tokens shifted since error; after three, turn off error status. */
820 if ( yyerrstatus
) yyerrstatus
--;
825 /* Do the default action for the current state. */
828 yyn
= yydefact
[ yystate
];
832 /* Do a reduction. yyn is the number of a rule to reduce with. */
836 yyval
= yyvsp
[ 1 - yylen
]; /* implement default value of the action */
843 fprintf ( stderr
, "Reducing via rule %d (line %d ), " ,
846 /* Print the symbols being reduced, and their result. */
847 for ( i
= yyprhs
[ yyn
]; yyrhs
[ i
] > 0 ; i
++)
848 fprintf ( stderr
, " %s " , yytname
[ yyrhs
[ i
]]);
849 fprintf ( stderr
, " -> %s \n " , yytname
[ yyr1
[ yyn
]]);
857 #line 144 "OSUnserializeXML.y"
858 { yyerror ( "unexpected end of buffer" );
863 #line 147 "OSUnserializeXML.y"
864 { STATE
-> parsedObject
= yyvsp
[ 0 ]-> object
;
865 yyvsp
[ 0 ]-> object
= 0 ;
866 freeObject ( STATE
, yyvsp
[ 0 ]);
871 #line 152 "OSUnserializeXML.y"
872 { yyerror ( "syntax error" );
877 #line 157 "OSUnserializeXML.y"
878 { yyval
= buildDictionary ( STATE
, yyvsp
[ 0 ]); ;
881 #line 158 "OSUnserializeXML.y"
882 { yyval
= buildArray ( STATE
, yyvsp
[ 0 ]); ;
885 #line 159 "OSUnserializeXML.y"
886 { yyval
= buildSet ( STATE
, yyvsp
[ 0 ]); ;
889 #line 160 "OSUnserializeXML.y"
890 { yyval
= buildString ( STATE
, yyvsp
[ 0 ]); ;
893 #line 161 "OSUnserializeXML.y"
894 { yyval
= buildData ( STATE
, yyvsp
[ 0 ]); ;
897 #line 162 "OSUnserializeXML.y"
898 { yyval
= buildNumber ( STATE
, yyvsp
[ 0 ]); ;
901 #line 163 "OSUnserializeXML.y"
902 { yyval
= buildBoolean ( STATE
, yyvsp
[ 0 ]); ;
905 #line 164 "OSUnserializeXML.y"
906 { yyval
= retrieveObject ( STATE
, yyvsp
[ 0 ]-> idref
);
908 yyval
-> object
-> retain ();
910 yyerror ( "forward reference detected" );
913 freeObject ( STATE
, yyvsp
[ 0 ]);
917 #line 177 "OSUnserializeXML.y"
919 yyval
-> elements
= NULL
;
923 #line 180 "OSUnserializeXML.y"
925 yyval
-> elements
= yyvsp
[- 1 ];
929 #line 187 "OSUnserializeXML.y"
931 yyval
-> next
= yyvsp
[- 1 ];
935 #line 192 "OSUnserializeXML.y"
937 yyval
-> key
= yyval
-> object
;
938 yyval
-> object
= yyvsp
[ 0 ]-> object
;
940 yyvsp
[ 0 ]-> object
= 0 ;
941 freeObject ( STATE
, yyvsp
[ 0 ]);
945 #line 201 "OSUnserializeXML.y"
946 { yyval
= buildString ( STATE
, yyvsp
[ 0 ]); ;
949 #line 206 "OSUnserializeXML.y"
951 yyval
-> elements
= NULL
;
955 #line 209 "OSUnserializeXML.y"
957 yyval
-> elements
= yyvsp
[- 1 ];
961 #line 215 "OSUnserializeXML.y"
963 yyval
-> elements
= NULL
;
967 #line 218 "OSUnserializeXML.y"
969 yyval
-> elements
= yyvsp
[- 1 ];
973 #line 224 "OSUnserializeXML.y"
979 #line 227 "OSUnserializeXML.y"
981 yyval
-> next
= yyvsp
[- 1 ];
985 /* the action file gets copied in in place of this dollarsign */
986 #line 543 "/usr/share/bison.simple"
997 short * ssp1
= yyss
- 1 ;
998 fprintf ( stderr
, "state stack now" );
999 while ( ssp1
!= yyssp
)
1000 fprintf ( stderr
, " %d " , *++ ssp1
);
1001 fprintf ( stderr
, " \n " );
1011 yylsp
-> first_line
= yylloc
. first_line
;
1012 yylsp
-> first_column
= yylloc
. first_column
;
1013 yylsp
-> last_line
= ( yylsp
- 1 )-> last_line
;
1014 yylsp
-> last_column
= ( yylsp
- 1 )-> last_column
;
1019 yylsp
-> last_line
= ( yylsp
+ yylen
- 1 )-> last_line
;
1020 yylsp
-> last_column
= ( yylsp
+ yylen
- 1 )-> last_column
;
1024 /* Now "shift" the result of the reduction.
1025 Determine what state that goes to,
1026 based on the state we popped back to
1027 and the rule number reduced by. */
1031 yystate
= yypgoto
[ yyn
- YYNTBASE
] + * yyssp
;
1032 if ( yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[ yystate
] == * yyssp
)
1033 yystate
= yytable
[ yystate
];
1035 yystate
= yydefgoto
[ yyn
- YYNTBASE
];
1039 yyerrlab
: /* here on detecting error */
1042 /* If not already recovering from an error, report this error. */
1046 #ifdef YYERROR_VERBOSE
1047 yyn
= yypact
[ yystate
];
1049 if ( yyn
> YYFLAG
&& yyn
< YYLAST
)
1056 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1057 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1058 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1059 if ( yycheck
[ x
+ yyn
] == x
)
1060 size
+= strlen ( yytname
[ x
]) + 15 , count
++;
1061 msg
= ( char *) malloc ( size
+ 15 );
1064 strcpy ( msg
, "parse error" );
1069 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1070 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1071 if ( yycheck
[ x
+ yyn
] == x
)
1073 strcat ( msg
, count
== 0 ? ", expecting `" : " or `" );
1074 strcat ( msg
, yytname
[ x
]);
1083 yyerror ( "parse error; also virtual memory exceeded" );
1086 #endif /* YYERROR_VERBOSE */
1087 yyerror ( "parse error" );
1091 yyerrlab1
: /* here on error raised explicitly by an action */
1093 if ( yyerrstatus
== 3 )
1095 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1097 /* return failure if at end of input */
1098 if ( yychar
== YYEOF
)
1103 fprintf ( stderr
, "Discarding token %d ( %s ). \n " , yychar
, yytname
[ yychar1
]);
1109 /* Else will try to reuse lookahead token
1110 after shifting the error token. */
1112 yyerrstatus
= 3 ; /* Each real token shifted decrements this */
1116 yyerrdefault
: /* current state does not do anything special for the error token. */
1119 /* This is wrong; only states that explicitly want error tokens
1120 should shift them. */
1121 yyn
= yydefact
[ yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1122 if ( yyn
) goto yydefault
;
1125 yyerrpop
: /* pop the current state because it cannot handle the error token */
1127 if ( yyssp
== yyss
) YYABORT
;
1137 short * ssp1
= yyss
- 1 ;
1138 fprintf ( stderr
, "Error: state stack now" );
1139 while ( ssp1
!= yyssp
)
1140 fprintf ( stderr
, " %d " , *++ ssp1
);
1141 fprintf ( stderr
, " \n " );
1147 yyn
= yypact
[ yystate
];
1152 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != YYTERROR
)
1171 fprintf ( stderr
, "Shifting error token, " );
1183 /* YYACCEPT comes here. */
1195 /* YYABORT comes here. */
1206 #line 249 "OSUnserializeXML.y"
1210 OSUnserializeerror ( parser_state_t
* state
, char * s
) /* Called by yyparse on errors */
1212 char tempString
[ 128 ];
1214 if ( state
-> errorString
) {
1215 snprintf ( tempString
, 128 , "OSUnserializeXML: %s near line %d \n " , s
, state
-> lineNumber
);
1216 *( state
-> errorString
) = OSString :: withCString ( tempString
);
1222 #define TAG_MAX_LENGTH 32
1223 #define TAG_MAX_ATTRIBUTES 32
1228 #define TAG_COMMENT 4
1230 #define currentChar() (state->parseBuffer[state->parseBufferIndex])
1231 #define nextChar() (state->parseBuffer[++state->parseBufferIndex])
1232 #define prevChar() (state->parseBuffer[state->parseBufferIndex - 1])
1234 #define isSpace(c) ((c) == ' ' || (c) == ' \t ' )
1235 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z' ) || ((c) >= 'a' && (c) <= 'z' ))
1236 #define isDigit(c) ((c) >= '0' && (c) <= '9' )
1237 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f' )
1238 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
1239 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-' ))
1242 getTag ( parser_state_t
* state
,
1243 char tag
[ TAG_MAX_LENGTH
],
1244 int * attributeCount
,
1245 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
],
1246 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
] )
1249 int c
= currentChar ();
1250 int tagType
= TAG_START
;
1252 * attributeCount
= 0 ;
1254 if ( c
!= '<' ) return TAG_BAD
;
1255 c
= nextChar (); // skip '<'
1257 if ( c
== '?' || c
== '!' ) {
1258 while (( c
= nextChar ()) != 0 ) {
1259 if ( c
== ' \n ' ) state
-> lineNumber
++;
1268 c
= nextChar (); // skip '/'
1271 if (! isAlpha ( c
)) return TAG_BAD
;
1273 /* find end of tag while copying it */
1274 while ( isAlphaNumeric ( c
)) {
1277 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1282 // printf("tag %s, type %d\n", tag, tagType);
1284 // look for attributes of the form attribute = "value" ...
1285 while (( c
!= '>' ) && ( c
!= '/' )) {
1286 while ( isSpace ( c
)) c
= nextChar ();
1289 while ( isAlphaNumeric ( c
)) {
1290 attributes
[* attributeCount
][ length
++] = c
;
1291 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1294 attributes
[* attributeCount
][ length
] = 0 ;
1296 while ( isSpace ( c
)) c
= nextChar ();
1298 if ( c
!= '=' ) return TAG_BAD
;
1301 while ( isSpace ( c
)) c
= nextChar ();
1303 if ( c
!= '"' ) return TAG_BAD
;
1307 values
[* attributeCount
][ length
++] = c
;
1308 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1311 values
[* attributeCount
][ length
] = 0 ;
1313 c
= nextChar (); // skip closing quote
1315 // printf(" attribute '%s' = '%s', nextchar = '%c'\n",
1316 // attributes[*attributeCount], values[*attributeCount], c);
1318 (* attributeCount
)++;
1319 if (* attributeCount
>= TAG_MAX_ATTRIBUTES
) return TAG_BAD
;
1323 c
= nextChar (); // skip '/'
1324 tagType
= TAG_EMPTY
;
1326 if ( c
!= '>' ) return TAG_BAD
;
1327 c
= nextChar (); // skip '>'
1333 getString ( parser_state_t
* state
)
1335 int c
= currentChar ();
1336 int start
, length
, i
, j
;
1339 start
= state
-> parseBufferIndex
;
1340 /* find end of string */
1343 if ( c
== ' \n ' ) state
-> lineNumber
++;
1350 if ( c
!= '<' ) return 0 ;
1352 length
= state
-> parseBufferIndex
- start
;
1354 /* copy to null terminated buffer */
1355 tempString
= ( char *) malloc ( length
+ 1 );
1356 if ( tempString
== 0 ) {
1357 printf ( "OSUnserializeXML: can't alloc temp memory \n " );
1361 // copy out string in tempString
1362 // "&" -> '&', "<" -> '<', ">" -> '>'
1365 while ( i
< length
) {
1366 c
= state
-> parseBuffer
[ start
+ i
++];
1368 tempString
[ j
++] = c
;
1370 if (( i
+ 3 ) > length
) goto error
;
1371 c
= state
-> parseBuffer
[ start
+ i
++];
1373 if ( state
-> parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1374 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1375 tempString
[ j
++] = '<' ;
1379 if ( state
-> parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1380 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1381 tempString
[ j
++] = '>' ;
1384 if (( i
+ 3 ) > length
) goto error
;
1386 if ( state
-> parseBuffer
[ start
+ i
++] != 'm' ) goto error
;
1387 if ( state
-> parseBuffer
[ start
+ i
++] != 'p' ) goto error
;
1388 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1389 tempString
[ j
++] = '&' ;
1397 // printf("string %s\n", tempString);
1402 if ( tempString
) free ( tempString
);
1407 getNumber ( parser_state_t
* state
)
1409 unsigned long long n
= 0 ;
1411 bool negate
= false ;
1412 int c
= currentChar ();
1427 n
= ( n
* base
+ c
- '0' );
1431 n
= ( unsigned long long )(( long long ) n
* ( long long )- 1 );
1434 while ( isHexDigit ( c
)) {
1436 n
= ( n
* base
+ c
- '0' );
1438 n
= ( n
* base
+ 0xa + c
- 'a' );
1443 // printf("number 0x%x\n", (unsigned long)n);
1447 // taken from CFXMLParsing/CFPropertyList.c
1449 static const signed char __CFPLDataDecodeTable
[ 128 ] = {
1450 /* 000 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1451 /* 010 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1452 /* 020 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1453 /* 030 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1454 /* ' ' */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1455 /* '(' */ - 1 , - 1 , - 1 , 62 , - 1 , - 1 , - 1 , 63 ,
1456 /* '0' */ 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 ,
1457 /* '8' */ 60 , 61 , - 1 , - 1 , - 1 , 0 , - 1 , - 1 ,
1458 /* '@' */ - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 ,
1459 /* 'H' */ 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ,
1460 /* 'P' */ 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 ,
1461 /* 'X' */ 23 , 24 , 25 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1462 /* '`' */ - 1 , 26 , 27 , 28 , 29 , 30 , 31 , 32 ,
1463 /* 'h' */ 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 ,
1464 /* 'p' */ 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 ,
1465 /* 'x' */ 49 , 50 , 51 , - 1 , - 1 , - 1 , - 1 , - 1
1468 #define DATA_ALLOC_SIZE 4096
1471 getCFEncodedData ( parser_state_t
* state
, unsigned int * size
)
1473 int numeq
= 0 , acc
= 0 , cntr
= 0 ;
1474 int tmpbufpos
= 0 , tmpbuflen
= 0 ;
1475 unsigned char * tmpbuf
= ( unsigned char *) malloc ( DATA_ALLOC_SIZE
);
1477 int c
= currentChar ();
1486 if ( c
== '=' ) numeq
++; else numeq
= 0 ;
1487 if ( c
== ' \n ' ) state
-> lineNumber
++;
1488 if ( __CFPLDataDecodeTable
[ c
] < 0 ) {
1494 acc
+= __CFPLDataDecodeTable
[ c
];
1495 if ( 0 == ( cntr
& 0x3 )) {
1496 if ( tmpbuflen
<= tmpbufpos
+ 2 ) {
1497 tmpbuflen
+= DATA_ALLOC_SIZE
;
1498 tmpbuf
= ( unsigned char *) realloc ( tmpbuf
, tmpbuflen
);
1500 tmpbuf
[ tmpbufpos
++] = ( acc
>> 16 ) & 0xff ;
1502 tmpbuf
[ tmpbufpos
++] = ( acc
>> 8 ) & 0xff ;
1504 tmpbuf
[ tmpbufpos
++] = acc
& 0xff ;
1517 getHexData ( parser_state_t
* state
, unsigned int * size
)
1520 unsigned char * d
, * start
, * lastStart
;
1522 start
= lastStart
= d
= ( unsigned char *) malloc ( DATA_ALLOC_SIZE
);
1527 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1529 state
-> lineNumber
++;
1536 * d
= ( c
- '0' ) << 4 ;
1537 } else if ( isAlphaDigit ( c
)) {
1538 * d
= ( 0xa + ( c
- 'a' )) << 4 ;
1547 } else if ( isAlphaDigit ( c
)) {
1548 * d
|= 0xa + ( c
- 'a' );
1554 if (( d
- lastStart
) >= DATA_ALLOC_SIZE
) {
1555 int oldsize
= d
- start
;
1556 start
= ( unsigned char *) realloc ( start
, oldsize
+ DATA_ALLOC_SIZE
);
1557 d
= lastStart
= start
+ oldsize
;
1573 yylex ( YYSTYPE
* lvalp
, parser_state_t
* state
)
1577 char tag
[ TAG_MAX_LENGTH
];
1579 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1580 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1586 /* skip white space */
1587 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1589 /* keep track of line number, don't return \n's */
1591 STATE
-> lineNumber
++;
1596 // end of the buffer?
1599 tagType
= getTag ( STATE
, tag
, & attributeCount
, attributes
, values
);
1600 if ( tagType
== TAG_BAD
) return SYNTAX_ERROR
;
1601 if ( tagType
== TAG_COMMENT
) goto top
;
1603 // handle allocation and check for "ID" and "IDREF" tags up front
1604 * lvalp
= object
= newObject ( STATE
);
1606 for ( i
= 0 ; i
< attributeCount
; i
++) {
1607 if ( attributes
[ i
][ 0 ] == 'I' && attributes
[ i
][ 1 ] == 'D' ) {
1608 // check for idref's, note: we ignore the tag, for
1609 // this to work correctly, all idrefs must be unique
1610 // across the whole serialization
1611 if ( attributes
[ i
][ 2 ] == 'R' && attributes
[ i
][ 3 ] == 'E' &&
1612 attributes
[ i
][ 4 ] == 'F' && ! attributes
[ i
][ 5 ]) {
1613 if ( tagType
!= TAG_EMPTY
) return SYNTAX_ERROR
;
1614 object
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1618 if (! attributes
[ i
][ 2 ]) {
1619 object
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1621 return SYNTAX_ERROR
;
1628 if (! strcmp ( tag
, "array" )) {
1629 if ( tagType
== TAG_EMPTY
) {
1630 object
-> elements
= NULL
;
1633 return ( tagType
== TAG_START
) ? '(' : ')' ;
1637 if (! strcmp ( tag
, "dict" )) {
1638 if ( tagType
== TAG_EMPTY
) {
1639 object
-> elements
= NULL
;
1642 return ( tagType
== TAG_START
) ? '{' : '}' ;
1644 if (! strcmp ( tag
, "data" )) {
1646 if ( tagType
== TAG_EMPTY
) {
1647 object
-> data
= NULL
;
1652 bool isHexFormat
= false ;
1653 for ( int i
= 0 ; i
< attributeCount
; i
++) {
1654 if (! strcmp ( attributes
[ i
], "format" ) && ! strcmp ( values
[ i
], "hex" )) {
1659 // CF encoded is the default form
1661 object
-> data
= getHexData ( STATE
, & size
);
1663 object
-> data
= getCFEncodedData ( STATE
, & size
);
1665 object
-> size
= size
;
1666 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "data" )) {
1667 return SYNTAX_ERROR
;
1673 if (! strcmp ( tag
, "false" )) {
1674 if ( tagType
== TAG_EMPTY
) {
1681 if (! strcmp ( tag
, "integer" )) {
1682 object
-> size
= 64 ; // default
1683 for ( i
= 0 ; i
< attributeCount
; i
++) {
1684 if (! strcmp ( attributes
[ i
], "size" )) {
1685 object
-> size
= strtoul ( values
[ i
], NULL
, 0 );
1688 if ( tagType
== TAG_EMPTY
) {
1692 object
-> number
= getNumber ( STATE
);
1693 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "integer" )) {
1694 return SYNTAX_ERROR
;
1700 if (! strcmp ( tag
, "key" )) {
1701 if ( tagType
== TAG_EMPTY
) return SYNTAX_ERROR
;
1702 object
-> string
= getString ( STATE
);
1703 if (! object
-> string
) {
1704 return SYNTAX_ERROR
;
1706 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1707 || strcmp ( tag
, "key" )) {
1708 return SYNTAX_ERROR
;
1714 if (! strcmp ( tag
, "plist" )) {
1715 freeObject ( STATE
, object
);
1720 if (! strcmp ( tag
, "string" )) {
1721 if ( tagType
== TAG_EMPTY
) {
1722 object
-> string
= ( char *) malloc ( 1 );
1723 object
-> string
[ 0 ] = 0 ;
1726 object
-> string
= getString ( STATE
);
1727 if (! object
-> string
) {
1728 return SYNTAX_ERROR
;
1730 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1731 || strcmp ( tag
, "string" )) {
1732 return SYNTAX_ERROR
;
1736 if (! strcmp ( tag
, "set" )) {
1737 if ( tagType
== TAG_EMPTY
) {
1738 object
-> elements
= NULL
;
1741 if ( tagType
== TAG_START
) {
1749 if (! strcmp ( tag
, "true" )) {
1750 if ( tagType
== TAG_EMPTY
) {
1758 return SYNTAX_ERROR
;
1761 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1762 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1763 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1765 // "java" like allocation, if this code hits a syntax error in the
1766 // the middle of the parsed string we just bail with pointers hanging
1767 // all over place, this code helps keeps it all together
1769 //static int object_count = 0;
1772 newObject ( parser_state_t
* state
)
1776 if ( state
-> freeObjects
) {
1777 o
= state
-> freeObjects
;
1778 state
-> freeObjects
= state
-> freeObjects
-> next
;
1780 o
= ( object_t
*) malloc ( sizeof ( object_t
));
1782 bzero ( o
, sizeof ( object_t
));
1783 o
-> free
= state
-> objects
;
1791 freeObject ( parser_state_t
* state
, object_t
* o
)
1793 o
-> next
= state
-> freeObjects
;
1794 state
-> freeObjects
= o
;
1798 cleanupObjects ( parser_state_t
* state
)
1800 object_t
* t
, * o
= state
-> objects
;
1804 // printf("OSUnserializeXML: releasing object o=%x object=%x\n", (int)o, (int)o->object);
1805 o
-> object
-> release ();
1808 // printf("OSUnserializeXML: freeing object o=%x data=%x\n", (int)o, (int)o->data);
1812 // printf("OSUnserializeXML: releasing object o=%x key=%x\n", (int)o, (int)o->key);
1816 // printf("OSUnserializeXML: freeing object o=%x string=%x\n", (int)o, (int)o->string);
1825 // printf("object_count = %d\n", object_count);
1828 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1829 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1830 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1833 rememberObject ( parser_state_t
* state
, int tag
, OSObject
* o
)
1836 snprintf ( key
, 16 , " %u " , tag
);
1838 // printf("remember key %s\n", key);
1840 state
-> tags
-> setObject ( key
, o
);
1844 retrieveObject ( parser_state_t
* state
, int tag
)
1849 snprintf ( key
, 16 , " %u " , tag
);
1851 // printf("retrieve key '%s'\n", key);
1853 ref
= state
-> tags
-> getObject ( key
);
1856 o
= newObject ( state
);
1861 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1862 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1863 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1866 buildDictionary ( parser_state_t
* state
, object_t
* header
)
1872 // get count and reverse order
1873 o
= header
-> elements
;
1874 header
-> elements
= 0 ;
1880 t
-> next
= header
-> elements
;
1881 header
-> elements
= t
;
1884 dict
= OSDictionary :: withCapacity ( count
);
1885 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, dict
);
1887 o
= header
-> elements
;
1889 dict
-> setObject ( o
-> key
, o
-> object
);
1892 o
-> object
-> release ();
1898 freeObject ( state
, t
);
1906 buildArray ( parser_state_t
* state
, object_t
* header
)
1912 // get count and reverse order
1913 o
= header
-> elements
;
1914 header
-> elements
= 0 ;
1920 t
-> next
= header
-> elements
;
1921 header
-> elements
= t
;
1924 array
= OSArray :: withCapacity ( count
);
1925 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, array
);
1927 o
= header
-> elements
;
1929 array
-> setObject ( o
-> object
);
1931 o
-> object
-> release ();
1936 freeObject ( state
, t
);
1944 buildSet ( parser_state_t
* state
, object_t
* header
)
1946 object_t
* o
= buildArray ( state
, header
);
1948 OSArray
* array
= ( OSArray
*) o
-> object
;
1949 OSSet
* set
= OSSet :: withArray ( array
, array
-> getCapacity ());
1951 // write over the reference created in buildArray
1952 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, set
);
1960 buildString ( parser_state_t
* state
, object_t
* o
)
1964 string
= OSString :: withCString ( o
-> string
);
1965 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, string
);
1975 buildData ( parser_state_t
* state
, object_t
* o
)
1980 data
= OSData :: withBytes ( o
-> data
, o
-> size
);
1982 data
= OSData :: withCapacity ( 0 );
1984 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, data
);
1986 if ( o
-> size
) free ( o
-> data
);
1993 buildNumber ( parser_state_t
* state
, object_t
* o
)
1995 OSNumber
* number
= OSNumber :: withNumber ( o
-> number
, o
-> size
);
1997 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, number
);
2004 buildBoolean ( parser_state_t
* state
, object_t
* o
)
2006 o
-> object
= (( o
-> number
== 0 ) ? kOSBooleanFalse
: kOSBooleanTrue
);
2007 o
-> object
-> retain ();
2012 OSUnserializeXML ( const char * buffer
, OSString
** errorString
)
2015 parser_state_t
* state
= ( parser_state_t
*) malloc ( sizeof ( parser_state_t
));
2017 if ((! state
) || (! buffer
)) return 0 ;
2020 if ( errorString
) * errorString
= NULL
;
2022 state
-> parseBuffer
= buffer
;
2023 state
-> parseBufferIndex
= 0 ;
2024 state
-> lineNumber
= 1 ;
2026 state
-> freeObjects
= 0 ;
2027 state
-> tags
= OSDictionary :: withCapacity ( 128 );
2028 state
-> errorString
= errorString
;
2029 state
-> parsedObject
= 0 ;
2031 ( void ) yyparse (( void *) state
);
2033 object
= state
-> parsedObject
;
2035 cleanupObjects ( state
);
2036 state
-> tags
-> release ();
2048 // DO NOT EDIT OSUnserializeXML.cpp!