A Simple X Image Viewer
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

options.c 2.0 KiB

14 år sedan
14 år sedan
14 år sedan
14 år sedan
14 år sedan
14 år sedan
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 [-hv] [-w WIDTH[xHEIGHT]] 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. int opt;
  36. _options.winw = w = 0;
  37. _options.winh = h = 0;
  38. while ((opt = getopt(argc, argv, "hvw:")) != -1) {
  39. switch (opt) {
  40. case '?':
  41. print_usage();
  42. exit(1);
  43. case 'h':
  44. print_usage();
  45. exit(0);
  46. case 'v':
  47. print_version();
  48. exit(0);
  49. case 'w':
  50. if (!sscanf(optarg, "%hux%hu", &w, &h)) {
  51. fprintf(stderr, "sxiv: invalid argument for option -w: %s\n",
  52. optarg);
  53. exit(1);
  54. } else {
  55. _options.winw = (int) w;
  56. _options.winh = (int) h;
  57. }
  58. break;
  59. }
  60. }
  61. if (!_options.winw) {
  62. _options.winw = WIN_WIDTH;
  63. _options.winh = WIN_HEIGHT;
  64. } else if (!_options.winh) {
  65. _options.winh = _options.winw;
  66. }
  67. _options.filenames = (const char**) argv + optind;
  68. _options.filecnt = argc - optind;
  69. }