Cleanup sconfig
Fix side-effects of name translation, treat original name as const. Change-Id: Iae26be8cefe7db11eeb8e62fce6f3b8bc9c1f4ed Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: http://review.coreboot.org/799 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
This commit is contained in:
parent
e4d40b4d6e
commit
1a2a6eebc5
@ -38,6 +38,13 @@ typedef enum {
|
|||||||
|
|
||||||
static scan_t scan_mode = STATIC_MODE;
|
static scan_t scan_mode = STATIC_MODE;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
UNSLASH,
|
||||||
|
SPLIT_1ST,
|
||||||
|
TO_LOWER,
|
||||||
|
TO_UPPER,
|
||||||
|
} translate_t;
|
||||||
|
|
||||||
static struct device root;
|
static struct device root;
|
||||||
static struct device mainboard = {
|
static struct device mainboard = {
|
||||||
.name = "mainboard",
|
.name = "mainboard",
|
||||||
@ -129,23 +136,31 @@ void postprocess_devtree(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void translate_name(char *str, int uppercase)
|
char * translate_name(const char *str, translate_t mode)
|
||||||
{
|
{
|
||||||
char *c;
|
char *b, *c;
|
||||||
for (c = str; *c; c++) {
|
b = c = strdup(str);
|
||||||
|
while (c && *c) {
|
||||||
|
if ((mode == SPLIT_1ST) && (*c == '/')) {
|
||||||
|
*c = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (*c == '/') *c = '_';
|
if (*c == '/') *c = '_';
|
||||||
if (*c == '-') *c = '_';
|
if (*c == '-') *c = '_';
|
||||||
if (uppercase)
|
if (mode == TO_UPPER)
|
||||||
*c = toupper(*c);
|
*c = toupper(*c);
|
||||||
|
if (mode == TO_LOWER)
|
||||||
|
*c = tolower(*c);
|
||||||
|
c++;
|
||||||
}
|
}
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct device *new_chip(struct device *parent, struct device *bus, char *path) {
|
struct device *new_chip(struct device *parent, struct device *bus, char *path) {
|
||||||
struct device *new_chip = new_dev(parent, bus);
|
struct device *new_chip = new_dev(parent, bus);
|
||||||
new_chip->chiph_exists = 1;
|
new_chip->chiph_exists = 1;
|
||||||
new_chip->name = path;
|
new_chip->name = path;
|
||||||
new_chip->name_underscore = strdup(new_chip->name);
|
new_chip->name_underscore = translate_name(new_chip->name, UNSLASH);
|
||||||
translate_name(new_chip->name_underscore, 0);
|
|
||||||
new_chip->type = chip;
|
new_chip->type = chip;
|
||||||
new_chip->chip = new_chip;
|
new_chip->chip = new_chip;
|
||||||
|
|
||||||
@ -625,8 +640,7 @@ int main(int argc, char** argv) {
|
|||||||
h = &headers;
|
h = &headers;
|
||||||
while (h->next) {
|
while (h->next) {
|
||||||
h = h->next;
|
h = h->next;
|
||||||
char *name_underscore = strdup(h->name);
|
char *name_underscore = translate_name(h->name, UNSLASH);
|
||||||
translate_name(name_underscore, 0);
|
|
||||||
fprintf(autogen, "extern struct chip_operations %s_ops;\n", name_underscore);
|
fprintf(autogen, "extern struct chip_operations %s_ops;\n", name_underscore);
|
||||||
free(name_underscore);
|
free(name_underscore);
|
||||||
}
|
}
|
||||||
@ -659,8 +673,11 @@ int main(int argc, char** argv) {
|
|||||||
h = &headers;
|
h = &headers;
|
||||||
while (h->next) {
|
while (h->next) {
|
||||||
h = h->next;
|
h = h->next;
|
||||||
translate_name(h->name, 0);
|
char * buf = translate_name(h->name, UNSLASH);
|
||||||
fprintf(autogen, "\tinit_%s();\n", h->name);
|
if (buf) {
|
||||||
|
fprintf(autogen, "\tinit_%s();\n", buf);
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(autogen, "\treturn 0;\n}\n");
|
fprintf(autogen, "\treturn 0;\n}\n");
|
||||||
@ -674,8 +691,11 @@ int main(int argc, char** argv) {
|
|||||||
h = &headers;
|
h = &headers;
|
||||||
while (h->next) {
|
while (h->next) {
|
||||||
h = h->next;
|
h = h->next;
|
||||||
translate_name(h->name, 1);
|
char * buf = translate_name(h->name, TO_UPPER);
|
||||||
fprintf(autogen, "\tselect %s\n", h->name);
|
if (buf) {
|
||||||
|
fprintf(autogen, "\tselect %s\n", buf);
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user