aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-30 16:28:30 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-30 16:28:30 +0000
commit39d551fd1570ca760582777b325ae3396d49ebf3 (patch)
treec0af0cad727962fb27c28c26dbd41e6e36b18614
parent274b8c0639ae3b733c63252959c3a7fa4025b5cc (diff)
downloadbusybox-39d551fd1570ca760582777b325ae3396d49ebf3.tar.gz
fbset: store short string in the structure itself instead of the pointer
(small size saving)
-rw-r--r--util-linux/fbset.c416
1 files changed, 203 insertions, 213 deletions
diff --git a/util-linux/fbset.c b/util-linux/fbset.c
index 9ca3e1b64..bc8ec1806 100644
--- a/util-linux/fbset.c
+++ b/util-linux/fbset.c
@@ -70,94 +70,92 @@ enum {
FBIOPUT_VSCREENINFO = 0x4601
};
struct fb_bitfield {
- uint32_t offset; /* beginning of bitfield */
- uint32_t length; /* length of bitfield */
- uint32_t msb_right; /* != 0 : Most significant bit is */
- /* right */
+ uint32_t offset; /* beginning of bitfield */
+ uint32_t length; /* length of bitfield */
+ uint32_t msb_right; /* !=0: Most significant bit is right */
};
struct fb_var_screeninfo {
- uint32_t xres; /* visible resolution */
+ uint32_t xres; /* visible resolution */
uint32_t yres;
- uint32_t xres_virtual; /* virtual resolution */
+ uint32_t xres_virtual; /* virtual resolution */
uint32_t yres_virtual;
- uint32_t xoffset; /* offset from virtual to visible */
- uint32_t yoffset; /* resolution */
+ uint32_t xoffset; /* offset from virtual to visible */
+ uint32_t yoffset; /* resolution */
- uint32_t bits_per_pixel; /* guess what */
- uint32_t grayscale; /* != 0 Graylevels instead of colors */
+ uint32_t bits_per_pixel;
+ uint32_t grayscale; /* !=0 Graylevels instead of colors */
- struct fb_bitfield red; /* bitfield in fb mem if true color, */
- struct fb_bitfield green; /* else only length is significant */
+ struct fb_bitfield red; /* bitfield in fb mem if true color, */
+ struct fb_bitfield green; /* else only length is significant */
struct fb_bitfield blue;
- struct fb_bitfield transp; /* transparency */
+ struct fb_bitfield transp; /* transparency */
- uint32_t nonstd; /* != 0 Non standard pixel format */
+ uint32_t nonstd; /* !=0 Non standard pixel format */
- uint32_t activate; /* see FB_ACTIVATE_* */
+ uint32_t activate; /* see FB_ACTIVATE_x */
- uint32_t height; /* height of picture in mm */
- uint32_t width; /* width of picture in mm */
+ uint32_t height; /* height of picture in mm */
+ uint32_t width; /* width of picture in mm */
uint32_t accel_flags; /* acceleration flags (hints) */
/* Timing: All values in pixclocks, except pixclock (of course) */
- uint32_t pixclock; /* pixel clock in ps (pico seconds) */
- uint32_t left_margin; /* time from sync to picture */
- uint32_t right_margin; /* time from picture to sync */
- uint32_t upper_margin; /* time from sync to picture */
+ uint32_t pixclock; /* pixel clock in ps (pico seconds) */
+ uint32_t left_margin; /* time from sync to picture */
+ uint32_t right_margin; /* time from picture to sync */
+ uint32_t upper_margin; /* time from sync to picture */
uint32_t lower_margin;
- uint32_t hsync_len; /* length of horizontal sync */
- uint32_t vsync_len; /* length of vertical sync */
- uint32_t sync; /* see FB_SYNC_* */
- uint32_t vmode; /* see FB_VMODE_* */
- uint32_t reserved[6]; /* Reserved for future compatibility */
+ uint32_t hsync_len; /* length of horizontal sync */
+ uint32_t vsync_len; /* length of vertical sync */
+ uint32_t sync; /* see FB_SYNC_x */
+ uint32_t vmode; /* see FB_VMODE_x */
+ uint32_t reserved[6]; /* Reserved for future compatibility */
};
static const struct cmdoptions_t {
- const char *name;
+ const char name[10];
const unsigned char param_count;
const unsigned char code;
} g_cmdoptions[] = {
- {
- "-fb", 1, CMD_FB}, {
- "-db", 1, CMD_DB}, {
- "-a", 0, CMD_ALL}, {
- "-i", 0, CMD_INFO}, {
- "-g", 5, CMD_GEOMETRY}, {
- "-t", 7, CMD_TIMING}, {
- "-accel", 1, CMD_ACCEL}, {
- "-hsync", 1, CMD_HSYNC}, {
- "-vsync", 1, CMD_VSYNC}, {
- "-laced", 1, CMD_LACED}, {
- "-double", 1, CMD_DOUBLE}, {
- "-n", 0, CMD_CHANGE}, {
+ { "-fb", 1, CMD_FB },
+ { "-db", 1, CMD_DB },
+ { "-a", 0, CMD_ALL },
+ { "-i", 0, CMD_INFO },
+ { "-g", 5, CMD_GEOMETRY },
+ { "-t", 7, CMD_TIMING },
+ { "-accel", 1, CMD_ACCEL },
+ { "-hsync", 1, CMD_HSYNC },
+ { "-vsync", 1, CMD_VSYNC },
+ { "-laced", 1, CMD_LACED },
+ { "-double", 1, CMD_DOUBLE },
+ { "-n", 0, CMD_CHANGE },
#ifdef CONFIG_FEATURE_FBSET_FANCY
- "-all", 0, CMD_ALL}, {
- "-xres", 1, CMD_XRES}, {
- "-yres", 1, CMD_YRES}, {
- "-vxres", 1, CMD_VXRES}, {
- "-vyres", 1, CMD_VYRES}, {
- "-depth", 1, CMD_DEPTH}, {
- "-match", 0, CMD_MATCH}, {
- "-geometry", 5, CMD_GEOMETRY}, {
- "-pixclock", 1, CMD_PIXCLOCK}, {
- "-left", 1, CMD_LEFT}, {
- "-right", 1, CMD_RIGHT}, {
- "-upper", 1, CMD_UPPER}, {
- "-lower", 1, CMD_LOWER}, {
- "-hslen", 1, CMD_HSLEN}, {
- "-vslen", 1, CMD_VSLEN}, {
- "-timings", 7, CMD_TIMING}, {
- "-csync", 1, CMD_CSYNC}, {
- "-gsync", 1, CMD_GSYNC}, {
- "-extsync", 1, CMD_EXTSYNC}, {
- "-bcast", 1, CMD_BCAST}, {
- "-rgba", 1, CMD_RGBA}, {
- "-step", 1, CMD_STEP}, {
- "-move", 1, CMD_MOVE}, {
+ { "-all", 0, CMD_ALL },
+ { "-xres", 1, CMD_XRES },
+ { "-yres", 1, CMD_YRES },
+ { "-vxres", 1, CMD_VXRES },
+ { "-vyres", 1, CMD_VYRES },
+ { "-depth", 1, CMD_DEPTH },
+ { "-match", 0, CMD_MATCH },
+ { "-geometry", 5, CMD_GEOMETRY },
+ { "-pixclock", 1, CMD_PIXCLOCK },
+ { "-left", 1, CMD_LEFT },
+ { "-right", 1, CMD_RIGHT },
+ { "-upper", 1, CMD_UPPER },
+ { "-lower", 1, CMD_LOWER },
+ { "-hslen", 1, CMD_HSLEN },
+ { "-vslen", 1, CMD_VSLEN },
+ { "-timings", 7, CMD_TIMING },
+ { "-csync", 1, CMD_CSYNC },
+ { "-gsync", 1, CMD_GSYNC },
+ { "-extsync", 1, CMD_EXTSYNC },
+ { "-bcast", 1, CMD_BCAST },
+ { "-rgba", 1, CMD_RGBA },
+ { "-step", 1, CMD_STEP },
+ { "-move", 1, CMD_MOVE },
#endif
- 0, 0, 0}
+ { "", 0, 0 }
};
#ifdef CONFIG_FEATURE_FBSET_READMODE
@@ -171,6 +169,7 @@ enum {
FB_SYNC_COMP_HIGH_ACT = 8 /* composite sync high active */
};
#endif
+
static int readmode(struct fb_var_screeninfo *base, const char *fn,
const char *mode)
{
@@ -182,89 +181,82 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn,
f = xfopen(fn, "r");
while (!feof(f)) {
fgets(buf, sizeof(buf), f);
- if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
- p += 5;
- if ((p = strstr(buf, mode))) {
- p += strlen(mode);
- if (!isspace(*p) && (*p != 0) && (*p != '"')
- && (*p != '\r') && (*p != '\n'))
- continue; /* almost, but not quite */
- while (!feof(f)) {
- fgets(buf, sizeof(buf), f);
-
- if ((p = strstr(buf, "geometry "))) {
- p += 9;
-
- sscanf(p, "%d %d %d %d %d",
- &(base->xres), &(base->yres),
- &(base->xres_virtual), &(base->yres_virtual),
- &(base->bits_per_pixel));
- } else if ((p = strstr(buf, "timings "))) {
- p += 8;
-
- sscanf(p, "%d %d %d %d %d %d %d",
- &(base->pixclock),
- &(base->left_margin), &(base->right_margin),
- &(base->upper_margin), &(base->lower_margin),
- &(base->hsync_len), &(base->vsync_len));
- } else if ((p = strstr(buf, "laced "))) {
- p += 6;
-
- if (strstr(buf, "false")) {
- base->vmode &= ~FB_VMODE_INTERLACED;
- } else {
- base->vmode |= FB_VMODE_INTERLACED;
- }
- } else if ((p = strstr(buf, "double "))) {
- p += 7;
-
- if (strstr(buf, "false")) {
- base->vmode &= ~FB_VMODE_DOUBLE;
- } else {
- base->vmode |= FB_VMODE_DOUBLE;
- }
- } else if ((p = strstr(buf, "vsync "))) {
- p += 6;
-
- if (strstr(buf, "low")) {
- base->sync &= ~FB_SYNC_VERT_HIGH_ACT;
- } else {
- base->sync |= FB_SYNC_VERT_HIGH_ACT;
- }
- } else if ((p = strstr(buf, "hsync "))) {
- p += 6;
-
- if (strstr(buf, "low")) {
- base->sync &= ~FB_SYNC_HOR_HIGH_ACT;
- } else {
- base->sync |= FB_SYNC_HOR_HIGH_ACT;
- }
- } else if ((p = strstr(buf, "csync "))) {
- p += 6;
-
- if (strstr(buf, "low")) {
- base->sync &= ~FB_SYNC_COMP_HIGH_ACT;
- } else {
- base->sync |= FB_SYNC_COMP_HIGH_ACT;
- }
- } else if ((p = strstr(buf, "extsync "))) {
- p += 8;
-
- if (strstr(buf, "false")) {
- base->sync &= ~FB_SYNC_EXT;
- } else {
- base->sync |= FB_SYNC_EXT;
- }
- }
-
- if (strstr(buf, "endmode"))
- return 1;
+ if (!(p = strstr(buf, "mode ")) && !(p = strstr(buf, "mode\t")))
+ continue;
+ p += 5;
+ if (!(p = strstr(buf, mode)))
+ continue;
+ p += strlen(mode);
+ if (!isspace(*p) && (*p != 0) && (*p != '"')
+ && (*p != '\r') && (*p != '\n'))
+ continue; /* almost, but not quite */
+
+ while (!feof(f)) {
+ fgets(buf, sizeof(buf), f);
+ if ((p = strstr(buf, "geometry "))) {
+ p += 9;
+ /* FIXME: catastrophic on arches with 64bit ints */
+ sscanf(p, "%d %d %d %d %d",
+ &(base->xres), &(base->yres),
+ &(base->xres_virtual), &(base->yres_virtual),
+ &(base->bits_per_pixel));
+ } else if ((p = strstr(buf, "timings "))) {
+ p += 8;
+ sscanf(p, "%d %d %d %d %d %d %d",
+ &(base->pixclock),
+ &(base->left_margin), &(base->right_margin),
+ &(base->upper_margin), &(base->lower_margin),
+ &(base->hsync_len), &(base->vsync_len));
+ } else if ((p = strstr(buf, "laced "))) {
+ //p += 6;
+ if (strstr(buf, "false")) {
+ base->vmode &= ~FB_VMODE_INTERLACED;
+ } else {
+ base->vmode |= FB_VMODE_INTERLACED;
+ }
+ } else if ((p = strstr(buf, "double "))) {
+ //p += 7;
+ if (strstr(buf, "false")) {
+ base->vmode &= ~FB_VMODE_DOUBLE;
+ } else {
+ base->vmode |= FB_VMODE_DOUBLE;
+ }
+ } else if ((p = strstr(buf, "vsync "))) {
+ //p += 6;
+ if (strstr(buf, "low")) {
+ base->sync &= ~FB_SYNC_VERT_HIGH_ACT;
+ } else {
+ base->sync |= FB_SYNC_VERT_HIGH_ACT;
+ }
+ } else if ((p = strstr(buf, "hsync "))) {
+ //p += 6;
+ if (strstr(buf, "low")) {
+ base->sync &= ~FB_SYNC_HOR_HIGH_ACT;
+ } else {
+ base->sync |= FB_SYNC_HOR_HIGH_ACT;
+ }
+ } else if ((p = strstr(buf, "csync "))) {
+ //p += 6;
+ if (strstr(buf, "low")) {
+ base->sync &= ~FB_SYNC_COMP_HIGH_ACT;
+ } else {
+ base->sync |= FB_SYNC_COMP_HIGH_ACT;
+ }
+ } else if ((p = strstr(buf, "extsync "))) {
+ //p += 8;
+ if (strstr(buf, "false")) {
+ base->sync &= ~FB_SYNC_EXT;
+ } else {
+ base->sync |= FB_SYNC_EXT;
}
}
+
+ if (strstr(buf, "endmode"))
+ return 1;
}
}
#else
- bb_error_msg( "mode reading not compiled in");
+ bb_error_msg("mode reading not compiled in");
#endif
return 0;
}
@@ -290,28 +282,28 @@ static inline void showmode(struct fb_var_screeninfo *v)
if (v->pixclock) {
drate = 1e12 / v->pixclock;
- hrate =
- drate / (v->left_margin + v->xres + v->right_margin +
- v->hsync_len);
- vrate =
- hrate / (v->upper_margin + v->yres + v->lower_margin +
- v->vsync_len);
+ hrate = drate / (v->left_margin + v->xres + v->right_margin + v->hsync_len);
+ vrate = hrate / (v->upper_margin + v->yres + v->lower_margin + v->vsync_len);
}
printf("\nmode \"%ux%u-%u\"\n"
#ifdef CONFIG_FEATURE_FBSET_FANCY
"\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n"
#endif
- "\tgeometry %u %u %u %u %u\n\ttimings %u %u %u %u %u %u %u\n\taccel %s\n\trgba %u/%u,%u/%u,%u/%u,%u/%u\nendmode\n\n",
- v->xres, v->yres, (int) (vrate + 0.5),
+ "\tgeometry %u %u %u %u %u\n"
+ "\ttimings %u %u %u %u %u %u %u\n"
+ "\taccel %s\n"
+ "\trgba %u/%u,%u/%u,%u/%u,%u/%u\n"
+ "endmode\n\n",
+ v->xres, v->yres, (int) (vrate + 0.5),
#ifdef CONFIG_FEATURE_FBSET_FANCY
- drate / 1e6, hrate / 1e3, vrate,
+ drate / 1e6, hrate / 1e3, vrate,
#endif
- v->xres, v->yres, v->xres_virtual, v->yres_virtual,
- v->bits_per_pixel, v->pixclock, v->left_margin,
- v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
- v->vsync_len, (v->accel_flags > 0 ? "true" : "false"), v->red.length,
- v->red.offset, v->green.length, v->green.offset, v->blue.length,
- v->blue.offset, v->transp.length, v->transp.offset);
+ v->xres, v->yres, v->xres_virtual, v->yres_virtual, v->bits_per_pixel,
+ v->pixclock, v->left_margin, v->right_margin, v->upper_margin, v->lower_margin,
+ v->hsync_len, v->vsync_len,
+ (v->accel_flags > 0 ? "true" : "false"),
+ v->red.length, v->red.offset, v->green.length, v->green.offset,
+ v->blue.length, v->blue.offset, v->transp.length, v->transp.offset);
}
#ifdef STANDALONE
@@ -332,73 +324,71 @@ int fbset_main(int argc, char **argv)
argv++;
argc--;
for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
- for (i = 0; g_cmdoptions[i].name; i++) {
- if (!strcmp(thisarg, g_cmdoptions[i].name)) {
- 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 = strtoul(argv[1], 0, 0);
- varset.yres = strtoul(argv[2], 0, 0);
- varset.xres_virtual = strtoul(argv[3], 0, 0);
- varset.yres_virtual = strtoul(argv[4], 0, 0);
- varset.bits_per_pixel = strtoul(argv[5], 0, 0);
- break;
- case CMD_TIMING:
- varset.pixclock = strtoul(argv[1], 0, 0);
- varset.left_margin = strtoul(argv[2], 0, 0);
- varset.right_margin = strtoul(argv[3], 0, 0);
- varset.upper_margin = strtoul(argv[4], 0, 0);
- varset.lower_margin = strtoul(argv[5], 0, 0);
- varset.hsync_len = strtoul(argv[6], 0, 0);
- varset.vsync_len = strtoul(argv[7], 0, 0);
- break;
- case CMD_ALL:
- g_options |= OPT_ALL;
- break;
- case CMD_CHANGE:
- g_options |= OPT_CHANGE;
- break;
+ 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 = strtoul(argv[1], 0, 0);
+ varset.yres = strtoul(argv[2], 0, 0);
+ varset.xres_virtual = strtoul(argv[3], 0, 0);
+ varset.yres_virtual = strtoul(argv[4], 0, 0);
+ varset.bits_per_pixel = strtoul(argv[5], 0, 0);
+ break;
+ case CMD_TIMING:
+ varset.pixclock = strtoul(argv[1], 0, 0);
+ varset.left_margin = strtoul(argv[2], 0, 0);
+ varset.right_margin = strtoul(argv[3], 0, 0);
+ varset.upper_margin = strtoul(argv[4], 0, 0);
+ varset.lower_margin = strtoul(argv[5], 0, 0);
+ varset.hsync_len = strtoul(argv[6], 0, 0);
+ varset.vsync_len = strtoul(argv[7], 0, 0);
+ 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 = strtoul(argv[1], 0, 0);
- break;
- case CMD_YRES:
- varset.yres = strtoul(argv[1], 0, 0);
- break;
- case CMD_DEPTH:
- varset.bits_per_pixel = strtoul(argv[1], 0, 0);
- break;
-#endif
- }
- argc -= g_cmdoptions[i].param_count;
- argv += g_cmdoptions[i].param_count;
+ case CMD_XRES:
+ varset.xres = strtoul(argv[1], 0, 0);
break;
+ case CMD_YRES:
+ varset.yres = strtoul(argv[1], 0, 0);
+ break;
+ case CMD_DEPTH:
+ varset.bits_per_pixel = strtoul(argv[1], 0, 0);
+ break;
+#endif
}
+ argc -= g_cmdoptions[i].param_count;
+ argv += g_cmdoptions[i].param_count;
+ break;
}
- if (!g_cmdoptions[i].name) {
- if (argc == 1) {
- mode = *argv;
- g_options |= OPT_READMODE;
- } else {
+ 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("fbset(ioctl)");
+ bb_perror_msg_and_die("ioctl(%sT_VSCREENINFO)", "GE");
if (g_options & OPT_READMODE) {
if (!readmode(&var, modefile, mode)) {
- bb_error_msg("unknown video mode '%s'", mode);
- return EXIT_FAILURE;
+ bb_error_msg_and_die("unknown video mode '%s'", mode);
}
}
@@ -407,7 +397,7 @@ int fbset_main(int argc, char **argv)
if (g_options & OPT_ALL)
var.activate = FB_ACTIVATE_ALL;
if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
- bb_perror_msg_and_die("fbset(ioctl)");
+ bb_perror_msg_and_die("ioctl(%sT_VSCREENINFO)", "PU");
}
showmode(&var);
/* Don't close the file, as exiting will take care of that */