프로그램의 설정 파일을 파싱할 경우 참고 코드
- android/external/bluetooth/bluedroid/main/bte_conf.c
/*******************************************************************************
**
** Function bte_load_conf
**
** Description Read conf entry from p_path file one by one and call
** the corresponding config function
**
** Returns None
**
*******************************************************************************/
void bte_load_conf(const char *p_path)
{
FILE *p_file;
char *p_name;
char *p_value;
conf_entry_t *p_entry;
char line[CONF_MAX_LINE_LEN+1]; /* add 1 for \0 char */
BOOLEAN name_matched;
ALOGI("Attempt to load stack conf from %s", p_path);
if ((p_file = fopen(p_path, "r")) != NULL)
{
/* read line by line */
while (fgets(line, CONF_MAX_LINE_LEN+1, p_file) != NULL)
{
if (line[0] == CONF_COMMENT)
continue;
p_name = strtok(line, CONF_DELIMITERS);
if (NULL == p_name)
{
continue;
}
p_value = strtok(NULL, CONF_VALUES_DELIMITERS);
if (NULL == p_value)
{
ALOGW("bte_load_conf: missing value for name: %s", p_name);
continue;
}
name_matched = FALSE;
p_entry = (conf_entry_t *)conf_table;
while (p_entry->conf_entry != NULL)
{
if (strcmp(p_entry->conf_entry, (const char *)p_name) == 0)
{
name_matched = TRUE;
if (p_entry->p_action != NULL)
p_entry->p_action(p_name, p_value);
break;
}
p_entry++;
}
if ((name_matched == FALSE) && (trace_conf_enabled == TRUE))
{
/* Check if this is a TRC config item */
bte_trace_conf(p_name, p_value);
}
}
fclose(p_file);
}
else
{
ALOGI( "bte_load_conf file >%s< not found", p_path);
}
}