示例#1
0
static
void read_config(ZString filename)
{
    std::ifstream in(filename.c_str());
    if (!in.is_open())
    {
        FPRINTF(stderr, "Monitor config file not found: %s\n", filename);
        exit(1);
    }

    FString line;
    while (io::getline(in, line))
    {
        SString name;
        TString value;
        if (!split_key_value(line, &name, &value))
            continue;

        parse_option(name, value);
    }
}
示例#2
0
/*
 * name:    get_all_keys_value
 * func:    get all key values in the specific section from buffer
 * input��  char *buffer, void *section
 * output�� char *keys[],void *value[]
 * return�� if correct, return keys number
 *					else return error number          
 */
static int get_all_keys_value(char *buffer, void *section, char *keys[], void *value[])
{ 
  char buf[LINE_MAX_CHAR_NUM + 1];
  char *key_ptr, *val_ptr; 
  int n, n_keys = 0, ret; 
  unsigned int i, buf_len;
	
	if((buf_len = strlen((char *)buffer)) < 1) 
    return CFG_ERR; 
	
	key_ptr = (char*)kzalloc(MAX_NAME_LEN,GFP_KERNEL);
	val_ptr = (char*)kzalloc(MAX_VALUE_LEN,GFP_KERNEL);
	
  for(i = 0; i < buf_len;)  /* search for section */
  { 
    ret = CFG_ERR_RD; 
    n = get_one_line(buffer, buf, LINE_MAX_CHAR_NUM); 
		buffer += n;
		i += n;
		
    ret = CFG_NOT_FOUND; 
    if(n < 0) 
      goto g_all_keys_end; /* end of file */ 
    n = strlen(strim(buf)); 
    if(n == 0 || buf[0] == comment_pre) 
      continue; /* null line or comment line */ 
    ret = CFG_ERR_FMT; 
    if(n > 2 && ((buf[0] == sct_pre && buf[n-1] != sct_post))) 
      goto g_all_keys_end; 
    if(buf[0] == sct_pre) 
    { 
      buf[n-1] = 0x00; 
      if(strcmp(buf+1, section) == 0) 
        break; /* section found */ 
    } 
  } 
  for( ; i < buf_len; ) /* search for keys */  
  { 
    ret = CFG_ERR_RD; 
    n = get_one_line(buffer, buf, LINE_MAX_CHAR_NUM); 
    buffer += n;
    i += n;
    
    if(n < 0) 
      break; /* end of file */ 
    n = strlen(strim(buf)); 
    if(n == 0 || buf[0] == comment_pre) 
      continue; /* null line or comment line */ 
    ret = CFG_NOT_FOUND; 
    if(buf[0] == sct_pre) 
      break; /* another section */ 
    ret = CFG_ERR_FMT; 
    if(split_key_value(buf, key_ptr, val_ptr) != 1) 
      goto g_all_keys_end; 
		
    strim(key_ptr);
    strcpy(keys[n_keys], key_ptr); 
    strim(val_ptr);
    strcpy(value[n_keys], val_ptr);

    n_keys++; 
  } 
  ret = n_keys; 
g_all_keys_end: 
	if(key_ptr)
		kfree(key_ptr);
	if(val_ptr)
		kfree(val_ptr);
  return ret; 
}