Project

General

Profile

Actions

Nxlib » History » Revision 1

Revision 1/9 | Next »
Stefan Mark, 01/02/2021 05:55 PM


nxlib

Provides libs for C and Bash to read simple key=value kind of configuration files used throught all parts of nxde. Most or all other tools from nxde will depend on this, except nxinit which provides its own version of nxshlib so it can be independent.

C Library

int nx_readkvs(const char *kvfn, nxkvs **result);

Loads a config file kvfn into result (has to be freed by nx_freekvs).

int nx_loadrc(nxclibrctypes types, nxkvs **kvs);

Loads either the system (nxrctype_system) or the user (nxrctype_user) config into kvs (has to be freed by nx_freekvs). The system config is stored at /etc/nx/system.rc, while the user config is stored at $NX_CONFIG_HOME/session.rc.

void nx_freekvs(nxkvs *kvs);

Frees the key value store kvs.

const char* nx_getkey(const char *name, const nxkvs *kvs);

Returns a pointer to the value of the first key name in kvs. NULL if name is not in kvs.

int nx_getkeybool(const char *name, int *val, const nxkvs *kvs);

Returns 1 if the key name exists. Gets a 1 into val if the value of key name is "true", 0 otherwise.

int nx_getkeyfloat(const char *name, float *val, const nxkvs *kvs);

Returns 1 if the key name exists and can be parsed as a float. Gets the float value into val.

int nx_getkeyint(const char *name, int *val, const nxkvs *kvs);

Returns 1 if the key name exists and can be parsed as an integer. Gets the integer value into val.

Bash Library

All function look at first in $NX_CONFIG_HOME/session.rc, then (if nothing found) in /etc/nx/system.rc. If source is given, either only the system.rc ("sys") or session.rc ("usr") is tried.

getkey key [-d default] [-n var_name] [-N] [source]

Returns 0 if key was found, 1 otherwise. Stores the value for key into $value.
If -d default was given, returns 0 even if key was not found and stores value into $value.
If -n var_name was gives, value is stored in $var_name instead of $value.
If -N was set, value is stored in $key instead of $value.

getapp key [source]

Note that getapp is a stub. Parameters like in getkey do not work and may break operation.

Returns 0 if key was found, 1 otherwise. Stores the value for keyApp_ into $command@.

getkeyarray key [source]

Note that getkeyarray will change: it shall return 0 and 1 like the others
Note that getapp is a stub. Parameters like in getkeyarray do not work and may break operation.

If key was found, interprets its value as an array (in shell notation) and stores its values in $value. The array is empty if key is not found.

keyistrue key [source]

Returns 0 if key was found and its value was true. 1 otherwise.

Commands

Note that all commands are using functions from nxshlib and (currently) send all parameters to the called function, which may cause trouble for all parameters not listed here.

nxgetkey key [-d default] [session]

Returns 0 if key was found, 1 otherwise. Echos the value for key.
If -d default was given, returns 0 even if key was not found and echos its value.

nxhaskey key [session]

Returns 0 if key was found, 1 otherwise.

nxapp key [session]

Returns 0 if @key@App was found, 1 otherwise. Execs value.

nxiftrue key [session]

Returns 0 if key was found and its value was true. 1 otherwise.

Updated by Stefan Mark almost 5 years ago · 9 revisions