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.
 
 
 
 
 
 

113 line
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 <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 [-dfhpsvZ] [-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. while ((opt = getopt(argc, argv, "dfhpsvw:Zz:")) != -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.fullscreen = 1;
  53. break;
  54. case 'h':
  55. print_usage();
  56. exit(0);
  57. case 'p':
  58. _options.aa = 0;
  59. break;
  60. case 's':
  61. _options.scalemode = SCALE_FIT;
  62. break;
  63. case 'v':
  64. print_version();
  65. exit(0);
  66. case 'w':
  67. if (!sscanf(optarg, "%hux%hu", &w, &h)) {
  68. fprintf(stderr, "sxiv: invalid argument for option -w: %s\n",
  69. optarg);
  70. exit(1);
  71. } else {
  72. _options.winw = (int) w;
  73. _options.winh = (int) h;
  74. }
  75. break;
  76. case 'Z':
  77. _options.scalemode = SCALE_ZOOM;
  78. _options.zoom = 1.0;
  79. break;
  80. case 'z':
  81. _options.scalemode = SCALE_ZOOM;
  82. if (!sscanf(optarg, "%f", &z) || z < 0) {
  83. fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
  84. optarg);
  85. exit(1);
  86. } else {
  87. _options.zoom = z / 100.0;
  88. }
  89. break;
  90. }
  91. }
  92. if (!_options.winw) {
  93. _options.winw = WIN_WIDTH;
  94. _options.winh = WIN_HEIGHT;
  95. } else if (!_options.winh) {
  96. _options.winh = _options.winw;
  97. }
  98. _options.filenames = (const char**) argv + optind;
  99. _options.filecnt = argc - optind;
  100. }