Chris Little wrote:
> We don't really need help in deciding how to represent Bibles that  
> don't use the KJV versification. That detail is already decided. We'll  
> be using GenBooks with OSIS-style refs as the keys. So Gen 1:1 goes  
> in /Gen/1/1 and so forth.
> 
> We can make these Bibles right now. The problem is they won't act or  
> appear like any of the other Bibles.
> 
> What we still lack is all of the code to make GenBook Bibles  
> accessible via existing Bible interface methods and any other work to  
> make GenBook Bible generally look & behave like VerseKey-type Bible.  
> (Slight simplification obviously. If anyone is actually willing to  
> help start implementing, we can give more details about what is  
> planned.)

I have just now looked through the code of libsword and could not find
where it gets its versification scheme. Maybe I did not look hard
enough. Or did see it, but not recognise it. A lot of it looked generic
and not at all dependent on any particular scheme,  be it KJV or Roman
Catholic or whatever.

Can someone point me in the right direction?

Being no coder, I can not see how completely new way of encoding Bibles
should be the right way forward - particularly as it would result in

a) a possibly long period of breakage/poor implementation on various
GUIs (+ some GUIs which are perfectly fine now will never get it)

b) a very different way of creating modules, requiring new tools etc
(unless I misunderstood you, Chris)

c) confuse the user, who often enough is perfectly unaware that his
particular tradition uses a different scheme (and hence his Bible will
display not in the ordinary window)

Would a change at the root of the problem not be a lot more economical?

As someone who creates modules I would not have to care at all about
which versification scheme my Bible uses during encoding it (apart from
the basic fact that I have to chose one.) All tools would work the same way.

As someone who uses the software I could use it just as now, and without
any changes apart from having a wider range of material available (which
will be have as I am sued to)

FWIW  Bibledit reads at the set up of each project a versification scheme.

There were when I last looked two or three schemes around, but the
principle was open and flexible - new schemes could easly added by
programmatically unskilled people like myself.

The two files setting this out are short. The Versifications.cpp is 193
lines long, the versification.cpp only 38 (in C++). The former loads and
parses a particular scheme, the second applies a chosen scheme on newly
imported text. (Bibledit is, as the name says a Bible editor, a
translation tool a la Paratext) There is probably other stuff too. Teus
uses sqlite a lot and that might play a role too.

I attach them below. The whole source can be obtained here:
http://bibledit.sourceforge.net/hot-off-press

Peter

-------------------------


/*
** Copyright (C) 2003-2006 Teus Benschop.
**  
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**  
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**  
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**  
*/


#include "versifications.h"
#include "utilities.h"
#include "directories.h"
#include "gwrappers.h"
#include <libxml/xmlreader.h>
#include "bookdata.h"
#include "books.h"


Versification::Versification (const ustring& system_in, const ustring& filename)
{
  system = system_in;
  
  if (g_file_test (filename.c_str(), G_FILE_TEST_IS_REGULAR)) {
    gchar *contents;
    g_file_get_contents (filename.c_str(), &contents, NULL, NULL);
    xmlParserInputBufferPtr inputbuffer;
    inputbuffer = xmlParserInputBufferCreateMem(contents, strlen (contents), XML_CHAR_ENCODING_NONE);
    xmlTextReaderPtr reader = xmlNewTextReader (inputbuffer, NULL);
    if (reader) {
      char * opening_element = NULL;
      unsigned int myid;
      unsigned int mychapter;
      unsigned int myverse;

      while ((xmlTextReaderRead(reader) == 1)) {
        switch (xmlTextReaderNodeType (reader)) {
          case XML_READER_TYPE_ELEMENT:
          {
            opening_element = (char *) xmlTextReaderName (reader);
            if (!strcmp (opening_element, "triad")) {
              myid = 0;
              mychapter = 0;
              myverse = 0;
            }
            break;
          }
          case XML_READER_TYPE_TEXT:
          {
            char * text = (char *) xmlTextReaderValue (reader);
            if (text) {
              if (!strcmp (opening_element, "book")) {
                myid = books_english_to_id (text);
              }
              if (!strcmp (opening_element, "chapter")) {
                mychapter = convert_to_int (text);
              }
              if (!strcmp (opening_element, "verse")) {
                myverse = convert_to_int (text);
              }
              free(text);
            }
            break;
          }
          case XML_READER_TYPE_END_ELEMENT:
          {
            char * closing_element = (char *) xmlTextReaderName (reader);
            if (!strcmp(closing_element, "triad")) {
              if (myid == 0) break;
              if (mychapter == 0) break;
              if (myverse == 0) break;
              id.push_back (myid);
              chapter.push_back (mychapter);
              verse.push_back (myverse);
            }
            break;
          }
        }
      }
    }
    if (reader) xmlFreeTextReader(reader);
    if (inputbuffer) xmlFreeParserInputBuffer (inputbuffer);
    if (contents) g_free (contents);  
  }
}


Versifications::Versifications (int dummy)
{
}


vector <ustring> Versifications::systems_get ()
// Gets all available versification systems and store them in the object.
{
  if (available_systems.empty()) {
    // Get the system from the templates that come with Bibledit.
    ReadFiles rf1 (directories_get_package_data (), "versification", ".xml");
    for (unsigned int i = 0; i < rf1.files.size(); i++) {
      available_filenames.push_back (gw_build_filename (directories_get_package_data (), rf1.files[i]));
      available_systems.push_back (filename_get_system (rf1.files[i]));
    }
    // Get the system from the templates provided by the user.
    ReadFiles rf2 (directories_get_templates_user (), "versification", ".xml");
    for (unsigned int i = 0; i < rf2.files.size(); i++) {
      available_filenames.push_back (gw_build_filename (directories_get_templates_user (), rf2.files[i]));
      available_systems.push_back (filename_get_system (rf2.files[i]));
    }
    // Sort everything on name.
    quick_sort (available_systems, available_filenames, 0, available_systems.size());
  }
  return available_systems;
}


ustring Versifications::filename_get_system (ustring filename)
// Taking a filename, it produces the versification name from it.
{
  filename.erase (0, 14);
  filename.erase (filename.length() - 4, 4);
  replace_text (filename, "_", " ");
  size_t pos = 0;
  while (pos != string::npos) {
    filename.replace (pos, 1, upperCase (filename.substr (pos, 1)));
    pos = filename.find (" ", pos);
    if (pos != string::npos) pos++;
  }
  return filename;
}


unsigned int Versifications::system_pointer_get (ustring system)
/*
Get a pointer to the Versification for "system".
If "system" does not exist, it takes "English".
If "system" is not yet loaded, it first loads it, then gives the pointer.
*/
{
  // Load the localizations.
  if (available_systems.empty()) {
    systems_get ();
  }
  // Is the requested system available?
  bool available = false;
  for (unsigned int i = 0; i < available_systems.size(); i++) {
    if (system == available_systems[i]) {
      available = true;
      break;
    }
  }
  // If the system is not available, take "English".
  if (!available) system = "English";
  // Get a pointer to the requested system, if it is already loaded.
  for (unsigned int i = 0; i < loaded_localizations.size(); i++) {
    if (system == loaded_localizations[i].system)
      return i;    
  }
  // Load the requested system from the filename, and return a pointer to it.
  ustring filename;
  for (unsigned int i = 0; i < available_systems.size(); i++) {
    if (system == available_systems[i]) {
      filename = available_filenames[i];
      break;
    }
  }
  Versification versification (system, filename);
  loaded_localizations.push_back (versification);
  return loaded_localizations.size() - 1;
}


void Versifications::book2chaptersverses (const ustring& system, unsigned int id, vector<unsigned int>& chapters, vector<unsigned int>& verses)
{
  chapters.clear();
  verses.clear();
  unsigned int pointer = system_pointer_get (system);
  for (unsigned int i = 0; i < loaded_localizations[pointer].id.size(); i++) {
    if (id == loaded_localizations[pointer].id[i]) {
      chapters.push_back (loaded_localizations[pointer].chapter[i]);
      verses.push_back (loaded_localizations[pointer].verse[i]);
    }
  }
}
/*
** Copyright (C) 2003-2006 Teus Benschop.
**  
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**  
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**  
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**  
*/


#include "versification.h"
#include "utilities.h"
#include "bible.h"
#include "books.h"
#include "sqlite_reader.h"
#include "gwrappers.h"
#include "directories.h"
#include "versifications.h"


void versification_get_chapters_verses (const ustring& versification,
                                        unsigned int book,
                                        vector<unsigned int>& chapters,
                                        vector<unsigned int>& verses)
{
  extern Versifications * versifications;
  versifications->book2chaptersverses (versification, book, chapters, verses);
}


void versification_create_book_template (const ustring& versification, unsigned int book, vector<ustring>& booktemplate)
{
  // Clear template and add id and running header.
  booktemplate.clear();
  unsigned index = book;
  ustring id = books_id_to_paratext (index);
  booktemplate.push_back ("\\id " + id);
  booktemplate.push_back ("\\h " + book);
  booktemplate.push_back ("\\toc2 " + book);
  // Get the number of chapters in the book and verses in the chapter.
  vector<unsigned int> chapters;
  vector<unsigned int> verses;
  versification_get_chapters_verses (versification, book, chapters, verses);
  // Add \c and \v information for all chapters.
  for (unsigned int i = 0; i < chapters.size(); i++) {
    booktemplate.push_back ("\\c " + convert_to_string (chapters[i]));
    // Some paragraph ought to follow the chapter, so insert it here.
    booktemplate.push_back ("\\p ");
    for (unsigned int verse = 1; verse <= verses[i]; verse++) {
      booktemplate.push_back ("\\v " + convert_to_string (verse));
    }
  }
}


void versification_create_chapter_template (const ustring& versification, unsigned int book, unsigned int chapter, vector<ustring>& chaptertemplate)
{
  chaptertemplate.clear();
  vector<unsigned int> chapters;
  vector<unsigned int> verses;
  versification_get_chapters_verses (versification, book, chapters, verses);
  for (unsigned int i = 0; i < chapters.size(); i++) {
    if (chapters[i] == chapter) {
      chaptertemplate.push_back ("\\c " + convert_to_string (chapter));
      chaptertemplate.push_back ("\\p ");
      for (unsigned int verse = 1; verse <= verses[i]; verse++) {
        chaptertemplate.push_back ("\\v " + convert_to_string (verse));
      }
    }
  }
}


vector <unsigned int> versification_get_chapters (const ustring& versification, unsigned int book)
{
  vector<unsigned int> chapters;
  vector<unsigned int> verses;
  versification_get_chapters_verses (versification, book, chapters, verses);
  return chapters;
}


ustring versification_get_last_verse (const ustring& versification, unsigned int book, unsigned int chapter)
{
  ustring lastverse = "1";
  vector<unsigned int> chapters;
  vector<unsigned int> verses;
  versification_get_chapters_verses (versification, book, chapters, verses);
  for (unsigned int i = 0; i < chapters.size(); i++) {
    if (chapters[i] == chapter) {
      lastverse = convert_to_string (verses[i]);
    }
  }
  return lastverse;
}
_______________________________________________
sword-devel mailing list: sword-devel@crosswire.org
http://www.crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page

Reply via email to