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.
 
 
 
 
 
 

118 line
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 <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 [-dfhpsvWZ] [-w WIDTH[xHEIGHT]] [-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. unsigned short w, h;
  35. float z;
  36. int opt;
  37. _options.scalemode = SCALE_MODE;
  38. _options.zoom = 1.0;
  39. _options.aa = 1;
  40. _options.winw = w = 0;
  41. _options.winh = h = 0;
  42. _options.fullscreen = 0;
  43. _options.warn = 0;
  44. while ((opt = getopt(argc, argv, "dfhpsvWw:Zz:")) != -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.fullscreen = 1;
  54. break;
  55. case 'h':
  56. print_usage();
  57. exit(0);
  58. case 'p':
  59. _options.aa = 0;
  60. break;
  61. case 's':
  62. _options.scalemode = SCALE_FIT;
  63. break;
  64. case 'v':
  65. print_version();
  66. exit(0);
  67. case 'W':
  68. _options.warn = 1;
  69. break;
  70. case 'w':
  71. if (!sscanf(optarg, "%hux%hu", &w, &h)) {
  72. fprintf(stderr, "sxiv: invalid argument for option -w: %s\n",
  73. optarg);
  74. exit(1);
  75. } else {
  76. _options.winw = (int) w;
  77. _options.winh = (int) h;
  78. }
  79. break;
  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. if (!_options.winw) {
  97. _options.winw = WIN_WIDTH;
  98. _options.winh = WIN_HEIGHT;
  99. } else if (!_options.winh) {
  100. _options.winh = _options.winw;
  101. }
  102. _options.filenames = (const char**) argv + optind;
  103. _options.filecnt = argc - optind;
  104. }