A Simple X Image Viewer
 
 
 
 
 
 

113 lines
2.7 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. options_t _options;
  26. const options_t *options = (const options_t*) &_options;
  27. void print_usage() {
  28. printf("usage: sxiv [-dFfhpqrsvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
  29. }
  30. void print_version() {
  31. printf("sxiv - simple x image viewer\n");
  32. printf("Version %s, written by Bert Muennich\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.fixed = 0;
  41. _options.fullscreen = 0;
  42. _options.geometry = NULL;
  43. _options.quiet = 0;
  44. _options.recursive = 0;
  45. while ((opt = getopt(argc, argv, "dFfg:hpqrsvZz:")) != -1) {
  46. switch (opt) {
  47. case '?':
  48. print_usage();
  49. exit(1);
  50. case 'd':
  51. _options.scalemode = SCALE_DOWN;
  52. break;
  53. case 'F':
  54. _options.fixed = 1;
  55. break;
  56. case 'f':
  57. _options.fullscreen = 1;
  58. break;
  59. case 'g':
  60. _options.geometry = optarg;
  61. break;
  62. case 'h':
  63. print_usage();
  64. exit(0);
  65. case 'p':
  66. _options.aa = 0;
  67. break;
  68. case 'q':
  69. _options.quiet = 1;
  70. break;
  71. case 'r':
  72. _options.recursive = 1;
  73. break;
  74. case 's':
  75. _options.scalemode = SCALE_FIT;
  76. break;
  77. case 'v':
  78. print_version();
  79. exit(0);
  80. case 'Z':
  81. _options.scalemode = SCALE_ZOOM;
  82. _options.zoom = 1.0;
  83. break;
  84. case 'z':
  85. _options.scalemode = SCALE_ZOOM;
  86. if (!sscanf(optarg, "%f", &z) || z < 0) {
  87. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  88. optarg);
  89. exit(1);
  90. } else {
  91. _options.zoom = z / 100.0;
  92. }
  93. break;
  94. }
  95. }
  96. _options.filenames = (const char**) argv + optind;
  97. _options.filecnt = argc - optind;
  98. _options.from_stdin = _options.filecnt == 1 &&
  99. strcmp(_options.filenames[0], "-") == 0;
  100. }