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

hrefcom.cpp

00001 /******************************************************************************
00002  *  hrefcom.cpp - code for class 'HREFCom'- a module that produces HTML HREFs
00003  *                      pointing to actual text desired.  Uses standard
00004  *                      files:  ot and nt using indexs ??.bks ??.cps ??.vss
00005  */
00006 
00007 
00008 #include <ctype.h>
00009 #include <stdio.h>
00010 #include <fcntl.h>
00011 
00012 #ifndef __GNUC__
00013 #include <io.h>
00014 #else
00015 #include <unistd.h>
00016 #endif
00017 
00018 #include <string.h>
00019 #include <utilfuns.h>
00020 #include <rawverse.h>
00021 #include <hrefcom.h>
00022 
00023 
00024  /******************************************************************************
00025  * HREFCom Constructor - Initializes data for instance of HREFCom
00026  *
00027  * ENT: iname - Internal name for module
00028  *      iprefix - string to prepend to each HREF (e.g. "file://mods/com/jfb/")
00029  *      idesc - Name to display to user for module
00030  *      idisp    - Display object to use for displaying
00031  */
00032 
00033 HREFCom::HREFCom(const char *ipath, const char *iprefix, const char *iname, const char *idesc, SWDisplay *idisp) : RawVerse(ipath), SWCom(iname, idesc, idisp)
00034 {
00035         prefix   = 0;
00036         stdstr(&prefix, iprefix);
00037 }
00038 
00039 
00040 /******************************************************************************
00041  * HREFCom Destructor - Cleans up instance of HREFCom
00042  */
00043 
00044 HREFCom::~HREFCom()
00045 {
00046         if (prefix)
00047                 delete [] prefix;
00048 }
00049 
00050 
00051 /******************************************************************************
00052  * HREFCom::operator char *     - Returns the correct verse when char * cast
00053  *                                      is requested
00054  *
00055  * RET: string buffer with verse
00056  */
00057 
00058 char *HREFCom::getRawEntry() {
00059         long  start;
00060         unsigned short size;
00061         char *tmpbuf;
00062         VerseKey *key = 0;
00063 
00064 #ifndef _WIN32_WCE
00065         try {
00066 #endif
00067                 key = SWDYNAMIC_CAST(VerseKey, this->key);
00068 #ifndef _WIN32_WCE
00069         }
00070         catch ( ... ) {}
00071 #endif
00072         if (!key)
00073                 key = new VerseKey(this->key);
00074 
00075         findoffset(key->Testament(), key->Index(), &start, &size);
00076         entrySize = size;        // support getEntrySize call
00077 
00078         unsigned long newsize = ((size + 2) + strlen(prefix)) * FILTERPAD;
00079         if (newsize > entrybufallocsize) {
00080                 if (entrybuf)
00081                         delete [] entrybuf;
00082                 entrybuf = new char [ newsize ];
00083                 entrybufallocsize = newsize;
00084         }
00085         tmpbuf   = new char [ size + 10 ];
00086 
00087         gettext(key->Testament(), start, size + 2, tmpbuf);
00088         sprintf(entrybuf, "%s%s", prefix, tmpbuf);
00089         preptext(entrybuf);
00090 
00091         delete [] tmpbuf;
00092 
00093         if (key != this->key)
00094                 delete key;
00095 
00096         return entrybuf;
00097 }

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