X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Ftextfile.c;h=9bd9b6a770f1d846ce4cdeac3c7b9d131ddba74a;hp=a2b630a7a0d09a0cbd6ab4f77a6770b32e092933;hb=d31b2fee211b1c31420bafe1c2379f6f89bd92fe;hpb=0e8a218c22b3c5d42ccc368b3b45d270f942cfde diff --git a/src/textfile.c b/src/textfile.c index a2b630a7..9bd9b6a7 100644 --- a/src/textfile.c +++ b/src/textfile.c @@ -5,33 +5,24 @@ /* * Copyright (C) 2014 Eric Biggers * - * This file is part of wimlib, a library for working with WIM files. + * This file is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. * - * wimlib is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) - * any later version. - * - * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more + * This file is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * - * You should have received a copy of the GNU General Public License - * along with wimlib; if not, see http://www.gnu.org/licenses/. + * You should have received a copy of the GNU Lesser General Public License + * along with this file; if not, see http://www.gnu.org/licenses/. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include "wimlib/assert.h" -#include "wimlib/encoding.h" -#include "wimlib/error.h" -#include "wimlib/file_io.h" -#include "wimlib/textfile.h" -#include "wimlib/util.h" - #include #include #include @@ -39,6 +30,12 @@ #include #include +#include "wimlib/encoding.h" +#include "wimlib/error.h" +#include "wimlib/file_io.h" +#include "wimlib/textfile.h" +#include "wimlib/util.h" + static int read_file_contents(const tchar *path, void **buf_ret, size_t *bufsize_ret) { @@ -131,22 +128,9 @@ translate_text_buffer(const u8 *buf_raw, size_t bufsize_raw, bufsize_raw - offset_raw, &buf_tstr, &bufsize_tstr); } else { - #if TCHAR_IS_UTF16LE - bufsize_tstr = bufsize_raw - offset_raw; - buf_tstr = MALLOC(bufsize_tstr + 2); - if (buf_tstr) { - memcpy(buf_tstr, buf_raw + offset_raw, bufsize_tstr); - ((u8*)buf_tstr)[bufsize_tstr + 0] = 0; - ((u8*)buf_tstr)[bufsize_tstr + 1] = 0; - ret = 0; - } else { - ret = WIMLIB_ERR_NOMEM; - } - #else ret = utf16le_to_tstr((const utf16lechar *)(buf_raw + offset_raw), bufsize_raw - offset_raw, &buf_tstr, &bufsize_tstr); - #endif } if (ret) return ret; @@ -298,29 +282,30 @@ parse_text_file(const tchar *path, tchar *buf, size_t buflen, * Path to the file on disk to read, or a dummy name for the buffer. * @buf * If NULL, the data will be read from the @path file. Otherwise the data - * will be read from this buffer, which must be newline-terminated. - * @buflen + * will be read from this buffer. + * @bufsize * Length of buffer in bytes; ignored if @buf is NULL. - * @buf_ret + * @mem_ret * On success, a pointer to a buffer backing the parsed lines is stored - * here. If @buf is not NULL, this will be @buf. Otherwise, this will be - * an allocated buffer that must be freed when finished with the lines. + * here. This must be freed after the parsed lines are done being used. * @pos_sections * Specifications of allowed sections in the file. Each such specification * consists of the name of the section (e.g. [ExclusionList], like in the * INI file format), along with a pointer to the list of lines parsed for * that section. Use an empty name to indicate the destination of lines - * not in any section. + * not in any section. Each list must be initialized to an empty string + * set. * @num_pos_sections - * Length of @pos_sections array. + * Number of entries in the @pos_sections array. * @flags - * LOAD_TEXT_FILE_REMOVE_QUOTES or 0. + * Flags: LOAD_TEXT_FILE_REMOVE_QUOTES, LOAD_TEXT_FILE_NO_WARNINGS. * @mangle_line - * Optional callback to modify each line being read. + * Optional callback to validate and/or modify each line being read. * - * Returns 0 on success or a positive error code on failure. + * Returns 0 on success; nonzero on failure. * - * Unknown sections are ignored (warning printed). + * Unknown sections are ignored, but a warning is printed for each, unless + * LOAD_TEXT_FILE_NO_WARNINGS is specified. */ int do_load_text_file(const tchar *path,