]>
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_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * OSUnserializeXML.y created by rsulack on Tue Oct 12 1999
37 // parser for unserializing OSContainer objects serialized to XML
40 // bison -p OSUnserializeXML OSUnserializeXML.y
41 // head -50 OSUnserializeXML.y > OSUnserializeXML.cpp
42 // sed -e "s/#include <stdio.h>//" < OSUnserializeXML.tab.c >> OSUnserializeXML.cpp
44 // when changing code check in both OSUnserializeXML.y and OSUnserializeXML.cpp
50 // DO NOT EDIT OSUnserializeXML.cpp!
60 /* A Bison parser, made from OSUnserializeXML.y
61 by GNU Bison version 1.28 */
63 #define YYBISON 1 /* Identify Bison output. */
65 #define yyparse OSUnserializeXMLparse
66 #define yylex OSUnserializeXMLlex
67 #define yyerror OSUnserializeXMLerror
68 #define yylval OSUnserializeXMLlval
69 #define yychar OSUnserializeXMLchar
70 #define yydebug OSUnserializeXMLdebug
71 #define yynerrs OSUnserializeXMLnerrs
75 #define DICTIONARY 260
81 #define SYNTAX_ERROR 266
83 #line 55 "OSUnserializeXML.y"
86 #include <libkern/c++/OSMetaClass.h>
87 #include <libkern/c++/OSContainers.h>
88 #include <libkern/c++/OSLib.h>
90 #define YYSTYPE object_t *
91 #define YYPARSE_PARAM state
92 #define YYLEX_PARAM (parser_state_t *)state
94 // this is the internal struct used to hold objects on parser stack
95 // it represents objects both before and after they have been created
96 typedef struct object
{
99 struct object
* elements
;
101 OSString
* key
; // for dictionary
103 void * data
; // for data
104 char * string
; // for string & symbol
105 long long number
; // for number
109 // this code is reentrant, this structure contains all
110 // state information for the parsing of a single buffer
111 typedef struct parser_state
{
112 const char * parseBuffer
; // start of text to be parsed
113 int parseBufferIndex
; // current index into text
114 int lineNumber
; // current line number
115 object_t
* objects
; // internal objects in use
116 object_t
* freeObjects
; // internal objects that are free
117 OSDictionary
* tags
; // used to remember "ID" tags
118 OSString
** errorString
; // parse error with line
119 OSObject
* parsedObject
; // resultant object of parsed text
122 #define STATE ((parser_state_t *)state)
125 #define yyerror(s) OSUnserializeerror(STATE, (s))
126 static int OSUnserializeerror ( parser_state_t
* state
, char * s
);
128 static int yylex ( YYSTYPE
* lvalp
, parser_state_t
* state
);
129 static int yyparse ( void * state
);
131 static object_t
* newObject ( parser_state_t
* state
);
132 static void freeObject ( parser_state_t
* state
, object_t
* o
);
133 static void rememberObject ( parser_state_t
* state
, int tag
, OSObject
* o
);
134 static object_t
* retrieveObject ( parser_state_t
* state
, int tag
);
135 static void cleanupObjects ( parser_state_t
* state
);
137 static object_t
* buildDictionary ( parser_state_t
* state
, object_t
* o
);
138 static object_t
* buildArray ( parser_state_t
* state
, object_t
* o
);
139 static object_t
* buildSet ( parser_state_t
* state
, object_t
* o
);
140 static object_t
* buildString ( parser_state_t
* state
, object_t
* o
);
141 static object_t
* buildData ( parser_state_t
* state
, object_t
* o
);
142 static object_t
* buildNumber ( parser_state_t
* state
, object_t
* o
);
143 static object_t
* buildBoolean ( parser_state_t
* state
, object_t
* o
);
146 extern void * kern_os_malloc ( size_t size
);
147 extern void * kern_os_realloc ( void * addr
, size_t size
);
148 extern void kern_os_free ( void * addr
);
150 //XXX shouldn't have to define these
151 extern long strtol ( const char *, char **, int );
152 extern unsigned long strtoul ( const char *, char **, int );
156 #define malloc(s) kern_os_malloc(s)
157 #define realloc(a, s) kern_os_realloc(a, s)
158 #define free(a) kern_os_free((void *)a)
174 #define YYFLAG -32768
177 #define YYTRANSLATE(x) ((unsigned)(x) <= 266 ? yytranslate[x] : 33)
179 static const char yytranslate
[] = { 0 ,
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 , 15 ,
184 16 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
185 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
186 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
187 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
188 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
189 17 , 2 , 18 , 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 , 13 , 2 , 14 , 2 , 2 , 2 , 2 , 2 ,
193 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
194 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
195 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
196 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
197 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
198 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
199 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
200 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
201 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
202 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
203 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
204 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
205 2 , 2 , 2 , 2 , 2 , 1 , 3 , 4 , 5 , 6 ,
210 static const short yyprhs
[] = { 0 ,
211 0 , 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 , 17 ,
212 19 , 21 , 24 , 28 , 30 , 32 , 35 , 38 , 40 , 43 ,
213 47 , 49 , 52 , 56 , 58 , 60 , 63 , 65 , 67 , 69 ,
217 static const short yyrhs
[] = { - 1 ,
218 20 , 0 , 12 , 0 , 21 , 0 , 25 , 0 , 26 , 0 ,
219 32 , 0 , 29 , 0 , 31 , 0 , 28 , 0 , 30 , 0 ,
220 13 , 14 , 0 , 13 , 22 , 14 , 0 , 6 , 0 , 23 ,
221 0 , 22 , 23 , 0 , 24 , 20 , 0 , 8 , 0 , 15 ,
222 16 , 0 , 15 , 27 , 16 , 0 , 3 , 0 , 17 , 18 ,
223 0 , 17 , 27 , 18 , 0 , 10 , 0 , 20 , 0 , 27 ,
224 20 , 0 , 4 , 0 , 5 , 0 , 7 , 0 , 9 , 0 ,
231 static const short yyrline
[] = { 0 ,
232 144 , 147 , 152 , 157 , 158 , 159 , 160 , 161 , 162 , 163 ,
233 164 , 177 , 180 , 183 , 186 , 187 , 192 , 201 , 206 , 209 ,
234 212 , 215 , 218 , 221 , 224 , 227 , 234 , 237 , 240 , 243 ,
240 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
242 static const char * const yytname
[] = { "$" , "error" , "$undefined." , "ARRAY" ,
243 "BOOLEAN" , "DATA" , "DICTIONARY" , "IDREF" , "KEY" , "NUMBER" , "SET" , "STRING" , "SYNTAX_ERROR" ,
244 "'{'" , "'}'" , "'('" , "')'" , "'['" , "']'" , "input" , "object" , "dict" , "pairs" , "pair" , "key" ,
245 "array" , "set" , "elements" , "boolean" , "data" , "idref" , "number" , "string" , NULL
249 static const short yyr1
[] = { 0 ,
250 19 , 19 , 19 , 20 , 20 , 20 , 20 , 20 , 20 , 20 ,
251 20 , 21 , 21 , 21 , 22 , 22 , 23 , 24 , 25 , 25 ,
252 25 , 26 , 26 , 26 , 27 , 27 , 28 , 29 , 30 , 31 ,
256 static const short yyr2
[] = { 0 ,
257 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
258 1 , 2 , 3 , 1 , 1 , 2 , 2 , 1 , 2 , 3 ,
259 1 , 2 , 3 , 1 , 1 , 2 , 1 , 1 , 1 , 1 ,
263 static const short yydefact
[] = { 1 ,
264 21 , 27 , 28 , 14 , 29 , 30 , 24 , 31 , 3 , 0 ,
265 0 , 0 , 2 , 4 , 5 , 6 , 10 , 8 , 11 , 9 ,
266 7 , 18 , 12 , 0 , 15 , 0 , 19 , 25 , 0 , 22 ,
267 0 , 13 , 16 , 17 , 20 , 26 , 23 , 0 , 0 , 0
270 static const short yydefgoto
[] = { 38 ,
271 28 , 14 , 24 , 25 , 26 , 15 , 16 , 29 , 17 , 18 ,
275 static const short yypact
[] = { 45 ,
276 - 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 4 ,
277 60 , - 2 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,
278 - 32768 ,- 32768 ,- 32768 , 6 ,- 32768 , 90 ,- 32768 ,- 32768 , 75 ,- 32768 ,
279 29 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 10 , 17 ,- 32768
282 static const short yypgoto
[] = {- 32768 ,
283 0 ,- 32768 ,- 32768 , - 18 ,- 32768 ,- 32768 ,- 32768 , 7 ,- 32768 ,- 32768 ,
291 static const short yytable
[] = { 13 ,
292 1 , 2 , 3 , 4 , 5 , 33 , 6 , 7 , 8 , 39 ,
293 10 , 22 , 11 , 22 , 12 , 30 , 40 , 23 , 31 , 32 ,
294 0 , 0 , 0 , 0 , 0 , 34 , 0 , 0 , 36 , 0 ,
295 36 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 , 8 ,
296 0 , 10 , 0 , 11 , 0 , 12 , 37 , 1 , 2 , 3 ,
297 4 , 5 , 0 , 6 , 7 , 8 , 9 , 10 , 0 , 11 ,
298 0 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
299 8 , 0 , 10 , 0 , 11 , 27 , 12 , 1 , 2 , 3 ,
300 4 , 5 , 0 , 6 , 7 , 8 , 0 , 10 , 0 , 11 ,
301 35 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
302 8 , 0 , 10 , 0 , 11 , 0 , 12
305 static const short yycheck
[] = { 0 ,
306 3 , 4 , 5 , 6 , 7 , 24 , 9 , 10 , 11 , 0 ,
307 13 , 8 , 15 , 8 , 17 , 18 , 0 , 14 , 12 , 14 ,
308 - 1 , - 1 , - 1 , - 1 , - 1 , 26 , - 1 , - 1 , 29 , - 1 ,
309 31 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 , 11 ,
310 - 1 , 13 , - 1 , 15 , - 1 , 17 , 18 , 3 , 4 , 5 ,
311 6 , 7 , - 1 , 9 , 10 , 11 , 12 , 13 , - 1 , 15 ,
312 - 1 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
313 11 , - 1 , 13 , - 1 , 15 , 16 , 17 , 3 , 4 , 5 ,
314 6 , 7 , - 1 , 9 , 10 , 11 , - 1 , 13 , - 1 , 15 ,
315 16 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
316 11 , - 1 , 13 , - 1 , 15 , - 1 , 17
320 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
321 #line 3 "/usr/share/bison.simple"
322 /* This file comes from bison-1.28. */
324 /* Skeleton output parser for bison,
325 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
327 This program is free software; you can redistribute it and/or modify
328 it under the terms of the GNU General Public License as published by
329 the Free Software Foundation; either version 2, or (at your option)
332 This program is distributed in the hope that it will be useful,
333 but WITHOUT ANY WARRANTY; without even the implied warranty of
334 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
335 GNU General Public License for more details.
337 You should have received a copy of the GNU General Public License
338 along with this program; if not, write to the Free Software
339 Foundation, Inc., 59 Temple Place - Suite 330,
340 Boston, MA 02111-1307, USA. */
342 /* As a special exception, when this file is copied by Bison into a
343 Bison output file, you may use that output file without restriction.
344 This special exception was added by the Free Software Foundation
345 in version 1.24 of Bison. */
347 /* This is the parser code that is written into each bison parser
348 when the %semantic_parser declaration is not specified in the grammar.
349 It was written by Richard Stallman by simplifying the hairy parser
350 used when %semantic_parser is specified. */
352 #ifndef YYSTACK_USE_ALLOCA
354 #define YYSTACK_USE_ALLOCA
355 #else /* alloca not defined */
357 #define YYSTACK_USE_ALLOCA
358 #define alloca __builtin_alloca
359 #else /* not GNU C. */
360 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
361 #define YYSTACK_USE_ALLOCA
363 #else /* not sparc */
364 /* We think this test detects Watcom and Microsoft C. */
365 /* This used to test MSDOS, but that is a bad idea
366 since that symbol is in the user namespace. */
367 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
368 #if 0 /* No need for malloc.h, which pollutes the namespace;
369 instead, just don't use alloca. */
372 #else /* not MSDOS, or __TURBOC__ */
374 /* I don't know what this was needed for, but it pollutes the namespace.
375 So I turned it off. rms, 2 May 1997. */
376 /* #include <malloc.h> */
378 #define YYSTACK_USE_ALLOCA
379 #else /* not MSDOS, or __TURBOC__, or _AIX */
381 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
382 and on HPUX 10. Eventually we can turn this on. */
383 #define YYSTACK_USE_ALLOCA
384 #define alloca __builtin_alloca
387 #endif /* not _AIX */
388 #endif /* not MSDOS, or __TURBOC__ */
389 #endif /* not sparc */
390 #endif /* not GNU C */
391 #endif /* alloca not defined */
392 #endif /* YYSTACK_USE_ALLOCA not defined */
394 #ifdef YYSTACK_USE_ALLOCA
395 #define YYSTACK_ALLOC alloca
397 #define YYSTACK_ALLOC malloc
400 /* Note: there must be only one dollar sign in this file.
401 It is replaced by the list of actions, each action
402 as one case of the switch. */
404 #define yyerrok (yyerrstatus = 0)
405 #define yyclearin (yychar = YYEMPTY)
408 #define YYACCEPT goto yyacceptlab
409 #define YYABORT goto yyabortlab
410 #define YYERROR goto yyerrlab1
411 /* Like YYERROR except do call yyerror.
412 This remains here temporarily to ease the
413 transition to the new meaning of YYERROR, for GCC.
414 Once GCC version 2 has supplanted version 1, this can go. */
415 #define YYFAIL goto yyerrlab
416 #define YYRECOVERING() (!!yyerrstatus)
417 #define YYBACKUP(token, value) \
419 if (yychar == YYEMPTY && yylen == 1) \
420 { yychar = (token), yylval = (value); \
421 yychar1 = YYTRANSLATE (yychar); \
426 { yyerror ( "syntax error: cannot back up" ); YYERROR; } \
430 #define YYERRCODE 256
433 #define YYLEX yylex()
439 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
441 #define YYLEX yylex(&yylval, &yylloc)
443 #else /* not YYLSP_NEEDED */
445 #define YYLEX yylex(&yylval, YYLEX_PARAM)
447 #define YYLEX yylex(&yylval)
449 #endif /* not YYLSP_NEEDED */
452 /* If nonreentrant, generate the variables here */
456 int yychar
; /* the lookahead symbol */
457 YYSTYPE yylval
; /* the semantic value of the */
458 /* lookahead symbol */
461 YYLTYPE yylloc
; /* location data for the lookahead */
465 int yynerrs
; /* number of parse errors so far */
466 #endif /* not YYPURE */
469 int yydebug
; /* nonzero means print parse trace */
470 /* Since this is uninitialized, it does not stop multiple parsers
474 /* YYINITDEPTH indicates the initial size of the parser's stacks */
477 #define YYINITDEPTH 200
480 /* YYMAXDEPTH is the maximum size the stacks can grow to
481 (effective only if the built-in stack extension method is used). */
488 #define YYMAXDEPTH 10000
491 /* Define __yy_memcpy. Note that the size argument
492 should be passed with type unsigned int, because that is what the non-GCC
493 definitions require. With GCC, __builtin_memcpy takes an arg
494 of type size_t, but it can handle unsigned int. */
496 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
497 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
498 #else /* not GNU C or C++ */
501 /* This is the most reliable way to avoid incompatibilities
502 in available built-in functions on various systems. */
504 __yy_memcpy ( to
, from
, count
)
509 register char * f
= from
;
510 register char * t
= to
;
511 register int i
= count
;
517 #else /* __cplusplus */
519 /* This is the most reliable way to avoid incompatibilities
520 in available built-in functions on various systems. */
522 __yy_memcpy ( char * to
, char * from
, unsigned int count
)
524 register char * t
= to
;
525 register char * f
= from
;
526 register int i
= count
;
535 #line 217 "/usr/share/bison.simple"
537 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
538 into yyparse. The argument should have type void *.
539 It should actually point to an object.
540 Grammar actions can access the variable by casting it
541 to the proper pointer type. */
545 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
546 #define YYPARSE_PARAM_DECL
547 #else /* not __cplusplus */
548 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
549 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
550 #endif /* not __cplusplus */
551 #else /* not YYPARSE_PARAM */
552 #define YYPARSE_PARAM_ARG
553 #define YYPARSE_PARAM_DECL
554 #endif /* not YYPARSE_PARAM */
556 /* Prevent warning if -Wstrict-prototypes. */
559 int yyparse ( void *);
566 yyparse ( YYPARSE_PARAM_ARG
)
569 register int yystate
;
571 register short * yyssp
;
572 register YYSTYPE
* yyvsp
;
573 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
574 int yychar1
= 0 ; /* lookahead token as an internal (translated) token number */
576 short yyssa
[ YYINITDEPTH
]; /* the state stack */
577 YYSTYPE yyvsa
[ YYINITDEPTH
]; /* the semantic value stack */
579 short * yyss
= yyssa
; /* refer to the stacks thru separate pointers */
580 YYSTYPE
* yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
583 YYLTYPE yylsa
[ YYINITDEPTH
]; /* the location stack */
584 YYLTYPE
* yyls
= yylsa
;
587 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
589 #define YYPOPSTACK (yyvsp--, yyssp--)
592 int yystacksize
= YYINITDEPTH
;
593 int yyfree_stacks
= 0 ;
604 YYSTYPE yyval
; /* the variable used to return */
605 /* semantic values from the action */
612 fprintf ( stderr
, "Starting parse \n " );
618 yychar
= YYEMPTY
; /* Cause a token to be read. */
620 /* Initialize stack pointers.
621 Waste one element of value and location stack
622 so that they stay on the same level as the state stack.
623 The wasted elements are never initialized. */
631 /* Push a new state, which is found in yystate . */
632 /* In all cases, when you get here, the value and location stacks
633 have just been pushed. so pushing a state here evens the stacks. */
638 if ( yyssp
>= yyss
+ yystacksize
- 1 )
640 /* Give user a chance to reallocate the stack */
641 /* Use copies of these so that the &'s don't force the real ones into memory. */
642 YYSTYPE
* yyvs1
= yyvs
;
645 YYLTYPE
* yyls1
= yyls
;
648 /* Get the current used size of the three stacks, in elements. */
649 int size
= yyssp
- yyss
+ 1 ;
652 /* Each stack pointer address is followed by the size of
653 the data in use in that stack, in bytes. */
655 /* This used to be a conditional around just the two extra args,
656 but that might be undefined if yyoverflow is a macro. */
657 yyoverflow ( "parser stack overflow" ,
658 & yyss1
, size
* sizeof (* yyssp
),
659 & yyvs1
, size
* sizeof (* yyvsp
),
660 & yyls1
, size
* sizeof (* yylsp
),
663 yyoverflow ( "parser stack overflow" ,
664 & yyss1
, size
* sizeof (* yyssp
),
665 & yyvs1
, size
* sizeof (* yyvsp
),
669 yyss
= yyss1
; yyvs
= yyvs1
;
673 #else /* no yyoverflow */
674 /* Extend the stack our own way. */
675 if ( yystacksize
>= YYMAXDEPTH
)
677 yyerror ( "parser stack overflow" );
689 if ( yystacksize
> YYMAXDEPTH
)
690 yystacksize
= YYMAXDEPTH
;
691 #ifndef YYSTACK_USE_ALLOCA
694 yyss
= ( short *) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyssp
));
695 __yy_memcpy (( char *) yyss
, ( char *) yyss1
,
696 size
* ( unsigned int ) sizeof (* yyssp
));
697 yyvs
= ( YYSTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyvsp
));
698 __yy_memcpy (( char *) yyvs
, ( char *) yyvs1
,
699 size
* ( unsigned int ) sizeof (* yyvsp
));
701 yyls
= ( YYLTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yylsp
));
702 __yy_memcpy (( char *) yyls
, ( char *) yyls1
,
703 size
* ( unsigned int ) sizeof (* yylsp
));
705 #endif /* no yyoverflow */
707 yyssp
= yyss
+ size
- 1 ;
708 yyvsp
= yyvs
+ size
- 1 ;
710 yylsp
= yyls
+ size
- 1 ;
715 fprintf ( stderr
, "Stack size increased to %d \n " , yystacksize
);
718 if ( yyssp
>= yyss
+ yystacksize
- 1 )
724 fprintf ( stderr
, "Entering state %d \n " , yystate
);
730 /* Do appropriate processing given the current state. */
731 /* Read a lookahead token if we need one and don't already have one. */
734 /* First try to decide what to do without reference to lookahead token. */
736 yyn
= yypact
[ yystate
];
740 /* Not known => get a lookahead token if don't already have one. */
742 /* yychar is either YYEMPTY or YYEOF
743 or a valid token in external form. */
745 if ( yychar
== YYEMPTY
)
749 fprintf ( stderr
, "Reading a token: " );
754 /* Convert token to internal form (in yychar1) for indexing tables with */
756 if ( yychar
<= 0 ) /* This means end of input. */
759 yychar
= YYEOF
; /* Don't call YYLEX any more */
763 fprintf ( stderr
, "Now at end of input. \n " );
768 yychar1
= YYTRANSLATE ( yychar
);
773 fprintf ( stderr
, "Next token is %d ( %s " , yychar
, yytname
[ yychar1
]);
774 /* Give the individual parser a way to print the precise meaning
775 of a token, for further debugging info. */
777 YYPRINT ( stderr
, yychar
, yylval
);
779 fprintf ( stderr
, ") \n " );
785 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != yychar1
)
790 /* yyn is what to do for this token type in this state.
791 Negative => reduce, -yyn is rule number.
792 Positive => shift, yyn is new state.
793 New state is final state => don't bother to shift,
795 0, or most negative number => error. */
810 /* Shift the lookahead token. */
814 fprintf ( stderr
, "Shifting token %d ( %s ), " , yychar
, yytname
[ yychar1
]);
817 /* Discard the token being shifted unless it is eof. */
826 /* count tokens shifted since error; after three, turn off error status. */
827 if ( yyerrstatus
) yyerrstatus
--;
832 /* Do the default action for the current state. */
835 yyn
= yydefact
[ yystate
];
839 /* Do a reduction. yyn is the number of a rule to reduce with. */
843 yyval
= yyvsp
[ 1 - yylen
]; /* implement default value of the action */
850 fprintf ( stderr
, "Reducing via rule %d (line %d ), " ,
853 /* Print the symbols being reduced, and their result. */
854 for ( i
= yyprhs
[ yyn
]; yyrhs
[ i
] > 0 ; i
++)
855 fprintf ( stderr
, " %s " , yytname
[ yyrhs
[ i
]]);
856 fprintf ( stderr
, " -> %s \n " , yytname
[ yyr1
[ yyn
]]);
864 #line 144 "OSUnserializeXML.y"
865 { yyerror ( "unexpected end of buffer" );
870 #line 147 "OSUnserializeXML.y"
871 { STATE
-> parsedObject
= yyvsp
[ 0 ]-> object
;
872 yyvsp
[ 0 ]-> object
= 0 ;
873 freeObject ( STATE
, yyvsp
[ 0 ]);
878 #line 152 "OSUnserializeXML.y"
879 { yyerror ( "syntax error" );
884 #line 157 "OSUnserializeXML.y"
885 { yyval
= buildDictionary ( STATE
, yyvsp
[ 0 ]); ;
888 #line 158 "OSUnserializeXML.y"
889 { yyval
= buildArray ( STATE
, yyvsp
[ 0 ]); ;
892 #line 159 "OSUnserializeXML.y"
893 { yyval
= buildSet ( STATE
, yyvsp
[ 0 ]); ;
896 #line 160 "OSUnserializeXML.y"
897 { yyval
= buildString ( STATE
, yyvsp
[ 0 ]); ;
900 #line 161 "OSUnserializeXML.y"
901 { yyval
= buildData ( STATE
, yyvsp
[ 0 ]); ;
904 #line 162 "OSUnserializeXML.y"
905 { yyval
= buildNumber ( STATE
, yyvsp
[ 0 ]); ;
908 #line 163 "OSUnserializeXML.y"
909 { yyval
= buildBoolean ( STATE
, yyvsp
[ 0 ]); ;
912 #line 164 "OSUnserializeXML.y"
913 { yyval
= retrieveObject ( STATE
, yyvsp
[ 0 ]-> idref
);
915 yyval
-> object
-> retain ();
917 yyerror ( "forward reference detected" );
920 freeObject ( STATE
, yyvsp
[ 0 ]);
924 #line 177 "OSUnserializeXML.y"
926 yyval
-> elements
= NULL
;
930 #line 180 "OSUnserializeXML.y"
932 yyval
-> elements
= yyvsp
[- 1 ];
936 #line 187 "OSUnserializeXML.y"
938 yyval
-> next
= yyvsp
[- 1 ];
942 #line 192 "OSUnserializeXML.y"
944 yyval
-> key
= ( OSString
*) yyval
-> object
;
945 yyval
-> object
= yyvsp
[ 0 ]-> object
;
947 yyvsp
[ 0 ]-> object
= 0 ;
948 freeObject ( STATE
, yyvsp
[ 0 ]);
952 #line 201 "OSUnserializeXML.y"
953 { yyval
= buildString ( STATE
, yyvsp
[ 0 ]); ;
956 #line 206 "OSUnserializeXML.y"
958 yyval
-> elements
= NULL
;
962 #line 209 "OSUnserializeXML.y"
964 yyval
-> elements
= yyvsp
[- 1 ];
968 #line 215 "OSUnserializeXML.y"
970 yyval
-> elements
= NULL
;
974 #line 218 "OSUnserializeXML.y"
976 yyval
-> elements
= yyvsp
[- 1 ];
980 #line 224 "OSUnserializeXML.y"
986 #line 227 "OSUnserializeXML.y"
988 yyval
-> next
= yyvsp
[- 1 ];
992 /* the action file gets copied in in place of this dollarsign */
993 #line 543 "/usr/share/bison.simple"
1004 short * ssp1
= yyss
- 1 ;
1005 fprintf ( stderr
, "state stack now" );
1006 while ( ssp1
!= yyssp
)
1007 fprintf ( stderr
, " %d " , *++ ssp1
);
1008 fprintf ( stderr
, " \n " );
1018 yylsp
-> first_line
= yylloc
. first_line
;
1019 yylsp
-> first_column
= yylloc
. first_column
;
1020 yylsp
-> last_line
= ( yylsp
- 1 )-> last_line
;
1021 yylsp
-> last_column
= ( yylsp
- 1 )-> last_column
;
1026 yylsp
-> last_line
= ( yylsp
+ yylen
- 1 )-> last_line
;
1027 yylsp
-> last_column
= ( yylsp
+ yylen
- 1 )-> last_column
;
1031 /* Now "shift" the result of the reduction.
1032 Determine what state that goes to,
1033 based on the state we popped back to
1034 and the rule number reduced by. */
1038 yystate
= yypgoto
[ yyn
- YYNTBASE
] + * yyssp
;
1039 if ( yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[ yystate
] == * yyssp
)
1040 yystate
= yytable
[ yystate
];
1042 yystate
= yydefgoto
[ yyn
- YYNTBASE
];
1046 yyerrlab
: /* here on detecting error */
1049 /* If not already recovering from an error, report this error. */
1053 #ifdef YYERROR_VERBOSE
1054 yyn
= yypact
[ yystate
];
1056 if ( yyn
> YYFLAG
&& yyn
< YYLAST
)
1063 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1064 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1065 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1066 if ( yycheck
[ x
+ yyn
] == x
)
1067 size
+= strlen ( yytname
[ x
]) + 15 , count
++;
1068 msg
= ( char *) malloc ( size
+ 15 );
1071 strcpy ( msg
, "parse error" );
1076 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1077 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1078 if ( yycheck
[ x
+ yyn
] == x
)
1080 strcat ( msg
, count
== 0 ? ", expecting `" : " or `" );
1081 strcat ( msg
, yytname
[ x
]);
1090 yyerror ( "parse error; also virtual memory exceeded" );
1093 #endif /* YYERROR_VERBOSE */
1094 yyerror ( "parse error" );
1098 yyerrlab1
: /* here on error raised explicitly by an action */
1100 if ( yyerrstatus
== 3 )
1102 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1104 /* return failure if at end of input */
1105 if ( yychar
== YYEOF
)
1110 fprintf ( stderr
, "Discarding token %d ( %s ). \n " , yychar
, yytname
[ yychar1
]);
1116 /* Else will try to reuse lookahead token
1117 after shifting the error token. */
1119 yyerrstatus
= 3 ; /* Each real token shifted decrements this */
1123 yyerrdefault
: /* current state does not do anything special for the error token. */
1126 /* This is wrong; only states that explicitly want error tokens
1127 should shift them. */
1128 yyn
= yydefact
[ yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1129 if ( yyn
) goto yydefault
;
1132 yyerrpop
: /* pop the current state because it cannot handle the error token */
1134 if ( yyssp
== yyss
) YYABORT
;
1144 short * ssp1
= yyss
- 1 ;
1145 fprintf ( stderr
, "Error: state stack now" );
1146 while ( ssp1
!= yyssp
)
1147 fprintf ( stderr
, " %d " , *++ ssp1
);
1148 fprintf ( stderr
, " \n " );
1154 yyn
= yypact
[ yystate
];
1159 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != YYTERROR
)
1178 fprintf ( stderr
, "Shifting error token, " );
1190 /* YYACCEPT comes here. */
1202 /* YYABORT comes here. */
1213 #line 249 "OSUnserializeXML.y"
1217 OSUnserializeerror ( parser_state_t
* state
, char * s
) /* Called by yyparse on errors */
1219 char tempString
[ 128 ];
1221 if ( state
-> errorString
) {
1222 snprintf ( tempString
, 128 , "OSUnserializeXML: %s near line %d \n " , s
, state
-> lineNumber
);
1223 *( state
-> errorString
) = OSString :: withCString ( tempString
);
1229 #define TAG_MAX_LENGTH 32
1230 #define TAG_MAX_ATTRIBUTES 32
1235 #define TAG_COMMENT 4
1237 #define currentChar() (state->parseBuffer[state->parseBufferIndex])
1238 #define nextChar() (state->parseBuffer[++state->parseBufferIndex])
1239 #define prevChar() (state->parseBuffer[state->parseBufferIndex - 1])
1241 #define isSpace(c) ((c) == ' ' || (c) == ' \t ' )
1242 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z' ) || ((c) >= 'a' && (c) <= 'z' ))
1243 #define isDigit(c) ((c) >= '0' && (c) <= '9' )
1244 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f' )
1245 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
1246 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-' ))
1249 getTag ( parser_state_t
* state
,
1250 char tag
[ TAG_MAX_LENGTH
],
1251 int * attributeCount
,
1252 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
],
1253 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
] )
1256 int c
= currentChar ();
1257 int tagType
= TAG_START
;
1259 * attributeCount
= 0 ;
1261 if ( c
!= '<' ) return TAG_BAD
;
1262 c
= nextChar (); // skip '<'
1264 if ( c
== '?' || c
== '!' ) {
1265 while (( c
= nextChar ()) != 0 ) {
1266 if ( c
== ' \n ' ) state
-> lineNumber
++;
1275 c
= nextChar (); // skip '/'
1278 if (! isAlpha ( c
)) return TAG_BAD
;
1280 /* find end of tag while copying it */
1281 while ( isAlphaNumeric ( c
)) {
1284 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1289 // printf("tag %s, type %d\n", tag, tagType);
1291 // look for attributes of the form attribute = "value" ...
1292 while (( c
!= '>' ) && ( c
!= '/' )) {
1293 while ( isSpace ( c
)) c
= nextChar ();
1296 while ( isAlphaNumeric ( c
)) {
1297 attributes
[* attributeCount
][ length
++] = c
;
1298 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1301 attributes
[* attributeCount
][ length
] = 0 ;
1303 while ( isSpace ( c
)) c
= nextChar ();
1305 if ( c
!= '=' ) return TAG_BAD
;
1308 while ( isSpace ( c
)) c
= nextChar ();
1310 if ( c
!= '"' ) return TAG_BAD
;
1314 values
[* attributeCount
][ length
++] = c
;
1315 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1318 values
[* attributeCount
][ length
] = 0 ;
1320 c
= nextChar (); // skip closing quote
1322 // printf(" attribute '%s' = '%s', nextchar = '%c'\n",
1323 // attributes[*attributeCount], values[*attributeCount], c);
1325 (* attributeCount
)++;
1326 if (* attributeCount
>= TAG_MAX_ATTRIBUTES
) return TAG_BAD
;
1330 c
= nextChar (); // skip '/'
1331 tagType
= TAG_EMPTY
;
1333 if ( c
!= '>' ) return TAG_BAD
;
1334 c
= nextChar (); // skip '>'
1340 getString ( parser_state_t
* state
)
1342 int c
= currentChar ();
1343 int start
, length
, i
, j
;
1346 start
= state
-> parseBufferIndex
;
1347 /* find end of string */
1350 if ( c
== ' \n ' ) state
-> lineNumber
++;
1357 if ( c
!= '<' ) return 0 ;
1359 length
= state
-> parseBufferIndex
- start
;
1361 /* copy to null terminated buffer */
1362 tempString
= ( char *) malloc ( length
+ 1 );
1363 if ( tempString
== 0 ) {
1364 printf ( "OSUnserializeXML: can't alloc temp memory \n " );
1368 // copy out string in tempString
1369 // "&" -> '&', "<" -> '<', ">" -> '>'
1372 while ( i
< length
) {
1373 c
= state
-> parseBuffer
[ start
+ i
++];
1375 tempString
[ j
++] = c
;
1377 if (( i
+ 3 ) > length
) goto error
;
1378 c
= state
-> parseBuffer
[ start
+ i
++];
1380 if ( state
-> parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1381 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1382 tempString
[ j
++] = '<' ;
1386 if ( state
-> parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1387 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1388 tempString
[ j
++] = '>' ;
1391 if (( i
+ 3 ) > length
) goto error
;
1393 if ( state
-> parseBuffer
[ start
+ i
++] != 'm' ) goto error
;
1394 if ( state
-> parseBuffer
[ start
+ i
++] != 'p' ) goto error
;
1395 if ( state
-> parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1396 tempString
[ j
++] = '&' ;
1404 // printf("string %s\n", tempString);
1409 if ( tempString
) free ( tempString
);
1414 getNumber ( parser_state_t
* state
)
1416 unsigned long long n
= 0 ;
1418 bool negate
= false ;
1419 int c
= currentChar ();
1434 n
= ( n
* base
+ c
- '0' );
1438 n
= ( unsigned long long )(( long long ) n
* ( long long )- 1 );
1441 while ( isHexDigit ( c
)) {
1443 n
= ( n
* base
+ c
- '0' );
1445 n
= ( n
* base
+ 0xa + c
- 'a' );
1450 // printf("number 0x%x\n", (unsigned long)n);
1454 // taken from CFXMLParsing/CFPropertyList.c
1456 static const signed char __CFPLDataDecodeTable
[ 128 ] = {
1457 /* 000 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1458 /* 010 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1459 /* 020 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1460 /* 030 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1461 /* ' ' */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1462 /* '(' */ - 1 , - 1 , - 1 , 62 , - 1 , - 1 , - 1 , 63 ,
1463 /* '0' */ 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 ,
1464 /* '8' */ 60 , 61 , - 1 , - 1 , - 1 , 0 , - 1 , - 1 ,
1465 /* '@' */ - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 ,
1466 /* 'H' */ 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ,
1467 /* 'P' */ 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 ,
1468 /* 'X' */ 23 , 24 , 25 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1469 /* '`' */ - 1 , 26 , 27 , 28 , 29 , 30 , 31 , 32 ,
1470 /* 'h' */ 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 ,
1471 /* 'p' */ 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 ,
1472 /* 'x' */ 49 , 50 , 51 , - 1 , - 1 , - 1 , - 1 , - 1
1475 #define DATA_ALLOC_SIZE 4096
1478 getCFEncodedData ( parser_state_t
* state
, unsigned int * size
)
1480 int numeq
= 0 , acc
= 0 , cntr
= 0 ;
1481 int tmpbufpos
= 0 , tmpbuflen
= 0 ;
1482 unsigned char * tmpbuf
= ( unsigned char *) malloc ( DATA_ALLOC_SIZE
);
1484 int c
= currentChar ();
1493 if ( c
== '=' ) numeq
++; else numeq
= 0 ;
1494 if ( c
== ' \n ' ) state
-> lineNumber
++;
1495 if ( __CFPLDataDecodeTable
[ c
] < 0 ) {
1501 acc
+= __CFPLDataDecodeTable
[ c
];
1502 if ( 0 == ( cntr
& 0x3 )) {
1503 if ( tmpbuflen
<= tmpbufpos
+ 2 ) {
1504 tmpbuflen
+= DATA_ALLOC_SIZE
;
1505 tmpbuf
= ( unsigned char *) realloc ( tmpbuf
, tmpbuflen
);
1507 tmpbuf
[ tmpbufpos
++] = ( acc
>> 16 ) & 0xff ;
1509 tmpbuf
[ tmpbufpos
++] = ( acc
>> 8 ) & 0xff ;
1511 tmpbuf
[ tmpbufpos
++] = acc
& 0xff ;
1524 getHexData ( parser_state_t
* state
, unsigned int * size
)
1527 unsigned char * d
, * start
, * lastStart
;
1529 start
= lastStart
= d
= ( unsigned char *) malloc ( DATA_ALLOC_SIZE
);
1534 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1536 state
-> lineNumber
++;
1543 * d
= ( c
- '0' ) << 4 ;
1544 } else if ( isAlphaDigit ( c
)) {
1545 * d
= ( 0xa + ( c
- 'a' )) << 4 ;
1554 } else if ( isAlphaDigit ( c
)) {
1555 * d
|= 0xa + ( c
- 'a' );
1561 if (( d
- lastStart
) >= DATA_ALLOC_SIZE
) {
1562 int oldsize
= d
- start
;
1563 start
= ( unsigned char *) realloc ( start
, oldsize
+ DATA_ALLOC_SIZE
);
1564 d
= lastStart
= start
+ oldsize
;
1580 yylex ( YYSTYPE
* lvalp
, parser_state_t
* state
)
1584 char tag
[ TAG_MAX_LENGTH
];
1586 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1587 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1593 /* skip white space */
1594 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1596 /* keep track of line number, don't return \n's */
1598 STATE
-> lineNumber
++;
1603 // end of the buffer?
1606 tagType
= getTag ( STATE
, tag
, & attributeCount
, attributes
, values
);
1607 if ( tagType
== TAG_BAD
) return SYNTAX_ERROR
;
1608 if ( tagType
== TAG_COMMENT
) goto top
;
1610 // handle allocation and check for "ID" and "IDREF" tags up front
1611 * lvalp
= object
= newObject ( STATE
);
1613 for ( i
= 0 ; i
< attributeCount
; i
++) {
1614 if ( attributes
[ i
][ 0 ] == 'I' && attributes
[ i
][ 1 ] == 'D' ) {
1615 // check for idref's, note: we ignore the tag, for
1616 // this to work correctly, all idrefs must be unique
1617 // across the whole serialization
1618 if ( attributes
[ i
][ 2 ] == 'R' && attributes
[ i
][ 3 ] == 'E' &&
1619 attributes
[ i
][ 4 ] == 'F' && ! attributes
[ i
][ 5 ]) {
1620 if ( tagType
!= TAG_EMPTY
) return SYNTAX_ERROR
;
1621 object
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1625 if (! attributes
[ i
][ 2 ]) {
1626 object
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1628 return SYNTAX_ERROR
;
1635 if (! strcmp ( tag
, "array" )) {
1636 if ( tagType
== TAG_EMPTY
) {
1637 object
-> elements
= NULL
;
1640 return ( tagType
== TAG_START
) ? '(' : ')' ;
1644 if (! strcmp ( tag
, "dict" )) {
1645 if ( tagType
== TAG_EMPTY
) {
1646 object
-> elements
= NULL
;
1649 return ( tagType
== TAG_START
) ? '{' : '}' ;
1651 if (! strcmp ( tag
, "data" )) {
1653 if ( tagType
== TAG_EMPTY
) {
1654 object
-> data
= NULL
;
1659 bool isHexFormat
= false ;
1660 for ( int i
= 0 ; i
< attributeCount
; i
++) {
1661 if (! strcmp ( attributes
[ i
], "format" ) && ! strcmp ( values
[ i
], "hex" )) {
1666 // CF encoded is the default form
1668 object
-> data
= getHexData ( STATE
, & size
);
1670 object
-> data
= getCFEncodedData ( STATE
, & size
);
1672 object
-> size
= size
;
1673 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "data" )) {
1674 return SYNTAX_ERROR
;
1680 if (! strcmp ( tag
, "false" )) {
1681 if ( tagType
== TAG_EMPTY
) {
1688 if (! strcmp ( tag
, "integer" )) {
1689 object
-> size
= 64 ; // default
1690 for ( i
= 0 ; i
< attributeCount
; i
++) {
1691 if (! strcmp ( attributes
[ i
], "size" )) {
1692 object
-> size
= strtoul ( values
[ i
], NULL
, 0 );
1695 if ( tagType
== TAG_EMPTY
) {
1699 object
-> number
= getNumber ( STATE
);
1700 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "integer" )) {
1701 return SYNTAX_ERROR
;
1707 if (! strcmp ( tag
, "key" )) {
1708 if ( tagType
== TAG_EMPTY
) return SYNTAX_ERROR
;
1709 object
-> string
= getString ( STATE
);
1710 if (! object
-> string
) {
1711 return SYNTAX_ERROR
;
1713 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1714 || strcmp ( tag
, "key" )) {
1715 return SYNTAX_ERROR
;
1721 if (! strcmp ( tag
, "plist" )) {
1722 freeObject ( STATE
, object
);
1727 if (! strcmp ( tag
, "string" )) {
1728 if ( tagType
== TAG_EMPTY
) {
1729 object
-> string
= ( char *) malloc ( 1 );
1730 object
-> string
[ 0 ] = 0 ;
1733 object
-> string
= getString ( STATE
);
1734 if (! object
-> string
) {
1735 return SYNTAX_ERROR
;
1737 if (( getTag ( STATE
, tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1738 || strcmp ( tag
, "string" )) {
1739 return SYNTAX_ERROR
;
1743 if (! strcmp ( tag
, "set" )) {
1744 if ( tagType
== TAG_EMPTY
) {
1745 object
-> elements
= NULL
;
1748 if ( tagType
== TAG_START
) {
1756 if (! strcmp ( tag
, "true" )) {
1757 if ( tagType
== TAG_EMPTY
) {
1765 return SYNTAX_ERROR
;
1768 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1769 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1770 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1772 // "java" like allocation, if this code hits a syntax error in the
1773 // the middle of the parsed string we just bail with pointers hanging
1774 // all over place, this code helps keeps it all together
1776 //static int object_count = 0;
1779 newObject ( parser_state_t
* state
)
1783 if ( state
-> freeObjects
) {
1784 o
= state
-> freeObjects
;
1785 state
-> freeObjects
= state
-> freeObjects
-> next
;
1787 o
= ( object_t
*) malloc ( sizeof ( object_t
));
1789 bzero ( o
, sizeof ( object_t
));
1790 o
-> free
= state
-> objects
;
1798 freeObject ( parser_state_t
* state
, object_t
* o
)
1800 o
-> next
= state
-> freeObjects
;
1801 state
-> freeObjects
= o
;
1805 cleanupObjects ( parser_state_t
* state
)
1807 object_t
* t
, * o
= state
-> objects
;
1811 // printf("OSUnserializeXML: releasing object o=%x object=%x\n", (int)o, (int)o->object);
1812 o
-> object
-> release ();
1815 // printf("OSUnserializeXML: freeing object o=%x data=%x\n", (int)o, (int)o->data);
1819 // printf("OSUnserializeXML: releasing object o=%x key=%x\n", (int)o, (int)o->key);
1823 // printf("OSUnserializeXML: freeing object o=%x string=%x\n", (int)o, (int)o->string);
1832 // printf("object_count = %d\n", object_count);
1835 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1836 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1837 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1840 rememberObject ( parser_state_t
* state
, int tag
, OSObject
* o
)
1843 snprintf ( key
, 16 , " %u " , tag
);
1845 // printf("remember key %s\n", key);
1847 state
-> tags
-> setObject ( key
, o
);
1851 retrieveObject ( parser_state_t
* state
, int tag
)
1856 snprintf ( key
, 16 , " %u " , tag
);
1858 // printf("retrieve key '%s'\n", key);
1860 ref
= state
-> tags
-> getObject ( key
);
1863 o
= newObject ( state
);
1868 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1869 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1870 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1873 buildDictionary ( parser_state_t
* state
, object_t
* header
)
1879 // get count and reverse order
1880 o
= header
-> elements
;
1881 header
-> elements
= 0 ;
1887 t
-> next
= header
-> elements
;
1888 header
-> elements
= t
;
1891 dict
= OSDictionary :: withCapacity ( count
);
1892 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, dict
);
1894 o
= header
-> elements
;
1896 dict
-> setObject ( o
-> key
, o
-> object
);
1899 o
-> object
-> release ();
1905 freeObject ( state
, t
);
1913 buildArray ( parser_state_t
* state
, object_t
* header
)
1919 // get count and reverse order
1920 o
= header
-> elements
;
1921 header
-> elements
= 0 ;
1927 t
-> next
= header
-> elements
;
1928 header
-> elements
= t
;
1931 array
= OSArray :: withCapacity ( count
);
1932 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, array
);
1934 o
= header
-> elements
;
1936 array
-> setObject ( o
-> object
);
1938 o
-> object
-> release ();
1943 freeObject ( state
, t
);
1951 buildSet ( parser_state_t
* state
, object_t
* header
)
1953 object_t
* o
= buildArray ( state
, header
);
1955 OSArray
* array
= ( OSArray
*) o
-> object
;
1956 OSSet
* set
= OSSet :: withArray ( array
, array
-> getCapacity ());
1958 // write over the reference created in buildArray
1959 if ( header
-> idref
>= 0 ) rememberObject ( state
, header
-> idref
, set
);
1967 buildString ( parser_state_t
* state
, object_t
* o
)
1971 string
= OSString :: withCString ( o
-> string
);
1972 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, string
);
1982 buildData ( parser_state_t
* state
, object_t
* o
)
1987 data
= OSData :: withBytes ( o
-> data
, o
-> size
);
1989 data
= OSData :: withCapacity ( 0 );
1991 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, data
);
1993 if ( o
-> size
) free ( o
-> data
);
2000 buildNumber ( parser_state_t
* state
, object_t
* o
)
2002 OSNumber
* number
= OSNumber :: withNumber ( o
-> number
, o
-> size
);
2004 if ( o
-> idref
>= 0 ) rememberObject ( state
, o
-> idref
, number
);
2011 buildBoolean ( parser_state_t
* state
, object_t
* o
)
2013 o
-> object
= (( o
-> number
== 0 ) ? kOSBooleanFalse
: kOSBooleanTrue
);
2014 o
-> object
-> retain ();
2019 OSUnserializeXML ( const char * buffer
, OSString
** errorString
)
2022 parser_state_t
* state
= ( parser_state_t
*) malloc ( sizeof ( parser_state_t
));
2024 if ((! state
) || (! buffer
)) return 0 ;
2027 if ( errorString
) * errorString
= NULL
;
2029 state
-> parseBuffer
= buffer
;
2030 state
-> parseBufferIndex
= 0 ;
2031 state
-> lineNumber
= 1 ;
2033 state
-> freeObjects
= 0 ;
2034 state
-> tags
= OSDictionary :: withCapacity ( 128 );
2035 state
-> errorString
= errorString
;
2036 state
-> parsedObject
= 0 ;
2038 ( void ) yyparse (( void *) state
);
2040 object
= state
-> parsedObject
;
2042 cleanupObjects ( state
);
2043 state
-> tags
-> release ();
2055 // DO NOT EDIT OSUnserializeXML.cpp!