A Simple X Image Viewer
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

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