summaryrefslogblamecommitdiffstats
path: root/versification/v11nsys.pl
blob: 0e9fbb83df3495f52440244572c8773b5e963b42 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11

                



                                                                           




                              











                                                                                             




































                                                                                   















                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           


                    
     
                                                                                                                                                         





                                                                                                                                                                                                                                                        

                    
         
                                    
         
                                                      




                                   
             
                                                 
             


                            
             





                                                                                            


                                       
              

          
                              







                              
                                                    
     


                  
#!/usr/bin/perl


sub cleanupLine {
    # here we'll do some cleanup of our input, mostly to regularlize input

    $ret = @_[0];

    $ret =~ s/>Pss\./>Ps\//g;

    return $ret;
}

sub buildBooks {
    if ($lastBook eq "Matt") {
	$otnt = 1;
    }
    if ($otnt == 0) {
	$otbooks .= "\t{\"$idmap{$lastBook}\", \"$lastBook\", \"$lastBook\", $lastChap},\n";
    }
    else {
	$ntbooks .= "\t{\"$idmap{$lastBook}\", \"$lastBook\", \"$lastBook\", $lastChap},\n";
    }
}

# @canons will contain this list of files, these are in a basic XML format.

# Each file lists osisIDs along with the English names associated with the

# osisID. These aren't exhaustive, and may or may not overlap (but hopefully

# don't). We are only using these to load mappings from osisIDs.

@canons = (
    "bible.xml",      # the Bible, broadly defined

    "otp.xml",        # OT pseudepigrapha

    "nta.xml",        # NT apocrpha

    "lds.xml",        # Mormon books

    "naghammadi.xml", # Nag Hammadi codices

    "qumran.xml",     # Qumran mss

    "classical.xml",  # intended for classical works, currently just Josephus

);

foreach $mapfile (@canons) {
    open MAP, "$mapfile";
    while (<MAP>) {
	$line = $_;

	if ($line =~ /<id>(.+?)<\/id>/) {
	    $id = $1;
	}
	elsif ($line =~ /<name>(.+?)<\/name>/) {
	    $name = $1;

	    if ($idmap{$id} eq "") {
		$idmap{$id} = $name;
	    }
	    else {
		# Duplicates most likely indicate alternate names, so ignore them.

#		print "ERROR: Duplicate mapping from $id found in $mapfile.\n"

	    }
	}
    }
    close (MAP);
}

opendir (DIR, ".");
@srcfiles = grep /Bible\.[^\.]+\.xml$/, readdir DIR;
closedir(DIR);

foreach $infile (@srcfiles) {
    
    $infile =~ /Bible\.([^\.]+)\.xml/;
    $v11n = $1;
    $outfile = lc("v11n$1.h");

    open INF, $infile;
    open OUTF, ">$outfile";

    print OUTF "/******************************************************************************\n * $outfile.h - Versification data for the $v11n system\n *\n * Copyright 1998-2005 CrossWire Bible Society (http://www.crosswire.org)\n *	CrossWire Bible Society\n *	P. O. Box 2528\n *	Tempe, AZ  85280-2528\n *\n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GNU General Public License as published by the\n * Free Software Foundation version 2.\n *\n * This program is distributed in the hope that it will be useful, but\n * WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * General Public License for more details.\n *\n */\n";
    print OUTF "\n#ifndef V11N" . uc($v11n) . "_H\n#define V11N" . uc($v11n) . "_H\n\nSWORD_NAMESPACE_START\n\n";

    $thisBook = "";
    $thisChap = "";
    $thisVers = "";
    
    $vm = "/******************************************************************************\n *	Maximum verses per chapter\n */\n\nint vm$v11n\[\] = {";
    $otbooks = "/******************************************************************************\n * [on]tbooks$v11n - initialize static instance for all canonical text names\n *		and chapmax\n */\nstruct sbook otbooks$v11n\[\] = {\n";
    $ntbooks = "struct sbook ntbooks$v11n\[\] = {\n";
    $booksCloser = "\t{\"\", \"\", \"\", 0}\n};\n";
    
    $otnt = 0; # 0 = ot, 1 = nt

    
    while (<INF>) {
	$line = $_;
	
	$line = cleanupLine($line);
	
	if ($line =~ /<osisID.+?code=\"(.+?)\"\/>/) {
	    $osisID = $1;
	    
	    $lastBook = $thisBook;
	    $lastChap = $thisChap;
	    $lastVers = $thisVers;
	    
	    $osisID =~ /([^\.]+)\.(\d+)\.(\d+)/;
	    
	    $thisBook = $1;
	    $thisChap = $2;
	    $thisVers = $3;
	    
	    if ((($thisBook ne $lastBook) ||($thisChap ne $lastChap)) && $lastVers ne "") {
		$vm .= "$lastVers, ";
	    }

	    if ($thisBook ne $lastBook) {
		$vm .= "\n\t// $idmap{$thisBook}\n\t";
		if ($lastBook ne "") {
		    buildBooks{};
		}
	    }
	}
    }
    $vm .= "$thisVers\n};\n";
    buildBooks();
    $otbooks .= $booksCloser;
    $ntbooks .= $booksCloser;
    
    print OUTF $otbooks;
    print OUTF $ntbooks;
    print OUTF $vm;
    
    print OUTF "\nSWORD_NAMESPACE_END\n\n#endif\n";
    
    close (INF);
    close (OUTF);
}