Krolyxon
Commit 63972db

Branches

Refs →

nsxiv63972db

add -0 for outputting null-terminated list (#68)

* add -0 for outputting null-terminated list

this doesn't add much, if any, additional complexity to the codebase and
can be quite handy for scripting purposes.

Closes: https://github.com/nsxiv/nsxiv/issues/67

* Fix typo
Author
N-R-K
Date
2021-09-21 05:11 +0600
Committer
GitHub · 2021-09-20 23:11 +0000
Parent
3234b0e
Commit
63972db743398a4c2f0159110f5e14fb1effb6d5

+8 −2

3 files changed

  1. M commands.c +1 −1
  2. M nsxiv.h +1 −0
  3. M options.c +6 −1
M commands.c View
@@ -59,7 +59,7 @@ bool cg_quit(arg_t _)
5959 if (options->to_stdout && markcnt > 0) {
6060 for (i = 0; i < filecnt; i++) {
6161 if (files[i].flags & FF_MARK)
62− printf("%s\n", files[i].name);
62+ printf("%s%c", files[i].name, options->stdout_separator);
6363 }
6464 }
6565 exit(EXIT_SUCCESS);
M nsxiv.h View
@@ -268,6 +268,7 @@ struct opt {
268268 char **filenames;
269269 bool from_stdin;
270270 bool to_stdout;
271+ char stdout_separator;
271272 bool recursive;
272273 int filecnt;
273274 int startnum;
M options.c View
@@ -52,6 +52,7 @@ void parse_options(int argc, char **argv)
5252
5353 _options.from_stdin = false;
5454 _options.to_stdout = false;
55+ _options.stdout_separator = '\n';
5556 _options.recursive = false;
5657 _options.startnum = 0;
5758
@@ -75,7 +76,7 @@ void parse_options(int argc, char **argv)
7576 _options.clean_cache = false;
7677 _options.private_mode = false;
7778
78− while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:opqrS:s:T:tvZz:")) != -1) {
79+ while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:0opqrS:s:T:tvZz:")) != -1) {
7980 switch (opt) {
8081 case '?':
8182 print_usage();
@@ -128,6 +129,10 @@ void parse_options(int argc, char **argv)
128129 case 'N':
129130 _options.res_name = optarg;
130131 break;
132+ case '0':
133+ _options.stdout_separator = '\0';
134+ /* -0 implies -o */
135+ /* fall through */
131136 case 'o':
132137 _options.to_stdout = true;
133138 break;