blob: d85d1ebac18d573418f56be37f696f60ce2a713e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/******************************************************************************
* swlocale.cpp - implementation of Class SWLocale used for retrieval
* of locale lookups
*
* $Id: swlocale.cpp,v 1.4 2002/07/28 01:48:38 scribe Exp $
*
* Copyright 2000 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
*/
#include <swlocale.h>
#include <utilfuns.h>
SWLocale::SWLocale(const char * ifilename) {
ConfigEntMap::iterator confEntry;
name = 0;
description = 0;
bookAbbrevs = 0;
BMAX = 0;
books = 0;
localeSource = new SWConfig(ifilename);
confEntry = localeSource->Sections["Meta"].find("Name");
if (confEntry != localeSource->Sections["Meta"].end())
stdstr(&name, (*confEntry).second.c_str());
confEntry = localeSource->Sections["Meta"].find("Description");
if (confEntry != localeSource->Sections["Meta"].end())
stdstr(&description, (*confEntry).second.c_str());
}
SWLocale::~SWLocale() {
delete localeSource;
if (description)
delete [] description;
if (name)
delete [] name;
if (bookAbbrevs)
delete [] bookAbbrevs;
if (BMAX) {
for (int i = 0; i < 2; i++)
delete [] books[i];
delete [] BMAX;
delete [] books;
}
}
const char *SWLocale::translate(const char *text) {
LookupMap::iterator entry;
entry = lookupTable.find(text);
if (entry == lookupTable.end()) {
ConfigEntMap::iterator confEntry;
confEntry = localeSource->Sections["Text"].find(text);
if (confEntry == localeSource->Sections["Text"].end())
lookupTable.insert(LookupMap::value_type(text, text));
else lookupTable.insert(LookupMap::value_type(text, (*confEntry).second.c_str()));
entry = lookupTable.find(text);
}
return (*entry).second.c_str();
}
const char *SWLocale::getName() {
return name;
}
const char *SWLocale::getDescription() {
return description;
}
void SWLocale::augment(SWLocale &addFrom) {
*localeSource += *addFrom.localeSource;
}
const struct abbrev *SWLocale::getBookAbbrevs() {
static const char *nullstr = "";
if (!bookAbbrevs) {
ConfigEntMap::iterator it;
int i;
int size = localeSource->Sections["Book Abbrevs"].size();
bookAbbrevs = new struct abbrev[size + 1];
for (i = 0, it = localeSource->Sections["Book Abbrevs"].begin(); it != localeSource->Sections["Book Abbrevs"].end(); it++, i++) {
bookAbbrevs[i].ab = (*it).first.c_str();
bookAbbrevs[i].book = atoi((*it).second.c_str());
}
bookAbbrevs[i].ab = nullstr;
bookAbbrevs[i].book = -1;
}
return bookAbbrevs;
}
void SWLocale::getBooks(char **iBMAX, struct sbook ***ibooks) {
if (!BMAX) {
BMAX = new char [2];
BMAX[0] = VerseKey::builtin_BMAX[0];
BMAX[1] = VerseKey::builtin_BMAX[1];
books = new struct sbook *[2];
books[0] = new struct sbook[BMAX[0]];
books[1] = new struct sbook[BMAX[1]];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < BMAX[i]; j++) {
books[i][j] = VerseKey::builtin_books[i][j];
books[i][j].name = translate(VerseKey::builtin_books[i][j].name);
}
}
}
*iBMAX = BMAX;
*ibooks = books;
}
|