tcc -ar options: use strchr, strpbrk (trivial, no-op)
I happened to bump into thsese, but I didn't try to review the file,
and there may be other places which could be similarly improved.
This is originally my suboptimal code from commit 100f94be
(tiny_libmaker: more robust arguments interpretation), so, a bit late,
but let's improve it anyway.
This commit is contained in:
parent
ef7e84454e
commit
a6ef31823b
1 changed files with 6 additions and 18 deletions
24
tcctools.c
24
tcctools.c
|
@ -48,18 +48,6 @@ static unsigned long le2belong(unsigned long ul) {
|
||||||
((ul & 0xFF)<<24)+((ul & 0xFF00)<<8);
|
((ul & 0xFF)<<24)+((ul & 0xFF00)<<8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns 1 if s contains any of the chars of list, else 0 */
|
|
||||||
static int contains_any(const char *s, const char *list) {
|
|
||||||
const char *l;
|
|
||||||
for (; *s; s++) {
|
|
||||||
for (l = list; *l; l++) {
|
|
||||||
if (*s == *l)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ar_usage(int ret) {
|
static int ar_usage(int ret) {
|
||||||
fprintf(stderr, "usage: tcc -ar [crstvx] lib [files]\n");
|
fprintf(stderr, "usage: tcc -ar [crstvx] lib [files]\n");
|
||||||
fprintf(stderr, "create library ([abdiopN] not supported).\n");
|
fprintf(stderr, "create library ([abdiopN] not supported).\n");
|
||||||
|
@ -103,16 +91,16 @@ ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv)
|
||||||
i_lib = 0; i_obj = 0; // will hold the index of the lib and first obj
|
i_lib = 0; i_obj = 0; // will hold the index of the lib and first obj
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
const char *a = argv[i];
|
const char *a = argv[i];
|
||||||
if (*a == '-' && strstr(a, "."))
|
if (*a == '-' && strchr(a, '.'))
|
||||||
ret = 1; // -x.y is always invalid (same as gnu ar)
|
ret = 1; // -x.y is always invalid (same as gnu ar)
|
||||||
if ((*a == '-') || (i == 1 && !strstr(a, "."))) { // options argument
|
if ((*a == '-') || (i == 1 && !strchr(a, '.'))) { // options argument
|
||||||
if (contains_any(a, ops_conflict))
|
if (strpbrk(a, ops_conflict))
|
||||||
ret = 1;
|
ret = 1;
|
||||||
if (strstr(a, "x"))
|
if (strchr(a, 'x'))
|
||||||
extract = 1;
|
extract = 1;
|
||||||
if (strstr(a, "t"))
|
if (strchr(a, 't'))
|
||||||
table = 1;
|
table = 1;
|
||||||
if (strstr(a, "v"))
|
if (strchr(a, 'v'))
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
} else { // lib or obj files: don't abort - keep validating all args.
|
} else { // lib or obj files: don't abort - keep validating all args.
|
||||||
if (!i_lib) // first file is the lib
|
if (!i_lib) // first file is the lib
|
||||||
|
|
Loading…
Add table
Reference in a new issue