aboutsummaryrefslogtreecommitdiff
path: root/lib/fstree
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-17 10:53:22 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-17 11:05:42 +0200
commit1f980897f6947dd17eaa0190b2c1a23fb700636b (patch)
treecc46ed7f514323b9bd7bfb2f633dc4d17b99c091 /lib/fstree
parente3ef871d6a80d72db02c9ab1ef492e8f58c2ddeb (diff)
fstree: add support for spaces in filenames
This commit adds a mechanism to fstree_from_file to support filenames with spaces in them by quoting the entire string. Quote marks can still be used inside file names by escaping them with a backslash. Back slashes (if that is your thing) can also be escaped. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree')
-rw-r--r--lib/fstree/fstree_from_file.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/lib/fstree/fstree_from_file.c b/lib/fstree/fstree_from_file.c
index 13328d5..901e431 100644
--- a/lib/fstree/fstree_from_file.c
+++ b/lib/fstree/fstree_from_file.c
@@ -113,7 +113,7 @@ static int handle_line(fstree_t *fs, const char *filename,
size_t line_num, char *line)
{
const char *extra = NULL, *msg = NULL;
- char keyword[16], *path;
+ char keyword[16], *path, *ptr;
unsigned int x;
struct stat sb;
size_t i;
@@ -136,17 +136,35 @@ static int handle_line(fstree_t *fs, const char *filename,
/* isolate path */
path = line + i;
- for (; line[i] != '\0'; ++i) {
- /* TODO: escape sequences to support spaces in path */
+ if (*path == '"') {
+ ptr = path;
+ ++i;
- if (isspace(line[i]))
- break;
- }
+ while (line[i] != '\0' && line[i] != '"') {
+ if (line[i] == '\\' &&
+ (line[i + 1] == '"' || line[i + 1] == '\\')) {
+ *(ptr++) = line[i + 1];
+ i += 2;
+ } else {
+ *(ptr++) = line[i++];
+ }
+ }
- if (!isspace(line[i]))
- goto fail_ent;
+ if (line[i] != '"' || !isspace(line[i + 1]))
+ goto fail_ent;
+
+ *ptr = '\0';
+ ++i;
+ } else {
+ while (line[i] != '\0' && !isspace(line[i]))
+ ++i;
+
+ if (!isspace(line[i]))
+ goto fail_ent;
+
+ line[i++] = '\0';
+ }
- line[i++] = '\0';
while (isspace(line[i]))
++i;