From 3a1a5d42d6d019d63736960c8b9aea27f9a0315d Mon Sep 17 00:00:00 2001 From: Nick White Date: Sat, 16 Jul 2011 01:13:19 +0100 Subject: Simplify page code --- getgbook.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/getgbook.c b/getgbook.c index 6461295..bb809d4 100644 --- a/getgbook.c +++ b/getgbook.c @@ -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); -- cgit v1.2.3