<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>versekey.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> </center>
<hr><h1>versekey.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> * VerseKey.cpp - code for class 'VerseKey'- a standard Biblical verse key</font>
00003 <font class="comment"> */</font>
00004
00005 <font class="preprocessor">#include <swmacs.h></font>
00006 <font class="preprocessor">#include <utilfuns.h></font>
00007 <font class="preprocessor">#include <string.h></font>
00008 <font class="preprocessor">#include <stdio.h></font>
00009 <font class="preprocessor">#include <fcntl.h></font>
00010 <font class="preprocessor">#include <stdlib.h></font>
00011
00012 <font class="preprocessor">#ifndef __GNUC__</font>
00013 <font class="preprocessor"></font><font class="preprocessor">#include <io.h></font>
00014 <font class="preprocessor">#else</font>
00015 <font class="preprocessor"></font><font class="preprocessor">#include <unistd.h></font>
00016 <font class="preprocessor">#endif</font>
00017 <font class="preprocessor"></font>
00018 <font class="preprocessor">#include <utilstr.h></font>
00019 <font class="preprocessor">#include <swkey.h></font>
00020 <font class="preprocessor">#include <swlog.h></font>
00021 <font class="preprocessor">#include <versekey.h></font>
00022 <font class="preprocessor">#include <localemgr.h></font>
00023 <font class="keyword">extern</font> <font class="stringliteral">"C"</font> {
00024 <font class="preprocessor">#include <roman.h></font>
00025 }
00026
00027
00028 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font> *classes[] = {<font class="stringliteral">"VerseKey"</font>, <font class="stringliteral">"SWKey"</font>, <font class="stringliteral">"SWObject"</font>, 0};
00029 <a class="code" href="class_s_w_class.html">SWClass</a> VerseKey::classdef(classes);
00030
00031 <font class="comment">/******************************************************************************</font>
00032 <font class="comment"> * Initialize static members of VerseKey</font>
00033 <font class="comment"> */</font>
00034
00035 <font class="preprocessor">#include <canon.h></font> <font class="comment">// Initialize static members of canonical books structure</font>
00036
00037 <font class="keyword">struct </font>sbook *VerseKey::builtin_books[2] = {0,0};
00038 <font class="keyword">const</font> <font class="keywordtype">char</font> VerseKey::builtin_BMAX[2] = {39, 27};
00039 <font class="keywordtype">long</font> *VerseKey::offsets[2][2] = {{VerseKey::otbks, VerseKey::otcps}, {VerseKey::ntbks, VerseKey::ntcps}};
<a name="l00040"></a><a class="code" href="class_verse_key.html#r3">00040</a> <font class="keywordtype">int</font> <a class="code" href="class_verse_key.html#r3">VerseKey::instance</a> = 0;
00041 VerseKey::LocaleCache VerseKey::localeCache;
00042
00043
00044 <font class="comment">/******************************************************************************</font>
00045 <font class="comment"> * VerseKey::init - initializes instance of VerseKey</font>
00046 <font class="comment"> */</font>
00047
<a name="l00048"></a><a class="code" href="class_verse_key.html#c3">00048</a> <font class="keywordtype">void</font> <a class="code" href="class_verse_key.html#c3">VerseKey::init</a>() {
00049 myclass = &classdef;
00050 <font class="keywordflow">if</font> (!<a class="code" href="class_verse_key.html#r3">instance</a>)
00051 <a class="code" href="class_verse_key.html#c2">initstatics</a>();
00052
00053 <a class="code" href="class_verse_key.html#r3">instance</a>++;
00054 <a class="code" href="class_verse_key.html#o8">autonorm</a> = 1; <font class="comment">// default auto normalization to true</font>
00055 <a class="code" href="class_verse_key.html#o9">headings</a> = 0; <font class="comment">// default display headings option is false</font>
00056 upperBound = 0;
00057 lowerBound = 0;
00058 <a class="code" href="class_verse_key.html#o4">testament</a> = 0;
00059 book = 0;
00060 chapter = 0;
00061 verse = 0;
00062 locale = 0;
00063
00064 setLocale(<a class="code" href="class_locale_mgr.html#p0">LocaleMgr::systemLocaleMgr</a>.getDefaultLocaleName());
00065 }
00066
00067 <font class="comment">/******************************************************************************</font>
00068 <font class="comment"> * VerseKey Constructor - initializes instance of VerseKey</font>
00069 <font class="comment"> *</font>
00070 <font class="comment"> * ENT: ikey - base key (will take various forms of 'BOOK CH:VS'. See</font>
00071 <font class="comment"> * VerseKey::parse for more detailed information)</font>
00072 <font class="comment"> */</font>
00073
<a name="l00074"></a><a class="code" href="class_verse_key.html#a1">00074</a> <a class="code" href="class_verse_key.html#a0">VerseKey::VerseKey</a>(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *ikey) : <a class="code" href="class_s_w_key.html">SWKey</a>(*ikey)
00075 {
00076 <a class="code" href="class_verse_key.html#c3">init</a>();
00077 <font class="keywordflow">if</font> (ikey)
00078 <a class="code" href="class_verse_key.html#c5">parse</a>();
00079 }
00080
00081
00082 <font class="comment">/******************************************************************************</font>
00083 <font class="comment"> * VerseKey Constructor - initializes instance of VerseKey</font>
00084 <font class="comment"> *</font>
00085 <font class="comment"> * ENT: ikey - text key (will take various forms of 'BOOK CH:VS'. See</font>
00086 <font class="comment"> * VerseKey::parse for more detailed information)</font>
00087 <font class="comment"> */</font>
00088
<a name="l00089"></a><a class="code" href="class_verse_key.html#a0">00089</a> <a class="code" href="class_verse_key.html#a0">VerseKey::VerseKey</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *ikey) : <a class="code" href="class_s_w_key.html">SWKey</a>(ikey)
00090 {
00091 <a class="code" href="class_verse_key.html#c3">init</a>();
00092 <font class="keywordflow">if</font> (ikey)
00093 <a class="code" href="class_verse_key.html#c5">parse</a>();
00094 }
00095
00096
00097 <a class="code" href="class_verse_key.html#a0">VerseKey::VerseKey</a>(VerseKey <font class="keyword">const</font> &k) : <a class="code" href="class_s_w_key.html">SWKey</a>(k)
00098 {
00099 <a class="code" href="class_verse_key.html#c3">init</a>();
00100 <a class="code" href="class_verse_key.html#o8">autonorm</a> = k.autonorm;
00101 <a class="code" href="class_verse_key.html#o9">headings</a> = k.headings;
00102 <a class="code" href="class_verse_key.html#o4">testament</a> = k.Testament();
00103 book = k.Book();
00104 chapter = k.Chapter();
00105 verse = k.Verse();
00106 <a class="code" href="class_verse_key.html#a7">LowerBound</a>(k.LowerBound());
00107 <a class="code" href="class_verse_key.html#a8">UpperBound</a>(k.UpperBound());
00108 }
00109
00110
<a name="l00111"></a><a class="code" href="class_verse_key.html#a2">00111</a> <a class="code" href="class_verse_key.html#a0">VerseKey::VerseKey</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *min, <font class="keyword">const</font> <font class="keywordtype">char</font> *max) : <a class="code" href="class_s_w_key.html">SWKey</a>()
00112 {
00113 <a class="code" href="class_verse_key.html#c3">init</a>();
00114 <a class="code" href="class_verse_key.html#a7">LowerBound</a>(min);
00115 <a class="code" href="class_verse_key.html#a8">UpperBound</a>(max);
00116 <a class="code" href="class_verse_key.html#a16">setPosition</a>(TOP);
00117 }
00118
00119
<a name="l00120"></a><a class="code" href="class_verse_key.html#a10">00120</a> <a class="code" href="class_s_w_key.html">SWKey</a> *<a class="code" href="class_verse_key.html#a10">VerseKey::clone</a>()<font class="keyword"> const</font>
00121 <font class="keyword"></font>{
00122 <font class="keywordflow">return</font> <font class="keyword">new</font> <a class="code" href="class_verse_key.html#a0">VerseKey</a>(*<font class="keyword">this</font>);
00123 }
00124
00125
00126 <font class="comment">/******************************************************************************</font>
00127 <font class="comment"> * VerseKey Destructor - cleans up instance of VerseKey</font>
00128 <font class="comment"> *</font>
00129 <font class="comment"> * ENT: ikey - text key</font>
00130 <font class="comment"> */</font>
00131
<a name="l00132"></a><a class="code" href="class_verse_key.html#a4">00132</a> <a class="code" href="class_verse_key.html#a4">VerseKey::~VerseKey</a>() {
00133 <font class="keywordflow">if</font> (upperBound)
00134 <font class="keyword">delete</font> upperBound;
00135 <font class="keywordflow">if</font> (lowerBound)
00136 <font class="keyword">delete</font> lowerBound;
00137 <font class="keywordflow">if</font> (locale)
00138 <font class="keyword">delete</font> [] locale;
00139
00140 --<a class="code" href="class_verse_key.html#r3">instance</a>;
00141 }
00142
00143
00144 <font class="keywordtype">void</font> VerseKey::setLocale(<font class="keyword">const</font> <font class="keywordtype">char</font> *name) {
00145 <font class="keywordtype">char</font> *BMAX;
00146 <font class="keyword">struct </font>sbook **books;
00147 <font class="keywordtype">bool</font> useCache = <font class="keyword">false</font>;
00148
00149 <font class="keywordflow">if</font> (localeCache.name)
00150 useCache = (!strcmp(localeCache.name, name));
00151
00152 <font class="keywordflow">if</font> (!useCache) { <font class="comment">// if we're setting params for a new locale</font>
00153 stdstr(&(localeCache.name), name);
00154 localeCache.abbrevsCnt = 0;
00155 }
00156
00157 <a class="code" href="class_s_w_locale.html">SWLocale</a> *locale = (useCache) ? localeCache.locale : <a class="code" href="class_locale_mgr.html#p0">LocaleMgr::systemLocaleMgr</a>.<a class="code" href="class_locale_mgr.html#a2">getLocale</a>(name);
00158 localeCache.locale = locale;
00159
00160 <font class="keywordflow">if</font> (locale) {
00161 locale-><a class="code" href="class_s_w_locale.html#a7">getBooks</a>(&BMAX, &books);
00162 setBooks(BMAX, books);
00163 setBookAbbrevs(locale-><a class="code" href="class_s_w_locale.html#a6">getBookAbbrevs</a>(), localeCache.abbrevsCnt);
00164 localeCache.abbrevsCnt = abbrevsCnt;
00165 }
00166 <font class="keywordflow">else</font> {
00167 setBooks(builtin_BMAX, builtin_books);
00168 setBookAbbrevs(builtin_abbrevs, localeCache.abbrevsCnt);
00169 localeCache.abbrevsCnt = abbrevsCnt;
00170 }
00171 stdstr(&(this->locale), localeCache.name);
00172 }
00173
00174
00175 <font class="keywordtype">void</font> VerseKey::setBooks(<font class="keyword">const</font> <font class="keywordtype">char</font> *iBMAX, <font class="keyword">struct</font> sbook **ibooks) {
00176 BMAX = iBMAX;
00177 books = ibooks;
00178 }
00179
00180
00181 <font class="keywordtype">void</font> VerseKey::setBookAbbrevs(<font class="keyword">const</font> <font class="keyword">struct</font> abbrev *bookAbbrevs, <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> size) {
00182 abbrevs = bookAbbrevs;
00183 <font class="keywordflow">if</font> (!size) {
00184 <font class="keywordflow">for</font> (abbrevsCnt = 1; *abbrevs[abbrevsCnt].ab; abbrevsCnt++) {
00185 <font class="comment">/*</font>
00186 <font class="comment"> if (strcmp(abbrevs[abbrevsCnt-1].ab, abbrevs[abbrevsCnt].ab) > 0) {</font>
00187 <font class="comment"> fprintf(stderr, "ERROR: book abbreviation (canon.h or locale) misordered at entry: %s\n", abbrevs[abbrevsCnt].ab);</font>
00188 <font class="comment"> exit(-1);</font>
00189 <font class="comment"> }</font>
00190 <font class="comment"> */</font>
00191 }
00192 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> t = 0; t < 2; t++) {
00193 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i = 0; i < BMAX[t]; i++) {
00194 <font class="keywordtype">int</font> bn = getBookAbbrev(books[t][i].name);
00195 <font class="keywordflow">if</font> ((bn-1)%39 != i) {
00196 SWLog::systemlog->LogError(<font class="stringliteral">"Book: %s does not have a matching toupper abbrevs entry! book number returned was: %d"</font>, books[t][i].name, bn);
00197 }
00198 }
00199 }
00200 }
00201 <font class="keywordflow">else</font> abbrevsCnt = size;
00202 }
00203
00204
00205 <font class="comment">/******************************************************************************</font>
00206 <font class="comment"> * VerseKey::initstatics - initializes statics. Performed only when first</font>
00207 <font class="comment"> * instance on VerseKey (or descendent) is created.</font>
00208 <font class="comment"> */</font>
00209
<a name="l00210"></a><a class="code" href="class_verse_key.html#c2">00210</a> <font class="keywordtype">void</font> <a class="code" href="class_verse_key.html#c2">VerseKey::initstatics</a>() {
00211 <font class="keywordtype">int</font> l1, l2, chaptmp = 0;
00212
00213 builtin_books[0] = otbooks;
00214 builtin_books[1] = ntbooks;
00215
00216 <font class="keywordflow">for</font> (l1 = 0; l1 < 2; l1++) {
00217 <font class="keywordflow">for</font> (l2 = 0; l2 < builtin_BMAX[l1]; l2++) {
00218 builtin_books[l1][l2].versemax = &vm[chaptmp];
00219 chaptmp += builtin_books[l1][l2].chapmax;
00220 }
00221 }
00222 }
00223
00224
00225 <font class="comment">/******************************************************************************</font>
00226 <font class="comment"> * VerseKey::parse - parses keytext into testament|book|chapter|verse</font>
00227 <font class="comment"> *</font>
00228 <font class="comment"> * RET: error status</font>
00229 <font class="comment"> */</font>
00230
<a name="l00231"></a><a class="code" href="class_verse_key.html#c5">00231</a> <font class="keywordtype">char</font> <a class="code" href="class_verse_key.html#c5">VerseKey::parse</a>()
00232 {
00233
00234
00235 <a class="code" href="class_verse_key.html#o4">testament</a> = 1;
00236 book = 1;
00237 chapter = 1;
00238 verse = 1;
00239
00240 error = 0;
00241
00242 <font class="keywordflow">if</font> (keytext) {
00243 <a class="code" href="class_list_key.html">ListKey</a> tmpListKey = VerseKey::ParseVerseList(keytext);
00244 <font class="keywordflow">if</font> (tmpListKey.<a class="code" href="class_list_key.html#a5">Count</a>()) {
00245 <a class="code" href="class_s_w_key.html#a7">SWKey::setText</a>((<font class="keyword">const</font> <font class="keywordtype">char</font> *)tmpListKey);
00246 <font class="keywordflow">for</font> (<a class="code" href="class_verse_key.html#o4">testament</a> = 1; <a class="code" href="class_verse_key.html#o4">testament</a> < 3; <a class="code" href="class_verse_key.html#o4">testament</a>++) {
00247 <font class="keywordflow">for</font> (book = 1; book <= BMAX[<a class="code" href="class_verse_key.html#o4">testament</a>-1]; book++) {
00248 <font class="keywordflow">if</font> (!strncmp(keytext, books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].name, strlen(books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].name)))
00249 <font class="keywordflow">break</font>;
00250 }
00251 <font class="keywordflow">if</font> (book <= BMAX[<a class="code" href="class_verse_key.html#o4">testament</a>-1])
00252 <font class="keywordflow">break</font>;
00253 }
00254
00255 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#o4">testament</a> < 3) {
00256 sscanf(&keytext[strlen(books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].name)], <font class="stringliteral">"%d:%d"</font>, &chapter, &verse);
00257 }
00258 <font class="keywordflow">else</font> error = 1;
00259 }
00260 }
00261 <a class="code" href="class_verse_key.html#a30">Normalize</a>(1);
00262 <a class="code" href="class_verse_key.html#c4">freshtext</a>();
00263
00264 <font class="keywordflow">return</font> error;
00265 }
00266
00267
00268 <font class="comment">/******************************************************************************</font>
00269 <font class="comment"> * VerseKey::freshtext - refreshes keytext based on</font>
00270 <font class="comment"> * testament|book|chapter|verse</font>
00271 <font class="comment"> */</font>
00272
<a name="l00273"></a><a class="code" href="class_verse_key.html#c4">00273</a> <font class="keywordtype">void</font> <a class="code" href="class_verse_key.html#c4">VerseKey::freshtext</a>()<font class="keyword"> const</font>
00274 <font class="keyword"></font>{
00275 <font class="keywordtype">char</font> buf[2024];
00276 <font class="keywordtype">int</font> realtest = <a class="code" href="class_verse_key.html#o4">testament</a>;
00277 <font class="keywordtype">int</font> realbook = book;
00278
00279 <font class="keywordflow">if</font> (book < 1) {
00280 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#o4">testament</a> < 1)
00281 sprintf(buf, <font class="stringliteral">"[ Module Heading ]"</font>);
00282 <font class="keywordflow">else</font> sprintf(buf, <font class="stringliteral">"[ Testament %d Heading ]"</font>, (<font class="keywordtype">int</font>)<a class="code" href="class_verse_key.html#o4">testament</a>);
00283 }
00284 <font class="keywordflow">else</font> {
00285 <font class="keywordflow">if</font> (realbook > BMAX[realtest-1]) {
00286 realbook -= BMAX[realtest-1];
00287 <font class="keywordflow">if</font> (realtest < 2)
00288 realtest++;
00289 <font class="keywordflow">if</font> (realbook > BMAX[realtest-1])
00290 realbook = BMAX[realtest-1];
00291 }
00292 sprintf(buf, <font class="stringliteral">"%s %d:%d"</font>, books[realtest-1][realbook-1].name, chapter, verse);
00293 }
00294
00295 stdstr((<font class="keywordtype">char</font> **)&keytext, buf);
00296 }
00297
00298
00299
00300 <font class="comment">/******************************************************************************</font>
00301 <font class="comment"> * VerseKey::getBookAbbrev - Attempts to find a book abbreviation for a buffer</font>
00302 <font class="comment"> *</font>
00303 <font class="comment"> * ENT: abbr - key for which to search;</font>
00304 <font class="comment"> * RET: book number or < 0 = not valid</font>
00305 <font class="comment"> */</font>
00306
00307 <font class="keywordtype">int</font> VerseKey::getBookAbbrev(<font class="keyword">const</font> <font class="keywordtype">char</font> *iabbr)
00308 {
00309 <font class="keywordtype">int</font> loop, diff, abLen, min, max, target, retVal = -1;
00310
00311 <font class="keywordtype">char</font> *abbr = 0;
00312
00313 stdstr(&abbr, iabbr);
00314 strstrip(abbr);
00315 abLen = strlen(abbr);
00316 <font class="keywordflow">for</font> (loop = 0; loop < abLen; loop++)
00317 abbr[loop] = SW_toupper(abbr[loop]);
00318
00319 <font class="keywordflow">if</font> (abLen) {
00320 min = 0;
00321 <font class="comment">// max = abbrevsCnt - 1;</font>
00322 max = abbrevsCnt;
00323 <font class="keywordflow">while</font>(1) {
00324 target = min + ((max - min) / 2);
00325 diff = strncmp(abbr, abbrevs[target].ab, abLen);
00326 <font class="keywordflow">if</font> ((!diff)||(target >= max)||(target <= min))
00327 <font class="keywordflow">break</font>;
00328 <font class="keywordflow">if</font> (diff > 0)
00329 min = target;
00330 <font class="keywordflow">else</font> max = target;
00331 }
00332 <font class="keywordflow">for</font> (; target > 0; target--) {
00333 <font class="keywordflow">if</font> (strncmp(abbr, abbrevs[target-1].ab, abLen))
00334 <font class="keywordflow">break</font>;
00335 }
00336
00337 retVal = (!diff) ? abbrevs[target].book : -1;
00338 }
00339 <font class="keyword">delete</font> [] abbr;
00340 <font class="keywordflow">return</font> retVal;
00341 }
00342
00343 <font class="comment">/******************************************************************************</font>
00344 <font class="comment"> * VerseKey::ParseVerseList - Attempts to parse a buffer into separate</font>
00345 <font class="comment"> * verse entries returned in a ListKey</font>
00346 <font class="comment"> *</font>
00347 <font class="comment"> * ENT: buf - buffer to parse;</font>
00348 <font class="comment"> * defaultKey - if verse, chap, book, or testament is left off,</font>
00349 <font class="comment"> * pull info from this key (ie. Gen 2:3; 4:5;</font>
00350 <font class="comment"> * Gen would be used when parsing the 4:5 section)</font>
00351 <font class="comment"> * expandRange - whether or not to expand eg. John 1:10-12 or just</font>
00352 <font class="comment"> * save John 1:10</font>
00353 <font class="comment"> *</font>
00354 <font class="comment"> * RET: ListKey reference filled with verse entries contained in buf</font>
00355 <font class="comment"> *</font>
00356 <font class="comment"> * COMMENT: This code works but wreaks. Rewrite to make more maintainable.</font>
00357 <font class="comment"> */</font>
00358
00359 <a class="code" href="class_list_key.html">ListKey</a> VerseKey::ParseVerseList(<font class="keyword">const</font> <font class="keywordtype">char</font> *buf, <font class="keyword">const</font> <font class="keywordtype">char</font> *defaultKey, <font class="keywordtype">bool</font> expandRange) {
00360 <a class="code" href="class_s_w_key.html">SWKey</a> textkey;
00361
00362 <font class="keywordtype">char</font> book[255];
00363 <font class="keywordtype">char</font> number[255];
00364 <font class="keywordtype">int</font> tobook = 0;
00365 <font class="keywordtype">int</font> tonumber = 0;
00366 <font class="keywordtype">int</font> chap = -1, verse = -1;
00367 <font class="keywordtype">int</font> bookno = 0;
00368 VerseKey curkey, lBound;
00369 curkey.<a class="code" href="class_verse_key.html#a42">setLocale</a>(getLocale());
00370 lBound.<a class="code" href="class_verse_key.html#a42">setLocale</a>(getLocale());
00371 <font class="keywordtype">int</font> loop;
00372 <font class="keywordtype">char</font> comma = 0;
00373 <font class="keywordtype">char</font> dash = 0;
00374 <font class="keyword">const</font> <font class="keywordtype">char</font> *orig = buf;
00375 <a class="code" href="class_list_key.html">ListKey</a> tmpListKey;
00376 <a class="code" href="class_list_key.html">ListKey</a> internalListKey;
00377 <a class="code" href="class_s_w_key.html">SWKey</a> tmpDefaultKey = defaultKey;
00378 <font class="keywordtype">char</font> lastPartial = 0;
00379
00380 curkey.<a class="code" href="class_verse_key.html#a31">AutoNormalize</a>(0);
00381 tmpListKey << tmpDefaultKey;
00382 tmpListKey.<a class="code" href="class_list_key.html#a8">GetElement</a>()-><a class="code" href="class_s_w_key.html#m0">userData</a> = (<font class="keywordtype">void</font> *)buf;
00383
00384 <font class="keywordflow">while</font> (*buf) {
00385 <font class="keywordflow">switch</font> (*buf) {
00386 <font class="keywordflow">case</font> <font class="charliteral">':'</font>:
00387 number[tonumber] = 0;
00388 tonumber = 0;
00389 <font class="keywordflow">if</font> (*number)
00390 chap = atoi(number);
00391 *number = 0;
00392 <font class="keywordflow">break</font>;
00393
00394 <font class="keywordflow">case</font> <font class="charliteral">'-'</font>:
00395 <font class="keywordflow">case</font> <font class="charliteral">','</font>: <font class="comment">// on number new verse</font>
00396 <font class="keywordflow">case</font> <font class="charliteral">';'</font>: <font class="comment">// on number new chapter</font>
00397 number[tonumber] = 0;
00398 tonumber = 0;
00399 <font class="keywordflow">if</font> (*number) {
00400 <font class="keywordflow">if</font> (chap >= 0)
00401 verse = atoi(number);
00402 <font class="keywordflow">else</font> chap = atoi(number);
00403 }
00404 *number = 0;
00405 book[tobook] = 0;
00406 tobook = 0;
00407 bookno = -1;
00408 <font class="keywordflow">if</font> (*book) {
00409 <font class="keywordflow">for</font> (loop = strlen(book) - 1; loop+1; loop--) {
00410 <font class="keywordflow">if</font> ((isdigit(book[loop])) || (book[loop] == <font class="charliteral">' '</font>)) {
00411 book[loop] = 0;
00412 <font class="keywordflow">continue</font>;
00413 }
00414 <font class="keywordflow">else</font> {
00415 <font class="keywordflow">if</font> ((SW_toupper(book[loop])==<font class="charliteral">'F'</font>)&&(loop)) {
00416 <font class="keywordflow">if</font> ((isdigit(book[loop-1])) || (book[loop-1] == <font class="charliteral">' '</font>) || (SW_toupper(book[loop-1]) == <font class="charliteral">'F'</font>)) {
00417 book[loop] = 0;
00418 <font class="keywordflow">continue</font>;
00419 }
00420 }
00421 }
00422 <font class="keywordflow">break</font>;
00423 }
00424
00425 <font class="keywordflow">for</font> (loop = strlen(book) - 1; loop+1; loop--) {
00426 <font class="keywordflow">if</font> (book[loop] == <font class="charliteral">' '</font>) {
00427 <font class="keywordflow">if</font> (isroman(&book[loop+1])) {
00428 <font class="keywordflow">if</font> (verse == -1) {
00429 verse = chap;
00430 chap = from_rom(&book[loop+1]);
00431 book[loop] = 0;
00432 }
00433 }
00434 <font class="keywordflow">break</font>;
00435 }
00436 }
00437
00438 <font class="keywordflow">if</font> ((!stricmp(book, <font class="stringliteral">"V"</font>)) || (!stricmp(book, <font class="stringliteral">"VER"</font>))) { <font class="comment">// Verse abbrev</font>
00439 <font class="keywordflow">if</font> (verse == -1) {
00440 verse = chap;
00441 chap = <a class="code" href="class_verse_key.html#a0">VerseKey</a>(tmpListKey).Chapter();
00442 *book = 0;
00443 }
00444 }
00445 bookno = getBookAbbrev(book);
00446 }
00447 <font class="keywordflow">if</font> (((bookno > -1) || (!*book)) && ((*book) || (chap >= 0) || (verse >= 0))) {
00448 <font class="keywordtype">char</font> partial = 0;
00449 curkey.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00450 curkey.<a class="code" href="class_verse_key.html#a24">Chapter</a>(1);
00451 curkey.<a class="code" href="class_verse_key.html#a23">Book</a>(1);
00452
00453 <font class="keywordflow">if</font> (bookno < 0) {
00454 curkey.<a class="code" href="class_verse_key.html#a22">Testament</a>(<a class="code" href="class_verse_key.html#a0">VerseKey</a>(tmpListKey).<a class="code" href="class_verse_key.html#a22">Testament</a>());
00455 curkey.<a class="code" href="class_verse_key.html#a23">Book</a>(<a class="code" href="class_verse_key.html#a0">VerseKey</a>(tmpListKey).<a class="code" href="class_verse_key.html#a23">Book</a>());
00456 }
00457 <font class="keywordflow">else</font> {
00458 curkey.<a class="code" href="class_verse_key.html#a22">Testament</a>(1);
00459 curkey.<a class="code" href="class_verse_key.html#a23">Book</a>(bookno);
00460 }
00461
00462 <font class="keywordflow">if</font> (((comma)||((verse < 0)&&(bookno < 0)))&&(!lastPartial)) {
00463 <font class="comment">// if (comma) {</font>
00464 curkey.<a class="code" href="class_verse_key.html#a24">Chapter</a>(<a class="code" href="class_verse_key.html#a0">VerseKey</a>(tmpListKey).<a class="code" href="class_verse_key.html#a24">Chapter</a>());
00465 curkey.<a class="code" href="class_verse_key.html#a25">Verse</a>(chap); <font class="comment">// chap because this is the first number captured</font>
00466 }
00467 <font class="keywordflow">else</font> {
00468 <font class="keywordflow">if</font> (chap >= 0) {
00469 curkey.<a class="code" href="class_verse_key.html#a24">Chapter</a>(chap);
00470 }
00471 <font class="keywordflow">else</font> {
00472 partial++;
00473 curkey.<a class="code" href="class_verse_key.html#a24">Chapter</a>(1);
00474 }
00475 <font class="keywordflow">if</font> (verse >= 0) {
00476 curkey.<a class="code" href="class_verse_key.html#a25">Verse</a>(verse);
00477 }
00478 <font class="keywordflow">else</font> {
00479 partial++;
00480 curkey.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00481 }
00482 }
00483
00484 <font class="keywordflow">if</font> ((*buf == <font class="charliteral">'-'</font>) && (expandRange)) { <font class="comment">// if this is a dash save lowerBound and wait for upper</font>
00485 VerseKey newElement;
00486 newElement.<a class="code" href="class_verse_key.html#a5">LowerBound</a>(curkey);
00487 newElement.<a class="code" href="class_verse_key.html#a16">setPosition</a>(TOP);
00488 tmpListKey << newElement;
00489 tmpListKey.<a class="code" href="class_list_key.html#a8">GetElement</a>()-><a class="code" href="class_s_w_key.html#m0">userData</a> = (<font class="keywordtype">void</font> *)buf;
00490 }
00491 <font class="keywordflow">else</font> {
00492 <font class="keywordflow">if</font> (!dash) { <font class="comment">// if last separator was not a dash just add</font>
00493 <font class="keywordflow">if</font> (expandRange && partial) {
00494 VerseKey newElement;
00495 newElement.<a class="code" href="class_verse_key.html#a5">LowerBound</a>(curkey);
00496 <font class="keywordflow">if</font> (partial > 1)
00497 curkey.<a class="code" href="class_verse_key.html#a16">setPosition</a>(MAXCHAPTER);
00498 <font class="keywordflow">if</font> (partial > 0)
00499 curkey = MAXVERSE;
00500 newElement.<a class="code" href="class_verse_key.html#a6">UpperBound</a>(curkey);
00501 newElement = TOP;
00502 tmpListKey << newElement;
00503 tmpListKey.<a class="code" href="class_list_key.html#a8">GetElement</a>()-><a class="code" href="class_s_w_key.html#m0">userData</a> = (<font class="keywordtype">void</font> *)buf;
00504 }
00505 <font class="keywordflow">else</font> {
00506 tmpListKey << (<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> &)(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a>)(<font class="keyword">const</font> <font class="keywordtype">char</font> *)curkey;
00507 tmpListKey.<a class="code" href="class_list_key.html#a8">GetElement</a>()-><a class="code" href="class_s_w_key.html#m0">userData</a> = (<font class="keywordtype">void</font> *)buf;
00508 }
00509 }
00510 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (expandRange) {
00511 VerseKey *newElement = SWDYNAMIC_CAST(VerseKey, tmpListKey.<a class="code" href="class_list_key.html#a8">GetElement</a>());
00512 <font class="keywordflow">if</font> (newElement) {
00513 <font class="keywordflow">if</font> (partial > 1)
00514 curkey = MAXCHAPTER;
00515 <font class="keywordflow">if</font> (partial > 0)
00516 curkey = MAXVERSE;
00517 newElement-><a class="code" href="class_verse_key.html#a6">UpperBound</a>(curkey);
00518 *newElement = TOP;
00519 tmpListKey.<a class="code" href="class_list_key.html#a8">GetElement</a>()-><a class="code" href="class_s_w_key.html#m0">userData</a> = (<font class="keywordtype">void</font> *)buf;
00520 }
00521 }
00522 }
00523 lastPartial = partial;
00524 }
00525 *book = 0;
00526 chap = -1;
00527 verse = -1;
00528 <font class="keywordflow">if</font> (*buf == <font class="charliteral">','</font>)
00529 comma = 1;
00530 <font class="keywordflow">else</font> comma = 0;
00531 <font class="keywordflow">if</font> (*buf == <font class="charliteral">'-'</font>)
00532 dash = 1;
00533 <font class="keywordflow">else</font> dash = 0;
00534 <font class="keywordflow">break</font>;
00535 <font class="keywordflow">case</font> 10: <font class="comment">// ignore these</font>
00536 <font class="keywordflow">case</font> 13:
00537 <font class="keywordflow">break</font>;
00538 <font class="keywordflow">case</font> <font class="charliteral">'.'</font>:
00539 <font class="keywordflow">if</font> (buf > orig) <font class="comment">// ignore (break) if preceeding char is not a digit</font>
00540 <font class="keywordflow">if</font> (!isdigit(*(buf-1)))
00541 <font class="keywordflow">break</font>;
00542
00543 <font class="keywordflow">default</font>:
00544 <font class="keywordflow">if</font> (isdigit(*buf)) {
00545 number[tonumber++] = *buf;
00546 }
00547 <font class="keywordflow">else</font> {
00548 <font class="keywordflow">switch</font> (*buf) {
00549 <font class="keywordflow">case</font> <font class="charliteral">' '</font>: <font class="comment">// ignore these and don't reset number</font>
00550 <font class="keywordflow">case</font> <font class="charliteral">'f'</font>:
00551 <font class="keywordflow">case</font> <font class="charliteral">'F'</font>:
00552 <font class="keywordflow">break</font>;
00553 <font class="keywordflow">default</font>:
00554 number[tonumber] = 0;
00555 tonumber = 0;
00556 <font class="keywordflow">break</font>;
00557 }
00558 }
00559 <font class="keywordflow">if</font> (chap == -1)
00560 book[tobook++] = SW_toupper(*buf);
00561 }
00562 buf++;
00563 }
00564 number[tonumber] = 0;
00565 tonumber = 0;
00566 <font class="keywordflow">if</font> (*number) {
00567 <font class="keywordflow">if</font> (chap >= 0)
00568 verse = atoi(number);
00569 <font class="keywordflow">else</font> chap = atoi(number);
00570 }
00571 *number = 0;
00572 book[tobook] = 0;
00573 tobook = 0;
00574 <font class="keywordflow">if</font> (*book) {
00575 <font class="keywordflow">for</font> (loop = strlen(book) - 1; loop+1; loop--) {
00576 <font class="keywordflow">if</font> ((isdigit(book[loop])) || (book[loop] == <font class="charliteral">' '</font>)) {
00577 book[loop] = 0;
00578 <font class="keywordflow">continue</font>;
00579 }
00580 <font class="keywordflow">else</font> {
00581 <font class="keywordflow">if</font> ((SW_toupper(book[loop])==<font class="charliteral">'F'</font>)&&(loop)) {
00582 <font class="keywordflow">if</font> ((isdigit(book[loop-1])) || (book[loop-1] == <font class="charliteral">' '</font>) || (SW_toupper(book[loop-1]) == <font class="charliteral">'F'</font>)) {
00583 book[loop] = 0;
00584 <font class="keywordflow">continue</font>;
00585 }
00586 }
00587 }
00588 <font class="keywordflow">break</font>;
00589 }
00590
00591 <font class="keywordflow">for</font> (loop = strlen(book) - 1; loop+1; loop--) {
00592 <font class="keywordflow">if</font> (book[loop] == <font class="charliteral">' '</font>) {
00593 <font class="keywordflow">if</font> (isroman(&book[loop+1])) {
00594 <font class="keywordflow">if</font> (verse == -1) {
00595 verse = chap;
00596 chap = from_rom(&book[loop+1]);
00597 book[loop] = 0;
00598 }
00599 }
00600 <font class="keywordflow">break</font>;
00601 }
00602 }
00603
00604 <font class="keywordflow">if</font> ((!stricmp(book, <font class="stringliteral">"V"</font>)) || (!stricmp(book, <font class="stringliteral">"VER"</font>))) { <font class="comment">// Verse abbrev.</font>
00605 <font class="keywordflow">if</font> (verse == -1) {
00606 verse = chap;
00607 chap = <a class="code" href="class_verse_key.html#a0">VerseKey</a>(tmpListKey).Chapter();
00608 *book = 0;
00609 }
00610 }
00611
00612 bookno = getBookAbbrev(book);
00613 }
00614 <font class="keywordflow">if</font> (((bookno > -1) || (!*book)) && ((*book) || (chap >= 0) || (verse >= 0))) {
00615 <font class="keywordtype">char</font> partial = 0;
00616 curkey.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00617 curkey.<a class="code" href="class_verse_key.html#a24">Chapter</a>(1);
00618 curkey.<a class="code" href="class_verse_key.html#a23">Book</a>(1);
00619
00620 <font class="keywordflow">if</font> (bookno < 0) {
00621 curkey.<a class="code" href="class_verse_key.html#a22">Testament</a>(<a class="code" href="class_verse_key.html#a0">VerseKey</a>(tmpListKey).<a class="code" href="class_verse_key.html#a22">Testament</a>());
00622 curkey.<a class="code" href="class_verse_key.html#a23">Book</a>(<a class="code" href="class_verse_key.html#a0">VerseKey</a>(tmpListKey).<a class="code" href="class_verse_key.html#a23">Book</a>());
00623 }
00624 <font class="keywordflow">else</font> {
00625 curkey.<a class="code" href="class_verse_key.html#a22">Testament</a>(1);
00626 curkey.<a class="code" href="class_verse_key.html#a23">Book</a>(bookno);
00627 }
00628
00629 <font class="keywordflow">if</font> (((comma)||((verse < 0)&&(bookno < 0)))&&(!lastPartial)) {
00630 <font class="comment">// if (comma) {</font>
00631 curkey.<a class="code" href="class_verse_key.html#a24">Chapter</a>(<a class="code" href="class_verse_key.html#a0">VerseKey</a>(tmpListKey).<a class="code" href="class_verse_key.html#a24">Chapter</a>());
00632 curkey.<a class="code" href="class_verse_key.html#a25">Verse</a>(chap); <font class="comment">// chap because this is the first number captured</font>
00633 }
00634 <font class="keywordflow">else</font> {
00635 <font class="keywordflow">if</font> (chap >= 0) {
00636 curkey.<a class="code" href="class_verse_key.html#a24">Chapter</a>(chap);
00637 }
00638 <font class="keywordflow">else</font> {
00639 partial++;
00640 curkey.<a class="code" href="class_verse_key.html#a24">Chapter</a>(1);
00641 }
00642 <font class="keywordflow">if</font> (verse >= 0) {
00643 curkey.<a class="code" href="class_verse_key.html#a25">Verse</a>(verse);
00644 }
00645 <font class="keywordflow">else</font> {
00646 partial++;
00647 curkey.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00648 }
00649 }
00650
00651 <font class="keywordflow">if</font> ((*buf == <font class="charliteral">'-'</font>) && (expandRange)) { <font class="comment">// if this is a dash save lowerBound and wait for upper</font>
00652 VerseKey newElement;
00653 newElement.<a class="code" href="class_verse_key.html#a5">LowerBound</a>(curkey);
00654 newElement = TOP;
00655 tmpListKey << newElement;
00656 tmpListKey.<a class="code" href="class_list_key.html#a8">GetElement</a>()-><a class="code" href="class_s_w_key.html#m0">userData</a> = (<font class="keywordtype">void</font> *)buf;
00657 }
00658 <font class="keywordflow">else</font> {
00659 <font class="keywordflow">if</font> (!dash) { <font class="comment">// if last separator was not a dash just add</font>
00660 <font class="keywordflow">if</font> (expandRange && partial) {
00661 VerseKey newElement;
00662 newElement.<a class="code" href="class_verse_key.html#a5">LowerBound</a>(curkey);
00663 <font class="keywordflow">if</font> (partial > 1)
00664 curkey = MAXCHAPTER;
00665 <font class="keywordflow">if</font> (partial > 0)
00666 curkey = MAXVERSE;
00667 newElement.<a class="code" href="class_verse_key.html#a6">UpperBound</a>(curkey);
00668 newElement = TOP;
00669 tmpListKey << newElement;
00670 tmpListKey.<a class="code" href="class_list_key.html#a8">GetElement</a>()-><a class="code" href="class_s_w_key.html#m0">userData</a> = (<font class="keywordtype">void</font> *)buf;
00671 }
00672 <font class="keywordflow">else</font> {
00673 tmpListKey << (<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> &)(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a>)(<font class="keyword">const</font> <font class="keywordtype">char</font> *)curkey;
00674 tmpListKey.<a class="code" href="class_list_key.html#a8">GetElement</a>()-><a class="code" href="class_s_w_key.html#m0">userData</a> = (<font class="keywordtype">void</font> *)buf;
00675 }
00676 }
00677 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (expandRange) {
00678 VerseKey *newElement = SWDYNAMIC_CAST(VerseKey, tmpListKey.<a class="code" href="class_list_key.html#a8">GetElement</a>());
00679 <font class="keywordflow">if</font> (newElement) {
00680 <font class="keywordflow">if</font> (partial > 1)
00681 curkey = MAXCHAPTER;
00682 <font class="keywordflow">if</font> (partial > 0)
00683 curkey = MAXVERSE;
00684 newElement-><a class="code" href="class_verse_key.html#a6">UpperBound</a>(curkey);
00685 *newElement = TOP;
00686 tmpListKey.<a class="code" href="class_list_key.html#a8">GetElement</a>()-><a class="code" href="class_s_w_key.html#m0">userData</a> = (<font class="keywordtype">void</font> *)buf;
00687 }
00688 }
00689 }
00690 }
00691 *book = 0;
00692 tmpListKey = TOP;
00693 tmpListKey.<a class="code" href="class_list_key.html#a6">Remove</a>(); <font class="comment">// remove defaultKey</font>
00694 internalListKey = tmpListKey;
00695 internalListKey = TOP; <font class="comment">// Align internalListKey to first element before passing back;</font>
00696
00697 <font class="keywordflow">return</font> internalListKey;
00698 }
00699
00700
00701 <font class="comment">/******************************************************************************</font>
00702 <font class="comment"> * VerseKey::LowerBound - sets / gets the lower boundary for this key</font>
00703 <font class="comment"> */</font>
00704
<a name="l00705"></a><a class="code" href="class_verse_key.html#a5">00705</a> VerseKey &<a class="code" href="class_verse_key.html#a7">VerseKey::LowerBound</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *lb)
00706 {
00707 <font class="keywordflow">if</font> (!lowerBound)
00708 initBounds();
00709
00710 (*lowerBound) = lb;
00711 lowerBound-><a class="code" href="class_verse_key.html#a30">Normalize</a>();
00712
00713 <font class="keywordflow">return</font> (*lowerBound);
00714 }
00715
00716
00717 <font class="comment">/******************************************************************************</font>
00718 <font class="comment"> * VerseKey::UpperBound - sets / gets the upper boundary for this key</font>
00719 <font class="comment"> */</font>
00720
<a name="l00721"></a><a class="code" href="class_verse_key.html#a6">00721</a> VerseKey &<a class="code" href="class_verse_key.html#a8">VerseKey::UpperBound</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *ub)
00722 {
00723 <font class="keywordflow">if</font> (!upperBound)
00724 initBounds();
00725
00726 <font class="comment">// need to set upperbound parsing to resolve to max verse/chap if not specified</font>
00727 (*upperBound) = ub;
00728 <font class="keywordflow">if</font> (*upperBound < *lowerBound)
00729 *upperBound = *lowerBound;
00730 upperBound-><a class="code" href="class_verse_key.html#a30">Normalize</a>();
00731
00732 <font class="comment">// until we have a proper method to resolve max verse/chap use this kludge</font>
00733 <font class="keywordtype">int</font> len = strlen(ub);
00734 <font class="keywordtype">bool</font> alpha = <font class="keyword">false</font>;
00735 <font class="keywordtype">bool</font> versespec = <font class="keyword">false</font>;
00736 <font class="keywordtype">bool</font> chapspec = <font class="keyword">false</font>;
00737 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i = 0; i < len; i++) {
00738 <font class="keywordflow">if</font> (isalpha(ub[i]))
00739 alpha = <font class="keyword">true</font>;
00740 <font class="keywordflow">if</font> (ub[i] == <font class="charliteral">':'</font>) <font class="comment">// if we have a : we assume verse spec</font>
00741 versespec = <font class="keyword">true</font>;
00742 <font class="keywordflow">if</font> ((isdigit(ub[i])) && (alpha)) <font class="comment">// if digit after alpha assume chap spec</font>
00743 chapspec = <font class="keyword">true</font>;
00744 }
00745 <font class="keywordflow">if</font> (!chapspec)
00746 *upperBound = MAXCHAPTER;
00747 <font class="keywordflow">if</font> (!versespec)
00748 *upperBound = MAXVERSE;
00749
00750
00751 <font class="comment">// -- end kludge</font>
00752
00753 <font class="keywordflow">return</font> (*upperBound);
00754 }
00755
00756
00757 <font class="comment">/******************************************************************************</font>
00758 <font class="comment"> * VerseKey::LowerBound - sets / gets the lower boundary for this key</font>
00759 <font class="comment"> */</font>
00760
<a name="l00761"></a><a class="code" href="class_verse_key.html#a7">00761</a> VerseKey &<a class="code" href="class_verse_key.html#a7">VerseKey::LowerBound</a>()<font class="keyword"> const</font>
00762 <font class="keyword"></font>{
00763 <font class="keywordflow">if</font> (!lowerBound)
00764 initBounds();
00765
00766 <font class="keywordflow">return</font> (*lowerBound);
00767 }
00768
00769
00770 <font class="comment">/******************************************************************************</font>
00771 <font class="comment"> * VerseKey::UpperBound - sets / gets the upper boundary for this key</font>
00772 <font class="comment"> */</font>
00773
<a name="l00774"></a><a class="code" href="class_verse_key.html#a8">00774</a> VerseKey &<a class="code" href="class_verse_key.html#a8">VerseKey::UpperBound</a>()<font class="keyword"> const</font>
00775 <font class="keyword"></font>{
00776 <font class="keywordflow">if</font> (!upperBound)
00777 initBounds();
00778
00779 <font class="keywordflow">return</font> (*upperBound);
00780 }
00781
00782
00783 <font class="comment">/******************************************************************************</font>
00784 <font class="comment"> * VerseKey::ClearBounds - clears bounds for this VerseKey</font>
00785 <font class="comment"> */</font>
00786
<a name="l00787"></a><a class="code" href="class_verse_key.html#a9">00787</a> <font class="keywordtype">void</font> <a class="code" href="class_verse_key.html#a9">VerseKey::ClearBounds</a>()
00788 {
00789 initBounds();
00790 }
00791
00792
00793 <font class="keywordtype">void</font> VerseKey::initBounds()<font class="keyword"> const</font>
00794 <font class="keyword"></font>{
00795 <font class="keywordflow">if</font> (!upperBound) {
00796 upperBound = <font class="keyword">new</font> <a class="code" href="class_verse_key.html#a0">VerseKey</a>();
00797 upperBound-><a class="code" href="class_verse_key.html#a31">AutoNormalize</a>(0);
00798 upperBound-><a class="code" href="class_verse_key.html#a32">Headings</a>(1);
00799 }
00800 <font class="keywordflow">if</font> (!lowerBound) {
00801 lowerBound = <font class="keyword">new</font> <a class="code" href="class_verse_key.html#a0">VerseKey</a>();
00802 lowerBound-><a class="code" href="class_verse_key.html#a31">AutoNormalize</a>(0);
00803 lowerBound-><a class="code" href="class_verse_key.html#a32">Headings</a>(1);
00804 }
00805
00806 lowerBound-><a class="code" href="class_verse_key.html#a22">Testament</a>(0);
00807 lowerBound-><a class="code" href="class_verse_key.html#a23">Book</a>(0);
00808 lowerBound-><a class="code" href="class_verse_key.html#a24">Chapter</a>(0);
00809 lowerBound-><a class="code" href="class_verse_key.html#a25">Verse</a>(0);
00810
00811 upperBound-><a class="code" href="class_verse_key.html#a22">Testament</a>(2);
00812 upperBound-><a class="code" href="class_verse_key.html#a23">Book</a>(BMAX[1]);
00813 upperBound-><a class="code" href="class_verse_key.html#a24">Chapter</a>(books[1][BMAX[1]-1].chapmax);
00814 upperBound-><a class="code" href="class_verse_key.html#a25">Verse</a>(books[1][BMAX[1]-1].versemax[upperBound-><a class="code" href="class_verse_key.html#a24">Chapter</a>()-1]);
00815 }
00816
00817
00818 <font class="comment">/******************************************************************************</font>
00819 <font class="comment"> * VerseKey::copyFrom - Equates this VerseKey to another VerseKey</font>
00820 <font class="comment"> */</font>
00821
<a name="l00822"></a><a class="code" href="class_verse_key.html#a15">00822</a> <font class="keywordtype">void</font> <a class="code" href="class_verse_key.html#a14">VerseKey::copyFrom</a>(<font class="keyword">const</font> VerseKey &ikey) {
00823 <a class="code" href="class_s_w_key.html#a8">SWKey::copyFrom</a>(ikey);
00824
00825 <a class="code" href="class_verse_key.html#c5">parse</a>();
00826 }
00827
00828
00829 <font class="comment">/******************************************************************************</font>
00830 <font class="comment"> * VerseKey::copyFrom - Equates this VerseKey to another SWKey</font>
00831 <font class="comment"> */</font>
00832
<a name="l00833"></a><a class="code" href="class_verse_key.html#a14">00833</a> <font class="keywordtype">void</font> <a class="code" href="class_verse_key.html#a14">VerseKey::copyFrom</a>(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> &ikey) {
00834 <a class="code" href="class_s_w_key.html#a8">SWKey::copyFrom</a>(ikey);
00835
00836 <a class="code" href="class_verse_key.html#c5">parse</a>();
00837 }
00838
00839
00840 <font class="comment">/******************************************************************************</font>
00841 <font class="comment"> * VerseKey::getText - refreshes keytext before returning if cast to</font>
00842 <font class="comment"> * a (char *) is requested</font>
00843 <font class="comment"> */</font>
00844
<a name="l00845"></a><a class="code" href="class_verse_key.html#a11">00845</a> <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="class_verse_key.html#a11">VerseKey::getText</a>()<font class="keyword"> const </font>{
00846 <a class="code" href="class_verse_key.html#c4">freshtext</a>();
00847 <font class="keywordflow">return</font> keytext;
00848 }
00849
00850
00851 <font class="keyword">const</font> <font class="keywordtype">char</font> *VerseKey::getShortText()<font class="keyword"> const </font>{
00852 <font class="keyword">static</font> <font class="keywordtype">char</font> *stext = 0;
00853 <font class="keywordtype">char</font> buf[2047];
00854 <a class="code" href="class_verse_key.html#c4">freshtext</a>();
00855 <font class="keywordflow">if</font> (book < 1) {
00856 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#o4">testament</a> < 1)
00857 sprintf(buf, <font class="stringliteral">"[ Module Heading ]"</font>);
00858 <font class="keywordflow">else</font> sprintf(buf, <font class="stringliteral">"[ Testament %d Heading ]"</font>, (<font class="keywordtype">int</font>)<a class="code" href="class_verse_key.html#o4">testament</a>);
00859 }
00860 <font class="keywordflow">else</font> {
00861 sprintf(buf, <font class="stringliteral">"%s %d:%d"</font>, books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].prefAbbrev, chapter, verse);
00862 }
00863 stdstr(&stext, buf);
00864 <font class="keywordflow">return</font> stext;
00865 }
00866
00867
00868 <font class="keyword">const</font> <font class="keywordtype">char</font> *VerseKey::getBookName()<font class="keyword"> const </font>{
00869 <font class="keywordflow">return</font> books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].name;
00870 }
00871
00872
00873 <font class="keyword">const</font> <font class="keywordtype">char</font> *VerseKey::getBookAbbrev()<font class="keyword"> const </font>{
00874 <font class="keywordflow">return</font> books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].prefAbbrev;
00875 }
00876 <font class="comment">/******************************************************************************</font>
00877 <font class="comment"> * VerseKey::setPosition(SW_POSITION) - Positions this key</font>
00878 <font class="comment"> *</font>
00879 <font class="comment"> * ENT: p - position</font>
00880 <font class="comment"> *</font>
00881 <font class="comment"> * RET: *this</font>
00882 <font class="comment"> */</font>
00883
<a name="l00884"></a><a class="code" href="class_verse_key.html#a16">00884</a> <font class="keywordtype">void</font> <a class="code" href="class_verse_key.html#a16">VerseKey::setPosition</a>(SW_POSITION p) {
00885 <font class="keywordflow">switch</font> (p) {
00886 <font class="keywordflow">case</font> POS_TOP:
00887 <a class="code" href="class_verse_key.html#o4">testament</a> = <a class="code" href="class_verse_key.html#a7">LowerBound</a>().<a class="code" href="class_verse_key.html#a22">Testament</a>();
00888 book = <a class="code" href="class_verse_key.html#a7">LowerBound</a>().<a class="code" href="class_verse_key.html#a23">Book</a>();
00889 chapter = <a class="code" href="class_verse_key.html#a7">LowerBound</a>().<a class="code" href="class_verse_key.html#a24">Chapter</a>();
00890 verse = <a class="code" href="class_verse_key.html#a7">LowerBound</a>().<a class="code" href="class_verse_key.html#a25">Verse</a>();
00891 <font class="keywordflow">break</font>;
00892 <font class="keywordflow">case</font> POS_BOTTOM:
00893 <a class="code" href="class_verse_key.html#o4">testament</a> = <a class="code" href="class_verse_key.html#a8">UpperBound</a>().<a class="code" href="class_verse_key.html#a22">Testament</a>();
00894 book = <a class="code" href="class_verse_key.html#a8">UpperBound</a>().<a class="code" href="class_verse_key.html#a23">Book</a>();
00895 chapter = <a class="code" href="class_verse_key.html#a8">UpperBound</a>().<a class="code" href="class_verse_key.html#a24">Chapter</a>();
00896 verse = <a class="code" href="class_verse_key.html#a8">UpperBound</a>().<a class="code" href="class_verse_key.html#a25">Verse</a>();
00897 <font class="keywordflow">break</font>;
00898 <font class="keywordflow">case</font> POS_MAXVERSE:
00899 <a class="code" href="class_verse_key.html#a30">Normalize</a>();
00900 verse = books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].versemax[chapter-1];
00901 <font class="keywordflow">break</font>;
00902 <font class="keywordflow">case</font> POS_MAXCHAPTER:
00903 verse = 1;
00904 <a class="code" href="class_verse_key.html#a30">Normalize</a>();
00905 chapter = books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].chapmax;
00906 <font class="keywordflow">break</font>;
00907 }
00908 <a class="code" href="class_verse_key.html#a30">Normalize</a>(1);
00909 <a class="code" href="class_s_w_key.html#a6">Error</a>(); <font class="comment">// clear error from normalize</font>
00910 }
00911
00912
00913 <font class="comment">/******************************************************************************</font>
00914 <font class="comment"> * VerseKey::increment - Increments key a number of verses</font>
00915 <font class="comment"> *</font>
00916 <font class="comment"> * ENT: step - Number of verses to jump forward</font>
00917 <font class="comment"> *</font>
00918 <font class="comment"> * RET: *this</font>
00919 <font class="comment"> */</font>
00920
<a name="l00921"></a><a class="code" href="class_verse_key.html#a18">00921</a> <font class="keywordtype">void</font> <a class="code" href="class_verse_key.html#a18">VerseKey::increment</a>(<font class="keywordtype">int</font> step) {
00922 <font class="keywordtype">char</font> ierror = 0;
00923 <a class="code" href="class_verse_key.html#a34">Index</a>(<a class="code" href="class_verse_key.html#a34">Index</a>() + step);
00924 <font class="keywordflow">while</font> ((!verse) && (!<a class="code" href="class_verse_key.html#o9">headings</a>) && (!ierror)) {
00925 <a class="code" href="class_verse_key.html#a34">Index</a>(<a class="code" href="class_verse_key.html#a34">Index</a>() + 1);
00926 ierror = <a class="code" href="class_s_w_key.html#a6">Error</a>();
00927 }
00928
00929 error = (ierror) ? ierror : error;
00930 }
00931
00932
00933 <font class="comment">/******************************************************************************</font>
00934 <font class="comment"> * VerseKey::decrement - Decrements key a number of verses</font>
00935 <font class="comment"> *</font>
00936 <font class="comment"> * ENT: step - Number of verses to jump backward</font>
00937 <font class="comment"> *</font>
00938 <font class="comment"> * RET: *this</font>
00939 <font class="comment"> */</font>
00940
<a name="l00941"></a><a class="code" href="class_verse_key.html#a17">00941</a> <font class="keywordtype">void</font> <a class="code" href="class_verse_key.html#a17">VerseKey::decrement</a>(<font class="keywordtype">int</font> step) {
00942 <font class="keywordtype">char</font> ierror = 0;
00943
00944 <a class="code" href="class_verse_key.html#a34">Index</a>(<a class="code" href="class_verse_key.html#a34">Index</a>() - step);
00945 <font class="keywordflow">while</font> ((!verse) && (!<a class="code" href="class_verse_key.html#o9">headings</a>) && (!ierror)) {
00946 <a class="code" href="class_verse_key.html#a34">Index</a>(<a class="code" href="class_verse_key.html#a34">Index</a>() - 1);
00947 ierror = <a class="code" href="class_s_w_key.html#a6">Error</a>();
00948 }
00949 <font class="keywordflow">if</font> ((ierror) && (!<a class="code" href="class_verse_key.html#o9">headings</a>))
00950 (*this)++;
00951
00952 error = (ierror) ? ierror : error;
00953 }
00954
00955
00956 <font class="comment">/******************************************************************************</font>
00957 <font class="comment"> * VerseKey::Normalize - checks limits and normalizes if necessary (e.g.</font>
00958 <font class="comment"> * Matthew 29:47 = Mark 2:2). If last verse is</font>
00959 <font class="comment"> * exceeded, key is set to last Book CH:VS</font>
00960 <font class="comment"> * RET: *this</font>
00961 <font class="comment"> */</font>
00962
<a name="l00963"></a><a class="code" href="class_verse_key.html#a30">00963</a> <font class="keywordtype">void</font> <a class="code" href="class_verse_key.html#a30">VerseKey::Normalize</a>(<font class="keywordtype">char</font> autocheck)
00964 {
00965 error = 0;
00966
00967 <font class="keywordflow">if</font> ((autocheck) && (!<a class="code" href="class_verse_key.html#o8">autonorm</a>)) <font class="comment">// only normalize if we were explicitely called or if autonorm is turned on</font>
00968 <font class="keywordflow">return</font>;
00969
00970 <font class="keywordflow">if</font> ((headings) && (!verse)) <font class="comment">// this is cheeze and temporary until deciding what actions should be taken.</font>
00971 <font class="keywordflow">return</font>; <font class="comment">// so headings should only be turned on when positioning with Index() or incrementors</font>
00972
00973 <font class="keywordflow">while</font> ((testament < 3) && (testament > 0)) {
00974
00975 <font class="keywordflow">if</font> (book > BMAX[<a class="code" href="class_verse_key.html#o4">testament</a>-1]) {
00976 book -= BMAX[<a class="code" href="class_verse_key.html#o4">testament</a>-1];
00977 <a class="code" href="class_verse_key.html#o4">testament</a>++;
00978 <font class="keywordflow">continue</font>;
00979 }
00980
00981 <font class="keywordflow">if</font> (book < 1) {
00982 <font class="keywordflow">if</font> (--<a class="code" href="class_verse_key.html#o4">testament</a> > 0) {
00983 book += BMAX[<a class="code" href="class_verse_key.html#o4">testament</a>-1];
00984 }
00985 <font class="keywordflow">continue</font>;
00986 }
00987
00988 <font class="keywordflow">if</font> (chapter > books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].chapmax) {
00989 chapter -= books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].chapmax;
00990 book++;
00991 <font class="keywordflow">continue</font>;
00992 }
00993
00994 <font class="keywordflow">if</font> (chapter < 1) {
00995 <font class="keywordflow">if</font> (--book > 0) {
00996 chapter += books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].chapmax;
00997 }
00998 <font class="keywordflow">else</font> {
00999 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#o4">testament</a> > 1) {
01000 chapter += books[0][BMAX[0]-1].chapmax;
01001 }
01002 }
01003 <font class="keywordflow">continue</font>;
01004 }
01005
01006 <font class="keywordflow">if</font> (verse > books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].versemax[chapter-1]) { <font class="comment">// -1 because e.g chapter 1 of Matthew is books[1][0].versemax[0]</font>
01007 verse -= books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].versemax[chapter++ - 1];
01008 <font class="keywordflow">continue</font>;
01009 }
01010
01011 <font class="keywordflow">if</font> (verse < 1) {
01012 <font class="keywordflow">if</font> (--chapter > 0) {
01013 verse += books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].versemax[chapter-1];
01014 }
01015 <font class="keywordflow">else</font> {
01016 <font class="keywordflow">if</font> (book > 1) {
01017 verse += books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-2].versemax[books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-2].chapmax-1];
01018 }
01019 <font class="keywordflow">else</font> {
01020 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#o4">testament</a> > 1) {
01021 verse += books[0][BMAX[0]-1].versemax[books[0][BMAX[0]-1].chapmax-1];
01022 }
01023 }
01024 }
01025 <font class="keywordflow">continue</font>;
01026 }
01027
01028 <font class="keywordflow">break</font>; <font class="comment">// If we've made it this far (all failure checks continue) we're ok</font>
01029 }
01030
01031 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#o4">testament</a> > 2) {
01032 <a class="code" href="class_verse_key.html#o4">testament</a> = 2;
01033 book = BMAX[<a class="code" href="class_verse_key.html#o4">testament</a>-1];
01034 chapter = books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].chapmax;
01035 verse = books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].versemax[chapter-1];
01036 error = KEYERR_OUTOFBOUNDS;
01037 }
01038
01039 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#o4">testament</a> < 1) {
01040 error = ((!<a class="code" href="class_verse_key.html#o9">headings</a>) || (<a class="code" href="class_verse_key.html#o4">testament</a> < 0) || (book < 0)) ? KEYERR_OUTOFBOUNDS : 0;
01041 <a class="code" href="class_verse_key.html#o4">testament</a> = ((headings) ? 0 : 1);
01042 book = ((headings) ? 0 : 1);
01043 chapter = ((headings) ? 0 : 1);
01044 verse = ((headings) ? 0 : 1);
01045 }
01046 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#a39">_compare</a>(<a class="code" href="class_verse_key.html#a8">UpperBound</a>()) > 0) {
01047 *<font class="keyword">this</font> = <a class="code" href="class_verse_key.html#a8">UpperBound</a>();
01048 error = KEYERR_OUTOFBOUNDS;
01049 }
01050 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#a39">_compare</a>(<a class="code" href="class_verse_key.html#a7">LowerBound</a>()) < 0) {
01051 *<font class="keyword">this</font> = <a class="code" href="class_verse_key.html#a7">LowerBound</a>();
01052 error = KEYERR_OUTOFBOUNDS;
01053 }
01054 }
01055
01056
01057 <font class="comment">/******************************************************************************</font>
01058 <font class="comment"> * VerseKey::Testament - Gets testament</font>
01059 <font class="comment"> *</font>
01060 <font class="comment"> * RET: value of testament</font>
01061 <font class="comment"> */</font>
01062
<a name="l01063"></a><a class="code" href="class_verse_key.html#a22">01063</a> <font class="keywordtype">char</font> <a class="code" href="class_verse_key.html#a22">VerseKey::Testament</a>()<font class="keyword"> const</font>
01064 <font class="keyword"></font>{
01065 <font class="keywordflow">return</font> <a class="code" href="class_verse_key.html#o4">testament</a>;
01066 }
01067
01068
01069 <font class="comment">/******************************************************************************</font>
01070 <font class="comment"> * VerseKey::Book - Gets book</font>
01071 <font class="comment"> *</font>
01072 <font class="comment"> * RET: value of book</font>
01073 <font class="comment"> */</font>
01074
<a name="l01075"></a><a class="code" href="class_verse_key.html#a23">01075</a> <font class="keywordtype">char</font> <a class="code" href="class_verse_key.html#a23">VerseKey::Book</a>()<font class="keyword"> const</font>
01076 <font class="keyword"></font>{
01077 <font class="keywordflow">return</font> book;
01078 }
01079
01080
01081 <font class="comment">/******************************************************************************</font>
01082 <font class="comment"> * VerseKey::Chapter - Gets chapter</font>
01083 <font class="comment"> *</font>
01084 <font class="comment"> * RET: value of chapter</font>
01085 <font class="comment"> */</font>
01086
<a name="l01087"></a><a class="code" href="class_verse_key.html#a24">01087</a> <font class="keywordtype">int</font> <a class="code" href="class_verse_key.html#a24">VerseKey::Chapter</a>()<font class="keyword"> const</font>
01088 <font class="keyword"></font>{
01089 <font class="keywordflow">return</font> chapter;
01090 }
01091
01092
01093 <font class="comment">/******************************************************************************</font>
01094 <font class="comment"> * VerseKey::Verse - Gets verse</font>
01095 <font class="comment"> *</font>
01096 <font class="comment"> * RET: value of verse</font>
01097 <font class="comment"> */</font>
01098
<a name="l01099"></a><a class="code" href="class_verse_key.html#a25">01099</a> <font class="keywordtype">int</font> <a class="code" href="class_verse_key.html#a25">VerseKey::Verse</a>()<font class="keyword"> const</font>
01100 <font class="keyword"></font>{
01101 <font class="keywordflow">return</font> verse;
01102 }
01103
01104
01105 <font class="comment">/******************************************************************************</font>
01106 <font class="comment"> * VerseKey::Testament - Sets/gets testament</font>
01107 <font class="comment"> *</font>
01108 <font class="comment"> * ENT: itestament - value which to set testament</font>
01109 <font class="comment"> * [MAXPOS(char)] - only get</font>
01110 <font class="comment"> *</font>
01111 <font class="comment"> * RET: if unchanged -> value of testament</font>
01112 <font class="comment"> * if changed -> previous value of testament</font>
01113 <font class="comment"> */</font>
01114
<a name="l01115"></a><a class="code" href="class_verse_key.html#a26">01115</a> <font class="keywordtype">char</font> <a class="code" href="class_verse_key.html#a22">VerseKey::Testament</a>(<font class="keywordtype">char</font> itestament)
01116 {
01117 <font class="keywordtype">char</font> retval = <a class="code" href="class_verse_key.html#o4">testament</a>;
01118
01119 <font class="keywordflow">if</font> (itestament != MAXPOS(<font class="keywordtype">char</font>)) {
01120 <a class="code" href="class_verse_key.html#o4">testament</a> = itestament;
01121 <a class="code" href="class_verse_key.html#a30">Normalize</a>(1);
01122 }
01123 <font class="keywordflow">return</font> retval;
01124 }
01125
01126
01127 <font class="comment">/******************************************************************************</font>
01128 <font class="comment"> * VerseKey::Book - Sets/gets book</font>
01129 <font class="comment"> *</font>
01130 <font class="comment"> * ENT: ibook - value which to set book</font>
01131 <font class="comment"> * [MAXPOS(char)] - only get</font>
01132 <font class="comment"> *</font>
01133 <font class="comment"> * RET: if unchanged -> value of book</font>
01134 <font class="comment"> * if changed -> previous value of book</font>
01135 <font class="comment"> */</font>
01136
<a name="l01137"></a><a class="code" href="class_verse_key.html#a27">01137</a> <font class="keywordtype">char</font> <a class="code" href="class_verse_key.html#a23">VerseKey::Book</a>(<font class="keywordtype">char</font> ibook)
01138 {
01139 <font class="keywordtype">char</font> retval = book;
01140
01141 <a class="code" href="class_verse_key.html#a24">Chapter</a>(1);
01142 book = ibook;
01143 <a class="code" href="class_verse_key.html#a30">Normalize</a>(1);
01144
01145 <font class="keywordflow">return</font> retval;
01146 }
01147
01148
01149 <font class="comment">/******************************************************************************</font>
01150 <font class="comment"> * VerseKey::Chapter - Sets/gets chapter</font>
01151 <font class="comment"> *</font>
01152 <font class="comment"> * ENT: ichapter - value which to set chapter</font>
01153 <font class="comment"> * [MAXPOS(int)] - only get</font>
01154 <font class="comment"> *</font>
01155 <font class="comment"> * RET: if unchanged -> value of chapter</font>
01156 <font class="comment"> * if changed -> previous value of chapter</font>
01157 <font class="comment"> */</font>
01158
<a name="l01159"></a><a class="code" href="class_verse_key.html#a28">01159</a> <font class="keywordtype">int</font> <a class="code" href="class_verse_key.html#a24">VerseKey::Chapter</a>(<font class="keywordtype">int</font> ichapter)
01160 {
01161 <font class="keywordtype">int</font> retval = chapter;
01162
01163 <a class="code" href="class_verse_key.html#a25">Verse</a>(1);
01164 chapter = ichapter;
01165 <a class="code" href="class_verse_key.html#a30">Normalize</a>(1);
01166
01167 <font class="keywordflow">return</font> retval;
01168 }
01169
01170
01171 <font class="comment">/******************************************************************************</font>
01172 <font class="comment"> * VerseKey::Verse - Sets/gets verse</font>
01173 <font class="comment"> *</font>
01174 <font class="comment"> * ENT: iverse - value which to set verse</font>
01175 <font class="comment"> * [MAXPOS(int)] - only get</font>
01176 <font class="comment"> *</font>
01177 <font class="comment"> * RET: if unchanged -> value of verse</font>
01178 <font class="comment"> * if changed -> previous value of verse</font>
01179 <font class="comment"> */</font>
01180
<a name="l01181"></a><a class="code" href="class_verse_key.html#a29">01181</a> <font class="keywordtype">int</font> <a class="code" href="class_verse_key.html#a25">VerseKey::Verse</a>(<font class="keywordtype">int</font> iverse)
01182 {
01183 <font class="keywordtype">int</font> retval = verse;
01184
01185 verse = iverse;
01186 <a class="code" href="class_verse_key.html#a30">Normalize</a>(1);
01187
01188 <font class="keywordflow">return</font> retval;
01189 }
01190
01191
01192 <font class="comment">/******************************************************************************</font>
01193 <font class="comment"> * VerseKey::AutoNormalize - Sets/gets flag that tells VerseKey to auto-</font>
01194 <font class="comment"> * matically normalize itself when modified</font>
01195 <font class="comment"> *</font>
01196 <font class="comment"> * ENT: iautonorm - value which to set autonorm</font>
01197 <font class="comment"> * [MAXPOS(char)] - only get</font>
01198 <font class="comment"> *</font>
01199 <font class="comment"> * RET: if unchanged -> value of autonorm</font>
01200 <font class="comment"> * if changed -> previous value of autonorm</font>
01201 <font class="comment"> */</font>
01202
<a name="l01203"></a><a class="code" href="class_verse_key.html#a31">01203</a> <font class="keywordtype">char</font> <a class="code" href="class_verse_key.html#a31">VerseKey::AutoNormalize</a>(<font class="keywordtype">char</font> iautonorm)
01204 {
01205 <font class="keywordtype">char</font> retval = <a class="code" href="class_verse_key.html#o8">autonorm</a>;
01206
01207 <font class="keywordflow">if</font> (iautonorm != MAXPOS(<font class="keywordtype">char</font>)) {
01208 <a class="code" href="class_verse_key.html#o8">autonorm</a> = iautonorm;
01209 <a class="code" href="class_verse_key.html#a30">Normalize</a>(1);
01210 }
01211 <font class="keywordflow">return</font> retval;
01212 }
01213
01214
01215 <font class="comment">/******************************************************************************</font>
01216 <font class="comment"> * VerseKey::Headings - Sets/gets flag that tells VerseKey to include</font>
01217 <font class="comment"> * chap/book/testmnt/module headings</font>
01218 <font class="comment"> *</font>
01219 <font class="comment"> * ENT: iheadings - value which to set headings</font>
01220 <font class="comment"> * [MAXPOS(char)] - only get</font>
01221 <font class="comment"> *</font>
01222 <font class="comment"> * RET: if unchanged -> value of headings</font>
01223 <font class="comment"> * if changed -> previous value of headings</font>
01224 <font class="comment"> */</font>
01225
<a name="l01226"></a><a class="code" href="class_verse_key.html#a32">01226</a> <font class="keywordtype">char</font> <a class="code" href="class_verse_key.html#a32">VerseKey::Headings</a>(<font class="keywordtype">char</font> iheadings)
01227 {
01228 <font class="keywordtype">char</font> retval = <a class="code" href="class_verse_key.html#o9">headings</a>;
01229
01230 <font class="keywordflow">if</font> (iheadings != MAXPOS(<font class="keywordtype">char</font>)) {
01231 <a class="code" href="class_verse_key.html#o9">headings</a> = iheadings;
01232 <a class="code" href="class_verse_key.html#a30">Normalize</a>(1);
01233 }
01234 <font class="keywordflow">return</font> retval;
01235 }
01236
01237
01238 <font class="comment">/******************************************************************************</font>
01239 <font class="comment"> * VerseKey::findindex - binary search to find the index closest, but less</font>
01240 <font class="comment"> * than the given value.</font>
01241 <font class="comment"> *</font>
01242 <font class="comment"> * ENT: array - long * to array to search</font>
01243 <font class="comment"> * size - number of elements in the array</font>
01244 <font class="comment"> * value - value to find</font>
01245 <font class="comment"> *</font>
01246 <font class="comment"> * RET: the index into the array that is less than but closest to value</font>
01247 <font class="comment"> */</font>
01248
<a name="l01249"></a><a class="code" href="class_verse_key.html#c6">01249</a> <font class="keywordtype">int</font> <a class="code" href="class_verse_key.html#c6">VerseKey::findindex</a>(<font class="keywordtype">long</font> *array, <font class="keywordtype">int</font> size, <font class="keywordtype">long</font> value)
01250 {
01251 <font class="keywordtype">int</font> lbound, ubound, tval;
01252
01253 lbound = 0;
01254 ubound = size - 1;
01255 <font class="keywordflow">while</font> ((ubound - lbound) > 1) {
01256 tval = lbound + (ubound-lbound)/2;
01257 <font class="keywordflow">if</font> (array[tval] <= value)
01258 lbound = tval;
01259 <font class="keywordflow">else</font> ubound = tval;
01260 }
01261 <font class="keywordflow">return</font> (array[ubound] <= value) ? ubound : lbound;
01262 }
01263
01264
01265 <font class="comment">/******************************************************************************</font>
01266 <font class="comment"> * VerseKey::Index - Gets index based upon current verse</font>
01267 <font class="comment"> *</font>
01268 <font class="comment"> * RET: offset</font>
01269 <font class="comment"> */</font>
01270
<a name="l01271"></a><a class="code" href="class_verse_key.html#a34">01271</a> <font class="keywordtype">long</font> <a class="code" href="class_verse_key.html#a34">VerseKey::Index</a>()<font class="keyword"> const</font>
01272 <font class="keyword"></font>{
01273 <font class="keywordtype">long</font> offset;
01274
01275 <font class="keywordflow">if</font> (!<a class="code" href="class_verse_key.html#o4">testament</a>) { <font class="comment">// if we want module heading</font>
01276 offset = 0;
01277 verse = 0;
01278 }
01279 <font class="keywordflow">else</font> {
01280 <font class="keywordflow">if</font> (!book)
01281 chapter = 0;
01282 <font class="keywordflow">if</font> (!chapter)
01283 verse = 0;
01284
01285 offset = offsets[<a class="code" href="class_verse_key.html#o4">testament</a>-1][0][book];
01286 offset = offsets[<a class="code" href="class_verse_key.html#o4">testament</a>-1][1][(int)offset + chapter];
01287 <font class="keywordflow">if</font> (!(offset|verse)) <font class="comment">// if we have a testament but nothing else.</font>
01288 offset = 1;
01289 }
01290 <font class="keywordflow">return</font> (offset + verse);
01291 }
01292
01293
01294 <font class="comment">/******************************************************************************</font>
01295 <font class="comment"> * VerseKey::Index - Gets index based upon current verse</font>
01296 <font class="comment"> *</font>
01297 <font class="comment"> * RET: offset</font>
01298 <font class="comment"> */</font>
01299
01300 <font class="keywordtype">long</font> VerseKey::NewIndex()<font class="keyword"> const</font>
01301 <font class="keyword"></font>{
01302 <font class="keyword">static</font> <font class="keywordtype">long</font> otMaxIndex = 32300 - 8245; <font class="comment">// total positions - new testament positions</font>
01303 <font class="comment">// static long otMaxIndex = offsets[0][1][(int)offsets[0][0][BMAX[0]] + books[0][BMAX[0]].chapmax];</font>
01304 <font class="keywordflow">return</font> ((<a class="code" href="class_verse_key.html#o4">testament</a>-1) * otMaxIndex) + <a class="code" href="class_verse_key.html#a34">Index</a>();
01305 }
01306
01307
01308 <font class="comment">/******************************************************************************</font>
01309 <font class="comment"> * VerseKey::Index - Sets index based upon current verse</font>
01310 <font class="comment"> *</font>
01311 <font class="comment"> * ENT: iindex - value to set index to</font>
01312 <font class="comment"> *</font>
01313 <font class="comment"> * RET: offset</font>
01314 <font class="comment"> */</font>
01315
<a name="l01316"></a><a class="code" href="class_verse_key.html#a35">01316</a> <font class="keywordtype">long</font> <a class="code" href="class_verse_key.html#a34">VerseKey::Index</a>(<font class="keywordtype">long</font> iindex)
01317 {
01318 <font class="keywordtype">long</font> offset;
01319
01320 <font class="comment">// This is the dirty stuff --------------------------------------------</font>
01321
01322 <font class="keywordflow">if</font> (!<a class="code" href="class_verse_key.html#o4">testament</a>)
01323 <a class="code" href="class_verse_key.html#o4">testament</a> = 1;
01324
01325 <font class="keywordflow">if</font> (iindex < 1) { <font class="comment">// if (-) or module heading</font>
01326 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#o4">testament</a> < 2) {
01327 <font class="keywordflow">if</font> (iindex < 0) {
01328 <a class="code" href="class_verse_key.html#o4">testament</a> = 0; <font class="comment">// previously we changed 0 -> 1</font>
01329 error = KEYERR_OUTOFBOUNDS;
01330 }
01331 <font class="keywordflow">else</font> <a class="code" href="class_verse_key.html#o4">testament</a> = 0; <font class="comment">// we want module heading</font>
01332 }
01333 <font class="keywordflow">else</font> {
01334 <a class="code" href="class_verse_key.html#o4">testament</a>--;
01335 iindex = (offsets[<a class="code" href="class_verse_key.html#o4">testament</a>-1][1][offsize[<a class="code" href="class_verse_key.html#o4">testament</a>-1][1]-1] + books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][BMAX[<a class="code" href="class_verse_key.html#o4">testament</a>-1]-1].versemax[books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][BMAX[<a class="code" href="class_verse_key.html#o4">testament</a>-1]-1].chapmax-1]) + iindex; <font class="comment">// What a doozy! ((offset of last chapter + number of verses in the last chapter) + iindex)</font>
01336 }
01337 }
01338
01339 <font class="comment">// --------------------------------------------------------------------</font>
01340
01341
01342 <font class="keywordflow">if</font> (testament) {
01343 <font class="keywordflow">if</font> ((!error) && (iindex)) {
01344 offset = <a class="code" href="class_verse_key.html#c6">findindex</a>(offsets[<a class="code" href="class_verse_key.html#o4">testament</a>-1][1], offsize[<a class="code" href="class_verse_key.html#o4">testament</a>-1][1], iindex);
01345 verse = iindex - offsets[<a class="code" href="class_verse_key.html#o4">testament</a>-1][1][offset];
01346 book = <a class="code" href="class_verse_key.html#c6">findindex</a>(offsets[<a class="code" href="class_verse_key.html#o4">testament</a>-1][0], offsize[<a class="code" href="class_verse_key.html#o4">testament</a>-1][0], offset);
01347 chapter = offset - offsets[<a class="code" href="class_verse_key.html#o4">testament</a>-1][0][VerseKey::book];
01348 verse = (chapter) ? verse : 0; <font class="comment">// funny check. if we are index=1 (testmt header) all gets set to 0 exept verse. Don't know why. Fix if you figure out. Think its in the offsets table.</font>
01349 <font class="keywordflow">if</font> (verse) { <font class="comment">// only check if -1 won't give negative</font>
01350 <font class="keywordflow">if</font> (verse > books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].versemax[chapter-1]) {
01351 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#o4">testament</a> > 1) {
01352 verse = books[<a class="code" href="class_verse_key.html#o4">testament</a>-1][book-1].versemax[chapter-1];
01353 error = KEYERR_OUTOFBOUNDS;
01354 }
01355 <font class="keywordflow">else</font> {
01356 <a class="code" href="class_verse_key.html#o4">testament</a>++;
01357 <a class="code" href="class_verse_key.html#a34">Index</a>(verse - books[<a class="code" href="class_verse_key.html#o4">testament</a>-2][book-1].versemax[chapter-1]);
01358 }
01359 }
01360 }
01361 }
01362 }
01363 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#a39">_compare</a>(<a class="code" href="class_verse_key.html#a8">UpperBound</a>()) > 0) {
01364 *<font class="keyword">this</font> = <a class="code" href="class_verse_key.html#a8">UpperBound</a>();
01365 error = KEYERR_OUTOFBOUNDS;
01366 }
01367 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#a39">_compare</a>(<a class="code" href="class_verse_key.html#a7">LowerBound</a>()) < 0) {
01368 *<font class="keyword">this</font> = <a class="code" href="class_verse_key.html#a7">LowerBound</a>();
01369 error = KEYERR_OUTOFBOUNDS;
01370 }
01371 <font class="keywordflow">return</font> <a class="code" href="class_verse_key.html#a34">Index</a>();
01372 }
01373
01374
01375 <font class="comment">/******************************************************************************</font>
01376 <font class="comment"> * VerseKey::compare - Compares another SWKey object</font>
01377 <font class="comment"> *</font>
01378 <font class="comment"> * ENT: ikey - key to compare with this one</font>
01379 <font class="comment"> *</font>
01380 <font class="comment"> * RET: >0 if this versekey is greater than compare versekey</font>
01381 <font class="comment"> * <0 <</font>
01382 <font class="comment"> * 0 =</font>
01383 <font class="comment"> */</font>
01384
<a name="l01385"></a><a class="code" href="class_verse_key.html#a38">01385</a> <font class="keywordtype">int</font> <a class="code" href="class_verse_key.html#a38">VerseKey::compare</a>(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> &ikey)
01386 {
01387 VerseKey ivkey = (<font class="keyword">const</font> <font class="keywordtype">char</font> *)ikey;
01388 <font class="keywordflow">return</font> <a class="code" href="class_verse_key.html#a39">_compare</a>(ivkey);
01389 }
01390
01391
01392 <font class="comment">/******************************************************************************</font>
01393 <font class="comment"> * VerseKey::_compare - Compares another VerseKey object</font>
01394 <font class="comment"> *</font>
01395 <font class="comment"> * ENT: ikey - key to compare with this one</font>
01396 <font class="comment"> *</font>
01397 <font class="comment"> * RET: >0 if this versekey is greater than compare versekey</font>
01398 <font class="comment"> * <0 <</font>
01399 <font class="comment"> * 0 =</font>
01400 <font class="comment"> */</font>
01401
<a name="l01402"></a><a class="code" href="class_verse_key.html#a39">01402</a> <font class="keywordtype">int</font> <a class="code" href="class_verse_key.html#a39">VerseKey::_compare</a>(<font class="keyword">const</font> VerseKey &ivkey)
01403 {
01404 <font class="keywordtype">long</font> keyval1 = 0;
01405 <font class="keywordtype">long</font> keyval2 = 0;
01406
01407 keyval1 += <a class="code" href="class_verse_key.html#a22">Testament</a>() * 1000000000;
01408 keyval2 += ivkey.<a class="code" href="class_verse_key.html#a22">Testament</a>() * 1000000000;
01409 keyval1 += <a class="code" href="class_verse_key.html#a23">Book</a>() * 1000000;
01410 keyval2 += ivkey.<a class="code" href="class_verse_key.html#a23">Book</a>() * 1000000;
01411 keyval1 += <a class="code" href="class_verse_key.html#a24">Chapter</a>() * 1000;
01412 keyval2 += ivkey.<a class="code" href="class_verse_key.html#a24">Chapter</a>() * 1000;
01413 keyval1 += <a class="code" href="class_verse_key.html#a25">Verse</a>();
01414 keyval2 += ivkey.<a class="code" href="class_verse_key.html#a25">Verse</a>();
01415 keyval1 -= keyval2;
01416 keyval1 = (keyval1) ? ((keyval1 > 0) ? 1 : -1) <font class="comment">/*keyval1/labs(keyval1)*/</font>:0; <font class="comment">// -1 | 0 | 1</font>
01417 <font class="keywordflow">return</font> keyval1;
01418 }
01419
01420
01421 <font class="keyword">const</font> <font class="keywordtype">char</font> *VerseKey::getOSISRef()<font class="keyword"> const </font>{
01422 <font class="keyword">static</font> <font class="keywordtype">char</font> buf[5][254];
01423 <font class="keyword">static</font> <font class="keywordtype">char</font> loop = 0;
01424
01425 <font class="keywordflow">if</font> (loop > 4)
01426 loop = 0;
01427
01428 <font class="keyword">static</font> <font class="keywordtype">char</font> *osisotbooks[] = {
01429 <font class="stringliteral">"Gen"</font>,<font class="stringliteral">"Exod"</font>,<font class="stringliteral">"Lev"</font>,<font class="stringliteral">"Num"</font>,<font class="stringliteral">"Deut"</font>,<font class="stringliteral">"Josh"</font>,<font class="stringliteral">"Judg"</font>,<font class="stringliteral">"Ruth"</font>,<font class="stringliteral">"_1Sam"</font>,<font class="stringliteral">"_2Sam"</font>,
01430 <font class="stringliteral">"_1Kgs"</font>,<font class="stringliteral">"_2Kgs"</font>,<font class="stringliteral">"_1Chr"</font>,<font class="stringliteral">"_2Chr"</font>,<font class="stringliteral">"Ezra"</font>,<font class="stringliteral">"Neh"</font>,<font class="stringliteral">"Esth"</font>,<font class="stringliteral">"Job"</font>,<font class="stringliteral">"Ps"</font>,
01431 <font class="stringliteral">"Prov"</font>, <font class="comment">// added this. Was not in OSIS spec</font>
01432 <font class="stringliteral">"Eccl"</font>,
01433 <font class="stringliteral">"Song"</font>,<font class="stringliteral">"Isa"</font>,<font class="stringliteral">"Jer"</font>,<font class="stringliteral">"Lam"</font>,<font class="stringliteral">"Ezek"</font>,<font class="stringliteral">"Dan"</font>,<font class="stringliteral">"Hos"</font>,<font class="stringliteral">"Joel"</font>,<font class="stringliteral">"Amos"</font>,<font class="stringliteral">"Obad"</font>,
01434 <font class="stringliteral">"Jonah"</font>,<font class="stringliteral">"Mic"</font>,<font class="stringliteral">"Nah"</font>,<font class="stringliteral">"Hab"</font>,<font class="stringliteral">"Zeph"</font>,<font class="stringliteral">"Hag"</font>,<font class="stringliteral">"Zech"</font>,<font class="stringliteral">"Mal"</font>,<font class="stringliteral">"Bar"</font>,<font class="stringliteral">"PrAzar"</font>,
01435 <font class="stringliteral">"Bel"</font>,<font class="stringliteral">"Sus"</font>,<font class="stringliteral">"_1Esd"</font>,<font class="stringliteral">"_2Esd"</font>,<font class="stringliteral">"AddEsth"</font>,<font class="stringliteral">"EpJer"</font>,<font class="stringliteral">"Jdt"</font>,<font class="stringliteral">"_1Macc"</font>,<font class="stringliteral">"_2Macc"</font>,<font class="stringliteral">"_3Macc"</font>,
01436 <font class="stringliteral">"_4Macc"</font>,<font class="stringliteral">"PrMan"</font>,<font class="stringliteral">"Ps151"</font>,<font class="stringliteral">"Sir"</font>,<font class="stringliteral">"Tob"</font>,<font class="stringliteral">"Wis"</font>};
01437 <font class="keyword">static</font> <font class="keywordtype">char</font> *osisntbooks[] = {
01438 <font class="stringliteral">"Matt"</font>,<font class="stringliteral">"Mark"</font>,<font class="stringliteral">"Luke"</font>,<font class="stringliteral">"John"</font>,<font class="stringliteral">"Acts"</font>,<font class="stringliteral">"Rom"</font>,<font class="stringliteral">"_1Cor"</font>,<font class="stringliteral">"_2Cor"</font>,<font class="stringliteral">"Gal"</font>,<font class="stringliteral">"Eph"</font>,
01439 <font class="stringliteral">"Phil"</font>,<font class="stringliteral">"Col"</font>,<font class="stringliteral">"_1Thess"</font>,<font class="stringliteral">"_2Thess"</font>,<font class="stringliteral">"_1Tim"</font>,<font class="stringliteral">"_2Tim"</font>,<font class="stringliteral">"Titus"</font>,<font class="stringliteral">"Phlm"</font>,<font class="stringliteral">"Heb"</font>,<font class="stringliteral">"Jas"</font>,
01440 <font class="stringliteral">"_1Pet"</font>,<font class="stringliteral">"_2Pet"</font>,<font class="stringliteral">"_1John"</font>,<font class="stringliteral">"_2John"</font>,<font class="stringliteral">"_3John"</font>,<font class="stringliteral">"Jude"</font>,<font class="stringliteral">"Rev"</font>};
01441 <font class="keyword">static</font> <font class="keywordtype">char</font> **osisbooks[] = { osisotbooks, osisntbooks };
01442 <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#a25">Verse</a>())
01443 sprintf(buf[loop], <font class="stringliteral">"%s.%d.%d"</font>, osisbooks[<a class="code" href="class_verse_key.html#a22">Testament</a>()-1][<a class="code" href="class_verse_key.html#a23">Book</a>()-1], (<font class="keywordtype">int</font>)<a class="code" href="class_verse_key.html#a24">Chapter</a>(), (<font class="keywordtype">int</font>)<a class="code" href="class_verse_key.html#a25">Verse</a>());
01444 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#a24">Chapter</a>())
01445 sprintf(buf[loop], <font class="stringliteral">"%s.%d"</font>, osisbooks[<a class="code" href="class_verse_key.html#a22">Testament</a>()-1][<a class="code" href="class_verse_key.html#a23">Book</a>()-1], (<font class="keywordtype">int</font>)<a class="code" href="class_verse_key.html#a24">Chapter</a>());
01446 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (<a class="code" href="class_verse_key.html#a23">Book</a>())
01447 sprintf(buf[loop], <font class="stringliteral">"%s"</font>, osisbooks[<a class="code" href="class_verse_key.html#a22">Testament</a>()-1][<a class="code" href="class_verse_key.html#a23">Book</a>()-1]);
01448 <font class="keywordflow">else</font> sprintf(buf[loop], <font class="stringliteral">""</font>);
01449 <font class="keywordflow">return</font> buf[loop++];
01450 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:01 2002 for The Sword Project by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>