A Simple X Image Viewer
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

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