A Simple X Image Viewer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

155 lines
3.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. #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 [-bcdFfhiopqrstvZ] [-g GEOMETRY] [-n NUM] "
  32. "[-N name] [-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 opt, t;
  41. _options.from_stdin = false;
  42. _options.to_stdout = false;
  43. _options.recursive = false;
  44. _options.startnum = 0;
  45. _options.scalemode = SCALE_MODE;
  46. _options.zoom = 1.0;
  47. _options.aa = true;
  48. _options.fixed_win = false;
  49. _options.fullscreen = false;
  50. _options.hide_bar = false;
  51. _options.geometry = NULL;
  52. _options.res_name = NULL;
  53. _options.quiet = false;
  54. _options.thumb_mode = false;
  55. _options.clean_cache = false;
  56. while ((opt = getopt(argc, argv, "bcdFfg:hin:N:opqrstvZz:")) != -1) {
  57. switch (opt) {
  58. case '?':
  59. print_usage();
  60. exit(EXIT_FAILURE);
  61. case 'b':
  62. _options.hide_bar = true;
  63. break;
  64. case 'c':
  65. _options.clean_cache = true;
  66. break;
  67. case 'd':
  68. _options.scalemode = SCALE_DOWN;
  69. break;
  70. case 'F':
  71. _options.fixed_win = true;
  72. break;
  73. case 'f':
  74. _options.fullscreen = true;
  75. break;
  76. case 'g':
  77. _options.geometry = optarg;
  78. break;
  79. case 'h':
  80. print_usage();
  81. exit(EXIT_SUCCESS);
  82. case 'i':
  83. _options.from_stdin = true;
  84. break;
  85. case 'n':
  86. if (sscanf(optarg, "%d", &t) <= 0 || t < 1) {
  87. fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
  88. optarg);
  89. exit(EXIT_FAILURE);
  90. } else {
  91. _options.startnum = t - 1;
  92. }
  93. break;
  94. case 'N':
  95. _options.res_name = optarg;
  96. break;
  97. case 'o':
  98. _options.to_stdout = true;
  99. break;
  100. case 'p':
  101. _options.aa = false;
  102. break;
  103. case 'q':
  104. _options.quiet = true;
  105. break;
  106. case 'r':
  107. _options.recursive = true;
  108. break;
  109. case 's':
  110. _options.scalemode = SCALE_FIT;
  111. break;
  112. case 't':
  113. _options.thumb_mode = true;
  114. break;
  115. case 'v':
  116. print_version();
  117. exit(EXIT_SUCCESS);
  118. case 'Z':
  119. _options.scalemode = SCALE_ZOOM;
  120. _options.zoom = 1.0;
  121. break;
  122. case 'z':
  123. _options.scalemode = SCALE_ZOOM;
  124. if (sscanf(optarg, "%d", &t) <= 0 || t <= 0) {
  125. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  126. optarg);
  127. exit(EXIT_FAILURE);
  128. }
  129. _options.zoom = (float) t / 100.0;
  130. break;
  131. }
  132. }
  133. _options.filenames = argv + optind;
  134. _options.filecnt = argc - optind;
  135. if (_options.filecnt == 1 && STREQ(_options.filenames[0], "-")) {
  136. _options.filenames++;
  137. _options.filecnt--;
  138. _options.from_stdin = true;
  139. }
  140. }