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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* sxiv: options.c
  2. * Copyright (c) 2012 Bert Muennich <be.muennich at googlemail.com>
  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 _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. "[-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.quiet = false;
  48. _options.thumb_mode = false;
  49. _options.clean_cache = false;
  50. while ((opt = getopt(argc, argv, "bcdFfg:hn:pqrstvZz:")) != -1) {
  51. switch (opt) {
  52. case '?':
  53. print_usage();
  54. exit(EXIT_FAILURE);
  55. case 'b':
  56. _options.hide_bar = true;
  57. break;
  58. case 'c':
  59. _options.clean_cache = true;
  60. break;
  61. case 'd':
  62. _options.scalemode = SCALE_DOWN;
  63. break;
  64. case 'F':
  65. _options.fixed_win = true;
  66. break;
  67. case 'f':
  68. _options.fullscreen = true;
  69. break;
  70. case 'g':
  71. _options.geometry = optarg;
  72. break;
  73. case 'h':
  74. print_usage();
  75. exit(EXIT_SUCCESS);
  76. case 'n':
  77. if (sscanf(optarg, "%d", &t) <= 0 || t < 1) {
  78. fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
  79. optarg);
  80. exit(EXIT_FAILURE);
  81. } else {
  82. _options.startnum = t - 1;
  83. }
  84. break;
  85. case 'p':
  86. _options.aa = false;
  87. break;
  88. case 'q':
  89. _options.quiet = true;
  90. break;
  91. case 'r':
  92. _options.recursive = true;
  93. break;
  94. case 's':
  95. _options.scalemode = SCALE_FIT;
  96. break;
  97. case 't':
  98. _options.thumb_mode = true;
  99. break;
  100. case 'v':
  101. print_version();
  102. exit(EXIT_SUCCESS);
  103. case 'Z':
  104. _options.scalemode = SCALE_ZOOM;
  105. _options.zoom = 1.0;
  106. break;
  107. case 'z':
  108. _options.scalemode = SCALE_ZOOM;
  109. if (sscanf(optarg, "%d", &t) <= 0 || t <= 0) {
  110. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  111. optarg);
  112. exit(EXIT_FAILURE);
  113. }
  114. _options.zoom = (float) t / 100.0;
  115. break;
  116. }
  117. }
  118. _options.filenames = argv + optind;
  119. _options.filecnt = argc - optind;
  120. _options.from_stdin = _options.filecnt == 1 &&
  121. STREQ(_options.filenames[0], "-");
  122. }