A Simple X Image Viewer
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

132 строки
3.0 KiB

  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
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #define _XOPEN_SOURCE
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <unistd.h>
  23. #include "config.h"
  24. #include "options.h"
  25. #include "util.h"
  26. options_t _options;
  27. const options_t *options = (const options_t*) &_options;
  28. void print_usage() {
  29. printf("usage: sxiv [-cdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] [-z ZOOM] FILES...\n");
  30. }
  31. void print_version() {
  32. printf("sxiv %s - simple x image viewer\n", VERSION);
  33. }
  34. void parse_options(int argc, char **argv) {
  35. float z;
  36. int n, opt;
  37. _options.startnum = 0;
  38. _options.scalemode = SCALE_MODE;
  39. _options.zoom = 1.0;
  40. _options.aa = 1;
  41. _options.thumbnails = 0;
  42. _options.fixed = 0;
  43. _options.fullscreen = 0;
  44. _options.geometry = NULL;
  45. _options.quiet = 0;
  46. _options.clean_cache = 0;
  47. _options.recursive = 0;
  48. while ((opt = getopt(argc, argv, "cdFfg:hn:pqrstvZz:")) != -1) {
  49. switch (opt) {
  50. case '?':
  51. print_usage();
  52. exit(1);
  53. case 'c':
  54. _options.clean_cache = 1;
  55. break;
  56. case 'd':
  57. _options.scalemode = SCALE_DOWN;
  58. break;
  59. case 'F':
  60. _options.fixed = 1;
  61. break;
  62. case 'f':
  63. _options.fullscreen = 1;
  64. break;
  65. case 'g':
  66. _options.geometry = optarg;
  67. break;
  68. case 'h':
  69. print_usage();
  70. exit(0);
  71. case 'n':
  72. if (!sscanf(optarg, "%d", &n) || n < 1) {
  73. fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
  74. optarg);
  75. exit(1);
  76. } else {
  77. _options.startnum = n - 1;
  78. }
  79. break;
  80. case 'p':
  81. _options.aa = 0;
  82. break;
  83. case 'q':
  84. _options.quiet = 1;
  85. break;
  86. case 'r':
  87. _options.recursive = 1;
  88. break;
  89. case 's':
  90. _options.scalemode = SCALE_FIT;
  91. break;
  92. case 't':
  93. _options.thumbnails = 1;
  94. break;
  95. case 'v':
  96. print_version();
  97. exit(0);
  98. case 'Z':
  99. _options.scalemode = SCALE_ZOOM;
  100. _options.zoom = 1.0;
  101. break;
  102. case 'z':
  103. _options.scalemode = SCALE_ZOOM;
  104. if (!sscanf(optarg, "%f", &z) || z < 0) {
  105. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  106. optarg);
  107. exit(1);
  108. } else {
  109. _options.zoom = z / 100.0;
  110. }
  111. break;
  112. }
  113. }
  114. _options.filenames = argv + optind;
  115. _options.filecnt = argc - optind;
  116. _options.from_stdin = _options.filecnt == 1 &&
  117. strcmp(_options.filenames[0], "-") == 0;
  118. }