aboutsummaryrefslogtreecommitdiffstats
path: root/shared.c
diff options
context:
space:
mode:
authorGravatar Lukas Fleischer <cgit@cryptocrack.de>2014-01-10 20:44:37 (JST)
committerGravatar Jason A. Donenfeld <Jason@zx2c4.com>2014-01-11 01:04:14 (JST)
commitf04b8d5c99afdc55178f1a06ff1594f5f0cc4be6 (patch)
tree7aaea2611c19c3ce30a83da982b801d3efa57536 /shared.c
parent2abce4300b90fa80845193c14d4b6849720007b1 (diff)
downloadcgit-f04b8d5c99afdc55178f1a06ff1594f5f0cc4be6.zip
cgit-f04b8d5c99afdc55178f1a06ff1594f5f0cc4be6.tar.gz
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.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/shared.c b/shared.c
index 1f6310a..01197f1 100644
--- a/shared.c
+++ b/shared.c
@@ -404,28 +404,29 @@ void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix)
404 404
405int cgit_parse_snapshots_mask(const char *str) 405int 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