aboutsummaryrefslogtreecommitdiffstats
path: root/options.c
diff options
context:
space:
mode:
authorBert Münnich <be.muennich@gmail.com>2013-03-19 21:11:29 +0100
committerBert Münnich <be.muennich@gmail.com>2013-03-19 21:14:58 +0100
commit6f05e777280cd36a8ccaf20182c4e8a0554bb563 (patch)
tree07029d49c352d9a2fd26ff810a551ebfae9afe23 /options.c
parent447bc1c784cc358078f4ffbbac0c63ee74a069c8 (diff)
downloadnsxiv-6f05e777280cd36a8ccaf20182c4e8a0554bb563.tar.zst
New options: -[io], read/write files from/to stdin/out
Fixes issue #84
Diffstat (limited to 'options.c')
-rw-r--r--options.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/options.c b/options.c
index 0354616..2d35992 100644
--- a/options.c
+++ b/options.c
@@ -33,7 +33,7 @@ const options_t *options = (const options_t*) &_options;
void print_usage(void)
{
- printf("usage: sxiv [-bcdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] "
+ printf("usage: sxiv [-bcdFfhiopqrstvZ] [-g GEOMETRY] [-n NUM] "
"[-N name] [-z ZOOM] FILES...\n");
}
@@ -46,6 +46,8 @@ void parse_options(int argc, char **argv)
{
int opt, t;
+ _options.from_stdin = false;
+ _options.to_stdout = false;
_options.recursive = false;
_options.startnum = 0;
@@ -63,7 +65,7 @@ void parse_options(int argc, char **argv)
_options.thumb_mode = false;
_options.clean_cache = false;
- while ((opt = getopt(argc, argv, "bcdFfg:hn:N:pqrstvZz:")) != -1) {
+ while ((opt = getopt(argc, argv, "bcdFfg:hin:N:opqrstvZz:")) != -1) {
switch (opt) {
case '?':
print_usage();
@@ -89,6 +91,9 @@ void parse_options(int argc, char **argv)
case 'h':
print_usage();
exit(EXIT_SUCCESS);
+ case 'i':
+ _options.from_stdin = true;
+ break;
case 'n':
if (sscanf(optarg, "%d", &t) <= 0 || t < 1) {
fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
@@ -101,6 +106,9 @@ void parse_options(int argc, char **argv)
case 'N':
_options.res_name = optarg;
break;
+ case 'o':
+ _options.to_stdout = true;
+ break;
case 'p':
_options.aa = false;
break;
@@ -137,6 +145,10 @@ void parse_options(int argc, char **argv)
_options.filenames = argv + optind;
_options.filecnt = argc - optind;
- _options.from_stdin = _options.filecnt == 1 &&
- STREQ(_options.filenames[0], "-");
+
+ if (_options.filecnt == 1 && STREQ(_options.filenames[0], "-")) {
+ _options.filenames++;
+ _options.filecnt--;
+ _options.from_stdin = true;
+ }
}