~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to utilities/addvs.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden, Jonathan Marsden, Dmitrijs Ledkovs, Closed Bugs
  • Date: 2009-05-30 11:55:55 UTC
  • mfrom: (1.3.1 upstream) (6.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090530115555-r427zsn3amivdpfu
Tags: 1.6.0+dfsg-1
[ Jonathan Marsden ]
* New upstream release. (Closes: #507960) (LP: #320558)
* debian/patches/02_libver.diff:
  - Bump SONAME to 8 -- SWORD 1.6 is not backward compatible with 1.5.11.
* debian/patches/series:
  - Remove 10_diatheke.diff -- included in upstream source.
* debian/patches/:
  - Remove several old unused .diff files.
  - Add 11_regex_only_when_needed.diff to conditionally include regex lib.
  - Add 12_fix_compiler_warnings.diff to remove all compiler warnings.
  - Add 13_fix_osis2mod_compression_default.diff from upstream svn.
  - Add 14_closing_section_not_chapter.diff from upstream svn.
* debian/libsword7.*: 
  - Rename to libsword8.*
  - Change libsword7 to libsword8 within files.
* debian/rules: 
  - SONAME bump to 8.
  - Set library version check to >= 1.6
* debian/control:
  - Change libsword7 to libsword8.
  - Add libsword7 to Conflicts.
  - Fix case of sword to SWORD in package descriptions.
  - Bump Standards-Version to 3.8.1 (no changes needed).
  - Fix section for libsword-dbg to avoid lintian warning.
* debian/rules:
  - Add DFSG get-orig-source target.
* debian/copyright:
  - Fix various mistakes in initial attempt to document copyrights.

[ Dmitrijs Ledkovs ]
* debian/rules: Added utils.mk to use missing-files target and call it on
  each build.
* debian/libsword-dev.install: Added libsword.la, previously missing.
* debian/libsword7.install: Added missing libicu translit files.
* debian/control:
  - Updated all uses of SWORD version to 1.6
  - Added libsword-dbg package
* debian/watch: Fixed a small mistake which was resulting in extra "."
  in final version name.
* debian/rules: simplified manpage processing.
* debian/libsword8.lintian-overrides: added override for module
  installation directory.
* debian/copyright: Updated with information about everyfile.
  Closes: #513448 LP: #322638
* debian/diatheke.examples: moved examples here from the diatheke.install
* debian/rules:
  - enabled shell script based testsuite
  - added commented out cppunit testsuite
* debian/patches/40_missing_includes.diff: 
  - added several missing stdio.h includes to prevent FTBFS of testsuite.

[ Closed Bugs ]
* FTBFS on intrepid (LP: #305172)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
 
3
 *      CrossWire Bible Society
 
4
 *      P. O. Box 2528
 
5
 *      Tempe, AZ  85280-2528
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License as published by the
 
9
 * Free Software Foundation version 2.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * General Public License for more details.
 
15
 *
 
16
 */
 
17
 
 
18
#include <ctype.h>
 
19
#include <stdio.h>
 
20
#include <fcntl.h>
 
21
#include <errno.h>
 
22
#include <stdlib.h>
 
23
 
 
24
#ifndef __GNUC__
 
25
#include <io.h>
 
26
#else
 
27
#include <unistd.h>
 
28
#endif
 
29
 
 
30
#include <swmgr.h>
 
31
#include <versekey.h>
 
32
#include <rawtext.h>
 
33
#include <iostream>
 
34
 
 
35
#ifndef NO_SWORD_NAMESPACE
 
36
using sword::SWMgr;
 
37
using sword::RawText;
 
38
using sword::SWKey;
 
39
using sword::VerseKey;
 
40
using sword::ListKey;
 
41
using sword::SWModule;
 
42
#endif
 
43
 
 
44
int main(int argc, char **argv) {
 
45
  
 
46
  const char * helptext = "addvs 1.1 Bible & Commentary module creation tool for the SWORD Project\nUse -a to add a new verse from standard input or a file, -d to delete a verse,\n-l to link two verses, -c to create a new module.\n  usage:\n   %s -a </path/to/module> <verse> [</path/to/file/with/verse>]\n   %s -d </path/to/module> <key>\n   %s -l </path/to/module> <first verse (already assigned)> <second verse>\n   %s -c </path/to/module>\n";
 
47
  long entrysize;
 
48
 
 
49
  if (argc < 3) {
 
50
    fprintf(stderr, helptext, argv[0], argv[0], argv[0], argv[0]);
 
51
    exit(-1);
 
52
  }
 
53
 if (!strcmp(argv[1], "-a") && (argc == 4 || argc == 5)) {      
 
54
    
 
55
    // Do some initialization stuff
 
56
    char buffer[65536];  //this is the max size of any entry
 
57
    RawText * mod = new RawText(argv[2]);       // open our datapath with our RawText driver.
 
58
    VerseKey *vkey = new VerseKey;
 
59
    vkey->Headings(1);
 
60
    vkey->AutoNormalize(0);
 
61
    vkey->Persist(1);      // the magical setting
 
62
    *vkey = argv[3];   
 
63
    // Set our VerseKey
 
64
    mod->setKey(*vkey);
 
65
    if (!vkey->Chapter()) {
 
66
      // bad hack >>
 
67
      // 0:0 is Book intro
 
68
      // (chapter):0 is Chapter intro
 
69
      //
 
70
      // 0:2 is Module intro
 
71
      // 0:1 is Testament intro
 
72
      int backstep = vkey->Verse();
 
73
      vkey->Verse(0);
 
74
      *mod -= backstep;       
 
75
      // << bad hack
 
76
 
 
77
      FILE *infile;
 
78
      // case: add from text file
 
79
      //Open our data file and read its contents into the buffer
 
80
      if (argc == 5) infile = fopen(argv[4], "r");
 
81
      // case: add from stdin
 
82
      else infile = stdin;
 
83
      
 
84
      entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile);
 
85
      
 
86
      mod->setEntry(buffer, entrysize); // save text to module at current position
 
87
    }
 
88
    else {
 
89
      ListKey listkey = vkey->ParseVerseList(argv[3], "Gen1:1", true);
 
90
      int i;
 
91
      bool havefirst = false;
 
92
      VerseKey firstverse;
 
93
      for (i = 0; i < listkey.Count(); i++) {
 
94
        VerseKey *element = SWDYNAMIC_CAST(VerseKey, listkey.GetElement(i));
 
95
        if (element) {
 
96
          mod->Key(element->LowerBound());
 
97
          VerseKey finalkey = element->UpperBound();
 
98
          std::cout << (const char*)mod->Key() << "-" << (const char*)finalkey << std::endl;
 
99
          if (!havefirst) {
 
100
            havefirst = true;
 
101
            firstverse = mod->Key();
 
102
            FILE *infile;
 
103
            // case: add from text file
 
104
            //Open our data file and read its contents into the buffer
 
105
            if (argc == 5) infile = fopen(argv[4], "r");
 
106
            // case: add from stdin
 
107
            else infile = stdin;
 
108
            
 
109
            entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile);
 
110
            
 
111
            mod->setEntry(buffer, entrysize);   // save text to module at current position
 
112
            std::cout << "f" << (const char*)firstverse << std::endl;
 
113
            (*mod)++;
 
114
          }
 
115
          while (mod->Key() <= finalkey) {
 
116
            std::cout << (const char*)mod->Key() << std::endl;
 
117
            *(SWModule*)mod << &firstverse;
 
118
            (*mod)++;
 
119
          }
 
120
        }
 
121
        else {
 
122
          if (havefirst) {
 
123
            mod->Key(*listkey.GetElement(i));
 
124
            *(SWModule*)mod << &firstverse;
 
125
            std::cout << (const char*)mod->Key() << std::endl;
 
126
          }
 
127
          else {
 
128
            mod->Key(*listkey.GetElement(i));
 
129
            havefirst = true;
 
130
            firstverse = mod->Key();
 
131
            FILE *infile;
 
132
            // case: add from text file
 
133
            //Open our data file and read its contents into the buffer
 
134
            if (argc == 5) infile = fopen(argv[4], "r");
 
135
            // case: add from stdin
 
136
            else infile = stdin;
 
137
            
 
138
            entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile);
 
139
            
 
140
            mod->setEntry(buffer, entrysize);   // save text to module at current position
 
141
            std::cout << "f" << (const char*)firstverse << std::endl;
 
142
          }
 
143
        }
 
144
      }
 
145
    }
 
146
    delete vkey;
 
147
 }
 
148
 // Link 2 verses
 
149
 else if (!strcmp(argv[1], "-l") && argc == 5) {
 
150
   // Do some initialization stuff
 
151
   RawText *mod = new RawText(argv[2]); // open our datapath with our RawText driver.
 
152
   
 
153
   mod->setKey(argv[4]);    // set key from argument
 
154
   SWKey tmpkey = (SWKey) argv[3];
 
155
   *(SWModule*)mod << &(tmpkey);
 
156
   delete mod;
 
157
 }
 
158
 
 
159
 else if (!strcmp(argv[1], "-d") && argc == 4) {
 
160
   RawText mod(argv[2]);        // open our datapath with our RawText driver.
 
161
   VerseKey *vkey = new VerseKey;
 
162
   vkey->Headings(1);
 
163
   vkey->AutoNormalize(0);
 
164
   vkey->Persist(1);      // the magical setting
 
165
   
 
166
   // Set our VerseKey
 
167
   mod.setKey(*vkey);
 
168
   *vkey = argv[3];
 
169
 
 
170
   if (!vkey->Chapter())
 
171
     {
 
172
       // bad hack >>
 
173
       // 0:0 is Book intro
 
174
       // (chapter):0 is Chapter intro
 
175
       //
 
176
       // 0:2 is Module intro
 
177
       // 0:1 is Testament intro
 
178
       int backstep = vkey->Verse();
 
179
       vkey->Verse(0);
 
180
       mod -= backstep;       
 
181
       // << bad hack
 
182
     }
 
183
   
 
184
   mod.deleteEntry();
 
185
   delete vkey;
 
186
 }
 
187
 
 
188
  // Make a new module
 
189
  else if (!strcmp(argv[1], "-c") && argc == 3) {
 
190
    // Try to initialize a default set of datafiles and indicies at our
 
191
    // datapath location passed to us from the user.
 
192
    if (RawText::createModule(argv[2])) {
 
193
      fprintf(stderr, "error: %s: couldn't create module at path: %s \n", argv[0], argv[2]);
 
194
      exit(-2);
 
195
    }
 
196
  }   
 
197
  
 
198
  // Bad arguments, print usage
 
199
  else {
 
200
    fprintf(stderr, helptext, argv[0], argv[0], argv[0], argv[0]);
 
201
    exit(-1);
 
202
  }
 
203
}