mirror of
https://github.com/AuxXxilium/kmod.git
synced 2024-12-18 20:48:11 +07:00
Add underscores() helper to replace - with _
This commit is contained in:
parent
81cf2060e0
commit
8185fc91e2
@ -63,5 +63,6 @@ int kmod_parse_config(struct kmod_ctx *ctx, struct kmod_config *config);
|
||||
void kmod_free_config(struct kmod_ctx *ctx, struct kmod_config *config);
|
||||
|
||||
char *getline_wrapped(FILE *fp, unsigned int *linenum);
|
||||
char *underscores(struct kmod_ctx *ctx, char *s);
|
||||
|
||||
#endif
|
||||
|
@ -83,3 +83,35 @@ char *getline_wrapped(FILE *fp, unsigned int *linenum)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Replace dashes with underscores.
|
||||
* Dashes inside character range patterns (e.g. [0-9]) are left unchanged.
|
||||
*/
|
||||
char *underscores(struct kmod_ctx *ctx, char *s)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; s[i]; i++) {
|
||||
switch (s[i]) {
|
||||
case '-':
|
||||
s[i] = '_';
|
||||
break;
|
||||
|
||||
case ']':
|
||||
INFO(ctx, "Unmatched bracket in %s\n", s);
|
||||
break;
|
||||
|
||||
case '[':
|
||||
i += strcspn(&s[i], "]");
|
||||
if (!s[i])
|
||||
INFO(ctx, "Unmatched bracket in %s\n", s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user