From b012f1b037150ec7d27762f27ea1081ca376bbde Mon Sep 17 00:00:00 2001 From: HW Date: Tue, 9 Oct 2012 18:00:19 +0200 Subject: [PATCH] changed page number reading this is far from complete since in fact, we read page references which follow a more complex syntax. while specifying page numbers is one option for them, they might also specify page names. we currently do not yet have code for this case and we will return "-1" for all page references we can not parse. --- djvu.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/djvu.c b/djvu.c index 27a215b2f..c2ba5a5ca 100644 --- a/djvu.c +++ b/djvu.c @@ -17,6 +17,7 @@ */ #include #include +#include #include #include @@ -134,17 +135,28 @@ static int walkTableOfContent(lua_State *L, miniexp_t r, int *count, int depth) int length = miniexp_length(r); int counter = 0; - char page_number[6]; + const char* page_name; + int page_number; while(counter < length-1) { lua_pushnumber(L, *count); lua_newtable(L); lua_pushstring(L, "page"); - strcpy(page_number,miniexp_to_str(miniexp_car(miniexp_cdr(miniexp_nth(counter, lista))))); - /* page numbers appear as #11, set # to 0 so strtol works */ - page_number[0]= '0'; - lua_pushnumber(L, strtol(page_number, NULL, 10)); + page_name = miniexp_to_str(miniexp_car(miniexp_cdr(miniexp_nth(counter, lista)))); + if(page_name != NULL && page_name[0] == '#') { + errno = 0; + page_number = strtol(page_name + 1, NULL, 10); + if(!errno) { + lua_pushnumber(L, page_number); + } else { + /* we can not parse this as a number, TODO: parse page names */ + lua_pushnumber(L, -1); + } + } else { + /* something we did not expect here */ + lua_pushnumber(L, -1); + } lua_settable(L, -3); lua_pushstring(L, "depth");