From f54f69df7a96b5189fec805df0a4fe886056df1b Mon Sep 17 00:00:00 2001 From: HACKER3000 Date: Mon, 25 Apr 2022 20:30:54 +0200 Subject: [PATCH 1/6] add cmdline args to pixelnuke (untested) --- pixelnuke/pixelnuke.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pixelnuke/pixelnuke.c b/pixelnuke/pixelnuke.c index d879328..ea0c80e 100644 --- a/pixelnuke/pixelnuke.c +++ b/pixelnuke/pixelnuke.c @@ -183,13 +183,35 @@ void px_on_window_close() { net_stop(); } +void args_parse_and_act(int argc, char **argv) { + for (int arg = 1; arg < argc; ++arg) { + switch (argv[arg][0]) { //compare first char of argument + case 'H': + printf("==pixelnuke commandline arguments==\nH\tshows this help\nF[X]\n starts pixelflut in fullscreen on monitor X\n \tonly numbers 0 to 9. defaults to monitor 0\n"); + break; + case 'F': + ; //funny C quirk + int target_fs_disp = 0; + if (argv[arg][1] != 0) { //if not null + int possible_num = argv[arg][1] - '0'; //convert to number if in range 0-9 + if (possible_num >= 0 && possible_num <= 9) { //check if range fits + target_fs_disp = possible_num; + } + } + canvas_fullscreen(target_fs_disp); //fullscreen pxnuke on the target screen + break; + } + } +} + int main(int argc, char **argv) { canvas_setcb_key(&px_on_key); canvas_setcb_resize(&px_on_resize); canvas_start(1024, &px_on_window_close); + args_parse_and_act(argc, argv); + net_start(1337, &px_on_connect, &px_on_read, &px_on_close); return 0; } - From 356f66ebf62dad3091ea67ba245bfe0d79e7b1a8 Mon Sep 17 00:00:00 2001 From: HACKER3000 Date: Mon, 25 Apr 2022 20:37:12 +0200 Subject: [PATCH 2/6] debug output added --- pixelnuke/pixelnuke.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pixelnuke/pixelnuke.c b/pixelnuke/pixelnuke.c index ea0c80e..1e0a797 100644 --- a/pixelnuke/pixelnuke.c +++ b/pixelnuke/pixelnuke.c @@ -190,7 +190,7 @@ void args_parse_and_act(int argc, char **argv) { printf("==pixelnuke commandline arguments==\nH\tshows this help\nF[X]\n starts pixelflut in fullscreen on monitor X\n \tonly numbers 0 to 9. defaults to monitor 0\n"); break; case 'F': - ; //funny C quirk + ; //funny C quirk not allowing lables before declarations int target_fs_disp = 0; if (argv[arg][1] != 0) { //if not null int possible_num = argv[arg][1] - '0'; //convert to number if in range 0-9 @@ -198,6 +198,7 @@ void args_parse_and_act(int argc, char **argv) { target_fs_disp = possible_num; } } + printf("Fullscreening on display %d due to cmdline arg\n", target_fs_disp); canvas_fullscreen(target_fs_disp); //fullscreen pxnuke on the target screen break; } From cb60d0589717f763c3d8a27c6ab967627f3981a7 Mon Sep 17 00:00:00 2001 From: HACKER3000 Date: Mon, 25 Apr 2022 20:46:08 +0200 Subject: [PATCH 3/6] microfix help formatting --- pixelnuke/pixelnuke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pixelnuke/pixelnuke.c b/pixelnuke/pixelnuke.c index 1e0a797..21e47ef 100644 --- a/pixelnuke/pixelnuke.c +++ b/pixelnuke/pixelnuke.c @@ -187,7 +187,7 @@ void args_parse_and_act(int argc, char **argv) { for (int arg = 1; arg < argc; ++arg) { switch (argv[arg][0]) { //compare first char of argument case 'H': - printf("==pixelnuke commandline arguments==\nH\tshows this help\nF[X]\n starts pixelflut in fullscreen on monitor X\n \tonly numbers 0 to 9. defaults to monitor 0\n"); + printf("==pixelnuke commandline arguments==\nH\tshows this help\nF[X] starts pixelflut in fullscreen on monitor X\n\tonly numbers 0 to 9. defaults to monitor 0\n"); break; case 'F': ; //funny C quirk not allowing lables before declarations From 9a4fe177f348f20a786dd33ec54576b112688287 Mon Sep 17 00:00:00 2001 From: HACKER3000 Date: Mon, 25 Apr 2022 21:06:18 +0200 Subject: [PATCH 4/6] added args in README.md --- README.md | 5 +++++ pixelnuke/pixelnuke.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c549c02..f480c1e 100755 --- a/README.md +++ b/README.md @@ -67,6 +67,11 @@ Server written in C, based on libevent2, OpenGL, GLFW and pthreads. It won't get make ./pixelnuke +Commandline Arguments: + +* `H`: Show help for commandline arguments +* `F[screen_id]`: Start fullscreened. You can additionally specify the fullscreen monitor by adding a screen id from 0 to 9 after the F + Keyboard controls: * `F11`: Toggle between fullscreen and windowed mode diff --git a/pixelnuke/pixelnuke.c b/pixelnuke/pixelnuke.c index 21e47ef..b5eb533 100644 --- a/pixelnuke/pixelnuke.c +++ b/pixelnuke/pixelnuke.c @@ -187,7 +187,7 @@ void args_parse_and_act(int argc, char **argv) { for (int arg = 1; arg < argc; ++arg) { switch (argv[arg][0]) { //compare first char of argument case 'H': - printf("==pixelnuke commandline arguments==\nH\tshows this help\nF[X] starts pixelflut in fullscreen on monitor X\n\tonly numbers 0 to 9. defaults to monitor 0\n"); + printf("==pixelnuke commandline arguments==\nH\tshows this help\nF[screen_id]\tStart fullscreened. You can additionally specify the fullscreen monitor\n\tby adding a screen id from 0 to 9 after the F, the default is 0.\n"); break; case 'F': ; //funny C quirk not allowing lables before declarations From 3e20878572494a3176440ad9676c2db9d0fb131f Mon Sep 17 00:00:00 2001 From: HACKER3000 Date: Mon, 25 Apr 2022 21:10:23 +0200 Subject: [PATCH 5/6] quit after help --- pixelnuke/pixelnuke.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pixelnuke/pixelnuke.c b/pixelnuke/pixelnuke.c index b5eb533..683da46 100644 --- a/pixelnuke/pixelnuke.c +++ b/pixelnuke/pixelnuke.c @@ -183,12 +183,12 @@ void px_on_window_close() { net_stop(); } -void args_parse_and_act(int argc, char **argv) { +uint8_t args_parse_and_act(int argc, char **argv) { for (int arg = 1; arg < argc; ++arg) { switch (argv[arg][0]) { //compare first char of argument case 'H': - printf("==pixelnuke commandline arguments==\nH\tshows this help\nF[screen_id]\tStart fullscreened. You can additionally specify the fullscreen monitor\n\tby adding a screen id from 0 to 9 after the F, the default is 0.\n"); - break; + printf("==pixelnuke commandline arguments==\nH\t\tshows this help\nF[screen_id]\t\tStart fullscreened. You can additionally specify the fullscreen monitor\n\t\tby adding a screen id from 0 to 9 after the F, the default is 0.\n"); + return 1; //1 means please quit case 'F': ; //funny C quirk not allowing lables before declarations int target_fs_disp = 0; @@ -200,7 +200,7 @@ void args_parse_and_act(int argc, char **argv) { } printf("Fullscreening on display %d due to cmdline arg\n", target_fs_disp); canvas_fullscreen(target_fs_disp); //fullscreen pxnuke on the target screen - break; + return 0; } } } @@ -211,7 +211,7 @@ int main(int argc, char **argv) { canvas_start(1024, &px_on_window_close); - args_parse_and_act(argc, argv); + if (args_parse_and_act(argc, argv)) return 0; //handle args and quit if needed net_start(1337, &px_on_connect, &px_on_read, &px_on_close); return 0; From 4be4c21abf4490bd9d05aa480327caf656750bd3 Mon Sep 17 00:00:00 2001 From: HACKER3000 Date: Mon, 25 Apr 2022 21:12:10 +0200 Subject: [PATCH 6/6] added return at the end so the compiler is happy --- pixelnuke/pixelnuke.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pixelnuke/pixelnuke.c b/pixelnuke/pixelnuke.c index 683da46..bf59bc7 100644 --- a/pixelnuke/pixelnuke.c +++ b/pixelnuke/pixelnuke.c @@ -187,7 +187,7 @@ uint8_t args_parse_and_act(int argc, char **argv) { for (int arg = 1; arg < argc; ++arg) { switch (argv[arg][0]) { //compare first char of argument case 'H': - printf("==pixelnuke commandline arguments==\nH\t\tshows this help\nF[screen_id]\t\tStart fullscreened. You can additionally specify the fullscreen monitor\n\t\tby adding a screen id from 0 to 9 after the F, the default is 0.\n"); + printf("==pixelnuke commandline arguments==\nH\t\tshows this help\nF[screen_id]\tStart fullscreened. You can additionally specify the fullscreen monitor\n\t\tby adding a screen id from 0 to 9 after the F, the default is 0.\n"); return 1; //1 means please quit case 'F': ; //funny C quirk not allowing lables before declarations @@ -203,6 +203,7 @@ uint8_t args_parse_and_act(int argc, char **argv) { return 0; } } + return 0; } int main(int argc, char **argv) {