示例#1
0
STATIC bool skip_whitespace(mp_lexer_t *lex, bool stop_at_newline) {
    bool had_physical_newline = false;
    while (!is_end(lex)) {
        if (is_physical_newline(lex)) {
            if (stop_at_newline && lex->nested_bracket_level == 0) {
                break;
            }
            had_physical_newline = true;
            next_char(lex);
        } else if (is_whitespace(lex)) {
            next_char(lex);
        } else if (is_char(lex, '#')) {
            next_char(lex);
            while (!is_end(lex) && !is_physical_newline(lex)) {
                next_char(lex);
            }
            // had_physical_newline will be set on next loop
        } else if (is_char_and(lex, '\\', '\n')) {
            // line-continuation, so don't set had_physical_newline
            next_char(lex);
            next_char(lex);
        } else {
            break;
        }
    }
    return had_physical_newline;
}
示例#2
0
static inline void
insert(TrieNode<CharT, BucketT>* root, unsigned char** strings, size_t n)
{
	for (size_t i=0; i < n; ++i) {
		unsigned char* str = strings[i];
		size_t depth = 0;
		CharT c = get_char<CharT>(str, 0);
		TrieNode<CharT, BucketT>* node = root;
		while (node->is_trie(c)) {
			assert(not is_end(c));
			node = node->get_node(c);
			depth += sizeof(CharT);
			c = get_char<CharT>(str, depth);
		}
		BucketT* bucket = node->get_bucket(c);
		assert(bucket);
		bucket->push_back(str);
		if (is_end(c)) continue;
		if (bucket->size() > Threshold) {
			node->_buckets[c] = BurstImpl()(*bucket,
					depth+sizeof(CharT));
			make_trie(node->_buckets[c]);
			delete bucket;
		}
	}
}
示例#3
0
int next_word(FILE *fd, char *word, int break_on_newline) {
	int c, k = 0;
	/* eat up any whitespace */
	while (!is_end(c = fgetc(fd), break_on_newline) && isspace(c)) {
	}
	if (is_end(c, break_on_newline)) {
		return 0; /* no more words :c */
	}
	/* c now contains the first character of the word */
	do {
		word[k++] = c; /* fill in the word */
	} while (k < 255 && !is_end(c = fgetc(fd), break_on_newline) && !isspace(c));
	/*
	 * at this point, if we ran up against the k limit, then c contains the
	 * last character in the word. if we didn't, it contains the first space
	 * after the word.
	 */
	if (!is_end(c, break_on_newline) && !isspace(c)) /* if we ran out of word space */
		while (is_end(c = fgetc(fd), break_on_newline) && !isspace(c)); /* then ignore rest */

	word[k] = '\0'; /* add a terminator */

	if (break_on_newline && c == '\n') {
		ungetc('\n', fd);
	}

	/*
	 * c now contains either EOF or a blank, which we can safely ignore.
	 * if it's an EOF, the next call to this function will return zero
	 * and end the parse loop.
	 */

	return 1; 
}
示例#4
0
文件: options.cpp 项目: quesnel/efyj
    eastl::optional<eastl::string> getline()
    {
        // If the next line is already available in the m_buffer, we return a
        // substring of the m_buffer and update the m_buffer.

        auto newline_pos = m_buffer.find_first_of('\n');
        if (newline_pos != eastl::string::npos) {
            auto ret = m_buffer.substr(0, newline_pos);

            if (newline_pos >= m_buffer.size())
                m_buffer.clear();
            else
                m_buffer =
                  m_buffer.substr(newline_pos + 1, eastl::string::npos);

            return eastl::make_optional(ret);
        }

        // We need to append data to the buffer.

        char buffer[BUFSIZ];

        do {
            if (is_end()) {
                m_buffer.clear();
                return {};
            }

            auto len = fread(buffer, 1, BUFSIZ, is);
            buffer[len] = '\0';

            if (len == 0) {
                auto ret = eastl::move(m_buffer);
                ret += '\n';

                return eastl::make_optional(ret);
            } else {
                auto* newline = strchr(buffer, '\n');
                if (newline == nullptr) {
                    m_buffer.append(buffer);
                } else {
                    m_buffer.append(buffer, newline);
                    auto ret = eastl::move(m_buffer);
                    m_buffer.assign(newline + 1);

                    return eastl::make_optional(ret);
                }
            }
        } while (!is_end());

        auto ret = eastl::move(m_buffer);
        ret += '\n';

        return eastl::make_optional(ret);
    }
示例#5
0
 bool equal_aux(self_t const& other, boost::forward_traversal_tag) const
 {
     if (is_end() != other.is_end())
         return false;
     else if (is_end() && other.is_end())
         return true;
     else {
         BOOST_ASSERT(!is_end() && !other.is_end());
         return *m_result == *other.m_result;
     }
 }
示例#6
0
static int
try_read_move(const char *cmd)
{
    move move;

    if (is_end())
        return 1;

    switch (read_move(current_position(), cmd, &move, turn())) {
    case none_move:
        return 1;
    case illegal_move:
        printf("Illegal move: %s\n", cmd);
        return 0;
    case 0:
        if (!is_force_mode && !is_opp_turn()) {
            printf("It is not %s's turn\n",
                   whose_turn[opponent_of(computer_side)]);
            return 0;
        }
        operator_move(move);
        return 0;
    default:
        assert(0);
    }
    return 0;
}
示例#7
0
static void
decide_move(void)
{
    mtx_lock(&game_mutex);

    if (game_started && !is_end() && !is_force_mode) {
        if (game_started && has_single_response()) {
            move m = get_single_response();

            print_computer_move(m);
            add_move(m);
            engine_move_count_inc();
        }
        else {
            move m = book_get_move(book, current_position());
            if (m != none_move) {
                print_computer_move(m);
                add_move(m);
                engine_move_count_inc();
            }
            else {
                set_thinking_done_cb(computer_move,
                                     ++callback_key);
                start_thinking();
            }
        }
    }
    else {
        game_started = false;
    }

    mtx_unlock(&game_mutex);
}
示例#8
0
void SSPAggrBgWorker::ReadTableOpLogsIntoOpLogMeta(int32_t table_id,
                                                   ClientTable *table) {
  // Get OpLog index
  cuckoohash_map<int32_t, bool> *new_table_oplog_index_ptr
      = table->GetAndResetOpLogIndex(my_comm_channel_idx_);

  AbstractOpLog &table_oplog = table->get_oplog();
  TableOpLogMeta *table_oplog_meta = oplog_meta_.Get(table_id);

  if (table_oplog_meta == 0) {
    const AbstractRow *sample_row = table->get_sample_row();
    table_oplog_meta = oplog_meta_.AddTableOpLogMeta(table_id, sample_row);
  }

  for (auto oplog_index_iter = new_table_oplog_index_ptr->cbegin();
       !oplog_index_iter.is_end(); oplog_index_iter++) {
    int32_t row_id = oplog_index_iter->first;
    RowOpLogMeta row_oplog_meta;
    bool found = table_oplog.GetInvalidateOpLogMeta(row_id, &row_oplog_meta);
    if (!found || (row_oplog_meta.get_clock() == -1)) {
      continue;
    }

    table_oplog_meta->InsertMergeRowOpLogMeta(row_id, row_oplog_meta);
  }
  delete new_table_oplog_index_ptr;
}
示例#9
0
	size_t load_buffer(ALuint buf) {
		// seek to beginning if in a end
		if (is_end()) {
			if (info_.seekable) {
				if (sf_seek(file_.get(), 0, SEEK_SET) == -1) {
					Output::Error("libsndfile seek error: %s", sf_strerror(file_.get()));
					return 0;
				}
			} else {
				file_.reset(sf_open(filename_.c_str(), SFM_READ, &info_), sf_close);
				if (!file_) {
					Output::Error("libsndfile open error: %s", sf_strerror(NULL));
					return 0;
				}
			}
			loop_count_++;
			seek_pos_ = 0;
		}

		data_.resize(info_.channels * info_.samplerate * SECOND_PER_BUFFER);
		sf_count_t const read_size =
		    sf_readf_short(file_.get(), &data_.front(), data_.size() / info_.channels);
		alBufferData(buf, format_, &data_.front(), sizeof(int16_t) * data_.size(),
		             info_.samplerate);
		seek_pos_ += read_size;
		return read_size;
	}
static TrieNode<CharT>*
pseudo_sample(unsigned char** strings, size_t n)
{
	// Limit the maximum number of nodes to whatever fits in 30 megabytes.
	debug()<<__func__<<"(): sampling "<<n/8192<<" strings ...\n";
	size_t max_nodes = 30000000/sizeof(TrieNode<CharT>);
	TrieNode<CharT>* root = new TrieNode<CharT>;
	for (size_t i=0; i < n; i += 8192) {
		unsigned char* str = strings[i];
		size_t depth = 0;
		TrieNode<CharT>* node = root;
		while (true) {
			CharT c = get_char<CharT>(str, depth);
			if (is_end(c)) break;
			depth += sizeof(CharT);
			if (not node->is_trie[c]) {
				node->is_trie[c] = true;
				node->buckets[c] = new TrieNode<CharT>;
				if (--max_nodes==0) goto finish;
			}
			node = static_cast<TrieNode<CharT>*>(node->buckets[c]);
			assert(node);
		}
	}
finish:
	debug()<<"   Sampling done, created "
	       <<(30000000/sizeof(TrieNode<CharT>))-max_nodes<<" nodes.\n";
	return root;
}
static TrieNode<CharT>*
random_sample(unsigned char** strings, size_t n)
{
	// Limit the maximum number of nodes to whatever fits in 30 megabytes.
	const size_t sample_size = n/8192;
	size_t max_nodes = 30000000/sizeof(TrieNode<CharT>);
	debug()<<__PRETTY_FUNCTION__<<" sampling "<<sample_size<<" strings\n";
	TrieNode<CharT>* root = new TrieNode<CharT>;
	for (size_t i=0; i < sample_size; ++i) {
		unsigned char* str = strings[size_t(drand48()*n)];
		size_t depth = 0;
		TrieNode<CharT>* node = root;
		while (true) {
			CharT c = get_char<CharT>(str, depth);
			if (is_end(c)) break;
			depth += sizeof(CharT);
			if (not node->is_trie[c]) {
				node->is_trie[c] = true;
				node->buckets[c] = new TrieNode<CharT>;
				if (--max_nodes==0) goto finish;
			}
			node = static_cast<TrieNode<CharT>*>(node->buckets[c]);
			assert(node);
		}
	}
finish:
	return root;
}
示例#12
0
文件: parser.c 项目: Tao-Ma/flatcc
static int parse_schema(fb_parser_t *P)
{
    fb_token_t *t, *t0;
    parse_include(P);
    t = P->token;
    for (;;) {
        if (is_end(t)) {
            break;
        }
        if (P->failed >= FLATCC_MAX_ERRORS) {
            return -1;
        }
        t0 = t;
        parse_schema_decl(P);
        t = P->token;
        if (t == t0) {
            if (P->failed) {
                return -1;
            }
            error_tok(P, t, "extra tokens in input");
            return -1;
        }
    }
    revert_names(&P->schema.attributes);
    revert_symbols(&P->schema.symbols);
    return 0;
}
示例#13
0
void PhraseGraph::extract_Template() {
    int VertexNum = ztree.nodes.size();
    int *visited = new int[VertexNum];

    for(int i=0;i<VertexNum;i++){
        visited[i]=0;
    }

    int *global_pid = new int(0);

    for(int i=0;i<VertexNum;i++){

        if(visited[i] ==0&&!is_end(i)) //找一个没被访问过,并且不是arg的开始遍历
        {

                Phrase* new_phrase= new Phrase(*global_pid);

                dfs(i, -1,visited, new_phrase,global_pid);  //起始点的previous置为-1

                phrases.insert({new_phrase->id,*new_phrase});

                *global_pid = *global_pid+1;

                //std::cout<<"hello"<<std::endl;
        }
    }
    for(int j=0;j<phrases.size();j++){
        Phrase *phrase_head = &phrases.at(j);
        find_head(phrase_head);
    }
}
示例#14
0
void		get_rooms(t_env *env)
{
	t_args		*tmp;
	char		start;
	char		end;
	t_args		*prev;

	tmp = env->a_start;
	while (tmp)
	{
		if (start != 1 && tmp != env->a_start)
			start = is_start(prev);
		if (end != 1 && tmp != env->a_start)
			end = is_end(prev);
		if (is_room(tmp, env, 1) != -1)
		{
			add_room(env, ft_strsplit(tmp->data, ' '), start, end);
			start = 0;
			end = 0;
		}
		else if (is_command(tmp) != 1 && is_com(tmp) != 1 && \
		is_ants(tmp, env) != 1)
			break ;
		prev = tmp;
		tmp = tmp->next;
	}
}
示例#15
0
文件: parser.c 项目: hacatu/Praser2
/*
char str_getc_esc(const char **s){
	if(*(*s)++ != '\\'){
		return (*s)[-1];
	}
	char ret = 0;
	switch(**s){
	case 'a':
		++*s;
		return '\a';
	case 'b':
		++*s;
		return '\b';
	case 'e':
		++*s;
		return '\e';
	case 'f':
		++*s;
		return '\f';
	case 'n':
		++*s;
		return '\n';
	case 'r':
		++*s;
		return '\r';
	case 't':
		++*s;
		return '\t';
	case 'v':
		++*s;
		return '\v';
	case 'x':
		++*s;
		if('0' <= **s && **s <= '9'){
			ret = (**s - '0') << 4;
		}else if('A' <= **s && **s <= 'F'){
			ret = (**s - 'A' + 10) << 4;
		}else if('a' <= **s && **s <= 'f'){
			ret = (**s - 'a' + 10) << 4;
		}else{
			return '\0';
		}
		++*s;
		if('0' <= **s && **s <= '9'){
			ret |= **s - '0';
		}else if('A' <= **s && **s <= 'F'){
			ret |= **s - 'A' + 10;
		}else if('a' <= **s && **s <= 'f'){
			ret |= **s - 'a' + 10;
		}else{
			return '\0';
		}
		++*s;
		return ret;
	default:
		if('0' <= **s && **s <= '7'){
			ret = (*(*s)++ - '0') << 6; 
		}else{
			return *(*s)++;
		}
		if('0' <= **s && **s <= '7'){
			ret |= (*(*s)++ - '0') << 3;
		}else{
			return '\0';
		}
		return ('0' <= **s && **s <= '7') ? ret | (*(*s)++ - '0') : '\0';
	}
}
*/
int read_charset_prefix(const char *a, ast *t, position *p){
	if(is_end(p)){
		return 0;
	}
	int found = 0;
	for(const char *s = a + 1; *s;){
		++s;
		if(s[-1] == '.'){
			if(*p->curr == *s++){
				found = 1;
				break;
			}
		}else if(*s++ > *p->curr){
			s++;
		}else if(*p->curr <= *s++){
			found = 1;
			break;
		}
	}
	if(found ^ (*a == '-')){
		add_text(t, p->curr, 1);
		++p->curr;
		return 1;
	}
	return 0;
}
示例#16
0
 void increment()
 {
     BOOST_ASSERT(!is_end());
     this->base_reference() = detail::assert_not_old(this->base())(
         m_elect(this->base(), egg::to_cref(m_last))
     );
 }
示例#17
0
 void move_next()
 {
     if (!is_end())
     {
         ++_iter;
     }
 }
示例#18
0
static TrieNode<CharT, BucketT>*
random_sample(unsigned char** strings, size_t n)
{
	const size_t sample_size = n/8192;
	debug()<<__PRETTY_FUNCTION__<<" sampling "<<sample_size<<" strings\n";
	size_t max_nodes = (sizeof(CharT) == 1) ? 5000 : 2000;
	TrieNode<CharT, BucketT>* root = new TrieNode<CharT, BucketT>;
	for (size_t i=0; i < sample_size; ++i) {
		unsigned char* str = strings[size_t(drand48()*n)];
		size_t depth = 0;
		TrieNode<CharT, BucketT>* node = root;
		while (true) {
			CharT c = get_char<CharT>(str, depth);
			if (is_end(c)) break;
			depth += sizeof(CharT);
			node->extend(c+1);
			if (not node->is_trie(c)) {
				node->_buckets[c] = new TrieNode<CharT, BucketT>;
				make_trie(node->_buckets[c]);
				if (--max_nodes==0) goto finish;
			}
			node = node->get_node(c);
			assert(node);
		}
	}
finish:
	return root;
}
示例#19
0
static TrieNode<CharT, BucketT>*
pseudo_sample(unsigned char** strings, size_t n)
{
	debug()<<__func__<<"(): sampling "<<n/8192<<" strings ...\n";
	size_t max_nodes = (sizeof(CharT) == 1) ? 5000 : 2000;
	TrieNode<CharT, BucketT>* root = new TrieNode<CharT, BucketT>;
	for (size_t i=0; i < n; i += 8192) {
		unsigned char* str = strings[i];
		size_t depth = 0;
		TrieNode<CharT, BucketT>* node = root;
		while (true) {
			CharT c = get_char<CharT>(str, depth);
			if (is_end(c)) break;
			depth += sizeof(CharT);
			node->extend(c+1);
			if (not node->is_trie(c)) {
				node->_buckets[c] = new TrieNode<CharT, BucketT>;
				make_trie(node->_buckets[c]);
				if (--max_nodes==0) goto finish;
			}
			node = node->get_node(c);
			assert(node);
		}
	}
finish:
	return root;
}
示例#20
0
static inline size_t
handle_bucket(TSTNode<CharT>* node,
              unsigned char** strings,
              size_t pos,
              size_t depth)
{
	static_assert(BucketNum < 3, "BucketNum < 3");
	if (node->is_tst[BucketNum]) {
		pos = burst_traverse<BucketT>(
			static_cast<TSTNode<CharT>*>(node->buckets[BucketNum]),
			strings,
			pos,
			depth + (BucketNum==1)*sizeof(CharT));
	} else if (node->buckets[BucketNum]) {
		BucketT* buck = static_cast<BucketT*>(node->buckets[BucketNum]);
		size_t bsize = buck->size();
		std::copy(buck->begin(), buck->end(), strings+pos);
		delete buck;
		if (not is_middle_bucket(BucketNum)) {
			mkqsort(strings+pos, bsize, depth);
		} else if (not is_end(node->pivot)) {
			mkqsort(strings+pos,
				bsize,
				depth+sizeof(CharT));
		}
		pos += bsize;
	}
	return pos;
}
示例#21
0
文件: a2_io.c 项目: changguanghua/A2
// read a char from io buf
inline char a2_io_readchar(struct a2_io* io_p){
	assert(io_p);
	if(is_end(io_p)) 
		return '\0';
	if(is_load(io_p, 0)) 
		_a2_io_load(io_p);
	
	return io_p->buf[io_p->seek++];
}
示例#22
0
文件: loop.c 项目: AmesianX/tg
void net_loop (int flags, int (*is_end)(void)) {
  delete_stdin_event = 0;
  if (verbosity >= E_DEBUG) {
    logprintf ("Starting netloop\n");
  }
  if (flags & 3) {
    if (flags & 1) {
      term_ev = event_new (TLS->ev_base, 0, EV_READ | EV_PERSIST, stdin_read_callback_char, 0);
    } else {
      term_ev = event_new (TLS->ev_base, 0, EV_READ | EV_PERSIST, stdin_read_callback_line, 0);
    }
    event_add (term_ev, 0);
  }
  int last_get_state = time (0);
  while (!is_end || !is_end ()) {

    event_base_loop (TLS->ev_base, EVLOOP_ONCE);

    if (term_ev && delete_stdin_event) {
      event_free (term_ev);
      term_ev = 0;
    }

    #ifdef USE_LUA
      lua_do_all ();
    #endif
    if (safe_quit && !TLS->active_queries) {
      printf ("All done. Exit\n");
      do_halt (0);
    }
    if (sigterm_cnt > 0) {
      do_halt (0);
    }
    if (time (0) - last_get_state > 3600) {
      tgl_do_lookup_state (TLS);
      last_get_state = time (0);
    }
    write_state_file ();
    update_prompt ();
    if (unknown_user_list_pos) {
      int i;
      for (i = 0; i < unknown_user_list_pos; i++) {
        tgl_do_get_user_info (TLS, TGL_MK_USER (unknown_user_list[i]), 0, 0, 0);
      }
      unknown_user_list_pos = 0;
    }   
  }

  if (term_ev) {
    event_free (term_ev);
    term_ev = 0;
  }
  
  if (verbosity >= E_DEBUG) {
    logprintf ("End of netloop\n");
  }
}
示例#23
0
文件: parser.c 项目: hacatu/Praser2
int read_dedent(position *p){
	if(is_end(p)){
		return 0;
	}
	if(*p->curr == '\x14'){//Device control 4, generated by preprocessing
		++p->curr;
		return 1;
	}
	return 0;
}
示例#24
0
文件: parser.c 项目: hacatu/Praser2
int read_newline(position *p){
	if(is_end(p)){
		return 0;
	}
	if(*p->curr == '\n'){
		++p->curr;
		return 1;
	}
	return 0;
}
示例#25
0
unsigned find_in_sensitive (long given)
{
  unsigned find;
  for (find = 0; !is_end (find); find++)
    {
      if ((given & SENSE_INSTR_MASK (find)) == SENSE_INSTR_VALUE (find))
	return find;
    }
  return find;
}
示例#26
0
文件: parser.c 项目: hacatu/Praser2
int read_setrange(char a, char b, ast *t, position *p){
	if(is_end(p)){
		return 0;
	}
	if(a <= *p->curr && *p->curr <= b){
		add_text(t, p->curr, 1);
		++p->curr;
		return 1;
	}
	return 0;
}
int		nb_car(char *str, char c)
{
  int	res;
  int	i;

  res = 0;
  i = 0;
  while (is_end(str[i]) == 0 && str[i] != c && str[i] != '\n' && str[i] != '\t')
    i++;
  return (i);
}
示例#28
0
LQ_EXTERN_C LqHttpPthResultEnm LQ_CALL LqHttpPthCopyFile
(
	LqHttp* Http,
	const char* WebDomenDest,
	const char* WebDomenSource,
	const char* WebPath
) {
	auto Dmns = LqHttpGetHttpData(Http)->Dmns;
	auto DmnSourceInterator = Dmns.search(WebDomenSource);
	auto DmnDestInterator = Dmns.search(WebDomenDest);
	if(DmnSourceInterator.is_end() || DmnDestInterator.is_end())
		return LQHTTPPTH_RES_NOT_HAVE_DOMEN;
	auto PthInterator = (*DmnSourceInterator)->Pths.search(WebPath);
	if(PthInterator.is_end())
		return LQHTTPPTH_RES_NOT_HAVE_PATH;
	switch((*DmnDestInterator)->Pths.push_back_uniq(*PthInterator)) {
		case -1: return LQHTTPPTH_RES_NOT_ALLOC_MEM;
		case 0: return LQHTTPPTH_RES_ALREADY_HAVE;
	}
	return LQHTTPPTH_RES_OK;
}
示例#29
0
/* if fails return 1, else 0
   this function acts like the string starts AFTER the command word*/
static uint16_t send_txt_from_str(char *str, struct Bucket *buc)
{
    str = skip_spaces(str);
    if(!is_num(*str))
            return 1;
    buc->destination_address = str_to_int(str, &str);
    str = skip_spaces(str);
    if(is_end(*str))
            return 1;

    string_copy((char *) buc->message , str, 0);
    return 0;
}
示例#30
0
int sf(const char* seps, char *buf, char **fb, size_t fb_sz) {
    if (fb_sz < 1 || is_end(buf)) { *fb = 0; return 0; }
    str_spn sseps(seps);
    fb[0] = 0;
    int n = 0;
    // skip leading delimeters
    buf = sseps.cbrk(buf);
    if (is_end(buf)) return 0;
    // store fields
    while (n < (int) fb_sz) {
        fb[n++] = buf;
        // find delimeters
        buf = sseps.brk(buf+1);
        if (is_end(buf)) break;
        *buf = 0;
        // skip delimiters
        buf = sseps.cbrk(buf+1);
        if (is_end(buf)) break;
    }
    fb[n] = 0;
    return n;
}