A Simple X Image Viewer
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

146 lignes
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. #include <stdlib.h>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <unistd.h>
  23. #include "options.h"
  24. #include "util.h"
  25. #define _IMAGE_CONFIG
  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. float z;
  50. int n, opt;
  51. _options.startnum = 0;
  52. _options.scalemode = SCALE_MODE;
  53. _options.zoom = 1.0;
  54. _options.aa = 1;
  55. _options.thumbnails = 0;
  56. _options.fixed = 0;
  57. _options.fullscreen = 0;
  58. _options.geometry = NULL;
  59. _options.quiet = 0;
  60. _options.clean_cache = 0;
  61. _options.recursive = 0;
  62. while ((opt = getopt(argc, argv, "cdFfg:hn:pqrstvZz:")) != -1) {
  63. switch (opt) {
  64. case '?':
  65. print_usage();
  66. exit(1);
  67. case 'c':
  68. _options.clean_cache = 1;
  69. break;
  70. case 'd':
  71. _options.scalemode = SCALE_DOWN;
  72. break;
  73. case 'F':
  74. _options.fixed = 1;
  75. break;
  76. case 'f':
  77. _options.fullscreen = 1;
  78. break;
  79. case 'g':
  80. _options.geometry = optarg;
  81. break;
  82. case 'h':
  83. print_usage();
  84. exit(0);
  85. case 'n':
  86. if (!sscanf(optarg, "%d", &n) || n < 1) {
  87. fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
  88. optarg);
  89. exit(1);
  90. } else {
  91. _options.startnum = n - 1;
  92. }
  93. break;
  94. case 'p':
  95. _options.aa = 0;
  96. break;
  97. case 'q':
  98. _options.quiet = 1;
  99. break;
  100. case 'r':
  101. _options.recursive = 1;
  102. break;
  103. case 's':
  104. _options.scalemode = SCALE_FIT;
  105. break;
  106. case 't':
  107. _options.thumbnails = 1;
  108. break;
  109. case 'v':
  110. print_version();
  111. exit(0);
  112. case 'Z':
  113. _options.scalemode = SCALE_ZOOM;
  114. _options.zoom = 1.0;
  115. break;
  116. case 'z':
  117. _options.scalemode = SCALE_ZOOM;
  118. if (!sscanf(optarg, "%f", &z) || z < 0) {
  119. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  120. optarg);
  121. exit(1);
  122. }
  123. _options.zoom = z / 100.0;
  124. break;
  125. }
  126. }
  127. _options.filenames = argv + optind;
  128. _options.filecnt = argc - optind;
  129. _options.from_stdin = _options.filecnt == 1 &&
  130. strcmp(_options.filenames[0], "-") == 0;
  131. }