Nxlib » History » Revision 4
Revision 3 (Stefan Mark, 01/02/2021 06:01 PM) → Revision 4/9 (Stefan Mark, 01/02/2021 06:02 PM)
h1. 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.
[[nxclib]]
[[nxshlib]]
[[commands]]
h2. C Library
<pre><code class="c">int nx_readkvs(const char *kvfn, nxkvs **result);</code></pre>
Loads a config file @kvfn@ into @result@ (has to be freed by %{color:dodgerblue}@nx_freekvs@%).
<pre><code class="c">int nx_loadrc(nxclibrctypes types, nxkvs **kvs);</code></pre>
Loads either the system (@nxrctype_system@) or the user (@nxrctype_user@) config into @kvs@ (has to be freed by %{color:dodgerblue}@nx_freekvs@%). The system config is stored at _/etc/nx/system.rc_, while the user config is stored at _$NX_CONFIG_HOME/session.rc_.
<pre><code class="c">void nx_freekvs(nxkvs *kvs);</code></pre>
Frees the key value store @kvs@.
<pre><code class="c">const char* nx_getkey(const char *name, const nxkvs *kvs);</code></pre>
Returns a pointer to the value of the first key @name@ in @kvs@. NULL if @name@ is not in @kvs@.
<pre><code class="c">int nx_getkeybool(const char *name, int *val, const nxkvs *kvs);</code></pre>
Returns 1 if the key @name@ exists. Gets a 1 into @val@ if the value of key @name@ is "true", 0 otherwise.
<pre><code class="c">int nx_getkeyfloat(const char *name, float *val, const nxkvs *kvs);</code></pre>
Returns 1 if the key @name@ exists and can be parsed as a float. Gets the float value into @val@.
<pre><code class="c">int nx_getkeyint(const char *name, int *val, const nxkvs *kvs);</code></pre>
Returns 1 if the key @name@ exists and can be parsed as an integer. Gets the integer value into @val@.
h2. 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.
<pre>getkey key [-d default] [-n var_name] [-N] [source]</pre>
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@.
<pre>getapp key [source]</pre>
> 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@.
<pre>getkeyarray key [source]</pre>
> 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.
<pre>keyistrue key [source]</pre>
Returns 0 if @key@ was found and its value was true. 1 otherwise.
h2. 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.
<pre>nxgetkey key [-d default] [session]</pre>
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.
<pre>nxhaskey key [session]</pre>
Returns 0 if @key@ was found, 1 otherwise.
<pre>nxapp key [session]</pre>
Returns 0 if @key@App was found, 1 otherwise. Execs value.
<pre>nxiftrue key [session]</pre>
Returns 0 if @key@ was found and its value was true. 1 otherwise.