- `--blacklist-contains <text>`
- `--blacklist-begins-with <text>`
- `--blacklist-ends-with <text>`
+ - `--wb-case-insensitive`
These flags should affect what entries are archived, what entries are printed
(with `-t`), and what entries are extracted.
--blacklist-contains <text> : blacklist entries that contains "<text>", specify multiple times to deny multiple "<text>" entries at once.
--blacklist-begins-with <text> : blacklist entries that starts with "<text>", specify multiple times to deny multiple entries starting with different "<text>" entries.
--blacklist-ends-with <text> : blacklist entries that ends with "<text>", specify multiple times to deny multiple entries ending with different "<text>" entries.
+ --wb-case-insensitive : Makes white/black-list checking case insensitive.
--version : prints version and exits
-- : specifies remaining arguments are files to archive/extract
If creating archive file, remaining args specify files to archive.
// Check white/black lists.
if (!simple_archiver_helper_string_allowed_lists(
file_info->filename,
+ state->parsed->flags & 0x20000 ? 1 : 0,
state->parsed->whitelist_contains,
state->parsed->whitelist_begins,
state->parsed->whitelist_ends,
const uint_fast8_t lists_allowed = simple_archiver_helper_string_allowed_lists(
link_name,
+ state->parsed->flags & 0x20000 ? 1 : 0,
state->parsed->whitelist_contains,
state->parsed->whitelist_begins,
state->parsed->whitelist_ends,
file_info->other_flags |= 1;
} else if (simple_archiver_helper_string_allowed_lists(
file_info->filename,
+ state->parsed->flags & 0x20000 ? 1 : 0,
state->parsed->whitelist_contains,
state->parsed->whitelist_begins,
state->parsed->whitelist_ends,
const uint_fast8_t lists_allowed =
simple_archiver_helper_string_allowed_lists(
archive_dir_name,
+ state->parsed->flags & 0x20000 ? 1 : 0,
state->parsed->whitelist_contains,
state->parsed->whitelist_begins,
state->parsed->whitelist_ends,
}
uint_fast8_t simple_archiver_helper_string_contains(const char *cstring,
- const char *contains) {
+ const char *contains,
+ uint_fast8_t case_i) {
const size_t cstring_size = strlen(cstring);
const size_t contains_size = strlen(contains);
size_t contains_match_start = 0;
size_t contains_match_idx = 0;
for (size_t idx = 0; idx < cstring_size; ++idx) {
- if (cstring[idx] == contains[contains_match_idx]) {
+ char cstring_next = cstring[idx];
+ char contains_next = contains[contains_match_idx];
+ if (case_i) {
+ if (cstring_next >= 'A' && cstring_next <= 'Z') {
+ cstring_next += 0x20;
+ }
+ if (contains_next >= 'A' && contains_next <= 'Z') {
+ contains_next += 0x20;
+ }
+ }
+
+ if (cstring_next == contains_next) {
if (contains_match_idx == 0) {
contains_match_start = idx;
}
}
uint_fast8_t simple_archiver_helper_string_starts(const char *cstring,
- const char *starts) {
+ const char *starts,
+ uint_fast8_t case_i) {
const size_t cstring_len = strlen(cstring);
const size_t starts_len = strlen(starts);
size_t starts_match_idx = 0;
for (size_t idx = 0; idx < cstring_len; ++idx) {
- if (cstring[idx] == starts[starts_match_idx]) {
+ char cstring_next = cstring[idx];
+ char starts_next = starts[starts_match_idx];
+ if (case_i) {
+ if (cstring_next >= 'A' && cstring_next <= 'Z') {
+ cstring_next += 0x20;
+ }
+ if (starts_next >= 'A' && starts_next <= 'Z') {
+ starts_next += 0x20;
+ }
+ }
+
+ if (cstring_next == starts_next) {
if (starts_match_idx == 0) {
if (idx != 0) {
return 0;
}
uint_fast8_t simple_archiver_helper_string_ends(const char *cstring,
- const char *ends) {
+ const char *ends,
+ uint_fast8_t case_i) {
const size_t cstring_len = strlen(cstring);
const size_t ends_len = strlen(ends);
size_t ends_idx = 0;
for (size_t idx = cstring_len - ends_len; idx < cstring_len; ++idx) {
- if (cstring[idx] == ends[ends_idx]) {
+ char cstring_next = cstring[idx];
+ char ends_next = ends[ends_idx];
+ if (case_i) {
+ if (cstring_next >= 'A' && cstring_next <= 'Z') {
+ cstring_next += 0x20;
+ }
+ if (ends_next >= 'A' && ends_next <= 'Z') {
+ ends_next += 0x20;
+ }
+ }
+
+ if (cstring_next == ends_next) {
++ends_idx;
if (ends_idx == ends_len) {
return 1;
uint_fast8_t simple_archiver_helper_string_allowed_lists(
const char *cstring,
+ uint_fast8_t case_i,
const SDArchiverLinkedList *w_contains,
const SDArchiverLinkedList *w_begins,
const SDArchiverLinkedList *w_ends,
node != w_contains->tail;
node = node->next) {
if (node->data) {
- if (!simple_archiver_helper_string_contains(cstring, node->data)) {
+ if (!simple_archiver_helper_string_contains(
+ cstring, node->data, case_i)) {
return 0;
}
}
node != w_begins->tail;
node = node->next) {
if (node->data) {
- if (!simple_archiver_helper_string_starts(cstring, node->data)) {
+ if (!simple_archiver_helper_string_starts(
+ cstring, node->data, case_i)) {
return 0;
}
}
node != w_ends->tail;
node = node->next) {
if (node->data) {
- if (!simple_archiver_helper_string_ends(cstring, node->data)) {
+ if (!simple_archiver_helper_string_ends(cstring, node->data, case_i)) {
return 0;
}
}
node != b_contains->tail;
node = node->next) {
if (node->data) {
- if (simple_archiver_helper_string_contains(cstring, node->data)) {
+ if (simple_archiver_helper_string_contains(
+ cstring, node->data, case_i)) {
return 0;
}
}
node != b_begins->tail;
node = node->next) {
if (node->data) {
- if (simple_archiver_helper_string_starts(cstring, node->data)) {
+ if (simple_archiver_helper_string_starts(cstring, node->data, case_i)) {
return 0;
}
}
node != b_ends->tail;
node = node->next) {
if (node->data) {
- if (simple_archiver_helper_string_ends(cstring, node->data)) {
+ if (simple_archiver_helper_string_ends(cstring, node->data, case_i)) {
return 0;
}
}
SAHelperStringParts string_parts);
// Returns non-zero if "cstring" contains string "contains".
+// "case_i" stands for "case-insensitive".
uint_fast8_t simple_archiver_helper_string_contains(const char *cstring,
- const char *contains);
+ const char *contains,
+ uint_fast8_t case_i);
// Returns non-zero if "cstring" starts with string "starts".
+// "case_i" stands for "case-insensitive".
uint_fast8_t simple_archiver_helper_string_starts(const char *cstring,
- const char *starts);
+ const char *starts,
+ uint_fast8_t case_i);
// Returns non-zero if "cstring" ends with string "ends".
+// "case_i" stands for "case-insensitive".
uint_fast8_t simple_archiver_helper_string_ends(const char *cstring,
- const char *ends);
+ const char *ends,
+ uint_fast8_t case_i);
// Returns non-zero if "cstring" is allowed by lists.
+// "case_i" stands for "case-insensitive".
uint_fast8_t simple_archiver_helper_string_allowed_lists(
const char *cstring,
+ uint_fast8_t case_i,
const SDArchiverLinkedList *w_contains,
const SDArchiverLinkedList *w_begins,
const SDArchiverLinkedList *w_ends,
"--blacklist-ends-with <text> : blacklist entries that ends with "
"\"<text>\", specify multiple times to deny multiple entries ending "
"with different \"<text>\" entries.\n");
+ fprintf(stderr,
+ "--wb-case-insensitive : Makes white/black-list checking case "
+ "insensitive.\n");
fprintf(stderr, "--version : prints version and exits\n");
fprintf(stderr,
"-- : specifies remaining arguments are files to archive/extract\n");
--argc;
++argv;
+ } else if (strcmp(argv[0], "--wb-case-insensitive") == 0) {
+ out->flags |= 0x20000;
} else if (strcmp(argv[0], "--version") == 0) {
fprintf(stderr, "Version: %s\n", SIMPLE_ARCHIVER_VERSION_STR);
exit(0);
/// 0b x1xx xxxx xxxx xxxx - Prefer UID over Username when extracting.
/// 0b 1xxx xxxx xxxx xxxx - Prefer GID over Group when extracting.
/// 0b xxxx xxx1 xxxx xxxx xxxx xxxx - Force set empty directory permissions.
+ /// 0b xxxx xx1x xxxx xxxx xxxx xxxx - white/black-list checking is
+ /// case-insensitive.
uint32_t flags;
/// Null-terminated string.
char *filename;
// Test contains/starts/ends helpers.
{
CHECK_TRUE(simple_archiver_helper_string_contains(
- "The string is this.", " is "));
+ "The string is this.", " is ", 0));
CHECK_FALSE(simple_archiver_helper_string_contains(
- "The string is this.", " is d"));
+ "The string is this.", " is d", 0));
CHECK_TRUE(simple_archiver_helper_string_contains(
- "TheseTheThesesThe", "Theses"));
+ "TheseTheThesesThe", "Theses", 0));
CHECK_TRUE(simple_archiver_helper_string_starts(
- "The string is this.", "The "));
+ "The string is this.", "The ", 0));
CHECK_FALSE(simple_archiver_helper_string_starts(
- "The string is this.", "tThe "));
+ "The string is this.", "tThe ", 0));
CHECK_TRUE(simple_archiver_helper_string_ends(
- "The string is this.", " this."));
+ "The string is this.", " this.", 0));
CHECK_FALSE(simple_archiver_helper_string_ends(
- "The string is this.", " this"));
+ "The string is this.", " this", 0));
+
+
+ CHECK_TRUE(simple_archiver_helper_string_contains(
+ "The String Is This.", "sTRING", 1));
+ CHECK_TRUE(simple_archiver_helper_string_starts(
+ "The String Is This.", "tHE", 1));
+ CHECK_TRUE(simple_archiver_helper_string_ends(
+ "The String Is This.", "tHIS.", 1));
}
printf("Checks checked: %" PRId32 "\n", checks_checked);