diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | main.c | 14 |
2 files changed, 10 insertions, 6 deletions
@@ -4,9 +4,11 @@ LDLIBS+=-llua5.3 PREFIX?=/usr/local SHARE?=$(PREFIX)/share +PLOP_DEFAULT_HANDLER?=$(SHARE)/plop/default.lua plop: connection.o main.o plop.o stream.o response.o +main.o: CFLAGS+=-DPLOP_DEFAULT_HANDLER=\"$(PLOP_DEFAULT_HANDLER)\" main.o: plop.h plop.o: connection.h plop.h stream.h connection.o: connection.h @@ -11,8 +11,9 @@ static void usage(const char * const name) { dprintf(2, - "Usage: %s [-p PORT] HANDLER\n" - "Starts plop server listening on PORT and serving HANDLER.\n\n" + "Usage: %s [-p PORT] [HANDLER]\n" + "Starts plop server listening on PORT and serving HANDLER.\n" + "HANDLER defaults to '" PLOP_DEFAULT_HANDLER "'.\n\n" " -p\tstart listening on PORT (default: 8080)\n", name); } @@ -43,10 +44,11 @@ int main(int argc, char ** argv) } } - if (optind >= argc) + const char * handler_path = PLOP_DEFAULT_HANDLER; + + if (optind < argc) { - usage(argv[0]); - return 8; + handler_path = argv[optind]; } lua_State * L = plop_initialize_lua(); @@ -56,7 +58,7 @@ int main(int argc, char ** argv) return 9; } - if (LUA_OK != plop_load_handler(L, argv[optind])) + if (LUA_OK != plop_load_handler(L, handler_path)) { return 2; } |