A Simple X Image Viewer
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

132 行
3.2 KiB

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