Пример #1
0
void KDeckDefStatic::setHeroSkill(const char* buf)
{
	char strBuf[1024];
	strcpy(strBuf,buf);
	if(strlen(buf)<2) return;
	char* ss[64];
	int ns = split(strBuf, ";", ss, 64);

	int pos = 0;
	for(int i=0; i<ns; i++)
	{
		char* s = _trim(ss[i]);

		char* qq[64];
		int nb = split(s, "*", qq, 64);
		if(nb!=2) continue;
		
		char* p = _trim(qq[0]);
		int id = atoi(p);
		p = _trim(qq[1]);
		int lev =atoi(p);
		m_skill[pos++].init(id,lev);
	}

}
Пример #2
0
int main(int argc, char *argv[]) {

  graph_t gin;
  graph_t gout;

  args_t      args;
  struct argp argp = {options, _parse_opt, "INPUT OUTPUT", doc};

  memset(&args, 0, sizeof(args_t));
  startup("ctrim", argc, argv, &argp, &args);

  if (ngdb_read(args.input, &gin)) {

    printf("Could not read in %s\n", args.input);
    goto fail;
  }

  stats_cache_init(&gin);

  if (_trim(&gin, &gout, &args)) {
    printf("Could not trim graph\n");
    goto fail;
  }

  if (ngdb_write(&gout, args.output)) {
    printf("Could not write to %s\n", args.output);
    goto fail;
  }

  return 0;

fail:
  return 1;
}
Пример #3
0
QList<QVariantList> TcDataAccess::fetchAllList(const QString &sql,
            const QVariantList &bind /* = QVariantList() */)
{
    _prepareExec(sql, bind);

    QList<QVariantList> result;
    QVariantList row;
    QSqlRecord rec;
    while (_query->next())
    {
        rec = _query->record();
        if (result.isEmpty())
        {
            for (int i = 0; i < rec.count(); i++)
            {
                row << _case(rec.fieldName(i));
            }
            result << row;
            row.clear();
        }
        for (int i = 0; i < rec.count(); i++)
        {
            row << _trim(rec.value(i));
        }
        result << row;
        row.clear();
    }
    return result;
}
Пример #4
0
QVariant TcDataAccess::fetchOne(const QString &sql,
            const QVariantList &bind /* = QVariantList() */)
{
    _prepareExec(sql, bind);
    QVariant val;
    if (_query->next())
    {
        val = _trim(_query->value(0));
    }
    return val;
}
Пример #5
0
int str_to_int(const char* const s) {
    if (s == NULL) return 0;

    int sign = 0;
    char *cursor = s;
    sign = _trim(s, &cursor);

    int res = _extract_digits(&cursor);

    return (res * sign);
}
Пример #6
0
QVariantList TcDataAccess::fetchCol(const QString &sql,
            const QVariantList &bind /* = QVariantList() */)
{
    _prepareExec(sql, bind);

    QVariantList rows;
    while (_query->next())
    {
        rows << _trim(_query->value(0));
    }
    return rows;
}
Пример #7
0
        // --------------------------------------------------------------------
        void _read(scanner_type & in, int & node_count)
        {
            static const char delims[] = ";:(),";

            //
            // Create a new id for each node created.
            //
            _id = ++node_count;

            //
            // Determine if this node has children.
            //
            if (in.try_char('('))
            {
                //
                // Loop over all children, which are separated by colons.
                //
                do
                {
                    //
                    // Create the child, storing it into the collection of
                    // children, and updating the child to reference the parent.
                    //
                    auto child = new basic_newick_node();
                    child->_parent = this;
                    _children.push_back(child);
                    child->_read(in, node_count);
                }
                while (in.try_char(','));

                //
                // Require a closing parenthesis after the last child.
                //
                in.expect(')');
            }

            //
            // Parse the name, if any.
            //
            _name = _trim(in.read_token(delims));

            //
            // If the stream provides a colon, parse the length.
            //
            if (in.try_char(':'))
            {
                _length     = in.read_real<value_type>();
                _has_length = true;
            }
        }
Пример #8
0
void XParser::endElement(const XMLCh* const uri, const XMLCh* const local,
			 const XMLCh* const raw)
{
	if (_readElement)
	{
		if (_elementBuffer.length() > 0)
		{
			unsigned long long	value = XHash::hash(_elementBuffer);

			_currentNodeID = _xtree->addText(_idStack[_stackTop],
							 _lsidStack[_stackTop],
							 _elementBuffer, value);

			_valueStack[_stackTop] += value;
		}
		else	// an empty element
		{
			_currentNodeID = _xtree->addText(_idStack[_stackTop],
							 _lsidStack[_stackTop],
							 "", 0);
		}

		_readElement = false;
	}
	else	// mixed contents
	{
		if (_elementBuffer.length() > 0)
		{
			std::string	text = _trim(_elementBuffer);
			if (text.length() > 0)
			{
				unsigned long long	value = XHash::hash(text);
				_currentNodeID =
					_xtree->addText(_idStack[_stackTop],
							_lsidStack[_stackTop],
							text, value);
				_valueStack[_stackTop] += value;
			}
		}
	}

	_elementBuffer = std::string("");
	_xtree->addHashValue(_idStack[_stackTop], _valueStack[_stackTop]);
	_valueStack[_stackTop-1] += _valueStack[_stackTop] *
				    _valueStack[_stackTop];
	_lsidStack[_stackTop-1] = _idStack[_stackTop];

	// Pop
	_stackTop--;
}
Пример #9
0
void KDeckDefStatic::setDeck(const char* buf)
{
	char strBuf[1024];
	strcpy(strBuf,buf);

	m_cardList.clear();
	char* ss[64];
	int ns = split(strBuf, ";", ss, 64);

	for(int i=0; i<ns; i++)
	{
		char* s = _trim(ss[i]);
		int id = atoi(s);
		if(id>0) m_cardList.push_back(id);
	}
}
Пример #10
0
QVariantMap TcDataAccess::fetchRow(const QString &sql,
            const QVariantList &bind /* = QVariantList() */)
{
    _prepareExec(sql, bind);

    QVariantMap row;
    if (_query->next())
    {
        QSqlRecord rec = _query->record();
        for (int i = rec.count() - 1; i > -1; i--)
        {
            row[_case(rec.fieldName(i))] = _trim(rec.value(i));
        }
    }
    return row;
}
Пример #11
0
// read to buffer
bool KLogFileReader::onTimer_readLogFile(DWORD name, Identity64 cookie, const void* data)
{
	if(!m_readBuf.ReadAvail())
	{
		if(!this->_readToBuffer())
		{
			time_t now = time(NULL);
			if(now - m_lastSuccessReadTime > 20)
			{
				this->_close();
				this->startTimer(AppTimer_SearchNextLogFile, 0, 1.0f, NULL);
			}
			else
			{
				this->startTimer(AppTimer_ReadLogFile, 0, 1.0f, NULL);
			}
			return true;
		}
	}

	char* line;
	while(1)
	{
		if(!g_pApp->isDatabaseReady())
		{
			this->startTimer(AppTimer_WaitDatabase, 0, 2.f, NULL);
			return true;
		}

		int n = this->_readLine(&line);
		if(n < 0 || !line) break;

		lineCount++;
		
		m_frameLineCount++;
		line = _trim(line);

		if(line[0])
		{
			this->_processLogLine(line);
			g_pApp->m_msFrameSleep = 0;
		}
	}

	this->startTimer(AppTimer_ReadLogFile, 0, 0.0f, NULL);
	return true;
}
Пример #12
0
QList<QVariantMap> TcDataAccess::fetchAll(const QString &sql,
            const QVariantList &bind /* = QVariantList() */)
{
    _prepareExec(sql, bind);

    QList<QVariantMap> result;
    QVariantMap row;
    while (_query->next())
    {
        QSqlRecord rec = _query->record();
        for (int i = rec.count() - 1; i > -1; i--)
        {
            row[_case(rec.fieldName(i))] = _trim(rec.value(i));
        }
        result << row;
        row.clear();
    }
    return result;
}
Пример #13
0
void KDeckDefStatic::setDynamic(const char* buf)
{
	char strBuf[1024];
	strcpy(strBuf,buf);

	char* ss[64];
	int ns = split(strBuf, ";", ss, 64);

	for(int i=0; i<ns; i++)
	{
		char* s = _trim(ss[i]);
		if(strlen(s)<2) continue;
		DynamicCardDef* pDef =  DynamicCardDef::create();
		if(!pDef->init(s)){
			delete pDef;
			continue;
		}
		m_defList.push_back(pDef);
	}

}
Пример #14
0
void XParser::startElement(const XMLCh* const uri, const XMLCh* const local,
		  	   const XMLCh* const raw,
			   const xercesc::Attributes& attrs)
{
	// if text is mixed with elements.
	if (_elementBuffer.length() > 0)
	{
		std::string	text = _trim(_elementBuffer);
		if (text.length() > 0)
		{
			unsigned long long	value = XHash::hash(text);
			int	tid = _xtree->addText(_idStack[_stackTop],
						      _lsidStack[_stackTop],
						      text, value);
			_lsidStack[_stackTop] = tid;
			_currentNodeID = tid;
			_valueStack[_stackTop] += value;
		}
	}

	std::string local_s(xercesc::XMLString::transcode(local));

//cout << "Add element " << _idStack[_stackTop] << "\t" << _lsidStack[_stackTop] << "\t" << local_s << endl;
	int	eid = _xtree->addElement(_idStack[_stackTop],
					 _lsidStack[_stackTop], local_s);
	// Update last sibling info.
	_lsidStack[_stackTop] = eid;

	// Push
	_stackTop++;
	_idStack[_stackTop] = eid;
	_currentNodeID = eid;
	_lsidStack[_stackTop] = XTree::NULL_NODE;
	_valueStack[_stackTop] = XHash::hash(local_s);

	// Take care of attributes
	if (attrs.getLength() > 0)
	{
		for (unsigned int i = 0; i < attrs.getLength(); i++)
		{
			std::string	name(xercesc::XMLString::transcode(attrs.getQName(i)));
			unsigned long long	namehash = XHash::hash(name);
			
			unsigned long long	attrhash = namehash * namehash;
			std::string	value = "";
			char	*valueP = xercesc::XMLString::transcode(attrs.getValue(i));
			if (valueP != NULL)
			{
				value = std::string(valueP);
				unsigned long long valuehash = XHash::hash(value);
				attrhash += valuehash * valuehash;
			}
			int	aid = _xtree->addAttribute(eid, _lsidStack[_stackTop], name, value, namehash, attrhash);

			_lsidStack[_stackTop] = aid;
			_currentNodeID = aid + 1;
			_valueStack[_stackTop] += attrhash * attrhash;
		}
	}
	
	_readElement = true;
	_elementBuffer = std::string("");

}
Eina_Bool Add_To_Most_Visited_Sites_View::_save_button_clicked(void)
{
	BROWSER_LOGD("[%s]", __func__);
	Evas_Object *entry = br_elm_editfield_entry_get(m_url_edit_field);
	char* url = _trim(elm_entry_markup_to_utf8(elm_entry_entry_get(entry)));
	if (!url || !strlen(url)) {
		show_msg_popup(BR_STRING_EMPTY);
		return EINA_FALSE;
	}

	std::string full_url = std::string(url);

	if (_has_url_sheme(url)) {
		char *token = strstr(url, BROWSER_URL_SCHEME_CHECK);
		if (token && strlen(token) == 3) {
			/* If input url has only sheme such as 'http://', 'https://' */
			show_msg_popup(BR_STRING_EMPTY);
			return EINA_FALSE;
		}
	} else
		full_url = std::string(BROWSER_HTTP_SCHEME) + std::string(url);

	if (m_most_visited_sites->m_selected_item->url && strlen(m_most_visited_sites->m_selected_item->url)) {
		if (!strcmp(full_url.c_str(), m_most_visited_sites->m_selected_item->url)) {
			/* If the url is not changed in case of modify speed dial item. */
			if (elm_naviframe_bottom_item_get(m_navi_bar)
			    != elm_naviframe_top_item_get(m_navi_bar))
				elm_naviframe_item_pop(m_navi_bar);
			return EINA_FALSE;
		}
	}

	std::string history_id;
	history_id = m_most_visited_sites->m_most_visited_sites_db->get_history_id_by_url(full_url.c_str());

	char *screen_shot_path = NULL;
	if (history_id.empty())
		screen_shot_path = strdup("default_noscreenshot");
	else
		screen_shot_path = strdup(history_id.c_str());

	if (!screen_shot_path) {
		BROWSER_LOGE("strdup failed");
		return EINA_FALSE;
	}

	int index = 0;
	Elm_Object_Item *it = elm_gengrid_first_item_get(m_most_visited_sites->m_gengrid);
	do {
		if (it == m_most_visited_sites->m_selected_item->item)
			break;
		index++;
	} while (it = elm_gengrid_item_next_get(it));

	if (!m_most_visited_sites->m_most_visited_sites_db->save_most_visited_sites_item(index, full_url.c_str(),
						full_url.c_str(), screen_shot_path)) {
		BROWSER_LOGE("save_most_visited_sites_item failed");
		return EINA_FALSE;
	}

	free(screen_shot_path);

	if (!m_most_visited_sites->_reload_items()) {
		BROWSER_LOGE("m_most_visited_sites->_reload_items failed");
		return EINA_FALSE;
	}

	return EINA_TRUE;
}
Пример #16
0
    bool accept(const char* val)
    {
        m_map.clear();

        int len = strcpy_k(m_line, sizeof(m_line), val);
        m_map.parseLine(m_line);

        // trade: time,map,target,in,out

        int time = str2int(m_map.get("time"));
        if(time < m_startTime)
            return true;

        KTrade* pTrade = m_pServer->newTrade();

        int map = str2int(m_map.get("map"));
        const char* target = m_map.get("target");
        const char* srcPlayer = m_map.get("srcPlayer");
        const char* dstPlayer = m_map.get("dstPlayer");
        const char* sip = m_map.get("sip");
        const char* tip = m_map.get("tip");
        const char* in_items = m_map.get("in");
        const char* out_items = m_map.get("out");

        pTrade->m_serverName = m_pServer->name();
        pTrade->m_time = time;
        pTrade->m_source = m_acctName;
        pTrade->m_target = g_stringPool.get(target);
        pTrade->m_srcPlayer = g_stringPool.get(srcPlayer);
        pTrade->m_dstPlayer = g_stringPool.get(dstPlayer);
        if(sip) pTrade->m_sip = g_stringPool.get(sip);
        if(tip) pTrade->m_tip = g_stringPool.get(tip);
        pTrade->m_map = map;
        pTrade->m_sVipLevel = str2int(m_map.get("sVipLevel"));
        pTrade->m_tVipLevel = str2int(m_map.get("tVipLevel"));
        pTrade->m_friendDegree = str2int(m_map.get("friendDegree"));

        char* ss[128];
        char* ilist = _trim((char*)in_items);
        if(ilist[0])
        {
            int n = split(ilist, ":,", ss, sizeof(ss)/sizeof(char*));
            {
                for(int i=0; i<n; i+=2)
                {
                    int itemType = str2int(ss[i]);
                    int itemCount = str2int(ss[i+1]);
                    pTrade->m_ilist[itemType] = itemCount;
                }
            }
        }
        char* olist = _trim((char*)out_items);
        if(olist[0])
        {
            int n = split(olist, ":,", ss, sizeof(ss)/sizeof(char*));
            {
                for(int i=0; i<n; i+=2)
                {
                    int itemType = str2int(ss[i]);
                    int itemCount = str2int(ss[i+1]);
                    pTrade->m_olist[itemType] = itemCount;
                }
            }
        }

        return true;
    }
Пример #17
0
int main(int argc, char **argv)
{
   const char *book;
   char *pos;
   struct stat st;
   int **seq;
   int i, count;

   if (argc != 3)
     {
        printf("Usage ./oracle [book] [count]\n");
        exit(2);
     }

   book = argv[1];
   if (stat(book, &st) < 0)
     exit(1);
  
   count = atoi(argv[2]);
   if (count <= 0) exit(1 << 3);

   int total_bytes = st.st_size;
 
   seq = rand_seq(count, total_bytes);

   int fd = open(book, 0444);
   if (fd == -1)
     {
        fprintf(stderr, "ERR: could not open '%s'\n", book);
        exit(1 << 2);
     }

   char *map = (char *) mmap(NULL, total_bytes, PROT_READ, MAP_SHARED, fd, 0);
   close(fd);

   i = 0;

   while (i < count)
     {
        int byte = 0;
        while (byte < total_bytes)
          {
             pos = map + byte++;
             if (byte == *seq[i])
               {
                  char *end, *start = pos;
                  while (*start++ != ' ');
                  end = strchr(start, ' ');
                  size_t len = end - start;
                  char *word = malloc(len);
                  memcpy(word, start, len);
                  word[len] = '\0';
                  _trim(word);
                  printf(" %s ", word); 
                  free(word);
                  free(seq[i]);
                  i++;
                  break;
               }
          } 
     }

   free(seq);
   printf("\n");

   return EXIT_SUCCESS;
}
Пример #18
0
QVariant ZStringFormatter::transform(QVariant val){
    if(method() == ZFMT_METHOD_STR_CONCAT){ //!                      concat( with )
        return _concat(val,arg("with",ZML_DEFAULT_PARAM_NAME));

    }else if(method() == ZFMT_METHOD_STR_DOWNCASE){ //!              downcase
        return _downcase(val);

    }else if(method() == ZFMT_METHOD_STR_ELIDE){ //!                 elide( [maxLength [, placeholder]] )
        if(arg("placeholder").isValid())
            return _elide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString());
        else
            return _elide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt());

    }else if(method() == ZFMT_METHOD_STR_LEFT){ //!                  left( length )
        return _left(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_LEFTOF){ //!                leftOf( delimiter )
        return _leftOf(val, arg("delimiter",ZML_DEFAULT_PARAM_NAME).toString());

    }else if(method() == ZFMT_METHOD_STR_LELIDE){ //!                lelide( [maxLength [, placeholder]] )
        if(arg("placeholder").isValid())
            return _lelide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString());
        else
            return _lelide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt());

    }else if(method() == ZFMT_METHOD_STR_LPAD){ //!                  lpad( length [, symbol] )
        if(arg("symbol").isValid())
            return _lpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt(), arg("symbol").toChar());
        else
            return _lpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_LSHIFT){ //!                lshift( places )
        return _lshift(val, arg("places", ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_LTRIM){ //!                 ltrim( [pattern] )
        if(arg("pattern").isValid())
            return _ltrim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString());
        else
            return _ltrim(val);

    }else if(method() == ZFMT_METHOD_STR_RELIDE){ //!                relide( [maxLength [, placeholder]] )
        if(arg("placeholder").isValid())
            return _relide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt(), arg("placeholder").toString());
        else
            return _relide(val, arg("maxLength",ZML_DEFAULT_PARAM_NAME).toInt());

    }else if(method() == ZFMT_METHOD_STR_REPEAT){ //!                repeat( times )
        return _repeat(val, arg("times",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_REVERSE){ //!               reverse
        return _reverse(val);

    }else if(method() == ZFMT_METHOD_STR_RIGHT){ //!                 right( length )
        return _right(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_RIGHTOF){ //!               rightOf( delimiter )
        return _rightOf(val, arg("delimiter",ZML_DEFAULT_PARAM_NAME).toString());

    }else if(method() == ZFMT_METHOD_STR_RPAD){ //!                  rpad( length [, symbol] )
        if(arg("symbol").isValid())
            return _rpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt(), arg("symbol").toChar());
        else
            return _rpad(val, arg("length",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_RSHIFT){ //!                rshift( places )
        return _rshift(val, arg("places",ZML_DEFAULT_PARAM_NAME).toUInt());

    }else if(method() == ZFMT_METHOD_STR_RTRIM){ //!                 rtrim( [pattern] )
        if(arg("pattern").isValid())
            return _rtrim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString());
        else
            return _rtrim(val);

    }else if(method() == ZFMT_METHOD_STR_SCASE){ //!                 capitalize
        return _sentenceCase(val);

    }else if(method() == ZFMT_METHOD_STR_SQUEEZE){ //!               squeeze( [symbol] )
        if(arg("symbol").isValid())
            return _squeeze(val, arg("symbol",ZML_DEFAULT_PARAM_NAME).toChar());
        else
            return _squeeze(val);

    }else if(method() == ZFMT_METHOD_STR_TCASE){ //!                 titleize
        return _titleCase(val);

    }else if(method() == ZFMT_METHOD_STR_TRIM){ //!                  trim( [pattern] )
        if(arg("pattern").isValid())
            return _trim(val, arg("pattern",ZML_DEFAULT_PARAM_NAME).toString());
        else
            return _trim(val);

    }else if(method() == ZFMT_METHOD_STR_UPCASE){ //!                upcase
        return _upcase(val);
    }

    return val;
}
Пример #19
0
bool
metisConfigurationFile_Process(MetisConfigurationFile *configFile)
{
    assertNotNull(configFile, "Parameter configFile must be non-null");

    // default to a "true" return value and only set to false if we encounter an error.
    bool success = true;

    #define BUFFERLEN 2048
    char buffer[BUFFERLEN];

    configFile->linesRead = 0;

    // always clear errors and fseek to start of file in case we get called multiple times.
    clearerr(configFile->fh);
    rewind(configFile->fh);

    while (success && fgets(buffer, BUFFERLEN, configFile->fh) != NULL) {
        configFile->linesRead++;

        char *stripedBuffer = _trim(buffer);
        if (strlen(stripedBuffer) > 0) {
            if (stripedBuffer[0] != '#') {
                // not empty and not a comment

                // _parseArgs will modify the string
                char *copy = parcMemory_StringDuplicate(stripedBuffer, strlen(stripedBuffer));
                PARCList *args = _parseArgs(copy);
                MetisCommandReturn result = metisControlState_DispatchCommand(configFile->controlState, args);

                // we ignore EXIT from the configuration file
                if (result == MetisCommandReturn_Failure) {
                    if (metisLogger_IsLoggable(metisForwarder_GetLogger(configFile->metis), MetisLoggerFacility_Config, PARCLogLevel_Error)) {
                        metisLogger_Log(metisForwarder_GetLogger(configFile->metis), MetisLoggerFacility_Config, PARCLogLevel_Error, __func__,
                                        "Error on input file %s line %d: %s",
                                        configFile->filename,
                                        configFile->linesRead,
                                        stripedBuffer);
                    }
                    success = false;
                }
                parcList_Release(&args);
                parcMemory_Deallocate((void **) &copy);
            }
        }
    }

    if (ferror(configFile->fh)) {
        if (metisLogger_IsLoggable(metisForwarder_GetLogger(configFile->metis), MetisLoggerFacility_Config, PARCLogLevel_Error)) {
            metisLogger_Log(metisForwarder_GetLogger(configFile->metis), MetisLoggerFacility_Config, PARCLogLevel_Error, __func__,
                            "Error on input file %s line %d: (%d) %s",
                            configFile->filename,
                            configFile->linesRead,
                            errno,
                            strerror(errno));
        }
        success = false;
    }

    return success;
}
Пример #20
0
int main(int argc, char **argv)
{
    //open input file & output file
    FILE *fp_in;
    FILE *fp_out;
    fp_in = fopen("./ip_list.txt", "rb");
    if (!fp_in) {
        printf("open ip_list.txt failed, errmsg=%s\n", strerror(errno));
        exit(-1);
    }
    fp_out = fopen("./conf.txt", "w+");
    if (!fp_out) {
        printf("open conf.txt failed, errmsg=%s\n", strerror(errno));
        exit(-1);
    }

    MacInfo machines[MAX_MACHINE];
    int machine_num = 0;
    char buf[256];
    int idx = 0;
    while (fgets(buf, 256, fp_in) != NULL) {
        _trim(buf);
        printf("reading ip: %s\n", buf);
        strcpy(machines[idx].ip, buf);
        ++idx;
    }
    machine_num = idx;
    if ((machine_num % 3) != 0) {
        printf("machine number not multiple of 3, machine_num=%d\n", machine_num);
        exit(-1);
    }

    int group_idx = 0;
    int group_id = 1;
    int i;
    int j;
    int k;
    int selectIdx[3];

    for (i = 0; i < machine_num; i += 3) {
        //fill all of these three machines
        int port = START_PORT;
        for (j = 1; j <= DISK_NUM; ++j) {
            fprintf(fp_out, "##Group %d\n", group_idx);
            fprintf(fp_out, "GROUP[%d]=%d\n", group_idx, group_id);

            int tmp = j % 3; 
            for (k = 0; k < 3; ++k) {
                selectIdx[k] = tmp;
                tmp = (tmp + 1) % 3;
            }

            for (k = 0; k < 3; ++k) {
                fprintf(fp_out, "ip%d[%d]=%s\n", k, group_id, machines[i+selectIdx[k]].ip);
                fprintf(fp_out, "port%d[%d]=%d\n", k, group_id, port);
                fprintf(fp_out, "path%d[%d]=/data%d/dataservice_%d\n", k, group_id, j, group_id);
                fprintf(fp_out, "user%d[%d]=bladefs\n", k, group_id);
                fprintf(fp_out, "passwd%d[%d]=bladefs\n", k, group_id);
                fprintf(fp_out, "\n");
            }
            ++port;
            ++group_idx;
            ++group_id;
        }
    }

    printf("=======finish generating conf.txt==========\n");
    printf("total machine number: %d\n", machine_num);
    printf("total group number: %d\n", group_idx);

    fclose(fp_in);
    fclose(fp_out);
    return 0;
}