A Simple X Image Viewer
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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] [-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. 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. while ((opt = getopt(argc, argv, "aA:bce: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 'A':
  71. _options.animate = true;
  72. n = strtol(optarg, &end, 0);
  73. if (*end != '\0' || n <= 0)
  74. error(EXIT_FAILURE, 0, "Invalid argument for option -A: %s", optarg);
  75. _options.framerate = n;
  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 = strtol(optarg, &end, 0);
  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. }