A Simple X Image Viewer
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

179 lignes
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 <stdlib.h>
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <unistd.h>
  22. #include "options.h"
  23. #include "util.h"
  24. #define _IMAGE_CONFIG
  25. #include "config.h"
  26. options_t _options;
  27. const options_t *options = (const options_t*) &_options;
  28. void print_usage(void)
  29. {
  30. printf("usage: sxiv [-abcfhioqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] "
  31. "[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] [-z ZOOM] "
  32. "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 n, opt;
  41. char *end, *s;
  42. const char *scalemodes = "dfwh";
  43. progname = strrchr(argv[0], '/');
  44. progname = progname ? progname + 1 : argv[0];
  45. _options.from_stdin = false;
  46. _options.to_stdout = false;
  47. _options.recursive = false;
  48. _options.startnum = 0;
  49. _options.scalemode = SCALE_DOWN;
  50. _options.zoom = 1.0;
  51. _options.animate = false;
  52. _options.gamma = 0;
  53. _options.slideshow = 0;
  54. _options.framerate = 0;
  55. _options.fullscreen = false;
  56. _options.embed = 0;
  57. _options.hide_bar = false;
  58. _options.geometry = NULL;
  59. _options.res_name = NULL;
  60. _options.quiet = false;
  61. _options.thumb_mode = false;
  62. _options.clean_cache = false;
  63. while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:oqrS: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 'q':
  120. _options.quiet = true;
  121. break;
  122. case 'r':
  123. _options.recursive = true;
  124. break;
  125. case 'S':
  126. n = strtof(optarg, &end) * 10;
  127. if (*end != '\0' || n <= 0)
  128. error(EXIT_FAILURE, 0, "Invalid argument for option -S: %s", optarg);
  129. _options.slideshow = n;
  130. break;
  131. case 's':
  132. s = strchr(scalemodes, optarg[0]);
  133. if (s == NULL || *s == '\0' || strlen(optarg) != 1)
  134. error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", optarg);
  135. _options.scalemode = s - scalemodes;
  136. break;
  137. case 't':
  138. _options.thumb_mode = true;
  139. break;
  140. case 'v':
  141. print_version();
  142. exit(EXIT_SUCCESS);
  143. case 'Z':
  144. _options.scalemode = SCALE_ZOOM;
  145. _options.zoom = 1.0;
  146. break;
  147. case 'z':
  148. n = strtol(optarg, &end, 0);
  149. if (*end != '\0' || n <= 0)
  150. error(EXIT_FAILURE, 0, "Invalid argument for option -z: %s", optarg);
  151. _options.scalemode = SCALE_ZOOM;
  152. _options.zoom = (float) n / 100.0;
  153. break;
  154. }
  155. }
  156. _options.filenames = argv + optind;
  157. _options.filecnt = argc - optind;
  158. if (_options.filecnt == 1 && STREQ(_options.filenames[0], "-")) {
  159. _options.filenames++;
  160. _options.filecnt--;
  161. _options.from_stdin = true;
  162. }
  163. }