From ffba8e0fd362b8d1381e52e1ade89690f72f21d0 Mon Sep 17 00:00:00 2001 From: Nick White Date: Sat, 16 Jul 2011 16:46:26 +0100 Subject: Make stdin work, and add -p support --- getgbook.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'getgbook.c') diff --git a/getgbook.c b/getgbook.c index fa69db9..975c948 100644 --- a/getgbook.c +++ b/getgbook.c @@ -103,31 +103,30 @@ char *getpageurl(char *bookid, char *pg) int main(int argc, char *argv[]) { - char *bookid, *url, pg[16]; + char *bookid, *url, pg[16], buf[1024]; int totalpages, i; - if(argc < 2 || argc > 3) + if(argc < 2 || argc > 3 || + (argv[1][0]=='-' && ((argv[1][1]!='p' && argv[1][1]!='a') || argc < 3))) die(usage); - if(argv[1][0] == '-') { - if((argv[1][1] != 'p' && argv[1][1] != 'a') || argc < 3) - die(usage); - - if((bookid = getbookid(argv[2])) == NULL) - die("Could not find book\n"); + if((bookid = getbookid(argv[argc-1])) == NULL) + die("Could not find book\n"); - if(!(totalpages = gettotalpages(bookid))) - die("Book has no pages\n"); + if(!(totalpages = gettotalpages(bookid))) + die("Book has no pages\n"); + if(argv[1][0] == '-') { /* note this isn't the best way, not least because it misses the * non PA pages. best is to crawl around the json grabbing everything * available, by starting on PP1, and filling in by going through * all pages in totalpages. then crawl through the pages struct. */ for(i=1; i