localserv/src/usage.c

73 lines
1.6 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "usage.h"
const char server_callstring[] = "server [-h] [-u] [-a] <path>";
const char server_helpstring[] =
" <path>: filesystem path at which to create server Unix domain socket\n"
" -u, --username: include username in request output\n"
" -a, --auth: run server in auth mode (implies --username)\n"
" -h, --help: show usage message\n";
const char client_callstring[] = "client [-h] <path> [<message>]";
const char client_helpstring[] =
" <path>: filesystem path of target servers socket\n"
" <message>: string to send to server\n"
" -h, --help: show usage message\n";
const char *my_name = NULL;
void set_exe_name(char *argv0) {
my_name = basename(argv0);
if (my_name == NULL) {
my_name = "localserv";
}
}
usage_type usage_context = usage_both;
void set_usage_context(usage_type usage) {
usage_context = usage;
}
void show_usage(int is_error) {
if (my_name == NULL) {
my_name = "localserv";
}
FILE *file = is_error ? stderr : stdout;
if (usage_context == usage_server) {
fprintf(
file,
"usage: %s %s\n\n%s\n",
my_name,
server_callstring,
server_helpstring
);
} else if (usage_context == usage_client) {
fprintf(
file,
"usage: %s %s\n\n%s\n",
my_name,
client_callstring,
client_helpstring
);
} else { // usage_context == usage_both
fprintf(
file,
"usage:\n"
" %s %s\n"
" %s %s\n"
"\n"
" server:\n%s\n"
" client:\n%s",
my_name,
server_callstring,
my_name,
client_callstring,
server_helpstring,
client_helpstring
);
}
}