source: libpipi/trunk/genethumb/genethumb.c @ 2258

Last change on this file since 2258 was 2258, checked in by Sam Hocevar, 12 years ago
  • Add getopt and getopt_long support to genethumb.
File size: 1.5 KB
Line 
1#include "config.h"
2#include "common.h"
3
4#if !defined HAVE_GETOPT_LONG
5#   include "mygetopt.h"
6#elif defined HAVE_GETOPT_H
7#   include <getopt.h>
8#endif
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13
14#include <pipi.h>
15
16#if defined HAVE_GETOPT_LONG
17#   define mygetopt getopt_long
18#   define myoptind optind
19#   define myoptarg optarg
20#   define myoption option
21#endif
22
23#define MOREINFO "Try `%s --help' for more information.\n"
24
25int main(int argc, char *argv[])
26{
27    char *srcname = NULL, *dstname = NULL;
28    pipi_image_t *src, *dst;
29
30    int i, w = 0, h = 0;
31
32    for(;;)
33    {
34        int option_index = 0;
35        static struct myoption long_options[] =
36        {
37            { "geometry",    1, NULL, 'g' },
38        };
39        int c = mygetopt(argc, argv, "g:", long_options, &option_index);
40
41        if(c == -1)
42            break;
43
44        switch(c)
45        {
46        case 'g':
47            w = atoi(myoptarg);
48            if(strchr(myoptarg, 'x'))
49                h = atoi(strchr(myoptarg, 'x') + 1);
50            break;
51        default:
52            fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
53            printf(MOREINFO, argv[0]);
54            return EXIT_FAILURE;
55        }
56    }
57
58    for(i = myoptind; i < argc; i++)
59    {
60        if(!srcname)
61            srcname = argv[i];
62        else
63            dstname = argv[i];
64    }
65
66    src = pipi_load(srcname);
67    dst = pipi_resize(src, w, h);
68    pipi_save(dst, dstname);
69    pipi_free(src);
70    pipi_free(dst);
71
72    return 0;
73}
74
Note: See TracBrowser for help on using the repository browser.