Function options now returns arg with error option.
[idzebra-moved-to-github.git] / util / res-test.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: res-test.c,v $
7  * Revision 1.4  1994-10-04 17:47:11  adam
8  * Function options now returns arg with error option.
9  *
10  * Revision 1.3  1994/08/18  11:02:27  adam
11  * Implementation of res_write.
12  *
13  * Revision 1.2  1994/08/18  10:02:01  adam
14  * Module alexpath moved from res.c to alexpath.c. Minor changes in res-test.c
15  *
16  * Revision 1.1  1994/08/18  09:43:51  adam
17  * Development of resource manager. Only missing is res_write.
18  *
19  */
20
21 #include <stdio.h>
22 #include <util.h>
23
24 static void res_print (const char *name, const char *value)
25 {
26     log (LOG_LOG, "%s=%s", name, value);
27 }
28
29 int main(int argc, char **argv)
30 {
31     char *arg;
32     char *resfile = NULL;
33     char *prefix = NULL;
34     int ret;
35     char *prog = *argv;
36     Res res;
37     int write_flag = 0;
38
39     log_init (LOG_DEFAULT_LEVEL, prog, NULL);
40     while ((ret = options ("wp:v", argv, argc, &arg)) != -2)
41         if (ret == 0)
42             resfile = arg;
43         else if (ret == 'v')
44             log_init (LOG_ALL, prog, NULL);
45         else if (ret == 'p')
46             prefix = arg;
47         else if (ret == 'w')
48             write_flag = 1;
49         else
50         {
51             log (LOG_FATAL, "Unknown option '-%s'", arg);
52             exit (1);
53         }
54     if (!resfile)
55     {
56         log (LOG_FATAL, "No resource file given.");
57         exit (1);
58     }
59     res = res_open (resfile);
60     res_trav (res, prefix, res_print);
61     if (write_flag)
62         res_write (res);
63     res_close (res);
64     return 0;
65 }