]>
git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSUnserializeXML.cpp
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)
147 #define YYFLAG -32768
150 #define YYTRANSLATE(x) ((unsigned)(x) <= 266 ? yytranslate[x] : 33)
152 static const char yytranslate
[] = { 0 ,
153 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
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 , 15 ,
157 16 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
158 2 , 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 17 , 2 , 18 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
163 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
164 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
165 2 , 2 , 13 , 2 , 14 , 2 , 2 , 2 , 2 , 2 ,
166 2 , 2 , 2 , 2 , 2 , 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 , 1 , 3 , 4 , 5 , 6 ,
183 static const short yyprhs
[] = { 0 ,
184 0 , 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 , 17 ,
185 19 , 21 , 24 , 28 , 30 , 32 , 35 , 38 , 40 , 43 ,
186 47 , 49 , 52 , 56 , 58 , 60 , 63 , 65 , 67 , 69 ,
190 static const short yyrhs
[] = { - 1 ,
191 20 , 0 , 12 , 0 , 21 , 0 , 25 , 0 , 26 , 0 ,
192 32 , 0 , 29 , 0 , 31 , 0 , 28 , 0 , 30 , 0 ,
193 13 , 14 , 0 , 13 , 22 , 14 , 0 , 6 , 0 , 23 ,
194 0 , 22 , 23 , 0 , 24 , 20 , 0 , 8 , 0 , 15 ,
195 16 , 0 , 15 , 27 , 16 , 0 , 3 , 0 , 17 , 18 ,
196 0 , 17 , 27 , 18 , 0 , 10 , 0 , 20 , 0 , 27 ,
197 20 , 0 , 4 , 0 , 5 , 0 , 7 , 0 , 9 , 0 ,
204 static const short yyrline
[] = { 0 ,
205 123 , 124 , 129 , 135 , 136 , 137 , 138 , 139 , 140 , 141 ,
206 142 , 155 , 158 , 161 , 164 , 165 , 170 , 178 , 183 , 186 ,
207 189 , 192 , 195 , 198 , 201 , 204 , 211 , 214 , 217 , 220 ,
213 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
215 static const char * const yytname
[] = { "$" , "error" , "$undefined." , "ARRAY" ,
216 "BOOLEAN" , "DATA" , "DICTIONARY" , "IDREF" , "KEY" , "NUMBER" , "SET" , "STRING" , "SYNTAX_ERROR" ,
217 "'{'" , "'}'" , "'('" , "')'" , "'['" , "']'" , "input" , "object" , "dict" , "pairs" , "pair" , "key" ,
218 "array" , "set" , "elements" , "boolean" , "data" , "idref" , "number" , "string" , NULL
222 static const short yyr1
[] = { 0 ,
223 19 , 19 , 19 , 20 , 20 , 20 , 20 , 20 , 20 , 20 ,
224 20 , 21 , 21 , 21 , 22 , 22 , 23 , 24 , 25 , 25 ,
225 25 , 26 , 26 , 26 , 27 , 27 , 28 , 29 , 30 , 31 ,
229 static const short yyr2
[] = { 0 ,
230 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
231 1 , 2 , 3 , 1 , 1 , 2 , 2 , 1 , 2 , 3 ,
232 1 , 2 , 3 , 1 , 1 , 2 , 1 , 1 , 1 , 1 ,
236 static const short yydefact
[] = { 1 ,
237 21 , 27 , 28 , 14 , 29 , 30 , 24 , 31 , 3 , 0 ,
238 0 , 0 , 2 , 4 , 5 , 6 , 10 , 8 , 11 , 9 ,
239 7 , 18 , 12 , 0 , 15 , 0 , 19 , 25 , 0 , 22 ,
240 0 , 13 , 16 , 17 , 20 , 26 , 23 , 0 , 0 , 0
243 static const short yydefgoto
[] = { 38 ,
244 28 , 14 , 24 , 25 , 26 , 15 , 16 , 29 , 17 , 18 ,
248 static const short yypact
[] = { 45 ,
249 - 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 4 ,
250 60 , - 2 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,
251 - 32768 ,- 32768 ,- 32768 , 6 ,- 32768 , 90 ,- 32768 ,- 32768 , 75 ,- 32768 ,
252 29 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 ,- 32768 , 10 , 17 ,- 32768
255 static const short yypgoto
[] = {- 32768 ,
256 0 ,- 32768 ,- 32768 , - 18 ,- 32768 ,- 32768 ,- 32768 , 7 ,- 32768 ,- 32768 ,
264 static const short yytable
[] = { 13 ,
265 1 , 2 , 3 , 4 , 5 , 33 , 6 , 7 , 8 , 39 ,
266 10 , 22 , 11 , 22 , 12 , 30 , 40 , 23 , 31 , 32 ,
267 0 , 0 , 0 , 0 , 0 , 34 , 0 , 0 , 36 , 0 ,
268 36 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 , 8 ,
269 0 , 10 , 0 , 11 , 0 , 12 , 37 , 1 , 2 , 3 ,
270 4 , 5 , 0 , 6 , 7 , 8 , 9 , 10 , 0 , 11 ,
271 0 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
272 8 , 0 , 10 , 0 , 11 , 27 , 12 , 1 , 2 , 3 ,
273 4 , 5 , 0 , 6 , 7 , 8 , 0 , 10 , 0 , 11 ,
274 35 , 12 , 1 , 2 , 3 , 4 , 5 , 0 , 6 , 7 ,
275 8 , 0 , 10 , 0 , 11 , 0 , 12
278 static const short yycheck
[] = { 0 ,
279 3 , 4 , 5 , 6 , 7 , 24 , 9 , 10 , 11 , 0 ,
280 13 , 8 , 15 , 8 , 17 , 18 , 0 , 14 , 12 , 14 ,
281 - 1 , - 1 , - 1 , - 1 , - 1 , 26 , - 1 , - 1 , 29 , - 1 ,
282 31 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 , 11 ,
283 - 1 , 13 , - 1 , 15 , - 1 , 17 , 18 , 3 , 4 , 5 ,
284 6 , 7 , - 1 , 9 , 10 , 11 , 12 , 13 , - 1 , 15 ,
285 - 1 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
286 11 , - 1 , 13 , - 1 , 15 , 16 , 17 , 3 , 4 , 5 ,
287 6 , 7 , - 1 , 9 , 10 , 11 , - 1 , 13 , - 1 , 15 ,
288 16 , 17 , 3 , 4 , 5 , 6 , 7 , - 1 , 9 , 10 ,
289 11 , - 1 , 13 , - 1 , 15 , - 1 , 17
291 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
292 #line 3 "/usr/share/bison.simple"
293 /* This file comes from bison-1.28. */
295 /* Skeleton output parser for bison,
296 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
298 This program is free software; you can redistribute it and/or modify
299 it under the terms of the GNU General Public License as published by
300 the Free Software Foundation; either version 2, or (at your option)
303 This program is distributed in the hope that it will be useful,
304 but WITHOUT ANY WARRANTY; without even the implied warranty of
305 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
306 GNU General Public License for more details.
308 You should have received a copy of the GNU General Public License
309 along with this program; if not, write to the Free Software
310 Foundation, Inc., 59 Temple Place - Suite 330,
311 Boston, MA 02111-1307, USA. */
313 /* As a special exception, when this file is copied by Bison into a
314 Bison output file, you may use that output file without restriction.
315 This special exception was added by the Free Software Foundation
316 in version 1.24 of Bison. */
318 /* This is the parser code that is written into each bison parser
319 when the %semantic_parser declaration is not specified in the grammar.
320 It was written by Richard Stallman by simplifying the hairy parser
321 used when %semantic_parser is specified. */
323 #ifndef YYSTACK_USE_ALLOCA
325 #define YYSTACK_USE_ALLOCA
326 #else /* alloca not defined */
328 #define YYSTACK_USE_ALLOCA
329 #define alloca __builtin_alloca
330 #else /* not GNU C. */
331 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
332 #define YYSTACK_USE_ALLOCA
334 #else /* not sparc */
335 /* We think this test detects Watcom and Microsoft C. */
336 /* This used to test MSDOS, but that is a bad idea
337 since that symbol is in the user namespace. */
338 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
339 #if 0 /* No need for malloc.h, which pollutes the namespace;
340 instead, just don't use alloca. */
343 #else /* not MSDOS, or __TURBOC__ */
345 /* I don't know what this was needed for, but it pollutes the namespace.
346 So I turned it off. rms, 2 May 1997. */
347 /* #include <malloc.h> */
349 #define YYSTACK_USE_ALLOCA
350 #else /* not MSDOS, or __TURBOC__, or _AIX */
352 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
353 and on HPUX 10. Eventually we can turn this on. */
354 #define YYSTACK_USE_ALLOCA
355 #define alloca __builtin_alloca
358 #endif /* not _AIX */
359 #endif /* not MSDOS, or __TURBOC__ */
360 #endif /* not sparc */
361 #endif /* not GNU C */
362 #endif /* alloca not defined */
363 #endif /* YYSTACK_USE_ALLOCA not defined */
365 #ifdef YYSTACK_USE_ALLOCA
366 #define YYSTACK_ALLOC alloca
368 #define YYSTACK_ALLOC malloc
371 /* Note: there must be only one dollar sign in this file.
372 It is replaced by the list of actions, each action
373 as one case of the switch. */
375 #define yyerrok (yyerrstatus = 0)
376 #define yyclearin (yychar = YYEMPTY)
379 #define YYACCEPT goto yyacceptlab
380 #define YYABORT goto yyabortlab
381 #define YYERROR goto yyerrlab1
382 /* Like YYERROR except do call yyerror.
383 This remains here temporarily to ease the
384 transition to the new meaning of YYERROR, for GCC.
385 Once GCC version 2 has supplanted version 1, this can go. */
386 #define YYFAIL goto yyerrlab
387 #define YYRECOVERING() (!!yyerrstatus)
388 #define YYBACKUP(token, value) \
390 if (yychar == YYEMPTY && yylen == 1) \
391 { yychar = (token), yylval = (value); \
392 yychar1 = YYTRANSLATE (yychar); \
397 { yyerror ( "syntax error: cannot back up" ); YYERROR; } \
401 #define YYERRCODE 256
404 #define YYLEX yylex()
410 #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
412 #define YYLEX yylex(&yylval, &yylloc)
414 #else /* not YYLSP_NEEDED */
416 #define YYLEX yylex(&yylval, YYLEX_PARAM)
418 #define YYLEX yylex(&yylval)
420 #endif /* not YYLSP_NEEDED */
423 /* If nonreentrant, generate the variables here */
427 int yychar
; /* the lookahead symbol */
428 YYSTYPE yylval
; /* the semantic value of the */
429 /* lookahead symbol */
432 YYLTYPE yylloc
; /* location data for the lookahead */
436 int yynerrs
; /* number of parse errors so far */
437 #endif /* not YYPURE */
440 int yydebug
; /* nonzero means print parse trace */
441 /* Since this is uninitialized, it does not stop multiple parsers
445 /* YYINITDEPTH indicates the initial size of the parser's stacks */
448 #define YYINITDEPTH 200
451 /* YYMAXDEPTH is the maximum size the stacks can grow to
452 (effective only if the built-in stack extension method is used). */
459 #define YYMAXDEPTH 10000
462 /* Define __yy_memcpy. Note that the size argument
463 should be passed with type unsigned int, because that is what the non-GCC
464 definitions require. With GCC, __builtin_memcpy takes an arg
465 of type size_t, but it can handle unsigned int. */
467 #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
468 #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
469 #else /* not GNU C or C++ */
472 /* This is the most reliable way to avoid incompatibilities
473 in available built-in functions on various systems. */
475 __yy_memcpy ( to
, from
, count
)
480 register char * f
= from
;
481 register char * t
= to
;
482 register int i
= count
;
488 #else /* __cplusplus */
490 /* This is the most reliable way to avoid incompatibilities
491 in available built-in functions on various systems. */
493 __yy_memcpy ( char * to
, char * from
, unsigned int count
)
495 register char * t
= to
;
496 register char * f
= from
;
497 register int i
= count
;
506 #line 217 "/usr/share/bison.simple"
508 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
509 into yyparse. The argument should have type void *.
510 It should actually point to an object.
511 Grammar actions can access the variable by casting it
512 to the proper pointer type. */
516 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
517 #define YYPARSE_PARAM_DECL
518 #else /* not __cplusplus */
519 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
520 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
521 #endif /* not __cplusplus */
522 #else /* not YYPARSE_PARAM */
523 #define YYPARSE_PARAM_ARG
524 #define YYPARSE_PARAM_DECL
525 #endif /* not YYPARSE_PARAM */
527 /* Prevent warning if -Wstrict-prototypes. */
530 int yyparse ( void *);
537 yyparse ( YYPARSE_PARAM_ARG
)
540 register int yystate
;
542 register short * yyssp
;
543 register YYSTYPE
* yyvsp
;
544 int yyerrstatus
; /* number of tokens to shift before error messages enabled */
545 int yychar1
= 0 ; /* lookahead token as an internal (translated) token number */
547 short yyssa
[ YYINITDEPTH
]; /* the state stack */
548 YYSTYPE yyvsa
[ YYINITDEPTH
]; /* the semantic value stack */
550 short * yyss
= yyssa
; /* refer to the stacks thru separate pointers */
551 YYSTYPE
* yyvs
= yyvsa
; /* to allow yyoverflow to reallocate them elsewhere */
554 YYLTYPE yylsa
[ YYINITDEPTH
]; /* the location stack */
555 YYLTYPE
* yyls
= yylsa
;
558 #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
560 #define YYPOPSTACK (yyvsp--, yyssp--)
563 int yystacksize
= YYINITDEPTH
;
564 int yyfree_stacks
= 0 ;
575 YYSTYPE yyval
; /* the variable used to return */
576 /* semantic values from the action */
583 fprintf ( stderr
, "Starting parse \n " );
589 yychar
= YYEMPTY
; /* Cause a token to be read. */
591 /* Initialize stack pointers.
592 Waste one element of value and location stack
593 so that they stay on the same level as the state stack.
594 The wasted elements are never initialized. */
602 /* Push a new state, which is found in yystate . */
603 /* In all cases, when you get here, the value and location stacks
604 have just been pushed. so pushing a state here evens the stacks. */
609 if ( yyssp
>= yyss
+ yystacksize
- 1 )
611 /* Give user a chance to reallocate the stack */
612 /* Use copies of these so that the &'s don't force the real ones into memory. */
613 YYSTYPE
* yyvs1
= yyvs
;
616 YYLTYPE
* yyls1
= yyls
;
619 /* Get the current used size of the three stacks, in elements. */
620 int size
= yyssp
- yyss
+ 1 ;
623 /* Each stack pointer address is followed by the size of
624 the data in use in that stack, in bytes. */
626 /* This used to be a conditional around just the two extra args,
627 but that might be undefined if yyoverflow is a macro. */
628 yyoverflow ( "parser stack overflow" ,
629 & yyss1
, size
* sizeof (* yyssp
),
630 & yyvs1
, size
* sizeof (* yyvsp
),
631 & yyls1
, size
* sizeof (* yylsp
),
634 yyoverflow ( "parser stack overflow" ,
635 & yyss1
, size
* sizeof (* yyssp
),
636 & yyvs1
, size
* sizeof (* yyvsp
),
640 yyss
= yyss1
; yyvs
= yyvs1
;
644 #else /* no yyoverflow */
645 /* Extend the stack our own way. */
646 if ( yystacksize
>= YYMAXDEPTH
)
648 yyerror ( "parser stack overflow" );
660 if ( yystacksize
> YYMAXDEPTH
)
661 yystacksize
= YYMAXDEPTH
;
662 #ifndef YYSTACK_USE_ALLOCA
665 yyss
= ( short *) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyssp
));
666 __yy_memcpy (( char *) yyss
, ( char *) yyss1
,
667 size
* ( unsigned int ) sizeof (* yyssp
));
668 yyvs
= ( YYSTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yyvsp
));
669 __yy_memcpy (( char *) yyvs
, ( char *) yyvs1
,
670 size
* ( unsigned int ) sizeof (* yyvsp
));
672 yyls
= ( YYLTYPE
*) YYSTACK_ALLOC ( yystacksize
* sizeof (* yylsp
));
673 __yy_memcpy (( char *) yyls
, ( char *) yyls1
,
674 size
* ( unsigned int ) sizeof (* yylsp
));
676 #endif /* no yyoverflow */
678 yyssp
= yyss
+ size
- 1 ;
679 yyvsp
= yyvs
+ size
- 1 ;
681 yylsp
= yyls
+ size
- 1 ;
686 fprintf ( stderr
, "Stack size increased to %d \n " , yystacksize
);
689 if ( yyssp
>= yyss
+ yystacksize
- 1 )
695 fprintf ( stderr
, "Entering state %d \n " , yystate
);
701 /* Do appropriate processing given the current state. */
702 /* Read a lookahead token if we need one and don't already have one. */
705 /* First try to decide what to do without reference to lookahead token. */
707 yyn
= yypact
[ yystate
];
711 /* Not known => get a lookahead token if don't already have one. */
713 /* yychar is either YYEMPTY or YYEOF
714 or a valid token in external form. */
716 if ( yychar
== YYEMPTY
)
720 fprintf ( stderr
, "Reading a token: " );
725 /* Convert token to internal form (in yychar1) for indexing tables with */
727 if ( yychar
<= 0 ) /* This means end of input. */
730 yychar
= YYEOF
; /* Don't call YYLEX any more */
734 fprintf ( stderr
, "Now at end of input. \n " );
739 yychar1
= YYTRANSLATE ( yychar
);
744 fprintf ( stderr
, "Next token is %d ( %s " , yychar
, yytname
[ yychar1
]);
745 /* Give the individual parser a way to print the precise meaning
746 of a token, for further debugging info. */
748 YYPRINT ( stderr
, yychar
, yylval
);
750 fprintf ( stderr
, ") \n " );
756 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != yychar1
)
761 /* yyn is what to do for this token type in this state.
762 Negative => reduce, -yyn is rule number.
763 Positive => shift, yyn is new state.
764 New state is final state => don't bother to shift,
766 0, or most negative number => error. */
781 /* Shift the lookahead token. */
785 fprintf ( stderr
, "Shifting token %d ( %s ), " , yychar
, yytname
[ yychar1
]);
788 /* Discard the token being shifted unless it is eof. */
797 /* count tokens shifted since error; after three, turn off error status. */
798 if ( yyerrstatus
) yyerrstatus
--;
803 /* Do the default action for the current state. */
806 yyn
= yydefact
[ yystate
];
810 /* Do a reduction. yyn is the number of a rule to reduce with. */
814 yyval
= yyvsp
[ 1 - yylen
]; /* implement default value of the action */
821 fprintf ( stderr
, "Reducing via rule %d (line %d ), " ,
824 /* Print the symbols being reduced, and their result. */
825 for ( i
= yyprhs
[ yyn
]; yyrhs
[ i
] > 0 ; i
++)
826 fprintf ( stderr
, " %s " , yytname
[ yyrhs
[ i
]]);
827 fprintf ( stderr
, " -> %s \n " , yytname
[ yyr1
[ yyn
]]);
835 #line 123 "OSUnserializeXML.y"
836 { parsedObject
= ( OSObject
*) NULL
; YYACCEPT
; ;
839 #line 124 "OSUnserializeXML.y"
840 { parsedObject
= yyvsp
[ 0 ]-> object
;
841 yyvsp
[ 0 ]-> object
= 0 ;
842 freeObject ( yyvsp
[ 0 ]);
847 #line 129 "OSUnserializeXML.y"
849 yyerror ( "syntax error" );
854 #line 135 "OSUnserializeXML.y"
855 { yyval
= buildOSDictionary ( yyvsp
[ 0 ]); ;
858 #line 136 "OSUnserializeXML.y"
859 { yyval
= buildOSArray ( yyvsp
[ 0 ]); ;
862 #line 137 "OSUnserializeXML.y"
863 { yyval
= buildOSSet ( yyvsp
[ 0 ]); ;
866 #line 138 "OSUnserializeXML.y"
867 { yyval
= buildOSString ( yyvsp
[ 0 ]); ;
870 #line 139 "OSUnserializeXML.y"
871 { yyval
= buildOSData ( yyvsp
[ 0 ]); ;
874 #line 140 "OSUnserializeXML.y"
875 { yyval
= buildOSNumber ( yyvsp
[ 0 ]); ;
878 #line 141 "OSUnserializeXML.y"
879 { yyval
= buildOSBoolean ( yyvsp
[ 0 ]); ;
882 #line 142 "OSUnserializeXML.y"
883 { yyval
= retrieveObject ( yyvsp
[ 0 ]-> idref
);
885 yyval
-> object
-> retain ();
887 yyerror ( "forward reference detected" );
890 freeObject ( yyvsp
[ 0 ]);
894 #line 155 "OSUnserializeXML.y"
896 yyval
-> elements
= NULL
;
900 #line 158 "OSUnserializeXML.y"
902 yyval
-> elements
= yyvsp
[- 1 ];
906 #line 165 "OSUnserializeXML.y"
908 yyval
-> next
= yyvsp
[- 1 ];
912 #line 170 "OSUnserializeXML.y"
915 yyval
-> object
= yyvsp
[ 0 ]-> object
;
916 yyvsp
[ 0 ]-> object
= 0 ;
917 freeObject ( yyvsp
[ 0 ]);
921 #line 178 "OSUnserializeXML.y"
922 { yyval
= buildKey ( yyvsp
[ 0 ]); ;
925 #line 183 "OSUnserializeXML.y"
927 yyval
-> elements
= NULL
;
931 #line 186 "OSUnserializeXML.y"
933 yyval
-> elements
= yyvsp
[- 1 ];
937 #line 192 "OSUnserializeXML.y"
939 yyval
-> elements
= NULL
;
943 #line 195 "OSUnserializeXML.y"
945 yyval
-> elements
= yyvsp
[- 1 ];
949 #line 201 "OSUnserializeXML.y"
955 #line 204 "OSUnserializeXML.y"
957 yyval
-> next
= yyvsp
[- 1 ];
961 /* the action file gets copied in in place of this dollarsign */
962 #line 543 "/usr/share/bison.simple"
973 short * ssp1
= yyss
- 1 ;
974 fprintf ( stderr
, "state stack now" );
975 while ( ssp1
!= yyssp
)
976 fprintf ( stderr
, " %d " , *++ ssp1
);
977 fprintf ( stderr
, " \n " );
987 yylsp
-> first_line
= yylloc
. first_line
;
988 yylsp
-> first_column
= yylloc
. first_column
;
989 yylsp
-> last_line
= ( yylsp
- 1 )-> last_line
;
990 yylsp
-> last_column
= ( yylsp
- 1 )-> last_column
;
995 yylsp
-> last_line
= ( yylsp
+ yylen
- 1 )-> last_line
;
996 yylsp
-> last_column
= ( yylsp
+ yylen
- 1 )-> last_column
;
1000 /* Now "shift" the result of the reduction.
1001 Determine what state that goes to,
1002 based on the state we popped back to
1003 and the rule number reduced by. */
1007 yystate
= yypgoto
[ yyn
- YYNTBASE
] + * yyssp
;
1008 if ( yystate
>= 0 && yystate
<= YYLAST
&& yycheck
[ yystate
] == * yyssp
)
1009 yystate
= yytable
[ yystate
];
1011 yystate
= yydefgoto
[ yyn
- YYNTBASE
];
1015 yyerrlab
: /* here on detecting error */
1018 /* If not already recovering from an error, report this error. */
1022 #ifdef YYERROR_VERBOSE
1023 yyn
= yypact
[ yystate
];
1025 if ( yyn
> YYFLAG
&& yyn
< YYLAST
)
1032 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
1033 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1034 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1035 if ( yycheck
[ x
+ yyn
] == x
)
1036 size
+= strlen ( yytname
[ x
]) + 15 , count
++;
1037 msg
= ( char *) malloc ( size
+ 15 );
1040 strcpy ( msg
, "parse error" );
1045 for ( x
= ( yyn
< 0 ? - yyn
: 0 );
1046 x
< ( sizeof ( yytname
) / sizeof ( char *)); x
++)
1047 if ( yycheck
[ x
+ yyn
] == x
)
1049 strcat ( msg
, count
== 0 ? ", expecting `" : " or `" );
1050 strcat ( msg
, yytname
[ x
]);
1059 yyerror ( "parse error; also virtual memory exceeded" );
1062 #endif /* YYERROR_VERBOSE */
1063 yyerror ( "parse error" );
1067 yyerrlab1
: /* here on error raised explicitly by an action */
1069 if ( yyerrstatus
== 3 )
1071 /* if just tried and failed to reuse lookahead token after an error, discard it. */
1073 /* return failure if at end of input */
1074 if ( yychar
== YYEOF
)
1079 fprintf ( stderr
, "Discarding token %d ( %s ). \n " , yychar
, yytname
[ yychar1
]);
1085 /* Else will try to reuse lookahead token
1086 after shifting the error token. */
1088 yyerrstatus
= 3 ; /* Each real token shifted decrements this */
1092 yyerrdefault
: /* current state does not do anything special for the error token. */
1095 /* This is wrong; only states that explicitly want error tokens
1096 should shift them. */
1097 yyn
= yydefact
[ yystate
]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1098 if ( yyn
) goto yydefault
;
1101 yyerrpop
: /* pop the current state because it cannot handle the error token */
1103 if ( yyssp
== yyss
) YYABORT
;
1113 short * ssp1
= yyss
- 1 ;
1114 fprintf ( stderr
, "Error: state stack now" );
1115 while ( ssp1
!= yyssp
)
1116 fprintf ( stderr
, " %d " , *++ ssp1
);
1117 fprintf ( stderr
, " \n " );
1123 yyn
= yypact
[ yystate
];
1128 if ( yyn
< 0 || yyn
> YYLAST
|| yycheck
[ yyn
] != YYTERROR
)
1147 fprintf ( stderr
, "Shifting error token, " );
1159 /* YYACCEPT comes here. */
1171 /* YYABORT comes here. */
1182 #line 226 "OSUnserializeXML.y"
1185 static int lineNumber
= 0 ;
1186 static const char * parseBuffer
;
1187 static int parseBufferIndex
;
1189 #define currentChar() (parseBuffer[parseBufferIndex])
1190 #define nextChar() (parseBuffer[++parseBufferIndex])
1191 #define prevChar() (parseBuffer[parseBufferIndex - 1])
1193 #define isSpace(c) ((c) == ' ' || (c) == ' \t ' )
1194 #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z' ) || ((c) >= 'a' && (c) <= 'z' ))
1195 #define isDigit(c) ((c) >= '0' && (c) <= '9' )
1196 #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f' )
1197 #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
1198 #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-' ))
1200 static char yyerror_message
[ 128 ];
1203 yyerror ( char * s
) /* Called by yyparse on error */
1205 sprintf ( yyerror_message
, "OSUnserializeXML: %s near line %d \n " , s
, lineNumber
);
1209 #define TAG_MAX_LENGTH 32
1210 #define TAG_MAX_ATTRIBUTES 32
1215 #define TAG_COMMENT 4
1218 getTag ( char tag
[ TAG_MAX_LENGTH
],
1219 int * attributeCount
,
1220 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
],
1221 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
] )
1224 int c
= currentChar ();
1225 int tagType
= TAG_START
;
1227 * attributeCount
= 0 ;
1229 if ( c
!= '<' ) return TAG_BAD
;
1230 c
= nextChar (); // skip '<'
1232 if ( c
== '?' || c
== '!' ) {
1233 while (( c
= nextChar ()) != 0 ) {
1234 if ( c
== ' \n ' ) lineNumber
++;
1243 c
= nextChar (); // skip '/'
1246 if (! isAlpha ( c
)) return TAG_BAD
;
1248 /* find end of tag while copying it */
1249 while ( isAlphaNumeric ( c
)) {
1252 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1257 //printf("tag %s, type %d\n", tag, tagType);
1259 // look for attributes of the form attribute = "value" ...
1260 while (( c
!= '>' ) && ( c
!= '/' )) {
1261 while ( isSpace ( c
)) c
= nextChar ();
1264 while ( isAlphaNumeric ( c
)) {
1265 attributes
[* attributeCount
][ length
++] = c
;
1266 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1269 attributes
[* attributeCount
][ length
] = 0 ;
1271 while ( isSpace ( c
)) c
= nextChar ();
1273 if ( c
!= '=' ) return TAG_BAD
;
1276 while ( isSpace ( c
)) c
= nextChar ();
1278 if ( c
!= '"' ) return TAG_BAD
;
1282 values
[* attributeCount
][ length
++] = c
;
1283 if ( length
>= ( TAG_MAX_LENGTH
- 1 )) return TAG_BAD
;
1286 values
[* attributeCount
][ length
] = 0 ;
1288 c
= nextChar (); // skip closing quote
1290 //printf(" attribute '%s' = '%s', nextchar = '%c'\n", attributes[*attributeCount], values[*attributeCount], c);
1292 (* attributeCount
)++;
1293 if (* attributeCount
>= TAG_MAX_ATTRIBUTES
) return TAG_BAD
;
1297 c
= nextChar (); // skip '/'
1298 tagType
= TAG_EMPTY
;
1300 if ( c
!= '>' ) return TAG_BAD
;
1301 c
= nextChar (); // skip '>'
1309 int c
= currentChar ();
1311 int start
, length
, i
, j
;;
1314 start
= parseBufferIndex
;
1315 /* find end of string */
1318 if ( c
== ' \n ' ) lineNumber
++;
1325 if ( c
!= '<' ) return 0 ;
1327 length
= parseBufferIndex
- start
;
1329 /* copy to null terminated buffer */
1330 tempString
= ( char *) malloc ( length
+ 1 );
1331 if ( tempString
== 0 ) {
1332 printf ( "OSUnserializeXML: can't alloc temp memory \n " );
1336 // copy out string in tempString
1337 // "&" -> '&', "<" -> '<', ">" -> '>'
1340 while ( i
< length
) {
1341 c
= parseBuffer
[ start
+ i
++];
1343 tempString
[ j
++] = c
;
1345 if (( i
+ 3 ) > length
) goto error
;
1346 c
= parseBuffer
[ start
+ i
++];
1348 if ( parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1349 if ( parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1350 tempString
[ j
++] = '<' ;
1354 if ( parseBuffer
[ start
+ i
++] != 't' ) goto error
;
1355 if ( parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1356 tempString
[ j
++] = '>' ;
1359 if (( i
+ 3 ) > length
) goto error
;
1361 if ( parseBuffer
[ start
+ i
++] != 'm' ) goto error
;
1362 if ( parseBuffer
[ start
+ i
++] != 'p' ) goto error
;
1363 if ( parseBuffer
[ start
+ i
++] != ';' ) goto error
;
1364 tempString
[ j
++] = '&' ;
1372 //printf("string %s\n", tempString);
1377 if ( tempString
) free ( tempString
);
1384 unsigned long long n
= 0 ;
1386 int c
= currentChar ();
1388 if (! isDigit ( c
)) return 0 ;
1399 n
= ( n
* base
+ c
- '0' );
1403 while ( isHexDigit ( c
)) {
1405 n
= ( n
* base
+ c
- '0' );
1407 n
= ( n
* base
+ 0xa + c
- 'a' );
1412 //printf("number 0x%x\n", (unsigned long)n);
1416 // taken from CFXMLParsing/CFPropertyList.c
1418 static const signed char __CFPLDataDecodeTable
[ 128 ] = {
1419 /* 000 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1420 /* 010 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1421 /* 020 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1422 /* 030 */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1423 /* ' ' */ - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1424 /* '(' */ - 1 , - 1 , - 1 , 62 , - 1 , - 1 , - 1 , 63 ,
1425 /* '0' */ 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 ,
1426 /* '8' */ 60 , 61 , - 1 , - 1 , - 1 , 0 , - 1 , - 1 ,
1427 /* '@' */ - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 ,
1428 /* 'H' */ 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ,
1429 /* 'P' */ 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 ,
1430 /* 'X' */ 23 , 24 , 25 , - 1 , - 1 , - 1 , - 1 , - 1 ,
1431 /* '`' */ - 1 , 26 , 27 , 28 , 29 , 30 , 31 , 32 ,
1432 /* 'h' */ 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 ,
1433 /* 'p' */ 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 ,
1434 /* 'x' */ 49 , 50 , 51 , - 1 , - 1 , - 1 , - 1 , - 1
1437 #define OSDATA_ALLOC_SIZE 4096
1440 getCFEncodedData ( unsigned int * size
)
1442 int numeq
= 0 , acc
= 0 , cntr
= 0 ;
1443 int tmpbufpos
= 0 , tmpbuflen
= 0 ;
1444 unsigned char * tmpbuf
= ( unsigned char *) malloc ( OSDATA_ALLOC_SIZE
);
1446 int c
= currentChar ();
1455 if ( c
== '=' ) numeq
++; else numeq
= 0 ;
1456 if ( c
== ' \n ' ) lineNumber
++;
1457 if ( __CFPLDataDecodeTable
[ c
] < 0 ) {
1463 acc
+= __CFPLDataDecodeTable
[ c
];
1464 if ( 0 == ( cntr
& 0x3 )) {
1465 if ( tmpbuflen
<= tmpbufpos
+ 2 ) {
1466 tmpbuflen
+= OSDATA_ALLOC_SIZE
;
1467 tmpbuf
= ( unsigned char *) realloc ( tmpbuf
, tmpbuflen
);
1469 tmpbuf
[ tmpbufpos
++] = ( acc
>> 16 ) & 0xff ;
1471 tmpbuf
[ tmpbufpos
++] = ( acc
>> 8 ) & 0xff ;
1473 tmpbuf
[ tmpbufpos
++] = acc
& 0xff ;
1482 getHexData ( unsigned int * size
)
1485 unsigned char * d
, * start
, * lastStart
;
1487 start
= lastStart
= d
= ( unsigned char *) malloc ( OSDATA_ALLOC_SIZE
);
1492 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1501 * d
= ( c
- '0' ) << 4 ;
1502 } else if ( isAlphaDigit ( c
)) {
1503 * d
= ( 0xa + ( c
- 'a' )) << 4 ;
1512 } else if ( isAlphaDigit ( c
)) {
1513 * d
|= 0xa + ( c
- 'a' );
1519 if (( d
- lastStart
) >= OSDATA_ALLOC_SIZE
) {
1520 int oldsize
= d
- start
;
1521 start
= ( unsigned char *) realloc ( start
, oldsize
+ OSDATA_ALLOC_SIZE
);
1522 d
= lastStart
= start
+ oldsize
;
1542 char tag
[ TAG_MAX_LENGTH
];
1544 char attributes
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1545 char values
[ TAG_MAX_ATTRIBUTES
][ TAG_MAX_LENGTH
];
1547 if ( parseBufferIndex
== 0 ) lineNumber
= 1 ;
1552 /* skip white space */
1553 if ( isSpace ( c
)) while (( c
= nextChar ()) != 0 && isSpace ( c
)) {};
1555 /* keep track of line number, don't return \n's */
1564 tagType
= getTag ( tag
, & attributeCount
, attributes
, values
);
1565 if ( tagType
== TAG_BAD
) return SYNTAX_ERROR
;
1566 if ( tagType
== TAG_COMMENT
) goto top
;
1568 // handle allocation and check for "ID" and "IDREF" tags up front
1569 yylval
= newObject ();
1571 for ( int i
= 0 ; i
< attributeCount
; i
++) {
1572 if ( attributes
[ i
][ 0 ] == 'I' && attributes
[ i
][ 1 ] == 'D' ) {
1573 // check for idref's, note: we ignore the tag, for
1574 // this to work correctly, all idrefs must be unique
1575 // across the whole serialization
1576 if ( attributes
[ i
][ 2 ] == 'R' && attributes
[ i
][ 3 ] == 'E' &&
1577 attributes
[ i
][ 4 ] == 'F' && ! attributes
[ i
][ 5 ]) {
1578 if ( tagType
!= TAG_EMPTY
) return SYNTAX_ERROR
;
1579 yylval
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1583 if (! attributes
[ i
][ 2 ]) {
1584 yylval
-> idref
= strtol ( values
[ i
], NULL
, 0 );
1586 return SYNTAX_ERROR
;
1593 if (! strcmp ( tag
, "array" )) {
1594 if ( tagType
== TAG_EMPTY
) {
1595 yylval
-> elements
= NULL
;
1598 return ( tagType
== TAG_START
) ? '(' : ')' ;
1602 if (! strcmp ( tag
, "dict" )) {
1603 if ( tagType
== TAG_EMPTY
) {
1604 yylval
-> elements
= NULL
;
1607 return ( tagType
== TAG_START
) ? '{' : '}' ;
1609 if (! strcmp ( tag
, "data" )) {
1612 if ( tagType
== TAG_EMPTY
) {
1613 yylval
-> data
= NULL
;
1617 for ( int i
= 0 ; i
< attributeCount
; i
++) {
1618 if (! strcmp ( attributes
[ i
], "format" ) && ! strcmp ( values
[ i
], "hex" )) {
1623 // CF encoded is the default form
1625 yylval
-> data
= getHexData (& size
);
1627 yylval
-> data
= getCFEncodedData (& size
);
1629 yylval
-> size
= size
;
1630 if (( getTag ( tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "data" )) {
1631 return SYNTAX_ERROR
;
1637 if (! strcmp ( tag
, "false" )) {
1638 if ( tagType
== TAG_EMPTY
) {
1645 if (! strcmp ( tag
, "integer" )) {
1646 yylval
-> size
= 64 ; // default
1647 for ( int i
= 0 ; i
< attributeCount
; i
++) {
1648 if (! strcmp ( attributes
[ i
], "size" )) {
1649 yylval
-> size
= strtoul ( values
[ i
], NULL
, 0 );
1652 if ( tagType
== TAG_EMPTY
) {
1656 yylval
-> number
= getNumber ();
1657 if (( getTag ( tag
, & attributeCount
, attributes
, values
) != TAG_END
) || strcmp ( tag
, "integer" )) {
1658 return SYNTAX_ERROR
;
1664 if (! strcmp ( tag
, "key" )) {
1665 if ( tagType
== TAG_EMPTY
) return SYNTAX_ERROR
;
1666 yylval
-> string
= getString ();
1667 if (! yylval
-> string
) {
1668 return SYNTAX_ERROR
;
1670 if (( getTag ( tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1671 || strcmp ( tag
, "key" )) {
1672 return SYNTAX_ERROR
;
1678 if (! strcmp ( tag
, "plist" )) {
1684 if (! strcmp ( tag
, "string" )) {
1685 if ( tagType
== TAG_EMPTY
) {
1686 yylval
-> string
= ( char *) malloc ( 1 );
1687 * yylval
-> string
= 0 ;
1690 yylval
-> string
= getString ();
1691 if (! yylval
-> string
) {
1692 return SYNTAX_ERROR
;
1694 if (( getTag ( tag
, & attributeCount
, attributes
, values
) != TAG_END
)
1695 || strcmp ( tag
, "string" )) {
1696 return SYNTAX_ERROR
;
1700 if (! strcmp ( tag
, "set" )) {
1701 if ( tagType
== TAG_EMPTY
) {
1702 yylval
-> elements
= NULL
;
1705 if ( tagType
== TAG_START
) {
1713 if (! strcmp ( tag
, "true" )) {
1714 if ( tagType
== TAG_EMPTY
) {
1722 // XXX should we ignore invalid tags?
1723 return SYNTAX_ERROR
;
1730 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1731 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1732 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1734 // "java" like allocation, if this code hits a syntax error in the
1735 // the middle of the parsed string we just bail with pointers hanging
1736 // all over place, so this code helps keeps all together
1738 static object_t
* objects
= 0 ;
1739 static object_t
* freeObjects
= 0 ;
1748 freeObjects
= freeObjects
-> next
;
1750 o
= ( object_t
*) malloc ( sizeof ( object_t
));
1751 bzero ( o
, sizeof ( object_t
));
1760 freeObject ( object_t
* o
)
1762 o
-> next
= freeObjects
;
1769 object_t
* t
, * o
= objects
;
1773 printf ( "OSUnserializeXML: releasing object o= %x object= %x \n " , ( int ) o
, ( int ) o
-> object
);
1774 o
-> object
-> release ();
1777 printf ( "OSUnserializeXML: freeing object o= %x data= %x \n " , ( int ) o
, ( int ) o
-> data
);
1781 printf ( "OSUnserializeXML: releasing object o= %x key= %x \n " , ( int ) o
, ( int ) o
-> key
);
1785 printf ( "OSUnserializeXML: freeing object o= %x string= %x \n " , ( int ) o
, ( int ) o
-> string
);
1795 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1796 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1797 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1799 static OSDictionary
* tags
;
1802 rememberObject ( int tag
, OSObject
* o
)
1805 sprintf ( key
, " %u " , tag
);
1807 //printf("remember key %s\n", key);
1809 tags
-> setObject ( key
, o
);
1813 retrieveObject ( int tag
)
1816 sprintf ( key
, " %u " , tag
);
1818 //printf("retrieve key '%s'\n", key);
1820 OSObject
* ref
= tags
-> getObject ( key
);
1823 object_t
* o
= newObject ();
1828 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1829 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1830 // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1833 buildOSDictionary ( object_t
* header
)
1838 // get count and reverse order
1839 o
= header
-> elements
;
1840 header
-> elements
= 0 ;
1846 t
-> next
= header
-> elements
;
1847 header
-> elements
= t
;
1850 OSDictionary
* d
= OSDictionary :: withCapacity ( count
);
1852 if ( header
-> idref
>= 0 ) rememberObject ( header
-> idref
, d
);
1854 o
= header
-> elements
;
1856 d
-> setObject ( o
-> key
, o
-> object
);
1857 o
-> object
-> release ();
1871 buildOSArray ( object_t
* header
)
1876 // get count and reverse order
1877 o
= header
-> elements
;
1878 header
-> elements
= 0 ;
1884 t
-> next
= header
-> elements
;
1885 header
-> elements
= t
;
1888 OSArray
* a
= OSArray :: withCapacity ( count
);
1890 if ( header
-> idref
>= 0 ) rememberObject ( header
-> idref
, a
);
1892 o
= header
-> elements
;
1894 a
-> setObject ( o
-> object
);
1895 o
-> object
-> release ();
1907 buildOSSet ( object_t
* o
)
1909 o
= buildOSArray ( o
);
1910 OSArray
* a
= ( OSArray
*) o
-> object
;
1912 OSSet
* s
= OSSet :: withArray ( a
, a
-> getCapacity ());
1914 //write over reference created in array
1915 if ( o
-> idref
>= 0 ) rememberObject ( o
-> idref
, s
);
1923 buildOSString ( object_t
* o
)
1925 OSString
* s
= OSString :: withCString ( o
-> string
);
1927 if ( o
-> idref
>= 0 ) rememberObject ( o
-> idref
, s
);
1937 buildKey ( object_t
* o
)
1939 const OSSymbol
* s
= OSSymbol :: withCString ( o
-> string
);
1949 buildOSData ( object_t
* o
)
1954 d
= OSData :: withBytes ( o
-> data
, o
-> size
);
1957 d
= OSData :: withCapacity ( 0 );
1959 if ( o
-> idref
>= 0 ) rememberObject ( o
-> idref
, d
);
1967 buildOSNumber ( object_t
* o
)
1969 OSNumber
* n
= OSNumber :: withNumber ( o
-> number
, o
-> size
);
1971 if ( o
-> idref
>= 0 ) rememberObject ( o
-> idref
, n
);
1978 buildOSBoolean ( object_t
* o
)
1980 OSBoolean
* b
= OSBoolean :: withBoolean ( o
-> number
!= 0 );
1986 #include <kern/lock.h>
1989 static mutex_t
* lock
= 0 ;
1992 OSUnserializeXML ( const char * buffer
, OSString
** errorString
)
1997 lock
= mutex_alloc ( ETAP_IO_AHA
);
2006 yyerror_message
[ 0 ] = 0 ; //just in case
2007 parseBuffer
= buffer
;
2008 parseBufferIndex
= 0 ;
2009 tags
= OSDictionary :: withCapacity ( 128 );
2010 if ( yyparse () == 0 ) {
2011 object
= parsedObject
;
2012 if ( errorString
) * errorString
= 0 ;
2016 * errorString
= OSString :: withCString ( yyerror_message
);
2032 // DO NOT EDIT OSUnserializeXML.cpp!