Пример #1
0
static int entry_erase(LuaState *L)
{
    Entry *e  = ms_lua_checkclass(L, CLASS, 1);
    int count = luaL_checkinteger(L, 2);
    if (!count)
        return 0;

    if (count > 0) {
        /* Delete chars after the current cursor location. */
        int start = e->curs_off;
        int end   = MIN(e->bufused, e->curs_off + count);
        erase_region(e, start, end);
    } else {
        /* Delete chars before the current cursor location */
        guint start = e->curs_off + count;
        guint end   = e->curs_off;

        /* Note: if (-count) > e->curs_off, start will overflow and
         * be > e->bufused */
        if (start > e->bufused)
            start = 0;
        erase_region(e, start, end);
    }
    return 0;
}
Пример #2
0
bool gui_input_mode_before_delete()
{
#if DBG_EXEC
    if( dbg_flags&DBG_EXEC )
        _dbg_msg( FormatString("Before delete in %s dot is %d") << bf_cur->b_buf_name << dot );
#endif
    bool result = false;

    if( bf_cur->b_mark.isSet()                          // have a mark
    && bf_cur->b_gui_input_mode_set_mark )              // owned by GUI input
    {
        if( (bf_cur->b_mark.to_mark() - dot) != 0 )    // with a region that is not empty
        {
            erase_region();
#if DBG_EXEC
            if( dbg_flags&DBG_EXEC )
                _dbg_msg( "   erase_region()" );
#endif
            result = true;    // we did the delete
        }

        // force the mark to be unset
        bf_cur->unset_mark();
    }

    // always clear the shift state when deleting
    shift_state = false;

    return result;
}
Пример #3
0
void gui_input_mode_before_insert()
{
#if DBG_EXEC
    if( dbg_flags&DBG_EXEC )
        _dbg_msg( FormatString("Before insert in %s dot is %d") << bf_cur->b_buf_name << dot );
#endif
    if( bf_cur->b_mark.isSet() && bf_cur->b_gui_input_mode_set_mark )
    {
        erase_region();
#if DBG_EXEC
        if( dbg_flags&DBG_EXEC )
            _dbg_msg( "   erase_region()" );
#endif
    }
}
int CommandErase_Region(char *szCom, target_context_t **tc,
                        char *szRegion, unsigned long flags)
{
    int ret;

    init_crc32();

    if (flags & F_FORCE_LOCKED)
        opt_force_locked = 1;
    else
        opt_force_locked = 0;

    ret = CommandMemmap(szCom, tc);
    if (ret == FALSE)
        return FALSE;

    set_serial_timeout(((target_context_t *)*tc)->portfd, TIMEOUT_FLASH);
    ret = erase_region(*tc, szRegion);
    set_serial_timeout(((target_context_t *)*tc)->portfd, TIMEOUT_NORMAL);
    if (ret == -1)
        return FALSE;

    return TRUE;
}
Пример #5
0
int main(int argc, char *argv[])
{
	command_t *cmd;
	mem_region_t *mr;
	target_context_t *tc;

#if !defined(WIN32)
	cmd = get_commands(argc, argv);
	if(cmd == NULL) return -1;
#endif

	/* open raw ethernet socket if desired, then drop root */
#if !defined(WIN32)
	if (opt_ethernet)
		eth_raw_socket();
#endif
	drop_root();

	/* miscellaneous initialization */

	init_crc32();

	/* open a connection to the target */
	if (!(tc = target_open(opt_port, opt_ethernet ? opt_netif : NULL))){
		panic("couldn't open connection to target");
		return -1;
	}

	while (cmd) {
		command_t *tmp;

		if (opt_verbose)
			print_command(cmd);

		switch (cmd->type) {

#ifdef AJ_FIRMUPDATE_SUPPORT
                case CMD_FIRMUPDATE:
			mr = slurp_file_or_die(cmd->input_path);
			if(require_flags(tc, REQ_MEM_MAP) == -1){
				return -1;
			}
                        firmupdate(tc, mr);
			break;
#endif

		case CMD_DOWNLOAD:
			if (cmd->region && cmd->info.download.have_address){
				panic("can't specify both region and address");
				return -1;
			}

			mr = slurp_file_or_die(cmd->input_path);
			if(require_flags(tc, REQ_MEM_MAP) == -1){
				return -1;
			}
			if (cmd->region)
				download_to_region(tc, mr, cmd->region);
			else if (cmd->info.download.have_address)
				download_to_addr(tc, mr, cmd->addr);
			else{
				warn("download: must specify address or region\n");
				return -1;
			}
			break;

		case CMD_ERASE:
			if (cmd->region && cmd->info.download.have_address){
				panic("can't specify both region and address");
				return -1;
			}

			if(require_flags(tc, REQ_MEM_MAP) == -1){
				return -1;
			}
			if (cmd->region)
				erase_region(tc, cmd->region);
			else if (cmd->info.download.have_address)
				erase_addr(tc, cmd->addr);
			else{
				warn("erase: must specify address or region\n");
				return -1;
			}
			break;

		case CMD_MAP:
			if(require_flags(tc, REQ_MEM_MAP) == -1){
				return -1;
			}
			region_print(tc->memmap);
			return 0;

		case CMD_TERMINAL:
			if(restore_interactive(tc) == -1){
				return -1;
			}
#if !defined(WIN32)
			serial_terminal();
#endif
			return 0;

		case CMD_MD5SUM:
			if (cmd->region && cmd->info.download.have_address){
				panic("md5sum: can't specify both region and address");
				return -1;
			}

			if (cmd->size == 0) {
				warn("md5sum: must specify size\n");
				return -1;
			}

			if (cmd->region){
				if(require_flags(tc, REQ_MEM_MAP) == -1){
					return -1;
				}

				md5sum_region(tc, cmd->region, cmd->size);
			} else if (cmd->info.download.have_address) {
				md5sum_addr(tc, cmd->addr, cmd->size);
			} else{
				warn("md5sum: must specify address or region\n");
				return -1;
			}
			break;

		default:
			warn("unsupported command\n");
			return -1;
		}

		tmp = cmd;
		cmd = cmd->next;
		/*
		 * We don't free paths in the command because we don't
		 * know whether or not they're dynamically allocated.
		 * Thus we leak a little memory.  It's not like this
		 * is a long-running program...
		 */
		free(tmp);
	}

	restore_interactive(tc);
	return 0;
}