A Simple X Image Viewer
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

options.c 4.4 KiB

13 år sedan
13 år sedan
13 år sedan
13 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. #include "sxiv.h"
  19. #define _IMAGE_CONFIG
  20. #include "config.h"
  21. #include "version.h"
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <unistd.h>
  25. opt_t _options;
  26. const opt_t *options = (const opt_t*) &_options;
  27. void print_usage(void)
  28. {
  29. printf("usage: sxiv [-abcfhiopqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] "
  30. "[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] [-z ZOOM] "
  31. "FILES...\n");
  32. }
  33. void print_version(void)
  34. {
  35. puts("sxiv " VERSION);
  36. }
  37. void parse_options(int argc, char **argv)
  38. {
  39. int n, opt;
  40. char *end, *s;
  41. const char *scalemodes = "dfwh";
  42. progname = strrchr(argv[0], '/');
  43. progname = progname ? progname + 1 : argv[0];
  44. _options.from_stdin = false;
  45. _options.to_stdout = false;
  46. _options.recursive = false;
  47. _options.startnum = 0;
  48. _options.scalemode = SCALE_DOWN;
  49. _options.zoom = 1.0;
  50. _options.animate = false;
  51. _options.gamma = 0;
  52. _options.slideshow = 0;
  53. _options.framerate = 0;
  54. _options.fullscreen = false;
  55. _options.embed = 0;
  56. _options.hide_bar = false;
  57. _options.geometry = NULL;
  58. _options.res_name = NULL;
  59. _options.quiet = false;
  60. _options.thumb_mode = false;
  61. _options.clean_cache = false;
  62. _options.private_mode = false;
  63. while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:opqrS:s:tvZz:")) != -1) {
  64. switch (opt) {
  65. case '?':
  66. print_usage();
  67. exit(EXIT_FAILURE);
  68. case 'A':
  69. n = strtol(optarg, &end, 0);
  70. if (*end != '\0' || n <= 0)
  71. error(EXIT_FAILURE, 0, "Invalid argument for option -A: %s", optarg);
  72. _options.framerate = n;
  73. /* fall through */
  74. case 'a':
  75. _options.animate = true;
  76. break;
  77. case 'b':
  78. _options.hide_bar = true;
  79. break;
  80. case 'c':
  81. _options.clean_cache = true;
  82. break;
  83. case 'e':
  84. n = strtol(optarg, &end, 0);
  85. if (*end != '\0')
  86. error(EXIT_FAILURE, 0, "Invalid argument for option -e: %s", optarg);
  87. _options.embed = n;
  88. break;
  89. case 'f':
  90. _options.fullscreen = true;
  91. break;
  92. case 'G':
  93. n = strtol(optarg, &end, 0);
  94. if (*end != '\0')
  95. error(EXIT_FAILURE, 0, "Invalid argument for option -G: %s", optarg);
  96. _options.gamma = n;
  97. break;
  98. case 'g':
  99. _options.geometry = optarg;
  100. break;
  101. case 'h':
  102. print_usage();
  103. exit(EXIT_SUCCESS);
  104. case 'i':
  105. _options.from_stdin = true;
  106. break;
  107. case 'n':
  108. n = strtol(optarg, &end, 0);
  109. if (*end != '\0' || n <= 0)
  110. error(EXIT_FAILURE, 0, "Invalid argument for option -n: %s", optarg);
  111. _options.startnum = n - 1;
  112. break;
  113. case 'N':
  114. _options.res_name = optarg;
  115. break;
  116. case 'o':
  117. _options.to_stdout = true;
  118. break;
  119. case 'p':
  120. _options.private_mode = true;
  121. break;
  122. case 'q':
  123. _options.quiet = true;
  124. break;
  125. case 'r':
  126. _options.recursive = true;
  127. break;
  128. case 'S':
  129. n = strtof(optarg, &end) * 10;
  130. if (*end != '\0' || n <= 0)
  131. error(EXIT_FAILURE, 0, "Invalid argument for option -S: %s", optarg);
  132. _options.slideshow = n;
  133. break;
  134. case 's':
  135. s = strchr(scalemodes, optarg[0]);
  136. if (s == NULL || *s == '\0' || strlen(optarg) != 1)
  137. error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", optarg);
  138. _options.scalemode = s - scalemodes;
  139. break;
  140. case 't':
  141. _options.thumb_mode = true;
  142. break;
  143. case 'v':
  144. print_version();
  145. exit(EXIT_SUCCESS);
  146. case 'Z':
  147. _options.scalemode = SCALE_ZOOM;
  148. _options.zoom = 1.0;
  149. break;
  150. case 'z':
  151. n = strtol(optarg, &end, 0);
  152. if (*end != '\0' || n <= 0)
  153. error(EXIT_FAILURE, 0, "Invalid argument for option -z: %s", optarg);
  154. _options.scalemode = SCALE_ZOOM;
  155. _options.zoom = (float) n / 100.0;
  156. break;
  157. }
  158. }
  159. _options.filenames = argv + optind;
  160. _options.filecnt = argc - optind;
  161. if (_options.filecnt == 1 && STREQ(_options.filenames[0], "-")) {
  162. _options.filenames++;
  163. _options.filecnt--;
  164. _options.from_stdin = true;
  165. }
  166. }