Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

mobi toc, part II

  • Loading branch information...
commit 515bb45a74efb063b2e5d2c91d47f451d56b6ddb 1 parent 3563665
@drotiro authored
Showing with 7 additions and 6 deletions.
  1. +3 −2 src/Ebook.cpp
  2. +4 −4 src/MobiDumper.cpp
View
5 src/Ebook.cpp
@@ -40,10 +40,11 @@ void Dumper::write(const char * name, char * content, size_t len) {
string Dumper::read(string name) {
FILE * f;
string res;
- char buf[BUFLEN];
+ char buf[BUFLEN], fname[PATHLEN];
size_t read;
- f = fopen(name.c_str(), "rb");
+ sprintf(fname, "%s%s%s", outDir, SEP, name.c_str());
+ f = fopen(fname, "rb");
read = fread(buf, 1, BUFLEN, f);
while(read > 0) {
res.append(buf, read);
View
8 src/MobiDumper.cpp
@@ -48,12 +48,12 @@ string MobiDumper::fixLinks(string src) {
char fbuf[24];
// Step 1. fix a[@href]
- string fmark = "filepos=", href="href=text_";
+ string fmark = "filepos=", href="href=\"text_";
size_t fml = fmark.length(), hl = href.length();
string::size_type pos = src.find(fmark);
while(pos!=string::npos) {
src.replace(pos, fml, href);
- src.insert(pos+hl+FPOSLEN,".html");
+ src.insert(pos+hl+FPOSLEN,".html\"");
pos = src.find(fmark, pos+hl+FPOSLEN);
}
@@ -144,9 +144,9 @@ JsonObj MobiDumper::buildToc() {
string href = rx.get("//reference[@type='toc']/@href");
if(href.empty()) return toc;
//open toc file and process 'a' elements
- Xml tocx(href);
+ Xml tocx(read(href));
Xpath tx = tocx.xpath(NULL);
- vector<string> links = tx.query("//a/@href");
+ vector<string> links = tx.query("//a[@href]/@href");
for(vector<string>::iterator it = links.begin(); it != links.end(); ++it) {
toc.add(*it, *it);
}
Please sign in to comment.
Something went wrong with that request. Please try again.