// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Read and parse syslinux config file. // // return: // 0: ok, 1: error // int read_config_file(void) { FILE *f; char *s, *t, buf[MAX_CONFIG_LINE_LEN]; unsigned u, menu_idx = 0, label_size = 0, append_size = 0; menu_t *menu_ptr = NULL, **menu_next = &menu; menu_default = calloc(1, sizeof *menu_default); if(!(f = fopen(syslinux_config_file(), "r"))) return 1; while((s = fgets(buf, sizeof buf, f))) { chop_line(s); s = skip_spaces(s); if(!*s || *s == '#') continue; t = skip_nonspaces(s); if(*t) *t++ = 0; t = skip_spaces(t); if(!strcasecmp(s, "timeout")) { timeout = atoi(t); continue; } if(!strcasecmp(s, "default")) { menu_default->label = strdup(t); u = strlen(t); if(u > label_size) label_size = u; continue; } if(!strcasecmp(s, "label")) { menu_ptr = *menu_next = calloc(1, sizeof **menu_next); menu_next = &menu_ptr->next; menu_idx++; menu_ptr->label = menu_ptr->menu_label = strdup(t); u = strlen(t); if(u > label_size) label_size = u; continue; } if(!strcasecmp(s, "kernel") && menu_ptr) { menu_ptr->kernel = strdup(t); continue; } if(!strcasecmp(s, "linux") && menu_ptr) { menu_ptr->linux = strdup(t); continue; } if(!strcasecmp(s, "localboot") && menu_ptr) { menu_ptr->localboot = strdup(t); continue; } if(!strcasecmp(s, "initrd") && menu_ptr) { menu_ptr->initrd = strdup(t); continue; } if(!strcasecmp(s, "append")) { (menu_ptr ?: menu_default)->append = strdup(t); u = strlen(t); if(u > append_size) append_size = u; continue; } if(!strcasecmp(s, "ipappend")) { (menu_ptr ?: menu_default)->ipappend = strdup(t); continue; }
/* Print the syslinux config file name */ void rosh_cfg(void) { printf("CFG: '%s'\n", syslinux_config_file()); } /* rosh_cfg */
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Read and parse syslinux config file. // // return: // 0: ok, 1: error // int read_config_file(const char *filename) { FILE *f; char *s, *t, buf[MAX_CONFIG_LINE_LEN]; unsigned u, top_level = 0, text = 0; if(!strcmp(filename, "~")) { top_level = 1; filename = syslinux_config_file(); gfx_menu.entries = 0; gfx_menu.label_size = 0; gfx_menu.arg_size = 0; menu_ptr = NULL; menu_next = &menu; menu_default = calloc(1, sizeof *menu_default); } if(!(f = fopen(filename, "r"))) return 1; while((s = fgets(buf, sizeof buf, f))) { chop_line(s); s = skipspace(s); if(!*s || *s == '#') continue; t = skip_nonspaces(s); if(*t) *t++ = 0; t = skipspace(t); if(!strcasecmp(s, "endtext")) { text = 0; continue; } if (text) continue; if(!strcasecmp(s, "timeout")) { timeout = atoi(t); continue; } if(!strcasecmp(s, "default")) { menu_default->label = strdup(t); u = strlen(t); if(u > gfx_menu.label_size) gfx_menu.label_size = u; continue; } if(!strcasecmp(s, "label")) { menu_ptr = *menu_next = calloc(1, sizeof **menu_next); menu_next = &menu_ptr->next; gfx_menu.entries++; menu_ptr->label = menu_ptr->menu_label = strdup(t); u = strlen(t); if(u > gfx_menu.label_size) gfx_menu.label_size = u; continue; } if(!strcasecmp(s, "kernel") && menu_ptr) { menu_ptr->kernel = strdup(t); continue; } if(!strcasecmp(s, "linux") && menu_ptr) { menu_ptr->linux = strdup(t); continue; } if(!strcasecmp(s, "localboot") && menu_ptr) { menu_ptr->localboot = strdup(t); continue; } if(!strcasecmp(s, "initrd") && menu_ptr) { menu_ptr->initrd = strdup(t); continue; } if(!strcasecmp(s, "append")) { (menu_ptr ?: menu_default)->append = strdup(t); u = strlen(t); if(u > gfx_menu.arg_size) gfx_menu.arg_size = u; continue; } if(!strcasecmp(s, "ipappend")) { (menu_ptr ?: menu_default)->ipappend = strdup(t); continue; }
static struct match *parse_config(const char *filename) { char line[MAX_LINE], *p; FILE *f; struct match *list = NULL; struct match **ep = &list; struct match *m; if (!filename) filename = syslinux_config_file(); f = fopen(filename, "r"); if (!f) return list; while (fgets(line, sizeof line, f)) { p = skipspace(line); if (!looking_at(p, "#")) continue; p = skipspace(p + 1); if (!looking_at(p, "dev")) continue; p = skipspace(p + 3); m = malloc(sizeof(struct match)); if (!m) continue; memset(m, 0, sizeof *m); m->rid_max = 0xff; for (;;) { p = skipspace(p); if (looking_at(p, "did")) { p = get_did(p + 3, &m->did, &m->did_mask); } else if (looking_at(p, "sid")) { p = get_did(p + 3, &m->sid, &m->sid_mask); } else if (looking_at(p, "rid")) { p = get_rid_range(p + 3, &m->rid_min, &m->rid_max); } else { char *e; e = strchr(p, '\n'); if (*e) *e = '\0'; e = strchr(p, '\r'); if (*e) *e = '\0'; m->filename = strdup(p); if (!m->filename) m->did = -1; break; /* Done with this line */ } } dprintf("DEV DID %08x/%08x SID %08x/%08x RID %02x-%02x CMD %s\n", m->did, m->did_mask, m->sid, m->sid_mask, m->rid_min, m->rid_max, m->filename); *ep = m; ep = &m->next; } return list; }