]>
git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSUnserializeXML.cpp
f169f77206bcb1edcb4e44e0de2b9424989b78a0
2 * Copyright (c) 2000 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@
23 /* OSUnserializeXML.y created by rsulack on Tue Oct 12 1999 */
25 // XML parser for unserializing OSContainer objects
28 // bison -p OSUnserializeXML OSUnserializeXML.y
29 // head -50 OSUnserializeXML.y > OSUnserializeXML.cpp
30 // sed -e "s/stdio.h/stddef.h/" < OSUnserializeXML.tab.c >> OSUnserializeXML.cpp
32 // when changing code check in both OSUnserializeXML.y and OSUnserializeXML.cpp
40 // 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 52 "OSUnserializeXML.y"
78 #include <libkern/c++/OSMetaClass.h>
79 #include <libkern/c++/OSContainers.h>
80 #include <libkern/c++/OSLib.h>
82 typedef struct object
{
85 struct object
* elements
;
87 const OSSymbol
* key
; // for dictionary
89 void * data
; // for data
90 char * string
; // for string & symbol
91 long long number
; // for number
96 static int yyerror ( char * s
);
99 static object_t
* newObject ();
100 static void freeObject ( object_t
* o
);
102 static object_t
* buildOSDictionary ( object_t
*);
103 static object_t
* buildOSArray ( object_t
*);
104 static object_t
* buildOSSet ( object_t
*);
105 static object_t
* buildOSString ( object_t
*);
106 static object_t
* buildKey ( object_t
*);
107 static object_t
* buildOSData ( object_t
*);
108 static object_t
* buildOSNumber ( object_t
*);
109 static object_t
* buildOSBoolean ( object_t
* o
);
111 static void rememberObject ( int , OSObject
*);
112 static object_t
* retrieveObject ( int );
114 // resultant object of parsed text
115 static OSObject
* parsedObject
;
117 #define YYSTYPE object_t *
120 extern void * kern_os_malloc ( size_t size
);
121 extern void * kern_os_realloc ( void * addr
, size_t size
);
122 extern void kern_os_free ( void * addr
);
124 //XXX shouldn't have to define these
125 extern long strtol ( const char *, char **, int );
126 extern unsigned long strtoul ( const char *, char **, int );
130 #define malloc(s) kern_os_malloc(s)
131 #define realloc(a, s) kern_os_realloc(a, s)
132 #define free(a) kern_os_free(a)
148 #define YYFLAG -32768
151 #define YYTRANSLATE(x) ((unsigned)(x) <= 266 ? yytranslate[x] : 33)
153 static const char yytranslate
[] = { 0 ,
154 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
155 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
156 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
157 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 15 ,
158 16 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
159 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
160 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
161 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
162 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
163 17 , 2 , 18 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
164 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
165 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
166 2 , 2 , 13 , 2 , 14 , 2 , 2 , 2 , 2 , 2 ,
167 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
168 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
169 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
170 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
171 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
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 , 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 , 2 ,
179 2 , 2 , 2 , 2 , 2 , 1 , 3 , 4 , 5 , 6 ,
184 static const short yyprhs
[] = { 0 ,
185 0 , 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 , 17 ,
186 19 , 21 , 24 , 28 , 30 , 32 , 35 , 38 , 40 , 43 ,
187 47 , 49 , 52 , 56 , 58 , 60 , 63 , 65 , 67 , 69 ,
191 static const short yyrhs
[] = { - 1 ,
192 20 , 0 , 12 , 0 , 21 , 0 , 25 , 0 , 26 , 0 ,
193 32 , 0 , 29 , 0 , 31 , 0 , 28 , 0 , 30 , 0 ,
194 13 , 14 , 0 , 13 , 22 , 14 , 0 , 6 , 0 , 23 ,
195 0 , 22 , 23 , 0 , 24 , 20 , 0 , 8 , 0 , 15 ,
196 16 , 0 , 15 , 27 , 16 , 0 , 3 , 0 , 17 , 18 ,
197 0 , 17 , 27 , 18 , 0 , 10 , 0 , 20 , 0 , 27 ,
198 20 , 0 , 4 , 0 , 5 , 0 , 7 , 0 , 9 , 0 ,
205 static const short yyrline
[] = { 0 ,
206 123 , 124 , 129 , 135 , 136 , 137 , 138 , 139 , 140 , 141 ,
207 142 , 155 , 158 , 161 , 164 , 165 , 170 , 178 , 183 , 186 ,
208 189 , 192 , 195 , 198 , 201 , 204 , 211 , 214 , 217 , 220 ,
214 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
216 static const char * const yytname
[] = { "$" , "error" , "$undefined." , "ARRAY" ,
217 "BOOLEAN" , "DATA" , "DICTIONARY" , "IDREF" , "KEY" , "NUMBER" , "SET" , "STRING" , "SYNTAX_ERROR" ,
218 "'{'" , "'}'" , "'('" , "')'" , "'['" , "']'" , "input" , "object" , "dict" , "pairs" , "pair" , "key" ,
219 "array" , "set" , "elements" , "boolean" , "data" , "idref" , "number" , "string" , NULL
223 static const short yyr1
[] = { 0 ,
224 19 , 19 , 19 , 20 , 20 , 20 , 20 , 20 , 20 , 20 ,
225 20 , 21 , 21 , 21 , 22 , 22 , 23 , 24 , 25 , 25 ,
226 25 , 26 , 26 , 26 , 27 , 27 , 28 , 29 , 30 , 31 ,
230 static const short yyr2
[] = { 0 ,
231 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
232 1 , 2 , 3 , 1 , 1 , 2 , 2 , 1 , 2 , 3 ,
233 1 , 2 , 3 , 1 , 1 , 2 , 1 , 1 , 1 , 1 ,
237 static const short yydefact
[] = { 1 ,
238 21 , 27 , 28 , 14 , 29 , 30 , 24 , 31 , 3 , 0 ,
239 0 , 0 , 2 , 4 , 5 , 6 , 10 , 8 , 11 , 9 ,
240 7 , 18 , 12 , 0 , 15 , 0 , 19 , 25 , 0 , 22 ,
241 0 , 13 , 16 , 17 , 20 , 26 , 23 , 0 , 0 , 0
244 static const short yydefgoto
[] = { 38 ,
245 28 , 14 , 24 , 25 , 26 , 15 , 16 , 29 , 17 , 18 ,
249 static const short yypact
[] = { 45 ,
250 - 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 4 ,
251 60 , - 2 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,
252 - 32768 ,- 32768 ,- 32768 , 6 ,- 32768 , 90 ,- 32768 ,- 32768 , 75 ,- 32768 ,
253 29 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 10 , 17 ,- 32768
256 static const short yypgoto
[] = {- 32768 ,
257 0 ,- 32768 ,- 32768 , - 18 ,- 32768 ,- 32768 ,- 32768 , 7 ,- 32768 ,- 32768 ,
265 static const short yytable
[] = { 13 ,
266 1 , 2 , 3 , 4 , 5 , 33 , 6 , 7 , 8 , 39 ,
267 10 , 22 , 11 , 22 , 12 , 30 , 40 , 23 , 31 , 32 ,
268 0 , 0 , 0 , 0 , 0 , 34 , 0 , 0 , 36 , 0 ,
269 36 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 , 8 ,
270 0 , 10 , 0 , 11 , 0 , 12 , 37 , 1 , 2 , 3 ,
271 4 , 5 , 0 , 6 , 7 , 8 , 9 , 10 , 0 , 11 ,
272 0 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
273 8 , 0 , 10 , 0 , 11 , 27 , 12 , 1 , 2 , 3 ,
274 4 , 5 , 0 , 6 , 7 , 8 , 0 , 10 , 0 , 11 ,
275 35 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
276 8 , 0 , 10 , 0 , 11 , 0 , 12
279 static const short yycheck
[] = { 0 ,
280 3 , 4 , 5 , 6 , 7 , 24 , 9 , 10 , 11 , 0 ,
281 13 , 8 , 15 , 8 , 17 , 18 , 0 , 14 , 12 , 14 ,
282 - 1 , - 1 , - 1 , - 1 , - 1 , 26 , - 1 , - 1 , 29 , - 1 ,
283 31 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 , 11 ,
284 - 1 , 13 , - 1 , 15 , - 1 , 17 , 18 , 3 , 4 , 5 ,
285 6 , 7 , - 1 , 9 , 10 , 11 , 12 , 13 , - 1 , 15 ,
286 - 1 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
287 11 , - 1 , 13 , - 1 , 15 , 16 , 17 , 3 , 4 , 5 ,
288 6 , 7 , - 1 , 9 , 10 , 11 , - 1 , 13 , - 1 , 15 ,
289 16 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
290 11 , - 1 , 13 , - 1 , 15 , - 1 , 17
292 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
293 #line 3 "/usr/share/bison.simple"
294 /* This file comes from bison-1.28. */
296 /* Skeleton output parser for bison,
297 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
299 This program is free software; you can redistribute it and/or modify
300 it under the terms of the GNU General Public License as published by
301 the Free Software Foundation; either version 2, or (at your option)
304 This program is distributed in the hope that it will be useful,
305 but WITHOUT ANY WARRANTY; without even the implied warranty of
306 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
307 GNU General Public License for more details.
309 You should have received a copy of the GNU General Public License
310 along with this program; if not, write to the Free Software
311 Foundation, Inc., 59 Temple Place - Suite 330,
312 Boston, MA 02111-1307, USA. */
314 /* As a special exception, when this file is copied by Bison into a
315 Bison output file, you may use that output file without restriction.
316 This special exception was added by the Free Software Foundation
317 in version 1.24 of Bison. */
319 /* This is the parser code that is written into each bison parser
320 when the %semantic_parser declaration is not specified in the grammar.
321 It was written by Richard Stallman by simplifying the hairy parser
322 used when %semantic_parser is specified. */
324 #ifndef YYSTACK_USE_ALLOCA
326 #define YYSTACK_USE_ALLOCA
327 #else /* alloca not defined */
329 #define YYSTACK_USE_ALLOCA
330 #define alloca __builtin_alloca
331 #else /* not GNU C. */
332 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
333 #define YYSTACK_USE_ALLOCA
335 #else /* not sparc */
336 /* We think this test detects Watcom and Microsoft C. */
337 /* This used to test MSDOS, but that is a bad idea
338 since that symbol is in the user namespace. */
339 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
340 #if 0 /* No need for malloc.h, which pollutes the namespace;
341 instead, just don't use alloca. */
344 #else /* not MSDOS, or __TURBOC__ */
346 /* I don't know what this was needed for, but it pollutes the namespace.
347 So I turned it off. rms, 2 May 1997. */
348 /* #include <malloc.h> */
350 #define YYSTACK_USE_ALLOCA
351 #else /* not MSDOS, or __TURBOC__, or _AIX */
353 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
354 and on HPUX 10. Eventually we can turn this on. */
355 #define YYSTACK_USE_ALLOCA
356 #define alloca __builtin_alloca
359 #endif /* not _AIX */
360 #endif /* not MSDOS, or __TURBOC__ */
361 #endif /* not sparc */
362 #endif /* not GNU C */
363 #endif /* alloca not defined */
364 #endif /* YYSTACK_USE_ALLOCA not defined */
366 #ifdef YYSTACK_USE_ALLOCA
367 #define YYSTACK_ALLOC alloca
369 #define YYSTACK_ALLOC malloc
372 /* Note: there must be only one dollar sign in this file.
373 It is replaced by the list of actions, each action
374 as one case of the switch. */
376 #define yyerrok (yyerrstatus = 0)
377 #define yyclearin (yychar = YYEMPTY)
380 #define YYACCEPT goto yyacceptlab
381 #define YYABORT goto yyabortlab
382 #define YYERROR goto yyerrlab1
383 /* Like YYERROR except do call yyerror.
384 This remains here temporarily to ease the
385 transition to the new meaning of YYERROR, for GCC.
386 Once GCC version 2 has supplanted version 1, this can go. */
387 #define YYFAIL goto yyerrlab
388 #define YYRECOVERING() (!!yyerrstatus)
389 #define YYBACKUP(token, value) \
391 if (yychar == YYEMPTY && yylen == 1) \
392 { yychar = (token), yylval = (value); \
393 yychar1 = YYTRANSLATE (yychar); \
398 { yyerror ( "syntax error: cannot back up" ); YYERROR; } \
402 #define YYERRCODE 256
405 #define YYLEX yylex()
411 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
413 #define YYLEX yylex(&yylval, &yylloc)
415 #else /* not YYLSP_NEEDED */
417 #define YYLEX yylex(&yylval, YYLEX_PARAM)
419 #define YYLEX yylex(&yylval)
421 #endif /* not YYLSP_NEEDED */
424 /* If nonreentrant, generate the variables here */
428 int yychar
; /* the lookahead symbol */
429 YYSTYPE yylval
; /* the semantic value of the */
430 /* lookahead symbol */
433 YYLTYPE yylloc
; /* location data for the lookahead */
437 int yynerrs
; /* number of parse errors so far */
438 #endif /* not YYPURE */
441 int yydebug
; /* nonzero means print parse trace */
442 /* Since this is uninitialized, it does not stop multiple parsers
446 /* YYINITDEPTH indicates the initial size of the parser's stacks */
449 #define YYINITDEPTH 200
452 /* YYMAXDEPTH is the maximum size the stacks can grow to
453 (effective only if the built-in stack extension method is used). */
460 #define YYMAXDEPTH 10000
463 /* Define __yy_memcpy. Note that the size argument
464 should be passed with type unsigned int, because that is what the non-GCC
465 definitions require. With GCC, __builtin_memcpy takes an arg
466 of type size_t, but it can handle unsigned int. */
468 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
469 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
470 #else /* not GNU C or C++ */
473 /* This is the most reliable way to avoid incompatibilities
474 in available built-in functions on various systems. */
476 __yy_memcpy ( to
, from
, count
)
481 register char * f
= from
;
482 register char * t
= to
;
483 register int i
= count
;
489 #else /* __cplusplus */
491 /* This is the most reliable way to avoid incompatibilities
492 in available built-in functions on various systems. */
494 __yy_memcpy ( char * to
, char * from
, unsigned int count
)
496 register char * t
= to
;
497 register char * f
= from
;
498 register int i
= count
;
507 #line 217 "/usr/share/bison.simple"
509 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
510 into yyparse. The argument should have type void *.
511 It should actually point to an object.
512 Grammar actions can access the variable by casting it
513 to the proper pointer type. */
517 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
518 #define YYPARSE_PARAM_DECL
519 #else /* not __cplusplus */
520 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
521 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
522 #endif /* not __cplusplus */
523 #else /* not YYPARSE_PARAM */
524 #define YYPARSE_PARAM_ARG
525 #define YYPARSE_PARAM_DECL
526 #endif /* not YYPARSE_PARAM */
528 /* Prevent warning if -Wstrict-prototypes. */
531 int yyparse ( void *);
538 yyparse ( YYPARSE_PARAM_ARG
)
541 register int yystate
;
543 register short * yyssp
;
544 register YYSTYPE
* yyvsp
;
545 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
546 int yychar1
= 0 ; /* lookahead token as an internal (translated) token number */
548 short yyssa
[ YYINITDEPTH
]; /* the state stack */
549 YYSTYPE yyvsa
[ YYINITDEPTH
]; /* the semantic value stack */
551 short * yyss
= yyssa
; /* refer to the stacks thru separate pointers */
552 YYSTYPE
* yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
555 YYLTYPE yylsa
[ YYINITDEPTH
]; /* the location stack */
556 YYLTYPE
* yyls
= yylsa
;
559 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
561 #define YYPOPSTACK (yyvsp--, yyssp--)
564 int yystacksize
= YYINITDEPTH
;
565 int yyfree_stacks
= 0 ;
576 YYSTYPE yyval
; /* the variable used to return */
577 /* semantic values from the action */
584 fprintf ( stderr
, "Starting parse \n " );
590 yychar
= YYEMPTY
; /* Cause a token to be read. */
592 /* Initialize stack pointers.
593 Waste one element of value and location stack
594 so that they stay on the same level as the state stack.
595 The wasted elements are never initialized. */
603 /* Push a new state, which is found in yystate . */
604 /* In all cases, when you get here, the value and location stacks
605 have just been pushed. so pushing a state here evens the stacks. */
610 if ( yyssp
>= yyss
+ yystacksize
- 1 )
612 /* Give user a chance to reallocate the stack */
613 /* Use copies of these so that the &'s don't force the real ones into memory. */
614 YYSTYPE
* yyvs1
= yyvs
;
617 YYLTYPE
* yyls1
= yyls
;
620 /* Get the current used size of the three stacks, in elements. */
621 int size
= yyssp
- yyss
+ 1 ;
624 /* Each stack pointer address is followed by the size of
625 the data in use in that stack, in bytes. */
627 /* This used to be a conditional around just the two extra args,
628 but that might be undefined if yyoverflow is a macro. */
629 yyoverflow ( "parser stack overflow" ,
630 & yyss1
, size
* sizeof (* yyssp
),
631 & yyvs1
, size
* sizeof (* yyvsp
),
632 & yyls1
, size
* sizeof (* yylsp
),
635 yyoverflow ( "parser stack overflow" ,
636 & yyss1
, size
* sizeof (* yyssp
),
637 & yyvs1
, size
* sizeof (* yyvsp
),
641 yyss
= yyss1
; yyvs
= yyvs1
;
645 #else /* no yyoverflow */
646 /* Extend the stack our own way. */
647 if ( yystacksize
>= YYMAXDEPTH
)
649 yyerror ( "parser stack overflow" );
661 if ( yystacksize
> YYMAXDEPTH
)
662 yystacksize
= YYMAXDEPTH
;
663 #ifndef YYSTACK_USE_ALLOCA
666 yyss
= ( short *) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyssp
));
667 __yy_memcpy (( char *) yyss
, ( char *) yyss1
,
668 size
* ( unsigned int ) sizeof (* yyssp
));
669 yyvs
= ( YYSTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyvsp
));
670 __yy_memcpy (( char *) yyvs
, ( char *) yyvs1
,
671 size
* ( unsigned int ) sizeof (* yyvsp
));
673 yyls
= ( YYLTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yylsp
));
674 __yy_memcpy (( char *) yyls
, ( char *) yyls1
,
675 size
* ( unsigned int ) sizeof (* yylsp
));
677 #endif /* no yyoverflow */
679 yyssp
= yyss
+ size
- 1 ;
680 yyvsp
= yyvs
+ size
- 1 ;
682 yylsp
= yyls
+ size
- 1 ;
687 fprintf ( stderr
, "Stack size increased to %d \n " , yystacksize
);
690 if ( yyssp
>= yyss
+ yystacksize
- 1 )
696 fprintf ( stderr
, "Entering state %d \n " , yystate
);
702 /* Do appropriate processing given the current state. */
703 /* Read a lookahead token if we need one and don't already have one. */
706 /* First try to decide what to do without reference to lookahead token. */
708 yyn
= yypact
[ yystate
];
712 /* Not known => get a lookahead token if don't already have one. */
714 /* yychar is either YYEMPTY or YYEOF
715 or a valid token in external form. */
717 if ( yychar
== YYEMPTY
)
721 fprintf ( stderr
, "Reading a token: " );
726 /* Convert token to internal form (in yychar1) for indexing tables with */
728 if ( yychar
<= 0 ) /* This means end of input. */
731 yychar
= YYEOF
; /* Don't call YYLEX any more */
735 fprintf ( stderr
, "Now at end of input. \n " );
740 yychar1
= YYTRANSLATE ( yychar
);
745 fprintf ( stderr
, "Next token is %d ( %s " , yychar
, yytname
[ yychar1
]);
746 /* Give the individual parser a way to print the precise meaning
747 of a token, for further debugging info. */
749 YYPRINT ( stderr
, yychar
, yylval
);
751 fprintf ( stderr
, ") \n " );
757 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != yychar1
)
762 /* yyn is what to do for this token type in this state.
763 Negative => reduce, -yyn is rule number.
764 Positive => shift, yyn is new state.
765 New state is final state => don't bother to shift,
767 0, or most negative number => error. */
782 /* Shift the lookahead token. */
786 fprintf ( stderr
, "Shifting token %d ( %s ), " , yychar
, yytname
[ yychar1
]);
789 /* Discard the token being shifted unless it is eof. */
798 /* count tokens shifted since error; after three, turn off error status. */
799 if ( yyerrstatus
) yyerrstatus
--;
804 /* Do the default action for the current state. */
807 yyn
= yydefact
[ yystate
];
811 /* Do a reduction. yyn is the number of a rule to reduce with. */
815 yyval
= yyvsp
[ 1 - yylen
]; /* implement default value of the action */
822 fprintf ( stderr
, "Reducing via rule %d (line %d ), " ,
825 /* Print the symbols being reduced, and their result. */
826 for ( i
= yyprhs
[ yyn
]; yyrhs
[ i
] > 0 ; i
++)
827 fprintf ( stderr
, " %s " , yytname
[ yyrhs
[ i
]]);
828 fprintf ( stderr
, " -> %s \n " , yytname
[ yyr1
[ yyn
]]);
836 #line 123 "OSUnserializeXML.y"
837 { parsedObject
= ( OSObject
*) NULL
; YYACCEPT
; ;
840 #line 124 "OSUnserializeXML.y"
841 { parsedObject
= yyvsp
[ 0 ]-> object
;
842 yyvsp
[ 0 ]-> object
= 0 ;
843 freeObject ( yyvsp
[ 0 ]);
848 #line 129 "OSUnserializeXML.y"
850 yyerror ( "syntax error" );
855 #line 135 "OSUnserializeXML.y"
856 { yyval
= buildOSDictionary ( yyvsp
[ 0 ]); ;
859 #line 136 "OSUnserializeXML.y"
860 { yyval
= buildOSArray ( yyvsp
[ 0 ]); ;
863 #line 137 "OSUnserializeXML.y"
864 { yyval
= buildOSSet ( yyvsp
[ 0 ]); ;
867 #line 138 "OSUnserializeXML.y"
868 { yyval
= buildOSString ( yyvsp
[ 0 ]); ;
871 #line 139 "OSUnserializeXML.y"
872 { yyval
= buildOSData ( yyvsp
[ 0 ]); ;
875 #line 140 "OSUnserializeXML.y"
876 { yyval
= buildOSNumber ( yyvsp
[ 0 ]); ;
879 #line 141 "OSUnserializeXML.y"
880 { yyval
= buildOSBoolean ( yyvsp
[ 0 ]); ;
883 #line 142 "OSUnserializeXML.y"
884 { yyval
= retrieveObject ( yyvsp
[ 0 ]-> idref
);
886 yyval
-> object
-> retain ();
888 yyerror ( "forward reference detected" );
891 freeObject ( yyvsp
[ 0 ]);
895 #line 155 "OSUnserializeXML.y"
897 yyval
-> elements
= NULL
;
901 #line 158 "OSUnserializeXML.y"
903 yyval
-> elements
= yyvsp
[- 1 ];
907 #line 165 "OSUnserializeXML.y"
909 yyval
-> next
= yyvsp
[- 1 ];
913 #line 170 "OSUnserializeXML.y"
916 yyval
-> object
= yyvsp
[ 0 ]-> object
;
917 yyvsp
[ 0 ]-> object
= 0 ;
918 freeObject ( yyvsp
[ 0 ]);
922 #line 178 "OSUnserializeXML.y"
923 { yyval
= buildKey ( yyvsp
[ 0 ]); ;
926 #line 183 "OSUnserializeXML.y"
928 yyval
-> elements
= NULL
;
932 #line 186 "OSUnserializeXML.y"
934 yyval
-> elements
= yyvsp
[- 1 ];
938 #line 192 "OSUnserializeXML.y"
940 yyval
-> elements
= NULL
;
944 #line 195 "OSUnserializeXML.y"
946 yyval
-> elements
= yyvsp
[- 1 ];
950 #line 201 "OSUnserializeXML.y"
956 #line 204 "OSUnserializeXML.y"
958 yyval
-> next
= yyvsp
[- 1 ];
962 /* the action file gets copied in in place of this dollarsign */
963 #line 543 "/usr/share/bison.simple"
974 short * ssp1
= yyss
- 1 ;
975 fprintf ( stderr
, "state stack now" );
976 while ( ssp1
!= yyssp
)
977 fprintf ( stderr
, " %d " , *++ ssp1
);
978 fprintf ( stderr
, " \n " );
988 yylsp
-> first_line
= yylloc
. first_line
;
989 yylsp
-> first_column
= yylloc
. first_column
;
990 yylsp
-> last_line
= ( yylsp
- 1 )-> last_line
;
991 yylsp
-> last_column
= ( yylsp
- 1 )-> last_column
;
996 yylsp
-> last_line
= ( yylsp
+ yylen
- 1 )-> last_line
;
997 yylsp
-> last_column
= ( yylsp
+ yylen
- 1 )-> last_column
;
1001 /* Now "shift" the result of the reduction.
1002 Determine what state that goes to,
1003 based on the state we popped back to
1004 and the rule number reduced by. */
1008 yystate
= yypgoto
[ yyn
- YYNTBASE
] + * yyssp
;
1009 if ( yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[ yystate
] == * yyssp
)
1010 yystate
= yytable
[ yystate
];
1012 yystate
= yydefgoto
[ yyn
- YYNTBASE
];
1016 yyerrlab
: /* here on detecting error */
1019 /* If not already recovering from an error, report this error. */
1023 #ifdef YYERROR_VERBOSE
1024 yyn
= yypact
[ yystate
];
1026 if ( yyn
> YYFLAG
&& yyn
< YYLAST
)
1033 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1034 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1035 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1036 if ( yycheck
[ x
+ yyn
] == x
)
1037 size
+= strlen ( yytname
[ x
]) + 15 , count
++;
1038 msg
= ( char *) malloc ( size
+ 15 );
1041 strcpy ( msg
, "parse error" );
1046 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1047 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1048 if ( yycheck
[ x
+ yyn
] == x
)
1050 strcat ( msg
, count
== 0 ? ", expecting `" : " or `" );
1051 strcat ( msg
, yytname
[ x
]);
1060 yyerror ( "parse error; also virtual memory exceeded" );
1063 #endif /* YYERROR_VERBOSE */
1064 yyerror ( "parse error" );
1068 yyerrlab1
: /* here on error raised explicitly by an action */
1070 if ( yyerrstatus
== 3 )
1072 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1074 /* return failure if at end of input */
1075 if ( yychar
== YYEOF
)
1080 fprintf ( stderr
, "Discarding token %d ( %s ). \n " , yychar
, yytname
[ yychar1
]);
1086 /* Else will try to reuse lookahead token
1087 after shifting the error token. */
1089 yyerrstatus
= 3 ; /* Each real token shifted decrements this */
1093 yyerrdefault
: /* current state does not do anything special for the error token. */
1096 /* This is wrong; only states that explicitly want error tokens
1097 should shift them. */
1098 yyn
= yydefact
[ yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1099 if ( yyn
) goto yydefault
;
1102 yyerrpop
: /* pop the current state because it cannot handle the error token */
1104 if ( yyssp
== yyss
) YYABORT
;
1114 short * ssp1
= yyss
- 1 ;
1115 fprintf ( stderr
, "Error: state stack now" );
1116 while ( ssp1
!= yyssp
)
1117 fprintf ( stderr
, " %d " , *++ ssp1
);
1118 fprintf ( stderr
, " \n " );
1124 yyn
= yypact
[ yystate
];
1129 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != YYTERROR
)
1148 fprintf ( stderr
, "Shifting error token, " );
1160 /* YYACCEPT comes here. */
1172 /* YYABORT comes here. */
1183 #line 226 "OSUnserializeXML.y"
1186 static int lineNumber
= 0 ;
1187 static const char * parseBuffer
;
1188 static int parseBufferIndex
;
1190 #define currentChar() (parseBuffer[parseBufferIndex])
1191 #define nextChar() (parseBuffer[++parseBufferIndex])
1192 #define prevChar() (parseBuffer[parseBufferIndex - 1])
1194 #define isSpace(c) ((c) == ' ' || (c) == ' \t ' )
1195 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z' ) || ((c) >= 'a' && (c) <= 'z' ))
1196 #define isDigit(c) ((c) >= '0' && (c) <= '9' )
1197 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f' )
1198 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
1199 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-' ))
1201 static char yyerror_message
[ 128 ];
1204 yyerror ( char * s
) /* Called by yyparse on error */
1206 sprintf ( yyerror_message
, "OSUnserializeXML: %s near line %d \n " , s
, lineNumber
);
1210 #define TAG_MAX_LENGTH 32
1211 #define TAG_MAX_ATTRIBUTES 32
1216 #define TAG_COMMENT 4
1219 getTag ( char tag
[ TAG_MAX_LENGTH
],
1220 int * attributeCount
,
1221 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
],
1222 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
] )
1225 int c
= currentChar ();
1226 int tagType
= TAG_START
;
1228 * attributeCount
= 0 ;
1230 if ( c
!= '<' ) return TAG_BAD
;
1231 c
= nextChar (); // skip '<'
1233 if ( c
== '?' || c
== '!' ) {
1234 while (( c
= nextChar ()) != 0 ) {
1235 if ( c
== ' \n ' ) lineNumber
++;
1244 c
= nextChar (); // skip '/'
1247 if (! isAlpha ( c
)) return TAG_BAD
;
1249 /* find end of tag while copying it */
1250 while ( isAlphaNumeric ( c
)) {
1253 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1258 //printf("tag %s, type %d\n", tag, tagType);
1260 // look for attributes of the form attribute = "value" ...
1261 while (( c
!= '>' ) && ( c
!= '/' )) {
1262 while ( isSpace ( c
)) c
= nextChar ();
1265 while ( isAlphaNumeric ( c
)) {
1266 attributes
[* attributeCount
][ length
++] = c
;
1267 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1270 attributes
[* attributeCount
][ length
] = 0 ;
1272 while ( isSpace ( c
)) c
= nextChar ();
1274 if ( c
!= '=' ) return TAG_BAD
;
1277 while ( isSpace ( c
)) c
= nextChar ();
1279 if ( c
!= '"' ) return TAG_BAD
;
1283 values
[* attributeCount
][ length
++] = c
;
1284 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1287 values
[* attributeCount
][ length
] = 0 ;
1289 c
= nextChar (); // skip closing quote
1291 //printf(" attribute '%s' = '%s', nextchar = '%c'\n", attributes[*attributeCount], values[*attributeCount], c);
1293 (* attributeCount
)++;
1294 if (* attributeCount
>= TAG_MAX_ATTRIBUTES
) return TAG_BAD
;
1298 c
= nextChar (); // skip '/'
1299 tagType
= TAG_EMPTY
;
1301 if ( c
!= '>' ) return TAG_BAD
;
1302 c
= nextChar (); // skip '>'
1310 int c
= currentChar ();
1312 int start
, length
, i
, j
;;
1315 start
= parseBufferIndex
;
1316 /* find end of string */
1319 if ( c
== ' \n ' ) lineNumber
++;
1326 if ( c
!= '<' ) return 0 ;
1328 length
= parseBufferIndex
- start
;
1330 /* copy to null terminated buffer */
1331 tempString
= ( char *) malloc ( length
+ 1 );
1332 if ( tempString
== 0 ) {
1333 printf ( "OSUnserializeXML: can't alloc temp memory \n " );
1337 // copy out string in tempString
1338 // "&" -> '&', "<" -> '<', ">" -> '>'
1341 while ( i
< length
) {
1342 c
= parseBuffer
[ start
+ i
++];
1344 tempString
[ j
++] = c
;
1346 if (( i
+ 3 ) > length
) goto error
;
1347 c
= parseBuffer
[ start
+ i
++];
1349 if ( parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1350 if ( parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1351 tempString
[ j
++] = '<' ;
1355 if ( parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1356 if ( parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1357 tempString
[ j
++] = '>' ;
1360 if (( i
+ 3 ) > length
) goto error
;
1362 if ( parseBuffer
[ start
+ i
++] != 'm' ) goto error
;
1363 if ( parseBuffer
[ start
+ i
++] != 'p' ) goto error
;
1364 if ( parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1365 tempString
[ j
++] = '&' ;
1373 //printf("string %s\n", tempString);
1378 if ( tempString
) free ( tempString
);
1385 unsigned long long n
= 0 ;
1387 int c
= currentChar ();
1389 if (! isDigit ( c
)) return 0 ;
1400 n
= ( n
* base
+ c
- '0' );
1404 while ( isHexDigit ( c
)) {
1406 n
= ( n
* base
+ c
- '0' );
1408 n
= ( n
* base
+ 0xa + c
- 'a' );
1413 //printf("number 0x%x\n", (unsigned long)n);
1417 // taken from CFXMLParsing/CFPropertyList.c
1419 static const signed char __CFPLDataDecodeTable
[ 128 ] = {
1420 /* 000 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1421 /* 010 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1422 /* 020 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1423 /* 030 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1424 /* ' ' */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1425 /* '(' */ - 1 , - 1 , - 1 , 62 , - 1 , - 1 , - 1 , 63 ,
1426 /* '0' */ 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 ,
1427 /* '8' */ 60 , 61 , - 1 , - 1 , - 1 , 0 , - 1 , - 1 ,
1428 /* '@' */ - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 ,
1429 /* 'H' */ 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ,
1430 /* 'P' */ 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 ,
1431 /* 'X' */ 23 , 24 , 25 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1432 /* '`' */ - 1 , 26 , 27 , 28 , 29 , 30 , 31 , 32 ,
1433 /* 'h' */ 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 ,
1434 /* 'p' */ 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 ,
1435 /* 'x' */ 49 , 50 , 51 , - 1 , - 1 , - 1 , - 1 , - 1
1438 #define OSDATA_ALLOC_SIZE 4096
1441 getCFEncodedData ( unsigned int * size
)
1443 int numeq
= 0 , acc
= 0 , cntr
= 0 ;
1444 int tmpbufpos
= 0 , tmpbuflen
= 0 ;
1445 unsigned char * tmpbuf
= ( unsigned char *) malloc ( OSDATA_ALLOC_SIZE
);
1447 int c
= currentChar ();
1456 if ( c
== '=' ) numeq
++; else numeq
= 0 ;
1457 if ( c
== ' \n ' ) lineNumber
++;
1458 if ( __CFPLDataDecodeTable
[ c
] < 0 ) {
1464 acc
+= __CFPLDataDecodeTable
[ c
];
1465 if ( 0 == ( cntr
& 0x3 )) {
1466 if ( tmpbuflen
<= tmpbufpos
+ 2 ) {
1467 tmpbuflen
+= OSDATA_ALLOC_SIZE
;
1468 tmpbuf
= ( unsigned char *) realloc ( tmpbuf
, tmpbuflen
);
1470 tmpbuf
[ tmpbufpos
++] = ( acc
>> 16 ) & 0xff ;
1472 tmpbuf
[ tmpbufpos
++] = ( acc
>> 8 ) & 0xff ;
1474 tmpbuf
[ tmpbufpos
++] = acc
& 0xff ;
1483 getHexData ( unsigned int * size
)
1486 unsigned char * d
, * start
, * lastStart
;
1488 start
= lastStart
= d
= ( unsigned char *) malloc ( OSDATA_ALLOC_SIZE
);
1493 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1502 * d
= ( c
- '0' ) << 4 ;
1503 } else if ( isAlphaDigit ( c
)) {
1504 * d
= ( 0xa + ( c
- 'a' )) << 4 ;
1513 } else if ( isAlphaDigit ( c
)) {
1514 * d
|= 0xa + ( c
- 'a' );
1520 if (( d
- lastStart
) >= OSDATA_ALLOC_SIZE
) {
1521 int oldsize
= d
- start
;
1522 start
= ( unsigned char *) realloc ( start
, oldsize
+ OSDATA_ALLOC_SIZE
);
1523 d
= lastStart
= start
+ oldsize
;
1543 char tag
[ TAG_MAX_LENGTH
];
1545 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1546 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1548 if ( parseBufferIndex
== 0 ) lineNumber
= 1 ;
1553 /* skip white space */
1554 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1556 /* keep track of line number, don't return \n's */
1565 tagType
= getTag ( tag
, & attributeCount
, attributes
, values
);
1566 if ( tagType
== TAG_BAD
) return SYNTAX_ERROR
;
1567 if ( tagType
== TAG_COMMENT
) goto top
;
1569 // handle allocation and check for "ID" and "IDREF" tags up front
1570 yylval
= newObject ();
1572 for ( int i
= 0 ; i
< attributeCount
; i
++) {
1573 if ( attributes
[ i
][ 0 ] == 'I' && attributes
[ i
][ 1 ] == 'D' ) {
1574 // check for idref's, note: we ignore the tag, for
1575 // this to work correctly, all idrefs must be unique
1576 // across the whole serialization
1577 if ( attributes
[ i
][ 2 ] == 'R' && attributes
[ i
][ 3 ] == 'E' &&
1578 attributes
[ i
][ 4 ] == 'F' && ! attributes
[ i
][ 5 ]) {
1579 if ( tagType
!= TAG_EMPTY
) return SYNTAX_ERROR
;
1580 yylval
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1584 if (! attributes
[ i
][ 2 ]) {
1585 yylval
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1587 return SYNTAX_ERROR
;
1594 if (! strcmp ( tag
, "array" )) {
1595 if ( tagType
== TAG_EMPTY
) {
1596 yylval
-> elements
= NULL
;
1599 return ( tagType
== TAG_START
) ? '(' : ')' ;
1603 if (! strcmp ( tag
, "dict" )) {
1604 if ( tagType
== TAG_EMPTY
) {
1605 yylval
-> elements
= NULL
;
1608 return ( tagType
== TAG_START
) ? '{' : '}' ;
1610 if (! strcmp ( tag
, "data" )) {
1613 if ( tagType
== TAG_EMPTY
) {
1614 yylval
-> data
= NULL
;
1618 for ( int i
= 0 ; i
< attributeCount
; i
++) {
1619 if (! strcmp ( attributes
[ i
], "format" ) && ! strcmp ( values
[ i
], "hex" )) {
1624 // CF encoded is the default form
1626 yylval
-> data
= getHexData (& size
);
1628 yylval
-> data
= getCFEncodedData (& size
);
1630 yylval
-> size
= size
;
1631 if (( getTag ( tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "data" )) {
1632 return SYNTAX_ERROR
;
1638 if (! strcmp ( tag
, "false" )) {
1639 if ( tagType
== TAG_EMPTY
) {
1646 if (! strcmp ( tag
, "integer" )) {
1647 yylval
-> size
= 64 ; // default
1648 for ( int i
= 0 ; i
< attributeCount
; i
++) {
1649 if (! strcmp ( attributes
[ i
], "size" )) {
1650 yylval
-> size
= strtoul ( values
[ i
], NULL
, 0 );
1653 if ( tagType
== TAG_EMPTY
) {
1657 yylval
-> number
= getNumber ();
1658 if (( getTag ( tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "integer" )) {
1659 return SYNTAX_ERROR
;
1665 if (! strcmp ( tag
, "key" )) {
1666 if ( tagType
== TAG_EMPTY
) return SYNTAX_ERROR
;
1667 yylval
-> string
= getString ();
1668 if (! yylval
-> string
) {
1669 return SYNTAX_ERROR
;
1671 if (( getTag ( tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1672 || strcmp ( tag
, "key" )) {
1673 return SYNTAX_ERROR
;
1679 if (! strcmp ( tag
, "plist" )) {
1685 if (! strcmp ( tag
, "string" )) {
1686 if ( tagType
== TAG_EMPTY
) {
1687 yylval
-> string
= ( char *) malloc ( 1 );
1688 * yylval
-> string
= 0 ;
1691 yylval
-> string
= getString ();
1692 if (! yylval
-> string
) {
1693 return SYNTAX_ERROR
;
1695 if (( getTag ( tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1696 || strcmp ( tag
, "string" )) {
1697 return SYNTAX_ERROR
;
1701 if (! strcmp ( tag
, "set" )) {
1702 if ( tagType
== TAG_EMPTY
) {
1703 yylval
-> elements
= NULL
;
1706 if ( tagType
== TAG_START
) {
1714 if (! strcmp ( tag
, "true" )) {
1715 if ( tagType
== TAG_EMPTY
) {
1723 // XXX should we ignore invalid tags?
1724 return SYNTAX_ERROR
;
1731 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1732 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1733 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1735 // "java" like allocation, if this code hits a syntax error in the
1736 // the middle of the parsed string we just bail with pointers hanging
1737 // all over place, so this code helps keeps all together
1739 static object_t
* objects
= 0 ;
1740 static object_t
* freeObjects
= 0 ;
1749 freeObjects
= freeObjects
-> next
;
1751 o
= ( object_t
*) malloc ( sizeof ( object_t
));
1752 bzero ( o
, sizeof ( object_t
));
1761 freeObject ( object_t
* o
)
1763 o
-> next
= freeObjects
;
1770 object_t
* t
, * o
= objects
;
1774 printf ( "OSUnserializeXML: releasing object o= %x object= %x \n " , ( int ) o
, ( int ) o
-> object
);
1775 o
-> object
-> release ();
1778 printf ( "OSUnserializeXML: freeing object o= %x data= %x \n " , ( int ) o
, ( int ) o
-> data
);
1782 printf ( "OSUnserializeXML: releasing object o= %x key= %x \n " , ( int ) o
, ( int ) o
-> key
);
1786 printf ( "OSUnserializeXML: freeing object o= %x string= %x \n " , ( int ) o
, ( int ) o
-> string
);
1796 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1797 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1798 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1800 static OSDictionary
* tags
;
1803 rememberObject ( int tag
, OSObject
* o
)
1806 sprintf ( key
, " %u " , tag
);
1808 //printf("remember key %s\n", key);
1810 tags
-> setObject ( key
, o
);
1814 retrieveObject ( int tag
)
1817 sprintf ( key
, " %u " , tag
);
1819 //printf("retrieve key '%s'\n", key);
1821 OSObject
* ref
= tags
-> getObject ( key
);
1824 object_t
* o
= newObject ();
1829 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1830 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1831 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1834 buildOSDictionary ( object_t
* header
)
1839 // get count and reverse order
1840 o
= header
-> elements
;
1841 header
-> elements
= 0 ;
1847 t
-> next
= header
-> elements
;
1848 header
-> elements
= t
;
1851 OSDictionary
* d
= OSDictionary :: withCapacity ( count
);
1853 if ( header
-> idref
>= 0 ) rememberObject ( header
-> idref
, d
);
1855 o
= header
-> elements
;
1857 d
-> setObject ( o
-> key
, o
-> object
);
1858 o
-> object
-> release ();
1872 buildOSArray ( object_t
* header
)
1877 // get count and reverse order
1878 o
= header
-> elements
;
1879 header
-> elements
= 0 ;
1885 t
-> next
= header
-> elements
;
1886 header
-> elements
= t
;
1889 OSArray
* a
= OSArray :: withCapacity ( count
);
1891 if ( header
-> idref
>= 0 ) rememberObject ( header
-> idref
, a
);
1893 o
= header
-> elements
;
1895 a
-> setObject ( o
-> object
);
1896 o
-> object
-> release ();
1908 buildOSSet ( object_t
* o
)
1910 o
= buildOSArray ( o
);
1911 OSArray
* a
= ( OSArray
*) o
-> object
;
1913 OSSet
* s
= OSSet :: withArray ( a
, a
-> getCapacity ());
1915 //write over reference created in array
1916 if ( o
-> idref
>= 0 ) rememberObject ( o
-> idref
, s
);
1924 buildOSString ( object_t
* o
)
1926 OSString
* s
= OSString :: withCString ( o
-> string
);
1928 if ( o
-> idref
>= 0 ) rememberObject ( o
-> idref
, s
);
1938 buildKey ( object_t
* o
)
1940 const OSSymbol
* s
= OSSymbol :: withCString ( o
-> string
);
1950 buildOSData ( object_t
* o
)
1955 d
= OSData :: withBytes ( o
-> data
, o
-> size
);
1958 d
= OSData :: withCapacity ( 0 );
1960 if ( o
-> idref
>= 0 ) rememberObject ( o
-> idref
, d
);
1968 buildOSNumber ( object_t
* o
)
1970 OSNumber
* n
= OSNumber :: withNumber ( o
-> number
, o
-> size
);
1972 if ( o
-> idref
>= 0 ) rememberObject ( o
-> idref
, n
);
1979 buildOSBoolean ( object_t
* o
)
1981 OSBoolean
* b
= OSBoolean :: withBoolean ( o
-> number
!= 0 );
1987 #include <kern/lock.h>
1990 static mutex_t
* lock
= 0 ;
1993 OSUnserializeXML ( const char * buffer
, OSString
** errorString
)
1998 lock
= mutex_alloc ( ETAP_IO_AHA
);
2007 yyerror_message
[ 0 ] = 0 ; //just in case
2008 parseBuffer
= buffer
;
2009 parseBufferIndex
= 0 ;
2010 tags
= OSDictionary :: withCapacity ( 128 );
2011 if ( yyparse () == 0 ) {
2012 object
= parsedObject
;
2013 if ( errorString
) * errorString
= 0 ;
2017 * errorString
= OSString :: withCString ( yyerror_message
);
2033 // DO NOT EDIT OSUnserializeXML.cpp!