Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions Client/ydotool.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@

#include <errno.h>
#include <stdio.h>
#include <getopt.h>

#include <string.h>

#ifndef VERSION
#define VERSION "unknown"
#endif

struct tool_def {
char name[16];
void *ptr;
Expand Down Expand Up @@ -81,7 +86,10 @@ static const struct tool_def tool_list[] = {
};

static void show_help() {
puts("Usage: ydotool <cmd> <args>\n"
puts("Usage: ydotool [OPTION] <cmd> <args>\n"
"Options:\n"
" -h, --help Display this help and exit\n"
" -V, --version Show version information\n"
"Available commands:");

int tool_count = sizeof(tool_list) / sizeof(struct tool_def);
Expand All @@ -93,6 +101,11 @@ static void show_help() {
puts("Use environment variable YDOTOOL_SOCKET to specify daemon socket.");
}

static void show_version() {
puts("ydotool version(or hash): ");
puts(VERSION);
}

void uinput_emit(uint16_t type, uint16_t code, int32_t val, bool syn_report) {
struct input_event ie = {
.type = type,
Expand All @@ -112,11 +125,21 @@ void uinput_emit(uint16_t type, uint16_t code, int32_t val, bool syn_report) {
}

int main(int argc, char **argv) {
if (argc < 2 || strncmp(argv[1], "-h", 2) == 0 || strncmp(argv[1], "--h", 3) == 0 || strcmp(argv[1], "help") == 0) {

if (argc < 2) {
puts("ydotool: Missing arguments\n"
"Run 'ydotool --help' if you want a command list\n");
exit(0);
}
else if (strncmp(argv[1], "-h", 2) == 0 || strncmp(argv[1], "--help", 6) == 0 ) {
show_help();
return 0;
exit(0);
}

else if (strncmp(argv[1], "-V", 2) == 0 || strncmp(argv[1], "--version", 9) == 0 ) {
show_version();
exit(0);
}

int (*tool_main)(int argc, char **argv) = NULL;

int tool_count = sizeof(tool_list) / sizeof(struct tool_def);
Expand All @@ -129,7 +152,7 @@ int main(int argc, char **argv) {

if (!tool_main) {
printf("ydotool: Unknown command: %s\n"
"Run 'ydotool help' if you want a command list\n", argv[1]);
"Run 'ydotool --help' if you want a command list\n", argv[1]);
return 1;
}

Expand Down
1 change: 1 addition & 0 deletions Daemon/ydotoold.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static void show_help() {
}

static void show_version() {
puts("ydotoold version(or hash): ");
puts(VERSION);
}

Expand Down