home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / rdf / src / xmlss.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.0 KB  |  170 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /* 
  20.    This is some glue code for a semi-parsing CSS. Its used to
  21.    output html from XML.
  22.    This will be changed when we incorporate the real xml parser 
  23.    from James Clark will replace this  within the next few weeks.
  24.  
  25.    For more information on this file, contact rjc or guha 
  26.    For more information on RDF, look at the RDF section of www.mozilla.org
  27.    For more info on XML in navigator, look at the XML section
  28.    of www.mozilla.org.
  29. */
  30.  
  31. #include "xmlss.h"
  32.  
  33.  
  34.  
  35. int
  36. parseNextXMLCSSBlob (NET_StreamClass *stream, char* blob, int32 size)
  37. {
  38.   StyleSheet ss;
  39.   int32 n, last, m;
  40.   PRBool somethingseenp = false;
  41.   n = last = 0;
  42.   
  43.   ss = (StyleSheet)(stream->data_object);
  44.   if ((ss == NULL) || (size < 0)) {
  45.     return MK_INTERRUPTED;
  46.   }
  47.   
  48.   while (n < size) {
  49.     char c = blob[n];
  50.     m = 0;
  51.     memset(ss->line, '\0', ss->lineSize);
  52.     if (ss->holdOver[0] != '\0') {
  53.       memcpy(ss->line, ss->holdOver, strlen(ss->holdOver));
  54.       m = strlen(ss->holdOver);
  55.       memset(ss->holdOver, '\0', RDF_BUF_SIZE);
  56.     }
  57.     while ((m < 300) && (c != '{') && (c != '}')) {
  58.       ss->line[m] = c;
  59.       m++;
  60.       somethingseenp = (somethingseenp || ((c != ' ') && 
  61.                        (c != '\r') && (c != '\n')));
  62.       n++;
  63.       if (n < size) {
  64.     c = blob[n]; 
  65.       }  else break;
  66.     }
  67.     if (c == '}') ss->line[m] = c;
  68.     n++;
  69.     if (m > 0) {
  70.       if ((c == '}') || (c == '{')) {
  71.     last = n;
  72.     if (c == '{') ss->holdOver[0] = '{'; 
  73.     if (somethingseenp) {
  74.       parseNextXMLCSSElement(ss, ss->line);
  75.     } else if (size > last) {
  76.       memcpy(ss->holdOver, ss->line, m);
  77.     }
  78.       } else if (c == '{') ss->holdOver[0] = '{';
  79.     }
  80.   }
  81.   return(size);
  82. }
  83.  
  84.  
  85.  
  86. void
  87. parseNextXMLCSSElement (StyleSheet ss, char* ele)
  88. {
  89.   if (ele[0] == '{') {
  90.     char* sty = getMem(strlen(ele)-1);
  91.     memcpy(sty, &ele[1], strlen(ele)-2);
  92.     ss->el->style = sty;
  93.   } else {
  94.      StyleElement se = (StyleElement) getMem(sizeof(StyleElementStruct));
  95.      size_t numTags,  size, n, count;
  96.      se->next = ss->el;
  97.      ss->el = se;
  98.      size = strlen(ele);
  99.      count = n = 0;
  100.      numTags = countTagStackSize(ele);
  101.      while (count < numTags) {
  102.        size_t st = 0; 
  103.        char** tgs =  (char**) getMem(numTags * sizeof(char**));
  104.        se->tagStack = tgs;
  105.        while (st < numTags) {     
  106.      *(tgs + st++) = getNextSSTag(ele, &n);
  107.        }
  108.        count++;
  109.      }
  110.   }
  111. }
  112.  
  113.  
  114.  
  115. size_t
  116. countSSNumTags (char* ele)
  117. {
  118.   size_t n = 0;
  119.   size_t m = 1;
  120.   size_t sz = strlen(ele);
  121.   while (n < sz) {
  122.     if (ele[n++] == ',') m++;
  123.   }
  124.   return m;
  125. }
  126.  
  127.  
  128.  
  129. size_t
  130. countTagStackSize (char* ele)
  131. {
  132.   size_t n = 0;
  133.   size_t m = 0;
  134.   PRBool inSpace = 1;
  135.   size_t sz = strlen(ele);
  136.   while (n < sz) {
  137.     if (ele[n] == ',') break;
  138.     if ((ele[n] != ' ') && (ele[n] != '\r') && (ele[n] != '\n')) {
  139.       if (inSpace) {
  140.           m++;
  141.           inSpace = 0;
  142.       }
  143.     } else inSpace = 1;
  144.     n++;
  145.   }
  146.   return m;
  147. }
  148.  
  149.  
  150.  
  151. char*
  152. getNextSSTag (char* ele, size_t* n)
  153. {
  154.   char tag[100];
  155.   size_t m = 0;
  156.   char c = ele[*n];
  157.   size_t s = strlen(ele);
  158.   memset(tag, '\0', 100);
  159.   while ((c == '\r') || (c == ' ') || (c == '\n')) {
  160.     *n = *n + 1;
  161.     c = ele[*n];
  162.   }
  163.   while ((c != ' ') && (c != ',') && (*n < s)) {
  164.     tag[m++] = c;
  165.     *n = *n + 1;
  166.     c = ele[*n];
  167.   }
  168.   return copyString(tag);
  169. }
  170.