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.
 
 
 
 
 
 

140 líneas
3.2 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. printf("usage: sxiv [-bcdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] "
  31. "[-N name] [-z ZOOM] FILES...\n");
  32. }
  33. void print_version(void) {
  34. printf("sxiv %s - Simple X Image Viewer\n", VERSION);
  35. }
  36. void parse_options(int argc, char **argv) {
  37. int opt, t;
  38. _options.recursive = false;
  39. _options.startnum = 0;
  40. _options.scalemode = SCALE_MODE;
  41. _options.zoom = 1.0;
  42. _options.aa = true;
  43. _options.fixed_win = false;
  44. _options.fullscreen = false;
  45. _options.hide_bar = false;
  46. _options.geometry = NULL;
  47. _options.res_name = NULL;
  48. _options.quiet = false;
  49. _options.thumb_mode = false;
  50. _options.clean_cache = false;
  51. while ((opt = getopt(argc, argv, "bcdFfg:hn:N:pqrstvZz:")) != -1) {
  52. switch (opt) {
  53. case '?':
  54. print_usage();
  55. exit(EXIT_FAILURE);
  56. case 'b':
  57. _options.hide_bar = true;
  58. break;
  59. case 'c':
  60. _options.clean_cache = true;
  61. break;
  62. case 'd':
  63. _options.scalemode = SCALE_DOWN;
  64. break;
  65. case 'F':
  66. _options.fixed_win = true;
  67. break;
  68. case 'f':
  69. _options.fullscreen = true;
  70. break;
  71. case 'g':
  72. _options.geometry = optarg;
  73. break;
  74. case 'h':
  75. print_usage();
  76. exit(EXIT_SUCCESS);
  77. case 'n':
  78. if (sscanf(optarg, "%d", &t) <= 0 || t < 1) {
  79. fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
  80. optarg);
  81. exit(EXIT_FAILURE);
  82. } else {
  83. _options.startnum = t - 1;
  84. }
  85. break;
  86. case 'N':
  87. _options.res_name = optarg;
  88. break;
  89. case 'p':
  90. _options.aa = false;
  91. break;
  92. case 'q':
  93. _options.quiet = true;
  94. break;
  95. case 'r':
  96. _options.recursive = true;
  97. break;
  98. case 's':
  99. _options.scalemode = SCALE_FIT;
  100. break;
  101. case 't':
  102. _options.thumb_mode = true;
  103. break;
  104. case 'v':
  105. print_version();
  106. exit(EXIT_SUCCESS);
  107. case 'Z':
  108. _options.scalemode = SCALE_ZOOM;
  109. _options.zoom = 1.0;
  110. break;
  111. case 'z':
  112. _options.scalemode = SCALE_ZOOM;
  113. if (sscanf(optarg, "%d", &t) <= 0 || t <= 0) {
  114. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  115. optarg);
  116. exit(EXIT_FAILURE);
  117. }
  118. _options.zoom = (float) t / 100.0;
  119. break;
  120. }
  121. }
  122. _options.filenames = argv + optind;
  123. _options.filecnt = argc - optind;
  124. _options.from_stdin = _options.filecnt == 1 &&
  125. STREQ(_options.filenames[0], "-");
  126. }