<!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>rawgenbook.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>rawgenbook.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font> 00002 <font class="comment"> * rawtext.cpp - code for class 'RawGenBook'- a module that reads raw text files:</font> 00003 <font class="comment"> * ot and nt using indexs ??.bks ??.cps ??.vss</font> 00004 <font class="comment"> */</font> 00005 00006 00007 <font class="preprocessor">#include <stdio.h></font> 00008 <font class="preprocessor">#include <fcntl.h></font> 00009 00010 <font class="preprocessor">#ifndef __GNUC__</font> 00011 <font class="preprocessor"></font><font class="preprocessor">#include <io.h></font> 00012 <font class="preprocessor">#else</font> 00013 <font class="preprocessor"></font><font class="preprocessor">#include <unistd.h></font> 00014 <font class="preprocessor">#endif</font> 00015 <font class="preprocessor"></font> 00016 <font class="preprocessor">#include <string.h></font> 00017 <font class="preprocessor">#include <utilfuns.h></font> 00018 <font class="preprocessor">#include <rawgenbook.h></font> 00019 <font class="preprocessor">#include <rawstr.h></font> 00020 00021 <font class="preprocessor">#ifndef O_BINARY</font> 00022 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0</font> 00023 <font class="preprocessor"></font><font class="preprocessor">#endif</font> 00024 <font class="preprocessor"></font> 00025 <font class="comment">/******************************************************************************</font> 00026 <font class="comment"> * RawGenBook Constructor - Initializes data for instance of RawGenBook</font> 00027 <font class="comment"> *</font> 00028 <font class="comment"> * ENT: iname - Internal name for module</font> 00029 <font class="comment"> * idesc - Name to display to user for module</font> 00030 <font class="comment"> * idisp - Display object to use for displaying</font> 00031 <font class="comment"> */</font> 00032 00033 RawGenBook::RawGenBook(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath, <font class="keyword">const</font> <font class="keywordtype">char</font> *iname, <font class="keyword">const</font> <font class="keywordtype">char</font> *idesc, <a class="code" href="class_s_w_display.html">SWDisplay</a> *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, <font class="keyword">const</font> <font class="keywordtype">char</font>* ilang) 00034 : <a class="code" href="class_s_w_gen_book.html">SWGenBook</a>(iname, idesc, idisp, enc, dir, mark, ilang) { 00035 <font class="keywordtype">int</font> fileMode = O_RDWR; 00036 <font class="keywordtype">char</font> *buf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen (ipath) + 20 ]; 00037 00038 entryBuf = 0; 00039 path = 0; 00040 stdstr(&path, ipath); 00041 00042 00043 <font class="keywordflow">if</font> ((path[strlen(path)-1] == <font class="charliteral">'/'</font>) || (path[strlen(path)-1] == <font class="charliteral">'\\'</font>)) 00044 path[strlen(path)-1] = 0; 00045 00046 <font class="keyword">delete</font> key; 00047 key = CreateKey(); 00048 00049 00050 sprintf(buf, <font class="stringliteral">"%s.bdt"</font>, path); 00051 bdtfd = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>); 00052 00053 <font class="keyword">delete</font> [] buf; 00054 00055 } 00056 00057 00058 <font class="comment">/******************************************************************************</font> 00059 <font class="comment"> * RawGenBook Destructor - Cleans up instance of RawGenBook</font> 00060 <font class="comment"> */</font> 00061 00062 RawGenBook::~RawGenBook() { 00063 00064 FileMgr::systemFileMgr.close(bdtfd); 00065 00066 <font class="keywordflow">if</font> (path) 00067 <font class="keyword">delete</font> [] path; 00068 00069 <font class="keywordflow">if</font> (entryBuf) 00070 <font class="keyword">delete</font> [] entryBuf; 00071 } 00072 00073 00074 <font class="comment">/******************************************************************************</font> 00075 <font class="comment"> * RawGenBook::operator char * - Returns the correct verse when char * cast</font> 00076 <font class="comment"> * is requested</font> 00077 <font class="comment"> *</font> 00078 <font class="comment"> * RET: string buffer with verse</font> 00079 <font class="comment"> */</font> 00080 00081 <font class="keywordtype">char</font> *RawGenBook::getRawEntry() { 00082 00083 __u32 offset = 0; 00084 __u32 size = 0; 00085 00086 <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *key = 0; 00087 <font class="preprocessor">#ifndef _WIN32_WCE</font> 00088 <font class="preprocessor"></font> <font class="keywordflow">try</font> { 00089 <font class="preprocessor">#endif</font> 00090 <font class="preprocessor"></font> key = SWDYNAMIC_CAST(<a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a>, (this->key)); 00091 <font class="preprocessor">#ifndef _WIN32_WCE</font> 00092 <font class="preprocessor"></font> } 00093 <font class="keywordflow">catch</font> ( ... ) {} 00094 <font class="preprocessor">#endif</font> 00095 <font class="preprocessor"></font> 00096 <font class="keywordflow">if</font> (!key) { 00097 key = (<a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *)CreateKey(); 00098 (*key) = *(this->key); 00099 } 00100 00101 <font class="keywordflow">if</font> (entryBuf) 00102 <font class="keyword">delete</font> [] entryBuf; 00103 00104 <font class="keywordtype">int</font> dsize; 00105 key-><a class="code" href="class_tree_key_idx.html#a5">getUserData</a>(&dsize); 00106 <font class="keywordflow">if</font> (dsize > 7) { 00107 memcpy(&offset, key-><a class="code" href="class_tree_key_idx.html#a5">getUserData</a>(), 4); 00108 offset = swordtoarch32(offset); 00109 00110 memcpy(&size, key-><a class="code" href="class_tree_key_idx.html#a5">getUserData</a>() + 4, 4); 00111 size = swordtoarch32(size); 00112 00113 entrySize = size; <font class="comment">// support getEntrySize call</font> 00114 00115 entryBuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ (size + 2) * FILTERPAD ]; 00116 *entryBuf = 0; 00117 lseek(bdtfd->getFd(), offset, SEEK_SET); 00118 read(bdtfd->getFd(), entryBuf, size); 00119 00120 rawFilter(entryBuf, size, key); 00121 00122 <font class="keywordflow">if</font> (!isUnicode()) 00123 RawStr::preptext(entryBuf); 00124 } 00125 <font class="keywordflow">else</font> { 00126 entryBuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [2]; 00127 entryBuf[0] = 0; 00128 entryBuf[1] = 0; 00129 entrySize = 0; 00130 } 00131 00132 <font class="keywordflow">if</font> (key != this->key) <font class="comment">// free our key if we created a VerseKey</font> 00133 <font class="keyword">delete</font> key; 00134 00135 <font class="keywordflow">return</font> entryBuf; 00136 } 00137 00138 00139 00140 <font class="preprocessor">#ifdef _MSC_VER</font> 00141 <font class="preprocessor"></font><a class="code" href="class_s_w_module.html">SWModule</a> &RawGenBook::operator =(SW_POSITION p) { 00142 <font class="preprocessor">#else</font> 00143 <font class="preprocessor"></font>RawGenBook &RawGenBook::operator =(SW_POSITION p) { 00144 <font class="preprocessor">#endif</font> 00145 <font class="preprocessor"></font> <a class="code" href="class_s_w_module.html#a40">SWModule::operator =</a>(p); 00146 <font class="keywordflow">return</font> *<font class="keyword">this</font>; 00147 } 00148 00149 <a class="code" href="class_s_w_module.html">SWModule</a> &RawGenBook::setentry(<font class="keyword">const</font> <font class="keywordtype">char</font> *inbuf, <font class="keywordtype">long</font> len) { 00150 00151 __u32 offset = archtosword32(lseek(bdtfd->getFd(), 0, SEEK_END)); 00152 __u32 size = 0; 00153 <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *key = ((<a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *)this->key); 00154 00155 <font class="keywordtype">char</font> userData[8]; 00156 00157 <font class="keywordflow">if</font> (!len) 00158 len = strlen(inbuf); 00159 00160 write(bdtfd->getFd(), inbuf, len); 00161 00162 size = archtosword32(len); 00163 memcpy(userData, &offset, 4); 00164 memcpy(userData+4, &size, 4); 00165 key-><a class="code" href="class_tree_key_idx.html#a6">setUserData</a>(userData, 8); 00166 key-><a class="code" href="class_tree_key_idx.html#a18">save</a>(); 00167 00168 <font class="keywordflow">return</font> *<font class="keyword">this</font>; 00169 } 00170 00171 <a class="code" href="class_s_w_module.html">SWModule</a> &RawGenBook::operator <<(<font class="keyword">const</font> <font class="keywordtype">char</font> *inbuf) { 00172 <font class="keywordflow">return</font> setentry(inbuf, 0); 00173 } 00174 00175 00176 <a class="code" href="class_s_w_module.html">SWModule</a> &RawGenBook::operator <<(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *inkey) { 00177 <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *srckey = 0; 00178 <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *key = ((<a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *)this->key); 00179 <font class="comment">// see if we have a VerseKey * or decendant</font> 00180 <font class="preprocessor">#ifndef _WIN32_WCE</font> 00181 <font class="preprocessor"></font> <font class="keywordflow">try</font> { 00182 <font class="preprocessor">#endif</font> 00183 <font class="preprocessor"></font> srckey = SWDYNAMIC_CAST(<a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a>, inkey); 00184 <font class="preprocessor">#ifndef _WIN32_WCE</font> 00185 <font class="preprocessor"></font> } 00186 <font class="keywordflow">catch</font> ( ... ) {} 00187 <font class="preprocessor">#endif</font> 00188 <font class="preprocessor"></font> <font class="comment">// if we don't have a VerseKey * decendant, create our own</font> 00189 <font class="keywordflow">if</font> (!srckey) { 00190 srckey = (<a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *)CreateKey(); 00191 (*srckey) = *inkey; 00192 } 00193 00194 key-><a class="code" href="class_tree_key_idx.html#a6">setUserData</a>(srckey-><a class="code" href="class_tree_key_idx.html#a5">getUserData</a>(), 8); 00195 key-><a class="code" href="class_tree_key_idx.html#a18">save</a>(); 00196 00197 <font class="keywordflow">if</font> (inkey != srckey) <font class="comment">// free our key if we created a VerseKey</font> 00198 <font class="keyword">delete</font> srckey; 00199 00200 <font class="keywordflow">return</font> *<font class="keyword">this</font>; 00201 } 00202 00203 00204 <font class="comment">/******************************************************************************</font> 00205 <font class="comment"> * RawGenBook::deleteEntry - deletes this entry</font> 00206 <font class="comment"> *</font> 00207 <font class="comment"> * RET: *this</font> 00208 <font class="comment"> */</font> 00209 00210 <font class="keywordtype">void</font> RawGenBook::deleteEntry() { 00211 <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *key = ((<a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *)this->key); 00212 key-><a class="code" href="class_tree_key_idx.html#a17">remove</a>(); 00213 } 00214 00215 00216 <font class="keywordtype">char</font> RawGenBook::createModule(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath) { 00217 <font class="keywordtype">char</font> *path = 0; 00218 <font class="keywordtype">char</font> *buf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen (ipath) + 20 ]; 00219 FileDesc *fd; 00220 <font class="keywordtype">signed</font> <font class="keywordtype">char</font> retval; 00221 00222 stdstr(&path, ipath); 00223 00224 <font class="keywordflow">if</font> ((path[strlen(path)-1] == <font class="charliteral">'/'</font>) || (path[strlen(path)-1] == <font class="charliteral">'\\'</font>)) 00225 path[strlen(path)-1] = 0; 00226 00227 sprintf(buf, <font class="stringliteral">"%s.bdt"</font>, path); 00228 unlink(buf); 00229 fd = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE); 00230 fd->getFd(); 00231 FileMgr::systemFileMgr.close(fd); 00232 00233 retval = TreeKeyIdx::create(path); 00234 <font class="keyword">delete</font> [] path; 00235 <font class="keywordflow">return</font> retval; 00236 } 00237 00238 00239 <a class="code" href="class_s_w_key.html">SWKey</a> *RawGenBook::CreateKey() { 00240 <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *newKey = <font class="keyword">new</font> <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a>(path); 00241 <font class="keywordflow">return</font> newKey; 00242 } </pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:00 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>