A Simple X Image Viewer
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 2 /* for getopt(3) */
  19. #include <unistd.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <stdio.h>
  23. #include "options.h"
  24. #include "util.h"
  25. #define _IMAGE_CONFIG
  26. #include "config.h"
  27. options_t _options;
  28. const options_t *options = (const options_t*) &_options;
  29. void print_usage() {
  30. printf("usage: sxiv [-cdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] [-z ZOOM] FILES...\n");
  31. }
  32. void print_version() {
  33. printf("sxiv %s - simple x image viewer\n", VERSION);
  34. }
  35. void parse_options(int argc, char **argv) {
  36. float z;
  37. int n, opt;
  38. _options.startnum = 0;
  39. _options.scalemode = SCALE_MODE;
  40. _options.zoom = 1.0;
  41. _options.aa = 1;
  42. _options.thumbnails = 0;
  43. _options.fixed = 0;
  44. _options.fullscreen = 0;
  45. _options.geometry = NULL;
  46. _options.quiet = 0;
  47. _options.clean_cache = 0;
  48. _options.recursive = 0;
  49. while ((opt = getopt(argc, argv, "cdFfg:hn:pqrstvZz:")) != -1) {
  50. switch (opt) {
  51. case '?':
  52. print_usage();
  53. exit(1);
  54. case 'c':
  55. _options.clean_cache = 1;
  56. break;
  57. case 'd':
  58. _options.scalemode = SCALE_DOWN;
  59. break;
  60. case 'F':
  61. _options.fixed = 1;
  62. break;
  63. case 'f':
  64. _options.fullscreen = 1;
  65. break;
  66. case 'g':
  67. _options.geometry = optarg;
  68. break;
  69. case 'h':
  70. print_usage();
  71. exit(0);
  72. case 'n':
  73. if (!sscanf(optarg, "%d", &n) || n < 1) {
  74. fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
  75. optarg);
  76. exit(1);
  77. } else {
  78. _options.startnum = n - 1;
  79. }
  80. break;
  81. case 'p':
  82. _options.aa = 0;
  83. break;
  84. case 'q':
  85. _options.quiet = 1;
  86. break;
  87. case 'r':
  88. _options.recursive = 1;
  89. break;
  90. case 's':
  91. _options.scalemode = SCALE_FIT;
  92. break;
  93. case 't':
  94. _options.thumbnails = 1;
  95. break;
  96. case 'v':
  97. print_version();
  98. exit(0);
  99. case 'Z':
  100. _options.scalemode = SCALE_ZOOM;
  101. _options.zoom = 1.0;
  102. break;
  103. case 'z':
  104. _options.scalemode = SCALE_ZOOM;
  105. if (!sscanf(optarg, "%f", &z) || z < 0) {
  106. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  107. optarg);
  108. exit(1);
  109. } else {
  110. _options.zoom = z / 100.0;
  111. }
  112. break;
  113. }
  114. }
  115. _options.filenames = argv + optind;
  116. _options.filecnt = argc - optind;
  117. _options.from_stdin = _options.filecnt == 1 &&
  118. strcmp(_options.filenames[0], "-") == 0;
  119. }