]>
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_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * OSUnserializeXML.y created by rsulack on Tue Oct 12 1999
32 // parser for unserializing OSContainer objects serialized to XML
35 // bison -p OSUnserializeXML OSUnserializeXML.y
36 // head -50 OSUnserializeXML.y > OSUnserializeXML.cpp
37 // sed -e "s/#include <stdio.h>//" < OSUnserializeXML.tab.c >> OSUnserializeXML.cpp
39 // when changing code check in both OSUnserializeXML.y and OSUnserializeXML.cpp
45 // DO NOT EDIT OSUnserializeXML.cpp!
55 /* A Bison parser, made from OSUnserializeXML.y
56 by GNU Bison version 1.28 */
58 #define YYBISON 1 /* Identify Bison output. */
60 #define yyparse OSUnserializeXMLparse
61 #define yylex OSUnserializeXMLlex
62 #define yyerror OSUnserializeXMLerror
63 #define yylval OSUnserializeXMLlval
64 #define yychar OSUnserializeXMLchar
65 #define yydebug OSUnserializeXMLdebug
66 #define yynerrs OSUnserializeXMLnerrs
70 #define DICTIONARY 260
76 #define SYNTAX_ERROR 266
78 #line 55 "OSUnserializeXML.y"
81 #include <libkern/c++/OSMetaClass.h>
82 #include <libkern/c++/OSContainers.h>
83 #include <libkern/c++/OSLib.h>
85 #define YYSTYPE object_t *
86 #define YYPARSE_PARAM state
87 #define YYLEX_PARAM state
89 // this is the internal struct used to hold objects on parser stack
90 // it represents objects both before and after they have been created
91 typedef struct object
{
94 struct object
* elements
;
96 OSString
* key
; // for dictionary
98 void * data
; // for data
99 char * string
; // for string & symbol
100 long long number
; // for number
104 // this code is reentrant, this structure contains all
105 // state information for the parsing of a single buffer
106 typedef struct parser_state
{
107 const char * parseBuffer
; // start of text to be parsed
108 int parseBufferIndex
; // current index into text
109 int lineNumber
; // current line number
110 object_t
* objects
; // internal objects in use
111 object_t
* freeObjects
; // internal objects that are free
112 OSDictionary
* tags
; // used to remember "ID" tags
113 OSString
** errorString
; // parse error with line
114 OSObject
* parsedObject
; // resultant object of parsed text
117 #define STATE ((parser_state_t *)state)
120 #define yyerror(s) OSUnserializeerror(STATE, (s))
121 static int OSUnserializeerror ( parser_state_t
* state
, char * s
);
123 static int yylex ( YYSTYPE
* lvalp
, parser_state_t
* state
);
124 static int yyparse ( void * state
);
126 static object_t
* newObject ( parser_state_t
* state
);
127 static void freeObject ( parser_state_t
* state
, object_t
* o
);
128 static void rememberObject ( parser_state_t
* state
, int tag
, OSObject
* o
);
129 static object_t
* retrieveObject ( parser_state_t
* state
, int tag
);
130 static void cleanupObjects ( parser_state_t
* state
);
132 static object_t
* buildDictionary ( parser_state_t
* state
, object_t
* o
);
133 static object_t
* buildArray ( parser_state_t
* state
, object_t
* o
);
134 static object_t
* buildSet ( parser_state_t
* state
, object_t
* o
);
135 static object_t
* buildString ( parser_state_t
* state
, object_t
* o
);
136 static object_t
* buildData ( parser_state_t
* state
, object_t
* o
);
137 static object_t
* buildNumber ( parser_state_t
* state
, object_t
* o
);
138 static object_t
* buildBoolean ( parser_state_t
* state
, object_t
* o
);
141 extern void * kern_os_malloc ( size_t size
);
142 extern void * kern_os_realloc ( void * addr
, size_t size
);
143 extern void kern_os_free ( void * addr
);
145 //XXX shouldn't have to define these
146 extern long strtol ( const char *, char **, int );
147 extern unsigned long strtoul ( const char *, char **, int );
151 #define malloc(s) kern_os_malloc(s)
152 #define realloc(a, s) kern_os_realloc(a, s)
153 #define free(a) kern_os_free(a)
169 #define YYFLAG -32768
172 #define YYTRANSLATE(x) ((unsigned)(x) <= 266 ? yytranslate[x] : 33)
174 static const char yytranslate
[] = { 0 ,
175 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
176 2 , 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 , 15 ,
179 16 , 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 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
183 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
184 17 , 2 , 18 , 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 2 , 2 , 13 , 2 , 14 , 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 , 2 , 2 , 2 , 2 , 2 ,
199 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
200 2 , 2 , 2 , 2 , 2 , 1 , 3 , 4 , 5 , 6 ,
205 static const short yyprhs
[] = { 0 ,
206 0 , 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 , 17 ,
207 19 , 21 , 24 , 28 , 30 , 32 , 35 , 38 , 40 , 43 ,
208 47 , 49 , 52 , 56 , 58 , 60 , 63 , 65 , 67 , 69 ,
212 static const short yyrhs
[] = { - 1 ,
213 20 , 0 , 12 , 0 , 21 , 0 , 25 , 0 , 26 , 0 ,
214 32 , 0 , 29 , 0 , 31 , 0 , 28 , 0 , 30 , 0 ,
215 13 , 14 , 0 , 13 , 22 , 14 , 0 , 6 , 0 , 23 ,
216 0 , 22 , 23 , 0 , 24 , 20 , 0 , 8 , 0 , 15 ,
217 16 , 0 , 15 , 27 , 16 , 0 , 3 , 0 , 17 , 18 ,
218 0 , 17 , 27 , 18 , 0 , 10 , 0 , 20 , 0 , 27 ,
219 20 , 0 , 4 , 0 , 5 , 0 , 7 , 0 , 9 , 0 ,
226 static const short yyrline
[] = { 0 ,
227 144 , 147 , 152 , 157 , 158 , 159 , 160 , 161 , 162 , 163 ,
228 164 , 177 , 180 , 183 , 186 , 187 , 192 , 201 , 206 , 209 ,
229 212 , 215 , 218 , 221 , 224 , 227 , 234 , 237 , 240 , 243 ,
235 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
237 static const char * const yytname
[] = { "$" , "error" , "$undefined." , "ARRAY" ,
238 "BOOLEAN" , "DATA" , "DICTIONARY" , "IDREF" , "KEY" , "NUMBER" , "SET" , "STRING" , "SYNTAX_ERROR" ,
239 "'{'" , "'}'" , "'('" , "')'" , "'['" , "']'" , "input" , "object" , "dict" , "pairs" , "pair" , "key" ,
240 "array" , "set" , "elements" , "boolean" , "data" , "idref" , "number" , "string" , NULL
244 static const short yyr1
[] = { 0 ,
245 19 , 19 , 19 , 20 , 20 , 20 , 20 , 20 , 20 , 20 ,
246 20 , 21 , 21 , 21 , 22 , 22 , 23 , 24 , 25 , 25 ,
247 25 , 26 , 26 , 26 , 27 , 27 , 28 , 29 , 30 , 31 ,
251 static const short yyr2
[] = { 0 ,
252 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
253 1 , 2 , 3 , 1 , 1 , 2 , 2 , 1 , 2 , 3 ,
254 1 , 2 , 3 , 1 , 1 , 2 , 1 , 1 , 1 , 1 ,
258 static const short yydefact
[] = { 1 ,
259 21 , 27 , 28 , 14 , 29 , 30 , 24 , 31 , 3 , 0 ,
260 0 , 0 , 2 , 4 , 5 , 6 , 10 , 8 , 11 , 9 ,
261 7 , 18 , 12 , 0 , 15 , 0 , 19 , 25 , 0 , 22 ,
262 0 , 13 , 16 , 17 , 20 , 26 , 23 , 0 , 0 , 0
265 static const short yydefgoto
[] = { 38 ,
266 28 , 14 , 24 , 25 , 26 , 15 , 16 , 29 , 17 , 18 ,
270 static const short yypact
[] = { 45 ,
271 - 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 4 ,
272 60 , - 2 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,
273 - 32768 ,- 32768 ,- 32768 , 6 ,- 32768 , 90 ,- 32768 ,- 32768 , 75 ,- 32768 ,
274 29 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 10 , 17 ,- 32768
277 static const short yypgoto
[] = {- 32768 ,
278 0 ,- 32768 ,- 32768 , - 18 ,- 32768 ,- 32768 ,- 32768 , 7 ,- 32768 ,- 32768 ,
286 static const short yytable
[] = { 13 ,
287 1 , 2 , 3 , 4 , 5 , 33 , 6 , 7 , 8 , 39 ,
288 10 , 22 , 11 , 22 , 12 , 30 , 40 , 23 , 31 , 32 ,
289 0 , 0 , 0 , 0 , 0 , 34 , 0 , 0 , 36 , 0 ,
290 36 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 , 8 ,
291 0 , 10 , 0 , 11 , 0 , 12 , 37 , 1 , 2 , 3 ,
292 4 , 5 , 0 , 6 , 7 , 8 , 9 , 10 , 0 , 11 ,
293 0 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
294 8 , 0 , 10 , 0 , 11 , 27 , 12 , 1 , 2 , 3 ,
295 4 , 5 , 0 , 6 , 7 , 8 , 0 , 10 , 0 , 11 ,
296 35 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
297 8 , 0 , 10 , 0 , 11 , 0 , 12
300 static const short yycheck
[] = { 0 ,
301 3 , 4 , 5 , 6 , 7 , 24 , 9 , 10 , 11 , 0 ,
302 13 , 8 , 15 , 8 , 17 , 18 , 0 , 14 , 12 , 14 ,
303 - 1 , - 1 , - 1 , - 1 , - 1 , 26 , - 1 , - 1 , 29 , - 1 ,
304 31 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 , 11 ,
305 - 1 , 13 , - 1 , 15 , - 1 , 17 , 18 , 3 , 4 , 5 ,
306 6 , 7 , - 1 , 9 , 10 , 11 , 12 , 13 , - 1 , 15 ,
307 - 1 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
308 11 , - 1 , 13 , - 1 , 15 , 16 , 17 , 3 , 4 , 5 ,
309 6 , 7 , - 1 , 9 , 10 , 11 , - 1 , 13 , - 1 , 15 ,
310 16 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
311 11 , - 1 , 13 , - 1 , 15 , - 1 , 17
315 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
316 #line 3 "/usr/share/bison.simple"
317 /* This file comes from bison-1.28. */
319 /* Skeleton output parser for bison,
320 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
322 This program is free software; you can redistribute it and/or modify
323 it under the terms of the GNU General Public License as published by
324 the Free Software Foundation; either version 2, or (at your option)
327 This program is distributed in the hope that it will be useful,
328 but WITHOUT ANY WARRANTY; without even the implied warranty of
329 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
330 GNU General Public License for more details.
332 You should have received a copy of the GNU General Public License
333 along with this program; if not, write to the Free Software
334 Foundation, Inc., 59 Temple Place - Suite 330,
335 Boston, MA 02111-1307, USA. */
337 /* As a special exception, when this file is copied by Bison into a
338 Bison output file, you may use that output file without restriction.
339 This special exception was added by the Free Software Foundation
340 in version 1.24 of Bison. */
342 /* This is the parser code that is written into each bison parser
343 when the %semantic_parser declaration is not specified in the grammar.
344 It was written by Richard Stallman by simplifying the hairy parser
345 used when %semantic_parser is specified. */
347 #ifndef YYSTACK_USE_ALLOCA
349 #define YYSTACK_USE_ALLOCA
350 #else /* alloca not defined */
352 #define YYSTACK_USE_ALLOCA
353 #define alloca __builtin_alloca
354 #else /* not GNU C. */
355 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
356 #define YYSTACK_USE_ALLOCA
358 #else /* not sparc */
359 /* We think this test detects Watcom and Microsoft C. */
360 /* This used to test MSDOS, but that is a bad idea
361 since that symbol is in the user namespace. */
362 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
363 #if 0 /* No need for malloc.h, which pollutes the namespace;
364 instead, just don't use alloca. */
367 #else /* not MSDOS, or __TURBOC__ */
369 /* I don't know what this was needed for, but it pollutes the namespace.
370 So I turned it off. rms, 2 May 1997. */
371 /* #include <malloc.h> */
373 #define YYSTACK_USE_ALLOCA
374 #else /* not MSDOS, or __TURBOC__, or _AIX */
376 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
377 and on HPUX 10. Eventually we can turn this on. */
378 #define YYSTACK_USE_ALLOCA
379 #define alloca __builtin_alloca
382 #endif /* not _AIX */
383 #endif /* not MSDOS, or __TURBOC__ */
384 #endif /* not sparc */
385 #endif /* not GNU C */
386 #endif /* alloca not defined */
387 #endif /* YYSTACK_USE_ALLOCA not defined */
389 #ifdef YYSTACK_USE_ALLOCA
390 #define YYSTACK_ALLOC alloca
392 #define YYSTACK_ALLOC malloc
395 /* Note: there must be only one dollar sign in this file.
396 It is replaced by the list of actions, each action
397 as one case of the switch. */
399 #define yyerrok (yyerrstatus = 0)
400 #define yyclearin (yychar = YYEMPTY)
403 #define YYACCEPT goto yyacceptlab
404 #define YYABORT goto yyabortlab
405 #define YYERROR goto yyerrlab1
406 /* Like YYERROR except do call yyerror.
407 This remains here temporarily to ease the
408 transition to the new meaning of YYERROR, for GCC.
409 Once GCC version 2 has supplanted version 1, this can go. */
410 #define YYFAIL goto yyerrlab
411 #define YYRECOVERING() (!!yyerrstatus)
412 #define YYBACKUP(token, value) \
414 if (yychar == YYEMPTY && yylen == 1) \
415 { yychar = (token), yylval = (value); \
416 yychar1 = YYTRANSLATE (yychar); \
421 { yyerror ( "syntax error: cannot back up" ); YYERROR; } \
425 #define YYERRCODE 256
428 #define YYLEX yylex()
434 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
436 #define YYLEX yylex(&yylval, &yylloc)
438 #else /* not YYLSP_NEEDED */
440 #define YYLEX yylex(&yylval, YYLEX_PARAM)
442 #define YYLEX yylex(&yylval)
444 #endif /* not YYLSP_NEEDED */
447 /* If nonreentrant, generate the variables here */
451 int yychar
; /* the lookahead symbol */
452 YYSTYPE yylval
; /* the semantic value of the */
453 /* lookahead symbol */
456 YYLTYPE yylloc
; /* location data for the lookahead */
460 int yynerrs
; /* number of parse errors so far */
461 #endif /* not YYPURE */
464 int yydebug
; /* nonzero means print parse trace */
465 /* Since this is uninitialized, it does not stop multiple parsers
469 /* YYINITDEPTH indicates the initial size of the parser's stacks */
472 #define YYINITDEPTH 200
475 /* YYMAXDEPTH is the maximum size the stacks can grow to
476 (effective only if the built-in stack extension method is used). */
483 #define YYMAXDEPTH 10000
486 /* Define __yy_memcpy. Note that the size argument
487 should be passed with type unsigned int, because that is what the non-GCC
488 definitions require. With GCC, __builtin_memcpy takes an arg
489 of type size_t, but it can handle unsigned int. */
491 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
492 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
493 #else /* not GNU C or C++ */
496 /* This is the most reliable way to avoid incompatibilities
497 in available built-in functions on various systems. */
499 __yy_memcpy ( to
, from
, count
)
504 register char * f
= from
;
505 register char * t
= to
;
506 register int i
= count
;
512 #else /* __cplusplus */
514 /* This is the most reliable way to avoid incompatibilities
515 in available built-in functions on various systems. */
517 __yy_memcpy ( char * to
, char * from
, unsigned int count
)
519 register char * t
= to
;
520 register char * f
= from
;
521 register int i
= count
;
530 #line 217 "/usr/share/bison.simple"
532 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
533 into yyparse. The argument should have type void *.
534 It should actually point to an object.
535 Grammar actions can access the variable by casting it
536 to the proper pointer type. */
540 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
541 #define YYPARSE_PARAM_DECL
542 #else /* not __cplusplus */
543 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
544 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
545 #endif /* not __cplusplus */
546 #else /* not YYPARSE_PARAM */
547 #define YYPARSE_PARAM_ARG
548 #define YYPARSE_PARAM_DECL
549 #endif /* not YYPARSE_PARAM */
551 /* Prevent warning if -Wstrict-prototypes. */
554 int yyparse ( void *);
561 yyparse ( YYPARSE_PARAM_ARG
)
564 register int yystate
;
566 register short * yyssp
;
567 register YYSTYPE
* yyvsp
;
568 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
569 int yychar1
= 0 ; /* lookahead token as an internal (translated) token number */
571 short yyssa
[ YYINITDEPTH
]; /* the state stack */
572 YYSTYPE yyvsa
[ YYINITDEPTH
]; /* the semantic value stack */
574 short * yyss
= yyssa
; /* refer to the stacks thru separate pointers */
575 YYSTYPE
* yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
578 YYLTYPE yylsa
[ YYINITDEPTH
]; /* the location stack */
579 YYLTYPE
* yyls
= yylsa
;
582 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
584 #define YYPOPSTACK (yyvsp--, yyssp--)
587 int yystacksize
= YYINITDEPTH
;
588 int yyfree_stacks
= 0 ;
599 YYSTYPE yyval
; /* the variable used to return */
600 /* semantic values from the action */
607 fprintf ( stderr
, "Starting parse \n " );
613 yychar
= YYEMPTY
; /* Cause a token to be read. */
615 /* Initialize stack pointers.
616 Waste one element of value and location stack
617 so that they stay on the same level as the state stack.
618 The wasted elements are never initialized. */
626 /* Push a new state, which is found in yystate . */
627 /* In all cases, when you get here, the value and location stacks
628 have just been pushed. so pushing a state here evens the stacks. */
633 if ( yyssp
>= yyss
+ yystacksize
- 1 )
635 /* Give user a chance to reallocate the stack */
636 /* Use copies of these so that the &'s don't force the real ones into memory. */
637 YYSTYPE
* yyvs1
= yyvs
;
640 YYLTYPE
* yyls1
= yyls
;
643 /* Get the current used size of the three stacks, in elements. */
644 int size
= yyssp
- yyss
+ 1 ;
647 /* Each stack pointer address is followed by the size of
648 the data in use in that stack, in bytes. */
650 /* This used to be a conditional around just the two extra args,
651 but that might be undefined if yyoverflow is a macro. */
652 yyoverflow ( "parser stack overflow" ,
653 & yyss1
, size
* sizeof (* yyssp
),
654 & yyvs1
, size
* sizeof (* yyvsp
),
655 & yyls1
, size
* sizeof (* yylsp
),
658 yyoverflow ( "parser stack overflow" ,
659 & yyss1
, size
* sizeof (* yyssp
),
660 & yyvs1
, size
* sizeof (* yyvsp
),
664 yyss
= yyss1
; yyvs
= yyvs1
;
668 #else /* no yyoverflow */
669 /* Extend the stack our own way. */
670 if ( yystacksize
>= YYMAXDEPTH
)
672 yyerror ( "parser stack overflow" );
684 if ( yystacksize
> YYMAXDEPTH
)
685 yystacksize
= YYMAXDEPTH
;
686 #ifndef YYSTACK_USE_ALLOCA
689 yyss
= ( short *) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyssp
));
690 __yy_memcpy (( char *) yyss
, ( char *) yyss1
,
691 size
* ( unsigned int ) sizeof (* yyssp
));
692 yyvs
= ( YYSTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyvsp
));
693 __yy_memcpy (( char *) yyvs
, ( char *) yyvs1
,
694 size
* ( unsigned int ) sizeof (* yyvsp
));
696 yyls
= ( YYLTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yylsp
));
697 __yy_memcpy (( char *) yyls
, ( char *) yyls1
,
698 size
* ( unsigned int ) sizeof (* yylsp
));
700 #endif /* no yyoverflow */
702 yyssp
= yyss
+ size
- 1 ;
703 yyvsp
= yyvs
+ size
- 1 ;
705 yylsp
= yyls
+ size
- 1 ;
710 fprintf ( stderr
, "Stack size increased to %d \n " , yystacksize
);
713 if ( yyssp
>= yyss
+ yystacksize
- 1 )
719 fprintf ( stderr
, "Entering state %d \n " , yystate
);
725 /* Do appropriate processing given the current state. */
726 /* Read a lookahead token if we need one and don't already have one. */
729 /* First try to decide what to do without reference to lookahead token. */
731 yyn
= yypact
[ yystate
];
735 /* Not known => get a lookahead token if don't already have one. */
737 /* yychar is either YYEMPTY or YYEOF
738 or a valid token in external form. */
740 if ( yychar
== YYEMPTY
)
744 fprintf ( stderr
, "Reading a token: " );
749 /* Convert token to internal form (in yychar1) for indexing tables with */
751 if ( yychar
<= 0 ) /* This means end of input. */
754 yychar
= YYEOF
; /* Don't call YYLEX any more */
758 fprintf ( stderr
, "Now at end of input. \n " );
763 yychar1
= YYTRANSLATE ( yychar
);
768 fprintf ( stderr
, "Next token is %d ( %s " , yychar
, yytname
[ yychar1
]);
769 /* Give the individual parser a way to print the precise meaning
770 of a token, for further debugging info. */
772 YYPRINT ( stderr
, yychar
, yylval
);
774 fprintf ( stderr
, ") \n " );
780 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != yychar1
)
785 /* yyn is what to do for this token type in this state.
786 Negative => reduce, -yyn is rule number.
787 Positive => shift, yyn is new state.
788 New state is final state => don't bother to shift,
790 0, or most negative number => error. */
805 /* Shift the lookahead token. */
809 fprintf ( stderr
, "Shifting token %d ( %s ), " , yychar
, yytname
[ yychar1
]);
812 /* Discard the token being shifted unless it is eof. */
821 /* count tokens shifted since error; after three, turn off error status. */
822 if ( yyerrstatus
) yyerrstatus
--;
827 /* Do the default action for the current state. */
830 yyn
= yydefact
[ yystate
];
834 /* Do a reduction. yyn is the number of a rule to reduce with. */
838 yyval
= yyvsp
[ 1 - yylen
]; /* implement default value of the action */
845 fprintf ( stderr
, "Reducing via rule %d (line %d ), " ,
848 /* Print the symbols being reduced, and their result. */
849 for ( i
= yyprhs
[ yyn
]; yyrhs
[ i
] > 0 ; i
++)
850 fprintf ( stderr
, " %s " , yytname
[ yyrhs
[ i
]]);
851 fprintf ( stderr
, " -> %s \n " , yytname
[ yyr1
[ yyn
]]);
859 #line 144 "OSUnserializeXML.y"
860 { yyerror ( "unexpected end of buffer" );
865 #line 147 "OSUnserializeXML.y"
866 { STATE
-> parsedObject
= yyvsp
[ 0 ]-> object
;
867 yyvsp
[ 0 ]-> object
= 0 ;
868 freeObject ( STATE
, yyvsp
[ 0 ]);
873 #line 152 "OSUnserializeXML.y"
874 { yyerror ( "syntax error" );
879 #line 157 "OSUnserializeXML.y"
880 { yyval
= buildDictionary ( STATE
, yyvsp
[ 0 ]); ;
883 #line 158 "OSUnserializeXML.y"
884 { yyval
= buildArray ( STATE
, yyvsp
[ 0 ]); ;
887 #line 159 "OSUnserializeXML.y"
888 { yyval
= buildSet ( STATE
, yyvsp
[ 0 ]); ;
891 #line 160 "OSUnserializeXML.y"
892 { yyval
= buildString ( STATE
, yyvsp
[ 0 ]); ;
895 #line 161 "OSUnserializeXML.y"
896 { yyval
= buildData ( STATE
, yyvsp
[ 0 ]); ;
899 #line 162 "OSUnserializeXML.y"
900 { yyval
= buildNumber ( STATE
, yyvsp
[ 0 ]); ;
903 #line 163 "OSUnserializeXML.y"
904 { yyval
= buildBoolean ( STATE
, yyvsp
[ 0 ]); ;
907 #line 164 "OSUnserializeXML.y"
908 { yyval
= retrieveObject ( STATE
, yyvsp
[ 0 ]-> idref
);
910 yyval
-> object
-> retain ();
912 yyerror ( "forward reference detected" );
915 freeObject ( STATE
, yyvsp
[ 0 ]);
919 #line 177 "OSUnserializeXML.y"
921 yyval
-> elements
= NULL
;
925 #line 180 "OSUnserializeXML.y"
927 yyval
-> elements
= yyvsp
[- 1 ];
931 #line 187 "OSUnserializeXML.y"
933 yyval
-> next
= yyvsp
[- 1 ];
937 #line 192 "OSUnserializeXML.y"
939 yyval
-> key
= yyval
-> object
;
940 yyval
-> object
= yyvsp
[ 0 ]-> object
;
942 yyvsp
[ 0 ]-> object
= 0 ;
943 freeObject ( STATE
, yyvsp
[ 0 ]);
947 #line 201 "OSUnserializeXML.y"
948 { yyval
= buildString ( STATE
, yyvsp
[ 0 ]); ;
951 #line 206 "OSUnserializeXML.y"
953 yyval
-> elements
= NULL
;
957 #line 209 "OSUnserializeXML.y"
959 yyval
-> elements
= yyvsp
[- 1 ];
963 #line 215 "OSUnserializeXML.y"
965 yyval
-> elements
= NULL
;
969 #line 218 "OSUnserializeXML.y"
971 yyval
-> elements
= yyvsp
[- 1 ];
975 #line 224 "OSUnserializeXML.y"
981 #line 227 "OSUnserializeXML.y"
983 yyval
-> next
= yyvsp
[- 1 ];
987 /* the action file gets copied in in place of this dollarsign */
988 #line 543 "/usr/share/bison.simple"
999 short * ssp1
= yyss
- 1 ;
1000 fprintf ( stderr
, "state stack now" );
1001 while ( ssp1
!= yyssp
)
1002 fprintf ( stderr
, " %d " , *++ ssp1
);
1003 fprintf ( stderr
, " \n " );
1013 yylsp
-> first_line
= yylloc
. first_line
;
1014 yylsp
-> first_column
= yylloc
. first_column
;
1015 yylsp
-> last_line
= ( yylsp
- 1 )-> last_line
;
1016 yylsp
-> last_column
= ( yylsp
- 1 )-> last_column
;
1021 yylsp
-> last_line
= ( yylsp
+ yylen
- 1 )-> last_line
;
1022 yylsp
-> last_column
= ( yylsp
+ yylen
- 1 )-> last_column
;
1026 /* Now "shift" the result of the reduction.
1027 Determine what state that goes to,
1028 based on the state we popped back to
1029 and the rule number reduced by. */
1033 yystate
= yypgoto
[ yyn
- YYNTBASE
] + * yyssp
;
1034 if ( yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[ yystate
] == * yyssp
)
1035 yystate
= yytable
[ yystate
];
1037 yystate
= yydefgoto
[ yyn
- YYNTBASE
];
1041 yyerrlab
: /* here on detecting error */
1044 /* If not already recovering from an error, report this error. */
1048 #ifdef YYERROR_VERBOSE
1049 yyn
= yypact
[ yystate
];
1051 if ( yyn
> YYFLAG
&& yyn
< YYLAST
)
1058 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1059 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1060 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1061 if ( yycheck
[ x
+ yyn
] == x
)
1062 size
+= strlen ( yytname
[ x
]) + 15 , count
++;
1063 msg
= ( char *) malloc ( size
+ 15 );
1066 strcpy ( msg
, "parse error" );
1071 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1072 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1073 if ( yycheck
[ x
+ yyn
] == x
)
1075 strcat ( msg
, count
== 0 ? ", expecting `" : " or `" );
1076 strcat ( msg
, yytname
[ x
]);
1085 yyerror ( "parse error; also virtual memory exceeded" );
1088 #endif /* YYERROR_VERBOSE */
1089 yyerror ( "parse error" );
1093 yyerrlab1
: /* here on error raised explicitly by an action */
1095 if ( yyerrstatus
== 3 )
1097 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1099 /* return failure if at end of input */
1100 if ( yychar
== YYEOF
)
1105 fprintf ( stderr
, "Discarding token %d ( %s ). \n " , yychar
, yytname
[ yychar1
]);
1111 /* Else will try to reuse lookahead token
1112 after shifting the error token. */
1114 yyerrstatus
= 3 ; /* Each real token shifted decrements this */
1118 yyerrdefault
: /* current state does not do anything special for the error token. */
1121 /* This is wrong; only states that explicitly want error tokens
1122 should shift them. */
1123 yyn
= yydefact
[ yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1124 if ( yyn
) goto yydefault
;
1127 yyerrpop
: /* pop the current state because it cannot handle the error token */
1129 if ( yyssp
== yyss
) YYABORT
;
1139 short * ssp1
= yyss
- 1 ;
1140 fprintf ( stderr
, "Error: state stack now" );
1141 while ( ssp1
!= yyssp
)
1142 fprintf ( stderr
, " %d " , *++ ssp1
);
1143 fprintf ( stderr
, " \n " );
1149 yyn
= yypact
[ yystate
];
1154 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != YYTERROR
)
1173 fprintf ( stderr
, "Shifting error token, " );
1185 /* YYACCEPT comes here. */
1197 /* YYABORT comes here. */
1208 #line 249 "OSUnserializeXML.y"
1212 OSUnserializeerror ( parser_state_t
* state
, char * s
) /* Called by yyparse on errors */
1214 char tempString
[ 128 ];
1216 if ( state
-> errorString
) {
1217 snprintf ( tempString
, 128 , "OSUnserializeXML: %s near line %d \n " , s
, state
-> lineNumber
);
1218 *( state
-> errorString
) = OSString :: withCString ( tempString
);
1224 #define TAG_MAX_LENGTH 32
1225 #define TAG_MAX_ATTRIBUTES 32
1230 #define TAG_COMMENT 4
1232 #define currentChar() (state->parseBuffer[state->parseBufferIndex])
1233 #define nextChar() (state->parseBuffer[++state->parseBufferIndex])
1234 #define prevChar() (state->parseBuffer[state->parseBufferIndex - 1])
1236 #define isSpace(c) ((c) == ' ' || (c) == ' \t ' )
1237 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z' ) || ((c) >= 'a' && (c) <= 'z' ))
1238 #define isDigit(c) ((c) >= '0' && (c) <= '9' )
1239 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f' )
1240 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
1241 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-' ))
1244 getTag ( parser_state_t
* state
,
1245 char tag
[ TAG_MAX_LENGTH
],
1246 int * attributeCount
,
1247 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
],
1248 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
] )
1251 int c
= currentChar ();
1252 int tagType
= TAG_START
;
1254 * attributeCount
= 0 ;
1256 if ( c
!= '<' ) return TAG_BAD
;
1257 c
= nextChar (); // skip '<'
1259 if ( c
== '?' || c
== '!' ) {
1260 while (( c
= nextChar ()) != 0 ) {
1261 if ( c
== ' \n ' ) state
-> lineNumber
++;
1270 c
= nextChar (); // skip '/'
1273 if (! isAlpha ( c
)) return TAG_BAD
;
1275 /* find end of tag while copying it */
1276 while ( isAlphaNumeric ( c
)) {
1279 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1284 // printf("tag %s, type %d\n", tag, tagType);
1286 // look for attributes of the form attribute = "value" ...
1287 while (( c
!= '>' ) && ( c
!= '/' )) {
1288 while ( isSpace ( c
)) c
= nextChar ();
1291 while ( isAlphaNumeric ( c
)) {
1292 attributes
[* attributeCount
][ length
++] = c
;
1293 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1296 attributes
[* attributeCount
][ length
] = 0 ;
1298 while ( isSpace ( c
)) c
= nextChar ();
1300 if ( c
!= '=' ) return TAG_BAD
;
1303 while ( isSpace ( c
)) c
= nextChar ();
1305 if ( c
!= '"' ) return TAG_BAD
;
1309 values
[* attributeCount
][ length
++] = c
;
1310 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1313 values
[* attributeCount
][ length
] = 0 ;
1315 c
= nextChar (); // skip closing quote
1317 // printf(" attribute '%s' = '%s', nextchar = '%c'\n",
1318 // attributes[*attributeCount], values[*attributeCount], c);
1320 (* attributeCount
)++;
1321 if (* attributeCount
>= TAG_MAX_ATTRIBUTES
) return TAG_BAD
;
1325 c
= nextChar (); // skip '/'
1326 tagType
= TAG_EMPTY
;
1328 if ( c
!= '>' ) return TAG_BAD
;
1329 c
= nextChar (); // skip '>'
1335 getString ( parser_state_t
* state
)
1337 int c
= currentChar ();
1338 int start
, length
, i
, j
;
1341 start
= state
-> parseBufferIndex
;
1342 /* find end of string */
1345 if ( c
== ' \n ' ) state
-> lineNumber
++;
1352 if ( c
!= '<' ) return 0 ;
1354 length
= state
-> parseBufferIndex
- start
;
1356 /* copy to null terminated buffer */
1357 tempString
= ( char *) malloc ( length
+ 1 );
1358 if ( tempString
== 0 ) {
1359 printf ( "OSUnserializeXML: can't alloc temp memory \n " );
1363 // copy out string in tempString
1364 // "&" -> '&', "<" -> '<', ">" -> '>'
1367 while ( i
< length
) {
1368 c
= state
-> parseBuffer
[ start
+ i
++];
1370 tempString
[ j
++] = c
;
1372 if (( i
+ 3 ) > length
) goto error
;
1373 c
= state
-> parseBuffer
[ start
+ i
++];
1375 if ( state
-> parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1376 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1377 tempString
[ j
++] = '<' ;
1381 if ( state
-> parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1382 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1383 tempString
[ j
++] = '>' ;
1386 if (( i
+ 3 ) > length
) goto error
;
1388 if ( state
-> parseBuffer
[ start
+ i
++] != 'm' ) goto error
;
1389 if ( state
-> parseBuffer
[ start
+ i
++] != 'p' ) goto error
;
1390 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1391 tempString
[ j
++] = '&' ;
1399 // printf("string %s\n", tempString);
1404 if ( tempString
) free ( tempString
);
1409 getNumber ( parser_state_t
* state
)
1411 unsigned long long n
= 0 ;
1413 int c
= currentChar ();
1415 if (! isDigit ( c
)) return 0 ;
1426 n
= ( n
* base
+ c
- '0' );
1430 while ( isHexDigit ( c
)) {
1432 n
= ( n
* base
+ c
- '0' );
1434 n
= ( n
* base
+ 0xa + c
- 'a' );
1439 // printf("number 0x%x\n", (unsigned long)n);
1443 // taken from CFXMLParsing/CFPropertyList.c
1445 static const signed char __CFPLDataDecodeTable
[ 128 ] = {
1446 /* 000 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1447 /* 010 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1448 /* 020 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1449 /* 030 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1450 /* ' ' */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1451 /* '(' */ - 1 , - 1 , - 1 , 62 , - 1 , - 1 , - 1 , 63 ,
1452 /* '0' */ 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 ,
1453 /* '8' */ 60 , 61 , - 1 , - 1 , - 1 , 0 , - 1 , - 1 ,
1454 /* '@' */ - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 ,
1455 /* 'H' */ 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ,
1456 /* 'P' */ 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 ,
1457 /* 'X' */ 23 , 24 , 25 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1458 /* '`' */ - 1 , 26 , 27 , 28 , 29 , 30 , 31 , 32 ,
1459 /* 'h' */ 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 ,
1460 /* 'p' */ 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 ,
1461 /* 'x' */ 49 , 50 , 51 , - 1 , - 1 , - 1 , - 1 , - 1
1464 #define DATA_ALLOC_SIZE 4096
1467 getCFEncodedData ( parser_state_t
* state
, unsigned int * size
)
1469 int numeq
= 0 , acc
= 0 , cntr
= 0 ;
1470 int tmpbufpos
= 0 , tmpbuflen
= 0 ;
1471 unsigned char * tmpbuf
= ( unsigned char *) malloc ( DATA_ALLOC_SIZE
);
1473 int c
= currentChar ();
1482 if ( c
== '=' ) numeq
++; else numeq
= 0 ;
1483 if ( c
== ' \n ' ) state
-> lineNumber
++;
1484 if ( __CFPLDataDecodeTable
[ c
] < 0 ) {
1490 acc
+= __CFPLDataDecodeTable
[ c
];
1491 if ( 0 == ( cntr
& 0x3 )) {
1492 if ( tmpbuflen
<= tmpbufpos
+ 2 ) {
1493 tmpbuflen
+= DATA_ALLOC_SIZE
;
1494 tmpbuf
= ( unsigned char *) realloc ( tmpbuf
, tmpbuflen
);
1496 tmpbuf
[ tmpbufpos
++] = ( acc
>> 16 ) & 0xff ;
1498 tmpbuf
[ tmpbufpos
++] = ( acc
>> 8 ) & 0xff ;
1500 tmpbuf
[ tmpbufpos
++] = acc
& 0xff ;
1513 getHexData ( parser_state_t
* state
, unsigned int * size
)
1516 unsigned char * d
, * start
, * lastStart
;
1518 start
= lastStart
= d
= ( unsigned char *) malloc ( DATA_ALLOC_SIZE
);
1523 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1525 state
-> lineNumber
++;
1532 * d
= ( c
- '0' ) << 4 ;
1533 } else if ( isAlphaDigit ( c
)) {
1534 * d
= ( 0xa + ( c
- 'a' )) << 4 ;
1543 } else if ( isAlphaDigit ( c
)) {
1544 * d
|= 0xa + ( c
- 'a' );
1550 if (( d
- lastStart
) >= DATA_ALLOC_SIZE
) {
1551 int oldsize
= d
- start
;
1552 start
= ( unsigned char *) realloc ( start
, oldsize
+ DATA_ALLOC_SIZE
);
1553 d
= lastStart
= start
+ oldsize
;
1569 yylex ( YYSTYPE
* lvalp
, parser_state_t
* state
)
1573 char tag
[ TAG_MAX_LENGTH
];
1575 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1576 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1582 /* skip white space */
1583 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1585 /* keep track of line number, don't return \n's */
1587 STATE
-> lineNumber
++;
1592 // end of the buffer?
1595 tagType
= getTag ( STATE
, tag
, & attributeCount
, attributes
, values
);
1596 if ( tagType
== TAG_BAD
) return SYNTAX_ERROR
;
1597 if ( tagType
== TAG_COMMENT
) goto top
;
1599 // handle allocation and check for "ID" and "IDREF" tags up front
1600 * lvalp
= object
= newObject ( STATE
);
1602 for ( i
= 0 ; i
< attributeCount
; i
++) {
1603 if ( attributes
[ i
][ 0 ] == 'I' && attributes
[ i
][ 1 ] == 'D' ) {
1604 // check for idref's, note: we ignore the tag, for
1605 // this to work correctly, all idrefs must be unique
1606 // across the whole serialization
1607 if ( attributes
[ i
][ 2 ] == 'R' && attributes
[ i
][ 3 ] == 'E' &&
1608 attributes
[ i
][ 4 ] == 'F' && ! attributes
[ i
][ 5 ]) {
1609 if ( tagType
!= TAG_EMPTY
) return SYNTAX_ERROR
;
1610 object
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1614 if (! attributes
[ i
][ 2 ]) {
1615 object
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1617 return SYNTAX_ERROR
;
1624 if (! strcmp ( tag
, "array" )) {
1625 if ( tagType
== TAG_EMPTY
) {
1626 object
-> elements
= NULL
;
1629 return ( tagType
== TAG_START
) ? '(' : ')' ;
1633 if (! strcmp ( tag
, "dict" )) {
1634 if ( tagType
== TAG_EMPTY
) {
1635 object
-> elements
= NULL
;
1638 return ( tagType
== TAG_START
) ? '{' : '}' ;
1640 if (! strcmp ( tag
, "data" )) {
1642 if ( tagType
== TAG_EMPTY
) {
1643 object
-> data
= NULL
;
1648 bool isHexFormat
= false ;
1649 for ( int i
= 0 ; i
< attributeCount
; i
++) {
1650 if (! strcmp ( attributes
[ i
], "format" ) && ! strcmp ( values
[ i
], "hex" )) {
1655 // CF encoded is the default form
1657 object
-> data
= getHexData ( STATE
, & size
);
1659 object
-> data
= getCFEncodedData ( STATE
, & size
);
1661 object
-> size
= size
;
1662 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "data" )) {
1663 return SYNTAX_ERROR
;
1669 if (! strcmp ( tag
, "false" )) {
1670 if ( tagType
== TAG_EMPTY
) {
1677 if (! strcmp ( tag
, "integer" )) {
1678 object
-> size
= 64 ; // default
1679 for ( i
= 0 ; i
< attributeCount
; i
++) {
1680 if (! strcmp ( attributes
[ i
], "size" )) {
1681 object
-> size
= strtoul ( values
[ i
], NULL
, 0 );
1684 if ( tagType
== TAG_EMPTY
) {
1688 object
-> number
= getNumber ( STATE
);
1689 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "integer" )) {
1690 return SYNTAX_ERROR
;
1696 if (! strcmp ( tag
, "key" )) {
1697 if ( tagType
== TAG_EMPTY
) return SYNTAX_ERROR
;
1698 object
-> string
= getString ( STATE
);
1699 if (! object
-> string
) {
1700 return SYNTAX_ERROR
;
1702 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1703 || strcmp ( tag
, "key" )) {
1704 return SYNTAX_ERROR
;
1710 if (! strcmp ( tag
, "plist" )) {
1711 freeObject ( STATE
, object
);
1716 if (! strcmp ( tag
, "string" )) {
1717 if ( tagType
== TAG_EMPTY
) {
1718 object
-> string
= ( char *) malloc ( 1 );
1719 object
-> string
[ 0 ] = 0 ;
1722 object
-> string
= getString ( STATE
);
1723 if (! object
-> string
) {
1724 return SYNTAX_ERROR
;
1726 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1727 || strcmp ( tag
, "string" )) {
1728 return SYNTAX_ERROR
;
1732 if (! strcmp ( tag
, "set" )) {
1733 if ( tagType
== TAG_EMPTY
) {
1734 object
-> elements
= NULL
;
1737 if ( tagType
== TAG_START
) {
1745 if (! strcmp ( tag
, "true" )) {
1746 if ( tagType
== TAG_EMPTY
) {
1754 return SYNTAX_ERROR
;
1757 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1758 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1759 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1761 // "java" like allocation, if this code hits a syntax error in the
1762 // the middle of the parsed string we just bail with pointers hanging
1763 // all over place, this code helps keeps it all together
1765 //static int object_count = 0;
1768 newObject ( parser_state_t
* state
)
1772 if ( state
-> freeObjects
) {
1773 o
= state
-> freeObjects
;
1774 state
-> freeObjects
= state
-> freeObjects
-> next
;
1776 o
= ( object_t
*) malloc ( sizeof ( object_t
));
1778 bzero ( o
, sizeof ( object_t
));
1779 o
-> free
= state
-> objects
;
1787 freeObject ( parser_state_t
* state
, object_t
* o
)
1789 o
-> next
= state
-> freeObjects
;
1790 state
-> freeObjects
= o
;
1794 cleanupObjects ( parser_state_t
* state
)
1796 object_t
* t
, * o
= state
-> objects
;
1800 // printf("OSUnserializeXML: releasing object o=%x object=%x\n", (int)o, (int)o->object);
1801 o
-> object
-> release ();
1804 // printf("OSUnserializeXML: freeing object o=%x data=%x\n", (int)o, (int)o->data);
1808 // printf("OSUnserializeXML: releasing object o=%x key=%x\n", (int)o, (int)o->key);
1812 // printf("OSUnserializeXML: freeing object o=%x string=%x\n", (int)o, (int)o->string);
1821 // printf("object_count = %d\n", object_count);
1824 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1825 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1826 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1829 rememberObject ( parser_state_t
* state
, int tag
, OSObject
* o
)
1832 snprintf ( key
, 16 , " %u " , tag
);
1834 // printf("remember key %s\n", key);
1836 state
-> tags
-> setObject ( key
, o
);
1840 retrieveObject ( parser_state_t
* state
, int tag
)
1845 snprintf ( key
, 16 , " %u " , tag
);
1847 // printf("retrieve key '%s'\n", key);
1849 ref
= state
-> tags
-> getObject ( key
);
1852 o
= newObject ( state
);
1857 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1858 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1859 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1862 buildDictionary ( parser_state_t
* state
, object_t
* header
)
1868 // get count and reverse order
1869 o
= header
-> elements
;
1870 header
-> elements
= 0 ;
1876 t
-> next
= header
-> elements
;
1877 header
-> elements
= t
;
1880 dict
= OSDictionary :: withCapacity ( count
);
1881 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, dict
);
1883 o
= header
-> elements
;
1885 dict
-> setObject ( o
-> key
, o
-> object
);
1888 o
-> object
-> release ();
1894 freeObject ( state
, t
);
1902 buildArray ( parser_state_t
* state
, object_t
* header
)
1908 // get count and reverse order
1909 o
= header
-> elements
;
1910 header
-> elements
= 0 ;
1916 t
-> next
= header
-> elements
;
1917 header
-> elements
= t
;
1920 array
= OSArray :: withCapacity ( count
);
1921 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, array
);
1923 o
= header
-> elements
;
1925 array
-> setObject ( o
-> object
);
1927 o
-> object
-> release ();
1932 freeObject ( state
, t
);
1940 buildSet ( parser_state_t
* state
, object_t
* header
)
1942 object_t
* o
= buildArray ( state
, header
);
1944 OSArray
* array
= ( OSArray
*) o
-> object
;
1945 OSSet
* set
= OSSet :: withArray ( array
, array
-> getCapacity ());
1947 // write over the reference created in buildArray
1948 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, set
);
1956 buildString ( parser_state_t
* state
, object_t
* o
)
1960 string
= OSString :: withCString ( o
-> string
);
1961 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, string
);
1971 buildData ( parser_state_t
* state
, object_t
* o
)
1976 data
= OSData :: withBytes ( o
-> data
, o
-> size
);
1978 data
= OSData :: withCapacity ( 0 );
1980 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, data
);
1982 if ( o
-> size
) free ( o
-> data
);
1989 buildNumber ( parser_state_t
* state
, object_t
* o
)
1991 OSNumber
* number
= OSNumber :: withNumber ( o
-> number
, o
-> size
);
1993 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, number
);
2000 buildBoolean ( parser_state_t
* state
, object_t
* o
)
2002 o
-> object
= (( o
-> number
== 0 ) ? kOSBooleanFalse
: kOSBooleanTrue
);
2003 o
-> object
-> retain ();
2008 OSUnserializeXML ( const char * buffer
, OSString
** errorString
)
2011 parser_state_t
* state
= ( parser_state_t
*) malloc ( sizeof ( parser_state_t
));
2013 if ((! state
) || (! buffer
)) return 0 ;
2016 if ( errorString
) * errorString
= NULL
;
2018 state
-> parseBuffer
= buffer
;
2019 state
-> parseBufferIndex
= 0 ;
2020 state
-> lineNumber
= 1 ;
2022 state
-> freeObjects
= 0 ;
2023 state
-> tags
= OSDictionary :: withCapacity ( 128 );
2024 state
-> errorString
= errorString
;
2025 state
-> parsedObject
= 0 ;
2027 ( void ) yyparse (( void *) state
);
2029 object
= state
-> parsedObject
;
2031 cleanupObjects ( state
);
2032 state
-> tags
-> release ();
2044 // DO NOT EDIT OSUnserializeXML.cpp!