A Simple X Image Viewer
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

options.c 3.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Copyright 2011 Bert Muennich
  2. *
  3. * This file is part of sxiv.
  4. *
  5. * sxiv is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published
  7. * by the Free Software Foundation; either version 2 of the License,
  8. * or (at your option) any later version.
  9. *
  10. * sxiv is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #define _POSIX_C_SOURCE 200112L
  19. #define _IMAGE_CONFIG
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <stdio.h>
  23. #include <unistd.h>
  24. #include "options.h"
  25. #include "util.h"
  26. #include "config.h"
  27. options_t _options;
  28. const options_t *options = (const options_t*) &_options;
  29. void print_usage(void)
  30. {
  31. printf("usage: sxiv [-bcdFfhioqrstvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] "
  32. "[-N name] [-z ZOOM] FILES...\n");
  33. }
  34. void print_version(void)
  35. {
  36. printf("sxiv %s - Simple X Image Viewer\n", VERSION);
  37. }
  38. void parse_options(int argc, char **argv)
  39. {
  40. int opt, t, gamma;
  41. char *end;
  42. _options.from_stdin = false;
  43. _options.to_stdout = false;
  44. _options.recursive = false;
  45. _options.startnum = 0;
  46. _options.scalemode = SCALE_MODE;
  47. _options.zoom = 1.0;
  48. _options.gamma = 0;
  49. _options.fixed_win = false;
  50. _options.fullscreen = false;
  51. _options.hide_bar = false;
  52. _options.geometry = NULL;
  53. _options.res_name = NULL;
  54. _options.quiet = false;
  55. _options.thumb_mode = false;
  56. _options.clean_cache = false;
  57. while ((opt = getopt(argc, argv, "bcdFfG:g:hin:N:oqrstvZz:")) != -1) {
  58. switch (opt) {
  59. case '?':
  60. print_usage();
  61. exit(EXIT_FAILURE);
  62. case 'b':
  63. _options.hide_bar = true;
  64. break;
  65. case 'c':
  66. _options.clean_cache = true;
  67. break;
  68. case 'd':
  69. _options.scalemode = SCALE_DOWN;
  70. break;
  71. case 'F':
  72. _options.fixed_win = true;
  73. break;
  74. case 'f':
  75. _options.fullscreen = true;
  76. break;
  77. case 'G':
  78. gamma = strtol(optarg, &end, 0);
  79. if (*end != '\0') {
  80. fprintf(stderr, "sxiv: invalid argument for option -G: %s\n",
  81. optarg);
  82. exit(EXIT_FAILURE);
  83. }
  84. _options.gamma = gamma;
  85. break;
  86. case 'g':
  87. _options.geometry = optarg;
  88. break;
  89. case 'h':
  90. print_usage();
  91. exit(EXIT_SUCCESS);
  92. case 'i':
  93. _options.from_stdin = true;
  94. break;
  95. case 'n':
  96. if (sscanf(optarg, "%d", &t) <= 0 || t < 1) {
  97. fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
  98. optarg);
  99. exit(EXIT_FAILURE);
  100. } else {
  101. _options.startnum = t - 1;
  102. }
  103. break;
  104. case 'N':
  105. _options.res_name = optarg;
  106. break;
  107. case 'o':
  108. _options.to_stdout = true;
  109. break;
  110. case 'q':
  111. _options.quiet = true;
  112. break;
  113. case 'r':
  114. _options.recursive = true;
  115. break;
  116. case 's':
  117. _options.scalemode = SCALE_FIT;
  118. break;
  119. case 't':
  120. _options.thumb_mode = true;
  121. break;
  122. case 'v':
  123. print_version();
  124. exit(EXIT_SUCCESS);
  125. case 'Z':
  126. _options.scalemode = SCALE_ZOOM;
  127. _options.zoom = 1.0;
  128. break;
  129. case 'z':
  130. _options.scalemode = SCALE_ZOOM;
  131. if (sscanf(optarg, "%d", &t) <= 0 || t <= 0) {
  132. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  133. optarg);
  134. exit(EXIT_FAILURE);
  135. }
  136. _options.zoom = (float) t / 100.0;
  137. break;
  138. }
  139. }
  140. _options.filenames = argv + optind;
  141. _options.filecnt = argc - optind;
  142. if (_options.filecnt == 1 && STREQ(_options.filenames[0], "-")) {
  143. _options.filenames++;
  144. _options.filecnt--;
  145. _options.from_stdin = true;
  146. }
  147. }