Пример #1
0
/*  7.8  */
void lookupGenVal(SDocData *data,
                  Segment  *seg)
{
/* The string of the segment can contain subststrings what were specified
 * as 'Attribute value tokens' in SWmlDescriptor. ('.com/','.edu', etc.)
 * Search for these strings and substitute them, breaking the segment into
 * furter segments.
 *---------------------------------------------------------------------------
 */
/* Data Structures */
  PString   str       = seg->m_str;
  UINT16    pos       = 0;
  const WCHAR      *s = STR_DATA(str);
  const SWmlNode *node;


/*  Code  */
  for(; pos<STR_LEN(str); ++pos, ++s) {
      node = FIRST_NODE(data->m_desc->m_generalValues[(*s)&0x7f]);
      for(; node; node=node->m_next) {
      DBG_LOG2( (DBG_WML, node->m_name, "     :") );
          if(STR_LEN(str)>=(STR_LEN(node->m_name)+pos)) {
              const WCHAR *p = STR_DATA(node->m_name);
              const WCHAR *e = p + STR_LEN(node->m_name);
              const WCHAR *t = s;
              for(; p<e && *p==*t; p++,t++)
                  ;
              if(p==e) {
                  if(pos) {
                      seg->m_str = newSubString(str, 0, pos, DOCPOOL);
                      seg        = newSegment(data,0,0,seg);
                  }

                  seg->m_str  = 0;
                  seg->m_code = node->m_code;

                  if(STR_LEN(str)>(STR_LEN(node->m_name)+pos)) {
                      newSegment(data,
                                 newSubString(str,
                                           (UINT16)(pos+STR_LEN(node->m_name)),
                                           (UINT16) STR_LEN(str),
                                              DOCPOOL),
                                 0,
                                 seg);
                  }
                deleteString(str, DOCPOOL);
                return; 
              }
          }
      }
  }
}
Пример #2
0
/*  7.5  */
static int matchCP(const PString elem,
                   SCP *scp)
{
/*  Return: 1 - if the substring (from CUR to delimiter) is identical with elem.
 *          0 - otherwise
 *  Side effect: Leave CUR on the delimiter, regardless to the success.
 *---------------------------------------------------------------------------
 */
/*  Data Structures  */
  const WCHAR *p   = CUR;
  const WCHAR *e;

/*  Code  */
  for(; p<END && !ENDCH(*p); p++)        /* walk till separator */
      ;

  if((p-CUR)==STR_LEN(elem)) {
      e = STR_DATA(elem);
      for(; CUR<p && *CUR==*e; CUR++, e++)
          ;
      if(CUR==p)
          return 1;
  }
  CUR = p;
  return 0;
}
Пример #3
0
/*  7.1  */
const SWmlNode * lookupElement(SDocData *data)
{
/* 1. Pick up the name of the current element from event list.
 * 2. Look into table of tags/elements of SWmlDescriptor for it.
 * 3. Return the corresponding node, or the node of the unknown element.
 * 
 * Note: The value of the current XML event must exits.
 * Assume the calling takes place from the proper context.
 *---------------------------------------------------------------------------
 */
/* Data Structures */
  PString           _str;   /* name of the element                  */
  unsigned          _idx;   /* the index of element in the table    */
  const SWmlNode  * _node;  /* traverses the list                   */
  
/*  Code  */
  _str  = data->m_eventList.m_head->m_tokenValue;
  _idx  = (!STR_LEN(_str)) ? 0 : (*STR_DATA(_str))&0x7f;
  _node = FIRST_NODE(data->m_desc->m_elements[_idx]);
  

  while(_node && !STR_SAME(_node->m_name, _str))
      _node = _node->m_next;

  return _node ? _node : g_unknownElement;
}
Пример #4
0
/*  7.4  */
SWmlString * insertString(SDocData *data,
                          PString s)
{
/*  
 *  Place a copy of 's' into the 'm_stringTable' of DocData,
 *  and treat it as 'inline'.
 *
 *---------------------------------------------------------------------------
 */
/* Data Structures */
  SWmlString *_node;

/*  Code  */

  POOL_ALLOC(DOCPOOL, _node);
  _node->m_string = strXDup(s,DOCPOOL);
  _node->m_site   = STR_INLINE;
  _node->m_offset = ~0;
  if(STR_LEN(s)) {
      SLL_INSERT(data->m_stringTable[ (*(STR_DATA(s)))&0x7f], _node);
  }
  else {
      SLL_INSERT(data->m_stringTable[0], _node);
  }

  return _node;
}
Пример #5
0
/*  7.6  */
static void appendToTbl(SDocData   * data,
                        SWmlString * entry,
                        int          must)
{
/*  
 * Append string to the string table of the output binary stream,
 * according to the output character encoding.
 * Note: this function can fail if the output character encoding cannot
 *       represent one of the character.( I cannot use character
 *       entity in the string table.)
 *---------------------------------------------------------------------------
 */
/* Data Structures */
  UINT32  _n;                               /* string length            */
  WCHAR  *_s;                               /* ptr to string            */
  SCCOut *_scc    = &data->m_scc;           /* character converter      */
  UINT32  _offset = data->m_array.m_size;   /* save the current offset  */
  int     _failed = 0;                      /* assume: success          */


/* Code */
  if(entry->m_site==STR_IN_TABLE)
      return;                                   /* it is already there */

  /* Convert and copy */

  _n = STR_LEN(entry->m_string);
  _s = STR_DATA(entry->m_string);

  for( ; _n; _n--,_s++) {
      _scc->m_char = *_s;

      if(!(_scc->m_convert(_scc))) {
          if(must) {
              setWmlError( WML_ERROR_CHAR_CONV, 0, data);
          }
          _failed = 1;
          break;
      }
  }

  _scc->m_char = 0;
  _scc->m_convert(_scc);                /* terminating zero */

  if(!_failed) {
      entry->m_site=STR_IN_TABLE;
      entry->m_offset = _offset;
  }
}
Пример #6
0
/*  7.10  */
static int  ErrorHandler(XML_STATUS   errorCode,
                         PString      context,
                         void       * usrData)
{
/*
-----------------------------------------------------------------------------
*/
/*  Data structures */

  char _buf[256];
  SDocData *_s = (SDocData*)usrData;

/* Code */

  if(!_s->m_error) {
      if(context) {
          wPrint(STR_LEN(context),STR_DATA(context),
                 64,_buf);
          if(_s->m_docURL)
              wmlLOGssss( WSL_LOG_ERROR,
                      "XML error:",
                      (char*)_s->m_docURL,
                      (char*)error2str(errorCode),
                      _buf);
          else
              wmlLOGsss( WSL_LOG_ERROR,
                      "XML error: URL?:",
                      (char*)error2str(errorCode),
                      _buf);
      }
      else {
          if(_s->m_docURL)
              wmlLOGsss( WSL_LOG_ERROR,
                      "XML error: ",
                      (char*)_s->m_docURL,
                      (char*)error2str(errorCode));
          else
              wmlLOGss( WSL_LOG_ERROR,
                      "XML error: URL?: %s",
                      (char*)error2str(errorCode));
      }
      _s->m_error = errorCode;
  }

  return 1;
}
Пример #7
0
/*  7.3  */
SWmlString  * lookupString(SDocData *data,
                           PString str)
{
/*  Search for 'str' in 'stringTable' of DocData.
 *  Return the node or NULL.
 *---------------------------------------------------------------------------
 */
/* Data Structures */
  unsigned     _idx  = (!STR_LEN(str)) ? 0 : (*STR_DATA(str))&0x7f;
  SWmlString * _node = FIRST_NODE(data->m_stringTable[_idx]);
  
/*  Code  */
  while(_node && !STR_SAME(_node->m_string, str))
      _node = _node->m_next;

  return _node;
}
Пример #8
0
*/	REBSER *Copy_Bytes(const REBYTE *src, REBINT len)
/*
**		Create a string series from the given bytes.
**		Source is always latin-1 valid. Result is always 8bit.
**
***********************************************************************/
{
    REBSER *dst;

    if (len < 0) len = LEN_BYTES(src);

    dst = Make_Binary(len);
    memcpy(STR_DATA(dst), src, len);
    SERIES_TAIL(dst) = len;
    STR_TERM(dst);

    return dst;
}
Пример #9
0
/*  7.10  */
void setWmlError(WML_VALIDATION_ERROR   status,
                 PString     context,
                 SDocData   *data)
{
/* Set the status of the document if it was clean.
 *---------------------------------------------------------------------------
 */
/* Data structures */
  char _buf[256];
/* Code */

  if(!data->m_error) {
      if(context) {
          wPrint(STR_LEN(context),STR_DATA(context),
                 64,_buf);
          if(data->m_docURL)
              wmlLOGssss( WSL_LOG_ERROR,
                      "WML error:",
                      (char*)data->m_docURL,
                      (char*)error2str(status),
                      _buf);
          else
              wmlLOGsss( WSL_LOG_ERROR,
                      "WML error: URL?:",
                      (char*)error2str(status),
                      _buf);
      }
      else {
          if(data->m_docURL)
              wmlLOGsss( WSL_LOG_ERROR,
                      "WML error:",
                      (char*)data->m_docURL,
                      (char*)error2str(status));
          else
              wmlLOGss( WSL_LOG_ERROR,
                      "WML error: URL?:",
                      (char*)error2str(status));
      }

      data->m_error = status;
  }

}
Пример #10
0
/*  7.2  */
const SWmlNode * lookupAttr(SDocData *data,
                            const SWmlNode *element)
{
/* 1. Pick up the name of the current current attribute from event list.
 * 2. If the 'element' had that attribute: return it.
 * 3. If the attribute was found in the table of attributes of the
 *    SWmlDescriptor: return it.
 * 4. Otherwise return the 'unknown' attribute.
 *
 * Note: The value of the current XML event must exits.
 * Assume the calling takes place from the proper context.
 *---------------------------------------------------------------------------
 */
/* Data Structures */
  PString           _str  = data->m_eventList.m_head->m_tokenValue;
  const SWmlNode  * _node = FIRST_NODE(element->m_children);
  unsigned          _idx;
  
/*  Code  */
  DBG_LOG2( (DBG_WML, _str, "lookupAttr:") );
  while(_node && !STR_SAME(_node->m_name, _str)) {
      DBG_LOG2( (DBG_WML, _node->m_name, "   ?:") );
      _node = _node->m_next;
  }

  if(!_node) { 
      /* global attributes */
      _idx  = (!STR_LEN(_str)) ? 0 : (*STR_DATA(_str))&0x7f;
      _node = FIRST_NODE(data->m_desc->m_attributes[_idx]);

      while(_node && !STR_SAME(_node->m_name, _str))
          _node = _node->m_next;
  }
  DBG_LOG( (DBG_WML, "lookupAttr: found: %p",_node ) );

  return _node ? _node : g_unknownAttribute;
}