Loading...
libkern/c++/OSUnserializeXML.cpp xnu-1504.7.4 xnu-1228
--- xnu/xnu-1504.7.4/libkern/c++/OSUnserializeXML.cpp
+++ xnu/xnu-1228/libkern/c++/OSUnserializeXML.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999-2009 Apple Inc. All rights reserved.
+ * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -195,9 +195,10 @@
 
 #undef yyerror 	
 #define yyerror(s)	OSUnserializeerror(STATE, (s))
-static int		OSUnserializeerror(parser_state_t *state, const char *s);
+static int		OSUnserializeerror(parser_state_t *state, char *s);
 
 static int		yylex(YYSTYPE *lvalp, parser_state_t *state);
+static int		yyparse(void * state);
 
 static object_t 	*newObject(parser_state_t *state);
 static void 		freeObject(parser_state_t *state, object_t *o);
@@ -218,6 +219,10 @@
 extern void		*kern_os_realloc(void * addr, size_t size);
 extern void		kern_os_free(void * addr);
 
+//XXX shouldn't have to define these
+extern long		strtol(const char *, char **, int);
+extern unsigned long	strtoul(const char *, char **, int);
+
 } /* extern "C" */
 
 #define malloc(s) kern_os_malloc(s)
@@ -257,7 +262,7 @@
 
 
 /* Line 216 of yacc.c.  */
-#line 211 "OSUnserializeXML.tab.c"
+#line 216 "OSUnserializeXML.tab.c"
 
 #ifdef short
 # undef short
@@ -307,7 +312,7 @@
 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
 
 #ifndef YY_
-# if defined YYENABLE_NLS && YYENABLE_NLS
+# if YYENABLE_NLS
 #  if ENABLE_NLS
 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
@@ -549,10 +554,10 @@
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const yytype_uint8 yyrline[] =
 {
-       0,   145,   145,   148,   153,   158,   159,   160,   161,   162,
-     163,   164,   165,   178,   181,   184,   187,   188,   193,   202,
-     207,   210,   213,   216,   219,   222,   225,   228,   235,   238,
-     241,   244,   247
+       0,   150,   150,   153,   158,   163,   164,   165,   166,   167,
+     168,   169,   170,   183,   186,   189,   192,   193,   198,   207,
+     212,   215,   218,   221,   224,   227,   230,   233,   240,   243,
+     246,   249,   252
 };
 #endif
 
@@ -749,7 +754,7 @@
    we won't break user code: when these are the locations we know.  */
 
 #ifndef YY_LOCATION_PRINT
-# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
+# if YYLTYPE_IS_TRIVIAL
 #  define YY_LOCATION_PRINT(File, Loc)			\
      fprintf (File, "%d.%d-%d.%d",			\
 	      (Loc).first_line, (Loc).first_column,	\
@@ -1493,14 +1498,14 @@
   switch (yyn)
     {
         case 2:
-#line 145 "OSUnserializeXML.y"
+#line 150 "OSUnserializeXML.y"
     { yyerror("unexpected end of buffer");
 				  YYERROR;
 				;}
     break;
 
   case 3:
-#line 148 "OSUnserializeXML.y"
+#line 153 "OSUnserializeXML.y"
     { STATE->parsedObject = (yyvsp[(1) - (1)])->object;
 				  (yyvsp[(1) - (1)])->object = 0;
 				  freeObject(STATE, (yyvsp[(1) - (1)]));
@@ -1509,49 +1514,49 @@
     break;
 
   case 4:
-#line 153 "OSUnserializeXML.y"
+#line 158 "OSUnserializeXML.y"
     { yyerror("syntax error");
 				  YYERROR;
 				;}
     break;
 
   case 5:
-#line 158 "OSUnserializeXML.y"
+#line 163 "OSUnserializeXML.y"
     { (yyval) = buildDictionary(STATE, (yyvsp[(1) - (1)])); ;}
     break;
 
   case 6:
-#line 159 "OSUnserializeXML.y"
+#line 164 "OSUnserializeXML.y"
     { (yyval) = buildArray(STATE, (yyvsp[(1) - (1)])); ;}
     break;
 
   case 7:
-#line 160 "OSUnserializeXML.y"
+#line 165 "OSUnserializeXML.y"
     { (yyval) = buildSet(STATE, (yyvsp[(1) - (1)])); ;}
     break;
 
   case 8:
-#line 161 "OSUnserializeXML.y"
+#line 166 "OSUnserializeXML.y"
     { (yyval) = buildString(STATE, (yyvsp[(1) - (1)])); ;}
     break;
 
   case 9:
-#line 162 "OSUnserializeXML.y"
+#line 167 "OSUnserializeXML.y"
     { (yyval) = buildData(STATE, (yyvsp[(1) - (1)])); ;}
     break;
 
   case 10:
-#line 163 "OSUnserializeXML.y"
+#line 168 "OSUnserializeXML.y"
     { (yyval) = buildNumber(STATE, (yyvsp[(1) - (1)])); ;}
     break;
 
   case 11:
-#line 164 "OSUnserializeXML.y"
+#line 169 "OSUnserializeXML.y"
     { (yyval) = buildBoolean(STATE, (yyvsp[(1) - (1)])); ;}
     break;
 
   case 12:
-#line 165 "OSUnserializeXML.y"
+#line 170 "OSUnserializeXML.y"
     { (yyval) = retrieveObject(STATE, (yyvsp[(1) - (1)])->idref);
 				  if ((yyval)) {
 				    (yyval)->object->retain();
@@ -1564,28 +1569,28 @@
     break;
 
   case 13:
-#line 178 "OSUnserializeXML.y"
+#line 183 "OSUnserializeXML.y"
     { (yyval) = (yyvsp[(1) - (2)]);
 				  (yyval)->elements = NULL;
 				;}
     break;
 
   case 14:
-#line 181 "OSUnserializeXML.y"
+#line 186 "OSUnserializeXML.y"
     { (yyval) = (yyvsp[(1) - (3)]);
 				  (yyval)->elements = (yyvsp[(2) - (3)]);
 				;}
     break;
 
   case 17:
-#line 188 "OSUnserializeXML.y"
+#line 193 "OSUnserializeXML.y"
     { (yyval) = (yyvsp[(2) - (2)]);
 				  (yyval)->next = (yyvsp[(1) - (2)]);
 				;}
     break;
 
   case 18:
-#line 193 "OSUnserializeXML.y"
+#line 198 "OSUnserializeXML.y"
     { (yyval) = (yyvsp[(1) - (2)]);
 				  (yyval)->key = (OSString *)(yyval)->object;
 				  (yyval)->object = (yyvsp[(2) - (2)])->object;
@@ -1596,47 +1601,47 @@
     break;
 
   case 19:
-#line 202 "OSUnserializeXML.y"
+#line 207 "OSUnserializeXML.y"
     { (yyval) = buildString(STATE, (yyvsp[(1) - (1)])); ;}
     break;
 
   case 20:
-#line 207 "OSUnserializeXML.y"
+#line 212 "OSUnserializeXML.y"
     { (yyval) = (yyvsp[(1) - (2)]);
 				  (yyval)->elements = NULL;
 				;}
     break;
 
   case 21:
-#line 210 "OSUnserializeXML.y"
+#line 215 "OSUnserializeXML.y"
     { (yyval) = (yyvsp[(1) - (3)]);
 				  (yyval)->elements = (yyvsp[(2) - (3)]);
 				;}
     break;
 
   case 23:
-#line 216 "OSUnserializeXML.y"
+#line 221 "OSUnserializeXML.y"
     { (yyval) = (yyvsp[(1) - (2)]);
 				  (yyval)->elements = NULL;
 				;}
     break;
 
   case 24:
-#line 219 "OSUnserializeXML.y"
+#line 224 "OSUnserializeXML.y"
     { (yyval) = (yyvsp[(1) - (3)]);
 				  (yyval)->elements = (yyvsp[(2) - (3)]);
 				;}
     break;
 
   case 26:
-#line 225 "OSUnserializeXML.y"
+#line 230 "OSUnserializeXML.y"
     { (yyval) = (yyvsp[(1) - (1)]); 
 				  (yyval)->next = NULL; 
 				;}
     break;
 
   case 27:
-#line 228 "OSUnserializeXML.y"
+#line 233 "OSUnserializeXML.y"
     { (yyval) = (yyvsp[(2) - (2)]);
 				  (yyval)->next = (yyvsp[(1) - (2)]);
 				;}
@@ -1644,7 +1649,7 @@
 
 
 /* Line 1267 of yacc.c.  */
-#line 1595 "OSUnserializeXML.tab.c"
+#line 1600 "OSUnserializeXML.tab.c"
       default: break;
     }
   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -1858,18 +1863,19 @@
 }
 
 
-#line 250 "OSUnserializeXML.y"
+#line 255 "OSUnserializeXML.y"
 
 
 int
-OSUnserializeerror(parser_state_t * state, const char *s)  /* Called by yyparse on errors */
-{
+OSUnserializeerror(parser_state_t * state, char *s)  /* Called by yyparse on errors */
+{
+    char tempString[128];
+
     if (state->errorString) {
-	char tempString[128];
 	snprintf(tempString, 128, "OSUnserializeXML: %s near line %d\n", s, state->lineNumber);
 	*(state->errorString) = OSString::withCString(tempString);
     }
-    
+
     return 0;
 }
 
@@ -1879,7 +1885,7 @@
 #define TAG_START		1
 #define TAG_END			2
 #define TAG_EMPTY		3
-#define TAG_IGNORE		4
+#define TAG_COMMENT		4
 
 #define currentChar()	(state->parseBuffer[state->parseBufferIndex])
 #define nextChar()	(state->parseBuffer[++state->parseBufferIndex])
@@ -1908,50 +1914,16 @@
 	if (c != '<') return TAG_BAD;
         c = nextChar();		// skip '<'
 
-
-	// <!TAG   declarations     >
-	// <!--     comments      -->
-        if (c == '!') {
-	    c = nextChar();  
-	    bool isComment = (c == '-') && ((c = nextChar()) != 0) && (c == '-');
-	    if (!isComment && !isAlpha(c)) return TAG_BAD;   // <!1, <!-A, <!eos
-
-	    while (c && (c = nextChar()) != 0) {
-		if (c == '\n') state->lineNumber++;
-		if (isComment) {
-		    if (c != '-') continue;
-		    c = nextChar();
-		    if (c != '-') continue;
-		    c = nextChar();
-		}
-		if (c == '>') {
-		    (void)nextChar();
-		    return TAG_IGNORE;
-		}
-		if (isComment) break;
-	    }
-	    return TAG_BAD;
-	}
-
-	else
-
-	// <? Processing Instructions  ?>
-        if (c == '?') {
-	    while ((c = nextChar()) != 0) {
-		if (c == '\n') state->lineNumber++;
-		if (c != '?') continue;
-		c = nextChar();
-		if (c == '>') {
-		    (void)nextChar();
-		    return TAG_IGNORE;
-		}
-	    }
-	    return TAG_BAD;
-	}
-
-	else
-
-	// </ end tag >    
+        if (c == '?' || c == '!') {
+                while ((c = nextChar()) != 0) {
+                        if (c == '\n') state->lineNumber++;
+                        if (c == '>') {
+                                (void)nextChar();
+                                return TAG_COMMENT;
+                        }
+                }
+        }
+
 	if (c == '/') {
 		c = nextChar();		// skip '/'
 		tagType = TAG_END;
@@ -2286,7 +2258,7 @@
 
 	tagType = getTag(STATE, tag, &attributeCount, attributes, values);
 	if (tagType == TAG_BAD) return SYNTAX_ERROR;
-	if (tagType == TAG_IGNORE) goto top;
+	if (tagType == TAG_COMMENT) goto top;
 
 	// handle allocation and check for "ID" and "IDREF" tags up front
 	*lvalp = object = newObject(STATE);
@@ -2689,7 +2661,7 @@
 };
 
 object_t *
-buildBoolean(parser_state_t *state __unused, object_t *o)
+buildBoolean(parser_state_t *state, object_t *o)
 {
 	o->object = ((o->number == 0) ? kOSBooleanFalse : kOSBooleanTrue);
 	o->object->retain();