mirror of https://github.com/ericonr/purr-c.git
Add install target and symlinks.
purr can be symlinked to meow and meowd, in which cases it has special behavior.
This commit is contained in:
parent
e01615adff
commit
d5ce01c91f
|
@ -2,3 +2,4 @@ purr
|
||||||
tests
|
tests
|
||||||
*.o
|
*.o
|
||||||
*.a
|
*.a
|
||||||
|
.gdb_history
|
||||||
|
|
7
makefile
7
makefile
|
@ -1,3 +1,5 @@
|
||||||
|
PREFIX = /usr/local
|
||||||
|
|
||||||
INC = -Iextern
|
INC = -Iextern
|
||||||
OPT = -O2
|
OPT = -O2
|
||||||
WARN = -Wall -Wextra -Werror=implicit
|
WARN = -Wall -Wextra -Werror=implicit
|
||||||
|
@ -33,5 +35,10 @@ $(BASEENCODEOBJS): extern/libbaseencode/common.h extern/libbaseencode/baseencode
|
||||||
$(BASEENCODE): $(BASEENCODEOBJS)
|
$(BASEENCODE): $(BASEENCODEOBJS)
|
||||||
$(AR) r $@ $^
|
$(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:
|
clean:
|
||||||
rm -f $(FINAL) $(OBJS) $(TEST) $(TOBJS) $(LIBS) $(LIBSOBJS)
|
rm -f $(FINAL) $(OBJS) $(TEST) $(TOBJS) $(LIBS) $(LIBSOBJS)
|
||||||
|
|
82
purr.c
82
purr.c
|
@ -1,3 +1,4 @@
|
||||||
|
#define _GNU_SOURCE
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
@ -14,17 +15,33 @@
|
||||||
__attribute__ ((noreturn))
|
__attribute__ ((noreturn))
|
||||||
static void usage(bool fail)
|
static void usage(bool fail)
|
||||||
{
|
{
|
||||||
puts("Usage: purrito [options] <action> [FILE]\n"
|
char *proghelp;
|
||||||
" action: send | recv\n"
|
if (strcmp(program_invocation_short_name, "meow") == 0) {
|
||||||
"Options:\n"
|
proghelp =
|
||||||
" -a <algo>: choose algorithm, none available\n"
|
"Usage: meow [options] <file>\n"
|
||||||
" -u <url>: URL to use for send functionality\n"
|
" send <file> in encrypted format\n";
|
||||||
" -p <port>: port to use for send\n"
|
} else if (strcmp(program_invocation_short_name, "meowd") == 0) {
|
||||||
" -o <output_file>: use file instead of stdout\n"
|
proghelp =
|
||||||
" -n: don't strip HTTP header from response\n"
|
"Usage meowd [options] <url>\n"
|
||||||
" -e: encrypt content\n"
|
" receive encrypted file from <url>\n";
|
||||||
" -d: debug"
|
} else {
|
||||||
" -h: show this dialog"
|
proghelp =
|
||||||
|
"Usage: purr [options] <action> [<file>|<url>]\n"
|
||||||
|
" action: send | recv\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(
|
||||||
|
"%s"
|
||||||
|
"Options:\n"
|
||||||
|
" -a <algo>: choose algorithm, none available\n"
|
||||||
|
" -u <url>: URL to use for send functionality\n"
|
||||||
|
" -p <port>: port to use for send\n"
|
||||||
|
" -o <output_file>: 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);
|
exit(fail? EXIT_FAILURE : EXIT_SUCCESS);
|
||||||
|
@ -34,13 +51,24 @@ int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
int rv = EXIT_SUCCESS;
|
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);
|
usage(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int c;
|
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) {
|
while ((c = getopt(argc, argv, "a:u:p:o:nedh")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a':
|
||||||
|
@ -76,17 +104,21 @@ int main (int argc, char **argv)
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
if (argc < 1) {
|
if (recv || send) {
|
||||||
usage(true);
|
argc++;
|
||||||
}
|
argv--;
|
||||||
|
|
||||||
bool send = false, recv = false;
|
|
||||||
if (strcmp(argv[0], "recv") == 0) {
|
|
||||||
recv = true;
|
|
||||||
} else if (strcmp(argv[0], "send") == 0) {
|
|
||||||
send = true;
|
|
||||||
} else {
|
} 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;
|
struct mmap_file input;
|
||||||
|
@ -123,7 +155,7 @@ int main (int argc, char **argv)
|
||||||
} else if (argc > 2) {
|
} else if (argc > 2) {
|
||||||
usage(true);
|
usage(true);
|
||||||
} else {
|
} else {
|
||||||
fputs("stdin not supported for now!\n", stderr);
|
fputs("stdin not supported for ~now~ meow!\n", stderr);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue