A Simple X Image Viewer
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

options.c 3.3 KiB

hace 14 años
hace 14 años
hace 14 años
hace 14 años
hace 14 años
hace 14 años
hace 14 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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() {
  31. printf("usage: sxiv [-cdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] "
  32. "[-z ZOOM] FILES...\n");
  33. }
  34. void print_version() {
  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(1);
  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(0);
  85. case 'n':
  86. if (!sscanf(optarg, "%d", &t) || t < 1) {
  87. fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
  88. optarg);
  89. exit(1);
  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(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, "%d", &t) || t <= 0) {
  119. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  120. optarg);
  121. exit(1);
  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. !strcmp(_options.filenames[0], "-");
  131. }