X-Git-Url: https://git.archive.openwrt.org/?p=openwrt.git;a=blobdiff_plain;f=docs%2Fconfig.tex;h=08318b4b6cfb2468354a6e8f592bef9c1287137b;hp=acb4bdf857742ae6490bd71e3970e36b28634e3a;hb=b8b298508f1002878d4619d3cf0ccd3453aa6e86;hpb=a1aab420f0a1a7234b006e1d37358c72350dd3f6 diff --git a/docs/config.tex b/docs/config.tex index acb4bdf857..08318b4b6c 100644 --- a/docs/config.tex +++ b/docs/config.tex @@ -9,40 +9,40 @@ it was written under. Syntax: \begin{Verbatim} -config [] # Section - option # Option +config [""] # Section + option "" # 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 +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 +To be able to load configuration files, you need to include the common functions with: \begin{Verbatim} -. /etc/functions.sh +. /lib/functions.sh \end{Verbatim} -Then you can use \texttt{config\_load \textit{}} to load config files. The function -first checks for \textit{} as absolute filename and falls back to loading +Then you can use \texttt{config\_load \textit{}} to load config files. The function +first checks for \textit{} 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}): +(after including \texttt{/lib/functions.sh}): \begin{Verbatim} config_cb() { - local type="$1" - local name="$2" - # commands to be run for every section + local type="$1" + local name="$2" + # commands to be run for every section } option_cb() { - # commands to be run for every option + # commands to be run for every option } \end{Verbatim} @@ -57,18 +57,34 @@ after \texttt{config\_load} is done. That allows you to process sections both before and after all options were processed. +Another way of iterating on config sections is using the \texttt{config\_foreach} command. + +Syntax: +\begin{Verbatim} +config_foreach [] [] +\end{Verbatim} + +This command will run the supplied function for every single config section in the currently +loaded config. The section name will be passed to the function as argument 1. +If the section type is added to the command line, the function will only be called for +sections of the given type. + + You can access already processed options with the \texttt{config\_get} command Syntax: \begin{Verbatim} -config_get