Пример #1
0
std::istream& config_file::read(std::istream& is)
{
  // Load a config_file from is
  // Read in keys and values, keeping internal whitespace
  typedef std::string::size_type pos;
  const std::string& delim  = value_delimiter_;  
  const std::string& comm   = comment_;    // comment
  const pos skip = delim.length();        // length of separator
  
  std::string nextline = "";  // might need to read ahead to see where value ends
  
  while( is || nextline.length() > 0 )
  {
    // Read an entire line at a time
    std::string line;
    if( nextline.length() > 0 )
    {
      line = nextline;  // we read ahead; use it now
      nextline = "";
    }
    else
    {
      std::getline( is, line );
    }
    
    // Ignore comments
    line = line.substr( 0, line.find(comm) );
    
    
    // Parse the line if it contains a delimiter
    pos delim_pos = line.find( delim );
    if( delim_pos < std::string::npos )
    {
      // Extract the key
      std::string key = line.substr( 0, delim_pos );
      line.replace( 0, delim_pos+skip, "" );
      
      // See if value continues on the next line
      // Stop at blank line, next line with a key, end of stream,
      // or end of file sentry
      bool terminate = false;
      while( !terminate && is )
      {
        std::getline( is, nextline );
        terminate = true;
        
        std::string nlcopy = nextline;
        config_file::trim(nlcopy);
        if( nlcopy == "" ) continue;
        
        nextline = nextline.substr( 0, nextline.find(comm) );
        if( nextline.find(delim) != std::string::npos )
          continue;
        
        nlcopy = nextline;
        config_file::trim(nlcopy);
        if( nlcopy != "" ) line += "\n";
        line += nextline;
        terminate = false;
      }
      
      config_file::trim(key);
      config_file::trim(line);
      
      std::string rootkey = parse_key_name(key);
      mapi it = contents_.find(rootkey);
      if(it == contents_.end())
      {
        value new_value;
        parse_key(new_value, key, line);
        contents_[rootkey] = new_value;
      }
      else{
        parse_key(it->second, key, line);
        it = contents_.find(rootkey);
        it->second;
      }
    }
  }
  
  return is;
}
Пример #2
0
std::string config_file::parse_record_name(std::string& key)
{
  key = key.substr(1, key.length());
  return parse_key_name(key);
}
Пример #3
0
/* Lit le nom explicite d'une commande */
int Lit_cmd_explicite(flrn_char *str, int princip, int second,
	Cmd_return *la_commande) {
   int i, j, res=-1, ini, final, context;
   flrn_char *flncmd;
     
   la_commande->cmd_ret_flags|=CMD_RET_KEEP_DESC;
   /* Hack pour les touches fleches en no-cbreak */
   if (fl_strncmp(str, "key-", 4)==0) {
       flrn_char *buf;
       int key;
       struct key_entry ke;
       buf=fl_strchr(str,fl_static(' '));
       if (buf) *buf=fl_static('\0');
       key = parse_key_name(str+4);
       if (buf) *buf=fl_static(' ');
       ke.entry=ENTRY_SLANG_KEY;
       ke.value.slang_key=key;
       if (key) return Lit_cmd_key(&ke,princip,second,la_commande);
   }
   /* cas "normal" */
   
#ifdef USE_SLANG_LANGUAGE
   if (str[0]==fl_static('[')) {
      flrn_char *end_str, *comma;
      int ctxt=-1, flg=0;
      str++;
      if ((end_str=fl_strchr(str,fl_static(']')))==NULL) return -1;
      *end_str=fl_static('\0');
      add_str_to_description(str,la_commande);
      add_str_to_description(fl_static("]"),la_commande);
      comma=strchr(end_str,fl_static(','));
      if (comma) {
	 *comma=fl_static('\0');     
         for (i=0;i<NUMBER_OF_CONTEXTS;i++) {
           if (fl_strcmp(str, Noms_contextes[i])==0) {
 	      ctxt=i;
	      break;
           }
	 }
	 if (ctxt!=-1) {
	    str=comma+1;
	    *comma=fl_static(',');
	    if ((ctxt!=princip) && (ctxt!=second)) {
	       *end_str=fl_static(']');
	       return -1;
	    }
	 }
      }
      la_commande->fun_slang=safe_flstrdup(str);
      comma=fl_strchr(str,fl_static(','));
      if (comma) flg = Parse_type_fun_slang(comma+1);
      *end_str=fl_static(']');
      la_commande->cmd[CONTEXT_COMMAND]=NB_FLCMD+flg;
      la_commande->cmd[CONTEXT_PAGER]=NB_FLCMD_PAGER+flg;
      la_commande->cmd[CONTEXT_MENU]=NB_FLCMD_MENU+flg;
      return (((ctxt==princip) || (ctxt==-1)) ? 0 : 1);
   }
#endif      
   for (j=0;j<2;j++) {
      ini=0; final=NB_FLCMD;
      context=(j==0 ? princip : second);
      if (context==-1) break;
      switch (context) {
	  case CONTEXT_MENU  : ini=NB_FLCMD_PAGER;
			       final+=NB_FLCMD_MENU;  /* fall */
	  case CONTEXT_PAGER : ini+=NB_FLCMD;
			       final+=NB_FLCMD_PAGER;