platform_unix.c
changeset 41 7edecb332efb
parent 40 bac807d1f829
child 44 8ddfda0b6aaa
equal deleted inserted replaced
40:bac807d1f829 41:7edecb332efb
   171 static char *parse_xml(char *ptr, char **tag, char **val)
   171 static char *parse_xml(char *ptr, char **tag, char **val)
   172 {
   172 {
   173     char *ptr2;
   173     char *ptr2;
   174     while ( (ptr = strchr(ptr, '<')) != NULL )
   174     while ( (ptr = strchr(ptr, '<')) != NULL )
   175     {
   175     {
       
   176         ptr++;  /* skip past '<' to start of tag.*/
       
   177         if (*ptr == '/') continue;  /* prior endtag? */
       
   178         if (*ptr == '!') continue;  /* initial crap? */
       
   179         if (*ptr == '?') continue;  /* initial crap? */
       
   180 
       
   181         *tag = ptr;
       
   182         *(ptr-1) = '/';  /* prepend a '/' so we can search for the endtag. */
       
   183         ptr2 = strchr(ptr, ' '); /* look for a space (tag attributes?) */
       
   184         if ( (ptr = strchr(ptr, '>')) == NULL ) return(NULL);
       
   185         if ((ptr2) && (ptr2 < ptr)) *ptr2 = '\0';  /* chop out attributes. */
       
   186         *ptr = '\0';  /* chop off '<' at end of tag. */
       
   187         *val = ptr + 1;  /* (*val) == start of children of this tag. */
       
   188 
       
   189         /* Catch <tagname/> tags... */
       
   190         ptr2 = ptr - 1;
       
   191         while ( (ptr2 != *tag) && (isspace(*ptr2)) )
       
   192             ptr2--;
       
   193 
       
   194         if ((ptr2 != *tag) && (*ptr2 == '/'))  /* it's a <tag/> ... skip it. */
       
   195         {
       
   196             ptr = *val;
       
   197             continue;
       
   198         } /* if */
       
   199 
       
   200         /* look for endtag... */
   176         ptr++;
   201         ptr++;
   177         if (*ptr == '/') continue;  // prior endtag.
       
   178         if (*ptr == '!') continue;  // initial crap.
       
   179         if (*ptr == '?') continue;  // initial crap.
       
   180 
       
   181         *tag = ptr;
       
   182         *(ptr-1) = '/';
       
   183         ptr2 = strchr(ptr, ' ');
       
   184         if ( (ptr = strchr(ptr, '>')) == NULL ) return(NULL);
       
   185         if ((ptr2) && (ptr2 < ptr)) *ptr2 = '\0';
       
   186         *ptr = '\0';
       
   187         *val = ++ptr;
       
   188         while ( (ptr = strstr(ptr, (*tag)-1)) != NULL )
   202         while ( (ptr = strstr(ptr, (*tag)-1)) != NULL )
   189         {
   203         {
   190             if (*(ptr-1) != '<') { ptr++; continue; }
   204             if (*(ptr-1) != '<') { ptr++; continue; }  /* false positive */
   191             *(ptr-1) = '\0';
   205             *(ptr-1) = '\0';  /* null-terminate tag's children. */
   192             break;
   206             break;
   193         } /* while */
   207         } /* while */
   194 
   208 
       
   209         /* return everything after this tag's children. */
   195         return((ptr == NULL) ? NULL : ptr + 1);
   210         return((ptr == NULL) ? NULL : ptr + 1);
   196     } /* while */
   211     } /* while */
   197 
   212 
   198     return(NULL);
   213     return(NULL);
   199 } /* parse_xml */
   214 } /* parse_xml */