2
0
mirror of https://github.com/vasi/pixz synced 2024-11-18 15:26:46 +00:00

Make sure each spec matches something

This commit is contained in:
Dave Vasilevsky 2010-10-13 12:47:51 -04:00
parent 7aae647657
commit 6f83d58d51

16
pread.c
View File

@ -182,9 +182,11 @@ static void wanted_files(size_t count, char **specs) {
*c = '\0'; *c = '\0';
} }
bool matched[count]; // for each spec, does it match?
memset(matched, 0, sizeof(matched));
wanted_t *last = NULL; wanted_t *last = NULL;
// Check each file in order, to see if we want it
for (file_index_t *f = gFileIndex; f->name; f = f->next) { for (file_index_t *f = gFileIndex; f->name; f = f->next) {
// Do we want this file?
for (char **spec = specs; spec < specs + count; ++spec) { for (char **spec = specs; spec < specs + count; ++spec) {
char *sc, *nc; char *sc, *nc;
bool match = true; bool match = true;
@ -194,7 +196,9 @@ static void wanted_files(size_t count, char **specs) {
break; break;
} }
} }
if (match && (!*nc || *nc == '/')) { // prefix must be at dir bound // If spec's a prefix of the file name, it must be a dir name
if (match && (!*nc || *nc == '/')) {
// Ok, add the file
wanted_t *w = malloc(sizeof(wanted_t)); wanted_t *w = malloc(sizeof(wanted_t));
*w = (wanted_t){ .name = f->name, .start = f->offset, *w = (wanted_t){ .name = f->name, .start = f->offset,
.end = f->next->offset, .next = NULL }; .end = f->next->offset, .next = NULL };
@ -205,10 +209,18 @@ static void wanted_files(size_t count, char **specs) {
gWantedFiles = w; gWantedFiles = w;
} }
last = w; last = w;
matched[spec - specs] = true;
break; break;
} }
} }
} }
// Make sure each spec matched
for (size_t i = 0; i < count; ++i) {
if (!matched[i])
die("\"%s\" not found in archive", *(specs + i));
}
} }