diff options
author | plougher <plougher> | 2010-09-16 02:06:58 +0000 |
---|---|---|
committer | plougher <plougher> | 2010-09-16 02:06:58 +0000 |
commit | d0a8f2507c4e6ddad7ac16077f77129fe6421a8e (patch) | |
tree | 48377b547d117d3642c8f94c4cfe2d9e83c99dfd /squashfs-tools/pseudo.c | |
parent | db1c89e84f150823af525c3584f1964e4b0232b7 (diff) | |
download | squashfs-tools-d0a8f2507c4e6ddad7ac16077f77129fe6421a8e.tar.gz |
Pseudo files: allow the command to be split across multiple lines using '\'
Diffstat (limited to 'squashfs-tools/pseudo.c')
-rw-r--r-- | squashfs-tools/pseudo.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/squashfs-tools/pseudo.c b/squashfs-tools/pseudo.c index e8da6d7..6ddc839 100644 --- a/squashfs-tools/pseudo.c +++ b/squashfs-tools/pseudo.c @@ -468,10 +468,14 @@ error: } + +#define MAX_LINE 2048 + int read_pseudo_file(struct pseudo **pseudo, char *filename) { FILE *fd; - char line[2048]; + char *line = NULL; + int size = 0; int res = TRUE; fd = fopen(filename, "r"); @@ -480,13 +484,41 @@ int read_pseudo_file(struct pseudo **pseudo, char *filename) filename, strerror(errno)); return FALSE; } - while(fscanf(fd, "%2047[^\n]\n", line) > 0) { - if (line[0] == '#') - continue; + + while(1) { + int total = 0; + + while(1) { + int n, err; + + if(total + MAX_LINE > size) { + line = realloc(line, size += MAX_LINE); + if(line == NULL) { + ERROR("No space in read_pseudo_file\n"); + return FALSE; + } + } + + err = fscanf(fd, "%2047[^\n]%n\n", line + total, &n); + if(err <= 0) + goto done; + + if(line[total] == '#') + continue; + + if(line[total + n - 1] != '\\') + break; + + total += n - 1; + } + res = read_pseudo_def(pseudo, line); if(res == FALSE) break; - }; + } + +done: fclose(fd); + free(line); return res; } |