Conversion between different character encodings. More...
#include "config.h"#include <errno.h>#include <iconv.h>#include <stdbool.h>#include <stdio.h>#include <string.h>#include "mutt/lib.h"#include "email/lib.h"#include "lib.h"
Include dependency graph for convert.c:Go to the source code of this file.
Functions | |
| size_t | mutt_convert_file_to (FILE *fp, const char *fromcode, struct Slist const *const tocodes, int *tocode, struct Content *info) |
| Change the encoding of a file. | |
| size_t | mutt_convert_file_from_to (FILE *fp, const struct Slist *fromcodes, const struct Slist *tocodes, char **fromcode, char **tocode, struct Content *info) |
| Convert a file between encodings. | |
Conversion between different character encodings.
This program 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 details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file convert.c.
| size_t mutt_convert_file_to | ( | FILE * | fp, |
| const char * | fromcode, | ||
| struct Slist const *const | tocodes, | ||
| int * | tocode, | ||
| struct Content * | info ) |
Change the encoding of a file.
| [in] | fp | File to convert |
| [in] | fromcode | Original encoding |
| [in] | tocodes | List of target encodings |
| [out] | tocode | Chosen encoding |
| [out] | info | Encoding information |
| -1 | Error, no conversion was possible |
| >0 | Success, number of bytes converted |
Find the best charset conversion of the file from fromcode into one of the tocodes. If successful, set *tocode and Content *info and return the number of characters converted inexactly.
We convert via UTF-8 in order to avoid the condition -1(EINVAL), which would otherwise prevent us from knowing the number of inexact conversions. Where the candidate target charset is UTF-8 we avoid doing the second conversion because iconv_open("UTF-8", "UTF-8") fails with some libraries.
We assume that the output from iconv is never more than 4 times as long as the input for any pair of charsets we might be interested in.
Definition at line 64 of file convert.c.
Here is the call graph for this function:
Here is the caller graph for this function:| size_t mutt_convert_file_from_to | ( | FILE * | fp, |
| const struct Slist * | fromcodes, | ||
| const struct Slist * | tocodes, | ||
| char ** | fromcode, | ||
| char ** | tocode, | ||
| struct Content * | info ) |
Convert a file between encodings.
| [in] | fp | File to read from |
| [in] | fromcodes | Charsets to try converting FROM |
| [in] | tocodes | Charsets to try converting TO |
| [out] | fromcode | From charset selected |
| [out] | tocode | To charset selected |
| [out] | info | Info about the file |
| num | Characters converted |
| ICONV_ILLEGAL_SEQ | Error (as a size_t) |
Find the first of the fromcodes that gives a valid conversion and the best charset conversion of the file into one of the tocodes. If successful, set *fromcode and *tocode to dynamically allocated strings, set Content *info, and return the number of characters converted inexactly. If no conversion was possible, return -1.
Definition at line 215 of file convert.c.
Here is the call graph for this function:
Here is the caller graph for this function: