2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * A UniConf moniker that uses an .ini file to look up which moniker it
6 * should use to find the config file/subtree for a particular application.
8 #include "uniconfroot.h"
9 #include "unisubtreegen.h"
10 #include "wvlinkerhack.h"
16 * The moniker from which the auto: moniker retrieves its own settings.
17 * It's a bit silly to override this (since the point is to autoconfigure,
18 * and manually configuring the autoconfiguration thing is silly) but it's
19 * useful for writing unit tests.
21 WvString
uniautogen_moniker("default:ini:/etc/uniconf.conf");
24 * A moniker for finding the "right" config generator for a particular
25 * application, given the application name.
27 * For example, for moniker "auto:org/gnome/Nautilus", we would:
29 * - open /etc/uniconf.conf.
30 * - look for org/gnome/Nautilus in there.
31 * - if it exists, use that value as the config moniker, and return.
32 * - else, look for org/gnome
33 * - if it exists, go get that config moniker, take the subtree
34 * "Nautilus" from there, and return.
35 * - else, look for org
36 * - if it exists, go get that config moniker, take the subtree
37 * "gnome/Nautilus" from there, and return.
39 * - if it exists, go get that config moniker, take the subtree
40 * "org/gnome/Nautilus" from there, and return.
41 * - else, return a null: generator.
43 static IUniConfGen
*creator(WvStringParm s
, IObject
*_obj
)
45 UniConfRoot
cfg((UniConfGen
*)
46 wvcreate
<IUniConfGen
>(uniautogen_moniker
, _obj
), true);
47 const UniConfKey
appname(s
);
49 for (int i
= appname
.numsegments(); i
>= 0; i
--)
51 UniConfKey
prefix(appname
.first(i
)), suffix(appname
.removefirst(i
));
53 if (!!cfg
.xget(prefix
))
55 return new UniSubtreeGen(wvcreate
<IUniConfGen
>(cfg
.xget(prefix
)),
60 return wvcreate
<IUniConfGen
>("null:");
64 static WvMoniker
<IUniConfGen
> autoreg("auto", creator
);