summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-02-24 23:05:00 +0100
committerAki <please@ignore.pl>2021-02-24 23:05:00 +0100
commitffc14c05b5260166050397cfa50bb88299febea0 (patch)
tree1db69ffc70154062935d1e86fa66c66fdbf08835
parent5363bb572b05d0ae136c8db5fc8d9370ecff1d1d (diff)
downloadplop-ffc14c05b5260166050397cfa50bb88299febea0.zip
plop-ffc14c05b5260166050397cfa50bb88299febea0.tar.gz
plop-ffc14c05b5260166050397cfa50bb88299febea0.tar.bz2
Added default HANDLER argument
-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;
}