summaryrefslogtreecommitdiff
path: root/getgbook.c
diff options
context:
space:
mode:
authorNick White <hg@njw.me.uk>2011-07-16 12:55:44 +0100
committerNick White <hg@njw.me.uk>2011-07-16 12:55:44 +0100
commit4c5740f8a747cc886d2b7bd807300818e3be22a9 (patch)
tree6fe36344bf4274b3bab7c823b9d5010ff6ba6681 /getgbook.c
parent5f2172cc8ca50cea7d09b4a569f958a3015f33e7 (diff)
Handle \u0026 as &
Diffstat (limited to 'getgbook.c')
-rw-r--r--getgbook.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/getgbook.c b/getgbook.c
index ae47993..358d8c3 100644
--- a/getgbook.c
+++ b/getgbook.c
@@ -58,8 +58,7 @@ char *getbookid(char *isbn)
char *getpageurl(char *bookid, char *pg)
{
char url[URLMAX];
- int l;
- char *buf, *c, *d, m[80], *pageurl;
+ char *buf, *c, *d, m[80], *pageurl, *p;
snprintf(url, URLMAX, "/books?id=%s&pg=%s&jscmd=click3", bookid, pg);
@@ -71,11 +70,16 @@ char *getpageurl(char *bookid, char *pg)
return NULL;
if(strncmp(c+strlen(m)+1, "\"src\"", 5) != 0)
return NULL;
- for(l=0, d=c+strlen(m)+8; *d && *d != '"'; *d++, l++);
- pageurl = malloc(sizeof(char *) * l);
- strncpy(pageurl, c+strlen(m)+8, l);
- pageurl[l] = '\0';
+ pageurl = malloc(sizeof(char *) * URLMAX);
+ for(p=pageurl, d=c+strlen(m)+8; *d && *d != '"'; *d++, *p++) {
+ if(!strncmp(d, "\\u0026", 6)) {
+ *p = '&';
+ d+=5;
+ } else
+ *p = *d;
+ }
+ *p = '\0';
free(buf);
return pageurl;