示例#1
0
/* If this forms a complete tree down to max_depth, it's fixed. */
static bool is_fixed(const struct maaku_tree *tree, struct maaku_node *node)
{
	if (node->fixed)
		return true;

	if (node->depth == tree->max_depth)
		return node->fixed = true;

	if (!node->child[0] || !node->child[1])
		return false;

	node->fixed = is_fixed(tree, node->child[0]) && is_fixed(tree, node->child[1]);
	return node->fixed;
}
示例#2
0
文件: grep.c 项目: 2quala/git
static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
{
	int err;

	p->word_regexp = opt->word_regexp;
	p->ignore_case = opt->ignore_case;

	if (opt->fixed || is_fixed(p->pattern, p->patternlen))
		p->fixed = 1;
	else
		p->fixed = 0;

	if (p->fixed) {
		if (opt->regflags & REG_ICASE || p->ignore_case)
			p->kws = kwsalloc(tolower_trans_tbl);
		else
			p->kws = kwsalloc(NULL);
		kwsincr(p->kws, p->pattern, p->patternlen);
		kwsprep(p->kws);
		return;
	}

	if (opt->pcre) {
		compile_pcre_regexp(p, opt);
		return;
	}

	err = regcomp(&p->regexp, p->pattern, opt->regflags);
	if (err) {
		char errbuf[1024];
		regerror(err, &p->regexp, errbuf, 1024);
		regfree(&p->regexp);
		compile_regexp_failed(p, errbuf);
	}
}
示例#3
0
文件: grep.c 项目: Fabiano-lr/git
static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
{
	int err;

	p->word_regexp = opt->word_regexp;

	if (opt->fixed || is_fixed(p->pattern))
		p->fixed = 1;
	if (opt->regflags & REG_ICASE)
		p->fixed = 0;
	if (p->fixed)
		return;

	err = regcomp(&p->regexp, p->pattern, opt->regflags);
	if (err) {
		char errbuf[1024];
		char where[1024];
		if (p->no)
			sprintf(where, "In '%s' at %d, ",
				p->origin, p->no);
		else if (p->origin)
			sprintf(where, "%s, ", p->origin);
		else
			where[0] = 0;
		regerror(err, &p->regexp, errbuf, 1024);
		regfree(&p->regexp);
		die("%s'%s': %s", where, p->pattern, errbuf);
	}
}
示例#4
0
int is_solved() {
	int i;
	for(i=0; i<81; i++)
	if(!is_fixed(s[i]))
		return 0;
	printf("solved!\n");
	return 1;
}
示例#5
0
// returns a mask which covers all fixed values of the structure
int get_fixed_mask(int* struc[9]) {
	int mask = 0;
	int i;
	for(i=0; i<9; i++)
		if(is_fixed(*struc[i]))
			mask |= *struc[i];
	return mask;
}
示例#6
0
文件: grep.c 项目: KarthikNayak/git
static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
{
	int icase, ascii_only;
	int err;

	p->word_regexp = opt->word_regexp;
	p->ignore_case = opt->ignore_case;
	icase	       = opt->regflags & REG_ICASE || p->ignore_case;
	ascii_only     = !has_non_ascii(p->pattern);

	/*
	 * Even when -F (fixed) asks us to do a non-regexp search, we
	 * may not be able to correctly case-fold when -i
	 * (ignore-case) is asked (in which case, we'll synthesize a
	 * regexp to match the pattern that matches regexp special
	 * characters literally, while ignoring case differences).  On
	 * the other hand, even without -F, if the pattern does not
	 * have any regexp special characters and there is no need for
	 * case-folding search, we can internally turn it into a
	 * simple string match using kws.  p->fixed tells us if we
	 * want to use kws.
	 */
	if (opt->fixed || is_fixed(p->pattern, p->patternlen))
		p->fixed = !icase || ascii_only;
	else
		p->fixed = 0;

	if (p->fixed) {
		p->kws = kwsalloc(icase ? tolower_trans_tbl : NULL);
		kwsincr(p->kws, p->pattern, p->patternlen);
		kwsprep(p->kws);
		return;
	} else if (opt->fixed) {
		/*
		 * We come here when the pattern has the non-ascii
		 * characters we cannot case-fold, and asked to
		 * ignore-case.
		 */
		compile_fixed_regexp(p, opt);
		return;
	}

	if (opt->pcre) {
		compile_pcre_regexp(p, opt);
		return;
	}

	err = regcomp(&p->regexp, p->pattern, opt->regflags);
	if (err) {
		char errbuf[1024];
		regerror(err, &p->regexp, errbuf, 1024);
		regfree(&p->regexp);
		compile_regexp_failed(p, errbuf);
	}
}
示例#7
0
ascii_man::ascii_man()
{
	did_move(false);
	did_collide(false);
	feels_gravity(true);
	did_gravity(false);
	is_fixed(false);
	isdead(false);
	can_die(true);

	initialize(0);
}
示例#8
0
int simplify_nakedsingle_struc(int* struc[9]) {
	int progress = 0;
	int i,j;
	for(i=0; i<9; i++)
		if(is_fixed(*struc[i]))
			for(j=0; j<9; j++)
				if(i!=j && (*struc[j] & *struc[i])) {
					*struc[j] -= *struc[i];
					progress = 1;
				}

	return progress;
}
示例#9
0
/**
 * \brief Apply a forced movement to the item.
 * \param m The movement to apply.
 * \remark If this object already have a movement, il will be released.
 */
void
bear::universe::physical_item::set_forced_movement( const forced_movement& m )
{
  clear_forced_movement();

  if ( is_fixed() )
    claw::logger << claw::log_warning
                 << "physical_item::set_forced_movement(): setting a "
                 << "forced movement but the item is fixed." << std::endl;

  set_acceleration( force_type(0, 0) );

  m_forced_movement = m;

  if ( !m_forced_movement.is_null() )
    {
      m_forced_movement.set_item(*this);
      m_forced_movement.init();
    }
} // physical_item::set_forced_movement()
示例#10
0
bool fixable_page_h::change_possible_after_fix() const {
    w_assert1(is_fixed());
    return false; // for now assume no interference <<<>>>
}
示例#11
0
void TransformationCalculator::load_robot_model(std::string filepath, bool init_invalid){
    clear_all();

    bool success=false;
    success = kdl_parser::treeFromFile(filepath, kdl_tree_);
    if(!success){
        is_initialized_ = false;
        throw("Could not load Model file");
    }

    //Extract names of all joints defined in urdf file.
    //These are the names that are expected to be referred to in update function.
    KDL::SegmentMap map = kdl_tree_.getSegments();
    std::string root_name = kdl_tree_.getRootSegment()->first;

    KDL::Joint joint;
    KDL::Segment segment;
    for(KDL::SegmentMap::const_iterator it = map.begin(); it!=map.end(); ++it){
#ifdef KDL_USE_NEW_TREE_INTERFACE
        segment = it->second->segment;
#else
        segment = it->second.segment;
#endif
        joint = segment.getJoint();
        std::string j_name = joint.getName();

        if(j_name == "NoName" || j_name == ""){
            if(segment.getName() != root_name){
                LOG_ERROR("Segment %s has an unnamed joint. This is not okay, but will skip it for now.", segment.getName().c_str());
            }
            LOG_DEBUG("Skipping NonName joint of root segment");
            continue;
        }

        if(is_fixed(joint)){
            if(std::find(static_joint_names_.begin(), static_joint_names_.end(), j_name) == static_joint_names_.end()){
                static_segment_names_.push_back(segment.getName());
                static_joint_names_.push_back(j_name);
                joint_name2seg_name_[j_name] = segment.getName();
                all_joint_names_.push_back(j_name);
            }
        }
        if(is_valid_joint(joint)){
            if(std::find(moving_joint_names_.begin(), moving_joint_names_.end(), j_name) == moving_joint_names_.end()){
                moving_joint_names_.push_back(j_name);
                joint_name2seg_name_[j_name] = segment.getName();
                all_joint_names_.push_back(j_name);
            }
        }

    }
    //link_names_ = extract_keys(map);

    //Populate transforms map with identity transforms
    for(std::vector<std::string>::iterator it = moving_joint_names_.begin();
        it != moving_joint_names_.end(); ++it)
    {
        std::string j_name = *it;
        std::string seg_name = joint_name2seg_name_[j_name];
        moving_joints_transforms_[j_name] = base::samples::RigidBodyState(true);
        if(!init_invalid){
            //initUnknow sets trasform to identity. If we donÄt want invalidating, set to identity.
            moving_joints_transforms_[j_name].initUnknown();
        }
        moving_joints_transforms_[j_name].sourceFrame = seg_name;
#ifdef KDL_USE_NEW_TREE_INTERFACE
        moving_joints_transforms_[j_name].targetFrame = get_tree_element(seg_name).parent->second->segment.getName();
#else
        moving_joints_transforms_[j_name].targetFrame = get_tree_element(seg_name).parent->second.segment.getName();
#endif
    }

    //Populate static transforms vector
    for(uint i=0; i<static_joint_names_.size(); i++){
        std::string seg_name = static_segment_names_[i];
        KDL::TreeElement tree_elem = get_tree_element(seg_name);
        KDL::Frame kdl_transform = tree_elem.segment.pose(0);
        std::string j_name = static_joint_names_[i];
        base::samples::RigidBodyState rbs;
        convert(kdl_transform, rbs);
        //Skip root
        if(tree_elem.segment.getName() == kdl_tree_.getRootSegment()->first){
            continue;
        }
#ifdef KDL_USE_NEW_TREE_INTERFACE
        rbs.sourceFrame = tree_elem.parent->second->segment.getName();
#else
        rbs.sourceFrame = tree_elem.parent->second.segment.getName();
#endif
        rbs.targetFrame = tree_elem.segment.getName();
        static_joints_transforms_[j_name] = rbs;
    }


    is_initialized_ = true;
}
示例#12
0
int main(int argc, char *argv[])
{
    char         puzzle[82];
    sudoku_hint  hints[81];
    sudoku_hint  *hint;
    int         hint_cells[9];
    int ch;     /* getch */
    int i, t;   /* temp */
    int r, c, n;    /* more temp */
    int cr = 1; /* cursor position */
    int cc = 1; /* cursor position */
    int flags = 0;

    boardy = 1;
    boardx = 1;
    cellh = 3;
    cellw = 7;

    initscr();
    noecho();
    cbreak();
    keypad(stdscr, TRUE);

    getmaxyx(stdscr, winh, winw);
    init_msg_area();
    init_panels();

    /* set up and draw board */
    init_board(&board);
    nc_init_board(&ncboard, stdscr, &board, boardy, boardx, cellh, cellw);
    draw_board(&ncboard);
    print_title_area("%s", str_entry_mode);
    update_panels();
    doupdate();
    move_cursor(&ncboard, cr, cc);

    while ((ch = getch()) != 'q') {
        if (flags & ERROR_BIT) {
            clear_msg();
            flags ^= ERROR_BIT;
        }
        switch (ch) {
            case 0xC:  /* ^L form feed FF clear screen */
                unhighlight_all(&ncboard);
                draw_board(&ncboard);
                touchwin(curscr);
                wrefresh(curscr);
                break;
            case '?':   /* show help */
                print_msg("%s", str_help);
                break;
            case 'h':
                move_cursor_left(&ncboard, &cr, &cc);
                break;
            case 'j':
                move_cursor_down(&ncboard, &cr, &cc);
                break;
            case 'k':
                move_cursor_up(&ncboard, &cr, &cc);
                break;
            case 'l':
                move_cursor_right(&ncboard, &cr, &cc);
                break;
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                set_value(&board, cr, cc, ch);
                draw_cell(&ncboard, cr, cc);
                break;
            case ' ':
            case 'd':
            case 0x08: /* ^H */
            case KEY_BACKSPACE:
                set_value(&board, cr, cc, ' ');     /* erase */
                draw_cell(&ncboard, cr, cc);
                break;
            case 'c':
                unhighlight_all(&ncboard);
                clear_board(&board);
                draw_board(&ncboard);
                break;
            case 'f': toggle_fix_mode(&board);
                /* if entering fixed mode, validate and solve puzzle */
                if (get_givens(&board, puzzle) != NULL) {
                    /* if puzzle invalid */
                    if (!sudoku_solve_hints(puzzle, hints)) {
                        toggle_fix_mode(&board);
                        print_msg("Error: %s", str_invalid_puzzle);
                        flags |= ERROR_BIT;
                    } else { /* puzzle valid, but check uniqueness */
                        print_title_area("%s", str_solve_mode);
                        if (sudoku_nsolve(puzzle, NULL, 2) > 1) {
                            print_msg("%s", str_not_unique);
                            flags |= ERROR_BIT;
                            flags |= HINTS_DISABLED;
                        }
                    }
                } else {
                    print_title_area("%s", str_entry_mode);
                    flags &= ~ HINTS_DISABLED;
                }
                /* toggle_fix_mode (un)bolds every char so refresh needed */
                draw_board(&ncboard);
                break;
            case 'u': t = undo_board(&board);   /* only works in fixed mode */
                if (t >= 0) {
                    cr = t / 9 + 1;
                    cc = t % 9 + 1;
                    draw_cell(&ncboard, cr, cc);
                }
                break;
            case 's':   /* solve puzzle if in fixed mode */
                if (!is_fixed(&board)) {
                    print_msg("%s: %s", str_not_fixed,
                            "press 'f' to fix the givens first.");
                    flags |= ERROR_BIT;
                    break;
                } /* else */
                for (i = 0; i < 81; i++) {
                    hint2rcn(hints + i, &cr, &cc, &t);
                    set_value(&board, cr, cc, t % 10 + '0');
                }
                draw_board(&ncboard);
                break;
            case 'H':   /* give hint, if in fixed mode */
                if (!is_fixed(&board)) {
                    print_msg("%s: %s", str_not_fixed,
                            "Hints are only given in solver mode.");
                    flags |= ERROR_BIT;
                    break;
                }
                if (flags & HINTS_DISABLED)
                    break;
                unhighlight_all(&ncboard);
                get_values(&board, puzzle);
                hint = next_hint(hints, puzzle);
                if (hint - hints == 81)
                    break;
                t = hint2cells(hint, hint_cells);
                for (i = 0; i < t; i++) {
                    c = hint_cells[i];
                    r = c / 9 + 1;
                    c = c % 9 + 1;
                    highlight_cell(&ncboard, r, c);
                }
                if (t > 1) {
                    hint2rcn(hint, &r, &c, &n);
                    print_msg("Hint: try a %d in the highlighted cells", n);
                }
                draw_board(&ncboard);
                break;
        }
        update_panels();
        doupdate();
        move_cursor(&ncboard, cr, cc);
    }

    endwin();

    return 0;
}