|
|
1.1 root 1:
2: /* A Bison parser, made from OSUnserialize.y
3: by GNU Bison version 1.28 */
4:
5: #define YYBISON 1 /* Identify Bison output. */
6:
7: #define yyparse OSUnserializeparse
8: #define yylex OSUnserializelex
9: #define yyerror OSUnserializeerror
10: #define yylval OSUnserializelval
11: #define yychar OSUnserializechar
12: #define yydebug OSUnserializedebug
13: #define yynerrs OSUnserializenerrs
14: #define NUMBER 257
15: #define STRING 258
16: #define DATA 259
17: #define BOOLEAN 260
18: #define SYNTAX_ERROR 261
19:
20: #line 53 "OSUnserialize.y"
21:
22: #include <libkern/c++/OSMetaClass.h>
23: #include <libkern/c++/OSContainers.h>
24: #include <libkern/c++/OSLib.h>
25:
26: typedef struct object {
27: struct object *next;
28: struct object *prev;
29: void *object;
30: int size; // for data
31: union {
32: void *key; // for dictionary
33: long long offset; // for offset
34: } u;
35:
36: } object_t;
37:
38: static int yyparse();
39: static int yyerror(char *s);
40: static int yylex();
41:
42: static object_t * newObject();
43: static void freeObject(object_t *o);
44:
45: static OSObject *buildOSDictionary(object_t *);
46: static OSObject *buildOSArray(object_t *);
47: static OSObject *buildOSSet(object_t *);
48: static OSObject *buildOSString(object_t *);
49: static OSObject *buildOSData(object_t *);
50: static OSObject *buildOSOffset(object_t *);
51: static OSObject *buildOSBoolean(object_t *o);
52:
53: static void rememberObject(int, object_t *);
54: static OSObject *retrieveObject(int);
55:
56: // temp variable to use during parsing
57: static object_t *o;
58:
59: // resultant object of parsed text
60: static OSObject *parsedObject;
61:
62: #define YYSTYPE object_t *
63:
64: extern "C" {
65: extern void *kern_os_malloc(size_t size);
66: extern void *kern_os_realloc(void * addr, size_t size);
67: extern void kern_os_free(void * addr);
68: } /* extern "C" */
69:
70: #define malloc(s) kern_os_malloc(s)
71: #define realloc(a, s) kern_os_realloc(a, s)
72: #define free(a) kern_os_free(a)
73:
74: #ifndef YYSTYPE
75: #define YYSTYPE int
76: #endif
77: #include <stddef.h>
78:
79: #ifndef __cplusplus
80: #ifndef __STDC__
81: #define const
82: #endif
83: #endif
84:
85:
86:
87: #define YYFINAL 43
88: #define YYFLAG -32768
89: #define YYNTBASE 19
90:
91: #define YYTRANSLATE(x) ((unsigned)(x) <= 261 ? yytranslate[x] : 31)
92:
93: static const char yytranslate[] = { 0,
94: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
95: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
96: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
97: 2, 2, 2, 2, 2, 2, 2, 2, 2, 13,
98: 14, 2, 2, 17, 2, 2, 2, 2, 2, 2,
99: 2, 2, 2, 2, 2, 2, 2, 18, 12, 2,
100: 11, 2, 2, 8, 2, 2, 2, 2, 2, 2,
101: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
102: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
103: 15, 2, 16, 2, 2, 2, 2, 2, 2, 2,
104: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
105: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
106: 2, 2, 9, 2, 10, 2, 2, 2, 2, 2,
107: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
108: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
109: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
110: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
111: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
112: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
113: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
114: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
115: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
116: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
117: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
118: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
119: 2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
120: 7
121: };
122:
123: #if YYDEBUG != 0
124: static const short yyprhs[] = { 0,
125: 0, 1, 3, 5, 7, 9, 11, 13, 15, 17,
126: 19, 22, 26, 29, 33, 35, 38, 43, 46, 50,
127: 53, 57, 59, 63, 67, 69, 71
128: };
129:
130: static const short yyrhs[] = { -1,
131: 20, 0, 7, 0, 21, 0, 24, 0, 25, 0,
132: 29, 0, 28, 0, 27, 0, 30, 0, 8, 3,
133: 0, 20, 8, 3, 0, 9, 10, 0, 9, 22,
134: 10, 0, 23, 0, 22, 23, 0, 20, 11, 20,
135: 12, 0, 13, 14, 0, 13, 26, 14, 0, 15,
136: 16, 0, 15, 26, 16, 0, 20, 0, 26, 17,
137: 20, 0, 3, 18, 3, 0, 5, 0, 4, 0,
138: 6, 0
139: };
140:
141: #endif
142:
143: #if YYDEBUG != 0
144: static const short yyrline[] = { 0,
145: 115, 116, 117, 120, 121, 122, 123, 124, 125, 126,
146: 127, 136, 144, 145, 148, 149, 152, 162, 163, 166,
147: 167, 170, 175, 186, 194, 199, 204
148: };
149: #endif
150:
151:
152: #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
153:
154: static const char * const yytname[] = { "$","error","$undefined.","NUMBER",
155: "STRING","DATA","BOOLEAN","SYNTAX_ERROR","'@'","'{'","'}'","'='","';'","'('",
156: "')'","'['","']'","','","':'","input","object","dict","pairs","pair","array",
157: "set","elements","offset","data","string","boolean", NULL
158: };
159: #endif
160:
161: static const short yyr1[] = { 0,
162: 19, 19, 19, 20, 20, 20, 20, 20, 20, 20,
163: 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
164: 25, 26, 26, 27, 28, 29, 30
165: };
166:
167: static const short yyr2[] = { 0,
168: 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
169: 2, 3, 2, 3, 1, 2, 4, 2, 3, 2,
170: 3, 1, 3, 3, 1, 1, 1
171: };
172:
173: static const short yydefact[] = { 1,
174: 0, 26, 25, 27, 3, 0, 0, 0, 0, 2,
175: 4, 5, 6, 9, 8, 7, 10, 0, 11, 13,
176: 0, 0, 15, 18, 22, 0, 20, 0, 0, 24,
177: 0, 14, 16, 19, 0, 21, 12, 0, 23, 17,
178: 0, 0, 0
179: };
180:
181: static const short yydefgoto[] = { 41,
182: 21, 11, 22, 23, 12, 13, 26, 14, 15, 16,
183: 17
184: };
185:
186: static const short yypact[] = { 12,
187: -13,-32768,-32768,-32768,-32768, 9, 33, 46, -2, 2,
188: -32768,-32768,-32768,-32768,-32768,-32768,-32768, 25,-32768,-32768,
189: 21, 59,-32768,-32768, 2, 16,-32768, 7, 31,-32768,
190: 72,-32768,-32768,-32768, 72,-32768,-32768, 14, 2,-32768,
191: 40, 44,-32768
192: };
193:
194: static const short yypgoto[] = {-32768,
195: 0,-32768,-32768, 23,-32768,-32768, 38,-32768,-32768,-32768,
196: -32768
197: };
198:
199:
200: #define YYLAST 87
201:
202:
203: static const short yytable[] = { 10,
204: 1, 2, 3, 4, 18, 6, 7, 25, 25, 29,
205: 8, 19, 9, 27, 1, 2, 3, 4, 5, 6,
206: 7, 29, 36, 35, 8, 40, 9, 30, 29, 34,
207: 38, 31, 35, 37, 39, 1, 2, 3, 4, 42,
208: 6, 7, 20, 43, 33, 8, 28, 9, 1, 2,
209: 3, 4, 0, 6, 7, 0, 0, 0, 8, 24,
210: 9, 1, 2, 3, 4, 0, 6, 7, 32, 0,
211: 0, 8, 0, 9, 1, 2, 3, 4, 0, 6,
212: 7, 0, 0, 0, 8, 0, 9
213: };
214:
215: static const short yycheck[] = { 0,
216: 3, 4, 5, 6, 18, 8, 9, 8, 9, 8,
217: 13, 3, 15, 16, 3, 4, 5, 6, 7, 8,
218: 9, 8, 16, 17, 13, 12, 15, 3, 8, 14,
219: 31, 11, 17, 3, 35, 3, 4, 5, 6, 0,
220: 8, 9, 10, 0, 22, 13, 9, 15, 3, 4,
221: 5, 6, -1, 8, 9, -1, -1, -1, 13, 14,
222: 15, 3, 4, 5, 6, -1, 8, 9, 10, -1,
223: -1, 13, -1, 15, 3, 4, 5, 6, -1, 8,
224: 9, -1, -1, -1, 13, -1, 15
225: };
226: /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
227: #line 3 "/usr/share/bison.simple"
228: /* This file comes from bison-1.28. */
229:
230: /* Skeleton output parser for bison,
231: Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
232:
233: This program is free software; you can redistribute it and/or modify
234: it under the terms of the GNU General Public License as published by
235: the Free Software Foundation; either version 2, or (at your option)
236: any later version.
237:
238: This program is distributed in the hope that it will be useful,
239: but WITHOUT ANY WARRANTY; without even the implied warranty of
240: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
241: GNU General Public License for more details.
242:
243: You should have received a copy of the GNU General Public License
244: along with this program; if not, write to the Free Software
245: Foundation, Inc., 59 Temple Place - Suite 330,
246: Boston, MA 02111-1307, USA. */
247:
248: /* As a special exception, when this file is copied by Bison into a
249: Bison output file, you may use that output file without restriction.
250: This special exception was added by the Free Software Foundation
251: in version 1.24 of Bison. */
252:
253: /* This is the parser code that is written into each bison parser
254: when the %semantic_parser declaration is not specified in the grammar.
255: It was written by Richard Stallman by simplifying the hairy parser
256: used when %semantic_parser is specified. */
257:
258: #ifndef YYSTACK_USE_ALLOCA
259: #ifdef alloca
260: #define YYSTACK_USE_ALLOCA
261: #else /* alloca not defined */
262: #ifdef __GNUC__
263: #define YYSTACK_USE_ALLOCA
264: #define alloca __builtin_alloca
265: #else /* not GNU C. */
266: #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
267: #define YYSTACK_USE_ALLOCA
268: #include <alloca.h>
269: #else /* not sparc */
270: /* We think this test detects Watcom and Microsoft C. */
271: /* This used to test MSDOS, but that is a bad idea
272: since that symbol is in the user namespace. */
273: #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
274: #if 0 /* No need for malloc.h, which pollutes the namespace;
275: instead, just don't use alloca. */
276: #include <malloc.h>
277: #endif
278: #else /* not MSDOS, or __TURBOC__ */
279: #if defined(_AIX)
280: /* I don't know what this was needed for, but it pollutes the namespace.
281: So I turned it off. rms, 2 May 1997. */
282: /* #include <malloc.h> */
283: #pragma alloca
284: #define YYSTACK_USE_ALLOCA
285: #else /* not MSDOS, or __TURBOC__, or _AIX */
286: #if 0
287: #ifdef __hpux /* [email protected] says this works for HPUX 9.05 and up,
288: and on HPUX 10. Eventually we can turn this on. */
289: #define YYSTACK_USE_ALLOCA
290: #define alloca __builtin_alloca
291: #endif /* __hpux */
292: #endif
293: #endif /* not _AIX */
294: #endif /* not MSDOS, or __TURBOC__ */
295: #endif /* not sparc */
296: #endif /* not GNU C */
297: #endif /* alloca not defined */
298: #endif /* YYSTACK_USE_ALLOCA not defined */
299:
300: #ifdef YYSTACK_USE_ALLOCA
301: #define YYSTACK_ALLOC alloca
302: #else
303: #define YYSTACK_ALLOC malloc
304: #endif
305:
306: /* Note: there must be only one dollar sign in this file.
307: It is replaced by the list of actions, each action
308: as one case of the switch. */
309:
310: #define yyerrok (yyerrstatus = 0)
311: #define yyclearin (yychar = YYEMPTY)
312: #define YYEMPTY -2
313: #define YYEOF 0
314: #define YYACCEPT goto yyacceptlab
315: #define YYABORT goto yyabortlab
316: #define YYERROR goto yyerrlab1
317: /* Like YYERROR except do call yyerror.
318: This remains here temporarily to ease the
319: transition to the new meaning of YYERROR, for GCC.
320: Once GCC version 2 has supplanted version 1, this can go. */
321: #define YYFAIL goto yyerrlab
322: #define YYRECOVERING() (!!yyerrstatus)
323: #define YYBACKUP(token, value) \
324: do \
325: if (yychar == YYEMPTY && yylen == 1) \
326: { yychar = (token), yylval = (value); \
327: yychar1 = YYTRANSLATE (yychar); \
328: YYPOPSTACK; \
329: goto yybackup; \
330: } \
331: else \
332: { yyerror ("syntax error: cannot back up"); YYERROR; } \
333: while (0)
334:
335: #define YYTERROR 1
336: #define YYERRCODE 256
337:
338: #ifndef YYPURE
339: #define YYLEX yylex()
340: #endif
341:
342: #ifdef YYPURE
343: #ifdef YYLSP_NEEDED
344: #ifdef YYLEX_PARAM
345: #define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
346: #else
347: #define YYLEX yylex(&yylval, &yylloc)
348: #endif
349: #else /* not YYLSP_NEEDED */
350: #ifdef YYLEX_PARAM
351: #define YYLEX yylex(&yylval, YYLEX_PARAM)
352: #else
353: #define YYLEX yylex(&yylval)
354: #endif
355: #endif /* not YYLSP_NEEDED */
356: #endif
357:
358: /* If nonreentrant, generate the variables here */
359:
360: #ifndef YYPURE
361:
362: int yychar; /* the lookahead symbol */
363: YYSTYPE yylval; /* the semantic value of the */
364: /* lookahead symbol */
365:
366: #ifdef YYLSP_NEEDED
367: YYLTYPE yylloc; /* location data for the lookahead */
368: /* symbol */
369: #endif
370:
371: int yynerrs; /* number of parse errors so far */
372: #endif /* not YYPURE */
373:
374: #if YYDEBUG != 0
375: int yydebug; /* nonzero means print parse trace */
376: /* Since this is uninitialized, it does not stop multiple parsers
377: from coexisting. */
378: #endif
379:
380: /* YYINITDEPTH indicates the initial size of the parser's stacks */
381:
382: #ifndef YYINITDEPTH
383: #define YYINITDEPTH 200
384: #endif
385:
386: /* YYMAXDEPTH is the maximum size the stacks can grow to
387: (effective only if the built-in stack extension method is used). */
388:
389: #if YYMAXDEPTH == 0
390: #undef YYMAXDEPTH
391: #endif
392:
393: #ifndef YYMAXDEPTH
394: #define YYMAXDEPTH 10000
395: #endif
396:
397: /* Define __yy_memcpy. Note that the size argument
398: should be passed with type unsigned int, because that is what the non-GCC
399: definitions require. With GCC, __builtin_memcpy takes an arg
400: of type size_t, but it can handle unsigned int. */
401:
402: #if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
403: #define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
404: #else /* not GNU C or C++ */
405: #ifndef __cplusplus
406:
407: /* This is the most reliable way to avoid incompatibilities
408: in available built-in functions on various systems. */
409: static void
410: __yy_memcpy (to, from, count)
411: char *to;
412: char *from;
413: unsigned int count;
414: {
415: register char *f = from;
416: register char *t = to;
417: register int i = count;
418:
419: while (i-- > 0)
420: *t++ = *f++;
421: }
422:
423: #else /* __cplusplus */
424:
425: /* This is the most reliable way to avoid incompatibilities
426: in available built-in functions on various systems. */
427: static void
428: __yy_memcpy (char *to, char *from, unsigned int count)
429: {
430: register char *t = to;
431: register char *f = from;
432: register int i = count;
433:
434: while (i-- > 0)
435: *t++ = *f++;
436: }
437:
438: #endif
439: #endif
440:
441: #line 217 "/usr/share/bison.simple"
442:
443: /* The user can define YYPARSE_PARAM as the name of an argument to be passed
444: into yyparse. The argument should have type void *.
445: It should actually point to an object.
446: Grammar actions can access the variable by casting it
447: to the proper pointer type. */
448:
449: #ifdef YYPARSE_PARAM
450: #ifdef __cplusplus
451: #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
452: #define YYPARSE_PARAM_DECL
453: #else /* not __cplusplus */
454: #define YYPARSE_PARAM_ARG YYPARSE_PARAM
455: #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
456: #endif /* not __cplusplus */
457: #else /* not YYPARSE_PARAM */
458: #define YYPARSE_PARAM_ARG
459: #define YYPARSE_PARAM_DECL
460: #endif /* not YYPARSE_PARAM */
461:
462: /* Prevent warning if -Wstrict-prototypes. */
463: #ifdef __GNUC__
464: #ifdef YYPARSE_PARAM
465: int yyparse (void *);
466: #else
467: int yyparse (void);
468: #endif
469: #endif
470:
471: int
472: yyparse(YYPARSE_PARAM_ARG)
473: YYPARSE_PARAM_DECL
474: {
475: register int yystate;
476: register int yyn;
477: register short *yyssp;
478: register YYSTYPE *yyvsp;
479: int yyerrstatus; /* number of tokens to shift before error messages enabled */
480: int yychar1 = 0; /* lookahead token as an internal (translated) token number */
481:
482: short yyssa[YYINITDEPTH]; /* the state stack */
483: YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
484:
485: short *yyss = yyssa; /* refer to the stacks thru separate pointers */
486: YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
487:
488: #ifdef YYLSP_NEEDED
489: YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
490: YYLTYPE *yyls = yylsa;
491: YYLTYPE *yylsp;
492:
493: #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
494: #else
495: #define YYPOPSTACK (yyvsp--, yyssp--)
496: #endif
497:
498: int yystacksize = YYINITDEPTH;
499: int yyfree_stacks = 0;
500:
501: #ifdef YYPURE
502: int yychar;
503: YYSTYPE yylval;
504: int yynerrs;
505: #ifdef YYLSP_NEEDED
506: YYLTYPE yylloc;
507: #endif
508: #endif
509:
510: YYSTYPE yyval; /* the variable used to return */
511: /* semantic values from the action */
512: /* routines */
513:
514: int yylen;
515:
516: #if YYDEBUG != 0
517: if (yydebug)
518: fprintf(stderr, "Starting parse\n");
519: #endif
520:
521: yystate = 0;
522: yyerrstatus = 0;
523: yynerrs = 0;
524: yychar = YYEMPTY; /* Cause a token to be read. */
525:
526: /* Initialize stack pointers.
527: Waste one element of value and location stack
528: so that they stay on the same level as the state stack.
529: The wasted elements are never initialized. */
530:
531: yyssp = yyss - 1;
532: yyvsp = yyvs;
533: #ifdef YYLSP_NEEDED
534: yylsp = yyls;
535: #endif
536:
537: /* Push a new state, which is found in yystate . */
538: /* In all cases, when you get here, the value and location stacks
539: have just been pushed. so pushing a state here evens the stacks. */
540: yynewstate:
541:
542: *++yyssp = yystate;
543:
544: if (yyssp >= yyss + yystacksize - 1)
545: {
546: /* Give user a chance to reallocate the stack */
547: /* Use copies of these so that the &'s don't force the real ones into memory. */
548: YYSTYPE *yyvs1 = yyvs;
549: short *yyss1 = yyss;
550: #ifdef YYLSP_NEEDED
551: YYLTYPE *yyls1 = yyls;
552: #endif
553:
554: /* Get the current used size of the three stacks, in elements. */
555: int size = yyssp - yyss + 1;
556:
557: #ifdef yyoverflow
558: /* Each stack pointer address is followed by the size of
559: the data in use in that stack, in bytes. */
560: #ifdef YYLSP_NEEDED
561: /* This used to be a conditional around just the two extra args,
562: but that might be undefined if yyoverflow is a macro. */
563: yyoverflow("parser stack overflow",
564: &yyss1, size * sizeof (*yyssp),
565: &yyvs1, size * sizeof (*yyvsp),
566: &yyls1, size * sizeof (*yylsp),
567: &yystacksize);
568: #else
569: yyoverflow("parser stack overflow",
570: &yyss1, size * sizeof (*yyssp),
571: &yyvs1, size * sizeof (*yyvsp),
572: &yystacksize);
573: #endif
574:
575: yyss = yyss1; yyvs = yyvs1;
576: #ifdef YYLSP_NEEDED
577: yyls = yyls1;
578: #endif
579: #else /* no yyoverflow */
580: /* Extend the stack our own way. */
581: if (yystacksize >= YYMAXDEPTH)
582: {
583: yyerror("parser stack overflow");
584: if (yyfree_stacks)
585: {
586: free (yyss);
587: free (yyvs);
588: #ifdef YYLSP_NEEDED
589: free (yyls);
590: #endif
591: }
592: return 2;
593: }
594: yystacksize *= 2;
595: if (yystacksize > YYMAXDEPTH)
596: yystacksize = YYMAXDEPTH;
597: #ifndef YYSTACK_USE_ALLOCA
598: yyfree_stacks = 1;
599: #endif
600: yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
601: __yy_memcpy ((char *)yyss, (char *)yyss1,
602: size * (unsigned int) sizeof (*yyssp));
603: yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
604: __yy_memcpy ((char *)yyvs, (char *)yyvs1,
605: size * (unsigned int) sizeof (*yyvsp));
606: #ifdef YYLSP_NEEDED
607: yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
608: __yy_memcpy ((char *)yyls, (char *)yyls1,
609: size * (unsigned int) sizeof (*yylsp));
610: #endif
611: #endif /* no yyoverflow */
612:
613: yyssp = yyss + size - 1;
614: yyvsp = yyvs + size - 1;
615: #ifdef YYLSP_NEEDED
616: yylsp = yyls + size - 1;
617: #endif
618:
619: #if YYDEBUG != 0
620: if (yydebug)
621: fprintf(stderr, "Stack size increased to %d\n", yystacksize);
622: #endif
623:
624: if (yyssp >= yyss + yystacksize - 1)
625: YYABORT;
626: }
627:
628: #if YYDEBUG != 0
629: if (yydebug)
630: fprintf(stderr, "Entering state %d\n", yystate);
631: #endif
632:
633: goto yybackup;
634: yybackup:
635:
636: /* Do appropriate processing given the current state. */
637: /* Read a lookahead token if we need one and don't already have one. */
638: /* yyresume: */
639:
640: /* First try to decide what to do without reference to lookahead token. */
641:
642: yyn = yypact[yystate];
643: if (yyn == YYFLAG)
644: goto yydefault;
645:
646: /* Not known => get a lookahead token if don't already have one. */
647:
648: /* yychar is either YYEMPTY or YYEOF
649: or a valid token in external form. */
650:
651: if (yychar == YYEMPTY)
652: {
653: #if YYDEBUG != 0
654: if (yydebug)
655: fprintf(stderr, "Reading a token: ");
656: #endif
657: yychar = YYLEX;
658: }
659:
660: /* Convert token to internal form (in yychar1) for indexing tables with */
661:
662: if (yychar <= 0) /* This means end of input. */
663: {
664: yychar1 = 0;
665: yychar = YYEOF; /* Don't call YYLEX any more */
666:
667: #if YYDEBUG != 0
668: if (yydebug)
669: fprintf(stderr, "Now at end of input.\n");
670: #endif
671: }
672: else
673: {
674: yychar1 = YYTRANSLATE(yychar);
675:
676: #if YYDEBUG != 0
677: if (yydebug)
678: {
679: fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
680: /* Give the individual parser a way to print the precise meaning
681: of a token, for further debugging info. */
682: #ifdef YYPRINT
683: YYPRINT (stderr, yychar, yylval);
684: #endif
685: fprintf (stderr, ")\n");
686: }
687: #endif
688: }
689:
690: yyn += yychar1;
691: if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
692: goto yydefault;
693:
694: yyn = yytable[yyn];
695:
696: /* yyn is what to do for this token type in this state.
697: Negative => reduce, -yyn is rule number.
698: Positive => shift, yyn is new state.
699: New state is final state => don't bother to shift,
700: just return success.
701: 0, or most negative number => error. */
702:
703: if (yyn < 0)
704: {
705: if (yyn == YYFLAG)
706: goto yyerrlab;
707: yyn = -yyn;
708: goto yyreduce;
709: }
710: else if (yyn == 0)
711: goto yyerrlab;
712:
713: if (yyn == YYFINAL)
714: YYACCEPT;
715:
716: /* Shift the lookahead token. */
717:
718: #if YYDEBUG != 0
719: if (yydebug)
720: fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
721: #endif
722:
723: /* Discard the token being shifted unless it is eof. */
724: if (yychar != YYEOF)
725: yychar = YYEMPTY;
726:
727: *++yyvsp = yylval;
728: #ifdef YYLSP_NEEDED
729: *++yylsp = yylloc;
730: #endif
731:
732: /* count tokens shifted since error; after three, turn off error status. */
733: if (yyerrstatus) yyerrstatus--;
734:
735: yystate = yyn;
736: goto yynewstate;
737:
738: /* Do the default action for the current state. */
739: yydefault:
740:
741: yyn = yydefact[yystate];
742: if (yyn == 0)
743: goto yyerrlab;
744:
745: /* Do a reduction. yyn is the number of a rule to reduce with. */
746: yyreduce:
747: yylen = yyr2[yyn];
748: if (yylen > 0)
749: yyval = yyvsp[1-yylen]; /* implement default value of the action */
750:
751: #if YYDEBUG != 0
752: if (yydebug)
753: {
754: int i;
755:
756: fprintf (stderr, "Reducing via rule %d (line %d), ",
757: yyn, yyrline[yyn]);
758:
759: /* Print the symbols being reduced, and their result. */
760: for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
761: fprintf (stderr, "%s ", yytname[yyrhs[i]]);
762: fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
763: }
764: #endif
765:
766:
767: switch (yyn) {
768:
769: case 1:
770: #line 115 "OSUnserialize.y"
771: { parsedObject = (OSObject *)NULL; YYACCEPT; ;
772: break;}
773: case 2:
774: #line 116 "OSUnserialize.y"
775: { parsedObject = (OSObject *)yyvsp[0]; YYACCEPT; ;
776: break;}
777: case 3:
778: #line 117 "OSUnserialize.y"
779: { yyerror("syntax error"); YYERROR; ;
780: break;}
781: case 4:
782: #line 120 "OSUnserialize.y"
783: { yyval = (object_t *)buildOSDictionary(yyvsp[0]); ;
784: break;}
785: case 5:
786: #line 121 "OSUnserialize.y"
787: { yyval = (object_t *)buildOSArray(yyvsp[0]); ;
788: break;}
789: case 6:
790: #line 122 "OSUnserialize.y"
791: { yyval = (object_t *)buildOSSet(yyvsp[0]); ;
792: break;}
793: case 7:
794: #line 123 "OSUnserialize.y"
795: { yyval = (object_t *)buildOSString(yyvsp[0]); ;
796: break;}
797: case 8:
798: #line 124 "OSUnserialize.y"
799: { yyval = (object_t *)buildOSData(yyvsp[0]); ;
800: break;}
801: case 9:
802: #line 125 "OSUnserialize.y"
803: { yyval = (object_t *)buildOSOffset(yyvsp[0]); ;
804: break;}
805: case 10:
806: #line 126 "OSUnserialize.y"
807: { yyval = (object_t *)buildOSBoolean(yyvsp[0]); ;
808: break;}
809: case 11:
810: #line 127 "OSUnserialize.y"
811: { yyval = (object_t *)retrieveObject(yyvsp[0]->u.offset);
812: if (yyval) {
813: ((OSObject *)yyval)->retain();
814: } else {
815: yyerror("forward reference detected");
816: YYERROR;
817: }
818: freeObject(yyvsp[0]);
819: ;
820: break;}
821: case 12:
822: #line 136 "OSUnserialize.y"
823: { yyval = yyvsp[-2];
824: rememberObject(yyvsp[0]->u.offset, yyvsp[-2]);
825: freeObject(yyvsp[0]);
826: ;
827: break;}
828: case 13:
829: #line 144 "OSUnserialize.y"
830: { yyval = NULL; ;
831: break;}
832: case 14:
833: #line 145 "OSUnserialize.y"
834: { yyval = yyvsp[-1]; ;
835: break;}
836: case 16:
837: #line 149 "OSUnserialize.y"
838: { yyvsp[0]->next = yyvsp[-1]; yyvsp[-1]->prev = yyvsp[0]; yyval = yyvsp[0]; ;
839: break;}
840: case 17:
841: #line 152 "OSUnserialize.y"
842: { yyval = newObject();
843: yyval->next = NULL;
844: yyval->prev = NULL;
845: yyval->u.key = yyvsp[-3];
846: yyval->object = yyvsp[-1];
847: ;
848: break;}
849: case 18:
850: #line 162 "OSUnserialize.y"
851: { yyval = NULL; ;
852: break;}
853: case 19:
854: #line 163 "OSUnserialize.y"
855: { yyval = yyvsp[-1]; ;
856: break;}
857: case 20:
858: #line 166 "OSUnserialize.y"
859: { yyval = NULL; ;
860: break;}
861: case 21:
862: #line 167 "OSUnserialize.y"
863: { yyval = yyvsp[-1]; ;
864: break;}
865: case 22:
866: #line 170 "OSUnserialize.y"
867: { yyval = newObject();
868: yyval->object = yyvsp[0];
869: yyval->next = NULL;
870: yyval->prev = NULL;
871: ;
872: break;}
873: case 23:
874: #line 175 "OSUnserialize.y"
875: { o = newObject();
876: o->object = yyvsp[0];
877: o->next = yyvsp[-2];
878: o->prev = NULL;
879: yyvsp[-2]->prev = o;
880: yyval = o;
881: ;
882: break;}
883: case 24:
884: #line 186 "OSUnserialize.y"
885: { yyval = yyvsp[-2];
886: yyval->size = yyvsp[0]->u.offset;
887: freeObject(yyvsp[0]);
888: ;
889: break;}
890: }
891: /* the action file gets copied in in place of this dollarsign */
892: #line 543 "/usr/share/bison.simple"
893:
894: yyvsp -= yylen;
895: yyssp -= yylen;
896: #ifdef YYLSP_NEEDED
897: yylsp -= yylen;
898: #endif
899:
900: #if YYDEBUG != 0
901: if (yydebug)
902: {
903: short *ssp1 = yyss - 1;
904: fprintf (stderr, "state stack now");
905: while (ssp1 != yyssp)
906: fprintf (stderr, " %d", *++ssp1);
907: fprintf (stderr, "\n");
908: }
909: #endif
910:
911: *++yyvsp = yyval;
912:
913: #ifdef YYLSP_NEEDED
914: yylsp++;
915: if (yylen == 0)
916: {
917: yylsp->first_line = yylloc.first_line;
918: yylsp->first_column = yylloc.first_column;
919: yylsp->last_line = (yylsp-1)->last_line;
920: yylsp->last_column = (yylsp-1)->last_column;
921: yylsp->text = 0;
922: }
923: else
924: {
925: yylsp->last_line = (yylsp+yylen-1)->last_line;
926: yylsp->last_column = (yylsp+yylen-1)->last_column;
927: }
928: #endif
929:
930: /* Now "shift" the result of the reduction.
931: Determine what state that goes to,
932: based on the state we popped back to
933: and the rule number reduced by. */
934:
935: yyn = yyr1[yyn];
936:
937: yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
938: if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
939: yystate = yytable[yystate];
940: else
941: yystate = yydefgoto[yyn - YYNTBASE];
942:
943: goto yynewstate;
944:
945: yyerrlab: /* here on detecting error */
946:
947: if (! yyerrstatus)
948: /* If not already recovering from an error, report this error. */
949: {
950: ++yynerrs;
951:
952: #ifdef YYERROR_VERBOSE
953: yyn = yypact[yystate];
954:
955: if (yyn > YYFLAG && yyn < YYLAST)
956: {
957: int size = 0;
958: char *msg;
959: int x, count;
960:
961: count = 0;
962: /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
963: for (x = (yyn < 0 ? -yyn : 0);
964: x < (sizeof(yytname) / sizeof(char *)); x++)
965: if (yycheck[x + yyn] == x)
966: size += strlen(yytname[x]) + 15, count++;
967: msg = (char *) malloc(size + 15);
968: if (msg != 0)
969: {
970: strcpy(msg, "parse error");
971:
972: if (count < 5)
973: {
974: count = 0;
975: for (x = (yyn < 0 ? -yyn : 0);
976: x < (sizeof(yytname) / sizeof(char *)); x++)
977: if (yycheck[x + yyn] == x)
978: {
979: strcat(msg, count == 0 ? ", expecting `" : " or `");
980: strcat(msg, yytname[x]);
981: strcat(msg, "'");
982: count++;
983: }
984: }
985: yyerror(msg);
986: free(msg);
987: }
988: else
989: yyerror ("parse error; also virtual memory exceeded");
990: }
991: else
992: #endif /* YYERROR_VERBOSE */
993: yyerror("parse error");
994: }
995:
996: goto yyerrlab1;
997: yyerrlab1: /* here on error raised explicitly by an action */
998:
999: if (yyerrstatus == 3)
1000: {
1001: /* if just tried and failed to reuse lookahead token after an error, discard it. */
1002:
1003: /* return failure if at end of input */
1004: if (yychar == YYEOF)
1005: YYABORT;
1006:
1007: #if YYDEBUG != 0
1008: if (yydebug)
1009: fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1010: #endif
1011:
1012: yychar = YYEMPTY;
1013: }
1014:
1015: /* Else will try to reuse lookahead token
1016: after shifting the error token. */
1017:
1018: yyerrstatus = 3; /* Each real token shifted decrements this */
1019:
1020: goto yyerrhandle;
1021:
1022: yyerrdefault: /* current state does not do anything special for the error token. */
1023:
1024: #if 0
1025: /* This is wrong; only states that explicitly want error tokens
1026: should shift them. */
1027: yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
1028: if (yyn) goto yydefault;
1029: #endif
1030:
1031: yyerrpop: /* pop the current state because it cannot handle the error token */
1032:
1033: if (yyssp == yyss) YYABORT;
1034: yyvsp--;
1035: yystate = *--yyssp;
1036: #ifdef YYLSP_NEEDED
1037: yylsp--;
1038: #endif
1039:
1040: #if YYDEBUG != 0
1041: if (yydebug)
1042: {
1043: short *ssp1 = yyss - 1;
1044: fprintf (stderr, "Error: state stack now");
1045: while (ssp1 != yyssp)
1046: fprintf (stderr, " %d", *++ssp1);
1047: fprintf (stderr, "\n");
1048: }
1049: #endif
1050:
1051: yyerrhandle:
1052:
1053: yyn = yypact[yystate];
1054: if (yyn == YYFLAG)
1055: goto yyerrdefault;
1056:
1057: yyn += YYTERROR;
1058: if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1059: goto yyerrdefault;
1060:
1061: yyn = yytable[yyn];
1062: if (yyn < 0)
1063: {
1064: if (yyn == YYFLAG)
1065: goto yyerrpop;
1066: yyn = -yyn;
1067: goto yyreduce;
1068: }
1069: else if (yyn == 0)
1070: goto yyerrpop;
1071:
1072: if (yyn == YYFINAL)
1073: YYACCEPT;
1074:
1075: #if YYDEBUG != 0
1076: if (yydebug)
1077: fprintf(stderr, "Shifting error token, ");
1078: #endif
1079:
1080: *++yyvsp = yylval;
1081: #ifdef YYLSP_NEEDED
1082: *++yylsp = yylloc;
1083: #endif
1084:
1085: yystate = yyn;
1086: goto yynewstate;
1087:
1088: yyacceptlab:
1089: /* YYACCEPT comes here. */
1090: if (yyfree_stacks)
1091: {
1092: free (yyss);
1093: free (yyvs);
1094: #ifdef YYLSP_NEEDED
1095: free (yyls);
1096: #endif
1097: }
1098: return 0;
1099:
1100: yyabortlab:
1101: /* YYABORT comes here. */
1102: if (yyfree_stacks)
1103: {
1104: free (yyss);
1105: free (yyvs);
1106: #ifdef YYLSP_NEEDED
1107: free (yyls);
1108: #endif
1109: }
1110: return 1;
1111: }
1112: #line 207 "OSUnserialize.y"
1113:
1114:
1115: static int lineNumber = 0;
1116: static const char *parseBuffer;
1117: static int parseBufferIndex;
1118:
1119: #define currentChar() (parseBuffer[parseBufferIndex])
1120: #define nextChar() (parseBuffer[++parseBufferIndex])
1121: #define prevChar() (parseBuffer[parseBufferIndex - 1])
1122:
1123: #define isSpace(c) ((c) == ' ' || (c) == '\t')
1124: #define isAlpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
1125: #define isDigit(c) ((c) >= '0' && (c) <= '9')
1126: #define isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f')
1127: #define isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
1128: #define isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-'))
1129:
1130: static char yyerror_message[128];
1131:
1132: int
1133: yyerror(char *s) /* Called by yyparse on error */
1134: {
1135: sprintf(yyerror_message, "OSUnserialize: %s near line %d\n", s, lineNumber);
1136: return 0;
1137: }
1138:
1139: int
1140: yylex()
1141: {
1142: int c;
1143:
1144: if (parseBufferIndex == 0) lineNumber = 1;
1145:
1146: top:
1147: c = currentChar();
1148:
1149: /* skip white space */
1150: if (isSpace(c)) while ((c = nextChar()) != 0 && isSpace(c)) {};
1151:
1152: /* skip over comments */
1153: if (c == '#') while ((c = nextChar()) != 0 && c != '\n') {};
1154:
1155: /* keep track of line number, don't return \n's */
1156: if (c == '\n') {
1157: lineNumber++;
1158: (void)nextChar();
1159: goto top;
1160: }
1161:
1162: /* parse boolean */
1163: if (c == '.') {
1164: bool boolean = false;
1165: if (nextChar() == 't') {
1166: if (nextChar() != 'r') return SYNTAX_ERROR;
1167: if (nextChar() != 'u') return SYNTAX_ERROR;
1168: if (nextChar() != 'e') return SYNTAX_ERROR;
1169: boolean = true;
1170: } else {
1171: if (currentChar() != 'f') return SYNTAX_ERROR;
1172: if (nextChar() != 'a') return SYNTAX_ERROR;
1173: if (nextChar() != 'l') return SYNTAX_ERROR;
1174: if (nextChar() != 's') return SYNTAX_ERROR;
1175: if (nextChar() != 'e') return SYNTAX_ERROR;
1176: }
1177: if (nextChar() != '.') return SYNTAX_ERROR;
1178: /* skip over dot */
1179: (void)nextChar();
1180:
1181: yylval = (object_t *)boolean;
1182: return BOOLEAN;
1183: }
1184:
1185: /* parse unquoted string */
1186: if (isAlpha(c)) {
1187: int start, length;
1188: char * tempString;
1189:
1190: start = parseBufferIndex;
1191: /* find end of string */
1192: while (isAlphaNumeric(c)) {
1193: c = nextChar();
1194: }
1195: length = parseBufferIndex - start;
1196:
1197: /* copy to null terminated buffer */
1198: tempString = (char *)malloc(length + 1);
1199: if (tempString == 0) {
1200: printf("OSUnserialize: can't alloc temp memory\n");
1201: return 0;
1202: }
1203: bcopy(&parseBuffer[start], tempString, length);
1204: tempString[length] = 0;
1205: yylval = (object_t *)tempString;
1206: return STRING;
1207: }
1208:
1209: /* parse quoted string */
1210: if (c == '"' || c == '\'') {
1211: int start, length;
1212: char * tempString;
1213: char quoteChar = c;
1214:
1215: start = parseBufferIndex + 1; // skip quote
1216: /* find end of string, line, buffer */
1217: while ((c = nextChar()) != quoteChar) {
1218: if (c == '\\') c = nextChar();
1219: if (c == '\n') lineNumber++;
1220: if (c == 0) return SYNTAX_ERROR;
1221: }
1222: length = parseBufferIndex - start;
1223: /* skip over trailing quote */
1224: (void)nextChar();
1225: /* copy to null terminated buffer */
1226: tempString = (char *)malloc(length + 1);
1227: if (tempString == 0) {
1228: printf("OSUnserialize: can't alloc temp memory\n");
1229: return 0;
1230: }
1231:
1232: int to = 0;
1233: for (int from=start; from < parseBufferIndex; from++) {
1234: // hack - skip over backslashes
1235: if (parseBuffer[from] == '\\') {
1236: length--;
1237: continue;
1238: }
1239: tempString[to] = parseBuffer[from];
1240: to++;
1241: }
1242: tempString[length] = 0;
1243: yylval = (object_t *)tempString;
1244: return STRING;
1245: }
1246:
1247: /* process numbers */
1248: if (isDigit (c))
1249: {
1250: unsigned long long n = 0;
1251: int base = 10;
1252:
1253: if (c == '0') {
1254: c = nextChar();
1255: if (c == 'x') {
1256: base = 16;
1257: c = nextChar();
1258: }
1259: }
1260: if (base == 10) {
1261: while(isDigit(c)) {
1262: n = (n * base + c - '0');
1263: c = nextChar();
1264: }
1265: } else {
1266: while(isHexDigit(c)) {
1267: if (isDigit(c)) {
1268: n = (n * base + c - '0');
1269: } else {
1270: n = (n * base + 0xa + c - 'a');
1271: }
1272: c = nextChar();
1273: }
1274: }
1275:
1276: yylval = newObject();
1277: yylval->u.offset = n;
1278:
1279: return NUMBER;
1280: }
1281:
1282: #define OSDATA_ALLOC_SIZE 4096
1283:
1284: /* process data */
1285: if (c == '<') {
1286: unsigned char *d, *start, *lastStart;
1287:
1288: start = lastStart = d = (unsigned char *)malloc(OSDATA_ALLOC_SIZE);
1289: c = nextChar(); // skip over '<'
1290: while (c != 0 && c != '>') {
1291:
1292: if (isSpace(c)) while ((c = nextChar()) != 0 && isSpace(c)) {};
1293: if (c == '#') while ((c = nextChar()) != 0 && c != '\n') {};
1294: if (c == '\n') {
1295: lineNumber++;
1296: c = nextChar();
1297: continue;
1298: }
1299:
1300: // get high nibble
1301: if (!isHexDigit(c)) break;
1302: if (isDigit(c)) {
1303: *d = (c - '0') << 4;
1304: } else {
1305: *d = (0xa + (c - 'a')) << 4;
1306: }
1307:
1308: // get low nibble
1309: c = nextChar();
1310: if (!isHexDigit(c)) break;
1311: if (isDigit(c)) {
1312: *d |= c - '0';
1313: } else {
1314: *d |= 0xa + (c - 'a');
1315: }
1316:
1317: d++;
1318: if ((d - lastStart) >= OSDATA_ALLOC_SIZE) {
1319: int oldsize = d - start;
1320: start = (unsigned char *)realloc(start, oldsize + OSDATA_ALLOC_SIZE);
1321: d = lastStart = start + oldsize;
1322: }
1323: c = nextChar();
1324: }
1325: if (c != '>' ) {
1326: free(start);
1327: return SYNTAX_ERROR;
1328: }
1329:
1330: // got it!
1331: yylval = newObject();
1332: yylval->object = start;
1333: yylval->size = d - start;
1334:
1335: (void)nextChar(); // skip over '>'
1336: return DATA;
1337: }
1338:
1339:
1340: /* return single chars, move pointer to next char */
1341: (void)nextChar();
1342: return c;
1343: }
1344:
1345: // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1346: // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1347: // !@$&)(^Q$&*^!$(*!@$_(^%_(*Q#$(_*&!$_(*&!$_(*&!#$(*!@&^!@#%!_!#
1348:
1349: #ifdef DEBUG
1350: int debugUnserializeAllocCount = 0;
1351: #endif
1352:
1353: object_t *
1354: newObject()
1355: {
1356: #ifdef DEBUG
1357: debugUnserializeAllocCount++;
1358: #endif
1359: return (object_t *)malloc(sizeof(object_t));
1360: }
1361:
1362: void
1363: freeObject(object_t *o)
1364: {
1365: #ifdef DEBUG
1366: debugUnserializeAllocCount--;
1367: #endif
1368: free(o);
1369: }
1370:
1371: static OSDictionary *tags;
1372:
1373: static void
1374: rememberObject(int tag, object_t *o)
1375: {
1376: char key[16];
1377: sprintf(key, "%u", tag);
1378:
1379: tags->setObject(key, (OSObject *)o);
1380: }
1381:
1382: static OSObject *
1383: retrieveObject(int tag)
1384: {
1385: char key[16];
1386: sprintf(key, "%u", tag);
1387:
1388: return tags->getObject(key);
1389: }
1390:
1391: OSObject *
1392: buildOSDictionary(object_t *o)
1393: {
1394: object_t *temp, *last = o;
1395: int count = 0;
1396:
1397: // get count and last object
1398: while (o) {
1399: count++;
1400: last = o;
1401: o = o->next;
1402: }
1403: o = last;
1404:
1405: OSDictionary *d = OSDictionary::withCapacity(count);
1406:
1407: while (o) {
1408: #ifdef metaclass_stuff_worksXXX
1409: if (((OSObject *)o->u.key)->metaCast("OSSymbol")) {
1410: // XXX the evil frontdoor
1411: d->setObject((OSSymbol *)o->u.key, (OSObject *)o->object);
1412: } else {
1413: // If it isn't a symbol, I hope it's a string!
1414: d->setObject((OSString *)o->u.key, (OSObject *)o->object);
1415: }
1416: #else
1417: d->setObject((OSString *)o->u.key, (OSObject *)o->object);
1418: #endif
1419: ((OSObject *)o->object)->release();
1420: ((OSObject *)o->u.key)->release();
1421: temp = o;
1422: o = o->prev;
1423: freeObject(temp);
1424: }
1425: return d;
1426: };
1427:
1428: OSObject *
1429: buildOSArray(object_t *o)
1430: {
1431: object_t *temp, *last = o;
1432: int count = 0;
1433:
1434: // get count and last object
1435: while (o) {
1436: count++;
1437: last = o;
1438: o = o->next;
1439: }
1440: o = last;
1441:
1442: OSArray *a = OSArray::withCapacity(count);
1443:
1444: while (o) {
1445: a->setObject((OSObject *)o->object);
1446: ((OSObject *)o->object)->release();
1447: temp = o;
1448: o = o->prev;
1449: freeObject(temp);
1450: }
1451: return a;
1452: };
1453:
1454: OSObject *
1455: buildOSSet(object_t *o)
1456: {
1457: OSArray *a = (OSArray *)buildOSArray(o);
1458: OSSet *s = OSSet::withArray(a, a->getCapacity());
1459:
1460: a->release();
1461: return s;
1462: };
1463:
1464: OSObject *
1465: buildOSString(object_t *o)
1466: {
1467: OSString *s = OSString::withCString((char *)o);
1468:
1469: free(o);
1470:
1471: return s;
1472: };
1473:
1474: OSObject *
1475: buildOSData(object_t *o)
1476: {
1477: OSData *d;
1478:
1479: if (o->size) {
1480: d = OSData::withBytes(o->object, o->size);
1481: } else {
1482: d = OSData::withCapacity(0);
1483: }
1484: free(o->object);
1485: freeObject(o);
1486: return d;
1487: };
1488:
1489: OSObject *
1490: buildOSOffset(object_t *o)
1491: {
1492: OSNumber *off = OSNumber::withNumber(o->u.offset, o->size);
1493: freeObject(o);
1494: return off;
1495: };
1496:
1497: OSObject *
1498: buildOSBoolean(object_t *o)
1499: {
1500: OSBoolean *b = OSBoolean::withBoolean((bool)o);
1501: return b;
1502: };
1503:
1504: __BEGIN_DECLS
1505: #include <kern/lock.h>
1506: __END_DECLS
1507:
1508: static mutex_t *lock = 0;
1509:
1510: OSObject*
1511: OSUnserialize(const char *buffer, OSString **errorString)
1512: {
1513: OSObject *object;
1514:
1515: if (!lock) {
1516: lock = mutex_alloc(ETAP_IO_AHA);
1517: _mutex_lock(lock);
1518: } else {
1519: _mutex_lock(lock);
1520:
1521: }
1522:
1523: #ifdef DEBUG
1524: debugUnserializeAllocCount = 0;
1525: #endif
1526: yyerror_message[0] = 0; //just in case
1527: parseBuffer = buffer;
1528: parseBufferIndex = 0;
1529: tags = OSDictionary::withCapacity(128);
1530: if (yyparse() == 0) {
1531: object = parsedObject;
1532: if (errorString) *errorString = 0;
1533: } else {
1534: object = 0;
1535: if (errorString)
1536: *errorString = OSString::withCString(yyerror_message);
1537: }
1538:
1539: tags->release();
1540: #ifdef DEBUG
1541: if (debugUnserializeAllocCount) {
1542: printf("OSUnserialize: allocation check failed, count = %d.\n",
1543: debugUnserializeAllocCount);
1544: }
1545: #endif
1546: mutex_unlock(lock);
1547:
1548: return object;
1549: }
1550:
1551:
1552: //
1553: //
1554: //
1555: //
1556: //
1557: // DO NOT EDIT OSUnserialize.cpp!
1558: //
1559: // this means you!
1560: //
1561: //
1562: //
1563: //
1564: //
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.