Chinaunix首页 | 论坛 | 博客
  • 博客访问: 509399
  • 博文数量: 110
  • 博客积分: 3971
  • 博客等级: 中校
  • 技术积分: 1175
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-20 23:27
文章分类

全部博文(110)

文章存档

2015年(2)

2014年(1)

2013年(1)

2011年(9)

2010年(28)

2009年(12)

2008年(13)

2007年(23)

2006年(21)

我的朋友

分类: WINDOWS

2010-07-21 16:54:43

1.3 Advanced configuration

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:

  config       [""]      # Section
      option   ""       # Option

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.

每一个参量都是一个单一的字符串对象,其格式和SHELL功能的参量完全一样。引用同样的规则和特殊字符都可以运用,因为它是由SHELL解析的。

Parsing configuration files in custom scripts

To be able to load configuration files, you need to include the common functions with:

为了写入配置文件,你需要包括以下的常见功能:

  . /etc/functions.sh

Then you can use config_load to load config files. The function first checks for as absolute filename and falls back to loading it from /etc/config (which is the most common way of using it).

然后你可以使用config_load 来写入配置文件。该功能首先把认为是绝对的文件名,然后回落,从/etc/config进行编写(这是最常用的方式)

If you want to use special callbacks for sections and/or options, you need to define the following shell functions before running config_load (after including /etc/functions.sh):

如果你想针对章节或选择项使用特殊的回调函数,在运行config_load (在包含/etc/functions.sh之后)之前,你需要确定SHELL功能。

  config_cb() {
      local type="$1"
      local name="$2"
      # commands to be run for every section
  }
  
  option_cb() {
      # commands to be run for every option
  }

You can also alter option_cb from config_cb based on the section type. This allows you to process every single config section based on its type individually.

你可以根据片段类型,更改来自config_cboption_cb。这让你可以根据其类型,处理不同的配置片段。

config_cb is run every time a new section starts (before options are being processed). You can access the last section through the CONFIG_SECTION variable. Also an extra call to config_cb (without a new section) is generated after 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 config_foreach command.

config_cb每次都运行一个新的片段(在选择项被处理之前)。你可以用CONFIG_SECTION变量访问最后一个章节。config_load 完成之后,将产生一个到config_cb(不带新的章节)的呼叫。这样一来,你就可以在所有选项都处理前或后,处理片段了。另一种迭代配置片段的方式是使用config_foreach指令。

Syntax:

  config_foreach  [] []

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.

该指令将在当前加载的配置里,运行每一个简单配置片段的功能。该片段的名称将作为参数1,将传输到一些功能上。如果片段类型添加到了指令行,这些功能将针对给定类型的片段被呼叫。

You can access already processed options with the config_get command Syntax:

你可以用config_get命令语法访问已经处理的选项。

  # print the value of the option
  config_get 

 
阅读(1126) | 评论(0) | 转发(0) |
0

上一篇:openwrt1

下一篇:openwrt4

给主人留下些什么吧!~~