|
|
|
@ -17,17 +17,23 @@
|
|
|
|
|
|
|
|
|
|
#include "lkc.h"
|
|
|
|
|
|
|
|
|
|
// 定义警告信息输出函数
|
|
|
|
|
static void conf_warning(const char *fmt, ...)
|
|
|
|
|
__attribute__ ((format (printf, 1, 2)));
|
|
|
|
|
|
|
|
|
|
// 定义普通信息输出函数
|
|
|
|
|
static void conf_message(const char *fmt, ...)
|
|
|
|
|
__attribute__ ((format (printf, 1, 2)));
|
|
|
|
|
|
|
|
|
|
// 配置文件名
|
|
|
|
|
static const char *conf_filename;
|
|
|
|
|
// 当前行号
|
|
|
|
|
static int conf_lineno, conf_warnings, conf_unsaved;
|
|
|
|
|
|
|
|
|
|
// 默认配置文件名
|
|
|
|
|
const char conf_defname[] = ".defconfig";
|
|
|
|
|
|
|
|
|
|
// 输出警告信息
|
|
|
|
|
static void conf_warning(const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
@ -39,6 +45,7 @@ static void conf_warning(const char *fmt, ...)
|
|
|
|
|
conf_warnings++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 默认的消息回调函数
|
|
|
|
|
static void conf_default_message_callback(const char *fmt, va_list ap)
|
|
|
|
|
{
|
|
|
|
|
printf("#\n# ");
|
|
|
|
@ -46,13 +53,17 @@ static void conf_default_message_callback(const char *fmt, va_list ap)
|
|
|
|
|
printf("\n#\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 消息回调函数指针
|
|
|
|
|
static void (*conf_message_callback) (const char *fmt, va_list ap) =
|
|
|
|
|
conf_default_message_callback;
|
|
|
|
|
|
|
|
|
|
// 设置消息回调函数
|
|
|
|
|
void conf_set_message_callback(void (*fn) (const char *fmt, va_list ap))
|
|
|
|
|
{
|
|
|
|
|
conf_message_callback = fn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 输出消息信息
|
|
|
|
|
static void conf_message(const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
@ -62,6 +73,7 @@ static void conf_message(const char *fmt, ...)
|
|
|
|
|
conf_message_callback(fmt, ap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取配置文件名
|
|
|
|
|
const char *conf_get_configname(void)
|
|
|
|
|
{
|
|
|
|
|
char *name = getenv(PRODUCT_ENV"_CONFIG");
|
|
|
|
@ -69,11 +81,13 @@ const char *conf_get_configname(void)
|
|
|
|
|
return name ? name : ".config";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取自动配置文件名
|
|
|
|
|
const char *conf_get_autoconfig_name(void)
|
|
|
|
|
{
|
|
|
|
|
return getenv(PRODUCT_ENV"_AUTOCONFIG");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 展开配置值中的变量
|
|
|
|
|
static char *conf_expand_value(const char *in)
|
|
|
|
|
{
|
|
|
|
|
struct symbol *sym;
|
|
|
|
@ -100,6 +114,7 @@ static char *conf_expand_value(const char *in)
|
|
|
|
|
return res_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取默认配置文件名
|
|
|
|
|
char *conf_get_default_confname(void)
|
|
|
|
|
{
|
|
|
|
|
struct stat buf;
|
|
|
|
@ -116,6 +131,7 @@ char *conf_get_default_confname(void)
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置符号值
|
|
|
|
|
static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
|
|
|
|
|
{
|
|
|
|
|
char *p2;
|
|
|
|
@ -127,7 +143,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
|
|
|
|
|
sym->flags |= def_flags;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
/* fall through */
|
|
|
|
|
// 跌落至下一个case
|
|
|
|
|
case S_BOOLEAN:
|
|
|
|
|
if (p[0] == 'y') {
|
|
|
|
|
sym->def[def].tri = yes;
|
|
|
|
@ -150,7 +166,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
|
|
|
|
|
sym->type = S_STRING;
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
/* fall through */
|
|
|
|
|
// 跌落至下一个case
|
|
|
|
|
case S_STRING:
|
|
|
|
|
if (*p++ != '"')
|
|
|
|
|
break;
|
|
|
|
@ -166,7 +182,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
|
|
|
|
|
conf_warning("invalid string found");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
/* fall through */
|
|
|
|
|
// 跌落至下一个case
|
|
|
|
|
case S_INT:
|
|
|
|
|
case S_HEX:
|
|
|
|
|
done:
|
|
|
|
@ -186,6 +202,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 增加字节到行缓冲区
|
|
|
|
|
#define LINE_GROWTH 16
|
|
|
|
|
static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
|
|
|
|
|
{
|
|
|
|
@ -207,6 +224,7 @@ static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 兼容getline函数
|
|
|
|
|
static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream)
|
|
|
|
|
{
|
|
|
|
|
char *line = *lineptr;
|
|
|
|
@ -220,7 +238,7 @@ static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream)
|
|
|
|
|
if (add_byte(c, &line, slen, n) < 0)
|
|
|
|
|
goto e_out;
|
|
|
|
|
slen++;
|
|
|
|
|
/* fall through */
|
|
|
|
|
// 跌落至下一个case
|
|
|
|
|
case EOF:
|
|
|
|
|
if (add_byte('\0', &line, slen, n) < 0)
|
|
|
|
|
goto e_out;
|
|
|
|
@ -241,6 +259,7 @@ e_out:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 读取简单的配置文件
|
|
|
|
|
int conf_read_simple(const char *name, int def)
|
|
|
|
|
{
|
|
|
|
|
FILE *in = NULL;
|
|
|
|
@ -300,7 +319,7 @@ load:
|
|
|
|
|
case S_STRING:
|
|
|
|
|
if (sym->def[def].val)
|
|
|
|
|
free(sym->def[def].val);
|
|
|
|
|
/* fall through */
|
|
|
|
|
// 跌落至下一个case
|
|
|
|
|
default:
|
|
|
|
|
sym->def[def].val = NULL;
|
|
|
|
|
sym->def[def].tri = no;
|
|
|
|
@ -403,6 +422,7 @@ setsym:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 读取配置文件
|
|
|
|
|
int conf_read(const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct symbol *sym;
|
|
|
|
@ -418,7 +438,7 @@ int conf_read(const char *name)
|
|
|
|
|
if (sym_is_choice(sym) || (sym->flags & SYMBOL_AUTO))
|
|
|
|
|
continue;
|
|
|
|
|
if (sym_has_value(sym) && (sym->flags & SYMBOL_WRITE)) {
|
|
|
|
|
/* check that calculated value agrees with saved value */
|
|
|
|
|
// 检查计算值是否与保存值一致
|
|
|
|
|
switch (sym->type) {
|
|
|
|
|
case S_BOOLEAN:
|
|
|
|
|
case S_TRISTATE:
|
|
|
|
@ -426,33 +446,30 @@ int conf_read(const char *name)
|
|
|
|
|
break;
|
|
|
|
|
if (!sym_is_choice(sym))
|
|
|
|
|
continue;
|
|
|
|
|
/* fall through */
|
|
|
|
|
// 跌落至下一个case
|
|
|
|
|
default:
|
|
|
|
|
if (!strcmp(sym->curr.val, sym->def[S_DEF_USER].val))
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (!sym_has_value(sym) && !(sym->flags & SYMBOL_WRITE))
|
|
|
|
|
/* no previous value and not saved */
|
|
|
|
|
// 没有先前值且未保存
|
|
|
|
|
continue;
|
|
|
|
|
conf_unsaved++;
|
|
|
|
|
/* maybe print value in verbose mode... */
|
|
|
|
|
// 在详细模式下可能打印值...
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for_all_symbols(i, sym) {
|
|
|
|
|
if (sym_has_value(sym) && !sym_is_choice_value(sym)) {
|
|
|
|
|
/* Reset values of generates values, so they'll appear
|
|
|
|
|
* as new, if they should become visible, but that
|
|
|
|
|
* doesn't quite work if the Kconfig and the saved
|
|
|
|
|
* configuration disagree.
|
|
|
|
|
*/
|
|
|
|
|
// 重置生成值的值,以便它们在出现时会显示为新值,
|
|
|
|
|
// 但如果Kconfig和保存的配置不一致,则不起作用。
|
|
|
|
|
if (sym->visible == no && !conf_unsaved)
|
|
|
|
|
sym->flags &= ~SYMBOL_DEF_USER;
|
|
|
|
|
switch (sym->type) {
|
|
|
|
|
case S_STRING:
|
|
|
|
|
case S_INT:
|
|
|
|
|
case S_HEX:
|
|
|
|
|
/* Reset a string value if it's out of range */
|
|
|
|
|
// 如果字符串值超出范围,则重置字符串值
|
|
|
|
|
if (sym_string_within_range(sym, sym->def[S_DEF_USER].val))
|
|
|
|
|
break;
|
|
|
|
|
sym->flags &= ~(SYMBOL_VALID|SYMBOL_DEF_USER);
|
|
|
|
|