summaryrefslogtreecommitdiffstats
path: root/docs/config.tex
diff options
context:
space:
mode:
authornbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>2006-10-13 22:41:34 +0000
committernbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>2006-10-13 22:41:34 +0000
commitdfe52f0a791b7f715dabfc7c64c08a7d2d423e8b (patch)
treeb5f1b33afa73ec7f1f84d6a52a72258dccc435bd /docs/config.tex
parentf52d66ff00b24111f87c274d3d7085ef2e1d27b1 (diff)
add initial version of our new documentation - not too pretty yet, but will be improved
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@5060 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'docs/config.tex')
-rw-r--r--docs/config.tex79
1 files changed, 79 insertions, 0 deletions
diff --git a/docs/config.tex b/docs/config.tex
new file mode 100644
index 000000000..44b6689b5
--- /dev/null
+++ b/docs/config.tex
@@ -0,0 +1,79 @@
+\subsubsection{Structure of the configuration files}
+
+The config files are divided into sections and options/values.
+
+Every section has a type, but does not necessarily have a name.
+Every option has a name and a value and is assigned to the section
+it was written under.
+
+Syntax:
+
+\begin{Verbatim}
+config <type> [<name>] # Section
+ option <name> <value> # Option
+\end{Verbatim}
+
+Every parameter needs to be a single string and is formatted exactly
+like a parameter for a shell function. The same rules for Quoting and
+special characters also apply, as it is parsed by the shell.
+
+\subsubsection{Parsing configuration files in custom scripts}
+
+To be able to load configuration files, you need to include the common
+functions with:
+
+\begin{Verbatim}
+. /etc/functions.sh
+\end{Verbatim}
+
+Then you can use \texttt{config\_load \textit{<name>}} to load config files. The function
+first checks for \textit{<name>} as absolute filename and falls back to loading
+it from \texttt{/etc/config} (which is the most common way of using it).
+
+If you want to use special callbacks for sections and/or options, you
+need to define the following shell functions before running \texttt{config\_load}
+(after including \texttt{/etc/functions.sh}):
+
+\begin{Verbatim}
+config_cb() {
+ local type="$1"
+ local name="$2"
+ # commands to be run for every section
+}
+
+option_cb() {
+ # commands to be run for every option
+}
+\end{Verbatim}
+
+You can also alter \texttt{option\_cb} from \texttt{config\_cb} based on the section type.
+This allows you to process every single config section based on its type
+individually.
+
+\texttt{config\_cb} is run every time a new section starts (before options are being
+processed). You can access the last section through the \texttt{CONFIG\_SECTION}
+variable. Also an extra call to \texttt{config\_cb} (without a new section) is generated
+after \texttt{config\_load} is done.
+That allows you to process sections both before and after all options were
+processed.
+
+You can access already processed options with the \texttt{config\_get} command
+Syntax:
+
+\begin{Verbatim}
+config_get <section> <option> # prints the value of the option
+config_get <variable> <section> <option> # stores the value inside the variable
+\end{Verbatim}
+
+In busybox ash the three-option \texttt{config\_get} is faster, because it does not
+result in an extra fork, so it is the preferred way.
+
+Additionally you can also modify or add options to sections by using the
+\texttt{config\_set} command.
+
+Syntax:
+
+\begin{Verbatim}
+config_set <section> <option> <value>
+\end{Verbatim}
+