Git init
[external/libiri.git] / iri-config / iri-config.c.in
1 /*
2  * libiri: An IRI/URI/URL parsing library
3  * @(#) $Id$
4  */
5
6 /*
7  * Copyright (c) 2005, 2008 Mo McRoberts.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * 3. The names of the author(s) of this software may not be used to endorse
18  * or promote products derived from this software without specific prior
19  * written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
22  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
23  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
24  * AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifdef HAVE_CONFIG_H
34 # include "config.h"
35 #endif
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <unistd.h>
40 #include <string.h>
41
42 static struct
43 {
44         const char *key;
45         const char *value;
46 } pairs[] = 
47 {
48         { "cflags", "@IRI_CFLAGS@" },
49         { "include", "@IRI_INCLUDES@" },
50         { "libs", "@IRI_LIBS@" },
51         { "version", "@IRI_VERSION@" },
52         { NULL, NULL }
53 };
54
55 static void
56 usage(int status)
57 {
58         int d;
59         
60         puts("Usage: @bindir@/iri-config [OPTIONS]");
61         puts("Options:");
62         for(d = 0; NULL != pairs[d].key; d++)
63         {
64                 printf("\t--%-14s [%s]\n", pairs[d].key, pairs[d].value);
65         }
66         exit(status);
67 }
68
69 int
70 main(int argc, char **argv)
71 {
72         int c, d;
73         
74         if(argc < 2)
75         {
76                 usage(EXIT_SUCCESS);
77         }
78         for(c = 1 ; c < argc; c++)
79         {
80                 if(argv[c][0] == '-' && argv[c][1] == '-')
81                 {
82                         for(d = 0; NULL != pairs[d].key; d++)
83                         {
84                                 if(0 == strcmp(&(argv[c][2]), pairs[d].key))
85                                 {
86                                         break;
87                                 }
88                         }
89                         if(NULL == pairs[d].key)
90                         {
91                                 usage(EXIT_FAILURE);
92                         }
93                 }
94                 else
95                 {
96                         usage(EXIT_FAILURE);
97                 }
98         }
99         for(c = 1 ; c < argc; c++)
100         {
101                 for(d = 0; NULL != pairs[d].key; d++)
102                 {
103                         if(0 == strcmp(&(argv[c][2]), pairs[d].key))
104                         {
105                                 printf("%s\n", pairs[d].value);
106                                 break;
107                         }
108                 }
109         }
110         return 0;
111 }