Merge pull request #361 from houqp/new_ui_code

merge latest changes from master branch
pull/2/merge
Dobrica Pavlinušić 12 years ago
commit 40bdee5c1f

22
.gitignore vendored

@ -5,6 +5,7 @@ lua-*
mupdf-thirdparty.zip mupdf-thirdparty.zip
djvulibre* djvulibre*
kpdfview kpdfview
slider_watcher
*.o *.o
kindlepdfviewer-*.zip kindlepdfviewer-*.zip
@ -12,8 +13,29 @@ kindlepdfviewer-*.zip
/.cproject /.cproject
/.project /.project
/.reader.kpdfview /.reader.kpdfview
/settings.reader.lua
fonts
data
history
screenshots
cr3cache
kpvcrlib/CMakeCache.txt kpvcrlib/CMakeCache.txt
kpvcrlib/CMakeFiles/ kpvcrlib/CMakeFiles/
kpvcrlib/cmake_install.cmake kpvcrlib/cmake_install.cmake
kpvcrlib/Makefile 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

@ -2,7 +2,7 @@
LUADIR=luajit-2.0 LUADIR=luajit-2.0
MUPDFDIR=mupdf MUPDFDIR=mupdf
MUPDFTARGET=build/debug MUPDFTARGET=build/release
MUPDFLIBDIR=$(MUPDFDIR)/$(MUPDFTARGET) MUPDFLIBDIR=$(MUPDFDIR)/$(MUPDFTARGET)
DJVUDIR=djvulibre DJVUDIR=djvulibre
KPVCRLIBDIR=kpvcrlib KPVCRLIBDIR=kpvcrlib
@ -11,28 +11,36 @@ CRENGINEDIR=$(KPVCRLIBDIR)/crengine
FREETYPEDIR=$(MUPDFDIR)/thirdparty/freetype-2.4.10 FREETYPEDIR=$(MUPDFDIR)/thirdparty/freetype-2.4.10
LFSDIR=luafilesystem LFSDIR=luafilesystem
POPENNSDIR=popen-noshell
# must point to directory with *.ttf fonts for crengine # must point to directory with *.ttf fonts for crengine
TTF_FONTS_DIR=$(MUPDFDIR)/fonts TTF_FONTS_DIR=$(MUPDFDIR)/fonts
# set this to your ARM cross compiler: # set this to your ARM cross compiler:
HOST:=arm-none-linux-gnueabi CHOST?=arm-none-linux-gnueabi
CC:=$(HOST)-gcc CC:=$(CHOST)-gcc
CXX:=$(HOST)-g++ CXX:=$(CHOST)-g++
STRIP:=$(HOST)-strip STRIP:=$(CHOST)-strip
AR:=$(CHOST)-ar
ifdef SBOX_UNAME_MACHINE ifdef SBOX_UNAME_MACHINE
CC:=gcc CC:=gcc
CXX:=g++ CXX:=g++
endif endif
HOSTCC:=gcc HOSTCC:=gcc
HOSTCXX:=g++ HOSTCXX:=g++
HOSTAR:=ar
CFLAGS:=-O3 $(SYSROOT)
CXXFLAGS:=-O3 $(SYSROOT) # Base CFLAGS, without arch. We'll need it for luajit, because its Makefiles do some tricky stuff to differentiate HOST/TARGET
LDFLAGS:= $(SYSROOT) BASE_CFLAGS:=-O2 -ffast-math -pipe -fomit-frame-pointer -fno-stack-protector -U_FORTIFY_SOURCE
ARM_CFLAGS:=-march=armv6 # Use this for debugging:
# use this for debugging: #BASE_CFLAGS:=-O0 -g
#CFLAGS:=-O0 -g $(SYSROOT) 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++ DYNAMICLIBSTDCPP:=-lstdc++
ifdef STATICLIBSTDCPP ifdef STATICLIBSTDCPP
@ -46,6 +54,7 @@ endif
ifdef EMULATE_READER ifdef EMULATE_READER
CC:=$(HOSTCC) -g CC:=$(HOSTCC) -g
CXX:=$(HOSTCXX) CXX:=$(HOSTCXX)
AR:=$(HOSTAR)
EMULATE_READER_W?=824 EMULATE_READER_W?=824
EMULATE_READER_H?=1200 EMULATE_READER_H?=1200
EMU_CFLAGS?=$(shell sdl-config --cflags) EMU_CFLAGS?=$(shell sdl-config --cflags)
@ -56,8 +65,11 @@ ifdef EMULATE_READER
ifeq "$(shell uname -s -m)" "Darwin x86_64" ifeq "$(shell uname -s -m)" "Darwin x86_64"
EMU_LDFLAGS += -pagezero_size 10000 -image_base 100000000 EMU_LDFLAGS += -pagezero_size 10000 -image_base 100000000
endif endif
CFLAGS+= $(HOST_ARCH)
CXXFLAGS+= $(HOST_ARCH)
else else
CFLAGS+= $(ARM_CFLAGS) CFLAGS+= $(ARM_ARCH)
CXXFLAGS+= $(ARM_ARCH)
endif endif
# standard includes # standard includes
@ -87,16 +99,20 @@ THIRDPARTYLIBS := $(MUPDFLIBDIR)/libfreetype.a \
LUALIB := $(LUADIR)/src/libluajit.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) \ $(CC) \
$(CFLAGS) \
kpdfview.o \ kpdfview.o \
einkfb.o \ einkfb.o \
pdf.o \ pdf.o \
blitbuffer.o \ blitbuffer.o \
drawcontext.o \ drawcontext.o \
input.o \ input.o \
$(POPENNSLIB) \
util.o \ util.o \
ft.o \ ft.o \
lfs.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 \ cre.o \
$(CRENGINELIBS) \ $(CRENGINELIBS) \
$(STATICLIBSTDCPP) \ $(STATICLIBSTDCPP) \
-o kpdfview -lm -ldl -lpthread $(EMU_LDFLAGS) $(DYNAMICLIBSTDCPP) $(LDFLAGS) \
-o $@ -lm -ldl -lpthread $(EMU_LDFLAGS) $(DYNAMICLIBSTDCPP)
slider_watcher: slider_watcher.c slider_watcher.o: %.o: %.c
$(CC) $(CFLAGS) $< -o $@ $(CC) -c $(CFLAGS) $< -o $@
slider_watcher: slider_watcher.o $(POPENNSLIB)
$(CC) $(CFLAGS) slider_watcher.o $(POPENNSLIB) -o $@
ft.o: %.o: %.c $(THIRDPARTYLIBS) ft.o: %.o: %.c $(THIRDPARTYLIBS)
$(CC) -c $(KPDFREADER_CFLAGS) -I$(FREETYPEDIR)/include -I$(MUPDFDIR)/fitz $< -o $@ $(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 $@ $(CC) -c $(KPDFREADER_CFLAGS) -I$(DJVUDIR)/ $< -o $@
cre.o: %.o: %.cpp 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 lfs.o: $(LFSDIR)/src/lfs.c
$(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@ $(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@
fetchthirdparty: fetchthirdparty:
-rm -Rf mupdf/thirdparty rm -rf mupdf/thirdparty
test -d mupdf && (cd mupdf; git checkout .) || echo warn: mupdf folder not found 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 test -d $(LUADIR) && (cd $(LUADIR); git checkout .) || echo warn: $(LUADIR) folder not found
git submodule init git submodule init
@ -156,73 +176,81 @@ fetchthirdparty:
patch -N -p0 < ../../../kpvcrlib/jpeg_decompress_struct_size.patch patch -N -p0 < ../../../kpvcrlib/jpeg_decompress_struct_size.patch
# MuPDF patch: use external fonts # MuPDF patch: use external fonts
cd mupdf && patch -N -p1 < ../mupdf.patch 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: clean:
-rm -f *.o kpdfview slider_watcher rm -f *.o kpdfview slider_watcher
cleanthirdparty: cleanthirdparty:
-make -C $(LUADIR) clean $(MAKE) -C $(LUADIR) CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CROSS="$(CHOST)-" clean
-make -C $(MUPDFDIR) clean $(MAKE) -C $(MUPDFDIR) build="release" clean
-make -C $(CRENGINEDIR)/thirdparty/antiword 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/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)/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: crengine 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: kpvcrlib folder not found test -d $(KPVCRLIBDIR) && ($(MAKE) -C $(KPVCRLIBDIR) clean) || echo warn: chmlib folder not found
-rm -rf $(DJVUDIR)/build rm -rf $(DJVUDIR)/build
-rm -f $(MUPDFDIR)/fontdump.host rm -f $(MUPDFDIR)/fontdump.host
-rm -f $(MUPDFDIR)/cmapdump.host rm -f $(MUPDFDIR)/cmapdump.host
$(MAKE) -C $(POPENNSDIR) clean
$(MUPDFDIR)/fontdump.host: $(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 cp -a $(MUPDFLIBDIR)/fontdump $(MUPDFDIR)/fontdump.host
make -C mupdf clean $(MAKE) -C mupdf clean
$(MUPDFDIR)/cmapdump.host: $(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 cp -a $(MUPDFLIBDIR)/cmapdump $(MUPDFDIR)/cmapdump.host
make -C mupdf clean $(MAKE) -C mupdf clean
$(MUPDFLIBS) $(THIRDPARTYLIBS): $(MUPDFDIR)/cmapdump.host $(MUPDFDIR)/fontdump.host $(MUPDFLIBS) $(THIRDPARTYLIBS): $(MUPDFDIR)/cmapdump.host $(MUPDFDIR)/fontdump.host
# build only thirdparty libs, libfitz and pdf utils, which will care for libmupdf.a being built # 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): $(DJVULIBS):
-mkdir $(DJVUDIR)/build mkdir -p $(DJVUDIR)/build
ifdef EMULATE_READER 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 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 endif
make -C $(DJVUDIR)/build $(MAKE) -C $(DJVUDIR)/build
$(CRENGINELIBS): $(CRENGINELIBS):
cd $(KPVCRLIBDIR) && rm -rf CMakeCache.txt CMakeFiles && \ cd $(KPVCRLIBDIR) && rm -rf CMakeCache.txt CMakeFiles && \
CFLAGS="$(CFLAGS)" CC="$(CC)" CXX="$(CXX)" cmake . && \ CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS)" cmake . && \
make $(MAKE)
$(LUALIB): $(LUALIB):
ifdef EMULATE_READER ifdef EMULATE_READER
make -C $(LUADIR) $(MAKE) -C $(LUADIR)
else 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 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 INSTALL_DIR=kindlepdfviewer
LUA_FILES=reader.lua LUA_FILES=reader.lua
VERSION?=$(shell git rev-parse --short HEAD) VERSION?=$(shell git describe HEAD)
customupdate: all customupdate: all
# ensure that build binary is for ARM # ensure that build binary is for ARM
file kpdfview | grep ARM || exit 1 file kpdfview | grep ARM || exit 1
$(STRIP) --strip-unneeded kpdfview $(STRIP) --strip-unneeded kpdfview
-rm kindlepdfviewer-$(VERSION).zip rm -f kindlepdfviewer-$(VERSION).zip
rm -Rf $(INSTALL_DIR) rm -rf $(INSTALL_DIR)
mkdir -p $(INSTALL_DIR)/{history,screenshots} mkdir -p $(INSTALL_DIR)/{history,screenshots}
echo $(VERSION) > $(INSTALL_DIR)/git-rev 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 mkdir $(INSTALL_DIR)/data
cp -rpL data/*.css $(INSTALL_DIR)/data cp -rpL data/*.css $(INSTALL_DIR)/data
cp -rpL fonts $(INSTALL_DIR) cp -rpL fonts $(INSTALL_DIR)
@ -230,5 +258,5 @@ customupdate: all
cp -rpL frontend $(INSTALL_DIR) cp -rpL frontend $(INSTALL_DIR)
mkdir $(INSTALL_DIR)/fonts/host mkdir $(INSTALL_DIR)/fonts/host
zip -9 -r kindlepdfviewer-$(VERSION).zip $(INSTALL_DIR) launchpad/ kite/ 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" @echo "copy kindlepdfviewer-$(VERSION).zip to /mnt/us/customupdates and install with shift+shift+I"

@ -25,7 +25,7 @@ Follow these steps:
* install LuaJit sources into subfolder "luajit-2.0" * install LuaJit sources into subfolder "luajit-2.0"
* automatically fetch thirdparty sources with Makefile: * 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`. * run `make fetchthirdparty`.
* adapt Makefile to your needs * adapt Makefile to your needs

@ -15,7 +15,11 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "popen-noshell/popen_noshell.h"
#include <err.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
@ -29,9 +33,7 @@
#include "input.h" #include "input.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <signal.h>
#define OUTPUT_SIZE 21
#define CODE_IN_SAVER 10000 #define CODE_IN_SAVER 10000
#define CODE_OUT_SAVER 10001 #define CODE_OUT_SAVER 10001
#define CODE_USB_PLUG_IN 10010 #define CODE_USB_PLUG_IN 10010
@ -41,7 +43,17 @@
#define NUM_FDS 4 #define NUM_FDS 4
int inputfds[4] = { -1, -1, -1, -1 }; 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 findFreeFdSlot() {
int i; 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); 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 */ /* special case: the power slider */
int pipefd[2]; int pipefd[2];
int childpid; int childpid;
@ -73,10 +85,13 @@ static int openInputDevice(lua_State *L) {
return luaL_error(L, "cannot fork() slider event listener"); return luaL_error(L, "cannot fork() slider event listener");
} }
if(childpid == 0) { if(childpid == 0) {
// We send a SIGTERM to this child on exit, trap it to kill lipc properly.
signal(SIGTERM, slider_handler);
FILE *fp; FILE *fp;
char std_out[OUTPUT_SIZE] = ""; char std_out[256];
int status;
struct input_event ev; struct input_event ev;
int ret;
__u16 key_code = 10000; __u16 key_code = 10000;
close(pipefd[0]); close(pipefd[0]);
@ -85,17 +100,22 @@ static int openInputDevice(lua_State *L) {
ev.code = key_code; ev.code = key_code;
ev.value = 1; ev.value = 1;
/* listen power slider events */ /* listen power slider events (listen for ever for multiple events) */
while(1) { char *argv[] = {"lipc-wait-event", "-m", "-s", "0", "com.lab126.powerd", "goingToScreenSaver,outOfScreenSaver,charging,notCharging", (char *) NULL};
fp = popen("exec lipc-wait-event com.lab126.powerd goingToScreenSaver,outOfScreenSaver,charging,notCharging", "r"); /* @TODO 07.06 2012 (houqp)
/* @TODO 07.06 2012 (houqp) * plugin and out event can only be watched by:
* plugin and out event can only be watched by: lipc-wait-event com.lab126.hal usbPlugOut,usbPlugIn
lipc-wait-event com.lab126.hal usbPlugOut,usbPlugIn */
*/
if(fgets(std_out, OUTPUT_SIZE, fp) == NULL) { fp = popen_noshell("lipc-wait-event", (const char * const *)argv, "r", &pclose_arg, 0);
break; if (!fp) {
} err(EXIT_FAILURE, "popen_noshell()");
pclose(fp); }
/* Flush to get rid of buffering issues? */
fflush(fp);
while(fgets(std_out, sizeof(std_out)-1, fp)) {
if(std_out[0] == 'g') { if(std_out[0] == 'g') {
ev.code = CODE_IN_SAVER; ev.code = CODE_IN_SAVER;
} else if(std_out[0] == 'o') { } else if(std_out[0] == 'o') {
@ -116,10 +136,26 @@ static int openInputDevice(lua_State *L) {
/* generate event */ /* generate event */
if(write(pipefd[1], &ev, sizeof(struct input_event)) == -1) { 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 { } else {
close(pipefd[1]); close(pipefd[1]);
inputfds[fd] = pipefd[0]; inputfds[fd] = pipefd[0];
@ -138,6 +174,7 @@ static int openInputDevice(lua_State *L) {
if(SDL_Init(SDL_INIT_VIDEO) < 0) { if(SDL_Init(SDL_INIT_VIDEO) < 0) {
return luaL_error(L, "cannot initialize SDL."); return luaL_error(L, "cannot initialize SDL.");
} }
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
return 0; return 0;
#endif #endif
} }
@ -148,7 +185,7 @@ static int closeInputDevices(lua_State *L) {
for(i=0; i<NUM_FDS; i++) { for(i=0; i<NUM_FDS; i++) {
if(inputfds[i] != -1) { if(inputfds[i] != -1) {
ioctl(inputfds[i], EVIOCGRAB, 0); ioctl(inputfds[i], EVIOCGRAB, 0);
close(i); close(inputfds[i]);
} }
} }
if(slider_pid != -1) { if(slider_pid != -1) {
@ -164,15 +201,14 @@ static int closeInputDevices(lua_State *L) {
static int waitForInput(lua_State *L) { static int waitForInput(lua_State *L) {
int usecs = luaL_optint(L, 1, -1); // we check for <0 later int usecs = luaL_optint(L, 1, -1); // we check for <0 later
int secs = luaL_optint(L, 2, 0);
#ifndef EMULATE_READER #ifndef EMULATE_READER
fd_set fds; fd_set fds;
struct timeval timeout; struct timeval timeout;
int i, num, nfds; int i, num, nfds;
timeout.tv_sec = secs; timeout.tv_sec = (usecs/1000000);
timeout.tv_usec = usecs; timeout.tv_usec = (usecs%1000000);
nfds = 0; nfds = 0;
@ -222,11 +258,11 @@ static int waitForInput(lua_State *L) {
if (usecs < 0) if (usecs < 0)
SDL_WaitEvent(&event); SDL_WaitEvent(&event);
else { else {
while (SDL_GetTicks()-ticks <= secs * 1000 + usecs/1000) { while (SDL_GetTicks()-ticks <= usecs/1000) {
if (SDL_PollEvent(&event)) break; if (SDL_PollEvent(&event)) break;
SDL_Delay(10); SDL_Delay(10);
} }
if (SDL_GetTicks()-ticks > secs * 1000 + usecs/1000) if (SDL_GetTicks()-ticks > usecs/1000)
return luaL_error(L, "Waiting for input failed: timeout\n"); return luaL_error(L, "Waiting for input failed: timeout\n");
} }
switch(event.type) { switch(event.type) {

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
/mnt/us/launchpad/kpdf.sh /mnt/us/kindlepdfviewer/kpdf.sh

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
/mnt/us/launchpad/kpdf.sh /mnt/us/documents /mnt/us/kindlepdfviewer/kpdf.sh /mnt/us/documents

@ -22,7 +22,7 @@ fi
killall -stop cvm killall -stop cvm
# finally call reader # 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 # unmount system fonts
if grep /mnt/us/kindlepdfviewer/fonts/host /proc/mounts; then if grep /mnt/us/kindlepdfviewer/fonts/host /proc/mounts; then
@ -31,7 +31,3 @@ fi
# always try to continue cvm # always try to continue cvm
killall -cont cvm || /etc/init.d/framework start killall -cont cvm || /etc/init.d/framework start
# cleanup hanging process
killall lipc-wait-event

@ -79,7 +79,7 @@ static int docall(lua_State *L, int narg, int clear)
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
int i, err; int i;
if(argc < 2) { if(argc < 2) {
fprintf(stderr, "needs config file as first argument.\n"); fprintf(stderr, "needs config file as first argument.\n");

@ -1,11 +1,11 @@
[Actions] [Actions]
# start kindlepdfviewer with filebrowser in /mnt/us/documents # 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 # 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 # 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 # 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 # restart amazon framework - when it got irritated
P R = !/etc/init.d/framework restart P R = !/etc/init.d/framework restart

58
pdf.c

@ -492,9 +492,9 @@ static int getUsedBBox(lua_State *L) {
return luaL_error(L, "cannot calculate bbox for page"); 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.y0)/100);
lua_pushnumber(L, ((double)result.x1)/100); lua_pushnumber(L, ((double)result.x1)/100);
lua_pushnumber(L, ((double)result.y1)/100); lua_pushnumber(L, ((double)result.y1)/100);
return 4; return 4;
@ -577,6 +577,59 @@ static int cleanCache(lua_State *L) {
return 0; 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[] = { static const struct luaL_Reg pdf_func[] = {
{"openDocument", openDocument}, {"openDocument", openDocument},
{NULL, NULL} {NULL, NULL}
@ -599,6 +652,7 @@ static const struct luaL_Reg pdfpage_meth[] = {
{"getSize", getPageSize}, {"getSize", getPageSize},
{"getUsedBBox", getUsedBBox}, {"getUsedBBox", getUsedBBox},
{"getPageText", getPageText}, {"getPageText", getPageText},
{"getPageLinks", getPageLinks},
{"close", closePage}, {"close", closePage},
{"__gc", closePage}, {"__gc", closePage},
{"draw", drawPage}, {"draw", drawPage},

@ -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 <http://www.gnu.org/licenses>.
*/
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
#include "popen_noshell.h"
#include <errno.h>
#include <unistd.h>
@@ -28,10 +32,6 @@
#include <sys/wait.h>
#include <stdlib.h>
#include <inttypes.h>
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
#include <sched.h>
/*
@@ -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
}

@ -138,6 +138,20 @@ else
end 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 -- @TODO dirty workaround, find a way to force native system poll
-- screen orientation and upside down mode 09.03 2012 -- screen orientation and upside down mode 09.03 2012

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 950 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 B

@ -16,8 +16,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdlib.h> #include "popen-noshell/popen_noshell.h"
#include <err.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
@ -25,18 +28,19 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <errno.h> #include <errno.h>
#include <sys/wait.h>
#define OUTPUT_SIZE 21
#define EVENT_PIPE "/tmp/event_slider"
#define CODE_IN_SAVER 10000 #define CODE_IN_SAVER 10000
#define CODE_OUT_SAVER 10001 #define CODE_OUT_SAVER 10001
int int
main ( int argc, char *argv[] ) main ( int argc, char *argv[] )
{ {
int fd, ret; int fd;
FILE *fp; 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; struct input_event ev;
__u16 key_code = 10000; __u16 key_code = 10000;
@ -51,7 +55,7 @@ main ( int argc, char *argv[] )
/* open npipe for writing */ /* open npipe for writing */
fd = open(argv[1], O_RDWR | O_NONBLOCK); fd = open(argv[1], O_RDWR | O_NONBLOCK);
if(fd < 0) { 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); exit(EXIT_FAILURE);
} }
@ -60,15 +64,18 @@ main ( int argc, char *argv[] )
ev.code = key_code; ev.code = key_code;
ev.value = 1; ev.value = 1;
while(1) { /* listen power slider events */
/* listen power slider events */ char *argv[] = {"lipc-wait-event", "-m", "-s", "0", "com.lab126.powerd", "goingToScreenSaver,outOfScreenSaver", (char *) NULL};
memset(std_out, 0, OUTPUT_SIZE);
fp = popen("lipc-wait-event -s 0 com.lab126.powerd goingToScreenSaver,outOfScreenSaver", "r"); fp = popen_noshell("lipc-wait-event", (const char * const *)chargv, "r", &pclose_arg, 0);
ret = fread(std_out, OUTPUT_SIZE, 1, fp); if (!fp) {
pclose(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') { if(std_out[0] == 'g') {
ev.code = CODE_IN_SAVER; ev.code = CODE_IN_SAVER;
} else if(std_out[0] == 'o') { } else if(std_out[0] == 'o') {
@ -77,9 +84,29 @@ main ( int argc, char *argv[] )
printf("Unrecognized event.\n"); printf("Unrecognized event.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* fill event struct */
gettimeofday(&ev.time, NULL);
/* printf("Send event %d\n", ev.code); */
/* generate event */ /* 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); close(fd);

@ -43,7 +43,7 @@ static int util_usleep(lua_State *L) {
} }
static int util_df(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; struct statvfs vfs;
statvfs(path, &vfs); statvfs(path, &vfs);
lua_pushnumber(L, (double)vfs.f_bfree * (double)vfs.f_bsize); lua_pushnumber(L, (double)vfs.f_bfree * (double)vfs.f_bsize);

Loading…
Cancel
Save