]>
git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSUnserializeXML.cpp
068e91f61bf8d32783f4ce86e36a31e9470d1af4
2 * Copyright (c) 1999-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * OSUnserializeXML.y created by rsulack on Tue Oct 12 1999
29 // parser for unserializing OSContainer objects serialized to XML
32 // bison -p OSUnserializeXML OSUnserializeXML.y
33 // head -50 OSUnserializeXML.y > OSUnserializeXML.cpp
34 // sed -e "s/#include <stdio.h>//" < OSUnserializeXML.tab.c >> OSUnserializeXML.cpp
36 // when changing code check in both OSUnserializeXML.y and OSUnserializeXML.cpp
42 // DO NOT EDIT OSUnserializeXML.cpp!
52 /* A Bison parser, made from OSUnserializeXML.y
53 by GNU Bison version 1.28 */
55 #define YYBISON 1 /* Identify Bison output. */
57 #define yyparse OSUnserializeXMLparse
58 #define yylex OSUnserializeXMLlex
59 #define yyerror OSUnserializeXMLerror
60 #define yylval OSUnserializeXMLlval
61 #define yychar OSUnserializeXMLchar
62 #define yydebug OSUnserializeXMLdebug
63 #define yynerrs OSUnserializeXMLnerrs
67 #define DICTIONARY 260
73 #define SYNTAX_ERROR 266
75 #line 55 "OSUnserializeXML.y"
78 #include <libkern/c++/OSMetaClass.h>
79 #include <libkern/c++/OSContainers.h>
80 #include <libkern/c++/OSLib.h>
82 #define YYSTYPE object_t *
83 #define YYPARSE_PARAM state
84 #define YYLEX_PARAM (parser_state_t *)state
86 // this is the internal struct used to hold objects on parser stack
87 // it represents objects both before and after they have been created
88 typedef struct object
{
91 struct object
* elements
;
93 OSString
* key
; // for dictionary
95 void * data
; // for data
96 char * string
; // for string & symbol
97 long long number
; // for number
101 // this code is reentrant, this structure contains all
102 // state information for the parsing of a single buffer
103 typedef struct parser_state
{
104 const char * parseBuffer
; // start of text to be parsed
105 int parseBufferIndex
; // current index into text
106 int lineNumber
; // current line number
107 object_t
* objects
; // internal objects in use
108 object_t
* freeObjects
; // internal objects that are free
109 OSDictionary
* tags
; // used to remember "ID" tags
110 OSString
** errorString
; // parse error with line
111 OSObject
* parsedObject
; // resultant object of parsed text
114 #define STATE ((parser_state_t *)state)
117 #define yyerror(s) OSUnserializeerror(STATE, (s))
118 static int OSUnserializeerror ( parser_state_t
* state
, char * s
);
120 static int yylex ( YYSTYPE
* lvalp
, parser_state_t
* state
);
121 static int yyparse ( void * state
);
123 static object_t
* newObject ( parser_state_t
* state
);
124 static void freeObject ( parser_state_t
* state
, object_t
* o
);
125 static void rememberObject ( parser_state_t
* state
, int tag
, OSObject
* o
);
126 static object_t
* retrieveObject ( parser_state_t
* state
, int tag
);
127 static void cleanupObjects ( parser_state_t
* state
);
129 static object_t
* buildDictionary ( parser_state_t
* state
, object_t
* o
);
130 static object_t
* buildArray ( parser_state_t
* state
, object_t
* o
);
131 static object_t
* buildSet ( parser_state_t
* state
, object_t
* o
);
132 static object_t
* buildString ( parser_state_t
* state
, object_t
* o
);
133 static object_t
* buildData ( parser_state_t
* state
, object_t
* o
);
134 static object_t
* buildNumber ( parser_state_t
* state
, object_t
* o
);
135 static object_t
* buildBoolean ( parser_state_t
* state
, object_t
* o
);
138 extern void * kern_os_malloc ( size_t size
);
139 extern void * kern_os_realloc ( void * addr
, size_t size
);
140 extern void kern_os_free ( void * addr
);
142 //XXX shouldn't have to define these
143 extern long strtol ( const char *, char **, int );
144 extern unsigned long strtoul ( const char *, char **, int );
148 #define malloc(s) kern_os_malloc(s)
149 #define realloc(a, s) kern_os_realloc(a, s)
150 #define free(a) kern_os_free((void *)a)
166 #define YYFLAG -32768
169 #define YYTRANSLATE(x) ((unsigned)(x) <= 266 ? yytranslate[x] : 33)
171 static const char yytranslate
[] = { 0 ,
172 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
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 , 15 ,
176 16 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
177 2 , 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 17 , 2 , 18 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
182 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
183 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
184 2 , 2 , 13 , 2 , 14 , 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 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 , 1 , 3 , 4 , 5 , 6 ,
202 static const short yyprhs
[] = { 0 ,
203 0 , 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 , 17 ,
204 19 , 21 , 24 , 28 , 30 , 32 , 35 , 38 , 40 , 43 ,
205 47 , 49 , 52 , 56 , 58 , 60 , 63 , 65 , 67 , 69 ,
209 static const short yyrhs
[] = { - 1 ,
210 20 , 0 , 12 , 0 , 21 , 0 , 25 , 0 , 26 , 0 ,
211 32 , 0 , 29 , 0 , 31 , 0 , 28 , 0 , 30 , 0 ,
212 13 , 14 , 0 , 13 , 22 , 14 , 0 , 6 , 0 , 23 ,
213 0 , 22 , 23 , 0 , 24 , 20 , 0 , 8 , 0 , 15 ,
214 16 , 0 , 15 , 27 , 16 , 0 , 3 , 0 , 17 , 18 ,
215 0 , 17 , 27 , 18 , 0 , 10 , 0 , 20 , 0 , 27 ,
216 20 , 0 , 4 , 0 , 5 , 0 , 7 , 0 , 9 , 0 ,
223 static const short yyrline
[] = { 0 ,
224 144 , 147 , 152 , 157 , 158 , 159 , 160 , 161 , 162 , 163 ,
225 164 , 177 , 180 , 183 , 186 , 187 , 192 , 201 , 206 , 209 ,
226 212 , 215 , 218 , 221 , 224 , 227 , 234 , 237 , 240 , 243 ,
232 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
234 static const char * const yytname
[] = { "$" , "error" , "$undefined." , "ARRAY" ,
235 "BOOLEAN" , "DATA" , "DICTIONARY" , "IDREF" , "KEY" , "NUMBER" , "SET" , "STRING" , "SYNTAX_ERROR" ,
236 "'{'" , "'}'" , "'('" , "')'" , "'['" , "']'" , "input" , "object" , "dict" , "pairs" , "pair" , "key" ,
237 "array" , "set" , "elements" , "boolean" , "data" , "idref" , "number" , "string" , NULL
241 static const short yyr1
[] = { 0 ,
242 19 , 19 , 19 , 20 , 20 , 20 , 20 , 20 , 20 , 20 ,
243 20 , 21 , 21 , 21 , 22 , 22 , 23 , 24 , 25 , 25 ,
244 25 , 26 , 26 , 26 , 27 , 27 , 28 , 29 , 30 , 31 ,
248 static const short yyr2
[] = { 0 ,
249 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
250 1 , 2 , 3 , 1 , 1 , 2 , 2 , 1 , 2 , 3 ,
251 1 , 2 , 3 , 1 , 1 , 2 , 1 , 1 , 1 , 1 ,
255 static const short yydefact
[] = { 1 ,
256 21 , 27 , 28 , 14 , 29 , 30 , 24 , 31 , 3 , 0 ,
257 0 , 0 , 2 , 4 , 5 , 6 , 10 , 8 , 11 , 9 ,
258 7 , 18 , 12 , 0 , 15 , 0 , 19 , 25 , 0 , 22 ,
259 0 , 13 , 16 , 17 , 20 , 26 , 23 , 0 , 0 , 0
262 static const short yydefgoto
[] = { 38 ,
263 28 , 14 , 24 , 25 , 26 , 15 , 16 , 29 , 17 , 18 ,
267 static const short yypact
[] = { 45 ,
268 - 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 4 ,
269 60 , - 2 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,
270 - 32768 ,- 32768 ,- 32768 , 6 ,- 32768 , 90 ,- 32768 ,- 32768 , 75 ,- 32768 ,
271 29 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 10 , 17 ,- 32768
274 static const short yypgoto
[] = {- 32768 ,
275 0 ,- 32768 ,- 32768 , - 18 ,- 32768 ,- 32768 ,- 32768 , 7 ,- 32768 ,- 32768 ,
283 static const short yytable
[] = { 13 ,
284 1 , 2 , 3 , 4 , 5 , 33 , 6 , 7 , 8 , 39 ,
285 10 , 22 , 11 , 22 , 12 , 30 , 40 , 23 , 31 , 32 ,
286 0 , 0 , 0 , 0 , 0 , 34 , 0 , 0 , 36 , 0 ,
287 36 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 , 8 ,
288 0 , 10 , 0 , 11 , 0 , 12 , 37 , 1 , 2 , 3 ,
289 4 , 5 , 0 , 6 , 7 , 8 , 9 , 10 , 0 , 11 ,
290 0 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
291 8 , 0 , 10 , 0 , 11 , 27 , 12 , 1 , 2 , 3 ,
292 4 , 5 , 0 , 6 , 7 , 8 , 0 , 10 , 0 , 11 ,
293 35 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
294 8 , 0 , 10 , 0 , 11 , 0 , 12
297 static const short yycheck
[] = { 0 ,
298 3 , 4 , 5 , 6 , 7 , 24 , 9 , 10 , 11 , 0 ,
299 13 , 8 , 15 , 8 , 17 , 18 , 0 , 14 , 12 , 14 ,
300 - 1 , - 1 , - 1 , - 1 , - 1 , 26 , - 1 , - 1 , 29 , - 1 ,
301 31 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 , 11 ,
302 - 1 , 13 , - 1 , 15 , - 1 , 17 , 18 , 3 , 4 , 5 ,
303 6 , 7 , - 1 , 9 , 10 , 11 , 12 , 13 , - 1 , 15 ,
304 - 1 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
305 11 , - 1 , 13 , - 1 , 15 , 16 , 17 , 3 , 4 , 5 ,
306 6 , 7 , - 1 , 9 , 10 , 11 , - 1 , 13 , - 1 , 15 ,
307 16 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
308 11 , - 1 , 13 , - 1 , 15 , - 1 , 17
312 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
313 #line 3 "/usr/share/bison.simple"
314 /* This file comes from bison-1.28. */
316 /* Skeleton output parser for bison,
317 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
319 This program is free software; you can redistribute it and/or modify
320 it under the terms of the GNU General Public License as published by
321 the Free Software Foundation; either version 2, or (at your option)
324 This program is distributed in the hope that it will be useful,
325 but WITHOUT ANY WARRANTY; without even the implied warranty of
326 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
327 GNU General Public License for more details.
329 You should have received a copy of the GNU General Public License
330 along with this program; if not, write to the Free Software
331 Foundation, Inc., 59 Temple Place - Suite 330,
332 Boston, MA 02111-1307, USA. */
334 /* As a special exception, when this file is copied by Bison into a
335 Bison output file, you may use that output file without restriction.
336 This special exception was added by the Free Software Foundation
337 in version 1.24 of Bison. */
339 /* This is the parser code that is written into each bison parser
340 when the %semantic_parser declaration is not specified in the grammar.
341 It was written by Richard Stallman by simplifying the hairy parser
342 used when %semantic_parser is specified. */
344 #ifndef YYSTACK_USE_ALLOCA
346 #define YYSTACK_USE_ALLOCA
347 #else /* alloca not defined */
349 #define YYSTACK_USE_ALLOCA
350 #define alloca __builtin_alloca
351 #else /* not GNU C. */
352 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
353 #define YYSTACK_USE_ALLOCA
355 #else /* not sparc */
356 /* We think this test detects Watcom and Microsoft C. */
357 /* This used to test MSDOS, but that is a bad idea
358 since that symbol is in the user namespace. */
359 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
360 #if 0 /* No need for malloc.h, which pollutes the namespace;
361 instead, just don't use alloca. */
364 #else /* not MSDOS, or __TURBOC__ */
366 /* I don't know what this was needed for, but it pollutes the namespace.
367 So I turned it off. rms, 2 May 1997. */
368 /* #include <malloc.h> */
370 #define YYSTACK_USE_ALLOCA
371 #else /* not MSDOS, or __TURBOC__, or _AIX */
373 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
374 and on HPUX 10. Eventually we can turn this on. */
375 #define YYSTACK_USE_ALLOCA
376 #define alloca __builtin_alloca
379 #endif /* not _AIX */
380 #endif /* not MSDOS, or __TURBOC__ */
381 #endif /* not sparc */
382 #endif /* not GNU C */
383 #endif /* alloca not defined */
384 #endif /* YYSTACK_USE_ALLOCA not defined */
386 #ifdef YYSTACK_USE_ALLOCA
387 #define YYSTACK_ALLOC alloca
389 #define YYSTACK_ALLOC malloc
392 /* Note: there must be only one dollar sign in this file.
393 It is replaced by the list of actions, each action
394 as one case of the switch. */
396 #define yyerrok (yyerrstatus = 0)
397 #define yyclearin (yychar = YYEMPTY)
400 #define YYACCEPT goto yyacceptlab
401 #define YYABORT goto yyabortlab
402 #define YYERROR goto yyerrlab1
403 /* Like YYERROR except do call yyerror.
404 This remains here temporarily to ease the
405 transition to the new meaning of YYERROR, for GCC.
406 Once GCC version 2 has supplanted version 1, this can go. */
407 #define YYFAIL goto yyerrlab
408 #define YYRECOVERING() (!!yyerrstatus)
409 #define YYBACKUP(token, value) \
411 if (yychar == YYEMPTY && yylen == 1) \
412 { yychar = (token), yylval = (value); \
413 yychar1 = YYTRANSLATE (yychar); \
418 { yyerror ( "syntax error: cannot back up" ); YYERROR; } \
422 #define YYERRCODE 256
425 #define YYLEX yylex()
431 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
433 #define YYLEX yylex(&yylval, &yylloc)
435 #else /* not YYLSP_NEEDED */
437 #define YYLEX yylex(&yylval, YYLEX_PARAM)
439 #define YYLEX yylex(&yylval)
441 #endif /* not YYLSP_NEEDED */
444 /* If nonreentrant, generate the variables here */
448 int yychar
; /* the lookahead symbol */
449 YYSTYPE yylval
; /* the semantic value of the */
450 /* lookahead symbol */
453 YYLTYPE yylloc
; /* location data for the lookahead */
457 int yynerrs
; /* number of parse errors so far */
458 #endif /* not YYPURE */
461 int yydebug
; /* nonzero means print parse trace */
462 /* Since this is uninitialized, it does not stop multiple parsers
466 /* YYINITDEPTH indicates the initial size of the parser's stacks */
469 #define YYINITDEPTH 200
472 /* YYMAXDEPTH is the maximum size the stacks can grow to
473 (effective only if the built-in stack extension method is used). */
480 #define YYMAXDEPTH 10000
483 /* Define __yy_memcpy. Note that the size argument
484 should be passed with type unsigned int, because that is what the non-GCC
485 definitions require. With GCC, __builtin_memcpy takes an arg
486 of type size_t, but it can handle unsigned int. */
488 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
489 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
490 #else /* not GNU C or C++ */
493 /* This is the most reliable way to avoid incompatibilities
494 in available built-in functions on various systems. */
496 __yy_memcpy ( to
, from
, count
)
501 register char * f
= from
;
502 register char * t
= to
;
503 register int i
= count
;
509 #else /* __cplusplus */
511 /* This is the most reliable way to avoid incompatibilities
512 in available built-in functions on various systems. */
514 __yy_memcpy ( char * to
, char * from
, unsigned int count
)
516 register char * t
= to
;
517 register char * f
= from
;
518 register int i
= count
;
527 #line 217 "/usr/share/bison.simple"
529 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
530 into yyparse. The argument should have type void *.
531 It should actually point to an object.
532 Grammar actions can access the variable by casting it
533 to the proper pointer type. */
537 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
538 #define YYPARSE_PARAM_DECL
539 #else /* not __cplusplus */
540 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
541 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
542 #endif /* not __cplusplus */
543 #else /* not YYPARSE_PARAM */
544 #define YYPARSE_PARAM_ARG
545 #define YYPARSE_PARAM_DECL
546 #endif /* not YYPARSE_PARAM */
548 /* Prevent warning if -Wstrict-prototypes. */
551 int yyparse ( void *);
558 yyparse ( YYPARSE_PARAM_ARG
)
561 register int yystate
;
563 register short * yyssp
;
564 register YYSTYPE
* yyvsp
;
565 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
566 int yychar1
= 0 ; /* lookahead token as an internal (translated) token number */
568 short yyssa
[ YYINITDEPTH
]; /* the state stack */
569 YYSTYPE yyvsa
[ YYINITDEPTH
]; /* the semantic value stack */
571 short * yyss
= yyssa
; /* refer to the stacks thru separate pointers */
572 YYSTYPE
* yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
575 YYLTYPE yylsa
[ YYINITDEPTH
]; /* the location stack */
576 YYLTYPE
* yyls
= yylsa
;
579 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
581 #define YYPOPSTACK (yyvsp--, yyssp--)
584 int yystacksize
= YYINITDEPTH
;
585 int yyfree_stacks
= 0 ;
596 YYSTYPE yyval
; /* the variable used to return */
597 /* semantic values from the action */
604 fprintf ( stderr
, "Starting parse \n " );
610 yychar
= YYEMPTY
; /* Cause a token to be read. */
612 /* Initialize stack pointers.
613 Waste one element of value and location stack
614 so that they stay on the same level as the state stack.
615 The wasted elements are never initialized. */
623 /* Push a new state, which is found in yystate . */
624 /* In all cases, when you get here, the value and location stacks
625 have just been pushed. so pushing a state here evens the stacks. */
630 if ( yyssp
>= yyss
+ yystacksize
- 1 )
632 /* Give user a chance to reallocate the stack */
633 /* Use copies of these so that the &'s don't force the real ones into memory. */
634 YYSTYPE
* yyvs1
= yyvs
;
637 YYLTYPE
* yyls1
= yyls
;
640 /* Get the current used size of the three stacks, in elements. */
641 int size
= yyssp
- yyss
+ 1 ;
644 /* Each stack pointer address is followed by the size of
645 the data in use in that stack, in bytes. */
647 /* This used to be a conditional around just the two extra args,
648 but that might be undefined if yyoverflow is a macro. */
649 yyoverflow ( "parser stack overflow" ,
650 & yyss1
, size
* sizeof (* yyssp
),
651 & yyvs1
, size
* sizeof (* yyvsp
),
652 & yyls1
, size
* sizeof (* yylsp
),
655 yyoverflow ( "parser stack overflow" ,
656 & yyss1
, size
* sizeof (* yyssp
),
657 & yyvs1
, size
* sizeof (* yyvsp
),
661 yyss
= yyss1
; yyvs
= yyvs1
;
665 #else /* no yyoverflow */
666 /* Extend the stack our own way. */
667 if ( yystacksize
>= YYMAXDEPTH
)
669 yyerror ( "parser stack overflow" );
681 if ( yystacksize
> YYMAXDEPTH
)
682 yystacksize
= YYMAXDEPTH
;
683 #ifndef YYSTACK_USE_ALLOCA
686 yyss
= ( short *) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyssp
));
687 __yy_memcpy (( char *) yyss
, ( char *) yyss1
,
688 size
* ( unsigned int ) sizeof (* yyssp
));
689 yyvs
= ( YYSTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyvsp
));
690 __yy_memcpy (( char *) yyvs
, ( char *) yyvs1
,
691 size
* ( unsigned int ) sizeof (* yyvsp
));
693 yyls
= ( YYLTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yylsp
));
694 __yy_memcpy (( char *) yyls
, ( char *) yyls1
,
695 size
* ( unsigned int ) sizeof (* yylsp
));
697 #endif /* no yyoverflow */
699 yyssp
= yyss
+ size
- 1 ;
700 yyvsp
= yyvs
+ size
- 1 ;
702 yylsp
= yyls
+ size
- 1 ;
707 fprintf ( stderr
, "Stack size increased to %d \n " , yystacksize
);
710 if ( yyssp
>= yyss
+ yystacksize
- 1 )
716 fprintf ( stderr
, "Entering state %d \n " , yystate
);
722 /* Do appropriate processing given the current state. */
723 /* Read a lookahead token if we need one and don't already have one. */
726 /* First try to decide what to do without reference to lookahead token. */
728 yyn
= yypact
[ yystate
];
732 /* Not known => get a lookahead token if don't already have one. */
734 /* yychar is either YYEMPTY or YYEOF
735 or a valid token in external form. */
737 if ( yychar
== YYEMPTY
)
741 fprintf ( stderr
, "Reading a token: " );
746 /* Convert token to internal form (in yychar1) for indexing tables with */
748 if ( yychar
<= 0 ) /* This means end of input. */
751 yychar
= YYEOF
; /* Don't call YYLEX any more */
755 fprintf ( stderr
, "Now at end of input. \n " );
760 yychar1
= YYTRANSLATE ( yychar
);
765 fprintf ( stderr
, "Next token is %d ( %s " , yychar
, yytname
[ yychar1
]);
766 /* Give the individual parser a way to print the precise meaning
767 of a token, for further debugging info. */
769 YYPRINT ( stderr
, yychar
, yylval
);
771 fprintf ( stderr
, ") \n " );
777 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != yychar1
)
782 /* yyn is what to do for this token type in this state.
783 Negative => reduce, -yyn is rule number.
784 Positive => shift, yyn is new state.
785 New state is final state => don't bother to shift,
787 0, or most negative number => error. */
802 /* Shift the lookahead token. */
806 fprintf ( stderr
, "Shifting token %d ( %s ), " , yychar
, yytname
[ yychar1
]);
809 /* Discard the token being shifted unless it is eof. */
818 /* count tokens shifted since error; after three, turn off error status. */
819 if ( yyerrstatus
) yyerrstatus
--;
824 /* Do the default action for the current state. */
827 yyn
= yydefact
[ yystate
];
831 /* Do a reduction. yyn is the number of a rule to reduce with. */
835 yyval
= yyvsp
[ 1 - yylen
]; /* implement default value of the action */
842 fprintf ( stderr
, "Reducing via rule %d (line %d ), " ,
845 /* Print the symbols being reduced, and their result. */
846 for ( i
= yyprhs
[ yyn
]; yyrhs
[ i
] > 0 ; i
++)
847 fprintf ( stderr
, " %s " , yytname
[ yyrhs
[ i
]]);
848 fprintf ( stderr
, " -> %s \n " , yytname
[ yyr1
[ yyn
]]);
856 #line 144 "OSUnserializeXML.y"
857 { yyerror ( "unexpected end of buffer" );
862 #line 147 "OSUnserializeXML.y"
863 { STATE
-> parsedObject
= yyvsp
[ 0 ]-> object
;
864 yyvsp
[ 0 ]-> object
= 0 ;
865 freeObject ( STATE
, yyvsp
[ 0 ]);
870 #line 152 "OSUnserializeXML.y"
871 { yyerror ( "syntax error" );
876 #line 157 "OSUnserializeXML.y"
877 { yyval
= buildDictionary ( STATE
, yyvsp
[ 0 ]); ;
880 #line 158 "OSUnserializeXML.y"
881 { yyval
= buildArray ( STATE
, yyvsp
[ 0 ]); ;
884 #line 159 "OSUnserializeXML.y"
885 { yyval
= buildSet ( STATE
, yyvsp
[ 0 ]); ;
888 #line 160 "OSUnserializeXML.y"
889 { yyval
= buildString ( STATE
, yyvsp
[ 0 ]); ;
892 #line 161 "OSUnserializeXML.y"
893 { yyval
= buildData ( STATE
, yyvsp
[ 0 ]); ;
896 #line 162 "OSUnserializeXML.y"
897 { yyval
= buildNumber ( STATE
, yyvsp
[ 0 ]); ;
900 #line 163 "OSUnserializeXML.y"
901 { yyval
= buildBoolean ( STATE
, yyvsp
[ 0 ]); ;
904 #line 164 "OSUnserializeXML.y"
905 { yyval
= retrieveObject ( STATE
, yyvsp
[ 0 ]-> idref
);
907 yyval
-> object
-> retain ();
909 yyerror ( "forward reference detected" );
912 freeObject ( STATE
, yyvsp
[ 0 ]);
916 #line 177 "OSUnserializeXML.y"
918 yyval
-> elements
= NULL
;
922 #line 180 "OSUnserializeXML.y"
924 yyval
-> elements
= yyvsp
[- 1 ];
928 #line 187 "OSUnserializeXML.y"
930 yyval
-> next
= yyvsp
[- 1 ];
934 #line 192 "OSUnserializeXML.y"
936 yyval
-> key
= ( OSString
*) yyval
-> object
;
937 yyval
-> object
= yyvsp
[ 0 ]-> object
;
939 yyvsp
[ 0 ]-> object
= 0 ;
940 freeObject ( STATE
, yyvsp
[ 0 ]);
944 #line 201 "OSUnserializeXML.y"
945 { yyval
= buildString ( STATE
, yyvsp
[ 0 ]); ;
948 #line 206 "OSUnserializeXML.y"
950 yyval
-> elements
= NULL
;
954 #line 209 "OSUnserializeXML.y"
956 yyval
-> elements
= yyvsp
[- 1 ];
960 #line 215 "OSUnserializeXML.y"
962 yyval
-> elements
= NULL
;
966 #line 218 "OSUnserializeXML.y"
968 yyval
-> elements
= yyvsp
[- 1 ];
972 #line 224 "OSUnserializeXML.y"
978 #line 227 "OSUnserializeXML.y"
980 yyval
-> next
= yyvsp
[- 1 ];
984 /* the action file gets copied in in place of this dollarsign */
985 #line 543 "/usr/share/bison.simple"
996 short * ssp1
= yyss
- 1 ;
997 fprintf ( stderr
, "state stack now" );
998 while ( ssp1
!= yyssp
)
999 fprintf ( stderr
, " %d " , *++ ssp1
);
1000 fprintf ( stderr
, " \n " );
1010 yylsp
-> first_line
= yylloc
. first_line
;
1011 yylsp
-> first_column
= yylloc
. first_column
;
1012 yylsp
-> last_line
= ( yylsp
- 1 )-> last_line
;
1013 yylsp
-> last_column
= ( yylsp
- 1 )-> last_column
;
1018 yylsp
-> last_line
= ( yylsp
+ yylen
- 1 )-> last_line
;
1019 yylsp
-> last_column
= ( yylsp
+ yylen
- 1 )-> last_column
;
1023 /* Now "shift" the result of the reduction.
1024 Determine what state that goes to,
1025 based on the state we popped back to
1026 and the rule number reduced by. */
1030 yystate
= yypgoto
[ yyn
- YYNTBASE
] + * yyssp
;
1031 if ( yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[ yystate
] == * yyssp
)
1032 yystate
= yytable
[ yystate
];
1034 yystate
= yydefgoto
[ yyn
- YYNTBASE
];
1038 yyerrlab
: /* here on detecting error */
1041 /* If not already recovering from an error, report this error. */
1045 #ifdef YYERROR_VERBOSE
1046 yyn
= yypact
[ yystate
];
1048 if ( yyn
> YYFLAG
&& yyn
< YYLAST
)
1055 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1056 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1057 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1058 if ( yycheck
[ x
+ yyn
] == x
)
1059 size
+= strlen ( yytname
[ x
]) + 15 , count
++;
1060 msg
= ( char *) malloc ( size
+ 15 );
1063 strcpy ( msg
, "parse error" );
1068 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1069 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1070 if ( yycheck
[ x
+ yyn
] == x
)
1072 strcat ( msg
, count
== 0 ? ", expecting `" : " or `" );
1073 strcat ( msg
, yytname
[ x
]);
1082 yyerror ( "parse error; also virtual memory exceeded" );
1085 #endif /* YYERROR_VERBOSE */
1086 yyerror ( "parse error" );
1090 yyerrlab1
: /* here on error raised explicitly by an action */
1092 if ( yyerrstatus
== 3 )
1094 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1096 /* return failure if at end of input */
1097 if ( yychar
== YYEOF
)
1102 fprintf ( stderr
, "Discarding token %d ( %s ). \n " , yychar
, yytname
[ yychar1
]);
1108 /* Else will try to reuse lookahead token
1109 after shifting the error token. */
1111 yyerrstatus
= 3 ; /* Each real token shifted decrements this */
1115 yyerrdefault
: /* current state does not do anything special for the error token. */
1118 /* This is wrong; only states that explicitly want error tokens
1119 should shift them. */
1120 yyn
= yydefact
[ yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1121 if ( yyn
) goto yydefault
;
1124 yyerrpop
: /* pop the current state because it cannot handle the error token */
1126 if ( yyssp
== yyss
) YYABORT
;
1136 short * ssp1
= yyss
- 1 ;
1137 fprintf ( stderr
, "Error: state stack now" );
1138 while ( ssp1
!= yyssp
)
1139 fprintf ( stderr
, " %d " , *++ ssp1
);
1140 fprintf ( stderr
, " \n " );
1146 yyn
= yypact
[ yystate
];
1151 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != YYTERROR
)
1170 fprintf ( stderr
, "Shifting error token, " );
1182 /* YYACCEPT comes here. */
1194 /* YYABORT comes here. */
1205 #line 249 "OSUnserializeXML.y"
1209 OSUnserializeerror ( parser_state_t
* state
, char * s
) /* Called by yyparse on errors */
1211 char tempString
[ 128 ];
1213 if ( state
-> errorString
) {
1214 snprintf ( tempString
, 128 , "OSUnserializeXML: %s near line %d \n " , s
, state
-> lineNumber
);
1215 *( state
-> errorString
) = OSString :: withCString ( tempString
);
1221 #define TAG_MAX_LENGTH 32
1222 #define TAG_MAX_ATTRIBUTES 32
1227 #define TAG_COMMENT 4
1229 #define currentChar() (state->parseBuffer[state->parseBufferIndex])
1230 #define nextChar() (state->parseBuffer[++state->parseBufferIndex])
1231 #define prevChar() (state->parseBuffer[state->parseBufferIndex - 1])
1233 #define isSpace(c) ((c) == ' ' || (c) == ' \t ' )
1234 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z' ) || ((c) >= 'a' && (c) <= 'z' ))
1235 #define isDigit(c) ((c) >= '0' && (c) <= '9' )
1236 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f' )
1237 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
1238 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-' ))
1241 getTag ( parser_state_t
* state
,
1242 char tag
[ TAG_MAX_LENGTH
],
1243 int * attributeCount
,
1244 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
],
1245 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
] )
1248 int c
= currentChar ();
1249 int tagType
= TAG_START
;
1251 * attributeCount
= 0 ;
1253 if ( c
!= '<' ) return TAG_BAD
;
1254 c
= nextChar (); // skip '<'
1256 if ( c
== '?' || c
== '!' ) {
1257 while (( c
= nextChar ()) != 0 ) {
1258 if ( c
== ' \n ' ) state
-> lineNumber
++;
1267 c
= nextChar (); // skip '/'
1270 if (! isAlpha ( c
)) return TAG_BAD
;
1272 /* find end of tag while copying it */
1273 while ( isAlphaNumeric ( c
)) {
1276 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1281 // printf("tag %s, type %d\n", tag, tagType);
1283 // look for attributes of the form attribute = "value" ...
1284 while (( c
!= '>' ) && ( c
!= '/' )) {
1285 while ( isSpace ( c
)) c
= nextChar ();
1288 while ( isAlphaNumeric ( c
)) {
1289 attributes
[* attributeCount
][ length
++] = c
;
1290 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1293 attributes
[* attributeCount
][ length
] = 0 ;
1295 while ( isSpace ( c
)) c
= nextChar ();
1297 if ( c
!= '=' ) return TAG_BAD
;
1300 while ( isSpace ( c
)) c
= nextChar ();
1302 if ( c
!= '"' ) return TAG_BAD
;
1306 values
[* attributeCount
][ length
++] = c
;
1307 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1310 values
[* attributeCount
][ length
] = 0 ;
1312 c
= nextChar (); // skip closing quote
1314 // printf(" attribute '%s' = '%s', nextchar = '%c'\n",
1315 // attributes[*attributeCount], values[*attributeCount], c);
1317 (* attributeCount
)++;
1318 if (* attributeCount
>= TAG_MAX_ATTRIBUTES
) return TAG_BAD
;
1322 c
= nextChar (); // skip '/'
1323 tagType
= TAG_EMPTY
;
1325 if ( c
!= '>' ) return TAG_BAD
;
1326 c
= nextChar (); // skip '>'
1332 getString ( parser_state_t
* state
)
1334 int c
= currentChar ();
1335 int start
, length
, i
, j
;
1338 start
= state
-> parseBufferIndex
;
1339 /* find end of string */
1342 if ( c
== ' \n ' ) state
-> lineNumber
++;
1349 if ( c
!= '<' ) return 0 ;
1351 length
= state
-> parseBufferIndex
- start
;
1353 /* copy to null terminated buffer */
1354 tempString
= ( char *) malloc ( length
+ 1 );
1355 if ( tempString
== 0 ) {
1356 printf ( "OSUnserializeXML: can't alloc temp memory \n " );
1360 // copy out string in tempString
1361 // "&" -> '&', "<" -> '<', ">" -> '>'
1364 while ( i
< length
) {
1365 c
= state
-> parseBuffer
[ start
+ i
++];
1367 tempString
[ j
++] = c
;
1369 if (( i
+ 3 ) > length
) goto error
;
1370 c
= state
-> parseBuffer
[ start
+ i
++];
1372 if ( state
-> parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1373 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1374 tempString
[ j
++] = '<' ;
1378 if ( state
-> parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1379 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1380 tempString
[ j
++] = '>' ;
1383 if (( i
+ 3 ) > length
) goto error
;
1385 if ( state
-> parseBuffer
[ start
+ i
++] != 'm' ) goto error
;
1386 if ( state
-> parseBuffer
[ start
+ i
++] != 'p' ) goto error
;
1387 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1388 tempString
[ j
++] = '&' ;
1396 // printf("string %s\n", tempString);
1401 if ( tempString
) free ( tempString
);
1406 getNumber ( parser_state_t
* state
)
1408 unsigned long long n
= 0 ;
1410 bool negate
= false ;
1411 int c
= currentChar ();
1426 n
= ( n
* base
+ c
- '0' );
1430 n
= ( unsigned long long )(( long long ) n
* ( long long )- 1 );
1433 while ( isHexDigit ( c
)) {
1435 n
= ( n
* base
+ c
- '0' );
1437 n
= ( n
* base
+ 0xa + c
- 'a' );
1442 // printf("number 0x%x\n", (unsigned long)n);
1446 // taken from CFXMLParsing/CFPropertyList.c
1448 static const signed char __CFPLDataDecodeTable
[ 128 ] = {
1449 /* 000 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1450 /* 010 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1451 /* 020 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1452 /* 030 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1453 /* ' ' */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1454 /* '(' */ - 1 , - 1 , - 1 , 62 , - 1 , - 1 , - 1 , 63 ,
1455 /* '0' */ 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 ,
1456 /* '8' */ 60 , 61 , - 1 , - 1 , - 1 , 0 , - 1 , - 1 ,
1457 /* '@' */ - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 ,
1458 /* 'H' */ 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ,
1459 /* 'P' */ 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 ,
1460 /* 'X' */ 23 , 24 , 25 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1461 /* '`' */ - 1 , 26 , 27 , 28 , 29 , 30 , 31 , 32 ,
1462 /* 'h' */ 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 ,
1463 /* 'p' */ 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 ,
1464 /* 'x' */ 49 , 50 , 51 , - 1 , - 1 , - 1 , - 1 , - 1
1467 #define DATA_ALLOC_SIZE 4096
1470 getCFEncodedData ( parser_state_t
* state
, unsigned int * size
)
1472 int numeq
= 0 , acc
= 0 , cntr
= 0 ;
1473 int tmpbufpos
= 0 , tmpbuflen
= 0 ;
1474 unsigned char * tmpbuf
= ( unsigned char *) malloc ( DATA_ALLOC_SIZE
);
1476 int c
= currentChar ();
1485 if ( c
== '=' ) numeq
++; else numeq
= 0 ;
1486 if ( c
== ' \n ' ) state
-> lineNumber
++;
1487 if ( __CFPLDataDecodeTable
[ c
] < 0 ) {
1493 acc
+= __CFPLDataDecodeTable
[ c
];
1494 if ( 0 == ( cntr
& 0x3 )) {
1495 if ( tmpbuflen
<= tmpbufpos
+ 2 ) {
1496 tmpbuflen
+= DATA_ALLOC_SIZE
;
1497 tmpbuf
= ( unsigned char *) realloc ( tmpbuf
, tmpbuflen
);
1499 tmpbuf
[ tmpbufpos
++] = ( acc
>> 16 ) & 0xff ;
1501 tmpbuf
[ tmpbufpos
++] = ( acc
>> 8 ) & 0xff ;
1503 tmpbuf
[ tmpbufpos
++] = acc
& 0xff ;
1516 getHexData ( parser_state_t
* state
, unsigned int * size
)
1519 unsigned char * d
, * start
, * lastStart
;
1521 start
= lastStart
= d
= ( unsigned char *) malloc ( DATA_ALLOC_SIZE
);
1526 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1528 state
-> lineNumber
++;
1535 * d
= ( c
- '0' ) << 4 ;
1536 } else if ( isAlphaDigit ( c
)) {
1537 * d
= ( 0xa + ( c
- 'a' )) << 4 ;
1546 } else if ( isAlphaDigit ( c
)) {
1547 * d
|= 0xa + ( c
- 'a' );
1553 if (( d
- lastStart
) >= DATA_ALLOC_SIZE
) {
1554 int oldsize
= d
- start
;
1555 start
= ( unsigned char *) realloc ( start
, oldsize
+ DATA_ALLOC_SIZE
);
1556 d
= lastStart
= start
+ oldsize
;
1572 yylex ( YYSTYPE
* lvalp
, parser_state_t
* state
)
1576 char tag
[ TAG_MAX_LENGTH
];
1578 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1579 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1585 /* skip white space */
1586 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1588 /* keep track of line number, don't return \n's */
1590 STATE
-> lineNumber
++;
1595 // end of the buffer?
1598 tagType
= getTag ( STATE
, tag
, & attributeCount
, attributes
, values
);
1599 if ( tagType
== TAG_BAD
) return SYNTAX_ERROR
;
1600 if ( tagType
== TAG_COMMENT
) goto top
;
1602 // handle allocation and check for "ID" and "IDREF" tags up front
1603 * lvalp
= object
= newObject ( STATE
);
1605 for ( i
= 0 ; i
< attributeCount
; i
++) {
1606 if ( attributes
[ i
][ 0 ] == 'I' && attributes
[ i
][ 1 ] == 'D' ) {
1607 // check for idref's, note: we ignore the tag, for
1608 // this to work correctly, all idrefs must be unique
1609 // across the whole serialization
1610 if ( attributes
[ i
][ 2 ] == 'R' && attributes
[ i
][ 3 ] == 'E' &&
1611 attributes
[ i
][ 4 ] == 'F' && ! attributes
[ i
][ 5 ]) {
1612 if ( tagType
!= TAG_EMPTY
) return SYNTAX_ERROR
;
1613 object
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1617 if (! attributes
[ i
][ 2 ]) {
1618 object
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1620 return SYNTAX_ERROR
;
1627 if (! strcmp ( tag
, "array" )) {
1628 if ( tagType
== TAG_EMPTY
) {
1629 object
-> elements
= NULL
;
1632 return ( tagType
== TAG_START
) ? '(' : ')' ;
1636 if (! strcmp ( tag
, "dict" )) {
1637 if ( tagType
== TAG_EMPTY
) {
1638 object
-> elements
= NULL
;
1641 return ( tagType
== TAG_START
) ? '{' : '}' ;
1643 if (! strcmp ( tag
, "data" )) {
1645 if ( tagType
== TAG_EMPTY
) {
1646 object
-> data
= NULL
;
1651 bool isHexFormat
= false ;
1652 for ( int i
= 0 ; i
< attributeCount
; i
++) {
1653 if (! strcmp ( attributes
[ i
], "format" ) && ! strcmp ( values
[ i
], "hex" )) {
1658 // CF encoded is the default form
1660 object
-> data
= getHexData ( STATE
, & size
);
1662 object
-> data
= getCFEncodedData ( STATE
, & size
);
1664 object
-> size
= size
;
1665 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "data" )) {
1666 return SYNTAX_ERROR
;
1672 if (! strcmp ( tag
, "false" )) {
1673 if ( tagType
== TAG_EMPTY
) {
1680 if (! strcmp ( tag
, "integer" )) {
1681 object
-> size
= 64 ; // default
1682 for ( i
= 0 ; i
< attributeCount
; i
++) {
1683 if (! strcmp ( attributes
[ i
], "size" )) {
1684 object
-> size
= strtoul ( values
[ i
], NULL
, 0 );
1687 if ( tagType
== TAG_EMPTY
) {
1691 object
-> number
= getNumber ( STATE
);
1692 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "integer" )) {
1693 return SYNTAX_ERROR
;
1699 if (! strcmp ( tag
, "key" )) {
1700 if ( tagType
== TAG_EMPTY
) return SYNTAX_ERROR
;
1701 object
-> string
= getString ( STATE
);
1702 if (! object
-> string
) {
1703 return SYNTAX_ERROR
;
1705 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1706 || strcmp ( tag
, "key" )) {
1707 return SYNTAX_ERROR
;
1713 if (! strcmp ( tag
, "plist" )) {
1714 freeObject ( STATE
, object
);
1719 if (! strcmp ( tag
, "string" )) {
1720 if ( tagType
== TAG_EMPTY
) {
1721 object
-> string
= ( char *) malloc ( 1 );
1722 object
-> string
[ 0 ] = 0 ;
1725 object
-> string
= getString ( STATE
);
1726 if (! object
-> string
) {
1727 return SYNTAX_ERROR
;
1729 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1730 || strcmp ( tag
, "string" )) {
1731 return SYNTAX_ERROR
;
1735 if (! strcmp ( tag
, "set" )) {
1736 if ( tagType
== TAG_EMPTY
) {
1737 object
-> elements
= NULL
;
1740 if ( tagType
== TAG_START
) {
1748 if (! strcmp ( tag
, "true" )) {
1749 if ( tagType
== TAG_EMPTY
) {
1757 return SYNTAX_ERROR
;
1760 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1761 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1762 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1764 // "java" like allocation, if this code hits a syntax error in the
1765 // the middle of the parsed string we just bail with pointers hanging
1766 // all over place, this code helps keeps it all together
1768 //static int object_count = 0;
1771 newObject ( parser_state_t
* state
)
1775 if ( state
-> freeObjects
) {
1776 o
= state
-> freeObjects
;
1777 state
-> freeObjects
= state
-> freeObjects
-> next
;
1779 o
= ( object_t
*) malloc ( sizeof ( object_t
));
1781 bzero ( o
, sizeof ( object_t
));
1782 o
-> free
= state
-> objects
;
1790 freeObject ( parser_state_t
* state
, object_t
* o
)
1792 o
-> next
= state
-> freeObjects
;
1793 state
-> freeObjects
= o
;
1797 cleanupObjects ( parser_state_t
* state
)
1799 object_t
* t
, * o
= state
-> objects
;
1803 // printf("OSUnserializeXML: releasing object o=%x object=%x\n", (int)o, (int)o->object);
1804 o
-> object
-> release ();
1807 // printf("OSUnserializeXML: freeing object o=%x data=%x\n", (int)o, (int)o->data);
1811 // printf("OSUnserializeXML: releasing object o=%x key=%x\n", (int)o, (int)o->key);
1815 // printf("OSUnserializeXML: freeing object o=%x string=%x\n", (int)o, (int)o->string);
1824 // printf("object_count = %d\n", object_count);
1827 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1828 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1829 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1832 rememberObject ( parser_state_t
* state
, int tag
, OSObject
* o
)
1835 snprintf ( key
, 16 , " %u " , tag
);
1837 // printf("remember key %s\n", key);
1839 state
-> tags
-> setObject ( key
, o
);
1843 retrieveObject ( parser_state_t
* state
, int tag
)
1848 snprintf ( key
, 16 , " %u " , tag
);
1850 // printf("retrieve key '%s'\n", key);
1852 ref
= state
-> tags
-> getObject ( key
);
1855 o
= newObject ( state
);
1860 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1861 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1862 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1865 buildDictionary ( parser_state_t
* state
, object_t
* header
)
1871 // get count and reverse order
1872 o
= header
-> elements
;
1873 header
-> elements
= 0 ;
1879 t
-> next
= header
-> elements
;
1880 header
-> elements
= t
;
1883 dict
= OSDictionary :: withCapacity ( count
);
1884 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, dict
);
1886 o
= header
-> elements
;
1888 dict
-> setObject ( o
-> key
, o
-> object
);
1891 o
-> object
-> release ();
1897 freeObject ( state
, t
);
1905 buildArray ( parser_state_t
* state
, object_t
* header
)
1911 // get count and reverse order
1912 o
= header
-> elements
;
1913 header
-> elements
= 0 ;
1919 t
-> next
= header
-> elements
;
1920 header
-> elements
= t
;
1923 array
= OSArray :: withCapacity ( count
);
1924 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, array
);
1926 o
= header
-> elements
;
1928 array
-> setObject ( o
-> object
);
1930 o
-> object
-> release ();
1935 freeObject ( state
, t
);
1943 buildSet ( parser_state_t
* state
, object_t
* header
)
1945 object_t
* o
= buildArray ( state
, header
);
1947 OSArray
* array
= ( OSArray
*) o
-> object
;
1948 OSSet
* set
= OSSet :: withArray ( array
, array
-> getCapacity ());
1950 // write over the reference created in buildArray
1951 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, set
);
1959 buildString ( parser_state_t
* state
, object_t
* o
)
1963 string
= OSString :: withCString ( o
-> string
);
1964 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, string
);
1974 buildData ( parser_state_t
* state
, object_t
* o
)
1979 data
= OSData :: withBytes ( o
-> data
, o
-> size
);
1981 data
= OSData :: withCapacity ( 0 );
1983 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, data
);
1985 if ( o
-> size
) free ( o
-> data
);
1992 buildNumber ( parser_state_t
* state
, object_t
* o
)
1994 OSNumber
* number
= OSNumber :: withNumber ( o
-> number
, o
-> size
);
1996 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, number
);
2003 buildBoolean ( parser_state_t
* state
, object_t
* o
)
2005 o
-> object
= (( o
-> number
== 0 ) ? kOSBooleanFalse
: kOSBooleanTrue
);
2006 o
-> object
-> retain ();
2011 OSUnserializeXML ( const char * buffer
, OSString
** errorString
)
2014 parser_state_t
* state
= ( parser_state_t
*) malloc ( sizeof ( parser_state_t
));
2016 if ((! state
) || (! buffer
)) return 0 ;
2019 if ( errorString
) * errorString
= NULL
;
2021 state
-> parseBuffer
= buffer
;
2022 state
-> parseBufferIndex
= 0 ;
2023 state
-> lineNumber
= 1 ;
2025 state
-> freeObjects
= 0 ;
2026 state
-> tags
= OSDictionary :: withCapacity ( 128 );
2027 state
-> errorString
= errorString
;
2028 state
-> parsedObject
= 0 ;
2030 ( void ) yyparse (( void *) state
);
2032 object
= state
-> parsedObject
;
2034 cleanupObjects ( state
);
2035 state
-> tags
-> release ();
2047 // DO NOT EDIT OSUnserializeXML.cpp!