wmcore: use wmgeneral functions in libdockapp instead of the private copy.
[dockapps.git] / fookb / params.c
blob7bbacae402dc4280bb6efe87caebdaf377a28d7f
1 #include <stdio.h>
2 #include <string.h> /* strlen & strcat */
3 #include <ctype.h> /* toupper */
4 #include <stdlib.h>
5 #include <WINGs/WUtil.h>
6 #include "params.h"
7 #include "opts.h"
9 /* Let's make lint happy */
10 #define lputs(x) (void)puts(x)
12 char *read_param(char *string)
14 WMPropList *pl;
15 WMPropList *value;
16 WMPropList *tmp;
17 char *path;
18 char *result;
20 /* Command line parameters take precedence over all */
22 if (!strcmp(string, "Icon1")) {
23 if (icon1)
24 return icon1;
26 result = DEFAULT_ICON1;
28 if (!strcmp(string, "Icon2")) {
29 if (icon2)
30 return icon2;
32 result = DEFAULT_ICON2;
34 if (!strcmp(string, "Icon3")) {
35 if (icon3)
36 return icon3;
38 result = DEFAULT_ICON3;
40 if (!strcmp(string, "Icon4")) {
41 if (icon4)
42 return icon4;
44 result = DEFAULT_ICON4;
46 if (!strcmp(string, "IconBoom")) {
47 if (iconboom)
48 return iconboom;
50 result = DEFAULT_ICON_BOOM;
52 if (!strcmp(string, "Sound"))
53 result = DEFAULT_SOUND;
54 if (!strcmp(string, "Command"))
55 result = DEFAULT_COMMAND;
58 * Here we start the game with property lists.
59 * pl will be property list, read from DEFAULTS_FILE.
60 * tmp will be temporary key for this property list,
61 * constructed using ``string'', supplied to function.
62 * value will be property list, which contain the value
63 * of parameter
66 path = wexpandpath(DEFAULTS_FILE);
67 pl = WMReadPropListFromFile(path);
68 wfree(path);
70 if (!pl) {
71 return result;
74 tmp = WMCreatePLString(string);
75 value = WMGetFromPLDictionary(pl, tmp);
76 WMReleasePropList(tmp);
79 * pl and value objects will exist as long as fookb is running
82 if (!value) {
83 lputs("Cannot find in config file value for: ");
84 lputs(string);
85 exit(EXIT_FAILURE);
88 if (!WMIsPLString(value)) {
89 lputs("Value for: ");
90 lputs(string);
91 lputs("in config file is not a string.");
92 exit(EXIT_FAILURE);
95 result = WMGetFromPLString(value);
97 if (!result) {
98 lputs("Something wrong with libWUtils :(");
99 lputs("Please report this error to fookb author.");
100 exit(EXIT_FAILURE);
103 return result;