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.
 
 
 
 
 
 

106 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 "sxiv.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 [-dFfhpqsvZ] [-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. while ((opt = getopt(argc, argv, "dFfg:hpqsvZz:")) != -1) {
  44. switch (opt) {
  45. case '?':
  46. print_usage();
  47. exit(1);
  48. case 'd':
  49. _options.scalemode = SCALE_DOWN;
  50. break;
  51. case 'F':
  52. _options.fixed = 1;
  53. break;
  54. case 'f':
  55. _options.fullscreen = 1;
  56. break;
  57. case 'g':
  58. _options.geometry = optarg;
  59. break;
  60. case 'h':
  61. print_usage();
  62. exit(0);
  63. case 'p':
  64. _options.aa = 0;
  65. break;
  66. case 'q':
  67. _options.quiet = 1;
  68. break;
  69. case 's':
  70. _options.scalemode = SCALE_FIT;
  71. break;
  72. case 'v':
  73. print_version();
  74. exit(0);
  75. case 'Z':
  76. _options.scalemode = SCALE_ZOOM;
  77. _options.zoom = 1.0;
  78. break;
  79. case 'z':
  80. _options.scalemode = SCALE_ZOOM;
  81. if (!sscanf(optarg, "%f", &z) || z < 0) {
  82. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  83. optarg);
  84. exit(1);
  85. } else {
  86. _options.zoom = z / 100.0;
  87. }
  88. break;
  89. }
  90. }
  91. _options.filenames = (const char**) argv + optind;
  92. _options.filecnt = argc - optind;
  93. }