From 0230cefb4cee3580a705364232feb72258994237 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Thu, 24 Apr 2014 00:57:49 -0500 Subject: [PATCH] Remove quotes in do_load_text_file() --- include/wimlib/textfile.h | 11 ++++++++--- src/capture_common.c | 13 ++----------- src/textfile.c | 20 ++++++++++++++++++-- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/include/wimlib/textfile.h b/include/wimlib/textfile.h index 4c4d1227..bc2068ff 100644 --- a/include/wimlib/textfile.h +++ b/include/wimlib/textfile.h @@ -23,10 +23,13 @@ struct text_file_section { struct string_set *strings; }; +#define LOAD_TEXT_FILE_REMOVE_QUOTES 0x00000001 + extern int do_load_text_file(const tchar *path, tchar *buf, size_t buflen, tchar **buf_ret, const struct text_file_section *pos_sections, - int num_pos_sections, line_mangle_t mangle_line); + int num_pos_sections, int flags, + line_mangle_t mangle_line); static inline int load_text_file(const tchar *path, tchar **buf_ret, @@ -34,7 +37,8 @@ load_text_file(const tchar *path, tchar **buf_ret, int num_pos_sections, line_mangle_t mangle_line) { return do_load_text_file(path, NULL, 0, buf_ret, - pos_sections, num_pos_sections, mangle_line); + pos_sections, num_pos_sections, + LOAD_TEXT_FILE_REMOVE_QUOTES, mangle_line); } static inline int @@ -43,7 +47,8 @@ load_text_buffer(tchar *buf, size_t buflen, int num_pos_sections, line_mangle_t mangle_line) { return do_load_text_file(NULL, buf, buflen, &buf, - pos_sections, num_pos_sections, mangle_line); + pos_sections, num_pos_sections, + LOAD_TEXT_FILE_REMOVE_QUOTES, mangle_line); } #endif /* _WIMLIB_TEXTFILE_H_ */ diff --git a/src/capture_common.c b/src/capture_common.c index 62ab15b1..35aaee69 100644 --- a/src/capture_common.c +++ b/src/capture_common.c @@ -72,16 +72,6 @@ do_capture_progress(struct add_image_params *params, int status, static int mangle_pat(tchar *pat, const tchar *path, unsigned long line_no) { - /* Remove quotes */ - if (pat[0] == T('"') || pat[0] == T('\'')) { - tchar quote = pat[0]; - tchar *last = pat + tstrlen(pat) - 1; - if (last > pat && *last == quote) { - tmemmove(pat, pat + 1, last - (pat + 1)); - *(last - 1) = T('\0'); - } - } - if (!is_any_path_separator(pat[0]) && pat[0] != T('\0') && pat[1] == T(':')) { @@ -127,7 +117,8 @@ do_read_capture_config_file(const tchar *config_file, tchar *buf, size_t buflen, }; ret = do_load_text_file(config_file, buf, buflen, &buf, - sections, ARRAY_LEN(sections), mangle_pat); + sections, ARRAY_LEN(sections), + LOAD_TEXT_FILE_REMOVE_QUOTES, mangle_pat); if (ret) return ret; diff --git a/src/textfile.c b/src/textfile.c index 8e1bb6cc..c42a1724 100644 --- a/src/textfile.c +++ b/src/textfile.c @@ -189,7 +189,7 @@ string_set_append(struct string_set *set, tchar *str) static int parse_text_file(const tchar *path, tchar *buf, size_t buflen, const struct text_file_section *pos_sections, - int num_pos_sections, line_mangle_t mangle_line) + int num_pos_sections, int flags, line_mangle_t mangle_line) { int current_section = NOT_IN_SECTION; bool have_named_sections = false; @@ -261,6 +261,19 @@ parse_text_file(const tchar *path, tchar *buf, size_t buflen, continue; } + if (flags & LOAD_TEXT_FILE_REMOVE_QUOTES) { + if (line_begin[0] == T('"') || line_begin[0] == T('\'')) { + tchar quote = line_begin[0]; + if (line_len >= 2 && + line_begin[line_len - 1] == quote) + { + line_begin++; + line_len -= 2; + line_begin[line_len] = T('\0'); + } + } + } + if (mangle_line) { ret = (*mangle_line)(line_begin, path, line_no); if (ret) @@ -300,6 +313,8 @@ parse_text_file(const tchar *path, tchar *buf, size_t buflen, * not in any section. * @num_pos_sections * Length of @pos_sections array. + * @flags + * LOAD_TEXT_FILE_REMOVE_QUOTES or 0. * @mangle_line * Optional callback to modify each line being read. * @@ -313,6 +328,7 @@ do_load_text_file(const tchar *path, tchar **buf_ret, const struct text_file_section *pos_sections, int num_pos_sections, + int flags, line_mangle_t mangle_line) { int ret; @@ -331,7 +347,7 @@ do_load_text_file(const tchar *path, } ret = parse_text_file(path, buf, buflen, pos_sections, - num_pos_sections, mangle_line); + num_pos_sections, flags, mangle_line); if (ret) { for (int i = 0; i < num_pos_sections; i++) FREE(pos_sections[i].strings->strings); -- 2.43.0