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.
 
 
 
 
 
 

168 Zeilen
4.0 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. #define _POSIX_C_SOURCE 200112L
  19. #define _IMAGE_CONFIG
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <stdio.h>
  23. #include <unistd.h>
  24. #include "options.h"
  25. #include "util.h"
  26. #include "config.h"
  27. options_t _options;
  28. const options_t *options = (const options_t*) &_options;
  29. void print_usage(void)
  30. {
  31. printf("usage: sxiv [-bcfhioqrtvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] "
  32. "[-N NAME] [-S DELAY] [-s MODE] [-z ZOOM] 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. _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.gamma = 0;
  50. _options.slideshow = 0;
  51. _options.fullscreen = false;
  52. _options.hide_bar = false;
  53. _options.geometry = NULL;
  54. _options.res_name = NULL;
  55. _options.quiet = false;
  56. _options.thumb_mode = false;
  57. _options.clean_cache = false;
  58. while ((opt = getopt(argc, argv, "bcfG:g:hin:N:oqrS:s:tvZz:")) != -1) {
  59. switch (opt) {
  60. case '?':
  61. print_usage();
  62. exit(EXIT_FAILURE);
  63. case 'b':
  64. _options.hide_bar = true;
  65. break;
  66. case 'c':
  67. _options.clean_cache = true;
  68. break;
  69. case 'f':
  70. _options.fullscreen = true;
  71. break;
  72. case 'G':
  73. n = strtol(optarg, &end, 0);
  74. if (*end != '\0') {
  75. fprintf(stderr, "sxiv: invalid argument for option -G: %s\n", optarg);
  76. exit(EXIT_FAILURE);
  77. }
  78. _options.gamma = n;
  79. break;
  80. case 'g':
  81. _options.geometry = optarg;
  82. break;
  83. case 'h':
  84. print_usage();
  85. exit(EXIT_SUCCESS);
  86. case 'i':
  87. _options.from_stdin = true;
  88. break;
  89. case 'n':
  90. n = strtol(optarg, &end, 0);
  91. if (*end != '\0' || n <= 0) {
  92. fprintf(stderr, "sxiv: invalid argument for option -n: %s\n", optarg);
  93. exit(EXIT_FAILURE);
  94. }
  95. _options.startnum = n - 1;
  96. break;
  97. case 'N':
  98. _options.res_name = optarg;
  99. break;
  100. case 'o':
  101. _options.to_stdout = true;
  102. break;
  103. case 'q':
  104. _options.quiet = true;
  105. break;
  106. case 'r':
  107. _options.recursive = true;
  108. break;
  109. case 'S':
  110. n = strtol(optarg, &end, 0);
  111. if (*end != '\0' || n <= 0) {
  112. fprintf(stderr, "sxiv: invalid argument for option -S: %s\n", optarg);
  113. exit(EXIT_FAILURE);
  114. }
  115. _options.slideshow = n;
  116. break;
  117. case 's':
  118. s = strchr(scalemodes, optarg[0]);
  119. if (s == NULL || *s == '\0' || strlen(optarg) != 1) {
  120. fprintf(stderr, "sxiv: invalid argument for option -s: %s\n", optarg);
  121. exit(EXIT_FAILURE);
  122. }
  123. _options.scalemode = s - scalemodes;
  124. break;
  125. case 't':
  126. _options.thumb_mode = true;
  127. break;
  128. case 'v':
  129. print_version();
  130. exit(EXIT_SUCCESS);
  131. case 'Z':
  132. _options.scalemode = SCALE_ZOOM;
  133. _options.zoom = 1.0;
  134. break;
  135. case 'z':
  136. n = strtol(optarg, &end, 0);
  137. if (*end != '\0' || n <= 0) {
  138. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n", optarg);
  139. exit(EXIT_FAILURE);
  140. }
  141. _options.scalemode = SCALE_ZOOM;
  142. _options.zoom = (float) n / 100.0;
  143. break;
  144. }
  145. }
  146. _options.filenames = argv + optind;
  147. _options.filecnt = argc - optind;
  148. if (_options.filecnt == 1 && STREQ(_options.filenames[0], "-")) {
  149. _options.filenames++;
  150. _options.filecnt--;
  151. _options.from_stdin = true;
  152. }
  153. }