示例#1
0
文件: fpick.c 项目: matyler/mtPaint
/* Scan directory, populate widgets; return 1 if success, 0 if total failure,
 * -1 if failed with original dir and scanned a different one */
static int fpick_scan_directory(fpick_dd *dt, char *name, char *select)
{
	DIR	*dp;
	char	*cp, *parent = NULL;
	char	full_name[PATHBUF];
	int len, fail, res = 1;


	strncpy0(full_name, name, PATHBUF - 1);
	len = strlen(full_name);
	/* Ensure the invariant */
	if (!len || (full_name[len - 1] != DIR_SEP))
		full_name[len++] = DIR_SEP , full_name[len] = 0;
	/* Step up the path till a searchable dir is found */
	fail = 0;
	while (!(dp = opendir(full_name)))
	{
		res = -1; // Remember that original path was invalid
		full_name[len - 1] = 0;
		cp = strrchr(full_name, DIR_SEP);
		// Try to go one level up
		if (cp) len = cp - full_name + 1;
		// No luck - restart with current dir
		else if (!fail++)
                {
			getcwd(full_name, PATHBUF - 1);
			len = strlen(full_name);
			full_name[len++] = DIR_SEP;
                }
		// If current dir hasn't helped either, give up
		else return (0);
		full_name[len] = 0;
	}

	/* If we're going up the path and want to show from where */
	if (!select)
	{
		if (!strncmp(dt->txt_directory, full_name, len) &&
			dt->txt_directory[len])
		{
			cp = strchr(dt->txt_directory + len, DIR_SEP); // Guaranteed
			parent = dt->txt_directory + len;
			select = parent = g_strndup(parent, cp - parent);
		}
	}
	/* If we've nothing to show */
	else if (!select[0]) select = NULL; 

	strncpy(dt->txt_directory, full_name, PATHBUF);
	fpick_directory_new(dt, full_name);	// Register directory in combo

	scan_dir(dt, dp, select);
	g_free(parent);
	closedir(dp);
	filter_dir(dt, dt->txt_mask);

	cmd_reset(dt->list, dt);

	return (res);
}
示例#2
0
static void shift_btn(shifter_dd *dt, void **wdata, int what, void **where)
{
	int i;

	if ((what == op_EVT_OK) || (what == op_EVT_CANCEL))
	{
		shift_play_state = FALSE; // Stop

		mem_pal_copy(mem_pal, dt->old_pal);
		update_stuff(UPD_PAL);

		run_destroy(wdata);
		return;
	}

	if (what == op_EVT_CHANGE) // Play toggle
	{
		cmd_read(where, dt);
		if (shift_play_state && !shift_timer_state) // Start timer
			shift_timer_state = threads_timeout_add(100,
				shift_play_timer_call, dt);
		return;
	}

	where = origin_slot(where);

	if (where == dt->fix)	// Button to fix palette pressed
	{
		i = dt->frame[0];
		if (!i || (i > dt->frame[2])) return; // Nothing to do

		mem_pal_copy(mem_pal, dt->old_pal);
		spot_undo(UNDO_PAL);
		shifter_set_palette(dt, i);
		mem_pal_copy(dt->old_pal, mem_pal);
		cmd_set(dt->slider, 0);
		update_stuff(UPD_PAL);
	}

	else if (where == dt->clear)	// Button to clear all of the values
	{
		for (i = 0; i < NSHIFT; i++)
			spins[i][0][0] = spins[i][1][0] = spins[i][2][0] = 0;
		cmd_reset(dt->spinpack, dt);
		shifter_moved(dt, wdata, op_EVT_CHANGE, dt->spinpack);
	}

	else if (where == dt->create)	// Button to create a sequence of undo images
	{
		if (!dt->frame[2]) return;	// Nothing to do

		for (i = 0; i <= dt->frame[2]; i++)
		{
			shifter_set_palette(dt, i);
			spot_undo(UNDO_PAL);
		}
		shifter_set_palette(dt, dt->frame[0]);
		update_stuff(UPD_PAL);
	}
}
示例#3
0
void intel_cmd_destroy(struct intel_cmd *cmd)
{
    cmd_reset(cmd);

    intel_free(cmd, cmd->relocs);
    intel_base_destroy(&cmd->obj.base);
}
示例#4
0
static int
process_command(int serial, int cid, char *cmd)
{
  /*char *opt, *opt2; */
  char *p, *opt;
  int ret;

  if ((p = strchr(cmd, '\n')))
	*p = '\0';
  else
	return -1;

  if ((opt = strchr(cmd, ' '))) {
	*opt = '\0';
	opt ++;
  } else {
	opt = NULL;
  }

  debug_printf(DEBUG_NOTE, "cmd: %s\n", cmd);

  if (strcmp(cmd, "RELEASE") == 0)
	ret = cmd_release(cid);
  else if (strcmp(cmd, "UNFOCUSED") == 0)
	ret = cmd_unfocused(cid);
  else if (strcmp(cmd, "FOCUSED") == 0)
	ret = cmd_focused(cid);
  else if (strcmp(cmd, "HIDE") == 0)
	ret = cmd_hide(cid);
  else if (strcmp(cmd, "SHOW") == 0)
	ret = cmd_show(cid);
  else if (strcmp(cmd, "NEW") == 0)
  	ret = cmd_new(cid, opt);
  else if (strcmp(cmd, "RESET") == 0)
	ret = cmd_reset(cid);
  else if (strcmp(cmd, "CHANGE") == 0)
  	ret = cmd_change(cid, opt);
  else if (strcmp(cmd, "PROP") == 0)
  	ret = cmd_prop(cid, opt);
  else if (strcmp(cmd, "LABEL") == 0)
  	ret = cmd_label(cid);
  else if (strcmp(cmd, "HELPER") == 0)
	ret = cmd_helper(cid, opt);
  else if (strcmp(cmd, "NOP") == 0)
  	ret = cmd_nop(cid);
  else if (strcmp(cmd, "LIST") == 0)
  	ret = cmd_list();
  else if (strcmp(cmd, "SETENC") == 0)
  	ret = cmd_setenc(opt);
  else if (strcmp(cmd, "GETENC") == 0)
  	ret = cmd_getenc(opt); /* for debug */
  else
	ret = cmd_error();

  return ret;
}
示例#5
0
VkResult intel_cmd_begin(struct intel_cmd *cmd, const VkCommandBufferBeginInfo *info)
{
    VkResult ret;
    uint32_t i;

    cmd_reset(cmd);

    /* TODOVV: Check that render pass is defined */
    const VkCommandBufferInheritanceInfo *hinfo = info->pInheritanceInfo;
    if (!cmd->primary) {
        cmd_begin_render_pass(cmd,
                intel_render_pass(hinfo->renderPass),
                intel_fb(hinfo->framebuffer),
                hinfo->subpass,
                VK_SUBPASS_CONTENTS_INLINE);
    }

    if (cmd->flags != info->flags) {
        cmd->flags = info->flags;
        cmd->writers[INTEL_CMD_WRITER_BATCH].size = 0;
    }

    if (!cmd->writers[INTEL_CMD_WRITER_BATCH].size) {
        const uint32_t size = cmd->dev->gpu->max_batch_buffer_size / 2;

        cmd->writers[INTEL_CMD_WRITER_BATCH].size = size;
        cmd->writers[INTEL_CMD_WRITER_SURFACE].size = size / 2;
        cmd->writers[INTEL_CMD_WRITER_STATE].size = size / 2;
        cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].size = 16384;
    }

    for (i = 0; i < INTEL_CMD_WRITER_COUNT; i++) {
        ret = cmd_writer_alloc_and_map(cmd, i);
        if (ret != VK_SUCCESS) {
            cmd_reset(cmd);
            return  ret;
        }
    }

    cmd_batch_begin(cmd);

    return VK_SUCCESS;
}
示例#6
0
VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(
    VkCommandBuffer                              commandBuffer,
    VkCommandBufferResetFlags                    flags)
{
    struct intel_cmd *cmd = intel_cmd(commandBuffer);

    cmd_reset(cmd);

    return VK_SUCCESS;
}
示例#7
0
/*
 * Handle a char of an option toggle command.
 */
static int
mca_opt_char(int c)
{
	PARG parg;

	/*
	 * This may be a short option (single char),
	 * or one char of a long option name,
	 * or one char of the option parameter.
	 */
	if (curropt == NULL && len_cmdbuf() == 0) {
		int ret = mca_opt_first_char(c);
		if (ret != NO_MCA)
			return (ret);
	}
	if (optgetname) {
		/* We're getting a long option name.  */
		if (c != '\n' && c != '\r')
			return (mca_opt_nonfirst_char(c));
		if (curropt == NULL) {
			parg.p_string = get_cmdbuf();
			error("There is no --%s option", &parg);
			return (MCA_DONE);
		}
		optgetname = FALSE;
		cmd_reset();
	} else {
		if (is_erase_char(c))
			return (NO_MCA);
		if (curropt != NULL)
			/* We're getting the option parameter. */
			return (NO_MCA);
		curropt = findopt(c);
		if (curropt == NULL) {
			parg.p_string = propt(c);
			error("There is no %s option", &parg);
			return (MCA_DONE);
		}
	}
	/*
	 * If the option which was entered does not take a
	 * parameter, toggle the option immediately,
	 * so user doesn't have to hit RETURN.
	 */
	if ((optflag & ~OPT_NO_PROMPT) != OPT_TOGGLE ||
	    !opt_has_param(curropt)) {
		toggle_option(curropt, islower(c), "", optflag);
		return (MCA_DONE);
	}
	/*
	 * Display a prompt appropriate for the option parameter.
	 */
	start_mca(A_OPT_TOGGLE, opt_prompt(curropt), NULL, 0);
	return (MCA_MORE);
}
示例#8
0
文件: fpick.c 项目: matyler/mtPaint
static void fpick_scan_drives(fpick_dd *dt)	// Scan drives, populate widgets
{
	int cdrive = 0;

	/* Get the current drive letter */
	if (dt->txt_directory[1] == ':') cdrive = dt->txt_directory[0];

	dt->txt_directory[0] = '\0';
	cmd_setv(dt->combo, "", ENTRY_VALUE); // Just clear it

	scan_drives(dt, cdrive);
	cmd_reset(dt->list, dt);
}
示例#9
0
static int ms5607_power_on(struct ms5607_data *ms5607)
{
	int err;

	if (ms5607->pdata->power_on) {
		err = ms5607->pdata->power_on();
		if (err < 0)
			return err;
	}

	msleep(100);
	cmd_reset(ms5607->client);
	return 0;
}
示例#10
0
void cmd_process( const char* cmd )
{	
	switch( cmd[0] )
	{
		case WELCOME:
			cmd_welcome();
		break;
		case 'b':
			cmd_reboot();
		break;
		case 'e':
			cmd_eeprom(cmd);
		break;
		case 'i':
			cmd_current();
		break;
		case 'l':
			cmd_line_voltage();
		break;
		case 'm':
			cmd_stack_memory();
		break;
		case 'p':
			cmd_power(cmd);
		break;
		case 'q':
			cmd_capacity();
		break;
		case 'r':
			cmd_reset();
		break;
		case 't':
			cmd_temperatur();
		break;
		case 'u':
			cmd_voltage();
		break;
		case 'x':
			eMode = eTwike;
			plc_force_busy(0);
		break;
		case '?':
			cmd_help();
		break;
		default:
			strcpy_P(cmd_line, PSTR("<Unknown command, try ? for help."));
	}
	cmd_flush();
}
示例#11
0
文件: spi.c 项目: mrdudz/FPGAPCE
int spi_init()
{
	int j;
	int i;
	int r;
	SDHCtype=1;
	j=5;
	while(--j)
	{
		SPI_CS(0);	// Disable CS
		spi_spin();
		puts("SD init...\n");
	//	puts("SPI Init()\n");
		DBG("Activating CS\n");
		SPI_CS(1);
		i=50;
		while(--i)
		{
			if(cmd_reset()==1) // Enable SPI mode
			{
				i=1;
				j=1;
			}
			DBG("Sent reset command\n");
			if(i==2)
			{
				puts("SD card reset failed!\n");
				return(0);
			}
		}
	}
	DBG("Card responded to reset\n");
	SDHCtype=is_sdhc();
	if(SDHCtype)
		DBG("SDHC card detected\n");
	else 	// Not SDHC? Set blocksize to 512.
	{
		DBG("Sending cmd16\n");
		cmd_CMD16(1);
	}
	SPI(0xFF);
	SPI_CS(0);
	SPI(0xFF);
	DBG("Init done\n");

	return(1);
}
示例#12
0
文件: gps.cpp 项目: DrTon/Firmware
int
GPS::ioctl(struct file *filp, int cmd, unsigned long arg)
{
	lock();

	int ret = OK;

	switch (cmd) {
	case SENSORIOCRESET:
		cmd_reset();
		break;
	}

	unlock();

	return ret;
}
示例#13
0
文件: fpick.c 项目: matyler/mtPaint
/* Register directory in combo */
static void fpick_directory_new(fpick_dd *dt, char *name)
{
	char *dest, **cpp, txt[PATHTXT];
	int i;

	gtkuncpy(txt, name, PATHTXT);

	/* Does this text already exist in the list? */
	cpp = dt->cpp;
	for (i = 0 ; i < FPICK_COMBO_ITEMS - 1; i++)
		if (!strcmp(txt, cpp[i])) break;
	dest = cpp[i];
	memmove(cpp + 1, cpp, i * sizeof(*cpp)); // Shuffle items down as needed
	memcpy(cpp[0] = dest, txt, PATHTXT); // Add item to list

	dt->cdir = txt;
	cmd_reset(dt->combo, dt);
}
示例#14
0
文件: spawn.c 项目: matyler/mtPaint
static void faction_select_row(spawn_dd *dt, void **wdata, int what, void **where)
{
	spawn_row *rp;

	cmd_read(where, dt);

	if (dt->nidx == dt->idx) return; // no change
	dt->lock = TRUE;
	
	/* Get strings from array, and reset entries */
	rp = dt->strs + (dt->idx = dt->nidx);
	dt->name = rp->name;
	dt->cmd = rp->cmd;
	strncpy(dt->dir, rp->dir, PATHBUF);
	cmd_reset(dt->group, dt);

	dt->lock = FALSE;
}
示例#15
0
/*
 * Add a char to a long option name.
 * See if we've got a match for an option name yet.
 * If so, display the complete name and stop
 * accepting chars until user hits RETURN.
 */
static int
mca_opt_nonfirst_char(int c)
{
	char *p;
	char *oname;

	if (curropt != NULL) {
		/*
		 * Already have a match for the name.
		 * Don't accept anything but erase/kill.
		 */
		if (is_erase_char(c))
			return (MCA_DONE);
		return (MCA_MORE);
	}
	/*
	 * Add char to cmd buffer and try to match
	 * the option name.
	 */
	if (cmd_char(c) == CC_QUIT)
		return (MCA_DONE);
	p = get_cmdbuf();
	opt_lower = islower(p[0]);
	curropt = findopt_name(&p, &oname, NULL);
	if (curropt != NULL) {
		/*
		 * Got a match.
		 * Remember the option and
		 * display the full option name.
		 */
		cmd_reset();
		mca_opt_toggle();
		for (p = oname;  *p != '\0';  p++) {
			c = *p;
			if (!opt_lower && islower(c))
				c = toupper(c);
			if (cmd_char(c) != CC_OK)
				return (MCA_DONE);
		}
	}
	return (MCA_MORE);
}
示例#16
0
int
GPS::ioctl(struct file *filp, int cmd, unsigned long arg)
{
	lock();

	int ret = OK;

	switch (cmd) {
	case SENSORIOCRESET:
		cmd_reset();
		break;

	default:
		/* give it to parent if no one wants it */
		ret = CDev::ioctl(filp, cmd, arg);
		break;
	}

	unlock();

	return ret;
}
示例#17
0
文件: spi.c 项目: robinsonb5/ZPUDemos
int spi_init()
{
	int i;
	int r;
	SDHCtype=1;
	SPI_CS(0);	// Disable CS
	spi_spin();
	puts("SPI Init()\n");
	DBG("Activating CS\n");
	SPI_CS(1);
	i=8;
	while(--i)
	{
		if(cmd_reset()==1) // Enable SPI mode
			i=1;
		DBG("Sent reset command\n");
		if(i==2)
		{
			DBG("SD card initialization error!\n");
			return(0);
		}
	}
	DBG("Card responded to reset\n");
	SDHCtype=is_sdhc();
	if(SDHCtype)
		DBG("SDHC card detected\n");
	else // If not SDHC, Set blocksize to 512 bytes
	{
		DBG("Sending cmd16 (blocksize)\n");
		cmd_CMD16(1);
	}
	SPI(0xFF);
	SPI_CS(0);
	SPI(0xFF);
	DBG("Init done\n");

	return(1);
}
示例#18
0
/**@brief Function to consume queue item and notify the return value of the operation.
 *
 * @details This function will report the result and remove the command from the queue after
 *          notification.
 */
static void cmd_consume(uint32_t result, const fs_cmd_t * p_cmd)
{
    // Consume the current item on the queue.
    uint8_t rp = m_cmd_queue.rp;

    m_cmd_queue.count--;
    if (m_cmd_queue.count == 0)
    {
        // There are no elements left. Stop processing the queue.
        m_flags &= ~FS_FLAG_PROCESSING;
    }

    if (++(m_cmd_queue.rp) == FS_CMD_QUEUE_SIZE)
    {
        m_cmd_queue.rp = 0;
    }

    // Notify upon successful operation.
    app_notify(result, p_cmd);

    // Reset the queue element.
    cmd_reset(rp);
}
示例#19
0
文件: spi.c 项目: robinsonb5/ZPUTest
int spi_init()
{
    int i;
    int r;
    SDHCtype=1;
//	HW_PER(PER_TIMER_DIV7)=150;	// About 350KHz
    SPI_CS(0);	// Disable CS
    spi_spin();
//	puts("Activating CS\n");
    SPI_CS(1);
    i=8;
    while(--i)
    {
        if(cmd_reset()==1) // Enable SPI mode
            i=1;
        puts("Sent reset command\n");
        if(i==2)
        {
            puts("SD card initialization error!\n");
            return(0);
        }
    }
    puts("Card responded to reset\n");
    SDHCtype=is_sdhc();
    if(SDHCtype)
        puts("SDHC card detected\n");

    puts("Sending cmd16\n");
    cmd_CMD16(1);
    SPI(0xFF);
    SPI_CS(0);
    SPI(0xFF);
    puts("Init done\n");

//	HW_PER(PER_TIMER_DIV7)=HW_PER(PER_CAP_SPISPEED);
    return(1);
}
示例#20
0
文件: merge.c 项目: carey94tt/git
int cmd_merge(int argc, const char **argv, const char *prefix)
{
	unsigned char result_tree[20];
	unsigned char stash[20];
	unsigned char head_sha1[20];
	struct commit *head_commit;
	struct strbuf buf = STRBUF_INIT;
	const char *head_arg;
	int flag, i, ret = 0, head_subsumed;
	int best_cnt = -1, merge_was_ok = 0, automerge_was_ok = 0;
	struct commit_list *common = NULL;
	const char *best_strategy = NULL, *wt_strategy = NULL;
	struct commit_list *remoteheads, *p;
	void *branch_to_free;

	if (argc == 2 && !strcmp(argv[1], "-h"))
		usage_with_options(builtin_merge_usage, builtin_merge_options);

	/*
	 * Check if we are _not_ on a detached HEAD, i.e. if there is a
	 * current branch.
	 */
	branch = branch_to_free = resolve_refdup("HEAD", head_sha1, 0, &flag);
	if (branch && !prefixcmp(branch, "refs/heads/"))
		branch += 11;
	if (!branch || is_null_sha1(head_sha1))
		head_commit = NULL;
	else
		head_commit = lookup_commit_or_die(head_sha1, "HEAD");

	git_config(git_merge_config, NULL);

	if (branch_mergeoptions)
		parse_branch_merge_options(branch_mergeoptions);
	argc = parse_options(argc, argv, prefix, builtin_merge_options,
			builtin_merge_usage, 0);
	if (shortlog_len < 0)
		shortlog_len = (merge_log_config > 0) ? merge_log_config : 0;

	if (verbosity < 0 && show_progress == -1)
		show_progress = 0;

	if (abort_current_merge) {
		int nargc = 2;
		const char *nargv[] = {"reset", "--merge", NULL};

		if (!file_exists(git_path("MERGE_HEAD")))
			die(_("There is no merge to abort (MERGE_HEAD missing)."));

		/* Invoke 'git reset --merge' */
		ret = cmd_reset(nargc, nargv, prefix);
		goto done;
	}

	if (read_cache_unmerged())
		die_resolve_conflict("merge");

	if (file_exists(git_path("MERGE_HEAD"))) {
		/*
		 * There is no unmerged entry, don't advise 'git
		 * add/rm <file>', just 'git commit'.
		 */
		if (advice_resolve_conflict)
			die(_("You have not concluded your merge (MERGE_HEAD exists).\n"
				  "Please, commit your changes before you can merge."));
		else
			die(_("You have not concluded your merge (MERGE_HEAD exists)."));
	}
	if (file_exists(git_path("CHERRY_PICK_HEAD"))) {
		if (advice_resolve_conflict)
			die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
			    "Please, commit your changes before you can merge."));
		else
			die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists)."));
	}
	resolve_undo_clear();

	if (verbosity < 0)
		show_diffstat = 0;

	if (squash) {
		if (!allow_fast_forward)
			die(_("You cannot combine --squash with --no-ff."));
		option_commit = 0;
	}

	if (!allow_fast_forward && fast_forward_only)
		die(_("You cannot combine --no-ff with --ff-only."));

	if (!abort_current_merge) {
		if (!argc) {
			if (default_to_upstream)
				argc = setup_with_upstream(&argv);
			else
				die(_("No commit specified and merge.defaultToUpstream not set."));
		} else if (argc == 1 && !strcmp(argv[0], "-"))
			argv[0] = "@{-1}";
	}
	if (!argc)
		usage_with_options(builtin_merge_usage,
			builtin_merge_options);

	/*
	 * This could be traditional "merge <msg> HEAD <commit>..."  and
	 * the way we can tell it is to see if the second token is HEAD,
	 * but some people might have misused the interface and used a
	 * committish that is the same as HEAD there instead.
	 * Traditional format never would have "-m" so it is an
	 * additional safety measure to check for it.
	 */

	if (!have_message && head_commit &&
	    is_old_style_invocation(argc, argv, head_commit->object.sha1)) {
		strbuf_addstr(&merge_msg, argv[0]);
		head_arg = argv[1];
		argv += 2;
		argc -= 2;
		remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
	} else if (!head_commit) {
		struct commit *remote_head;
		/*
		 * If the merged head is a valid one there is no reason
		 * to forbid "git merge" into a branch yet to be born.
		 * We do the same for "git pull".
		 */
		if (argc != 1)
			die(_("Can merge only exactly one commit into "
				"empty head"));
		if (squash)
			die(_("Squash commit into empty head not supported yet"));
		if (!allow_fast_forward)
			die(_("Non-fast-forward commit does not make sense into "
			    "an empty head"));
		remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
		remote_head = remoteheads->item;
		if (!remote_head)
			die(_("%s - not something we can merge"), argv[0]);
		read_empty(remote_head->object.sha1, 0);
		update_ref("initial pull", "HEAD", remote_head->object.sha1,
			   NULL, 0, DIE_ON_ERR);
		goto done;
	} else {
		struct strbuf merge_names = STRBUF_INIT;

		/* We are invoked directly as the first-class UI. */
		head_arg = "HEAD";

		/*
		 * All the rest are the commits being merged; prepare
		 * the standard merge summary message to be appended
		 * to the given message.
		 */
		remoteheads = collect_parents(head_commit, &head_subsumed, argc, argv);
		for (p = remoteheads; p; p = p->next)
			merge_name(merge_remote_util(p->item)->name, &merge_names);

		if (!have_message || shortlog_len) {
			struct fmt_merge_msg_opts opts;
			memset(&opts, 0, sizeof(opts));
			opts.add_title = !have_message;
			opts.shortlog_len = shortlog_len;

			fmt_merge_msg(&merge_names, &merge_msg, &opts);
			if (merge_msg.len)
				strbuf_setlen(&merge_msg, merge_msg.len - 1);
		}
	}

	if (!head_commit || !argc)
		usage_with_options(builtin_merge_usage,
			builtin_merge_options);

	strbuf_addstr(&buf, "merge");
	for (p = remoteheads; p; p = p->next)
		strbuf_addf(&buf, " %s", merge_remote_util(p->item)->name);
	setenv("GIT_REFLOG_ACTION", buf.buf, 0);
	strbuf_reset(&buf);

	for (p = remoteheads; p; p = p->next) {
		struct commit *commit = p->item;
		strbuf_addf(&buf, "GITHEAD_%s",
			    sha1_to_hex(commit->object.sha1));
		setenv(buf.buf, merge_remote_util(commit)->name, 1);
		strbuf_reset(&buf);
		if (!fast_forward_only &&
		    merge_remote_util(commit) &&
		    merge_remote_util(commit)->obj &&
		    merge_remote_util(commit)->obj->type == OBJ_TAG)
			allow_fast_forward = 0;
	}

	if (option_edit < 0)
		option_edit = default_edit_option();

	if (!use_strategies) {
		if (!remoteheads)
			; /* already up-to-date */
		else if (!remoteheads->next)
			add_strategies(pull_twohead, DEFAULT_TWOHEAD);
		else
			add_strategies(pull_octopus, DEFAULT_OCTOPUS);
	}

	for (i = 0; i < use_strategies_nr; i++) {
		if (use_strategies[i]->attr & NO_FAST_FORWARD)
			allow_fast_forward = 0;
		if (use_strategies[i]->attr & NO_TRIVIAL)
			allow_trivial = 0;
	}

	if (!remoteheads)
		; /* already up-to-date */
	else if (!remoteheads->next)
		common = get_merge_bases(head_commit, remoteheads->item, 1);
	else {
		struct commit_list *list = remoteheads;
		commit_list_insert(head_commit, &list);
		common = get_octopus_merge_bases(list);
		free(list);
	}

	update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.sha1,
		   NULL, 0, DIE_ON_ERR);

	if (remoteheads && !common)
		; /* No common ancestors found. We need a real merge. */
	else if (!remoteheads ||
		 (!remoteheads->next && !common->next &&
		  common->item == remoteheads->item)) {
		/*
		 * If head can reach all the merge then we are up to date.
		 * but first the most common case of merging one remote.
		 */
		finish_up_to_date("Already up-to-date.");
		goto done;
	} else if (allow_fast_forward && !remoteheads->next &&
			!common->next &&
			!hashcmp(common->item->object.sha1, head_commit->object.sha1)) {
		/* Again the most common case of merging one remote. */
		struct strbuf msg = STRBUF_INIT;
		struct commit *commit;
		char hex[41];

		strcpy(hex, find_unique_abbrev(head_commit->object.sha1, DEFAULT_ABBREV));

		if (verbosity >= 0)
			printf(_("Updating %s..%s\n"),
				hex,
				find_unique_abbrev(remoteheads->item->object.sha1,
				DEFAULT_ABBREV));
		strbuf_addstr(&msg, "Fast-forward");
		if (have_message)
			strbuf_addstr(&msg,
				" (no commit created; -m option ignored)");
		commit = remoteheads->item;
		if (!commit) {
			ret = 1;
			goto done;
		}

		if (checkout_fast_forward(head_commit->object.sha1,
					  commit->object.sha1,
					  overwrite_ignore)) {
			ret = 1;
			goto done;
		}

		finish(head_commit, remoteheads, commit->object.sha1, msg.buf);
		drop_save();
		goto done;
	} else if (!remoteheads->next && common->next)
		;
		/*
		 * We are not doing octopus and not fast-forward.  Need
		 * a real merge.
		 */
	else if (!remoteheads->next && !common->next && option_commit) {
		/*
		 * We are not doing octopus, not fast-forward, and have
		 * only one common.
		 */
		refresh_cache(REFRESH_QUIET);
		if (allow_trivial && !fast_forward_only) {
			/* See if it is really trivial. */
			git_committer_info(IDENT_STRICT);
			printf(_("Trying really trivial in-index merge...\n"));
			if (!read_tree_trivial(common->item->object.sha1,
					       head_commit->object.sha1,
					       remoteheads->item->object.sha1)) {
				ret = merge_trivial(head_commit, remoteheads);
				goto done;
			}
			printf(_("Nope.\n"));
		}
	} else {
		/*
		 * An octopus.  If we can reach all the remote we are up
		 * to date.
		 */
		int up_to_date = 1;
		struct commit_list *j;

		for (j = remoteheads; j; j = j->next) {
			struct commit_list *common_one;

			/*
			 * Here we *have* to calculate the individual
			 * merge_bases again, otherwise "git merge HEAD^
			 * HEAD^^" would be missed.
			 */
			common_one = get_merge_bases(head_commit, j->item, 1);
			if (hashcmp(common_one->item->object.sha1,
				j->item->object.sha1)) {
				up_to_date = 0;
				break;
			}
		}
		if (up_to_date) {
			finish_up_to_date("Already up-to-date. Yeeah!");
			goto done;
		}
	}

	if (fast_forward_only)
		die(_("Not possible to fast-forward, aborting."));

	/* We are going to make a new commit. */
	git_committer_info(IDENT_STRICT);

	/*
	 * At this point, we need a real merge.  No matter what strategy
	 * we use, it would operate on the index, possibly affecting the
	 * working tree, and when resolved cleanly, have the desired
	 * tree in the index -- this means that the index must be in
	 * sync with the head commit.  The strategies are responsible
	 * to ensure this.
	 */
	if (use_strategies_nr == 1 ||
	    /*
	     * Stash away the local changes so that we can try more than one.
	     */
	    save_state(stash))
		hashcpy(stash, null_sha1);

	for (i = 0; i < use_strategies_nr; i++) {
		int ret;
		if (i) {
			printf(_("Rewinding the tree to pristine...\n"));
			restore_state(head_commit->object.sha1, stash);
		}
		if (use_strategies_nr != 1)
			printf(_("Trying merge strategy %s...\n"),
				use_strategies[i]->name);
		/*
		 * Remember which strategy left the state in the working
		 * tree.
		 */
		wt_strategy = use_strategies[i]->name;

		ret = try_merge_strategy(use_strategies[i]->name,
					 common, remoteheads,
					 head_commit, head_arg);
		if (!option_commit && !ret) {
			merge_was_ok = 1;
			/*
			 * This is necessary here just to avoid writing
			 * the tree, but later we will *not* exit with
			 * status code 1 because merge_was_ok is set.
			 */
			ret = 1;
		}

		if (ret) {
			/*
			 * The backend exits with 1 when conflicts are
			 * left to be resolved, with 2 when it does not
			 * handle the given merge at all.
			 */
			if (ret == 1) {
				int cnt = evaluate_result();

				if (best_cnt <= 0 || cnt <= best_cnt) {
					best_strategy = use_strategies[i]->name;
					best_cnt = cnt;
				}
			}
			if (merge_was_ok)
				break;
			else
				continue;
		}

		/* Automerge succeeded. */
		write_tree_trivial(result_tree);
		automerge_was_ok = 1;
		break;
	}

	/*
	 * If we have a resulting tree, that means the strategy module
	 * auto resolved the merge cleanly.
	 */
	if (automerge_was_ok) {
		ret = finish_automerge(head_commit, head_subsumed,
				       common, remoteheads,
				       result_tree, wt_strategy);
		goto done;
	}

	/*
	 * Pick the result from the best strategy and have the user fix
	 * it up.
	 */
	if (!best_strategy) {
		restore_state(head_commit->object.sha1, stash);
		if (use_strategies_nr > 1)
			fprintf(stderr,
				_("No merge strategy handled the merge.\n"));
		else
			fprintf(stderr, _("Merge with strategy %s failed.\n"),
				use_strategies[0]->name);
		ret = 2;
		goto done;
	} else if (best_strategy == wt_strategy)
		; /* We already have its result in the working tree. */
	else {
		printf(_("Rewinding the tree to pristine...\n"));
		restore_state(head_commit->object.sha1, stash);
		printf(_("Using the %s to prepare resolving by hand.\n"),
			best_strategy);
		try_merge_strategy(best_strategy, common, remoteheads,
				   head_commit, head_arg);
	}

	if (squash)
		finish(head_commit, remoteheads, NULL, NULL);
	else
		write_merge_state(remoteheads);

	if (merge_was_ok)
		fprintf(stderr, _("Automatic merge went well; "
			"stopped before committing as requested\n"));
	else
		ret = suggest_conflicts(option_renormalize);

done:
	free(branch_to_free);
	return ret;
}
示例#21
0
void gpio_init(void)
{
	cmd_reset(0);
}
示例#22
0
static int32_t dev_do_io (struct devstruct *dev, uaecptr request, int32_t quick)
{
	uint32_t command;
	uint32_t io_data = get_long (request + 40); // 0x28
	uint32_t io_length = get_long (request + 36); // 0x24
	uint32_t io_actual = get_long (request + 32); // 0x20
	uint32_t io_offset = get_long (request + 44); // 0x2c
	uint32_t io_error = 0;
	uint16_t io_status;
	int32_t async = 0;

	if (!dev)
		return 0;
	command = get_word (request + 28);
	io_log (_T("dev_io_START"),request);

	switch (command)
	{
	case SDCMD_QUERY:
		if (uaeser_query (dev->sysdata, &io_status, &io_actual))
			put_byte (request + io_Status, io_status);
		else
			io_error = IOERR_BADADDRESS;
		break;
	case SDCMD_SETPARAMS:
		io_error = setparams(dev, request);
		break;
	case CMD_WRITE:
		async = 1;
		break;
	case CMD_READ:
		async = 1;
		break;
	case SDCMD_BREAK:
		if (get_byte (request + io_SerFlags) & SERF_QUEUEDBRK) {
			async = 1;
		} else {
			uaeser_break (dev->sysdata,  get_long (request + io_BrkTime));
		}
		break;
	case CMD_CLEAR:
		uaeser_clearbuffers(dev->sysdata);
		break;
	case CMD_RESET:
		cmd_reset(dev, request);
		break;
	case CMD_FLUSH:
	case CMD_START:
	case CMD_STOP:
		break;
	case NSCMD_DEVICEQUERY:
		put_long (io_data + 0, 0);
		put_long (io_data + 4, 16); /* size */
		put_word (io_data + 8, NSDEVTYPE_SERIAL);
		put_word (io_data + 10, 0);
		put_long (io_data + 12, nscmd_cmd);
		io_actual = 16;
		break;
	default:
		io_error = IOERR_NOCMD;
		break;
	}
	put_long (request + 32, io_actual);
	put_byte (request + 31, io_error);
	io_log (_T("dev_io_END"),request);
	return async;
}
示例#23
0
/*
 * Main command processor.
 * Accept and execute commands until a quit command.
 */
void
commands(void)
{
	int c = 0;
	int action;
	char *cbuf;
	int newaction;
	int save_search_type;
	char *extra;
	char tbuf[2];
	PARG parg;
	IFILE old_ifile;
	IFILE new_ifile;
	char *tagfile;

	search_type = SRCH_FORW;
	wscroll = (sc_height + 1) / 2;
	newaction = A_NOACTION;

	for (;;) {
		mca = 0;
		cmd_accept();
		number = 0;
		curropt = NULL;

		/*
		 * See if any signals need processing.
		 */
		if (sigs) {
			psignals();
			if (quitting)
				quit(QUIT_SAVED_STATUS);
		}

		/*
		 * Display prompt and accept a character.
		 */
		cmd_reset();
		prompt();
		if (sigs)
			continue;
		if (newaction == A_NOACTION)
			c = getcc();

again:
		if (sigs)
			continue;

		if (newaction != A_NOACTION) {
			action = newaction;
			newaction = A_NOACTION;
		} else {
			/*
			 * If we are in a multicharacter command, call mca_char.
			 * Otherwise we call fcmd_decode to determine the
			 * action to be performed.
			 */
			if (mca)
				switch (mca_char(c)) {
				case MCA_MORE:
					/*
					 * Need another character.
					 */
					c = getcc();
					goto again;
				case MCA_DONE:
					/*
					 * Command has been handled by mca_char.
					 * Start clean with a prompt.
					 */
					continue;
				case NO_MCA:
					/*
					 * Not a multi-char command
					 * (at least, not anymore).
					 */
					break;
				}

			/*
			 * Decode the command character and decide what to do.
			 */
			if (mca) {
				/*
				 * We're in a multichar command.
				 * Add the character to the command buffer
				 * and display it on the screen.
				 * If the user backspaces past the start
				 * of the line, abort the command.
				 */
				if (cmd_char(c) == CC_QUIT || len_cmdbuf() == 0)
					continue;
				cbuf = get_cmdbuf();
			} else {
				/*
				 * Don't use cmd_char if we're starting fresh
				 * at the beginning of a command, because we
				 * don't want to echo the command until we know
				 * it is a multichar command.  We also don't
				 * want erase_char/kill_char to be treated
				 * as line editing characters.
				 */
				tbuf[0] = (char)c;
				tbuf[1] = '\0';
				cbuf = tbuf;
			}
			extra = NULL;
			action = fcmd_decode(cbuf, &extra);
			/*
			 * If an "extra" string was returned,
			 * process it as a string of command characters.
			 */
			if (extra != NULL)
				ungetsc(extra);
		}
		/*
		 * Clear the cmdbuf string.
		 * (But not if we're in the prefix of a command,
		 * because the partial command string is kept there.)
		 */
		if (action != A_PREFIX)
			cmd_reset();

		switch (action) {
		case A_DIGIT:
			/*
			 * First digit of a number.
			 */
			start_mca(A_DIGIT, ":", (void*)NULL, CF_QUIT_ON_ERASE);
			goto again;

		case A_F_WINDOW:
			/*
			 * Forward one window (and set the window size).
			 */
			if (number > 0)
				swindow = (int)number;
			/* FALLTHRU */
		case A_F_SCREEN:
			/*
			 * Forward one screen.
			 */
			if (number <= 0)
				number = get_swindow();
			cmd_exec();
			if (show_attn)
				set_attnpos(bottompos);
			forward((int)number, 0, 1);
			break;

		case A_B_WINDOW:
			/*
			 * Backward one window (and set the window size).
			 */
			if (number > 0)
				swindow = (int)number;
			/* FALLTHRU */
		case A_B_SCREEN:
			/*
			 * Backward one screen.
			 */
			if (number <= 0)
				number = get_swindow();
			cmd_exec();
			backward((int)number, 0, 1);
			break;

		case A_F_LINE:
			/*
			 * Forward N (default 1) line.
			 */
			if (number <= 0)
				number = 1;
			cmd_exec();
			if (show_attn == OPT_ONPLUS && number > 1)
				set_attnpos(bottompos);
			forward((int)number, 0, 0);
			break;

		case A_B_LINE:
			/*
			 * Backward N (default 1) line.
			 */
			if (number <= 0)
				number = 1;
			cmd_exec();
			backward((int)number, 0, 0);
			break;

		case A_F_SKIP:
			/*
			 * Skip ahead one screen, and then number lines.
			 */
			if (number <= 0) {
				number = get_swindow();
			} else {
				number += get_swindow();
			}
			cmd_exec();
			if (show_attn == OPT_ONPLUS)
				set_attnpos(bottompos);
			forward((int)number, 0, 1);
			break;

		case A_FF_LINE:
			/*
			 * Force forward N (default 1) line.
			 */
			if (number <= 0)
				number = 1;
			cmd_exec();
			if (show_attn == OPT_ONPLUS && number > 1)
				set_attnpos(bottompos);
			forward((int)number, 1, 0);
			break;

		case A_BF_LINE:
			/*
			 * Force backward N (default 1) line.
			 */
			if (number <= 0)
				number = 1;
			cmd_exec();
			backward((int)number, 1, 0);
			break;

		case A_FF_SCREEN:
			/*
			 * Force forward one screen.
			 */
			if (number <= 0)
				number = get_swindow();
			cmd_exec();
			if (show_attn == OPT_ONPLUS)
				set_attnpos(bottompos);
			forward((int)number, 1, 0);
			break;

		case A_F_FOREVER:
			/*
			 * Forward forever, ignoring EOF.
			 */
			newaction = forw_loop(0);
			break;

		case A_F_UNTIL_HILITE:
			newaction = forw_loop(1);
			break;

		case A_F_SCROLL:
			/*
			 * Forward N lines
			 * (default same as last 'd' or 'u' command).
			 */
			if (number > 0)
				wscroll = (int)number;
			cmd_exec();
			if (show_attn == OPT_ONPLUS)
				set_attnpos(bottompos);
			forward(wscroll, 0, 0);
			break;

		case A_B_SCROLL:
			/*
			 * Forward N lines
			 * (default same as last 'd' or 'u' command).
			 */
			if (number > 0)
				wscroll = (int)number;
			cmd_exec();
			backward(wscroll, 0, 0);
			break;

		case A_FREPAINT:
			/*
			 * Flush buffers, then repaint screen.
			 * Don't flush the buffers on a pipe!
			 */
			clear_buffers();
			/* FALLTHRU */
		case A_REPAINT:
			/*
			 * Repaint screen.
			 */
			cmd_exec();
			repaint();
			break;

		case A_GOLINE:
			/*
			 * Go to line N, default beginning of file.
			 */
			if (number <= 0)
				number = 1;
			cmd_exec();
			jump_back(number);
			break;

		case A_PERCENT:
			/*
			 * Go to a specified percentage into the file.
			 */
			if (number < 0) {
				number = 0;
				fraction = 0;
			}
			if (number > 100) {
				number = 100;
				fraction = 0;
			}
			cmd_exec();
			jump_percent((int)number, fraction);
			break;

		case A_GOEND:
			/*
			 * Go to line N, default end of file.
			 */
			cmd_exec();
			if (number <= 0)
				jump_forw();
			else
				jump_back(number);
			break;

		case A_GOPOS:
			/*
			 * Go to a specified byte position in the file.
			 */
			cmd_exec();
			if (number < 0)
				number = 0;
			jump_line_loc((off_t) number, jump_sline);
			break;

		case A_STAT:
			/*
			 * Print file name, etc.
			 */
			if (ch_getflags() & CH_HELPFILE)
				break;
			cmd_exec();
			parg.p_string = eq_message();
			error("%s", &parg);
			break;

		case A_VERSION:
			/*
			 * Print version number, without the "@(#)".
			 */
			cmd_exec();
			dispversion();
			break;

		case A_QUIT:
			/*
			 * Exit.
			 */
			if (curr_ifile != NULL_IFILE &&
			    ch_getflags() & CH_HELPFILE) {
				/*
				 * Quit while viewing the help file
				 * just means return to viewing the
				 * previous file.
				 */
				hshift = save_hshift;
				if (edit_prev(1) == 0)
					break;
			}
			if (extra != NULL)
				quit(*extra);
			quit(QUIT_OK);
			break;

/*
 * Define abbreviation for a commonly used sequence below.
 */
#define	DO_SEARCH() \
			if (number <= 0) number = 1;	\
			mca_search();			\
			cmd_exec();			\
			multi_search(NULL, (int)number);


		case A_F_SEARCH:
			/*
			 * Search forward for a pattern.
			 * Get the first char of the pattern.
			 */
			search_type = SRCH_FORW;
			if (number <= 0)
				number = 1;
			mca_search();
			c = getcc();
			goto again;

		case A_B_SEARCH:
			/*
			 * Search backward for a pattern.
			 * Get the first char of the pattern.
			 */
			search_type = SRCH_BACK;
			if (number <= 0)
				number = 1;
			mca_search();
			c = getcc();
			goto again;

		case A_FILTER:
			search_type = SRCH_FORW | SRCH_FILTER;
			mca_search();
			c = getcc();
			goto again;

		case A_AGAIN_SEARCH:
			/*
			 * Repeat previous search.
			 */
			DO_SEARCH();
			break;

		case A_T_AGAIN_SEARCH:
			/*
			 * Repeat previous search, multiple files.
			 */
			search_type |= SRCH_PAST_EOF;
			DO_SEARCH();
			break;

		case A_REVERSE_SEARCH:
			/*
			 * Repeat previous search, in reverse direction.
			 */
			save_search_type = search_type;
			search_type = SRCH_REVERSE(search_type);
			DO_SEARCH();
			search_type = save_search_type;
			break;

		case A_T_REVERSE_SEARCH:
			/*
			 * Repeat previous search,
			 * multiple files in reverse direction.
			 */
			save_search_type = search_type;
			search_type = SRCH_REVERSE(search_type);
			search_type |= SRCH_PAST_EOF;
			DO_SEARCH();
			search_type = save_search_type;
			break;

		case A_UNDO_SEARCH:
			undo_search();
			break;

		case A_HELP:
			/*
			 * Help.
			 */
			if (ch_getflags() & CH_HELPFILE)
				break;
			if (ungot != NULL || unget_end) {
				error(less_is_more
				    ? "Invalid option -p h"
				    : "Invalid option ++h",
				    NULL_PARG);
				break;
			}
			cmd_exec();
			save_hshift = hshift;
			hshift = 0;
			(void) edit(FAKE_HELPFILE);
			break;

		case A_EXAMINE:
			/*
			 * Edit a new file.  Get the filename.
			 */
			if (secure) {
				error("Command not available", NULL_PARG);
				break;
			}
			start_mca(A_EXAMINE, "Examine: ", ml_examine, 0);
			c = getcc();
			goto again;

		case A_VISUAL:
			/*
			 * Invoke an editor on the input file.
			 */
			if (secure) {
				error("Command not available", NULL_PARG);
				break;
			}
			if (ch_getflags() & CH_HELPFILE)
				break;
			if (strcmp(get_filename(curr_ifile), "-") == 0) {
				error("Cannot edit standard input", NULL_PARG);
				break;
			}
			if (curr_altfilename != NULL) {
				error("WARNING: This file was viewed via "
				    "LESSOPEN", NULL_PARG);
			}
			start_mca(A_SHELL, "!", ml_shell, 0);
			/*
			 * Expand the editor prototype string
			 * and pass it to the system to execute.
			 * (Make sure the screen is displayed so the
			 * expansion of "+%lm" works.)
			 */
			make_display();
			cmd_exec();
			lsystem(pr_expand(editproto, 0), NULL);
			break;

		case A_NEXT_FILE:
			/*
			 * Examine next file.
			 */
			if (ntags()) {
				error("No next file", NULL_PARG);
				break;
			}
			if (number <= 0)
				number = 1;
			if (edit_next((int)number)) {
				if (get_quit_at_eof() && eof_displayed() &&
				    !(ch_getflags() & CH_HELPFILE))
					quit(QUIT_OK);
				parg.p_string = (number > 1) ? "(N-th) " : "";
				error("No %snext file", &parg);
			}
			break;

		case A_PREV_FILE:
			/*
			 * Examine previous file.
			 */
			if (ntags()) {
				error("No previous file", NULL_PARG);
				break;
			}
			if (number <= 0)
				number = 1;
			if (edit_prev((int)number)) {
				parg.p_string = (number > 1) ? "(N-th) " : "";
				error("No %sprevious file", &parg);
			}
			break;

		case A_NEXT_TAG:
			if (number <= 0)
				number = 1;
			tagfile = nexttag((int)number);
			if (tagfile == NULL) {
				error("No next tag", NULL_PARG);
				break;
			}
			if (edit(tagfile) == 0) {
				off_t pos = tagsearch();
				if (pos != -1)
					jump_loc(pos, jump_sline);
			}
			break;

		case A_PREV_TAG:
			if (number <= 0)
				number = 1;
			tagfile = prevtag((int)number);
			if (tagfile == NULL) {
				error("No previous tag", NULL_PARG);
				break;
			}
			if (edit(tagfile) == 0) {
				off_t pos = tagsearch();
				if (pos != -1)
					jump_loc(pos, jump_sline);
			}
			break;

		case A_INDEX_FILE:
			/*
			 * Examine a particular file.
			 */
			if (number <= 0)
				number = 1;
			if (edit_index((int)number))
				error("No such file", NULL_PARG);
			break;

		case A_REMOVE_FILE:
			if (ch_getflags() & CH_HELPFILE)
				break;
			old_ifile = curr_ifile;
			new_ifile = getoff_ifile(curr_ifile);
			if (new_ifile == NULL_IFILE) {
				ring_bell();
				break;
			}
			if (edit_ifile(new_ifile) != 0) {
				reedit_ifile(old_ifile);
				break;
			}
			del_ifile(old_ifile);
			break;

		case A_OPT_TOGGLE:
			optflag = OPT_TOGGLE;
			optgetname = FALSE;
			mca_opt_toggle();
			c = getcc();
			goto again;

		case A_DISP_OPTION:
			/*
			 * Report a flag setting.
			 */
			optflag = OPT_NO_TOGGLE;
			optgetname = FALSE;
			mca_opt_toggle();
			c = getcc();
			goto again;

		case A_FIRSTCMD:
			/*
			 * Set an initial command for new files.
			 */
			start_mca(A_FIRSTCMD, "+", NULL, 0);
			c = getcc();
			goto again;

		case A_SHELL:
			/*
			 * Shell escape.
			 */
			if (secure) {
				error("Command not available", NULL_PARG);
				break;
			}
			start_mca(A_SHELL, "!", ml_shell, 0);
			c = getcc();
			goto again;

		case A_SETMARK:
			/*
			 * Set a mark.
			 */
			if (ch_getflags() & CH_HELPFILE)
				break;
			start_mca(A_SETMARK, "mark: ", (void*)NULL, 0);
			c = getcc();
			if (c == erase_char || c == erase2_char ||
			    c == kill_char || c == '\n' || c == '\r')
				break;
			setmark(c);
			break;

		case A_GOMARK:
			/*
			 * Go to a mark.
			 */
			start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0);
			c = getcc();
			if (c == erase_char || c == erase2_char ||
			    c == kill_char || c == '\n' || c == '\r')
				break;
			cmd_exec();
			gomark(c);
			break;

		case A_PIPE:
			if (secure) {
				error("Command not available", NULL_PARG);
				break;
			}
			start_mca(A_PIPE, "|mark: ", (void*)NULL, 0);
			c = getcc();
			if (c == erase_char || c == erase2_char ||
			    c == kill_char)
				break;
			if (c == '\n' || c == '\r')
				c = '.';
			if (badmark(c))
				break;
			pipec = c;
			start_mca(A_PIPE, "!", ml_shell, 0);
			c = getcc();
			goto again;

		case A_B_BRACKET:
		case A_F_BRACKET:
			start_mca(action, "Brackets: ", (void*)NULL, 0);
			c = getcc();
			goto again;

		case A_LSHIFT:
			if (number > 0)
				shift_count = number;
			else
				number = (shift_count > 0) ?
				    shift_count : sc_width / 2;
			if (number > hshift)
				number = hshift;
			hshift -= number;
			screen_trashed = 1;
			break;

		case A_RSHIFT:
			if (number > 0)
				shift_count = number;
			else
				number = (shift_count > 0) ?
				    shift_count : sc_width / 2;
			hshift += number;
			screen_trashed = 1;
			break;

		case A_PREFIX:
			/*
			 * The command is incomplete (more chars are needed).
			 * Display the current char, so the user knows
			 * what's going on, and get another character.
			 */
			if (mca != A_PREFIX) {
				cmd_reset();
				start_mca(A_PREFIX, " ", (void*)NULL,
				    CF_QUIT_ON_ERASE);
				(void) cmd_char(c);
			}
			c = getcc();
			goto again;

		case A_NOACTION:
			break;

		default:
			ring_bell();
			break;
		}
	}
}
void doCommand( void )
{
  int rv = 0;

  switch( ( *gbuffer & ~0x20 ) ) {
    
    // AT<CR>
  case 0x00:
    // OK
    break;

    // Autobaud detection
  case 'A': 
    rv = cmd_autobaud();
    break;
    
    // Set Baudrate
  case 'B': 
    rv = cmd_baudrate();
    break;
    
  case 'C': //
    {
      char buf[20];
      int rr;

      *buf = 0;
      rr = getNumericValue( ( gbuffer + 1 ) );
      itoa( rr, buf, 10 );
      uart0BlockingPutch( ' ' );
      uart0BlockingPuts( buf );
    }
    break;
    
  case 'D': // Dial - Go online
    rv = cmd_online();
    break;

  case 'E': // Turn on/off echo
    rv = cmd_echo();
    break;
    
  case 'F': // Set Filter/Mask
    rv = cmd_filter();
    break;
    
  case 'G': // Send Burst n - number of messages. sz - delay between frames
    rv = cmd_sendBurst();
    break;
    
  case 'H': // Hook - Go online
    rv = cmd_online();
    break;
    
  case 'I': // Information
    rv = cmd_info();
    break;
    
  case 'J':
    rv = -1; // Not implemented
    break;
    
  case 'K': 
    {
      canmsg_t msg;
      msg.id = 0x334;
      msg.length = 2;
      msg.data[ 0 ] = 1;
      msg.data[ 1 ] = 2;
      msg.flags |=  MSG_EXT;

      //if ( !sja1000_sendMsg( &msg ) ) {
      //doResponse( FALSE, 0  );
      //}
      if ( !sja1000_writeMsgToBuf( &msg ) ) {
	rv = -1; // Not implemented;
      }

      rv = 0;
    }
    break;
    
  case 'L':  // Go online in Listen only mode
    rv = cmd_listen();
    break;
    
  case 'M':
    rv = -1; // Not implemented
    break;
    
  case 'N':
    rv = -1; // Not implemented
    break;
    
  case 'O':
    rv = -1; // Not implemented
    break;
    
  case 'P':
    rv = -1; // Not implemented
    break;
    
  case 'Q': // Quite 
    rv = cmd_quite();
    break;
    
  case 'R': // Read message
    rv = cmd_readmsg();
    break;
    
  case 'S': // Set/read registers
    rv = cmd_register();
    break;
    
  case 'T':
    rv = -1; // Not implemented
    break;
    
  case 'U':
    rv = -1; // Not implemented
    break;
    
  case 'V': // Verbal
    rv = cmd_verbal();
    break;
    
  case 'W': // Write message
    rv = cmd_writemsg();
    break;
    
  case 'X':
    rv = -1; // Not implemented
    break;
    
  case 'Y':
    rv = -1; // Not implemented
    break;
    
  case 'Z': // Reset device
    rv = cmd_reset();
    break;
    
  case '?': // Get statistics
    rv = -1; // Not implemented
    break;

  default:  // Uknown command
    rv = -1; // Not implemented
    break;
  }

  // Print out response
  if ( 0 == rv ) {
    doResponse( TRUE, rv  );
  }
  else {
    doResponse( FALSE, rv  );
  }
}
示例#25
0
void LGNetwork::set_mode(network_mode_t newMode)
{
    cmd_enter();
    cmd_reset();
    cmd_setup();
    cmd_set_channel(newMode);

    if(newMode == LGNETWORK_OPERATE) {
        #ifdef USE_NETWORK_SERVER
            cmd_set_short_address(-1);
            cmd_set_target_short_address(-1);
            cmd_set_coordinator();

        #elif USE_NETWORK_CLIENT
            uint16_t short_addr = LGDB::read_address();
            cmd_set_short_address(short_addr); // It will either be something we want, or -1
            cmd_set_coordinator();

        #endif
    } else { // LGNETWORK_DISCOVER
        #ifdef USE_NETWORK_SERVER
            cmd_set_short_address(-1);
            cmd_set_target_short_address(-1);
            cmd_set_coordinator();

            // Get my uuid
            // Read the UUID (serial address)
            char ascii_id[17];
            for(int i=0; i < sizeof(ascii_id); i++) ascii_id[i] = '0';
            ascii_id[16] = 0;

            LGSerial::print_pgm( PSTR("ATSH") ); // Starting with the upper bits
            uint8_t high_chars_to_write = LGSerial::get(response_buf, '\r', 16) - 1;
            memcpy(ascii_id + (8 - high_chars_to_write), response_buf, high_chars_to_write);

            // Now the lower bits
            LGSerial::print_pgm( PSTR("ATSL") );
            uint8_t low_chars_to_write = LGSerial::get(response_buf, '\r', 16) - 1;
            memcpy(ascii_id + 8 + (8 - low_chars_to_write), response_buf, low_chars_to_write);

            uint8_t *p = (uint8_t*)&(LGNetwork::myUUID); // Ptr to current byte

            for(int i=0; i < 16; i+=2) {
                // Convert to bin
                *(p++) = asciis_to_byte(ascii_id + i);
            }


        #elif USE_NETWORK_CLIENT
            cmd_set_short_address(-1);
            cmd_set_target_short_address(-1);
            cmd_set_coordinator();

            #ifdef CLIENT_SENSOR
                LGSerial::print_pgm( PSTR("ATNIs") );
                cmd_wait_for_ok();
            #elif CLIENT_ACTUATOR
                LGSerial::print_pgm( PSTR("ATNIa") );
                cmd_wait_for_ok();
            #endif
        #endif
    }

    cmd_exit();

    currentMode = newMode;
}
示例#26
0
int main(int argc, char *argv[])
{
    struct sigaction sa;
    bdaddr_t bdaddr = { 0 };
    int ctl, csk, isk, debug, legacy, remote;

    if (argc > 3) {
      debug = atoi(argv[1]);
      legacy = atoi(argv[2]);
      remote = atoi(argv[3]);
    } else {
      std::cerr << argv[0] << " requires 'sixad'. Please run sixad instead" << std::endl;
      return 1;
    }


#if 0
    // Enable all bluetooth adapters
    int hci_ctl;
    if ((hci_ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) >= 0) {
      for (int i=0; i < 4; i++)
      {
        di.dev_id = i;
        if (ioctl(hci_ctl, HCIGETDEVINFO, (void *) &di) == 0)
        {
          if (hci_test_bit(HCI_RAW, &di.flags) && !bacmp(&di.bdaddr, BDADDR_ANY)) {
            int dd = hci_open_dev(di.dev_id);
            hci_read_bd_addr(dd, &di.bdaddr, 1000);
            hci_close_dev(dd);
          }
        }
        cmd_reset(hci_ctl, di.dev_id);
      }
    }
#endif

    open_log("sixad-bin");
    syslog(LOG_INFO, "started");

    ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HIDP);
    if (ctl < 0) {
        syslog(LOG_ERR, "Can't open HIDP control socket");
        close(ctl);
        return 1;
    }

    if (remote) {
        // BD Remote only

        syslog(LOG_INFO, "BD Remote mode active, hold Enter+Start on your remote now");

        while (!io_canceled()) {
            do_search(ctl, &bdaddr, debug);
            sleep(2);
        }

    } else {
        // Normal behaviour

        csk = l2cap_listen(&bdaddr, L2CAP_PSM_HIDP_CTRL, L2CAP_LM_MASTER, 10);
        if (csk < 0) {
            syslog(LOG_ERR, "Can't listen on HID control channel");
            close(csk);
            close(ctl);
            return 1;
        }

        isk = l2cap_listen(&bdaddr, L2CAP_PSM_HIDP_INTR, L2CAP_LM_MASTER, 10);
        if (isk < 0) {
            syslog(LOG_ERR, "Can't listen on HID interrupt channel");
            close(isk);
            close(csk);
            close(ctl);
            return 1;
        }

        memset(&sa, 0, sizeof(sa));
        sa.sa_flags = SA_NOCLDSTOP;

        sa.sa_handler = sig_term;
        sigaction(SIGTERM, &sa, NULL);
        sigaction(SIGINT, &sa, NULL);
        sa.sa_handler = sig_hup;
        sigaction(SIGHUP, &sa, NULL);

        sa.sa_handler = SIG_IGN;
        sigaction(SIGCHLD, &sa, NULL);
        sigaction(SIGPIPE, &sa, NULL);

        syslog(LOG_INFO, "sixad started, press the PS button now");

        hid_server(ctl, csk, isk, debug, legacy);

        close(isk);
        close(csk);
    }

    close(ctl);
    syslog(LOG_INFO, "Done");

    return 0;
}
示例#27
0
int main(int argc, char *argv[])
{
	int opt;
	int r = 0;
	struct libusb_device_handle *devh= NULL;
	rangetest_result rr;
	int do_stop, do_flash, do_isp, do_leds, do_part, do_reset;
	int do_serial, do_tx, do_palevel, do_channel, do_led_specan;
	int do_range_test, do_repeater, do_firmware, do_board_id;
	int do_range_result, do_all_leds, do_identify;
	int do_set_squelch, do_get_squelch, squelch_level;

	/* set command states to negative as a starter
	 * setting to 0 means 'do it'
	 * setting to positive is value of specified argument */
	do_stop= do_flash= do_isp= do_leds= do_part= do_reset= -1;
	do_serial= do_tx= do_palevel= do_channel= do_led_specan= -1;
	do_range_test= do_repeater= do_firmware= do_board_id= -1;
	do_range_result= do_all_leds= do_identify= -1;
	do_set_squelch= -1, do_get_squelch= -1; squelch_level= 0;

	while ((opt=getopt(argc,argv,"U:hnmefiIprsStvbl::a::C::c::d::q::z::")) != EOF) {
		switch(opt) {
		case 'U': 
			Ubertooth_Device= atoi(optarg);
                        break;
		case 'f':
			do_flash= 0;
			break;
		case 'i':
			do_isp= 0;
			break;
		case 'I':
			do_identify= 0;
			break;
		case 'l':
			if (optarg)
				do_leds= atoi(optarg);
			else
				do_leds= 2; /* can't use 0 as it's a valid option */
			break;
		case 'd':
			if (optarg)
				do_all_leds= atoi(optarg);
			else
				do_all_leds= 2; /* can't use 0 as it's a valid option */
			break;
		case 'p':
			do_part= 0;
			break;
		case 'r':
			do_reset= 0;
			break;
		case 's':
			do_serial= 0;
			break;
		case 'S':
			do_stop= 0;
			break;
		case 't':
			do_tx= 0;
			break;
		case 'a':
			if (optarg)
				do_palevel= atoi(optarg);
			else
				do_palevel= 0;
			break;
		case 'C':
                        if (optarg)
				do_channel= atoi(optarg) +2402;
                        else
				do_channel= 0;
                        break;
	
		case 'c':
			if (optarg)
				do_channel= atoi(optarg);
			else
				do_channel= 0;
			break;
		case 'q':
			if (optarg)
				do_led_specan= atoi(optarg);
			else
				do_led_specan= 0;
			break;
		case 'n':
			do_range_test= 0;
			break;
		case 'm':
			do_range_result= 0;
			break;
		case 'e':
			do_repeater= 0;
			break;
		case 'v':
			do_firmware= 0;
			break;
		case 'b':
			do_board_id= 0;
			break;
		case 'z':
			if (optarg) {
				squelch_level = atoi(optarg);
				do_set_squelch = 1;
			}
			else {
				do_get_squelch = 1;
			}
			break;
		case 'h':
		default:
			usage();
			return 1;
		}
	}

	/* initialise device */
	devh = ubertooth_start();
	if (devh == NULL) {
		usage();
		return 1;
	}
	if(do_reset == 0) {
		printf("Resetting ubertooth device number %d\n", (Ubertooth_Device >= 0) ? Ubertooth_Device : 0);
		r= cmd_reset(devh);
		sleep(2);
		devh = ubertooth_start();
	}
	if(do_stop == 0) {
		printf("Stopping ubertooth device number %d\n", (Ubertooth_Device >= 0) ? Ubertooth_Device : 0);
		r= cmd_stop(devh);
	}

	/* device configuration actions */
	if(do_all_leds == 0 || do_all_leds == 1) {
		cmd_set_usrled(devh, do_all_leds);
		cmd_set_rxled(devh, do_all_leds);
		r= cmd_set_txled(devh, do_all_leds);
		r = (r >= 0) ? 0 : r;
	}
	if(do_channel > 0)
		r= cmd_set_channel(devh, do_channel);
	if(do_leds == 0 || do_leds == 1)
		r= cmd_set_usrled(devh, do_leds);
	if(do_palevel > 0)
		r= cmd_set_palevel(devh, do_palevel);
	
	/* reporting actions */
	if(do_all_leds == 2) {
		printf("USR LED status: %d\n", cmd_get_usrled(devh));
		printf("RX LED status : %d\n", cmd_get_rxled(devh));
		printf("TX LED status : %d\n", r= cmd_get_txled(devh));
		r = (r >= 0) ? 0 : r;
	}
	if(do_board_id == 0) {
		r= cmd_get_board_id(devh);
		printf("Board ID Number: %d (%s)\n", r, board_names[r]);
	}
	if(do_channel == 0) {
		r= cmd_get_channel(devh);
		printf("Current frequency: %d MHz (Bluetooth channel %d)\n", r, r - 2402);
		}
	if(do_firmware == 0)
		printf("Firmare revision: %d\n", r= cmd_get_rev_num(devh));
	if(do_leds == 2)
		printf("USR LED status: %d\n", r= cmd_get_usrled(devh));
	if(do_palevel == 0)
		printf("PA Level: %d\n", r= cmd_get_palevel(devh));
	if(do_part == 0) {
		printf("Part ID: %X\n", r = cmd_get_partnum(devh));
		r = (r >= 0) ? 0 : r;
	}
	if(do_range_result == 0) {
		r = cmd_get_rangeresult(devh, &rr);
		if (r == 0) {
			if (rr.valid) {
				printf("request PA level : %d\n", rr.request_pa);
				printf("request number   : %d\n", rr.request_num);
				printf("reply PA level   : %d\n", rr.reply_pa);
				printf("reply number     : %d\n", rr.reply_num);
			} else {
				printf("invalid range test result\n");
			}
		}
	}
	if(do_serial == 0) {
		printf("Serial No: ");
		r= cmd_get_serial(devh);
		r = (r >= 0) ? 0 : r;
	}

	/* final actions */
	if(do_flash == 0) {
		printf("Entering flash programming (DFU) mode\n");
		return cmd_flash(devh);
	}
	if(do_identify == 0) {
		printf("Flashing LEDs on ubertooth device number %d\n", (Ubertooth_Device >= 0) ? Ubertooth_Device : 0);
		while(42) {
			do_identify= !do_identify;
			cmd_set_usrled(devh, do_identify);
			cmd_set_rxled(devh, do_identify);
			cmd_set_txled(devh, do_identify);
			sleep(1);
		}
	}
	if(do_isp == 0) {
		printf("Entering flash programming (ISP) mode\n");
		return cmd_set_isp(devh);
	}
	if(do_led_specan >= 0) {
		do_led_specan= do_led_specan ? do_led_specan : 225;
		printf("Entering LED specan mode (RSSI %d)\n", do_led_specan);
		return cmd_led_specan(devh, do_led_specan);
	}
	if(do_range_test == 0) {
		printf("Starting range test\n");
		return cmd_range_test(devh);
	}
	if(do_repeater == 0) {
		printf("Starting repeater\n");
		return cmd_repeater(devh);
	}
	if(do_tx == 0) {
		printf("Starting TX test\n");
		return cmd_tx_test(devh);
	}
	if(do_set_squelch > 0) {
		printf("Setting squelch to %d\n", squelch_level);
		cmd_set_squelch(devh, squelch_level);
	}
	if(do_get_squelch > 0) {
		r = cmd_get_squelch(devh);
		printf("Squelch set to %d\n", (int8_t)r);
	}

	return r;
}
示例#28
0
int main(int argc, char *argv[])
{
	int opt;
	int r = 0;
	ubertooth_t* ut = NULL;
	rangetest_result rr;
	int do_stop, do_flash, do_isp, do_leds, do_part, do_reset;
	int do_serial, do_tx, do_palevel, do_channel, do_led_specan;
	int do_range_test, do_repeater, do_firmware, do_board_id;
	int do_range_result, do_all_leds, do_identify;
	int do_set_squelch, do_get_squelch, squelch_level;
	int do_something, do_compile_info;
	char ubertooth_device = -1;

	/* set command states to negative as a starter
	 * setting to 0 means 'do it'
	 * setting to positive is value of specified argument */
	do_stop= do_flash= do_isp= do_leds= do_part= do_reset= -1;
	do_serial= do_tx= do_palevel= do_channel= do_led_specan= -1;
	do_range_test= do_repeater= do_firmware= do_board_id= -1;
	do_range_result= do_all_leds= do_identify= -1;
	do_set_squelch= -1, do_get_squelch= -1; squelch_level= 0;
	do_something= 0; do_compile_info= -1;

	while ((opt=getopt(argc,argv,"U:hnmefiIprsStvbl::a::C::c::d::q::z::9V")) != EOF) {
		switch(opt) {
		case 'U': 
			ubertooth_device = atoi(optarg);
			break;
		case 'f':
			fprintf(stderr, "ubertooth-util -f is no longer required - use ubertooth-dfu instead\n");
			do_flash= 0;
			break;
		case 'i':
			do_isp= 0;
			break;
		case 'I':
			do_identify= 0;
			break;
		case 'l':
			if (optarg)
				do_leds= atoi(optarg);
			else
				do_leds= 2; /* can't use 0 as it's a valid option */
			break;
		case 'd':
			if (optarg)
				do_all_leds= atoi(optarg);
			else
				do_all_leds= 2; /* can't use 0 as it's a valid option */
			break;
		case 'p':
			do_part= 0;
			break;
		case 'r':
			do_reset= 0;
			break;
		case 's':
			do_serial= 0;
			break;
		case 'S':
			do_stop= 0;
			break;
		case 't':
			do_tx= 0;
			break;
		case 'a':
			if (optarg)
				do_palevel= atoi(optarg);
			else
				do_palevel= 0;
			break;
		case 'C':
			if (optarg)
				do_channel= atoi(optarg) +2402;
			else
				do_channel= 0;
			break;	
		case 'c':
			if (optarg)
				do_channel= atoi(optarg);
			else
				do_channel= 0;
			break;
		case 'q':
			if (optarg)
				do_led_specan= atoi(optarg);
			else
				do_led_specan= 0;
			break;
		case 'n':
			do_range_test= 0;
			break;
		case 'm':
			do_range_result= 0;
			break;
		case 'e':
			do_repeater= 0;
			break;
		case 'v':
			do_firmware= 0;
			break;
		case 'b':
			do_board_id= 0;
			break;
		case 'z':
			if (optarg) {
				squelch_level = atoi(optarg);
				do_set_squelch = 1;
			}
			else {
				do_get_squelch = 1;
			}
			break;
		case '9':
			do_something= 1;
			break;
		case 'V':
			do_compile_info = 0;
			break;
		case 'h':
		default:
			usage();
			return 1;
		}
	}

	/* initialise device */
	ut = ubertooth_start(ubertooth_device);
	if (ut == NULL) {
		usage();
		return 1;
	}
	if(do_reset == 0) {
		printf("Resetting ubertooth device number %d\n", (ubertooth_device >= 0) ? ubertooth_device : 0);
		r = cmd_reset(ut->devh);
		sleep(2);
		ut = ubertooth_start(ubertooth_device);
	}
	if(do_stop == 0) {
		printf("Stopping ubertooth device number %d\n", (ubertooth_device >= 0) ? ubertooth_device : 0);
		r = cmd_stop(ut->devh);
	}

	/* device configuration actions */
	if(do_all_leds == 0 || do_all_leds == 1) {
		cmd_set_usrled(ut->devh, do_all_leds);
		cmd_set_rxled(ut->devh, do_all_leds);
		r= cmd_set_txled(ut->devh, do_all_leds);
		r = (r >= 0) ? 0 : r;
	}
	if(do_channel > 0)
		r= cmd_set_channel(ut->devh, do_channel);
	if(do_leds == 0 || do_leds == 1)
		r= cmd_set_usrled(ut->devh, do_leds);
	if(do_palevel > 0)
		r= cmd_set_palevel(ut->devh, do_palevel);
	
	/* reporting actions */
	if(do_all_leds == 2) {
		printf("USR LED status: %d\n", cmd_get_usrled(ut->devh));
		printf("RX LED status : %d\n", cmd_get_rxled(ut->devh));
		printf("TX LED status : %d\n", r= cmd_get_txled(ut->devh));
		r = (r >= 0) ? 0 : r;
	}
	if(do_board_id == 0) {
		r= cmd_get_board_id(ut->devh);
		printf("Board ID Number: %d (%s)\n", r, board_names[r]);
	}
	if(do_channel == 0) {
		r= cmd_get_channel(ut->devh);
		printf("Current frequency: %d MHz (Bluetooth channel %d)\n", r, r - 2402);
		}
	if(do_firmware == 0) {
		char version[255];
		cmd_get_rev_num(ut->devh, version, (u8)sizeof(version));
		printf("Firmware revision: %s\n", version);
        }
	if(do_compile_info == 0) {
		char compile_info[255];
		cmd_get_compile_info(ut->devh, compile_info, (u8)sizeof(compile_info));
		puts(compile_info);
	}
	if(do_leds == 2)
		printf("USR LED status: %d\n", r= cmd_get_usrled(ut->devh));
	if(do_palevel == 0)
		printf("PA Level: %d\n", r= cmd_get_palevel(ut->devh));
	if(do_part == 0) {
		printf("Part ID: %X\n", r = cmd_get_partnum(ut->devh));
		r = (r >= 0) ? 0 : r;
	}
	if(do_range_result == 0) {
		r = cmd_get_rangeresult(ut->devh, &rr);
		if (r == 0) {
			if (rr.valid==1) {
				printf("request PA level : %d\n", rr.request_pa);
				printf("request number   : %d\n", rr.request_num);
				printf("reply PA level   : %d\n", rr.reply_pa);
				printf("reply number     : %d\n", rr.reply_num);
			} else if (rr.valid>1) {
				printf("Invalid range test: mismatch on byte %d\n", rr.valid-2);
			} else {
				printf("invalid range test result\n");
			}
		}
	}
	if(do_serial == 0) {
		u8 serial[17];
		r= cmd_get_serial(ut->devh, serial);
		if(r==0) {
			print_serial(serial, NULL);
		}
		// FIXME: Why do we do this to non-zero results?
		r = (r >= 0) ? 0 : r;
	}

	/* final actions */
	if(do_flash == 0) {
		printf("Entering flash programming (DFU) mode\n");
		return cmd_flash(ut->devh);
	}
	if(do_identify == 0) {
		printf("Flashing LEDs on ubertooth device number %d\n", (ubertooth_device >= 0) ? ubertooth_device : 0);
		while(42) {
			do_identify= !do_identify;
			cmd_set_usrled(ut->devh, do_identify);
			cmd_set_rxled(ut->devh, do_identify);
			cmd_set_txled(ut->devh, do_identify);
			sleep(1);
		}
	}
	if(do_isp == 0) {
		printf("Entering flash programming (ISP) mode\n");
		return cmd_set_isp(ut->devh);
	}
	if(do_led_specan >= 0) {
		do_led_specan= do_led_specan ? do_led_specan : 225;
		printf("Entering LED specan mode (RSSI %d)\n", do_led_specan);
		return cmd_led_specan(ut->devh, do_led_specan);
	}
	if(do_range_test == 0) {
		printf("Starting range test\n");
		return cmd_range_test(ut->devh);
	}
	if(do_repeater == 0) {
		printf("Starting repeater\n");
		return cmd_repeater(ut->devh);
	}
	if(do_tx == 0) {
		printf("Starting TX test\n");
		return cmd_tx_test(ut->devh);
	}
	if(do_set_squelch > 0) {
		printf("Setting squelch to %d\n", squelch_level);
		cmd_set_squelch(ut->devh, squelch_level);
	}
	if(do_get_squelch > 0) {
		r = cmd_get_squelch(ut->devh);
		printf("Squelch set to %d\n", (int8_t)r);
	}
	if(do_something) {
		unsigned char buf[4] = { 0x55, 0x55, 0x55, 0x55 };
		cmd_do_something(ut->devh, NULL, 0);
		cmd_do_something_reply(ut->devh, buf, 4);
		printf("%02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]);
		return 0;
	}

	return r;
}
示例#29
0
文件: cli.c 项目: Godzil/sd2snes
void cli_loop(void) {
  while (1) {
    curchar = getline(">");
    printf("\n");

    /* Process medium changes before executing the command */
    if (disk_state != DISK_OK && disk_state != DISK_REMOVED) {
      FRESULT res;

      printf("Medium changed... ");
      res = f_mount(0,&fatfs);
      if (res != FR_OK) {
        printf("Failed to mount new medium, result %d\n",res);
      } else {
        printf("Ok\n");
      }

    }

    /* Remove whitespace */
    while (*curchar == ' ') curchar++;
    while (strlen(curchar) > 0 && curchar[strlen(curchar)-1] == ' ')
      curchar[strlen(curchar)-1] = 0;

    /* Ignore empty lines */
    if (strlen(curchar) == 0)
      continue;

    /* Parse command */
    int8_t command = parse_wordlist(command_words);
    if (command < 0)
      continue;


    FRESULT res;
    switch (command) {
    case CMD_CD:
#if _FS_RPATH
      if (strlen(curchar) == 0) {
        f_getcwd((TCHAR*)file_lfn, 255);
        printf("%s\n",file_lfn);
        break;
      }

      res = f_chdir((const TCHAR *)curchar);
      if (res != FR_OK) {
        printf("chdir %s failed with result %d\n",curchar,res);
      } else {
        printf("Ok.\n");
      }
#else
      printf("cd not supported.\n");
      res;
#endif
    break;
    case CMD_RESET:
      cmd_reset();
      break;

    case CMD_SRESET:
      cmd_sreset();
      break;

    case CMD_DIR:
    case CMD_LS:
      cmd_show_directory();
      break;

    case CMD_RESUME:
      return;
      break;

    case CMD_LOADROM:
      cmd_loadrom();
      break;

    case CMD_LOADRAW:
      cmd_loadraw();
      break;

    case CMD_SAVERAW:
      cmd_saveraw();
      break;

    case CMD_RM:
      cmd_rm();
      break;

    case CMD_D4:
      cmd_d4();
      break;

    case CMD_VMODE:
      cmd_vmode();
      break;

    case CMD_PUT:
      cmd_put();
      break;

    case CMD_MAPPER:
      cmd_mapper();
      break;

    case CMD_SETTIME:
      cmd_settime();
      break;

    case CMD_TIME:
      cmd_time();
      break;

    case CMD_TEST:
      testbattery();
      break;

    case CMD_SETFEATURE:
      cmd_setfeature();
      break;

    case CMD_HEXDUMP:
      cmd_hexdump();
      break;

    case CMD_W8:
      cmd_w8();
      break;

    case CMD_W16:
      cmd_w16();
      break;
    }

  }
}
示例#30
0
int cmd_merge(int argc, const char **argv, const char *prefix)
{
	unsigned char result_tree[20];
	unsigned char stash[20];
	unsigned char head_sha1[20];
	struct commit *head_commit;
	struct strbuf buf = STRBUF_INIT;
	const char *head_arg;
	int flag, i;
	int best_cnt = -1, merge_was_ok = 0, automerge_was_ok = 0;
	struct commit_list *common = NULL;
	const char *best_strategy = NULL, *wt_strategy = NULL;
	struct commit_list **remotes = &remoteheads;

	if (argc == 2 && !strcmp(argv[1], "-h"))
		usage_with_options(builtin_merge_usage, builtin_merge_options);

	/*
	 * Check if we are _not_ on a detached HEAD, i.e. if there is a
	 * current branch.
	 */
	branch = resolve_ref("HEAD", head_sha1, 0, &flag);
	if (branch && !prefixcmp(branch, "refs/heads/"))
		branch += 11;
	if (!branch || is_null_sha1(head_sha1))
		head_commit = NULL;
	else
		head_commit = lookup_commit_or_die(head_sha1, "HEAD");

	git_config(git_merge_config, NULL);

	if (branch_mergeoptions)
		parse_branch_merge_options(branch_mergeoptions);
	argc = parse_options(argc, argv, prefix, builtin_merge_options,
			builtin_merge_usage, 0);

	if (verbosity < 0 && show_progress == -1)
		show_progress = 0;

	if (abort_current_merge) {
		int nargc = 2;
		const char *nargv[] = {"reset", "--merge", NULL};

		if (!file_exists(git_path("MERGE_HEAD")))
			die(_("There is no merge to abort (MERGE_HEAD missing)."));

		/* Invoke 'git reset --merge' */
		return cmd_reset(nargc, nargv, prefix);
	}

	if (read_cache_unmerged())
		die_resolve_conflict("merge");

	if (file_exists(git_path("MERGE_HEAD"))) {
		/*
		 * There is no unmerged entry, don't advise 'git
		 * add/rm <file>', just 'git commit'.
		 */
		if (advice_resolve_conflict)
			die(_("You have not concluded your merge (MERGE_HEAD exists).\n"
				  "Please, commit your changes before you can merge."));
		else
			die(_("You have not concluded your merge (MERGE_HEAD exists)."));
	}
	if (file_exists(git_path("CHERRY_PICK_HEAD"))) {
		if (advice_resolve_conflict)
			die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
			    "Please, commit your changes before you can merge."));
		else
			die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists)."));
	}
	resolve_undo_clear();

	if (verbosity < 0)
		show_diffstat = 0;

	if (squash) {
		if (!allow_fast_forward)
			die(_("You cannot combine --squash with --no-ff."));
		option_commit = 0;
	}

	if (!allow_fast_forward && fast_forward_only)
		die(_("You cannot combine --no-ff with --ff-only."));

	if (!abort_current_merge) {
		if (!argc && default_to_upstream)
			argc = setup_with_upstream(&argv);
		else if (argc == 1 && !strcmp(argv[0], "-"))
			argv[0] = "@{-1}";
	}
	if (!argc)
		usage_with_options(builtin_merge_usage,
			builtin_merge_options);

	/*
	 * This could be traditional "merge <msg> HEAD <commit>..."  and
	 * the way we can tell it is to see if the second token is HEAD,
	 * but some people might have misused the interface and used a
	 * committish that is the same as HEAD there instead.
	 * Traditional format never would have "-m" so it is an
	 * additional safety measure to check for it.
	 */

	if (!have_message && head_commit &&
	    is_old_style_invocation(argc, argv, head_commit->object.sha1)) {
		strbuf_addstr(&merge_msg, argv[0]);
		head_arg = argv[1];
		argv += 2;
		argc -= 2;
	} else if (!head_commit) {
		struct object *remote_head;
		/*
		 * If the merged head is a valid one there is no reason
		 * to forbid "git merge" into a branch yet to be born.
		 * We do the same for "git pull".
		 */
		if (argc != 1)
			die(_("Can merge only exactly one commit into "
				"empty head"));
		if (squash)
			die(_("Squash commit into empty head not supported yet"));
		if (!allow_fast_forward)
			die(_("Non-fast-forward commit does not make sense into "
			    "an empty head"));
		remote_head = want_commit(argv[0]);
		if (!remote_head)
			die(_("%s - not something we can merge"), argv[0]);
		read_empty(remote_head->sha1, 0);
		update_ref("initial pull", "HEAD", remote_head->sha1, NULL, 0,
				DIE_ON_ERR);
		return 0;
	} else {
		struct strbuf merge_names = STRBUF_INIT;

		/* We are invoked directly as the first-class UI. */
		head_arg = "HEAD";

		/*
		 * All the rest are the commits being merged;
		 * prepare the standard