-#ifdef CONFIG_FEATURE_FBSET_READMODE
- FILE *f;
- char buf[256];
- char *p = buf;
-
- 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;
- }
+ char *token[2], *p, *s;
+ parser_t *parser = config_open(fn);
+
+ while (config_read(parser, token, 2, 1, "# \t\r", PARSE_NORMAL)) {
+ if (strcmp(token[0], "mode") != 0 || !token[1])
+ continue;
+ p = strstr(token[1], mode);
+ if (!p)
+ continue;
+ s = p + strlen(mode);
+ //bb_info_msg("CHECK[%s][%s][%d]", mode, p-1, *s);
+ /* exact match? */
+ if (((!*s || isspace(*s)) && '"' != s[-1]) /* end-of-token */
+ || ('"' == *s && '"' == p[-1]) /* ends with " but starts with " too! */
+ ) {
+ //bb_info_msg("FOUND[%s][%s][%s][%d]", token[1], p, mode, isspace(*s));
+ break;
+ }
+ }
+
+ if (!token[0])
+ return 0;
+
+ while (config_read(parser, token, 2, 1, "# \t", PARSE_NORMAL)) {
+ int i;
+
+//bb_info_msg("???[%s][%s]", token[0], token[1]);
+ if (strcmp(token[0], "endmode") == 0) {
+//bb_info_msg("OK[%s]", mode);
+ return 1;
+ }
+ p = token[1];
+ i = index_in_strings(
+ "geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0",
+ token[0]);
+ switch (i) {
+ case 0:
+ if (sizeof(int) == sizeof(base->xres)) {
+ sscanf(p, "%d %d %d %d %d",
+ &base->xres, &base->yres,
+ &base->xres_virtual, &base->yres_virtual,
+ &base->bits_per_pixel);
+ } else {
+ int base_xres, base_yres;
+ int base_xres_virtual, base_yres_virtual;
+ int base_bits_per_pixel;
+ sscanf(p, "%d %d %d %d %d",
+ &base_xres, &base_yres,
+ &base_xres_virtual, &base_yres_virtual,
+ &base_bits_per_pixel);
+ base->xres = base_xres;
+ base->yres = base_yres;
+ base->xres_virtual = base_xres_virtual;
+ base->yres_virtual = base_yres_virtual;
+ base->bits_per_pixel = base_bits_per_pixel;
+ }
+//bb_info_msg("GEO[%s]", p);
+ break;
+ case 1:
+ if (sizeof(int) == sizeof(base->xres)) {
+ 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 {
+ int base_pixclock;
+ int base_left_margin, base_right_margin;
+ int base_upper_margin, base_lower_margin;
+ int base_hsync_len, base_vsync_len;
+ 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);
+ base->pixclock = base_pixclock;
+ base->left_margin = base_left_margin;
+ base->right_margin = base_right_margin;
+ base->upper_margin = base_upper_margin;
+ base->lower_margin = base_lower_margin;
+ base->hsync_len = base_hsync_len;
+ base->vsync_len = base_vsync_len;