A Simple X Image Viewer
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

164 řádky
3.9 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] [-G GAMMA] [-g GEOMETRY] [-n NUM] "
  31. "[-N NAME] [-S DELAY] [-s MODE] [-z ZOOM] FILES...\n");
  32. }
  33. void print_version(void)
  34. {
  35. printf("sxiv %s - Simple X Image Viewer\n", 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.fullscreen = false;
  54. _options.hide_bar = false;
  55. _options.geometry = NULL;
  56. _options.res_name = NULL;
  57. _options.quiet = false;
  58. _options.thumb_mode = false;
  59. _options.clean_cache = false;
  60. while ((opt = getopt(argc, argv, "abcfG:g:hin:N:oqrS:s:tvZz:")) != -1) {
  61. switch (opt) {
  62. case '?':
  63. print_usage();
  64. exit(EXIT_FAILURE);
  65. case 'a':
  66. _options.animate = true;
  67. break;
  68. case 'b':
  69. _options.hide_bar = true;
  70. break;
  71. case 'c':
  72. _options.clean_cache = true;
  73. break;
  74. case 'f':
  75. _options.fullscreen = true;
  76. break;
  77. case 'G':
  78. n = strtol(optarg, &end, 0);
  79. if (*end != '\0')
  80. error(EXIT_FAILURE, 0, "Invalid argument for option -G: %s", optarg);
  81. _options.gamma = n;
  82. break;
  83. case 'g':
  84. _options.geometry = optarg;
  85. break;
  86. case 'h':
  87. print_usage();
  88. exit(EXIT_SUCCESS);
  89. case 'i':
  90. _options.from_stdin = true;
  91. break;
  92. case 'n':
  93. n = strtol(optarg, &end, 0);
  94. if (*end != '\0' || n <= 0)
  95. error(EXIT_FAILURE, 0, "Invalid argument for option -n: %s", optarg);
  96. _options.startnum = n - 1;
  97. break;
  98. case 'N':
  99. _options.res_name = optarg;
  100. break;
  101. case 'o':
  102. _options.to_stdout = true;
  103. break;
  104. case 'q':
  105. _options.quiet = true;
  106. break;
  107. case 'r':
  108. _options.recursive = true;
  109. break;
  110. case 'S':
  111. n = strtol(optarg, &end, 0);
  112. if (*end != '\0' || n <= 0)
  113. error(EXIT_FAILURE, 0, "Invalid argument for option -S: %s", optarg);
  114. _options.slideshow = n;
  115. break;
  116. case 's':
  117. s = strchr(scalemodes, optarg[0]);
  118. if (s == NULL || *s == '\0' || strlen(optarg) != 1)
  119. error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", optarg);
  120. _options.scalemode = s - scalemodes;
  121. break;
  122. case 't':
  123. _options.thumb_mode = true;
  124. break;
  125. case 'v':
  126. print_version();
  127. exit(EXIT_SUCCESS);
  128. case 'Z':
  129. _options.scalemode = SCALE_ZOOM;
  130. _options.zoom = 1.0;
  131. break;
  132. case 'z':
  133. n = strtol(optarg, &end, 0);
  134. if (*end != '\0' || n <= 0)
  135. error(EXIT_FAILURE, 0, "Invalid argument for option -z: %s", optarg);
  136. _options.scalemode = SCALE_ZOOM;
  137. _options.zoom = (float) n / 100.0;
  138. break;
  139. }
  140. }
  141. _options.filenames = argv + optind;
  142. _options.filecnt = argc - optind;
  143. if (_options.filecnt == 1 && STREQ(_options.filenames[0], "-")) {
  144. _options.filenames++;
  145. _options.filecnt--;
  146. _options.from_stdin = true;
  147. }
  148. }