]> wimlib.net Git - wimlib/commitdiff
Remove quotes in do_load_text_file()
authorEric Biggers <ebiggers3@gmail.com>
Thu, 24 Apr 2014 05:57:49 +0000 (00:57 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Thu, 24 Apr 2014 05:57:49 +0000 (00:57 -0500)
include/wimlib/textfile.h
src/capture_common.c
src/textfile.c

index 4c4d12279208d6acc5687c079b67a1179a88b2b2..bc2068ff418b3b5f5cd03047b7808a34b72f405e 100644 (file)
@@ -23,10 +23,13 @@ struct text_file_section {
        struct string_set *strings;
 };
 
        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,
 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,
 
 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,
               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
 }
 
 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,
                 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_ */
 }
 
 #endif /* _WIMLIB_TEXTFILE_H_ */
index 62ab15b11eef476b6cbf31c6c776d369c61f4e1a..35aaee69a789724584b6d5f1cc8e55eca4e3e1bf 100644 (file)
@@ -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)
 {
 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(':'))
        {
        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,
        };
 
        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;
 
        if (ret)
                return ret;
 
index 8e1bb6cc3383c4fd894f6aee39c74b4c040cca9a..c42a1724e427c2d7e77a1bc920689e52003357e1 100644 (file)
@@ -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,
 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;
 {
        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;
                }
 
                        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)
                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.
  *     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.
  *
  * @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,
                  tchar **buf_ret,
                  const struct text_file_section *pos_sections,
                  int num_pos_sections,
+                 int flags,
                  line_mangle_t mangle_line)
 {
        int ret;
                  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,
        }
 
        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);
        if (ret) {
                for (int i = 0; i < num_pos_sections; i++)
                        FREE(pos_sections[i].strings->strings);