Пример #1
2
static void
parseAnnotation (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb)
{
  cur = cur->children;

  while (cur != NULL) {

    if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) {
      parseP(doc, cur, 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) {
      bufferAppend("\n", 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"poem")) {
      parsePoem(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"cite")) {
      parseCite(doc, cur, fb);

    }

    cur = cur->next;
  }
  return;
}
Пример #2
0
static void
parseSection (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb)
{
  FB2Mark *mark;

  mark = getLink(cur, fb);

  cur = cur->children;
  while (cur != NULL) {

    if (!xmlStrcmp(cur->name, (const xmlChar *)"title")) {
      parseTitle(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"section")) {
      parseSection(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"poem")) {
      parsePoem(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"cite")) {
      parseCite(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"epigraph")) {
      parseEpigraph(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) {
      parseP(doc, cur, 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"subtitle")) {
      int start = fb->utf8_current_index;
      parseP(doc, cur, 0, fb);
      addMark(start, fb->utf8_current_index, BOOKMARK_TYPE, NULL, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) {
      bufferAppend("\n", 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"image")) {
      parseImage(doc, cur, fb);
    }

    cur = cur->next;
  }

  if (mark)
    mark->link_end = fb->text_current_index;

  return;
}
Пример #3
0
static void
parseCite (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb)
{
  xmlChar *content;
  cur = cur->children;

  while (cur != NULL) {

    if (!xmlStrcmp(cur->name, (const xmlChar *)"poem")) {
      parsePoem(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"p") ) {
      parseP(doc, cur, 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) {
      bufferAppend("\n", 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"text-author")) {
      content = xmlNodeGetContent(cur->children);
      if (content) {
	bufferAppend("\t", 1, fb);
	bufferAppend(content, xmlStrlen(content), fb);
	bufferAppend("\n", 1, fb);
      }
      xmlFree(content);

    }

    cur = cur->next;
  }
  return;
}
Пример #4
0
static void
parsePoem (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb)
{
  cur = cur->children;
  while (cur != NULL) {

    if (!xmlStrcmp(cur->name, (const xmlChar *)"title")) {
      parseTitle(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"epigraph")) {
      parseEpigraph(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) {
      parseP(doc, cur, 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) {
      bufferAppend("\n", 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"stanza")) {
      bufferAppend("\n", 1, fb);
      parseStanza(doc, cur, fb);
    }

    cur = cur->next;
  }
  bufferAppend("\n", 1, fb);
  return;
}
Пример #5
0
static void
parseTitle (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb)
{
  int start;

  bufferAppend("\n", 1, fb);

  start = fb->utf8_current_index;

  cur = cur->children;

  while (cur != NULL) {

    if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) {
      parseP(doc, cur, 0, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) {
      bufferAppend("\n", 1, fb);

    }
    cur = cur->next;
  }

  addMark(start, fb->utf8_current_index-1, BOOKMARK_TYPE, NULL, fb);

  bufferAppend("\n", 1, fb);

  return;
}
Пример #6
0
    /**
     * Reads the description from the string
     * @param json the json description as a string
     * @param kd the resulting knapsack data
     */
    static void readJson(const std::string& json, KnapData< T >& kd) {

        struct {
            bool mNSet;
            bool mCSet;
            bool mWSet;
            bool mPSet;
        } checklist = {false, false, false, false};

        JSONNode nd = libjson::parse(json);
        JSONNode::const_iterator i = nd.begin();
        kd.mN = 0;
        kd.mTP = 0;
        kd.mTW = 0;
        kd.mCoe = NULL;


        while (i != nd.end()) {
            std::string name = i->name();
            //std::cout << "node \"" << name << "\"\n";
            if (name == JSON_KNAP_N) {
                kd.mN = i->as_int();
                kd.mCoe = new KnapRecord<T>[kd.mN];
                BNB_ASSERT(kd.mCoe);
                checklist.mNSet = true;
            } else if (name == JSON_KNAP_C) {
                kd.mC = i->as_int();
                checklist.mCSet = true;
            } else if (name == JSON_KNAP_W) {
                BNB_ASSERT(kd.mCoe);
                parseW(*i, kd, checklist.mPSet);
                checklist.mWSet = true;
            } else if (name == JSON_KNAP_P) {
                BNB_ASSERT(kd.mCoe);
                parseP(*i, kd, checklist.mWSet);
                checklist.mPSet = true;
            }
            i++;
        }
    }
Пример #7
0
plyElements parseRow(char* text,int length)
{
	switch(text[0])
	{
		case 'p':
		{
			return parseP(text,length);
		}
		case 'f':
		{
			return FORMAT;
		}
		case 'c':
		{
			return COMMENT;
		}
		case 'e':
		{
			return parseE(text,length);
		}
	}
}
Пример #8
0
static void
parseStanza (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb)
{
  /*xmlChar *content;*/
  cur = cur->children;

  while (cur != NULL) {

    if (!xmlStrcmp(cur->name, (const xmlChar *)"v")) {
      parseP(doc, cur, 1, fb);
      /*
      content = xmlNodeGetContent(cur->children);
      if (content) {
	bufferAppend("\t", 1, fb);
	bufferAppend(content, xmlStrlen(content), fb);
	bufferAppend("\n", 1, fb);
      }
      xmlFree(content);
      */
    }
    cur = cur->next;
  }
  return;
}
Пример #9
0
ParsedElement
Animxmlparser::parseNext ()
{
  ParsedElement parsedElement;
  parsedElement.type = XML_INVALID;
  parsedElement.version = m_version;
  parsedElement.isWpacket = false;

  if (m_reader->atEnd () || m_reader->hasError ())
    {
      m_parsingComplete = true;
      m_traceFile->close ();
      return parsedElement;
    }



  QXmlStreamReader::TokenType token =  m_reader->readNext ();
  if (token == QXmlStreamReader::StartDocument)
    return parsedElement;

  if (token == QXmlStreamReader::StartElement)
    {
      if (m_reader->name () == "anim")
        {
          parsedElement = parseAnim ();
        }
      if (m_reader->name () == "topology")
        {
          parsedElement = parseTopology ();
        }
      if (m_reader->name () == "node")
        {
          parsedElement = parseNode ();
        }
      if (m_reader->name () == "packet")
        {
          parsedElement = parsePacket ();
        }
      if (m_reader->name () == "p")
        {
          parsedElement = parseP ();
        }
      if (m_reader->name () == "wp")
        {
          parsedElement = parseWp ();
        }
      if (m_reader->name () == "wpacket")
        {
          parsedElement = parseWPacket ();
        }
      if (m_reader->name () == "link")
        {
          parsedElement = parseLink ();
        }
      if (m_reader->name () == "nonp2plinkproperties")
        {
          parsedElement = parseNonP2pLink ();
        }
      if (m_reader->name () == "linkupdate")
        {
          parsedElement = parseLinkUpdate ();
        }
      if (m_reader->name () == "nu")
        {
          parsedElement = parseNodeUpdate ();
        }
      if (m_reader->name () == "res")
        {
          parsedElement = parseResource ();
        }
      if (m_reader->name () == "bg")
        {
          parsedElement = parseBackground ();
        }
      if (m_reader->name () == "ncs")
        {
          parsedElement = parseCreateNodeCounter ();
        }
      if (m_reader->name () == "nc")
        {
          parsedElement = parseNodeCounterUpdate ();
        }
      if (m_reader->name () == "pr")
        {
          parsedElement = parsePacketTxRef ();
        }
      if (m_reader->name () == "wpr")
        {
          parsedElement = parseWPacketRxRef ();
        }
      //qDebug (m_reader->name ().toString ());
    }

  if (m_reader->atEnd ())
    {
      m_parsingComplete = true;
      m_traceFile->close ();
    }
  return parsedElement;
}
Пример #10
0
static void
parseTitleInfo (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb)
{

  xmlChar *content;
  cur = cur->children;
  while (cur != NULL) {

    if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) {
      parseP(doc, cur, 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) {
      bufferAppend("\n", 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"genre")) {
      content = xmlNodeGetContent(cur->children);

      if(content) {
	/* add genre */
	int i;
	for (i=0; i<BUF_SIZE-1; i++) {
	  if (fb->genres[i] == NULL) {
	    fb->genres[i] = content;
	    fb->genres[i+1] = NULL;
	    fb->num_genres++;
	    break;
	  }
	}
      }

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"book-title")) {
      content = xmlNodeGetContent(cur->children);
      if (content)
	strncpy(fb->name, content, BUF_SIZE);
      xmlFree(content);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"author")) {
      parseAuthor(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"annotation")) {
      parseAnnotation(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"coverpage")) {
      xmlNodePtr c;
      c = cur->children;
      while (c) {
        if (!xmlStrcmp(c->name, (const xmlChar *)"image")) {
          xmlChar *cover_href;
          cover_href = xmlGetProp(c, (const xmlChar *)"href");
          strncpy(fb->cover_href, cover_href, BUF_SIZE);
          xmlFree (cover_href);
          break;
        }
        c = c->next;
      }
      /*
      content = xmlNodeGetContent(cur->children);
      if (content)
	strncpy(fb->cover_href, content, BUF_SIZE);
      */
      //if (cover_href)
      /*xmlFree(content);*/

    }

    cur = cur->next;
  }
  return;
}