WvStreams
|
00001 /* 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * A UniConf moniker that uses an .ini file to look up which moniker it 00006 * should use to find the config file/subtree for a particular application. 00007 */ 00008 #include "uniconfroot.h" 00009 #include "unisubtreegen.h" 00010 #include "wvlinkerhack.h" 00011 00012 WV_LINK(UniAutoGen); 00013 00014 00021 WvString uniautogen_moniker("default:ini:/etc/uniconf.conf"); 00022 00023 /* 00024 * A moniker for finding the "right" config generator for a particular 00025 * application, given the application name. 00026 * 00027 * For example, for moniker "auto:org/gnome/Nautilus", we would: 00028 * 00029 * - open /etc/uniconf.conf. 00030 * - look for org/gnome/Nautilus in there. 00031 * - if it exists, use that value as the config moniker, and return. 00032 * - else, look for org/gnome 00033 * - if it exists, go get that config moniker, take the subtree 00034 * "Nautilus" from there, and return. 00035 * - else, look for org 00036 * - if it exists, go get that config moniker, take the subtree 00037 * "gnome/Nautilus" from there, and return. 00038 * - else, look for / 00039 * - if it exists, go get that config moniker, take the subtree 00040 * "org/gnome/Nautilus" from there, and return. 00041 * - else, return a null: generator. 00042 */ 00043 static IUniConfGen *creator(WvStringParm s, IObject *_obj) 00044 { 00045 UniConfRoot cfg((UniConfGen *) 00046 wvcreate<IUniConfGen>(uniautogen_moniker, _obj), true); 00047 const UniConfKey appname(s); 00048 00049 for (int i = appname.numsegments(); i >= 0; i--) 00050 { 00051 UniConfKey prefix(appname.first(i)), suffix(appname.removefirst(i)); 00052 00053 if (!!cfg.xget(prefix)) 00054 { 00055 return new UniSubtreeGen(wvcreate<IUniConfGen>(cfg.xget(prefix)), 00056 suffix); 00057 } 00058 } 00059 00060 return wvcreate<IUniConfGen>("null:"); 00061 } 00062 00063 00064 static WvMoniker<IUniConfGen> autoreg("auto", creator);