A Simple X Image Viewer
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

121 行
2.8 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 [-adFfhpqrstvZ] [-g GEOMETRY] [-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 opt;
  37. _options.scalemode = SCALE_MODE;
  38. _options.zoom = 1.0;
  39. _options.aa = 1;
  40. _options.thumbnails = 0;
  41. _options.fixed = 0;
  42. _options.fullscreen = 0;
  43. _options.geometry = NULL;
  44. _options.all = 0;
  45. _options.quiet = 0;
  46. _options.recursive = 0;
  47. while ((opt = getopt(argc, argv, "adFfg:hpqrstvZz:")) != -1) {
  48. switch (opt) {
  49. case '?':
  50. print_usage();
  51. exit(1);
  52. case 'a':
  53. _options.all = 1;
  54. break;
  55. case 'd':
  56. _options.scalemode = SCALE_DOWN;
  57. break;
  58. case 'F':
  59. _options.fixed = 1;
  60. break;
  61. case 'f':
  62. _options.fullscreen = 1;
  63. break;
  64. case 'g':
  65. _options.geometry = optarg;
  66. break;
  67. case 'h':
  68. print_usage();
  69. exit(0);
  70. case 'p':
  71. _options.aa = 0;
  72. break;
  73. case 'q':
  74. _options.quiet = 1;
  75. break;
  76. case 'r':
  77. _options.recursive = 1;
  78. break;
  79. case 's':
  80. _options.scalemode = SCALE_FIT;
  81. break;
  82. case 't':
  83. _options.thumbnails = 1;
  84. break;
  85. case 'v':
  86. print_version();
  87. exit(0);
  88. case 'Z':
  89. _options.scalemode = SCALE_ZOOM;
  90. _options.zoom = 1.0;
  91. break;
  92. case 'z':
  93. _options.scalemode = SCALE_ZOOM;
  94. if (!sscanf(optarg, "%f", &z) || z < 0) {
  95. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  96. optarg);
  97. exit(1);
  98. } else {
  99. _options.zoom = z / 100.0;
  100. }
  101. break;
  102. }
  103. }
  104. _options.filenames = (const char**) argv + optind;
  105. _options.filecnt = argc - optind;
  106. _options.from_stdin = _options.filecnt == 1 &&
  107. strcmp(_options.filenames[0], "-") == 0;
  108. }