diff options
author | Nick White <hg@njw.me.uk> | 2011-07-16 01:13:19 +0100 |
---|---|---|
committer | Nick White <hg@njw.me.uk> | 2011-07-16 01:13:19 +0100 |
commit | 3a1a5d42d6d019d63736960c8b9aea27f9a0315d (patch) | |
tree | 7f2eb67a3d566015d422c692cffde64f6ca19ef9 | |
parent | bf49d1e671bddf3b5d0b89c8567d71a6054507ff (diff) |
Simplify page code
-rw-r--r-- | getgbook.c | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -60,7 +60,7 @@ char *getbookid(char *isbn) return bookid; } -char *getpageurl(char *bookid, char *pagetype, int pagenum) +char *getpageurl(char *bookid, char *pg) { char url[URLMAX]; int i, l; @@ -70,12 +70,12 @@ char *getpageurl(char *bookid, char *pagetype, int pagenum) i = dial("books.google.com", "80"); srv = fdopen(i, "r+"); - snprintf(url, URLMAX, "/books?id=%s&pg=%s%i&jscmd=click3", bookid, pagetype, pagenum); + snprintf(url, URLMAX, "/books?id=%s&pg=%s&jscmd=click3", bookid, pg); if((buf = get(srv, "books.google.com", url)) == NULL) return NULL; - snprintf(m, 80, "\"pid\":\"%s%i\"", pagetype, pagenum); + snprintf(m, 80, "\"pid\":\"%s\"", pg); if((c = strstr(buf,m)) == NULL) return NULL; if(strncmp(c+strlen(m)+1, "\"src\"", 5) != 0) @@ -92,7 +92,7 @@ char *getpageurl(char *bookid, char *pagetype, int pagenum) int main(int argc, char *argv[]) { - char *bookid, *url; + char *bookid, *url, pg[12]; if(argc < 2 || argc > 3) die(usage); @@ -109,10 +109,11 @@ int main(int argc, char *argv[]) die("Could not find book\n"); printf("bookid is %s\n", bookid); - if((url = getpageurl(bookid, "PA", 2)) != NULL) - printf("page 2 url is %s\n", url); + strncpy(pg, "PA2", 12); + if((url = getpageurl(bookid, pg)) != NULL) + printf("page %s url is %s\n", pg, url); else - fprintf(stderr, "Could not find page %s %i\n", "PA", 2); + fprintf(stderr, "Could not find page %s\n", pg); } free(bookid); |