The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hrefcom.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * hrefcom.cpp - code for class 'HREFCom'- a module that produces HTML
4  * HREFs pointing to actual text desired. Uses standard
5  * files: ot and nt using indexs ??.bks ??.cps ??.vss
6  *
7  * $Id: hrefcom.cpp 3821 2020-11-02 18:33:02Z scribe $
8  *
9  * Copyright 1998-2013 CrossWire Bible Society (http://www.crosswire.org)
10  * CrossWire Bible Society
11  * P. O. Box 2528
12  * Tempe, AZ 85280-2528
13  *
14  * This program is free software; you can redistribute it and/or modify it
15  * under the terms of the GNU General Public License as published by the
16  * Free Software Foundation version 2.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * General Public License for more details.
22  *
23  */
24 
25 
26 #include <ctype.h>
27 #include <stdio.h>
28 #include <fcntl.h>
29 
30 #include <utilstr.h>
31 #include <rawverse.h>
32 #include <hrefcom.h>
33 #include <swbuf.h>
34 #include <versekey.h>
35 
37 
38  /******************************************************************************
39  * HREFCom Constructor - Initializes data for instance of HREFCom
40  *
41  * ENT: iname - Internal name for module
42  * iprefix - string to prepend to each HREF (e.g. "file://mods/com/jfb/")
43  * idesc - Name to display to user for module
44  * idisp - Display object to use for displaying
45  */
46 
47 HREFCom::HREFCom(const char *ipath, const char *iprefix, const char *iname, const char *idesc, SWDisplay *idisp) : RawVerse(ipath), SWCom(iname, idesc, idisp)
48 {
49  prefix = 0;
50  stdstr(&prefix, iprefix);
51 }
52 
53 
54 /******************************************************************************
55  * HREFCom Destructor - Cleans up instance of HREFCom
56  */
57 
59 {
60  if (prefix)
61  delete [] prefix;
62 }
63 
64 
65 /******************************************************************************
66  * HREFCom::operator char * - Returns the correct verse when char * cast
67  * is requested
68  *
69  * RET: string buffer with verse
70  */
71 
73  long start;
74  unsigned short size;
75  const VerseKey *key = 0;
76 
77  key = &getVerseKey();
78 
79  findOffset(key->getTestament(), key->getTestamentIndex(), &start, &size);
80  entrySize = size; // support getEntrySize call
81 
82  SWBuf tmpbuf;
83 
84  readText(key->getTestament(), start, size, tmpbuf);
85  entryBuf = prefix;
86  entryBuf += tmpbuf.c_str();
87  prepText(entryBuf);
88 
89  if (key != (const VerseKey *)this->key)
90  delete key;
91 
92  return entryBuf;
93 }
94 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
static void prepText(SWBuf &buf)
Definition: swmodule.cpp:1695
void findOffset(char testmt, long idxoff, long *start, unsigned short *end) const
Definition: rawverse.cpp:118
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
const char * c_str() const
Definition: swbuf.h:158
char * prefix
Definition: hrefcom.h:38
void readText(char testmt, long start, unsigned short size, SWBuf &buf) const
Definition: rawverse.cpp:154
Definition: swcom.h:49
int entrySize
Definition: swmodule.h:157
int size
Definition: regex.c:5043
SWBuf entryBuf
Definition: swmodule.h:140
virtual long getTestamentIndex() const
Definition: versekey.cpp:1704
virtual ~HREFCom()
Definition: hrefcom.cpp:58
SWKey * key
Definition: swmodule.h:124
virtual SWBuf & getRawEntryBuf() const
Definition: hrefcom.cpp:72
#define SWORD_NAMESPACE_END
Definition: defs.h:40
VerseKey & getVerseKey(SWKey *key=0)
Definition: swcom.cpp:123
virtual char getTestament() const
Definition: versekey.cpp:1498
HREFCom(const char *ipath, const char *prefix, const char *iname=0, const char *idesc=0, SWDisplay *idisp=0)
Definition: hrefcom.cpp:47