From d5ce01c91f8cedb5706225b20f76dfb625d9c7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Rolim?= Date: Mon, 14 Sep 2020 01:16:14 -0300 Subject: [PATCH] Add install target and symlinks. purr can be symlinked to meow and meowd, in which cases it has special behavior. --- .gitignore | 1 + makefile | 7 +++++ purr.c | 82 +++++++++++++++++++++++++++++++++++++----------------- 3 files changed, 65 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 068ff5c..13398ec 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ purr tests *.o *.a +.gdb_history diff --git a/makefile b/makefile index 5166f03..4977fa2 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,5 @@ +PREFIX = /usr/local + INC = -Iextern OPT = -O2 WARN = -Wall -Wextra -Werror=implicit @@ -33,5 +35,10 @@ $(BASEENCODEOBJS): extern/libbaseencode/common.h extern/libbaseencode/baseencode $(BASEENCODE): $(BASEENCODEOBJS) $(AR) r $@ $^ +install: $(FINAL) + install -Dm755 purr $(DESTDIR)$(PREFIX)/bin + ln -sf purr $(DESTDIR)$(PREFIX)/bin/meow + ln -sf purr $(DESTDIR)$(PREFIX)/bin/meowd + clean: rm -f $(FINAL) $(OBJS) $(TEST) $(TOBJS) $(LIBS) $(LIBSOBJS) diff --git a/purr.c b/purr.c index c0aceb6..9113cfb 100644 --- a/purr.c +++ b/purr.c @@ -1,3 +1,4 @@ +#define _GNU_SOURCE #include #include #include @@ -14,17 +15,33 @@ __attribute__ ((noreturn)) static void usage(bool fail) { - puts("Usage: purrito [options] [FILE]\n" - " action: send | recv\n" - "Options:\n" - " -a : choose algorithm, none available\n" - " -u : URL to use for send functionality\n" - " -p : port to use for send\n" - " -o : use file instead of stdout\n" - " -n: don't strip HTTP header from response\n" - " -e: encrypt content\n" - " -d: debug" - " -h: show this dialog" + char *proghelp; + if (strcmp(program_invocation_short_name, "meow") == 0) { + proghelp = + "Usage: meow [options] \n" + " send in encrypted format\n"; + } else if (strcmp(program_invocation_short_name, "meowd") == 0) { + proghelp = + "Usage meowd [options] \n" + " receive encrypted file from \n"; + } else { + proghelp = + "Usage: purr [options] [|]\n" + " action: send | recv\n"; + } + + printf( + "%s" + "Options:\n" + " -a : choose algorithm, none available\n" + " -u : URL to use for send functionality\n" + " -p : port to use for send\n" + " -o : use file instead of stdout\n" + " -n: don't strip HTTP header from response\n" + " -e: encrypt content\n" + " -d: debug" + " -h: show this dialog", + proghelp ); exit(fail? EXIT_FAILURE : EXIT_SUCCESS); @@ -34,13 +51,24 @@ int main (int argc, char **argv) { int rv = EXIT_SUCCESS; - if (argc < 2) { + char *algo = NULL, *url_opt = NULL, *port_opt = NULL, *output_file = NULL; + bool no_strip = false, encrypt = false, debug = false; + + bool send = false, recv = false; + + if (strcmp(program_invocation_short_name, "meow") == 0) { + // encrypted send mode + send = true; + encrypt = true; + } else if (strcmp(program_invocation_short_name, "meowd") == 0) { + // encrypted recv mode + recv = true; + encrypt = true; + } else if (argc < 2) { usage(true); } int c; - char *algo = NULL, *url_opt = NULL, *port_opt = NULL, *output_file = NULL; - bool no_strip = false, encrypt = false, debug = false; while ((c = getopt(argc, argv, "a:u:p:o:nedh")) != -1) { switch (c) { case 'a': @@ -76,17 +104,21 @@ int main (int argc, char **argv) argc -= optind; argv += optind; - if (argc < 1) { - usage(true); - } - - bool send = false, recv = false; - if (strcmp(argv[0], "recv") == 0) { - recv = true; - } else if (strcmp(argv[0], "send") == 0) { - send = true; + if (recv || send) { + argc++; + argv--; } else { - usage(true); + if (argc < 1) { + usage(true); + } + + if (strcmp(argv[0], "recv") == 0) { + recv = true; + } else if (strcmp(argv[0], "send") == 0) { + send = true; + } else { + usage(true); + } } struct mmap_file input; @@ -123,7 +155,7 @@ int main (int argc, char **argv) } else if (argc > 2) { usage(true); } else { - fputs("stdin not supported for now!\n", stderr); + fputs("stdin not supported for ~now~ meow!\n", stderr); exit(EXIT_FAILURE); }