1
0
mirror of https://codeberg.org/vyivel/dulcepan/ synced 2025-09-07 19:00:58 +03:00

2 Commits

Author SHA1 Message Date
Kirill Primak
d2620c60c5 main: refuse to dump the result into tty
Closes: https://codeberg.org/vyivel/dulcepan/issues/17
2024-11-06 23:38:01 +03:00
Kirill Primak
c343fc1f73 main: validate args before loading everything else 2024-11-06 23:27:05 +03:00

View File

@@ -1,6 +1,7 @@
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wayland-client-core.h>
#include <wayland-client-protocol.h>
#include <xkbcommon/xkbcommon.h>
@@ -167,8 +168,9 @@ static void help(const char *prog) {
" -o <path> Specify the output file path.\n"
"\n"
"If the output file path is not specified, the resuling image will be printed to\n"
"the standard output. If the output file format is not specified, it is guessed\n"
"from the output file path if it's specified, and assumed to be PNG otherwise.\n"
"the standard output, which is expected to not be a terminal. If the output file\n"
"format is not specified, it is guessed from the output file path if it's\n"
"specified, and assumed to be PNG otherwise.\n"
"\n"
"Supported formats: png, ppm.\n"
"\n"
@@ -210,9 +212,13 @@ int main(int argc, char **argv) {
}
}
state.basedir_ctx = sfdo_basedir_ctx_create();
dp_config_load(&state, config_path);
if (state.output_path == NULL && isatty(STDOUT_FILENO)) {
fprintf(stderr,
"Refusing to run as the standard output is a terminal and there's no output file\n"
"path specified.\n\n");
help(argv[0]);
exit(1);
}
if (state.output_format == DP_FILE_UNKNOWN) {
if (state.output_path != NULL) {
@@ -227,6 +233,10 @@ int main(int argc, char **argv) {
}
}
state.basedir_ctx = sfdo_basedir_ctx_create();
dp_config_load(&state, config_path);
wl_list_init(&state.outputs);
wl_list_init(&state.seats);