Beispiel #1
0
int ask_yn(e2fsck_t ctx, const char * string, int def)
{
	int		c;
	const char	*defstr;
	const char	*short_yes = _("yY");
	const char	*short_no = _("nN");

#ifdef HAVE_TERMIOS_H
	struct termios	termios, tmp;

	tcgetattr (0, &termios);
	tmp = termios;
	tmp.c_lflag &= ~(ICANON | ECHO);
	tmp.c_cc[VMIN] = 1;
	tmp.c_cc[VTIME] = 0;
	tcsetattr (0, TCSANOW, &tmp);
#endif

	if (def == 1)
		defstr = _(_("<y>"));
	else if (def == 0)
		defstr = _(_("<n>"));
	else
		defstr = _(" (y/n)");
	log_out(ctx, "%s%s? ", string, defstr);
	while (1) {
		fflush (stdout);
		if ((c = read_a_char()) == EOF)
			break;
		if (c == 3) {
#ifdef HAVE_TERMIOS_H
			tcsetattr (0, TCSANOW, &termios);
#endif
			if (ctx->flags & E2F_FLAG_SETJMP_OK) {
				log_out(ctx, "\n");
				longjmp(e2fsck_global_ctx->abort_loc, 1);
			}
			log_out(ctx, "%s", _("cancelled!\n"));
			return 0;
		}
		if (strchr(short_yes, (char) c)) {
			def = 1;
			break;
		}
		else if (strchr(short_no, (char) c)) {
			def = 0;
			break;
		}
		else if ((c == 27 || c == ' ' || c == '\n') && (def != -1))
			break;
	}
	if (def)
		log_out(ctx, "%s", _("yes\n"));
	else
		log_out(ctx, "%s", _("no\n"));
#ifdef HAVE_TERMIOS_H
	tcsetattr (0, TCSANOW, &termios);
#endif
	return def;
}
Beispiel #2
0
int ask_yn(const char * string, int def)
{
	int		c;
	const char	*defstr;
	const char	*short_yes = _("yY");
	const char	*short_no = _("nN");

#ifdef HAVE_TERMIOS_H
	struct termios	termios, tmp;

	tcgetattr (0, &termios);
	tmp = termios;
	tmp.c_lflag &= ~(ICANON | ECHO);
	tmp.c_cc[VMIN] = 1;
	tmp.c_cc[VTIME] = 0;
	tcsetattr (0, TCSANOW, &tmp);
#endif

	if (def == 1)
		defstr = _("<y>");
	else if (def == 0)
		defstr = _("<n>");
	else
		defstr = _(" (y/n)");
	printf("%s%s? ", string, defstr);
	while (1) {
		fflush (stdout);
		if ((c = read_a_char()) == EOF)
			break;
		if (strchr(short_yes, (char) c)) {
			def = 1;
			break;
		}
		else if (strchr(short_no, (char) c)) {
			def = 0;
			break;
		}
		else if ((c == ' ' || c == '\n') && (def != -1))
			break;
	}
	if (def)
		printf ("yes\n\n");
	else
		printf ("no\n\n");
#ifdef HAVE_TERMIOS_H
	tcsetattr (0, TCSANOW, &termios);
#endif
	return def;
}
Beispiel #3
0
int ask_yn(e2fsck_t ctx, const char * string, int def)
{
	int		c;
	const char	*defstr;
	const char	*short_yes = _("yY");
	const char	*short_no = _("nN");
	const char	*short_yesall = _("aA");
	const char	*english_yes = "yY";
	const char	*english_no = "nN";
	const char	*english_yesall = "aA";
	const char	*yesall_prompt = _(" ('a' enables 'yes' to all) ");
	const char	*extra_prompt = "";
	static int	yes_answers;

#ifdef HAVE_TERMIOS_H
	struct termios	termios = {0, }, tmp;

	tcgetattr (0, &termios);
	tmp = termios;
	tmp.c_lflag &= ~(ICANON | ECHO);
	tmp.c_cc[VMIN] = 1;
	tmp.c_cc[VTIME] = 0;
	tcsetattr (0, TCSANOW, &tmp);
#endif

	if (def == 1)
		defstr = _(_("<y>"));
	else if (def == 0)
		defstr = _(_("<n>"));
	else
		defstr = _(" (y/n)");
	/*
	 * If the user presses 'y' more than 8 (but less than 12) times in
	 * succession without pressing anything else, display a hint about
	 * yes-to-all mode.
	 */
	if (yes_answers > 12)
		yes_answers = -1;
	else if (yes_answers > 8)
		extra_prompt = yesall_prompt;
	log_out(ctx, "%s%s%s? ", string, extra_prompt, defstr);
	while (1) {
		fflush (stdout);
		if ((c = read_a_char()) == EOF)
			break;
		if (c == 3) {
#ifdef HAVE_TERMIOS_H
			tcsetattr (0, TCSANOW, &termios);
#endif
			if (ctx->flags & E2F_FLAG_SETJMP_OK) {
				log_out(ctx, "\n");
				longjmp(e2fsck_global_ctx->abort_loc, 1);
			}
			log_out(ctx, "%s", _("cancelled!\n"));
			yes_answers = 0;
			return 0;
		}
		if (strchr(short_yes, (char) c)) {
		do_yes:
			def = 1;
			if (yes_answers >= 0)
				yes_answers++;
			break;
		} else if (strchr(short_no, (char) c)) {
		do_no:
			def = 0;
			yes_answers = -1;
			break;
		} else if (strchr(short_yesall, (char)c)) {
		do_all:
			def = 2;
			yes_answers = -1;
			ctx->options |= E2F_OPT_YES;
			break;
		} else if (strchr(english_yes, (char) c)) {
			goto do_yes;
		} else if (strchr(english_no, (char) c)) {
			goto do_no;
		} else if (strchr(english_yesall, (char) c)) {
			goto do_all;
		} else if ((c == 27 || c == ' ' || c == '\n') && (def != -1)) {
			yes_answers = -1;
			break;
		}
	}
	if (def == 2)
		log_out(ctx, "%s", _("yes to all\n"));
	else if (def)
		log_out(ctx, "%s", _("yes\n"));
	else
		log_out(ctx, "%s", _("no\n"));
#ifdef HAVE_TERMIOS_H
	tcsetattr (0, TCSANOW, &termios);
#endif
	return def;
}
Beispiel #4
0
/*============================================================================*/
int loadstate(char *filename)
{
	FILE *fn;
	int bios;
	uint32_t crc;
	size_t ret;

	if (filename == NULL)
		return O2EM_FAILURE;
	#ifdef __O2EM_DEBUG__
	printf("%s DEBUG %s\n", __func__, filename);
	#endif
	fn = fopen(filename, "rb");
	if (fn == NULL) {
		fprintf(stderr, "fopen error %s: %s\n", __func__, strerror(errno));
		return O2EM_FAILURE;
	}

	ret = fread(&crc, sizeof(crc), 1, fn);
	check_return_of_fxxx(ret, fn);
	if (crc != app_data.crc) { /* wrong cart*/
		fclose(fn);
		return 199;/* TODO made 199 a #define WRONG_BIOS*/
	}

	ret = fread(&bios, sizeof(bios), 1, fn);
	check_return_of_fxxx(ret, fn);
	if (bios!=app_data.bios) { /* wrong bios*/
		fclose(fn);
		return 200 + bios;
	}

	ret = fread(VDCwrite, 256, 1, fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(extRAM, 256, 1, fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(intRAM, 64, 1, fn);
	check_return_of_fxxx(ret, fn);

/*	fread(&pc, sizeof(pc),1,fn);*/
	read_a_char(&pc, sizeof(pc), fn);
	ret = fread(&sp, sizeof(sp), 1, fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&bs, sizeof(bs),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&p1, sizeof(p1),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&p2, sizeof(p2),1,fn);
	check_return_of_fxxx(ret, fn);

	ret = fread(&ac, sizeof(ac),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&cy, sizeof(cy),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&f0, sizeof(f0),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&A11, sizeof(A11),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&A11ff, sizeof(A11ff),1,fn);
	check_return_of_fxxx(ret, fn);

	ret = fread(&timer_on, sizeof(timer_on),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&count_on, sizeof(count_on),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&reg_pnt, sizeof(reg_pnt),1,fn);
	check_return_of_fxxx(ret, fn);

	ret = fread(&tirq_en, sizeof(tirq_en),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&xirq_en, sizeof(xirq_en),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&irq_ex, sizeof(irq_ex),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&xirq_pend, sizeof(xirq_pend),1,fn);
	check_return_of_fxxx(ret, fn);
	ret = fread(&tirq_pend, sizeof(tirq_pend),1,fn);
	check_return_of_fxxx(ret, fn);

	fclose(fn);
	return O2EM_SUCCESS;
}