beans

simple pastebin server
git clone git://git.bitsmanent.org/beans
Log | Files | Refs | LICENSE

commit 17f59e2e74f0937906fa79bf33185567658dd369
parent 53623d8cb7d97e3adc08f7f65a92b940dc2fa3e2
Author: Claudio Alessi <smoppy@gmail.com>
Date:   Tue,  8 Jan 2019 23:50:34 +0100

Add argv support.

Diffstat:
Aarg.h | 41+++++++++++++++++++++++++++++++++++++++++
Mbeans.c | 9+++++++++
2 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/arg.h b/arg.h @@ -0,0 +1,41 @@ +/* + * Copy me if you can. + * by 20h + */ + +#ifndef __ARG_H__ +#define __ARG_H__ + +extern char *argv0; + +#define USED(x) ((void)(x)) + +#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ + argv[0] && argv[0][1]\ + && argv[0][0] == '-';\ + argc--, argv++) {\ + char _argc;\ + char **_argv;\ + if (argv[0][1] == '-' && argv[0][2] == '\0') {\ + argv++;\ + argc--;\ + break;\ + }\ + for (argv[0]++, _argv = argv; argv[0][0];\ + argv[0]++) {\ + if (_argv != argv)\ + break;\ + _argc = argv[0][0];\ + switch (_argc) + +#define ARGEND }\ + USED(_argc);\ + }\ + USED(argv);\ + USED(argc); + +#define EARGF(x) ((argv[1] == NULL)? ((x), abort(), (char *)0) :\ + (argc--, argv++, argv[0])) + +#endif + diff --git a/beans.c b/beans.c @@ -10,10 +10,15 @@ #include <sys/types.h> #include <unistd.h> +#include "arg.h" + #define PORT "2023" #define BACKLOG 32 /* XXX What's a reasonable value? */ #define BASEURI "https://paste.bitmanent.org/p" +char *argv0; + +/* function implementations */ void die(const char *errstr, ...) { va_list ap; @@ -99,6 +104,10 @@ main(int argc, char *argv[]) { int sd, csd, len, tmpsd; char tmpfn[64] = {0}, *buf, *p; + ARGBEGIN { + case 'v': die("beans-"VERSION"\n"); + } ARGEND + sd = bindon(PORT); size = sizeof conn; while(1) {