Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

zld.cpp

00001 /******************************************************************************
00002  *  rawld.cpp - code for class 'RawLD'- a module that reads raw lexicon and
00003  *                              dictionary files: *.dat *.idx
00004  */
00005 
00006 
00007 #include <ctype.h>
00008 #include <stdio.h>
00009 #include <fcntl.h>
00010 
00011 #ifndef __GNUC__
00012 #include <io.h>
00013 #else
00014 #include <unistd.h>
00015 #endif
00016 
00017 #include <string.h>
00018 #include <utilfuns.h>
00019 #include <zstr.h>
00020 #include <zld.h>
00021 
00022 
00023  /******************************************************************************
00024  * RawLD Constructor - Initializes data for instance of RawLD
00025  *
00026  * ENT: ipath   - path and filename of files (no extension)
00027  *              iname   - Internal name for module
00028  *              idesc   - Name to display to user for module
00029  *              idisp   - Display object to use for displaying
00030  */
00031 
00032 zLD::zLD(const char *ipath, const char *iname, const char *idesc, long blockCount, SWCompress *icomp, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang) : zStr(ipath, -1, blockCount, icomp), SWLD(iname, idesc, idisp, enc, dir, mark, ilang)
00033 {
00034 }
00035 
00036 
00037 /******************************************************************************
00038  * RawLD Destructor - Cleans up instance of RawLD
00039  */
00040 
00041 zLD::~zLD()
00042 {
00043 }
00044 
00045 
00046 /******************************************************************************
00047  * zLD::strongsPad      - Pads a key if it is 100% digits to 5 places
00048  *
00049  * ENT: buf -   buffer to check and pad
00050  */
00051 
00052 void zLD::strongsPad(char *buf)
00053 {
00054         const char *check;
00055         long size = 0;
00056         int len = strlen(buf);
00057         if ((len < 5) && (len > 0)) {
00058                 for (check = buf; *check; check++) {
00059                         if (!isdigit(*check))
00060                                 break;
00061                         else size++;
00062                 }
00063 
00064                 if ((size == len) && size) 
00065                         sprintf(buf, "%.5d", atoi(buf));
00066         }
00067 }
00068 
00069 
00070 /******************************************************************************
00071  * zLD::getEntry        - Looks up entry from data file.  'Snaps' to closest
00072  *                              entry and sets 'entrybuf'.
00073  *
00074  * ENT: away - number of entries offset from key (default = 0)
00075  *
00076  * RET: error status
00077  */
00078 
00079 char zLD::getEntry(long away)
00080 {
00081         char *idxbuf = 0;
00082         char *ebuf = 0;
00083         char retval = 0;
00084         long index;
00085         unsigned long size;
00086         char *buf = new char [ strlen(*key) + 6 ];
00087         strcpy(buf, *key);
00088 
00089         strongsPad(buf);
00090 
00091         *entrybuf = 0;
00092         if (!(retval = findKeyIndex(buf, &index, away))) {
00093                 getText(index, &idxbuf, &ebuf);
00094                 size = strlen(ebuf) + 1;
00095                 entrybuf = new char [ size * FILTERPAD ];
00096                 strcpy(entrybuf, ebuf);
00097 
00098                 entrySize = size;        // support getEntrySize call
00099                 if (!key->Persist())                    // If we have our own key
00100                         *key = idxbuf;                          // reset it to entry index buffer
00101 
00102                 stdstr(&entkeytxt, idxbuf);     // set entry key text that module 'snapped' to.
00103                 free(idxbuf);
00104                 free(ebuf);
00105         }
00106         else {
00107                 entrybuf = new char [ 5 ];
00108                 entrybuf[0] = 0;
00109                 entrybuf[1] = 0;
00110         }
00111                 
00112         delete [] buf;
00113         return retval;
00114 }
00115 
00116 
00117 /******************************************************************************
00118  * zLD::operator char * - Returns the correct entry when char * cast
00119  *                                                      is requested
00120  *
00121  * RET: string buffer with entry
00122  */
00123 
00124 char *zLD::getRawEntry() {
00125         if (!getEntry() && !isUnicode()) {
00126                 prepText(entrybuf);
00127         }
00128 
00129         return entrybuf;
00130 }
00131 
00132 
00133 /******************************************************************************
00134  * zLD::operator +=     - Increments module key a number of entries
00135  *
00136  * ENT: increment       - Number of entries to jump forward
00137  *
00138  * RET: *this
00139  */
00140 
00141 SWModule &zLD::operator +=(int increment)
00142 {
00143         char tmperror;
00144 
00145         if (key->Traversable()) {
00146                 *key += increment;
00147                 error = key->Error();
00148                 increment = 0;
00149         }
00150         
00151         tmperror = (getEntry(increment)) ? KEYERR_OUTOFBOUNDS : 0;
00152         error = (error)?error:tmperror;
00153         *key = entkeytxt;
00154         return *this;
00155 }
00156 
00157 
00158 /******************************************************************************
00159  * zLD::operator =(SW_POSITION) - Positions this key if applicable
00160  */
00161 
00162 SWModule &zLD::operator =(SW_POSITION p)
00163 {
00164         if (!key->Traversable()) {
00165                 switch (p) {
00166                 case POS_TOP:
00167                         *key = "";
00168                         break;
00169                 case POS_BOTTOM:
00170                         *key = "zzzzzzzzz";
00171                         break;
00172                 } 
00173         }
00174         else    *key = p;
00175         return *this;
00176 }
00177 
00178 
00179 SWModule &zLD::setentry(const char *inbuf, long len) {
00180         setText(*key, inbuf, len);
00181 
00182         return *this;
00183 }
00184 
00185 SWModule &zLD::operator <<(const char *inbuf) {
00186         return setentry(inbuf, 0);
00187 }
00188 
00189 
00190 SWModule &zLD::operator <<(const SWKey *inkey) {
00191         linkEntry(*key, *inkey);
00192 
00193         return *this;
00194 }
00195 
00196 
00197 /******************************************************************************
00198  * RawFiles::deleteEntry        - deletes this entry
00199  *
00200  * RET: *this
00201  */
00202 
00203 void zLD::deleteEntry() {
00204         setText(*key, "");
00205 }

Generated on Thu Jun 20 22:13:01 2002 for The Sword Project by doxygen1.2.15