Exemple #1
0
int main(int argc, UCHAR **argv)
{
	UCHAR *script0 = malloc(SIZ_SCRIPT);
//	fat_flags = malloc(65536);
	fat = malloc(65536 * 2);
	filebuf0 = malloc(SIZ_FILEBUF);
	imgbuf0 = malloc(SIZ_IMGBUF);
	UCHAR *p, *q, *r, *script1;
	int i;
	FILE *fp;
	if (imgbuf0 == NULL)
		errend(1); /* out of memory */

	/* スクリプト準備 */
	q = script0;
	while ((p = *++argv) != NULL) {
		if (*p != '@') {
			r = ++q;
			while ((*q++ = *p++) != '\0') {
				if (q - script0 >= SIZ_SCRIPT - 4)
					errend(2); /* script too long */
			}
			if (q - r > 255 + 1)
				errend(3); /* script too long */
			*(r - 1) = (q - r) - 1;
			continue;
		}
		p++;
		fp = fopen(p, "rb");
		if (fp == NULL)
			errend(4); /* script file open error */
		i = fread(filebuf0, 1, SIZ_FILEBUF, fp);
		if (i >= SIZ_FILEBUF)
			errend(5); /* script file open error */
		script1 = filebuf0 + i;
		p = filebuf0;
		for (;;) {
			while (p < script1 && *p <= ' ')
				p++;
			if (p >= script1)
				break;
			r = ++q;
			while (p < script1 && *p > ' ') {
				if (q - script0 >= SIZ_SCRIPT - 4)
					errend(6); /* script too long */
				*q++ = *p++;
			}
			if (q - r > 255)
				errend(7); /* script too long */
			*(r - 1) = q - r;
			*q++ = '\0';
		}
	}
	*q++ = '\0';
	script1 = q;

	/* スクリプト解釈 */
	p = script0;
	for (;;) {
		if (*p == '\0')
			break;
		if (cmdmatch(p, "copy")) {
			p = (UCHAR *) cmd_copy(p);
			continue;
		}
		if (cmdmatch(p, "ovrcopy")) {
			p = (UCHAR *) cmd_ovrcopy(p);
			continue;
		}
		if (cmdmatch(p, "create")) {
			p = (UCHAR *) cmd_create(p);
			continue;
		}
		if (cmdmatch(p, "ovrcreate")) {
			p = (UCHAR *) cmd_ovrcreate(p);
			continue;
		}
		if (cmdmatch(p, "delete")) {
			p = (UCHAR *) cmd_delete(p);
			continue;
		}
		if (cmdmatch(p, "setattr")) {
			p = (UCHAR *) cmd_setattr(p);
			continue;
		}
		if (cmdmatch(p, "wbinimg")) {
			p = (UCHAR *) cmd_wbinimg(p);
			continue;
		}
		if (cmdmatch(p, "release")) {
			p = (UCHAR *) cmd_release(p);
			continue;
		}
		if (cmdmatch(p, "writedata")) {
			p = (UCHAR *) cmd_writedata(p);
			continue;
		}
		if (cmdmatch(p, "list")) {
			p = (UCHAR *) cmd_list(p);
			continue;
		}
		if (cmdmatch(p, "copyall")) {
			p = (UCHAR *) cmd_copyall(p);
			continue;
		}
		if (cmdmatch(p, "exe2bin")) {
			p = (UCHAR *) cmd_exe2bin(p);
			continue;
		}
		if (cmdmatch(p, "opt")) {
			p += *p + 2;
			continue;
		}
		if (optmatch(p, "imgin")) {
			p = (UCHAR *) opt_imgin(p);
			continue;
		}
		if (optmatch(p, "vsiz")) {
			p = (UCHAR *) opt_vsiz(p);
			continue;
		}
		if (optmatch(p, "imgout")) {
			p = (UCHAR *) opt_imgout(p);
			continue;
		}
		if (optmatch(p, "binin")) {
			p = (UCHAR *) opt_binin(p);
			continue;
		}
		if (optmatch(p, "binout")) {
			p = (UCHAR *) opt_binout(p);
			continue;
		}
		if (optmatch(p, "_path")) {
			p = (UCHAR *) opt_bpath(p);
			continue;
		}
		if (optmatch(p, "bias")) {
			p = (UCHAR *) opt_bias(p);
			continue;
		}
		if (cmdmatch(p, "/*")) {
			i = 1;
			do {
				p += *p + 2;
				if (*p == '\0')
					errend(9); /* comment nesting error */
				if (cmdmatch(p, "/*"))
					i++;
				if (cmdmatch(p, "*/"))
					i--;
			} while (i > 0);
			p += *p + 2;
			continue;
		}
		fputs("script syntax error. : ", stderr);
		fputs(p + 1, stderr);
		errend(8); /* script syntax error */
	}
	return 0;
}
Exemple #2
0
/* Menu */
static int menu_run(void)
{
	adv_bool done;
	int userkey;

	menu_base = 0;
	menu_rel = 0;
	menu_rel_max = MENU_DY;
	menu_max = crtc_container_max(&the_modes);
	menu_base_max = menu_max -  menu_rel_max;
	if (menu_base_max < 0)
		menu_base_max = 0;

	done = 0;
	while (!done) {

		draw_text_index(BAR_X, BAR_Y1+1, BAR_DX);
		draw_text_bar(BAR_X, BAR_Y1, BAR_Y2, BAR_DX);
		draw_text_info(INFO_X, INFO_Y, INFO_DX, INFO_DY, menu_base + menu_rel);
		menu_draw(MENU_X, MENU_Y, MENU_DX, MENU_DY);

		video_wait_vsync();

		target_idle();
		os_poll();

		userkey = inputb_get();

		switch (userkey) {
			case INPUTB_UP:
				cmd_gotopos(menu_base + menu_rel - 1);
				break;
			case INPUTB_DOWN:
				cmd_gotopos(menu_base + menu_rel + 1);
				break;
			case INPUTB_HOME: {
				int i = menu_base + menu_rel - 1;
				if (i<0)
					i = 0;
				while (i>0 && !(crtc_container_pos(&the_modes, i)->user_flags & MODE_FLAGS_USER_BIT0))
					--i;
				cmd_gotopos(i);
				break;
			}
			case INPUTB_END: {
				int i = menu_base + menu_rel + 1;
				if (i >= menu_max)
					i = menu_max - 1;
				while (i < menu_max - 1 && !(crtc_container_pos(&the_modes, i)->user_flags & MODE_FLAGS_USER_BIT0))
					++i;
				cmd_gotopos(i);
				break;
			}
			case INPUTB_PGDN:
				cmd_gotopos(menu_base + menu_rel + menu_rel_max);
				break;
			case INPUTB_PGUP:
				cmd_gotopos(menu_base + menu_rel - menu_rel_max);
				break;
			case INPUTB_F2:
				cmd_save();
				break;
			case INPUTB_LEFT :
			case INPUTB_RIGHT :
				cmd_type(userkey);
				break;
			case INPUTB_ESC:
				done = cmd_exit();
				break;
			case INPUTB_SPACE:
				cmd_select();
				cmd_gotopos(menu_base + menu_rel + 1);
				break;
			case INPUTB_ENTER:
				if (cmd_onvideo_test() != 0) {
					text_reset();
					draw_text_error();
				} else {
					text_reset();
				}
				break;
			case INPUTB_F9:
				if (cmd_onvideo_calib() != 0) {
					text_reset();
					draw_text_error();
				} else {
					text_reset();
				}
				break;
			case INPUTB_F10:
				if (cmd_onvideo_animate() != 0) {
					text_reset();
					draw_text_error();
				} else {
					text_reset();
				}
				break;
			case INPUTB_TAB :
				cmd_rename();
				break;
			case INPUTB_F5 :
				if (cmd_modeline_create(1) !=0) {
					text_reset();
					draw_text_error();
				} else {
					text_reset();
				}
				break;
			case INPUTB_F6 :
				if (cmd_modeline_create(0) !=0) {
					text_reset();
					draw_text_error();
				} else {
					text_reset();
				}
				break;
			case INPUTB_F7 :
				cmd_copy();
				break;
			case INPUTB_F8 :
				if (cmd_mode_clock() !=0) {
					text_reset();
					draw_text_error();
				} else {
					text_reset();
				}
				break;
			case INPUTB_DEL :
				cmd_del();
				cmd_gotopos(menu_base + menu_rel);
				break;
			case INPUTB_F1:
				draw_text_help();
				break;
			default:
				if (cmd_offvideo_test(userkey) != 0) {
					draw_text_error();
				}
				break;
		}
	}
	return userkey;
}