Пример #1
0
int fbset_main(int argc, char **argv)
#endif
{
	struct fb_var_screeninfo var, varset;
	int fh, i;
	char *fbdev = DEFAULTFBDEV;
	char *modefile = DEFAULTFBMODE;
	char *thisarg, *mode = NULL;

	memset(&varset, 0xFF, sizeof(varset));

	/* parse cmd args.... why do they have to make things so difficult? */
	argv++;
	argc--;
	for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
		for (i = 0; g_cmdoptions[i].name[0]; i++) {
			if (strcmp(thisarg, g_cmdoptions[i].name))
				continue;
			if (argc-1 < g_cmdoptions[i].param_count)
				bb_show_usage();

			switch (g_cmdoptions[i].code) {
			case CMD_FB:
				fbdev = argv[1];
				break;
			case CMD_DB:
				modefile = argv[1];
				break;
			case CMD_GEOMETRY:
				varset.xres = xatou32(argv[1]);
				varset.yres = xatou32(argv[2]);
				varset.xres_virtual = xatou32(argv[3]);
				varset.yres_virtual = xatou32(argv[4]);
				varset.bits_per_pixel = xatou32(argv[5]);
				break;
			case CMD_TIMING:
				varset.pixclock = xatou32(argv[1]);
				varset.left_margin = xatou32(argv[2]);
				varset.right_margin = xatou32(argv[3]);
				varset.upper_margin = xatou32(argv[4]);
				varset.lower_margin = xatou32(argv[5]);
				varset.hsync_len = xatou32(argv[6]);
				varset.vsync_len = xatou32(argv[7]);
				break;
			case CMD_ALL:
				g_options |= OPT_ALL;
				break;
			case CMD_CHANGE:
				g_options |= OPT_CHANGE;
				break;
#ifdef CONFIG_FEATURE_FBSET_FANCY
			case CMD_XRES:
				varset.xres = xatou32(argv[1]);
				break;
			case CMD_YRES:
				varset.yres = xatou32(argv[1]);
				break;
			case CMD_DEPTH:
				varset.bits_per_pixel = xatou32(argv[1]);
				break;
#endif
			}
			argc -= g_cmdoptions[i].param_count;
			argv += g_cmdoptions[i].param_count;
			break;
		}
		if (!g_cmdoptions[i].name[0]) {
			if (argc != 1)
				bb_show_usage();
			mode = *argv;
			g_options |= OPT_READMODE;
		}
	}

	fh = xopen(fbdev, O_RDONLY);
	if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
		bb_perror_msg_and_die("ioctl(%sT_VSCREENINFO)", "GE");
	if (g_options & OPT_READMODE) {
		if (!readmode(&var, modefile, mode)) {
			bb_error_msg_and_die("unknown video mode '%s'", mode);
		}
	}

	setmode(&var, &varset);
	if (g_options & OPT_CHANGE) {
		if (g_options & OPT_ALL)
			var.activate = FB_ACTIVATE_ALL;
		if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
			bb_perror_msg_and_die("ioctl(%sT_VSCREENINFO)", "PU");
	}
	showmode(&var);
	/* Don't close the file, as exiting will take care of that */
	/* close(fh); */

	return EXIT_SUCCESS;
}
Пример #2
0
int main(int argc, char **argv)
{
    enum { UNSPEC, READ, WRITE } mode = UNSPEC;
    int doing_opts = 1;

    ctldir = NULL;
    command = NULL;

    while (--argc > 0) {
        char *p = *++argv;
        if (doing_opts && *p == '-') {
            if (!strcmp(p, "-w")) {
                mode = WRITE;
            } else if (!strcmp(p, "-r")) {
                mode = READ;
            } else if (!strcmp(p, "--")) {
                doing_opts = 0;
            } else if (!strcmp(p, "--version")) {
                version();
                return 0;
            } else if (!strcmp(p, "--help")) {
                usage();
                return 0;
            } else if (!strcmp(p, "--licence") || !strcmp(p, "--license")) {
                licence();
                return 0;
            } else {
                fprintf(stderr, "buildrun: unrecognised option '%s'\n", p);
                return 1;
            }
        } else {
            if (!ctldir) {
                ctldir = p;
            } else {
                command = argv;
                break;
            }
        }
    }

    if (mode == UNSPEC) {
        fprintf(stderr, "buildrun: expected -w or -r\n");
        return 1;
    }

    if (!ctldir) {
        fprintf(stderr, "buildrun: expected a control directory name\n");
        return 1;
    }

    pipepath = malloc(strlen(ctldir) + strlen(PIPEFILE) + 2);
    if (!pipepath) {
        fprintf(stderr, "buildrun: out of memory\n");
        return 1;
    }
    sprintf(pipepath, "%s/%s", ctldir, PIPEFILE);

    if (mode == WRITE) {
        return writemode();
    } else if (mode == READ) {
        return readmode();
    }
}