A Simple X Image Viewer
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

172 строки
4.2 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] [-e WID] [-G GAMMA] [-g GEOMETRY] "
  31. "[-N NAME] [-n NUM] [-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. float f;
  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.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. while ((opt = getopt(argc, argv, "abce:fG:g:hin:N:oqrS:s:tvZz:")) != -1) {
  63. switch (opt) {
  64. case '?':
  65. print_usage();
  66. exit(EXIT_FAILURE);
  67. case 'a':
  68. _options.animate = true;
  69. break;
  70. case 'b':
  71. _options.hide_bar = true;
  72. break;
  73. case 'c':
  74. _options.clean_cache = true;
  75. break;
  76. case 'e':
  77. n = strtol(optarg, &end, 0);
  78. if (*end != '\0')
  79. error(EXIT_FAILURE, 0, "Invalid argument for option -e: %s", optarg);
  80. _options.embed = n;
  81. break;
  82. case 'f':
  83. _options.fullscreen = true;
  84. break;
  85. case 'G':
  86. n = strtol(optarg, &end, 0);
  87. if (*end != '\0')
  88. error(EXIT_FAILURE, 0, "Invalid argument for option -G: %s", optarg);
  89. _options.gamma = n;
  90. break;
  91. case 'g':
  92. _options.geometry = optarg;
  93. break;
  94. case 'h':
  95. print_usage();
  96. exit(EXIT_SUCCESS);
  97. case 'i':
  98. _options.from_stdin = true;
  99. break;
  100. case 'n':
  101. n = strtol(optarg, &end, 0);
  102. if (*end != '\0' || n <= 0)
  103. error(EXIT_FAILURE, 0, "Invalid argument for option -n: %s", optarg);
  104. _options.startnum = n - 1;
  105. break;
  106. case 'N':
  107. _options.res_name = optarg;
  108. break;
  109. case 'o':
  110. _options.to_stdout = true;
  111. break;
  112. case 'q':
  113. _options.quiet = true;
  114. break;
  115. case 'r':
  116. _options.recursive = true;
  117. break;
  118. case 'S':
  119. f = (float) strtof(optarg, &end);
  120. if (*end != '\0' || f <= 0.0)
  121. error(EXIT_FAILURE, 0, "Invalid argument for option -S: %s", optarg);
  122. _options.slideshow = (float) f;
  123. break;
  124. case 's':
  125. s = strchr(scalemodes, optarg[0]);
  126. if (s == NULL || *s == '\0' || strlen(optarg) != 1)
  127. error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", optarg);
  128. _options.scalemode = s - scalemodes;
  129. break;
  130. case 't':
  131. _options.thumb_mode = true;
  132. break;
  133. case 'v':
  134. print_version();
  135. exit(EXIT_SUCCESS);
  136. case 'Z':
  137. _options.scalemode = SCALE_ZOOM;
  138. _options.zoom = 1.0;
  139. break;
  140. case 'z':
  141. n = strtol(optarg, &end, 0);
  142. if (*end != '\0' || n <= 0)
  143. error(EXIT_FAILURE, 0, "Invalid argument for option -z: %s", optarg);
  144. _options.scalemode = SCALE_ZOOM;
  145. _options.zoom = (float) n / 100.0;
  146. break;
  147. }
  148. }
  149. _options.filenames = argv + optind;
  150. _options.filecnt = argc - optind;
  151. if (_options.filecnt == 1 && STREQ(_options.filenames[0], "-")) {
  152. _options.filenames++;
  153. _options.filecnt--;
  154. _options.from_stdin = true;
  155. }
  156. }