summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--main.c14
2 files changed, 10 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 26bb34c..226323a 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/main.c b/main.c
index 1f932fc..3587c56 100644
--- a/main.c
+++ b/main.c
@@ -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;
}