diff --git a/.gitignore b/.gitignore index 81a4bd850..9ff0fb666 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ lua-* mupdf-thirdparty.zip djvulibre* kpdfview +slider_watcher *.o kindlepdfviewer-*.zip @@ -12,8 +13,29 @@ kindlepdfviewer-*.zip /.cproject /.project /.reader.kpdfview +/settings.reader.lua + +fonts +data +history +screenshots +cr3cache kpvcrlib/CMakeCache.txt kpvcrlib/CMakeFiles/ kpvcrlib/cmake_install.cmake kpvcrlib/Makefile + +popen-noshell/libpopen_noshell.a +popen-noshell/*.o +popen-noshell/.svn/ +popen-noshell/CREDITS +popen-noshell/Makefile +popen-noshell/README +popen-noshell/performance_tests/ +popen-noshell/popen_noshell.c +popen-noshell/popen_noshell.h +popen-noshell/popen_noshell_examples.c +popen-noshell/popen_noshell_tests.c +popen-noshell/popen_noshell_tests.cpp + diff --git a/Makefile b/Makefile index f8a888e46..877b73d1e 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ LUADIR=luajit-2.0 MUPDFDIR=mupdf -MUPDFTARGET=build/debug +MUPDFTARGET=build/release MUPDFLIBDIR=$(MUPDFDIR)/$(MUPDFTARGET) DJVUDIR=djvulibre KPVCRLIBDIR=kpvcrlib @@ -11,28 +11,36 @@ CRENGINEDIR=$(KPVCRLIBDIR)/crengine FREETYPEDIR=$(MUPDFDIR)/thirdparty/freetype-2.4.10 LFSDIR=luafilesystem +POPENNSDIR=popen-noshell + # must point to directory with *.ttf fonts for crengine TTF_FONTS_DIR=$(MUPDFDIR)/fonts # set this to your ARM cross compiler: -HOST:=arm-none-linux-gnueabi -CC:=$(HOST)-gcc -CXX:=$(HOST)-g++ -STRIP:=$(HOST)-strip +CHOST?=arm-none-linux-gnueabi +CC:=$(CHOST)-gcc +CXX:=$(CHOST)-g++ +STRIP:=$(CHOST)-strip +AR:=$(CHOST)-ar ifdef SBOX_UNAME_MACHINE CC:=gcc CXX:=g++ endif HOSTCC:=gcc HOSTCXX:=g++ - -CFLAGS:=-O3 $(SYSROOT) -CXXFLAGS:=-O3 $(SYSROOT) -LDFLAGS:= $(SYSROOT) -ARM_CFLAGS:=-march=armv6 -# use this for debugging: -#CFLAGS:=-O0 -g $(SYSROOT) +HOSTAR:=ar + +# Base CFLAGS, without arch. We'll need it for luajit, because its Makefiles do some tricky stuff to differentiate HOST/TARGET +BASE_CFLAGS:=-O2 -ffast-math -pipe -fomit-frame-pointer -fno-stack-protector -U_FORTIFY_SOURCE +# Use this for debugging: +#BASE_CFLAGS:=-O0 -g +ARM_ARCH:=-march=armv6j -mtune=arm1136jf-s -mfpu=vfp +HOST_ARCH:=-march=native +HOSTCFLAGS:=$(HOST_ARCH) $(BASE_CFLAGS) +CFLAGS:=$(BASE_CFLAGS) +CXXFLAGS:=$(BASE_CFLAGS) -fno-use-cxa-atexit +LDFLAGS:=-Wl,-O1 -Wl,--as-needed DYNAMICLIBSTDCPP:=-lstdc++ ifdef STATICLIBSTDCPP @@ -46,6 +54,7 @@ endif ifdef EMULATE_READER CC:=$(HOSTCC) -g CXX:=$(HOSTCXX) + AR:=$(HOSTAR) EMULATE_READER_W?=824 EMULATE_READER_H?=1200 EMU_CFLAGS?=$(shell sdl-config --cflags) @@ -56,8 +65,11 @@ ifdef EMULATE_READER ifeq "$(shell uname -s -m)" "Darwin x86_64" EMU_LDFLAGS += -pagezero_size 10000 -image_base 100000000 endif + CFLAGS+= $(HOST_ARCH) + CXXFLAGS+= $(HOST_ARCH) else - CFLAGS+= $(ARM_CFLAGS) + CFLAGS+= $(ARM_ARCH) + CXXFLAGS+= $(ARM_ARCH) endif # standard includes @@ -87,16 +99,20 @@ THIRDPARTYLIBS := $(MUPDFLIBDIR)/libfreetype.a \ LUALIB := $(LUADIR)/src/libluajit.a -all:kpdfview +POPENNSLIB := $(POPENNSDIR)/libpopen_noshell.a + +all: kpdfview -kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft.o lfs.o mupdfimg.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS) +kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o $(POPENNSLIB) util.o ft.o lfs.o mupdfimg.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS) $(CC) \ + $(CFLAGS) \ kpdfview.o \ einkfb.o \ pdf.o \ blitbuffer.o \ drawcontext.o \ input.o \ + $(POPENNSLIB) \ util.o \ ft.o \ lfs.o \ @@ -109,10 +125,14 @@ kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft cre.o \ $(CRENGINELIBS) \ $(STATICLIBSTDCPP) \ - -o kpdfview -lm -ldl -lpthread $(EMU_LDFLAGS) $(DYNAMICLIBSTDCPP) + $(LDFLAGS) \ + -o $@ -lm -ldl -lpthread $(EMU_LDFLAGS) $(DYNAMICLIBSTDCPP) -slider_watcher: slider_watcher.c - $(CC) $(CFLAGS) $< -o $@ +slider_watcher.o: %.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ + +slider_watcher: slider_watcher.o $(POPENNSLIB) + $(CC) $(CFLAGS) slider_watcher.o $(POPENNSLIB) -o $@ ft.o: %.o: %.c $(THIRDPARTYLIBS) $(CC) -c $(KPDFREADER_CFLAGS) -I$(FREETYPEDIR)/include -I$(MUPDFDIR)/fitz $< -o $@ @@ -124,13 +144,13 @@ djvu.o: %.o: %.c $(CC) -c $(KPDFREADER_CFLAGS) -I$(DJVUDIR)/ $< -o $@ cre.o: %.o: %.cpp - $(CC) -c -I$(CRENGINEDIR)/crengine/include/ -I$(LUADIR)/src $< -o $@ -lstdc++ + $(CC) -c $(CFLAGS) -I$(CRENGINEDIR)/crengine/include/ -I$(LUADIR)/src $< -o $@ lfs.o: $(LFSDIR)/src/lfs.c $(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@ fetchthirdparty: - -rm -Rf mupdf/thirdparty + rm -rf mupdf/thirdparty test -d mupdf && (cd mupdf; git checkout .) || echo warn: mupdf folder not found test -d $(LUADIR) && (cd $(LUADIR); git checkout .) || echo warn: $(LUADIR) folder not found git submodule init @@ -156,73 +176,81 @@ fetchthirdparty: patch -N -p0 < ../../../kpvcrlib/jpeg_decompress_struct_size.patch # MuPDF patch: use external fonts cd mupdf && patch -N -p1 < ../mupdf.patch + test -f popen-noshell/popen_noshell.c || svn co http://popen-noshell.googlecode.com/svn/trunk/ popen-noshell + # popen_noshell patch: Make it build on recent TCs, and implement a simple Makefile for building it as a static lib + cd popen-noshell && test -f Makefile || patch -N -p0 < popen_noshell-buildfix.patch clean: - -rm -f *.o kpdfview slider_watcher + rm -f *.o kpdfview slider_watcher cleanthirdparty: - -make -C $(LUADIR) clean - -make -C $(MUPDFDIR) clean - -make -C $(CRENGINEDIR)/thirdparty/antiword clean - test -d $(CRENGINEDIR)/thirdparty/chmlib && make -C $(CRENGINEDIR)/thirdparty/chmlib clean || echo warn: chmlib folder not found - test -d $(CRENGINEDIR)/thirdparty/libpng && (make -C $(CRENGINEDIR)/thirdparty/libpng clean) || echo warn: libpng folder not found - test -d $(CRENGINEDIR)/crengine && (make -C $(CRENGINEDIR)/crengine clean) || echo warn: crengine folder not found - test -d $(KPVCRLIBDIR) && (make -C $(KPVCRLIBDIR) clean) || echo warn: kpvcrlib folder not found - -rm -rf $(DJVUDIR)/build - -rm -f $(MUPDFDIR)/fontdump.host - -rm -f $(MUPDFDIR)/cmapdump.host + $(MAKE) -C $(LUADIR) CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CROSS="$(CHOST)-" clean + $(MAKE) -C $(MUPDFDIR) build="release" clean + $(MAKE) -C $(CRENGINEDIR)/thirdparty/antiword clean + test -d $(CRENGINEDIR)/thirdparty/chmlib && $(MAKE) -C $(CRENGINEDIR)/thirdparty/chmlib clean || echo warn: chmlib folder not found + test -d $(CRENGINEDIR)/thirdparty/libpng && ($(MAKE) -C $(CRENGINEDIR)/thirdparty/libpng clean) || echo warn: chmlib folder not found + test -d $(CRENGINEDIR)/crengine && ($(MAKE) -C $(CRENGINEDIR)/crengine clean) || echo warn: chmlib folder not found + test -d $(KPVCRLIBDIR) && ($(MAKE) -C $(KPVCRLIBDIR) clean) || echo warn: chmlib folder not found + rm -rf $(DJVUDIR)/build + rm -f $(MUPDFDIR)/fontdump.host + rm -f $(MUPDFDIR)/cmapdump.host + $(MAKE) -C $(POPENNSDIR) clean $(MUPDFDIR)/fontdump.host: - make -C mupdf CC="$(HOSTCC)" $(MUPDFTARGET)/fontdump + $(MAKE) -C mupdf build="release" CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS) -I../mupdf/fitz -I../mupdf/pdf" $(MUPDFTARGET)/fontdump cp -a $(MUPDFLIBDIR)/fontdump $(MUPDFDIR)/fontdump.host - make -C mupdf clean + $(MAKE) -C mupdf clean $(MUPDFDIR)/cmapdump.host: - make -C mupdf CC="$(HOSTCC)" $(MUPDFTARGET)/cmapdump + $(MAKE) -C mupdf build="release" CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS) -I../mupdf/fitz -I../mupdf/pdf" $(MUPDFTARGET)/cmapdump cp -a $(MUPDFLIBDIR)/cmapdump $(MUPDFDIR)/cmapdump.host - make -C mupdf clean + $(MAKE) -C mupdf clean $(MUPDFLIBS) $(THIRDPARTYLIBS): $(MUPDFDIR)/cmapdump.host $(MUPDFDIR)/fontdump.host # build only thirdparty libs, libfitz and pdf utils, which will care for libmupdf.a being built - CFLAGS="$(CFLAGS) -DNOBUILTINFONT" make -C mupdf CC="$(CC)" CMAPDUMP=cmapdump.host FONTDUMP=fontdump.host MUPDF= MU_APPS= BUSY_APP= XPS_APPS= verbose=1 + CFLAGS="$(CFLAGS) -DNOBUILTINFONT" $(MAKE) -C mupdf build="release" CC="$(CC)" CMAPDUMP=cmapdump.host FONTDUMP=fontdump.host MUPDF= MU_APPS= BUSY_APP= XPS_APPS= verbose=1 $(DJVULIBS): - -mkdir $(DJVUDIR)/build + mkdir -p $(DJVUDIR)/build ifdef EMULATE_READER - cd $(DJVUDIR)/build && ../configure --disable-desktopfiles --disable-shared --enable-static --disable-xmltools --disable-largefiles + cd $(DJVUDIR)/build && ../configure --disable-desktopfiles --disable-shared --enable-static --disable-xmltools --disable-largefile else - cd $(DJVUDIR)/build && ../configure --disable-desktopfiles --disable-shared --enable-static --host=$(HOST) --disable-xmltools --disable-largefiles + cd $(DJVUDIR)/build && ../configure --disable-desktopfiles --disable-shared --enable-static --host=$(CHOST) --disable-xmltools --disable-largefile endif - make -C $(DJVUDIR)/build + $(MAKE) -C $(DJVUDIR)/build $(CRENGINELIBS): cd $(KPVCRLIBDIR) && rm -rf CMakeCache.txt CMakeFiles && \ - CFLAGS="$(CFLAGS)" CC="$(CC)" CXX="$(CXX)" cmake . && \ - make + CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS)" cmake . && \ + $(MAKE) $(LUALIB): ifdef EMULATE_READER - make -C $(LUADIR) + $(MAKE) -C $(LUADIR) else - make -C $(LUADIR) CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CROSS="$(HOST)-" TARGET_FLAGS="$(SYSROOT) -DLUAJIT_NO_LOG2 -DLUAJIT_NO_EXP2" + # To recap: build its TARGET_CC from CROSS+CC, so we need HOSTCC in CC. Build its HOST/TARGET_CFLAGS based on CFLAGS, so we need a neutral CFLAGS without arch + $(MAKE) -C $(LUADIR) CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CFLAGS="$(BASE_CFLAGS)" HOST_CFLAGS="$(HOSTCFLAGS)" TARGET_CFLAGS="$(CFLAGS)" CROSS="$(CHOST)-" TARGET_FLAGS="-DLUAJIT_NO_LOG2 -DLUAJIT_NO_EXP2" endif -thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) $(DJVULIBS) $(CRENGINELIBS) +$(POPENNSLIB): + $(MAKE) -C $(POPENNSDIR) CC="$(CC)" AR="$(AR)" + +thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) $(DJVULIBS) $(CRENGINELIBS) $(POPENNSLIB) INSTALL_DIR=kindlepdfviewer LUA_FILES=reader.lua -VERSION?=$(shell git rev-parse --short HEAD) +VERSION?=$(shell git describe HEAD) customupdate: all # ensure that build binary is for ARM file kpdfview | grep ARM || exit 1 $(STRIP) --strip-unneeded kpdfview - -rm kindlepdfviewer-$(VERSION).zip - rm -Rf $(INSTALL_DIR) + rm -f kindlepdfviewer-$(VERSION).zip + rm -rf $(INSTALL_DIR) mkdir -p $(INSTALL_DIR)/{history,screenshots} echo $(VERSION) > $(INSTALL_DIR)/git-rev - cp -p README.md COPYING kpdfview $(LUA_FILES) $(INSTALL_DIR) + cp -p README.md COPYING kpdfview kpdf.sh $(LUA_FILES) $(INSTALL_DIR) mkdir $(INSTALL_DIR)/data cp -rpL data/*.css $(INSTALL_DIR)/data cp -rpL fonts $(INSTALL_DIR) @@ -230,5 +258,5 @@ customupdate: all cp -rpL frontend $(INSTALL_DIR) mkdir $(INSTALL_DIR)/fonts/host zip -9 -r kindlepdfviewer-$(VERSION).zip $(INSTALL_DIR) launchpad/ kite/ - rm -Rf $(INSTALL_DIR) + rm -rf $(INSTALL_DIR) @echo "copy kindlepdfviewer-$(VERSION).zip to /mnt/us/customupdates and install with shift+shift+I" diff --git a/README.md b/README.md index 0093a9ebd..4ca2e4952 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Follow these steps: * install LuaJit sources into subfolder "luajit-2.0" * automatically fetch thirdparty sources with Makefile: - * make sure you have wget, unzip and git installed + * make sure you have wget, unzip, git and svn installed * run `make fetchthirdparty`. * adapt Makefile to your needs diff --git a/input.c b/input.c index 87a1123fd..d781c5b10 100644 --- a/input.c +++ b/input.c @@ -15,7 +15,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ + +#include "popen-noshell/popen_noshell.h" +#include #include +#include #include #include #include @@ -29,9 +33,7 @@ #include "input.h" #include #include -#include -#define OUTPUT_SIZE 21 #define CODE_IN_SAVER 10000 #define CODE_OUT_SAVER 10001 #define CODE_USB_PLUG_IN 10010 @@ -41,7 +43,17 @@ #define NUM_FDS 4 int inputfds[4] = { -1, -1, -1, -1 }; -int slider_pid = -1; +pid_t slider_pid = -1; +struct popen_noshell_pass_to_pclose pclose_arg; + +void slider_handler(int sig) +{ + /* Kill lipc-wait-event properly on exit */ + if(pclose_arg.pid != 0) { + // Be a little more gracious, lipc seems to handle SIGINT properly + kill(pclose_arg.pid, SIGINT); + } +} int findFreeFdSlot() { int i; @@ -63,7 +75,7 @@ static int openInputDevice(lua_State *L) { return luaL_error(L, "no free slot for new input device <%s>", inputdevice); } - if(!strcmp("fake_events",inputdevice)) { + if(!strcmp("slider",inputdevice)) { /* special case: the power slider */ int pipefd[2]; int childpid; @@ -73,10 +85,13 @@ static int openInputDevice(lua_State *L) { return luaL_error(L, "cannot fork() slider event listener"); } if(childpid == 0) { + // We send a SIGTERM to this child on exit, trap it to kill lipc properly. + signal(SIGTERM, slider_handler); + FILE *fp; - char std_out[OUTPUT_SIZE] = ""; + char std_out[256]; + int status; struct input_event ev; - int ret; __u16 key_code = 10000; close(pipefd[0]); @@ -85,17 +100,22 @@ static int openInputDevice(lua_State *L) { ev.code = key_code; ev.value = 1; - /* listen power slider events */ - while(1) { - fp = popen("exec lipc-wait-event com.lab126.powerd goingToScreenSaver,outOfScreenSaver,charging,notCharging", "r"); - /* @TODO 07.06 2012 (houqp) - * plugin and out event can only be watched by: - lipc-wait-event com.lab126.hal usbPlugOut,usbPlugIn - */ - if(fgets(std_out, OUTPUT_SIZE, fp) == NULL) { - break; - } - pclose(fp); + /* listen power slider events (listen for ever for multiple events) */ + char *argv[] = {"lipc-wait-event", "-m", "-s", "0", "com.lab126.powerd", "goingToScreenSaver,outOfScreenSaver,charging,notCharging", (char *) NULL}; + /* @TODO 07.06 2012 (houqp) + * plugin and out event can only be watched by: + lipc-wait-event com.lab126.hal usbPlugOut,usbPlugIn + */ + + fp = popen_noshell("lipc-wait-event", (const char * const *)argv, "r", &pclose_arg, 0); + if (!fp) { + err(EXIT_FAILURE, "popen_noshell()"); + } + + /* Flush to get rid of buffering issues? */ + fflush(fp); + + while(fgets(std_out, sizeof(std_out)-1, fp)) { if(std_out[0] == 'g') { ev.code = CODE_IN_SAVER; } else if(std_out[0] == 'o') { @@ -116,10 +136,26 @@ static int openInputDevice(lua_State *L) { /* generate event */ if(write(pipefd[1], &ev, sizeof(struct input_event)) == -1) { - break; + printf("Failed to generate event.\n"); } } - exit(0); /* cannot be reached?! */ + + status = pclose_noshell(&pclose_arg); + if (status == -1) { + err(EXIT_FAILURE, "pclose_noshell()"); + } else { + printf("lipc-wait-event exited with status %d.\n", status); + + if WIFEXITED(status) { + printf("lipc-wait-event exited normally with status: %d.\n", WEXITSTATUS(status)); + } + if WIFSIGNALED(status) { + printf("lipc-wait-event terminated by signal: %d.\n", WTERMSIG(status)); + } + } + + // We're done, go away :). + _exit(EXIT_SUCCESS); } else { close(pipefd[1]); inputfds[fd] = pipefd[0]; @@ -138,6 +174,7 @@ static int openInputDevice(lua_State *L) { if(SDL_Init(SDL_INIT_VIDEO) < 0) { return luaL_error(L, "cannot initialize SDL."); } + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); return 0; #endif } @@ -148,7 +185,7 @@ static int closeInputDevices(lua_State *L) { for(i=0; i secs * 1000 + usecs/1000) + if (SDL_GetTicks()-ticks > usecs/1000) return luaL_error(L, "Waiting for input failed: timeout\n"); } switch(event.type) { diff --git a/kite/KPDFviewer (last file) b/kite/KPDFviewer (last file) index 5d9acab14..de0c410d9 100755 --- a/kite/KPDFviewer (last file) +++ b/kite/KPDFviewer (last file) @@ -1,3 +1,3 @@ #!/bin/sh -/mnt/us/launchpad/kpdf.sh +/mnt/us/kindlepdfviewer/kpdf.sh diff --git a/kite/KPDFviewer File Manager b/kite/KPDFviewer File Manager index 3374ef3ae..f5f935234 100755 --- a/kite/KPDFviewer File Manager +++ b/kite/KPDFviewer File Manager @@ -1,3 +1,3 @@ #!/bin/sh -/mnt/us/launchpad/kpdf.sh /mnt/us/documents +/mnt/us/kindlepdfviewer/kpdf.sh /mnt/us/documents diff --git a/launchpad/kpdf.sh b/kpdf.sh similarity index 83% rename from launchpad/kpdf.sh rename to kpdf.sh index 173e5f7e4..3f5cffc43 100755 --- a/launchpad/kpdf.sh +++ b/kpdf.sh @@ -22,7 +22,7 @@ fi killall -stop cvm # finally call reader -./reader.lua -d "$1" 2> /mnt/us/kindlepdfviewer/crash.log || cat /mnt/us/kindlepdfviewer/crash.log +./reader.lua "$1" 2> /mnt/us/kindlepdfviewer/crash.log || cat /mnt/us/kindlepdfviewer/crash.log # unmount system fonts if grep /mnt/us/kindlepdfviewer/fonts/host /proc/mounts; then @@ -31,7 +31,3 @@ fi # always try to continue cvm killall -cont cvm || /etc/init.d/framework start - -# cleanup hanging process -killall lipc-wait-event - diff --git a/kpdfview.c b/kpdfview.c index 4fa85e940..94b33ff1a 100644 --- a/kpdfview.c +++ b/kpdfview.c @@ -79,7 +79,7 @@ static int docall(lua_State *L, int narg, int clear) } int main(int argc, char **argv) { - int i, err; + int i; if(argc < 2) { fprintf(stderr, "needs config file as first argument.\n"); diff --git a/launchpad/kpdf.ini b/launchpad/kpdf.ini index ab2a1b0d9..53be1fc3f 100755 --- a/launchpad/kpdf.ini +++ b/launchpad/kpdf.ini @@ -1,11 +1,11 @@ [Actions] # start kindlepdfviewer with filebrowser in /mnt/us/documents -P D = !/mnt/us/launchpad/kpdf.sh /mnt/us/documents +P D = !/mnt/us/kindlepdfviewer/kpdf.sh /mnt/us/documents # start kindlepdfviewer with last document -P P = !/mnt/us/launchpad/kpdf.sh +P P = !/mnt/us/kindlepdfviewer/kpdf.sh # start kindlepdfviewer without framework in /mnt/us/documents -P K = !/mnt/us/launchpad/kpdf.sh --framework_stop /mnt/us/documents +P K = !/mnt/us/kindlepdfviewer/kpdf.sh --framework_stop /mnt/us/documents # start kindlepdfviewer without framework on last read document -P L = !/mnt/us/launchpad/kpdf.sh --framework_stop +P L = !/mnt/us/kindlepdfviewer/kpdf.sh --framework_stop # restart amazon framework - when it got irritated P R = !/etc/init.d/framework restart diff --git a/pdf.c b/pdf.c index 780b33dd7..dd0de744b 100644 --- a/pdf.c +++ b/pdf.c @@ -492,9 +492,9 @@ static int getUsedBBox(lua_State *L) { return luaL_error(L, "cannot calculate bbox for page"); } - lua_pushnumber(L, ((double)result.x0)/100); + lua_pushnumber(L, ((double)result.x0)/100); lua_pushnumber(L, ((double)result.y0)/100); - lua_pushnumber(L, ((double)result.x1)/100); + lua_pushnumber(L, ((double)result.x1)/100); lua_pushnumber(L, ((double)result.y1)/100); return 4; @@ -577,6 +577,59 @@ static int cleanCache(lua_State *L) { return 0; } + +static int getPageLinks(lua_State *L) { + fz_link *page_links; + fz_link *link; + + int link_count; + + PdfPage *page = (PdfPage*) luaL_checkudata(L, 1, "pdfpage"); + + page_links = fz_load_links(page->doc->xref, page->page); // page->doc->xref? + + lua_newtable(L); // all links + + link_count = 0; + + for (link = page_links; link; link = link->next) { + lua_newtable(L); // new link + + lua_pushstring(L, "x0"); + lua_pushinteger(L, link->rect.x0); + lua_settable(L, -3); + lua_pushstring(L, "y0"); + lua_pushinteger(L, link->rect.y0); + lua_settable(L, -3); + lua_pushstring(L, "x1"); + lua_pushinteger(L, link->rect.x1); + lua_settable(L, -3); + lua_pushstring(L, "y1"); + lua_pushinteger(L, link->rect.y1); + lua_settable(L, -3); + + if (link->dest.kind == FZ_LINK_URI) { + lua_pushstring(L, "uri"); + lua_pushstring(L, link->dest.ld.uri.uri); + lua_settable(L, -3); + } else if (link->dest.kind == FZ_LINK_GOTO) { + lua_pushstring(L, "page"); + lua_pushinteger(L, link->dest.ld.gotor.page); // FIXME page+1? + lua_settable(L, -3); + } else { + printf("ERROR: unkown link kind: %x", link->dest.kind); + } + + lua_rawseti(L, -2, ++link_count); + } + + //printf("## getPageLinks found %d links in document\n", link_count); + + fz_drop_link(page->doc->context, page_links); + + return 1; +} + static const struct luaL_Reg pdf_func[] = { {"openDocument", openDocument}, {NULL, NULL} @@ -599,6 +652,7 @@ static const struct luaL_Reg pdfpage_meth[] = { {"getSize", getPageSize}, {"getUsedBBox", getUsedBBox}, {"getPageText", getPageText}, + {"getPageLinks", getPageLinks}, {"close", closePage}, {"__gc", closePage}, {"draw", drawPage}, diff --git a/popen-noshell/popen_noshell-buildfix.patch b/popen-noshell/popen_noshell-buildfix.patch new file mode 100644 index 000000000..97c09b881 --- /dev/null +++ b/popen-noshell/popen_noshell-buildfix.patch @@ -0,0 +1,86 @@ +Index: CREDITS +=================================================================== +--- CREDITS (revision 0) ++++ CREDITS (working copy) +@@ -0,0 +1 @@ ++Taken from http://code.google.com/p/popen-noshell/ + +Property changes on: CREDITS +___________________________________________________________________ +Added: svn:keywords +## -0,0 +1 ## ++Id +\ No newline at end of property +Index: Makefile +=================================================================== +--- Makefile (revision 0) ++++ Makefile (working copy) +@@ -0,0 +1,17 @@ ++SRCS=popen_noshell.c ++ ++OBJS:=$(SRCS:%.c=%.o) ++ ++%.o: %.c ++ $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $< ++ ++all: libpopen_noshell.a ++ ++libpopen_noshell.a: $(OBJS) ++ $(AR) rcs $@ $(OBJS) ++ ++clean: ++ rm -rf *.o ++ rm -rf libpopen_noshell.a ++ ++.PHONY: clean + +Property changes on: Makefile +___________________________________________________________________ +Added: svn:keywords +## -0,0 +1 ## ++Id +\ No newline at end of property +Index: popen_noshell.c +=================================================================== +--- popen_noshell.c (revision 8) ++++ popen_noshell.c (working copy) +@@ -16,6 +16,10 @@ + * along with this program. If not, see . + */ + ++#ifndef _GNU_SOURCE ++#define _GNU_SOURCE ++#endif ++ + #include "popen_noshell.h" + #include + #include +@@ -28,10 +32,6 @@ + #include + #include + #include +- +-#ifndef _GNU_SOURCE +-#define _GNU_SOURCE +-#endif + #include + + /* +@@ -249,7 +249,7 @@ + * The above malloc() + align implementation is taken from: + * http://stackoverflow.com/questions/227897/solve-the-memory-alignment-in-c-interview-question-that-stumped-me + */ +- ++ + #ifndef POPEN_NOSHELL_VALGRIND_DEBUG + pid = clone(fn, stack_aligned, CLONE_VM | SIGCHLD, arg); + #else +@@ -358,7 +358,7 @@ + + pclose_arg->fp = fp; + pclose_arg->pid = pid; +- ++ + return fp; // we should never end up here + } + diff --git a/reader.lua b/reader.lua index 8e9e627b2..e8e06ccc5 100755 --- a/reader.lua +++ b/reader.lua @@ -138,6 +138,20 @@ else end +if ARGV[optind] then + if lfs.attributes(ARGV[optind], "mode") == "directory" then + showFileManager(ARGV[optind]) + elseif lfs.attributes(ARGV[optind], "mode") == "file" then + showReader(ARGV[optind], optarg["p"]) + end + UIManager:run() +elseif last_file and lfs.attributes(last_file, "mode") == "file" then + showReader(last_file, optarg["p"]) + UIManager:run() +else + return showusage() +end + -- @TODO dirty workaround, find a way to force native system poll -- screen orientation and upside down mode 09.03 2012 diff --git a/resources/info-aux.png b/resources/info-aux.png new file mode 100644 index 000000000..afee09ee5 Binary files /dev/null and b/resources/info-aux.png differ diff --git a/resources/info-bug.png b/resources/info-bug.png new file mode 100644 index 000000000..990e0466f Binary files /dev/null and b/resources/info-bug.png differ diff --git a/resources/info-confirm.png b/resources/info-confirm.png new file mode 100644 index 000000000..85a6585ed Binary files /dev/null and b/resources/info-confirm.png differ diff --git a/resources/info-error.png b/resources/info-error.png new file mode 100644 index 000000000..97ecdfc37 Binary files /dev/null and b/resources/info-error.png differ diff --git a/resources/info-warn.png b/resources/info-warn.png new file mode 100644 index 000000000..f653634db Binary files /dev/null and b/resources/info-warn.png differ diff --git a/slider_watcher.c b/slider_watcher.c index 6a4e26e15..3d16c06ad 100644 --- a/slider_watcher.c +++ b/slider_watcher.c @@ -16,8 +16,11 @@ along with this program. If not, see . */ -#include +#include "popen-noshell/popen_noshell.h" +#include #include +#include +#include #include #include #include @@ -25,18 +28,19 @@ #include #include #include +#include -#define OUTPUT_SIZE 21 -#define EVENT_PIPE "/tmp/event_slider" #define CODE_IN_SAVER 10000 #define CODE_OUT_SAVER 10001 int main ( int argc, char *argv[] ) { - int fd, ret; + int fd; FILE *fp; - char std_out[OUTPUT_SIZE] = ""; + char std_out[256]; + int status; + struct popen_noshell_pass_to_pclose pclose_arg; struct input_event ev; __u16 key_code = 10000; @@ -51,7 +55,7 @@ main ( int argc, char *argv[] ) /* open npipe for writing */ fd = open(argv[1], O_RDWR | O_NONBLOCK); if(fd < 0) { - printf("Open %s falied: %s\n", argv[1], strerror(errno)); + printf("Open %s failed: %s\n", argv[1], strerror(errno)); exit(EXIT_FAILURE); } @@ -60,15 +64,18 @@ main ( int argc, char *argv[] ) ev.code = key_code; ev.value = 1; - while(1) { - /* listen power slider events */ - memset(std_out, 0, OUTPUT_SIZE); - fp = popen("lipc-wait-event -s 0 com.lab126.powerd goingToScreenSaver,outOfScreenSaver", "r"); - ret = fread(std_out, OUTPUT_SIZE, 1, fp); - pclose(fp); + /* listen power slider events */ + char *argv[] = {"lipc-wait-event", "-m", "-s", "0", "com.lab126.powerd", "goingToScreenSaver,outOfScreenSaver", (char *) NULL}; + + fp = popen_noshell("lipc-wait-event", (const char * const *)chargv, "r", &pclose_arg, 0); + if (!fp) { + err(EXIT_FAILURE, "popen_noshell()"); + } + + while(fgets(std_out, sizeof(std_out)-1, fp)) { + + /* printf("Got line: %s", std_out); */ - /* fill event struct */ - gettimeofday(&ev.time, NULL); if(std_out[0] == 'g') { ev.code = CODE_IN_SAVER; } else if(std_out[0] == 'o') { @@ -77,9 +84,29 @@ main ( int argc, char *argv[] ) printf("Unrecognized event.\n"); exit(EXIT_FAILURE); } + /* fill event struct */ + gettimeofday(&ev.time, NULL); + + /* printf("Send event %d\n", ev.code); */ /* generate event */ - ret = write(fd, &ev, sizeof(struct input_event)); + if(write(fd, &ev, sizeof(struct input_event)) == -1) { + printf("Failed to generate event.\n"); + } + } + + status = pclose_noshell(&pclose_arg); + if (status == -1) { + err(EXIT_FAILURE, "pclose_noshell()"); + } else { + printf("Power slider event listener child exited with status %d.\n", status); + + if WIFEXITED(status) { + printf("Child exited normally with status: %d.\n", WEXITSTATUS(status)); + } + if WIFSIGNALED(status) { + printf("Child terminated by signal: %d.\n", WTERMSIG(status)); + } } close(fd); diff --git a/util.c b/util.c index 6a61d3e22..b12e75851 100644 --- a/util.c +++ b/util.c @@ -43,7 +43,7 @@ static int util_usleep(lua_State *L) { } static int util_df(lua_State *L) { - char *path = luaL_checkstring(L, 1); + const char *path = luaL_checkstring(L, 1); struct statvfs vfs; statvfs(path, &vfs); lua_pushnumber(L, (double)vfs.f_bfree * (double)vfs.f_bsize);