Пример #1
0
int s6502_match_reg8 (cmd_t *cmd, sim6502_t *sim, unsigned char **reg)
{
	cmd_match_space (cmd);

	if (cmd_match (cmd, "ra")) {
		*reg = &sim->cpu->a;
		return (1);
	}
	else if (cmd_match (cmd, "x")) {
		*reg = &sim->cpu->x;
		return (1);
	}
	else if (cmd_match (cmd, "y")) {
		*reg = &sim->cpu->y;
		return (1);
	}
	else if (cmd_match (cmd, "p")) {
		*reg = &sim->cpu->p;
		return (1);
	}
	else if (cmd_match (cmd, "s")) {
		*reg = &sim->cpu->s;
		return (1);
	}

	return (0);
}
Пример #2
0
static
int s6502_do_cmd (sim6502_t *sim, cmd_t *cmd)
{
	if (cmd_match (cmd, "b")) {
		cmd_do_b (cmd, &sim->bps);
	}
	else if (cmd_match (cmd, "c")) {
		do_c (cmd, sim);
	}
	else if (cmd_match (cmd, "g")) {
		do_g (cmd, sim);
	}
	else if (cmd_match (cmd, "p")) {
		do_p (cmd, sim);
	}
	else if (cmd_match (cmd, "r")) {
		do_r (cmd, sim);
	}
	else if (cmd_match (cmd, "s")) {
		do_s (cmd, sim);
	}
	else if (cmd_match (cmd, "t")) {
		do_t (cmd, sim);
	}
	else if (cmd_match (cmd, "u")) {
		do_u (cmd, sim);
	}
	else {
		return (1);
	}

	return (0);
}
Пример #3
0
/* WHAT_CMD -- Determine which editing command has been sent.  Such commands
 * must begin with a non-printable character.  Return the command number or
 * zero if unrecognized.  We are called with the first character of the
 * command (some control code).  Additional keystrokes are read from the
 * standard input until an editor command is recognized.
 */
int 
what_cmd (
    int first_char		/* the first unprintable character */
)
{
	register int	nchars, k;
	char	cmd_string[9];
	char	*cmd;

	cmd = cmd_string;
	*cmd = first_char;

	/* Loop until we get an exact match or until we get no match.
	 * A character is read from the standard input in each pass
	 * through the loop.
	 */
	for (nchars=1;  nchars < 9;  nchars++)
	    if ((k = cmd_match (cmd_string, nchars)) < 0)
		return (0);
	    else if (nchars == strlen (command[k].escape))
		return (command[k].cmd);
	    else
		*(++cmd) = fgetc(stdin);

	return (0);
}
Пример #4
0
static
void do_g (cmd_t *cmd, sim6502_t *sim)
{
	if (cmd_match (cmd, "b")) {
		do_g_b (cmd, sim);
		return;
	}

	if (!cmd_match_end (cmd)) {
		return;
	}

	s6502_run (sim);
}
Пример #5
0
static
void prt_state (sim6502_t *sim, FILE *fp, const char *str)
{
	cmd_t cmd;

	cmd_set_str (&cmd, str);

	if (cmd_match_eol (&cmd)) {
		return;
	}

	while (!cmd_match_eol (&cmd)) {
		if (cmd_match (&cmd, "cpu")) {
			prt_state_cpu (sim->cpu, fp);
		}
		else if (cmd_match (&cmd, "mem")) {
			prt_state_mem (sim, fp);
		}
		else {
			printf ("unknown component (%s)\n", cmd_get_str (&cmd));
			return;
		}
	}
}
Пример #6
0
static int command_read_line(char buf[])
{
	char input_c;
	int cur_pos = 0;
	int cur_max = 0;
	int hst_pos = g_cmd_stack.hist;
	int esc_sequence = 0;
	int spec_key = 0;
	int ret;

	memset(buf, 0, MAX_ARG_LEN);

	while (0 == cur_max) {
		input_c = 0;

		printf("\033[4h");

		show_prompt();
		printf("\033[4h");
		while (input_c != '\r' && input_c != '\n') {
			input_c = shell_getchar();
			//fixme: support F1 F2 F3 ...
			if (input_c == '\033') {
				spec_key = 1;
				input_c = shell_getchar();
				if (input_c == '[') {
					esc_sequence = 1;
					input_c = shell_getchar();
				}
			} else {
				spec_key = 0;
				esc_sequence = 0;
			}

			switch (input_c) {
			case '\t':
#if 0
				pre_space_count = get_pre_space_count(buf);
				for (exe = g_exe_begin; exe < g_exe_end; exe++) {
					if (!cur_pos || strncmp(exe->name, buf + pre_space_count, strlen(exe->name)) == 0) {
						if (exe->usr_cmd_match && (cmd_line_status(buf, &cur_pos) == IS_CMD_MATCH)) {
							if (match_count != 1) {
								match_count = exe->usr_cmd_match(buf, &cur_pos, &cur_max);
								cmd_last_pos = cur_pos;
							}

							if (cur_pos != cmd_last_pos)
								match_count = exe->usr_cmd_match(buf, &cur_pos, &cur_max);
						}
						break;
					}
				}
#endif
				if (IS_CMD_MATCH == cmd_line_status(buf, &cur_pos))
					cmd_match(buf, &cur_pos, &cur_max);
				break;

			case '\r':
			case '\n':
				putchar('\n');
				break;

			case 0x03: // ctrl + c
				cur_pos = 0;
				cur_max = 0;
				input_c = '\n';
				putchar(input_c);
				break;

			case 0x08:
			case 0x7f:
				if (cur_pos > 0)
					backspace_one_key(buf, &cur_pos, &cur_max);

				break;

			case 'A':
			case 'B':// no filter: escape +' [' + 'A'
				if (1 == esc_sequence) {
					if ('A' == input_c)
						ret = cmd_up_key(buf, &cur_pos, &hst_pos, &cur_max);
					else
						ret = cmd_down_key(buf, &cur_pos, &hst_pos, &cur_max);

					if (ret < 0)
						// fixme: do something
						;
				} else // not a up/down key, treat it as a normal input
					print_input(input_c, buf, &cur_pos, &cur_max);

				break;

			case 'C':
			case 'D':
				if (1 == esc_sequence) {
					if ('C' == input_c)
						ret = cmd_right_key(buf, &cur_pos, &cur_max);
					else
						ret = cmd_left_key(buf, &cur_pos, &cur_max);
					break;
				} else // not a left/right key, treat it as a normal input
					print_input(input_c, buf, &cur_pos, &cur_max);

				break;

			case 'O':
				if (1 == spec_key) {
					input_c = shell_getchar();

					if ('H' == input_c) {
						if (cur_pos != 0)
							printf("\033[%dD", cur_pos);
						cur_pos = 0;
					}
					if ('F' == input_c) {
						if (cur_pos != cur_max)
							printf("\033[%dC", cur_max - cur_pos);
						cur_pos = cur_max;
					}
				} else // not a Home/End key, treat it as a normal input
					print_input(input_c, buf, &cur_pos, &cur_max);

				break;

			case '3':
				if (1 == spec_key) {
					input_c = shell_getchar();

					if ('~' == input_c)
						delete_one_key(buf, &cur_pos, &cur_max);
				} else
					print_input(input_c, buf, &cur_pos, &cur_max);

				break;

			default:
				if (input_c >= 0x20 && input_c <= 0x7f) //filter the character
					print_input(input_c, buf, &cur_pos, &cur_max);

				break;
			}
		}
	}

	buf[cur_max] = '\0';

	cmd_update_history(buf);

	printf("\033[4h");
	printf("\033[4l");

	return 0;
}
Пример #7
0
Файл: misc.c Проект: westes/flex
/* skelout - write out one section of the skeleton file
 *
 * Description
 *    Copies skelfile or skel array to stdout until a line beginning with
 *    "%%" or EOF is found.
 */
void skelout (void)
{
	char    buf_storage[MAXLINE];
	char   *buf = buf_storage;
	bool   do_copy = true;

    /* "reset" the state by clearing the buffer and pushing a '1' */
    if(sko_len > 0)
        sko_peek(&do_copy);
    sko_len = 0;
    sko_push(do_copy=true);


	/* Loop pulling lines either from the skelfile, if we're using
	 * one, or from the skel[] array.
	 */
	while (skelfile ?
	       (fgets (buf, MAXLINE, skelfile) != NULL) :
	       ((buf = (char *) skel[skel_ind++]) != 0)) {

		if (skelfile)
			chomp (buf);

		/* copy from skel array */
		if (buf[0] == '%') {	/* control line */
			/* print the control line as a comment. */
			if (ddebug && buf[1] != '#') {
				if (buf[strlen (buf) - 1] == '\\')
					out_str ("/* %s */\\\n", buf);
				else
					out_str ("/* %s */\n", buf);
			}

			/* We've been accused of using cryptic markers in the skel.
			 * So we'll use emacs-style-hyphenated-commands.
             * We might consider a hash if this if-else-if-else
             * chain gets too large.
			 */
#define cmd_match(s) (strncmp(buf,(s),strlen(s))==0)

		if (buf[1] == '#') {
                	/* %# indicates comment line to be ignored */
            	} 
		else if (buf[1] == '%') {
				/* %% is a break point for skelout() */
				return;
			}
            else if (cmd_match (CMD_PUSH)){
                sko_push(do_copy);
                if(ddebug){
                    out_str("/*(state = (%s) */",do_copy?"true":"false");
                }
                out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : "");
            }
            else if (cmd_match (CMD_POP)){
                sko_pop(&do_copy);
                if(ddebug){
                    out_str("/*(state = (%s) */",do_copy?"true":"false");
                }
                out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : "");
            }
            else if (cmd_match (CMD_IF_REENTRANT)){
                sko_push(do_copy);
                do_copy = reentrant && do_copy;
            }
            else if (cmd_match (CMD_IF_NOT_REENTRANT)){
                sko_push(do_copy);
                do_copy = !reentrant && do_copy;
            }
            else if (cmd_match(CMD_IF_BISON_BRIDGE)){
                sko_push(do_copy);
                do_copy = bison_bridge_lval && do_copy;
            }
            else if (cmd_match(CMD_IF_NOT_BISON_BRIDGE)){
                sko_push(do_copy);
                do_copy = !bison_bridge_lval && do_copy;
            }
            else if (cmd_match (CMD_ENDIF)){
                sko_pop(&do_copy);
            }
			else if (cmd_match (CMD_IF_TABLES_SER)) {
                do_copy = do_copy && tablesext;
			}
			else if (cmd_match (CMD_TABLES_YYDMAP)) {
				if (tablesext && yydmap_buf.elts)
					outn ((char *) (yydmap_buf.elts));
			}
            else if (cmd_match (CMD_DEFINE_YYTABLES)) {
                if ( tablesext )
                    out_str( "#define YYTABLES_NAME \"%s\"\n",
                           tablesname ? tablesname : "yytables" );
            }
			else if (cmd_match (CMD_IF_CPP_ONLY)) {
				/* only for C++ */
                sko_push(do_copy);
				do_copy = C_plus_plus;
			}
			else if (cmd_match (CMD_IF_C_ONLY)) {
				/* %- only for C */
                sko_push(do_copy);
				do_copy = !C_plus_plus;
			}
			else if (cmd_match (CMD_IF_C_OR_CPP)) {
				/* %* for C and C++ */
                sko_push(do_copy);
				do_copy = true;
			}
			else if (cmd_match (CMD_NOT_FOR_HEADER)) {
				/* %c begin linkage-only (non-header) code. */
				OUT_BEGIN_CODE ();
			}
			else if (cmd_match (CMD_OK_FOR_HEADER)) {
				/* %e end linkage-only code. */
				OUT_END_CODE ();
			}
			else {
				flexfatal (_("bad line in skeleton file"));
			}
		}

		else if (do_copy) 
            outn (buf);
	}			/* end while */
}