A Simple X Image Viewer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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