A Simple X Image Viewer
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

options.c 2.8 KiB

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