How do you rebuild Sword.pm and Sword.cxx using SWIG? Thanks Chad
On Sun, 2003-01-19 at 21:29, Joachim Ansorg wrote: > Perl normally assumes that you call a function like > > sub mysub { > my $self = shift; # or use $_[0]; > my $class = $self->someFunction(); > } > In this example someFunction is called with one parameter, the class it > belongs to! Strange but sometime useful! > > I looked into Sword.pm, the declaration of zCom::createModule is at line 971. > First try to craete the module using RawText. If this works try to use zCom. > > In the example I used > Sword::RawCom::createModule("data/modules/comments/rawcom/mak") || die > "Couldn't create the RawCom module!"; > my $mod = Sword::RawCom->new("data/modules/comments/rawcom/mak"); > > The last call is of the type I mentioned above, it wants two parameters (self > and path), but since you call it from Sword::RawCom you have to pass only the > path parameter. > > Have a look into the example, it's a working script. I attached a small piece > of text data which is in the format create_mak.pl wants to have. > > Simply copy the file (keeping the name) into the dir where the script is, > change into this dir and run the script. The created new module will be in > mak.zip. > > If you need help let me know. It works pretty well for me. > > Joachim > > > OK, the class is in the zcom.i file but after I build SWIG and install > > Perl it does not show up in the Sword.pm file. So ever time I try and > > use it, Perl can't find that function. And when I try and create a > > RawText module or other modules I get this message. > > > > Usage: RawText_createModule(self,path); > > > > It seems that the function is looking for two arguments (self, path). I > > know that path is where I want the module but what is the self. > > Furthermore this is not how it is set up in the rawtext.i file. It > > shows only one argument. Do you have any more things I can try? > > > > Thanks > > Chad > > > > On Sun, 2003-01-19 at 17:34, Joachim Ansorg wrote: > > > Normally build it with > > > > > > cd bindings/swig > > > ./configure > > > make > > > cd perl; > > > make install > > > > > > The make install is important, otherwise the Sword module is not > > > available and can't load the shared lib. > > > > > > Have a look into the .i files which functions are available in which > > > classes. Basically it's most of the things available in > > > sword-cvs/doc/api-documentation/ > > > > > > If you need some missing classes let me know. > > > > > > Let me know how it works, > > > Joachim > > > > > > > That did not work. I get a message when I try creating an zCom module > > > > in Perl. > > > > > > > > Can't locate auto/Sword/zCom/createModul.al in @INC > > > > > > > > I don't find zCom::createModule in the Sword.pm file. Did I build SWIG > > > > Perl wrong or something. > > > > > > > > Thanks > > > > Chad > > > > > > > > On Sun, 2003-01-19 at 05:25, Joachim Ansorg wrote: > > > > > Chad, > > > > > Have a look at the following messy Perl script. It was never intended > > > > > for a release, so the code isn't very good. At the end you'll see how > > > > > I created a compressed commentary module using the Swig bindings. > > > > > > > > > > If you need more help let me know. > > > > > > > > > > Joachim > > > > > > > > > > > Can someone tell me how to create a module in SWIG Perl? I try and > > > > > > follow the example given but I get an error message like this: > > > > > > > > > > > > Usage: xText_createModule(self,path,blockBound); > > > > > > > > > > > > Can any one help? > > > > > > > > > > > > Thanks > > > > > > Chad > > > > > > > > > > > > _______________________________________________ > > > > > > sword-devel mailing list > > > > > > [EMAIL PROTECTED] > > > > > > http://www.crosswire.org/mailman/listinfo/sword-devel > > > > > > > > > > -- > > > > > Joachim Ansorg > > > > > www.bibletime.info > > > > > www.ansorgs.de > > > > > > > > > > ---- > > > > > > > > > > > > > > > #!/usr/bin/perl > > > > > > > > > > use Sword; #Use the Sword bindings for Perl > > > > > use Encode; > > > > > use File::Path; > > > > > use Cwd; > > > > > use strict; > > > > > > > > > > # Parameters: > > > > > # 1. The modules > > > > > # 2. The key as english string > > > > > # 3. The data as string > > > > > > > > > > sub writeData { > > > > > my $mod = shift; > > > > > my $key = shift; > > > > > my $data = shift; > > > > > > > > > > # We have to parse the key to be able to write a range to the module > > > > > # The first entry is written using the data, ther others are written > > > > > as links my $vk = Sword::VerseKey->new(); > > > > > $vk->setLocale("de"); > > > > > > > > > > my $list = $vk->ParseVerseList($key, "Genesis 1:1", 1); # "1" to > > > > > parse ranges! for (my $i = 0; $i < $list->Count(); $i++) { > > > > > my $sw_key= $list->GetElement($i); > > > > > if (my $rangeKey = $sw_key->toVerseKey()) { > > > > > # write the data to the first key and link the others >to this > > > > > first one my $k = $rangeKey->LowerBound(); > > > > > print "\tWriting to " . $k->getText() . "\n"; > > > > > $mod->SetKey($k); > > > > > $mod->write($data); > > > > > > > > > > $k->next(); > > > > > # go up until we reach UpperBound and link each entry >to the > > > > > LowerBound while(($k->compare($rangeKey->UpperBound()) == -1)) { #as > > > > > long as $k is before UpperBound $mod->SetKey($k); > > > > > $mod->writeLink($rangeKey->LowerBound()); > > > > > print "\t\t" . $k->getText() . ": linking to ". > > > > > $sw_key->getText() . "\n"; $k->next(); > > > > > } > > > > > #we reached the last entry > > > > > #$mod->writeLink($rangeKey->LowerBound()); > > > > > print "\t\t" . $k->getText() . ": linking to ". >$sw_key->getText() > > > > > . "\n"; } > > > > > else { > > > > > print "\tWriting single key to " . $sw_key->getText() >. "\n"; > > > > > $mod->SetKey($sw_key); > > > > > $mod->write($data); > > > > > } > > > > > } > > > > > > > > > > #print out the list > > > > > }; > > > > > > > > > > sub convert_key { > > > > > my $key = shift; > > > > > $key =~ s/,/:/g; > > > > > $key =~ s/(\d)\./$1. /; > > > > > if ($key =~ /[^0-9]$/) { > > > > > die "Invalid key $key" > > > > > }; > > > > > > > > > > return $key; > > > > > }; > > > > > > > > > > sub format_content { > > > > > my $key = shift; > > > > > my $date = shift; > > > > > my $data = shift; > > > > > # Format the data in the following way: > > > > > # Datum: $date > > > > > # Stelle: <scripRef passage="$englishKey">$key</scripRef> > > > > > # <BR> > > > > > # $data > > > > > > > > > > #Fix existing scripRefs > > > > > # 1. Remove newlines within scripRef tags > > > > > $data =~ s/<scripRef[\n\s]?(.+?)\n(.+?)>/<scripRef $1 $2>/gi; > > > > > # 2. Remove version=".+?" parts > > > > > $data =~ s|<scripRef (.+?)version=".+?"(.+?)>|<scripRef $1 $2>|gis; > > > > > # 3. Beautify scripRefs, e.g. remove trailing spaces > > > > > $data =~ s|<scripRef (.+?)\s+>|<scripRef $1>|gis; > > > > > > > > > > > > > > > my $ret = '<FONT color="#800000"><B>Datum:</B> ' . $date . > > > > > '</FONT><BR>'; > > > > > > > > > > my $vk = Sword::VerseKey->new(); > > > > > $vk->setLocale("de"); > > > > > $vk->setText($key); > > > > > #$vk->setLocale("en"); > > > > > > > > > > my $rangeText = undef; > > > > > my $list = $vk->ParseVerseList($key, "Genesis 1:1", 1); # "1" to > > > > > parse ranges! for (my $i = 0; $i < $list->Count(); $i++) { > > > > > my $sw_key= $list->GetElement($i); > > > > > if (my $rangeKey = $sw_key->toVerseKey()) { > > > > > $rangeKey->setLocale("en"); > > > > > # write the data to the first key and link the others >to this > > > > > first one if( > > > > > $rangeKey->LowerBound()->compare($rangeKey->UpperBound()) == -1 ) { > > > > > #as long as $k is before UpperBound $rangeText .= > > > > > $rangeKey->LowerBound()->getText() . "-" . > > > > > $rangeKey->UpperBound()->getText() . ";"; } > > > > > } > > > > > else { > > > > > $vk->setLocale("de"); > > > > > $vk->setText($sw_key->getText()); > > > > > $vk->setLocale("en"); > > > > > $rangeText .= $vk->getText(); > > > > > } > > > > > } > > > > > > > > > > > > > > > $ret .= '<FONT color="#800000"><B>Stelle:</B> ' . '<scripRef > > > > > passage="' . $rangeText .'">' . $key . '</scripRef></FONT>'; $ret .= > > > > > '<BR><P align="justify">' . $data . '</P>'; > > > > > > > > > > #Finally change all possible characters into UTF-8 so it will work > > > > > on any platform Encode::from_to($ret, "iso-8859-15", "utf-8"); > > > > > return $ret; > > > > > }; > > > > > > > > > > # This function created the module configuration file for the MAK > > > > > module sub create_config { > > > > > my $path = shift; > > > > > my $filename = shift; > > > > > > > > > > mkpath("$path"); > > > > > open(OUT, "> $path/$filename"); > > > > > > > > > > print OUT <<'EOF'; > > > > > [MAK] > > > > > DataPath=./modules/comments/rawcom/mak/ > > > > > ModDrv=RawCom > > > > > SourceType=ThML > > > > > Encoding=UTF-8 > > > > > Lang=de > > > > > MinimumVersion=1.5.2 > > > > > Version=1.0 > > > > > History_1.0=2002-11-24 -- Major update. Many new comments, updated > > > > > format, changed encoding to UTF-8, fixed existing scripRefs > > > > > History_0.9=2000-07-29 -- First official version -- ThML-Tags for > > > > > scripture ref SwordVersionDate=2002-11-24 > > > > > Description=Matthias Ansorgs Kommentar > > > > > About=Matthias Ansorgs Kommentar zur Bibel\par\ > > > > > Der Kommentar wurde von Matthias Ansorg geschrieben.\par\ > > > > > Kontakt: [EMAIL PROTECTED] > > > > > TextSource=Matthias Ansorg,[EMAIL PROTECTED] > > > > > LCSH=Bible--Commentaries, German. > > > > > DistributionLicense=Public Domain > > > > > EOF > > > > > close(OUT); > > > > > }; > > > > > > > > > > > > > > > > > > > > sub write_module { > > > > > Sword::LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName("de"); > > > > > > > > > > my $file = shift; > > > > > open(IN, $file) || die "Can't open file $file\n"; > > > > > > > > > > my $key = undef; > > > > > my $date = undef; > > > > > my $comment = undef; > > > > > > > > > > #Create the directories where the module should be created > > > > > mkpath("data/modules/comments/rawcom/mak"); > > > > > #LocaleMgr()->setDefaultLocaleName("de"); > > > > > > > > > > > > > > > #Sword::zCom::createModule("data/modules/comments/rawcom/mak",4) || > > > > > die "Couldn't create the zCom module!"; > > > > > Sword::RawCom::createModule("data/modules/comments/rawcom/mak") || > > > > > die "Couldn't create the zCom module!"; #my $compressor = > > > > > Sword::LZSSCompress->new(); > > > > > #my $mod = Sword::zCom->new("data/modules/comments/rawcom/mak", 0, > > > > > 0, 4, $compressor ); #blocktype = 4, compressor type is > > > > > LZSSCompression my $mod = > > > > > Sword::RawCom->new("data/modules/comments/rawcom/mak"); > > > > > $mod->setSkipConsecutiveLinks(0); > > > > > > > > > > while (<IN>) { > > > > > if (/^Text:\s?(.+?)\n/) { #The start if a new entry was found > > > > > if ($key && $date && $comment) { #write the found >comment to disk > > > > > $key = convert_key($key); > > > > > print "Found: " . $key. "\n"; > > > > > my $data = format_content($key, $date, >$comment); > > > > > writeData($mod, $key, $data); > > > > > }; > > > > > > > > > > $key = $1; > > > > > $date = undef; > > > > > $comment = undef; > > > > > } > > > > > elsif (/^Datum:\s?(.+?)\n/) { > > > > > $date = $1; > > > > > } > > > > > else { > > > > > $comment .= $_; > > > > > }; > > > > > }; > > > > > #write the last entry into the module > > > > > if ($key && $date && $comment) { #write the found comment to disk > > > > > $key = convert_key($key); > > > > > print "Found: " . $key. "\n"; > > > > > my $data = format_content($key, $date, $comment); > > > > > writeData($mod, $key, $data); > > > > > }; > > > > > > > > > > close(IN); > > > > > }; > > > > > > > > > > sub zip_module { > > > > > my $path = shift; > > > > > my $filename = shift; > > > > > > > > > > my $start_dir = getcwd(); > > > > > unlink("$filename"); > > > > > chdir("$path"); > > > > > > > > > > system("chmod -R a+r+X $start_dir/$path"); > > > > > > > > > > # Call zip command to compress all files in the current directory > > > > > my $ret = system( "zip -q -9 -r $start_dir/$filename *"); > > > > > chdir($start_dir); > > > > > rmtree("$start_dir/data/"); > > > > > > > > > > print "Zipped module data files are in the ZIP archive $filename\n"; > > > > > > > > > > return $ret; > > > > > } > > > > > > > > > > #main part > > > > > create_config("data/mods.d/", "mak.conf"); > > > > > write_module("stilleZeit.Kommentare.txt"); > > > > > zip_module("data", "mak.zip"); > > > > > create_config(".", "mak.conf"); > > > > > > > > _______________________________________________ > > > > sword-devel mailing list > > > > [EMAIL PROTECTED] > > > > http://www.crosswire.org/mailman/listinfo/sword-devel > > > > > > -- > > > Joachim Ansorg > > > www.bibletime.info > > > www.ansorgs.de > > > _______________________________________________ > > > sword-devel mailing list > > > [EMAIL PROTECTED] > > > http://www.crosswire.org/mailman/listinfo/sword-devel > > > > _______________________________________________ > > sword-devel mailing list > > [EMAIL PROTECTED] > > http://www.crosswire.org/mailman/listinfo/sword-devel > > -- > Joachim Ansorg > www.bibletime.info > www.ansorgs.de > ---- > > #!/usr/bin/perl > > use Sword; #Use the Sword bindings for Perl > use Encode; > use File::Path; > use Cwd; > use strict; > > # Parameters: > # 1. The modules > # 2. The key as english string > # 3. The data as string > > sub writeData { > my $mod = shift; > my $key = shift; > my $data = shift; > > # We have to parse the key to be able to write a range to the module > # The first entry is written using the data, ther others are written as links > my $vk = Sword::VerseKey->new(); > $vk->setLocale("de"); > > my $list = $vk->ParseVerseList($key, "Genesis 1:1", 1); # "1" to parse ranges! > for (my $i = 0; $i < $list->Count(); $i++) { > my $sw_key= $list->GetElement($i); > if (my $rangeKey = $sw_key->toVerseKey()) { > # write the data to the first key and link the others to this >first one > my $k = $rangeKey->LowerBound(); > print "\tWriting to " . $k->getText() . "\n"; > $mod->SetKey($k); > $mod->write($data); > > $k->next(); > # go up until we reach UpperBound and link each entry to the >LowerBound > while(($k->compare($rangeKey->UpperBound()) == -1)) { #as long >as $k is before UpperBound > $mod->SetKey($k); > $mod->writeLink($rangeKey->LowerBound()); > print "\t\t" . $k->getText() . ": linking to ". >$sw_key->getText() . "\n"; > $k->next(); > } > #we reached the last entry > #$mod->writeLink($rangeKey->LowerBound()); > print "\t\t" . $k->getText() . ": linking to ". >$sw_key->getText() . "\n"; > } > else { > print "\tWriting single key to " . $sw_key->getText() . "\n"; > $mod->SetKey($sw_key); > $mod->write($data); > } > } > > #print out the list > }; > > sub convert_key { > my $key = shift; > $key =~ s/,/:/g; > $key =~ s/(\d)\./$1. /; > if ($key =~ /[^0-9]$/) { > die "Invalid key $key" > }; > > return $key; > }; > > sub format_content { > my $key = shift; > my $date = shift; > my $data = shift; > # Format the data in the following way: > # Datum: $date > # Stelle: <scripRef passage="$englishKey">$key</scripRef> > # <BR> > # $data > > #Fix existing scripRefs > # 1. Remove newlines within scripRef tags > $data =~ s/<scripRef[\n\s]?(.+?)\n(.+?)>/<scripRef $1 $2>/gi; > # 2. Remove version=".+?" parts > $data =~ s|<scripRef (.+?)version=".+?"(.+?)>|<scripRef $1 $2>|gis; > # 3. Beautify scripRefs, e.g. remove trailing spaces > $data =~ s|<scripRef (.+?)\s+>|<scripRef $1>|gis; > > > my $ret = '<FONT color="#800000"><B>Datum:</B> ' . $date . '</FONT><BR>'; > > my $vk = Sword::VerseKey->new(); > $vk->setLocale("de"); > $vk->setText($key); > #$vk->setLocale("en"); > > my $rangeText = undef; > my $list = $vk->ParseVerseList($key, "Genesis 1:1", 1); # "1" to parse ranges! > for (my $i = 0; $i < $list->Count(); $i++) { > my $sw_key= $list->GetElement($i); > if (my $rangeKey = $sw_key->toVerseKey()) { > $rangeKey->setLocale("en"); > # write the data to the first key and link the others to this >first one > if( $rangeKey->LowerBound()->compare($rangeKey->UpperBound()) >== -1 ) { #as long as $k is before UpperBound > $rangeText .= $rangeKey->LowerBound()->getText() . "-" >. $rangeKey->UpperBound()->getText() . ";"; > } > } > else { > $vk->setLocale("de"); > $vk->setText($sw_key->getText()); > $vk->setLocale("en"); > $rangeText .= $vk->getText(); > } > } > > > $ret .= '<FONT color="#800000"><B>Stelle:</B> ' . '<scripRef passage="' . >$rangeText .'">' . $key . '</scripRef></FONT>'; > $ret .= '<BR><P align="justify">' . $data . '</P>'; > > #Finally change all possible characters into UTF-8 so it will work on any >platform > Encode::from_to($ret, "iso-8859-15", "utf-8"); > return $ret; > }; > > # This function created the module configuration file for the MAK module > sub create_config { > my $path = shift; > my $filename = shift; > > mkpath("$path"); > open(OUT, "> $path/$filename"); > > print OUT <<'EOF'; > [MAK] > DataPath=./modules/comments/rawcom/mak/ > ModDrv=RawCom > SourceType=ThML > Encoding=UTF-8 > Lang=de > MinimumVersion=1.5.2 > Version=1.0 > History_1.0=2002-11-24 -- Major update. Many new comments, updated format, changed >encoding to UTF-8, fixed existing scripRefs > History_0.9=2000-07-29 -- First official version -- ThML-Tags for scripture ref > SwordVersionDate=2002-11-24 > Description=Matthias Ansorgs Kommentar > About=Matthias Ansorgs Kommentar zur Bibel\par\ > Der Kommentar wurde von Matthias Ansorg geschrieben.\par\ > Kontakt: [EMAIL PROTECTED] > TextSource=Matthias Ansorg,[EMAIL PROTECTED] > LCSH=Bible--Commentaries, German. > DistributionLicense=Public Domain > EOF > close(OUT); > }; > > > > sub write_module { > Sword::LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName("de"); > > my $file = shift; > open(IN, $file) || die "Can't open file $file\n"; > > my $key = undef; > my $date = undef; > my $comment = undef; > > #Create the directories where the module should be created > mkpath("data/modules/comments/rawcom/mak"); > #LocaleMgr()->setDefaultLocaleName("de"); > > > #Sword::zCom::createModule("data/modules/comments/rawcom/mak",4) || die >"Couldn't create the zCom module!"; > Sword::RawCom::createModule("data/modules/comments/rawcom/mak") || die >"Couldn't create the zCom module!"; > #my $compressor = Sword::LZSSCompress->new(); > #my $mod = Sword::zCom->new("data/modules/comments/rawcom/mak", 0, 0, 4, >$compressor ); #blocktype = 4, compressor type is LZSSCompression > my $mod = Sword::RawCom->new("data/modules/comments/rawcom/mak"); > $mod->setSkipConsecutiveLinks(0); > > while (<IN>) { > if (/^Text:\s?(.+?)\n/) { #The start if a new entry was found > if ($key && $date && $comment) { #write the found comment to >disk > $key = convert_key($key); > print "Found: " . $key. "\n"; > my $data = format_content($key, $date, $comment); > writeData($mod, $key, $data); > }; > > $key = $1; > $date = undef; > $comment = undef; > } > elsif (/^Datum:\s?(.+?)\n/) { > $date = $1; > } > else { > $comment .= $_; > }; > }; > #write the last entry into the module > if ($key && $date && $comment) { #write the found comment to disk > $key = convert_key($key); > print "Found: " . $key. "\n"; > my $data = format_content($key, $date, $comment); > writeData($mod, $key, $data); > }; > > close(IN); > }; > > sub zip_module { > my $path = shift; > my $filename = shift; > > my $start_dir = getcwd(); > unlink("$filename"); > chdir("$path"); > > system("chmod -R a+r+X $start_dir/$path"); > > # Call zip command to compress all files in the current directory > my $ret = system( "zip -q -9 -r $start_dir/$filename *"); > chdir($start_dir); > rmtree("$start_dir/data/"); > > print "Zipped module data files are in the ZIP archive $filename\n"; > > return $ret; > } > > #main part > create_config("data/mods.d/", "mak.conf"); > write_module("stilleZeit.Kommentare.txt"); > zip_module("data", "mak.zip"); > create_config(".", "mak.conf"); > ---- > > Text: Lukas 12,2-3 > Datum: 19.10.1998 > > Das Gericht wird einst alle Verfehlungen der Menschen hervorholen und bloßstellen. >Doch was den > Gläubigen durch Jesus vergeben ist, wird nicht mehr hervorgeholt werden, denn diese >Anklageschrift > ist zerrissen. Darum müssen Christen das kommende Gericht nicht fürchten. > > > »Freunde« gebraucht der HERR hier als Anrede für SEINE Jünger, denn an dies sind die >Verse 1-12 > gerichtet (Lk.12,1). Joh.15,14: "Ihr seid meine Freunde, wenn ihr alles tut, was >irgend ich euch > geboten habe." Das Gegenteil eines Freundes Jesu wird in Jakobus 4,4 definiert: >"Wer nun irgend > ein Freund der Welt sein will, stellt sich als Feind Gottes dar." > > > Text: Lukas 12,4 > Datum: 19.10.1998 > > Der HERR zeigt, dass sich Seele und Leib im Tod trennen. Vgl. auch 1.Mo.35,18. Es >ist ein Befehl > des HERRN, dass wir Menschen nicht fürchten sollen - demnach ist Menschenfurcht >Ungehorsam > gegenüber IHM. > > > Text: Lukas 12,5 > Datum: 19.10.1998 > > Der HERR will nicht, dass wir die Hölle und das Gericht fürchten, sondern dass wir >Ehrfurcht vor > Gott haben, der die Gewalt hat zu richten. Solche Furcht vor dem HERRN bildet »der >Erkenntnis > Anfang« (Spr.1,7). Aus dieser Ehrfurcht resultiert eine heilige Scheu davor, Gott zu >betrüben, der > uns so sehr liebt. > > > Text: Lukas 12,6-7 > Datum: 19.10.1998 > > Phil.4,6: "In allem lasst durch Gebet und Flehen mit Danksagung eure Anliegen vor >Gott > kundwerden." Auch unsere geringsten Anliegen sind vor Gott nicht zu gering, sondern >ER ist so groß, > dass ER selbst auf jeden einzelnen Sperling achtgibt. > > > Text: Lukas 12,10 > Datum: 19.10.1998 > > Die Lästerung gegen den Geist ist keine Lästerrede, sondern das Verleugnen des >Glaubens, das > Abweisen der Überführung durch den Heiligen Geist, dass Jesus der Christus ist. Wer >aber nicht > glaubt, kann nicht wiedergeboren werden. > > > Text: Lukas 12,11-12 > Datum: 19.10.1998 > > Wenn man sich vor Obrigkeit für seinen Glauben verantworten muss, wird man die >rechte Rede vom > Heiligen Geist bekommen und soll nicht selbst nach Worten suchen. Ein Beispiel >hierfür sind Petrus > und Johannes vor dem Hohen Rat (Apg.4,8). Dagegen beziehen sich diese Worte nicht >auf die > Wortverkündigung. _______________________________________________ sword-devel mailing list [EMAIL PROTECTED] http://www.crosswire.org/mailman/listinfo/sword-devel