Esempio n. 1
0
void ValueEnumerator::EnumerateAttributes(AttributeList PAL) {
  if (PAL.isEmpty()) return;  // null is always 0.

  // Do a lookup.
  unsigned &Entry = AttributeListMap[PAL];
  if (Entry == 0) {
    // Never saw this before, add it.
    AttributeLists.push_back(PAL);
    Entry = AttributeLists.size();
  }

  // Do lookups for all attribute groups.
  for (unsigned i = 0, e = PAL.getNumSlots(); i != e; ++i) {
    IndexAndAttrSet Pair = {PAL.getSlotIndex(i), PAL.getSlotAttributes(i)};
    unsigned &Entry = AttributeGroupMap[Pair];
    if (Entry == 0) {
      AttributeGroups.push_back(Pair);
      Entry = AttributeGroups.size();
    }
  }
}
Esempio n. 2
0
void saveElement(xmlElementPtr elem, xmlBufferPtr buf)
{
  Q_UNUSED(buf);
  if (elem)
  {
    QString elemName = QString((const char*)elem->name);
    QFile file( DTD::dirName + elemName + ".tag" );
    if ( file.open( IO_WriteOnly ) )
    {
      QTextStream stream( &file );
      stream.setEncoding(QTextStream::UnicodeUTF8);
      stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
      stream << "<!DOCTYPE TAGS>" << endl
             << "<TAGS>" << endl
             << "<tag name=\"" << elemName << "\">" << endl << endl;

      xmlElementPtr  el_ptr; /* Pointer to an element description */
      xmlAttributePtr at_ptr;
      el_ptr = xmlGetDtdElementDesc(DTD::dtd_ptr, elem->name);
      AttributeList attributes;
      attributes.setAutoDelete(true);
      if (el_ptr)
      {
        at_ptr = el_ptr->attributes;
        while (at_ptr) {
          Attribute *attr =  new Attribute;
          attr->name = QString((const char*)at_ptr->name);
          switch (at_ptr->def) {
            case 1: {attr->status = "optional"; break;} //NONE
            case 2: {attr->status = "required"; break;} //REQUIRED
            case 3: {attr->status = "implied"; break;} //IMPLIED
            case 4: {attr->status = "fixed"; break;} //FIXED
          }
          attr->defaultValue = QString((const char*)at_ptr->defaultValue);
          xmlEnumerationPtr enum_ptr;
          enum_ptr = at_ptr->tree;
          while (enum_ptr) {
            attr->values += QString((const char*)enum_ptr->name);
            enum_ptr = enum_ptr->next;
          }
          QString attrtype;
          switch (at_ptr->atype) {
            case 9: {attrtype = "list"; break;}
            default: {attrtype = "input"; break;} //TODO handle the rest of types
          }
          attr->type = attrtype;
          attributes.append(attr);
          at_ptr = at_ptr->nexth;
       }
      }
      if (!attributes.isEmpty())
        stream << QuantaCommon::xmlFromAttributes(&attributes);
      const xmlChar *list_ptr[MAX_CHILD_ELEMENTS];
      int childNum = 0;
      childNum = xmlValidGetPotentialChildren(el_ptr->content, list_ptr,
                        &childNum, MAX_CHILD_ELEMENTS);

      if (childNum > 0)
      {
        stream << "<children>" << endl;
        for( int i = 0; i < childNum; i++ )
        {
          stream << "  <child name=\"" << QString((const char*)list_ptr[i]) << "\"";
          xmlElementPtr child_ptr = xmlGetDtdElementDesc(DTD::dtd_ptr, list_ptr[i]);
          if (child_ptr && child_ptr->content && child_ptr->content->ocur)
          {
            //if (child_ptr->content->ocur == XML_ELEMENT_CONTENT_PLUS)
            //{
//              stream << " usage=\"required\"";
  //          }
            QString ocur;
            switch (child_ptr->content->ocur)
            {
              case 1: {ocur = "once"; break;}
              case 2: {ocur = "opt"; break;}
              case 3: {ocur = "mult"; break;}
              case 4: {ocur = "plus"; break;}
            }
            stream << " usage=\"" << ocur << "\"";
            QString name = QString((const char*)child_ptr->content->name);
            if (name == "#PCDATA")
               name == "#text";
            stream << " name2=\"" << name << "\"";
          }
          stream << " />" << endl;
        }

        stream << "</children>" << endl;
        stream << endl;
      }
      /*
      xmlElementContentPtr content_ptr = el_ptr->content;
      if (content_ptr)
      {
        stream << "<children>" << endl;
        while (content_ptr)
        {
          if (!QString((const char*)content_ptr->name).isEmpty())
          {
            stream << "  <child name=\"" << QString((const char*)content_ptr->name) << "\"";
            QString ocur;
            switch (content_ptr->ocur)
            {
              case 1: {ocur = "once"; break;}
              case 2: {ocur = "opt"; break;}
              case 3: {ocur = "mult"; break;}
              case 4: {ocur = "plus"; break;}
            }
            stream << " usage=\"" << ocur << "\"";
            stream << " />" << endl;
          }
          if (content_ptr->c1)
              content_ptr = content_ptr->c1;
          else if (content_ptr->c2)
              content_ptr = content_ptr->c2;
          else
          {
            if (content_ptr == el_ptr->content)
              break;
            if (content_ptr->parent)
            {
              if (content_ptr == content_ptr->parent->c1)
                  content_ptr->c1 = 0L;
              else
                  content_ptr->c2 = 0L;
            }
            content_ptr = content_ptr->parent;
          }
        }
        stream << "</children>" << endl;
      } */
      stream << "</tag>" << endl
             << "</TAGS>" << endl;
      file.close();
    }
 }
}