A Simple X Image Viewer
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

144 lines
3.3 KiB

  1. /* sxiv: options.c
  2. * Copyright (c) 2011 Bert Muennich <muennich at informatik.hu-berlin.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  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() {
  30. printf("usage: sxiv [-cdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] "
  31. "[-z ZOOM] FILES...\n");
  32. }
  33. void print_version() {
  34. printf("sxiv %s - Simple X Image Viewer\n", VERSION);
  35. printf("Additional features included (+) or not (-): %s, %s\n",
  36. #ifdef EXIF_SUPPORT
  37. "+exif",
  38. #else
  39. "-exif",
  40. #endif
  41. #ifdef GIF_SUPPORT
  42. "+gif"
  43. #else
  44. "-gif"
  45. #endif
  46. );
  47. }
  48. void parse_options(int argc, char **argv) {
  49. int opt, t;
  50. _options.recursive = false;
  51. _options.startnum = 0;
  52. _options.scalemode = SCALE_MODE;
  53. _options.zoom = 1.0;
  54. _options.aa = true;
  55. _options.fixed_win = false;
  56. _options.fullscreen = false;
  57. _options.geometry = NULL;
  58. _options.quiet = false;
  59. _options.thumb_mode = false;
  60. _options.clean_cache = false;
  61. while ((opt = getopt(argc, argv, "cdFfg:hn:pqrstvZz:")) != -1) {
  62. switch (opt) {
  63. case '?':
  64. print_usage();
  65. exit(1);
  66. case 'c':
  67. _options.clean_cache = true;
  68. break;
  69. case 'd':
  70. _options.scalemode = SCALE_DOWN;
  71. break;
  72. case 'F':
  73. _options.fixed_win = true;
  74. break;
  75. case 'f':
  76. _options.fullscreen = true;
  77. break;
  78. case 'g':
  79. _options.geometry = optarg;
  80. break;
  81. case 'h':
  82. print_usage();
  83. exit(0);
  84. case 'n':
  85. if (!sscanf(optarg, "%d", &t) || t < 1) {
  86. fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
  87. optarg);
  88. exit(1);
  89. } else {
  90. _options.startnum = t - 1;
  91. }
  92. break;
  93. case 'p':
  94. _options.aa = false;
  95. break;
  96. case 'q':
  97. _options.quiet = true;
  98. break;
  99. case 'r':
  100. _options.recursive = true;
  101. break;
  102. case 's':
  103. _options.scalemode = SCALE_FIT;
  104. break;
  105. case 't':
  106. _options.thumb_mode = true;
  107. break;
  108. case 'v':
  109. print_version();
  110. exit(0);
  111. case 'Z':
  112. _options.scalemode = SCALE_ZOOM;
  113. _options.zoom = 1.0;
  114. break;
  115. case 'z':
  116. _options.scalemode = SCALE_ZOOM;
  117. if (!sscanf(optarg, "%d", &t) || t <= 0) {
  118. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  119. optarg);
  120. exit(1);
  121. }
  122. _options.zoom = (float) t / 100.0;
  123. break;
  124. }
  125. }
  126. _options.filenames = argv + optind;
  127. _options.filecnt = argc - optind;
  128. _options.from_stdin = _options.filecnt == 1 &&
  129. !strcmp(_options.filenames[0], "-");
  130. }