A Simple X Image Viewer
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

145 satır
3.4 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 _FEATURE_CONFIG
  20. #define _IMAGE_CONFIG
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <stdio.h>
  24. #include <unistd.h>
  25. #include "options.h"
  26. #include "util.h"
  27. #include "config.h"
  28. options_t _options;
  29. const options_t *options = (const options_t*) &_options;
  30. void print_usage(void) {
  31. printf("usage: sxiv [-cdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] "
  32. "[-z ZOOM] FILES...\n");
  33. }
  34. void print_version(void) {
  35. printf("sxiv %s - Simple X Image Viewer\n", VERSION);
  36. printf("Additional features included (+) or not (-): %s, %s\n",
  37. #if EXIF_SUPPORT
  38. "+exif",
  39. #else
  40. "-exif",
  41. #endif
  42. #if GIF_SUPPORT
  43. "+gif"
  44. #else
  45. "-gif"
  46. #endif
  47. );
  48. }
  49. void parse_options(int argc, char **argv) {
  50. int opt, t;
  51. _options.recursive = false;
  52. _options.startnum = 0;
  53. _options.scalemode = SCALE_MODE;
  54. _options.zoom = 1.0;
  55. _options.aa = true;
  56. _options.fixed_win = false;
  57. _options.fullscreen = false;
  58. _options.geometry = NULL;
  59. _options.quiet = false;
  60. _options.thumb_mode = false;
  61. _options.clean_cache = false;
  62. while ((opt = getopt(argc, argv, "cdFfg:hn:pqrstvZz:")) != -1) {
  63. switch (opt) {
  64. case '?':
  65. print_usage();
  66. exit(EXIT_FAILURE);
  67. case 'c':
  68. _options.clean_cache = true;
  69. break;
  70. case 'd':
  71. _options.scalemode = SCALE_DOWN;
  72. break;
  73. case 'F':
  74. _options.fixed_win = true;
  75. break;
  76. case 'f':
  77. _options.fullscreen = true;
  78. break;
  79. case 'g':
  80. _options.geometry = optarg;
  81. break;
  82. case 'h':
  83. print_usage();
  84. exit(EXIT_SUCCESS);
  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 'p':
  95. _options.aa = false;
  96. break;
  97. case 'q':
  98. _options.quiet = true;
  99. break;
  100. case 'r':
  101. _options.recursive = true;
  102. break;
  103. case 's':
  104. _options.scalemode = SCALE_FIT;
  105. break;
  106. case 't':
  107. _options.thumb_mode = true;
  108. break;
  109. case 'v':
  110. print_version();
  111. exit(EXIT_SUCCESS);
  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, "%d", &t) <= 0 || t <= 0) {
  119. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  120. optarg);
  121. exit(EXIT_FAILURE);
  122. }
  123. _options.zoom = (float) t / 100.0;
  124. break;
  125. }
  126. }
  127. _options.filenames = argv + optind;
  128. _options.filecnt = argc - optind;
  129. _options.from_stdin = _options.filecnt == 1 &&
  130. streq(_options.filenames[0], "-");
  131. }