Towards GPL
[idzebra-moved-to-github.git] / util / res-test.c
1 /* $Id: res-test.c,v 1.8 2002-08-02 19:26:57 adam Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23
24
25 #include <stdio.h>
26
27 #include <zebrautl.h>
28
29 static void res_print (const char *name, const char *value)
30 {
31     logf (LOG_LOG, "%s=%s", name, value);
32 }
33
34 int main(int argc, char **argv)
35 {
36     char *arg;
37     char *resfile = NULL;
38     char *prefix = NULL;
39     int ret;
40     char *prog = *argv;
41     Res res;
42     int write_flag = 0;
43
44     log_init (LOG_DEFAULT_LEVEL, prog, NULL);
45     while ((ret = options ("wp:v", argv, argc, &arg)) != -2)
46         if (ret == 0)
47             resfile = arg;
48         else if (ret == 'v')
49             log_init (LOG_ALL, prog, NULL);
50         else if (ret == 'p')
51             prefix = arg;
52         else if (ret == 'w')
53             write_flag = 1;
54         else
55         {
56             logf (LOG_FATAL, "Unknown option '-%s'", arg);
57             exit (1);
58         }
59     if (!resfile)
60     {
61         logf (LOG_FATAL, "No resource file given.");
62         exit (1);
63     }
64     res = res_open (resfile);
65     res_trav (res, prefix, res_print);
66     if (write_flag)
67         res_write (res);
68     res_close (res);
69     return 0;
70 }