A Simple X Image Viewer
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

180 рядки
4.4 KiB

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