diff options
author | Lukas Fleischer | 2014-01-10 12:44:37 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2014-01-10 17:04:14 +0100 |
commit | f04b8d5c99afdc55178f1a06ff1594f5f0cc4be6 (patch) | |
tree | 7aaea2611c19c3ce30a83da982b801d3efa57536 /shared.c | |
parent | 2abce4300b90fa80845193c14d4b6849720007b1 (diff) | |
download | cgit-f04b8d5c99afdc55178f1a06ff1594f5f0cc4be6.tar.gz cgit-f04b8d5c99afdc55178f1a06ff1594f5f0cc4be6.tar.bz2 cgit-f04b8d5c99afdc55178f1a06ff1594f5f0cc4be6.zip |
Refactor cgit_parse_snapshots_mask()
Use Git string lists instead of str{spn,cspn,ncmp}() magic. This
significantly improves readability.
Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
Diffstat (limited to 'shared.c')
-rw-r--r-- | shared.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -404,28 +404,29 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix) | |||
404 | 404 | ||
405 | int cgit_parse_snapshots_mask(const char *str) | 405 | int cgit_parse_snapshots_mask(const char *str) |
406 | { | 406 | { |
407 | struct string_list tokens = STRING_LIST_INIT_DUP; | ||
408 | struct string_list_item *item; | ||
407 | const struct cgit_snapshot_format *f; | 409 | const struct cgit_snapshot_format *f; |
408 | static const char *delim = " "; | 410 | int rv = 0; |
409 | int tl, sl, rv = 0; | ||
410 | 411 | ||
411 | /* favor legacy setting */ | 412 | /* favor legacy setting */ |
412 | if (atoi(str)) | 413 | if (atoi(str)) |
413 | return 1; | 414 | return 1; |
414 | for (;;) { | 415 | |
415 | str += strspn(str, delim); | 416 | string_list_split(&tokens, str, ' ', -1); |
416 | tl = strcspn(str, delim); | 417 | string_list_remove_empty_items(&tokens, 0); |
417 | if (!tl) | 418 | |
418 | break; | 419 | for_each_string_list_item(item, &tokens) { |
419 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 420 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
420 | sl = strlen(f->suffix); | 421 | if (!strcmp(item->string, f->suffix) || |
421 | if ((tl == sl && !strncmp(f->suffix, str, tl)) || | 422 | !strcmp(item->string, f->suffix + 1)) { |
422 | (tl == sl - 1 && !strncmp(f->suffix + 1, str, tl - 1))) { | ||
423 | rv |= f->bit; | 423 | rv |= f->bit; |
424 | break; | 424 | break; |
425 | } | 425 | } |
426 | } | 426 | } |
427 | str += tl; | ||
428 | } | 427 | } |
428 | |||
429 | string_list_clear(&tokens, 0); | ||
429 | return rv; | 430 | return rv; |
430 | } | 431 | } |
431 | 432 | ||