Example #1
0
void notes_get_references_from_editor(GtkTextBuffer * textbuffer, vector < Reference > &references, vector < ustring > &messages)
/*
 Gets all references from the notes editor.
 Normalizes them.
 Produces messages on trouble.
 Handles notes that span more than one chapter.
 */
{
    // Get all lines from the textbuffer.
    vector < ustring > lines;
    textbuffer_get_lines(textbuffer, lines);
    // When discovering a reference from a user's entry, use previous values,
    // so that it becomes quicker for a user to enter new references.
    // If Leviticus 10:11 is already there, and the user wishes to add verse
    // 12 also, he just enters 12 on a line, and that' it.
    Reference previousreference;
    for (unsigned int i = 0; i < lines.size(); i++) {
        if (!lines[i].empty()) {
            // Normalize reference.
            Reference reference;
            if (reference_discover(previousreference, lines[i], reference)) {
                ustring ch1, vs1, ch2, vs2;
                if (chapter_span_discover(lines[i], ch1, vs1, ch2, vs2)) {
                    // We cross the chapter boundaries.
                    // Store as two or more references,
                    // the first one going up to the end of the chapter,
                    // and the second one starting at the next chapter verse 1,
                    // and any chapter in-between.
                    extern Settings *settings;
                    ProjectConfiguration *projectconfig = settings->projectconfig(settings->genconfig.project_get());
                    Reference ref(reference.book_get(), convert_to_int(ch1), vs1);
                    ustring lastverse = versification_get_last_verse(projectconfig->versification_get(), reference.book_get(), convert_to_int(ch1));
                    ref.verse_append("-" + lastverse);
                    references.push_back(ref);
                    for (unsigned int ch = convert_to_int(ch1) + 1; ch < convert_to_int(ch2); ch++) {
                        Reference ref(reference.book_get(), ch, "1");
                        ustring lastverse = versification_get_last_verse(projectconfig->versification_get(), reference.book_get(), ch);
                        ref.verse_append("-" + lastverse);
                        references.push_back(ref);
                    }
                    ref.chapter_set(convert_to_int(ch2));
                    ref.verse_set("1-" + vs2);
                    references.push_back(ref);
                    // Store values to discover next reference.
                    previousreference.book_set(reference.book_get());
                    previousreference.chapter_set(convert_to_int(ch2));
                    previousreference.verse_set(vs2);
                } else {
                    // We've a normal reference.
                    // Store reference.
                    references.push_back(reference);
                    // Store values to discover next reference.
                    previousreference.assign(reference);
                }
            } else {
                messages.push_back(_("Reference ") + lines[i] + _(" is not valid and has been removed."));
            }
        }
    }
}
Reference WindowCheckKeyterms::get_reference (const ustring& text)
// Generates a reference out of the text.
{
  Reference ref;
  ustring book, chapter, verse = ref.verse_get();
  decode_reference(text, book, chapter, verse);
  ref.book_set(books_english_to_id (book));
  ref.chapter_set(convert_to_int (chapter));
  ref.verse_set(verse);
  return ref;
}
Example #3
0
void OTQuotations::read()
{
  // Get contents of the data file. Bail out if not there.
  ustring xmlfilename = gw_build_filename(Directories->get_package_data(), "ot-quotations-in-nt.xml");
  if (!g_file_test(xmlfilename.c_str(), G_FILE_TEST_IS_REGULAR))
    return;
  gchar *contents;
  g_file_get_contents(xmlfilename.c_str(), &contents, NULL, NULL);

  /*
     Read the xml data. Example:
     <set>
     <nt book="Matthew" chapter="1" verse="23"/>
     <ot book="Isaiah" chapter="8" verse="8"/>
     <ot book="Isaiah" chapter="8" verse="10"/>
     <lxx>1</lxx>
     </set>
   */
  xmlParserInputBufferPtr inputbuffer;
  inputbuffer = xmlParserInputBufferCreateMem(contents, strlen(contents), XML_CHAR_ENCODING_NONE);
  xmlTextReaderPtr reader = xmlNewTextReader(inputbuffer, NULL);
  if (reader) {
    char *opening_element = NULL;
    OTQuotation quotation(0);
    while ((xmlTextReaderRead(reader) == 1)) {
      switch (xmlTextReaderNodeType(reader)) {
      case XML_READER_TYPE_ELEMENT:
        {
          opening_element = (char *)xmlTextReaderName(reader);
          if (!strcmp(opening_element, "set")) {
            quotation.reference.clear();
            quotation.referents.clear();
            quotation.lxx = false;
	    free(opening_element); opening_element = NULL; // not used next loop iteration
          }
          else if (!strcmp(opening_element, "nt") || !strcmp(opening_element, "ot")) {
            Reference ref;
            char *attribute;
            attribute = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "book");
            if (attribute) {
              ref.book_set(books_english_to_id(attribute));
              free(attribute);
            }
            attribute = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "chapter");
            if (attribute) {
              ref.chapter_set(convert_to_int(attribute));
              free(attribute);
            }
            attribute = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "verse");
            if (attribute) {
              ref.verse_set(attribute);
              free(attribute);
            }
            if (!strcmp(opening_element, "nt")) {
              quotation.reference.assign(ref);
            }
            if (!strcmp(opening_element, "ot")) {
              quotation.referents.push_back(ref);
            }
			// cannot free(opening_element) because it will be used next loop iter in following switch case
          }
		  break;
        }
      case XML_READER_TYPE_TEXT:
        {
          char *text = (char *)xmlTextReaderValue(reader);
          if (opening_element && text) {
            if (!strcmp(opening_element, "lxx")) {
              quotation.lxx = convert_to_bool(text);
            }
            free(text);
			free(opening_element); opening_element = NULL;
          }
          break;
        }
      case XML_READER_TYPE_END_ELEMENT:
        {
          char *closing_element = (char *)xmlTextReaderName(reader);
          if (!strcmp(closing_element, "set")) {
            quotations_nt_order.push_back(quotation);
          }
		  free(closing_element);
          break;
        }
      }
    }
  }
  // Free memory.
  if (reader)
    xmlFreeTextReader(reader);
  if (inputbuffer)
    xmlFreeParserInputBuffer(inputbuffer);
  if (contents)
    g_free(contents);
}