From ca9116d685f375ba91be47c3c60b66853a95cb4a Mon Sep 17 00:00:00 2001 From: Nick White Date: Sun, 24 Jul 2011 12:40:13 +0100 Subject: Fix little bugs --- getgbook.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/getgbook.c b/getgbook.c index 08cee6c..ecd34a6 100644 --- a/getgbook.c +++ b/getgbook.c @@ -49,7 +49,8 @@ Page *getpagedetail(char *bookid, char *pg, char *cookie) *p = *d; } *p = '\0'; - } + } else + d=c; for(; *d; d++) { if(*d == '}') { @@ -106,20 +107,29 @@ int main(int argc, char *argv[]) } continue; } + retry=0; if(argv[1][1] == 'a') { - snprintf(n, 80, "%05d.png", page->num); + if(page->num != -1) + snprintf(n, 80, "%05d.png", page->num); + else + snprintf(n, 80, "%s.png", page->name); gettofile("books.google.com", page->url, cookie, NULL, n); printf("Downloaded page %d\n", page->num); - } else if(page->num != -1) - printf("%s %d\n", page->name, page->num); + } else { + printf("%s ", page->name); + if(page->num != -1) printf("%d", page->num); + printf("\n"); + } free(page); } } else { while(fgets(buf, 1024, stdin)) { sscanf(buf, "%15s", pg); + snprintf(u, URLMAX, "/books?id=%s", bookid); + get("books.google.com", u, NULL, cookie, &tmp); if(!(page = getpagedetail(bookid, pg, cookie)) || !page->url[0]) { fprintf(stderr, "%s failed\n", pg); - free(page); + if(page) free(page); continue; } snprintf(n, 80, "%05d.png", page->num); -- cgit v1.2.3