コード例 #1
0
ファイル: notes_utils.cpp プロジェクト: postiffm/bibledit-gtk
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."));
            }
        }
    }
}
コード例 #2
0
ustring resource_url_enter_reference(const ustring& constructor, map <unsigned int, ustring>& books, map <unsigned int, ustring>& books2, const Reference& reference)
{
  ustring url (constructor);
  replace_text(url, resource_url_constructor_book(), books[reference.book_get()]);
  replace_text(url, resource_url_constructor_book2(), books2[reference.book_get()]);
  replace_text(url, resource_url_constructor_chapter(), convert_to_string(reference.chapter_get()));
  replace_text(url, resource_url_constructor_verse(), number_in_string(reference.verse_get()));
  return url;
}
コード例 #3
0
void WindowsOutpost::SantaFeFocusReferenceSet(const Reference & reference)
// Schedules a reference to be sent to the santa fe focus system.
{
  if (!reference.book_get())
    return;
  ustring bk = books_id_to_paratext(reference.book_get());
  if (bk.empty())
    return;
  santafefocus_reference_set_value = "SantaFeFocusReferenceSet " + bk + " " + convert_to_string(reference.chapter_get()) + ":" + reference.verse_get();
}
コード例 #4
0
void WindowsOutpost::BibleWorksReferenceSet(const Reference & reference)
// Schedules a reference to be sent to BibleWorks.
{
  if (!reference.book_get())
    return;
  // As it does not respond properly to chapter/verses that are 0, care for that.
  unsigned int goto_ch = reference.chapter_get();
  if (goto_ch == 0)
    goto_ch = 1;
  ustring goto_vs = reference.verse_get();
  if (goto_vs == "0")
    goto_vs = "1";
  ustring bw_book = books_id_to_bibleworks(reference.book_get());
  if (bw_book.empty())
    return;
  bibleworks_reference_set_value = "BibleWorksReferenceSet " + bw_book + " " + convert_to_string(goto_ch) + ":" + goto_vs;
}
コード例 #5
0
void WindowsOutpost::OnlineBibleReferenceSet(const Reference & reference)
// Schedules a reference to be sent to the Online Bible.
// Sample: 
// OLB ShowPassage AV "Mt 10:5"
{
  // Ensure that the Online Bible server is connected.
  online_bible_server_connect (true);

  // Send the references.
  if (!reference.book_get())
    return;
  if (!reference.chapter_get())
    return;
  if (reference.verse_get().empty())
    return;
  onlinebible_reference_set_value = "OLB ShowPassage AV \"" + books_id_to_online_bible (reference.book_get()) + " " + convert_to_string(reference.chapter_get()) + ":" + reference.verse_get() + "\"";
}
コード例 #6
0
ファイル: notes_utils.cpp プロジェクト: postiffm/bibledit-gtk
void notes_store_index_entry (sqlite3 *db, gint32 id)
{
    gchar *sql;

    // Delete optional previous entry with "id".
    sql = g_strdup_printf("delete from notes where id = %d;", id);
    sqlite3_exec(db, sql, NULL, NULL, NULL);
    g_free(sql);

    // Read the note with "id".
    ustring note;
    ustring project;
    ustring references;
    ustring category;
    int date_created;
    ustring user_created;
    int date_modified;
    ustring logbook;
    notes_read_one_from_file (id, note, project, references, category, date_created, user_created, date_modified, logbook);

    // Bail out if there's no note.
    if (note.empty()) {
        return;
    }

    // Attend to the id: use variable "id".

    // Attend to the encoded references.
    Parse parse(references, false);
    ustring encoded_references;
    for (unsigned int i = 0; i < parse.words.size(); i++) {
        Reference oldRef;
        Reference newRef;
        reference_discover(oldRef, parse.words[i], newRef);
        ustring book = books_id_to_english(newRef.book_get());
        ustring chapter = convert_to_string(newRef.chapter_get());
        vector < int >verses = verses_encode(newRef.verse_get());
        int book_chapter = reference_to_numerical_equivalent(book, chapter, "0");
        for (unsigned int i2 = 0; i2 < verses.size(); i2++) {
            encoded_references.append(" ");
            encoded_references.append(convert_to_string(int (book_chapter + verses[i2])));
        }
    }
    encoded_references.append(" ");

    // Attend to the project: use variable "project".
    // Apostrophies need to be doubled before storing them.
    project = double_apostrophy(project);

    // Attend to the category: use variable "category".
    // Apostrophies need to be doubled before storing them.
    category = double_apostrophy(category);

    // Attend to the note text in case folded form
    // Apostrophies need to be doubled before storing them.
    note = note.casefold ();
    note = double_apostrophy(note);

    // Attend to the date created: use variable "date_created".

    // Attend to the date modified: use variable "date_modified".

    // Put new data in the database.
    sql = g_strdup_printf("insert into notes values (%d, '%s', '%s', '%s', '%s', %d, %d);",
                          id, encoded_references.c_str(), project.c_str(), category.c_str(), note.c_str(), date_created, date_modified);
    sqlite3_exec(db, sql, NULL, NULL, NULL);
    g_free(sql);
}
コード例 #7
0
ファイル: kjv.cpp プロジェクト: postiffm/bibledit-gtk
void kjv_get_strongs_data (const Reference& reference, vector <ustring>& strongs, vector <ustring>& words)
// This gets the words and their applicable Strong's numbers for a verse.
{
  sqlite3 *db;
  int rc;
  char *error = NULL;
  try {
    // Open the database.
    rc = sqlite3_open(kjv_sql_filename().c_str(), &db);
    if (rc)
      throw runtime_error(sqlite3_errmsg(db));
    sqlite3_busy_timeout(db, 1000);
    // Retrieve the bits.
    SqliteReader reader(0);
    char *sql;
    sql = g_strdup_printf("select fragment, lemma from kjv where book = %d and chapter = %d and verse = %d order by item asc;", reference.book_get(), reference.chapter_get(), convert_to_int (reference.verse_get()));
    rc = sqlite3_exec(db, sql, reader.callback, &reader, &error);
    g_free(sql);
    if (rc) {
      throw runtime_error(sqlite3_errmsg(db));
    }
    words = reader.ustring0;
    strongs = reader.ustring1;
  }
  catch(exception & ex) {
    gw_critical(ex.what());
  }
  sqlite3_close(db);
}
コード例 #8
0
ファイル: kjv.cpp プロジェクト: postiffm/bibledit-gtk
void kjv_import_sword (const ustring& textfile, const ustring& database)
{
  // Show the progress. KJV has 31102 verses.
  ProgressWindow progresswindow (_("Importing King James Bible"), false);
  progresswindow.set_iterate (0, 1, 31102);
  gchar * contents;
  g_file_get_contents(textfile.c_str(), &contents, NULL, NULL);
  if (!contents)
    return;

  // Create the database, put it in fast mode.
  unix_unlink (database.c_str());
  sqlite3 *db;
  sqlite3_open(database.c_str(), &db);
  sqlite3_exec(db, "create table kjv (book integer, chapter integer, verse integer, item integer, fragment text, lemma text);", NULL, NULL, NULL);
  sqlite3_exec(db, "PRAGMA synchronous=OFF;", NULL, NULL, NULL);

  // Parse input.
  xmlParserInputBufferPtr inputbuffer;
  inputbuffer = xmlParserInputBufferCreateMem(contents, strlen (contents), XML_CHAR_ENCODING_NONE);
  xmlTextReaderPtr reader = xmlNewTextReader(inputbuffer, NULL);
  if (reader) {
    bool within_relevant_element = false;
    Reference reference (0, 0, "0");
    unsigned int item_number = 0;
    ustring textfragment;
    ustring lemmata;
    while ((xmlTextReaderRead(reader) == 1)) {
      switch (xmlTextReaderNodeType(reader)) {
      case XML_READER_TYPE_ELEMENT:
        {
          xmlChar *element_name = xmlTextReaderName(reader);
          // Deal with a verse element.
          if (!xmlStrcmp(element_name, BAD_CAST "verse")) {
            progresswindow.iterate();
            char *attribute;
            attribute = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "osisID");
            if (attribute) {
              Parse parse (attribute, false, ".");
              if (parse.words.size() == 3) {
                reference.assign(books_osis_to_id (parse.words[0]), // book
				 convert_to_int (parse.words[1]),   // chapter
				 parse.words[2]);                   // verse
              } else {
                gw_critical (attribute);
              }
              free(attribute);
            }
            item_number = 0;
          }
          // Deal with a w element.
          if (!xmlStrcmp(element_name, BAD_CAST "w")) {
            within_relevant_element = true;
            item_number++;
            textfragment.clear();
            lemmata.clear();
            char *attribute;
            attribute = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "lemma");
            if (attribute) {
              lemmata = attribute;
              free(attribute);
            }
          }
          break;
        }
      case XML_READER_TYPE_TEXT:
        {
          if (within_relevant_element) {
            xmlChar *text = xmlTextReaderValue(reader);
            if (text) {
              textfragment = (const char *)text;
              xmlFree(text);
              textfragment = textfragment.casefold();
            }
          }
          break;
        }
      case XML_READER_TYPE_END_ELEMENT:
        {
          xmlChar *element_name = xmlTextReaderName(reader);
          if (!xmlStrcmp(element_name, BAD_CAST "w")) {
            replace_text (lemmata, "strong:", "");
            char *sql;
            sql = g_strdup_printf("insert into kjv values (%d, %d, %d, %d, '%s', '%s');", 
                                  reference.book_get(), reference.chapter_get(), convert_to_int (reference.verse_get()), 
                                  item_number, 
                                  double_apostrophy (textfragment).c_str(), lemmata.c_str());
            sqlite3_exec(db, sql, NULL, NULL, NULL);
            g_free(sql);
            within_relevant_element = false;
          }
          break;
        }
      }
    }
  }
  if (reader)
    xmlFreeTextReader(reader);
  if (inputbuffer)
    xmlFreeParserInputBuffer(inputbuffer);

  // Close database.
  sqlite3_close(db);
  
  // Free xml data.    
  g_free(contents);
}
コード例 #9
0
void WindowCheckKeyterms::html_write_keyterms (HtmlWriter2& htmlwriter, unsigned int keyword_id)
{
  // Get data about the project.
  extern Settings *settings;
  ustring project = settings->genconfig.project_get();
  ProjectConfiguration *projectconfig = settings->projectconfig(project);
  ustring versification = projectconfig->versification_get();

  // Add action links.
  htmlwriter.paragraph_open ();
  htmlwriter.hyperlink_add ("index", "[Index]");
  htmlwriter.text_add (" ");
  htmlwriter.hyperlink_add ("send", _("[Send to references window]"));
  htmlwriter.paragraph_close ();

  // Add the keyterm itself.
  ustring keyterm;
  keyterms_get_term(keyword_id, keyterm);
  htmlwriter.heading_open (3);
  htmlwriter.text_add (keyterm);
  htmlwriter.heading_close();
  
  // Retrieve the renderings.
  vector <ustring> renderings;
  vector <bool> wholewords;
  vector <bool> casesensitives;
  get_renderings(renderings, wholewords, casesensitives);

  // Get the data for the keyword identifier.
  ustring dummy;
  ustring information;
  keyterms_get_data(keyword_id, dummy, information, references);

  // Divide the information into lines.
  ParseLine parseline (information);
  
  // Write the information.
  for (unsigned int i = 0; i < parseline.lines.size(); i++) {
 
    information = parseline.lines[i];
    htmlwriter.paragraph_open ();
    size_t pos = information.find (keyterms_reference_start_markup ());
    while (pos != string::npos) {
      htmlwriter.text_add (information.substr (0, pos));
      information.erase (0, pos + keyterms_reference_start_markup ().length());
      pos = information.find (keyterms_reference_end_markup ());
      if (pos != string::npos) {
        // Extract the reference.
        htmlwriter.paragraph_close ();
        ustring original_reference_text = information.substr (0, pos);
        Reference reference = get_reference (original_reference_text);
        // Remap the reference.
        {
          Mapping mapping(versification, reference.book_get());
          vector <int> chapters;
          vector <int> verses;
          mapping.original_to_me(reference.chapter_get(), reference.verse_get(), chapters, verses);
          if (!chapters.empty()) {
            reference.chapter_set(chapters[0]);
            reference.verse_set(convert_to_string (verses[0]));
          }
        }
        ustring remapped_reference_text = reference.human_readable ("");
        ustring displayed_reference_text (remapped_reference_text);
        if (remapped_reference_text != original_reference_text) {
          displayed_reference_text.append (" (");
          displayed_reference_text.append (original_reference_text);
          displayed_reference_text.append (")");
        }
        // Add the reference with hyperlink.
        htmlwriter.hyperlink_add ("goto " + remapped_reference_text, remapped_reference_text);
        information.erase (0, pos + keyterms_reference_end_markup ().length());
        // Add the reference's text.
        ustring verse = project_retrieve_verse(project, reference);
        if (verse.empty()) {
          verse.append(_("<empty>"));
        } else {
          CategorizeLine cl(verse);
          cl.remove_verse_number(reference.verse_get());
          verse = cl.verse;
        }
        htmlwriter.text_add (" ");

        // Add the verse plus markup for approved text.
        vector <size_t> startpositions;
        vector <size_t> lengths;
        size_t processposition = 0;
        if (find_renderings (verse, renderings, wholewords, casesensitives, &startpositions, &lengths)) {
          quick_sort (startpositions, lengths, 0, startpositions.size());
          // Overlapping items need to be combined to avoid crashes.
          xml_combine_overlaps (startpositions, lengths);
          for (unsigned int i = 0; i < startpositions.size(); i++) {
            htmlwriter.text_add (verse.substr (0, startpositions[i] - processposition));
            htmlwriter.bold_open();
            htmlwriter.text_add (verse.substr (startpositions[i] - processposition, lengths[i]));
            htmlwriter.bold_close();
            verse.erase (0, startpositions[i] - processposition + lengths[i]);
            processposition = startpositions[i] + lengths[i];
          }
          // Add whatever is left over of the verse. This could be the full verse in case it wasn't processed.
          htmlwriter.text_add (verse);
        }
        else
        {
        	htmlwriter.highlight_open();
        	htmlwriter.text_add (verse);
        	htmlwriter.highlight_close();
        }

        // Proceed to next.
        htmlwriter.paragraph_open ();
        pos = information.find (keyterms_reference_start_markup ());
      }
    }
    htmlwriter.text_add (information);
    htmlwriter.paragraph_close ();
  }
}
コード例 #10
0
void OTQuotations::get(Reference & reference, vector < Reference > &references, vector < ustring > &comments)
/*
Retrieves an Old Testament quotation of a New Testament reference.
This function does a bit more too. If an OT reference is passed, it also looks 
up the place in the NT where this is quoted.
reference: The input reference.
references: The output reference: contains the related references.
*/
{
  // Read data if we've nothing yet.
  if (quotations_nt_order.empty())
    read();

  // Store the original reference.
  references.push_back(reference);
  comments.push_back(_("Current one"));

  // Remap the references.
  extern Settings *settings;
  ustring project = settings->genconfig.project_get();
  ProjectConfiguration *projectconfig = settings->projectconfig(project, false);
  Mapping mapping(projectconfig->versification_get(), reference.book_get());
  for (unsigned int i = 0; i < quotations_nt_order.size(); i++) {
    mapping.book_change(quotations_nt_order[i].reference.book_get());
    mapping.original_to_me(quotations_nt_order[i].reference);
    for (unsigned int i2 = 0; i2 < quotations_nt_order[i].referents.size(); i2++) {
      mapping.book_change(quotations_nt_order[i].referents[i2].book_get());
      mapping.original_to_me(quotations_nt_order[i].referents[i2]);
    }
  }

  // Go through the quotations looking for matching ones.
  bool lxx = false;
  for (unsigned int i = 0; i < quotations_nt_order.size(); i++) {
    // If this is a NT reference, look for the corresponding OT quotations.
    if (reference.equals(quotations_nt_order[i].reference)) {
      for (unsigned int i2 = 0; i2 < quotations_nt_order[i].referents.size(); i2++) {
        references.push_back(quotations_nt_order[i].referents[i2]);
        comments.push_back(comment(_("Quotation"), lxx));
      }
    }
    // If this is an OT reference, look for possible other ones in the OT, and the NT place that quotes it.
    for (unsigned int i2 = 0; i2 < quotations_nt_order[i].referents.size(); i2++) {
      if (reference.equals(quotations_nt_order[i].referents[i2])) {
        references.push_back(quotations_nt_order[i].reference);
        comments.push_back(_("Quoted here"));
        for (unsigned int i3 = 0; i3 < quotations_nt_order[i].referents.size(); i3++) {
          if (i3 != i2) {
            references.push_back(quotations_nt_order[i].referents[i3]);
            comments.push_back(comment(_("Parallel passage"), lxx));
          }
        }
      }
    }
  }

  // If there is only one reference found, that will be the original one.
  // That means that no parallel or corresponding references were found.
  // Erase that single one in such cases.
  if (references.size() == 1) {
    references.clear();
    comments.clear();
  }
}