History

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.

Avi Halachmi (:avih) committed 1 year ago

Commit a6ef3181 parent ef7e8441 file · +6 −18Browse files

Unified · Split

tcctools.c+6−18
@@ -48,18 +48,6 @@ static unsigned long le2belong(unsigned long ul) { · 47 unmodified lines
4848 ((ul & 0xFF)<<24)+((ul & 0xFF00)<<8);
4949 }
5050
51−/* Returns 1 if s contains any of the chars of list, else 0 */
52−static int contains_any(const char *s, const char *list) {
53− const char *l;
54− for (; *s; s++) {
55− for (l = list; *l; l++) {
56− if (*s == *l)
57− return 1;
58− }
59− }
60− return 0;
61−}
62−
6351 static int ar_usage(int ret) {
6452 fprintf(stderr, "usage: tcc -ar [crstvx] lib [files]\n");
6553 fprintf(stderr, "create library ([abdiopN] not supported).\n");
@@ -103,16 +91,16 @@ ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv) · 37 unmodified lines
10391 i_lib = 0; i_obj = 0; // will hold the index of the lib and first obj
10492 for (i = 1; i < argc; i++) {
10593 const char *a = argv[i];
106− if (*a == '-' && strstr(a, "."))
94+ if (*a == '-' && strchr(a, '.'))
10795 ret = 1; // -x.y is always invalid (same as gnu ar)
108− if ((*a == '-') || (i == 1 && !strstr(a, "."))) { // options argument
109− if (contains_any(a, ops_conflict))
96+ if ((*a == '-') || (i == 1 && !strchr(a, '.'))) { // options argument
97+ if (strpbrk(a, ops_conflict))
11098 ret = 1;
111− if (strstr(a, "x"))
99+ if (strchr(a, 'x'))
112100 extract = 1;
113− if (strstr(a, "t"))
101+ if (strchr(a, 't'))
114102 table = 1;
115− if (strstr(a, "v"))
103+ if (strchr(a, 'v'))
116104 verbose = 1;
117105 } else { // lib or obj files: don't abort - keep validating all args.
118106 if (!i_lib) // first file is the lib

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t