version 1.1.1.1, 2012/02/21 22:57:48
|
version 1.1.1.3, 2021/03/17 13:38:46
|
Line 1
|
Line 1
|
/* Copyright (C) 2000-2009 Free Software Foundation, Inc. | /* Copyright (C) 2000-2009, 2011-2012, 2016-2019 Free Software Foundation, Inc. |
This file is part of the GNU LIBICONV Library. |
This file is part of the GNU LIBICONV Library. |
|
|
This program is free software: you can redistribute it and/or modify |
This program is free software: you can redistribute it and/or modify |
Line 12
|
Line 12
|
GNU General Public License for more details. |
GNU General Public License for more details. |
|
|
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
along with this program. If not, see <http://www.gnu.org/licenses/>. */ | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
|
|
#include "config.h" |
#include "config.h" |
#ifndef ICONV_CONST |
#ifndef ICONV_CONST |
Line 38
|
Line 38
|
#include "binary-io.h" |
#include "binary-io.h" |
#include "progname.h" |
#include "progname.h" |
#include "relocatable.h" |
#include "relocatable.h" |
|
#include "safe-read.h" |
#include "xalloc.h" |
#include "xalloc.h" |
#include "uniwidth.h" |
#include "uniwidth.h" |
#include "uniwidth/cjk.h" |
#include "uniwidth/cjk.h" |
Line 106 static void usage (int exitcode)
|
Line 107 static void usage (int exitcode)
|
Align it correctly against the first line. */ |
Align it correctly against the first line. */ |
_("or: iconv -l"); |
_("or: iconv -l"); |
fprintf(stderr, "%s\n%s\n", helpstring1, helpstring2); |
fprintf(stderr, "%s\n%s\n", helpstring1, helpstring2); |
fprintf(stderr, _("Try `%s --help' for more information.\n"), program_name); | fprintf(stderr, _("Try '%s --help' for more information.\n"), program_name); |
} else { |
} else { |
/* xgettext: no-wrap */ |
/* xgettext: no-wrap */ |
/* TRANSLATORS: The first line of the long usage message. |
/* TRANSLATORS: The first line of the long usage message. |
Line 190 static void print_version (void)
|
Line 191 static void print_version (void)
|
{ |
{ |
printf("iconv (GNU libiconv %d.%d)\n", |
printf("iconv (GNU libiconv %d.%d)\n", |
_libiconv_version >> 8, _libiconv_version & 0xff); |
_libiconv_version >> 8, _libiconv_version & 0xff); |
printf("Copyright (C) %s Free Software Foundation, Inc.\n", "2000-2009"); | printf("Copyright (C) %s Free Software Foundation, Inc.\n", "2000-2019"); |
/* xgettext: no-wrap */ |
/* xgettext: no-wrap */ |
fputs (_("\ |
fputs (_("\ |
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\ | License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>\n\ |
This is free software: you are free to change and redistribute it.\n\ |
This is free software: you are free to change and redistribute it.\n\ |
There is NO WARRANTY, to the extent permitted by law.\n\ |
There is NO WARRANTY, to the extent permitted by law.\n\ |
"),stdout); |
"),stdout); |
Line 667 static void conversion_error_other (int errnum, const
|
Line 668 static void conversion_error_other (int errnum, const
|
|
|
/* Convert the input given in infile. */ |
/* Convert the input given in infile. */ |
|
|
static int convert (iconv_t cd, FILE* infile, const char* infilename) | static int convert (iconv_t cd, int infile, const char* infilename) |
{ |
{ |
char inbuf[4096+4096]; |
char inbuf[4096+4096]; |
size_t inbufrest = 0; |
size_t inbufrest = 0; |
|
int infile_error = 0; |
char initial_outbuf[4096]; |
char initial_outbuf[4096]; |
char *outbuf = initial_outbuf; |
char *outbuf = initial_outbuf; |
size_t outbufsize = sizeof(initial_outbuf); |
size_t outbufsize = sizeof(initial_outbuf); |
int status = 0; |
int status = 0; |
|
|
#if O_BINARY |
#if O_BINARY |
SET_BINARY(fileno(infile)); | SET_BINARY(infile); |
#endif |
#endif |
line = 1; column = 0; |
line = 1; column = 0; |
iconv(cd,NULL,NULL,NULL,NULL); |
iconv(cd,NULL,NULL,NULL,NULL); |
for (;;) { |
for (;;) { |
size_t inbufsize = fread(inbuf+4096,1,4096,infile); | size_t inbufsize; |
if (inbufsize == 0) { | /* Transfer the accumulated output to its destination, in case the |
| safe_read() call will block. */ |
| fflush(stdout); |
| inbufsize = safe_read(infile,inbuf+4096,4096); |
| if (inbufsize == 0 || inbufsize == SAFE_READ_ERROR) { |
| infile_error = (inbufsize == SAFE_READ_ERROR ? errno : 0); |
if (inbufrest == 0) |
if (inbufrest == 0) |
break; |
break; |
else { |
else { |
Line 809 static int convert (iconv_t cd, FILE* infile, const ch
|
Line 816 static int convert (iconv_t cd, FILE* infile, const ch
|
} else |
} else |
break; |
break; |
} |
} |
if (ferror(infile)) { | if (infile_error) { |
fflush(stdout); |
fflush(stdout); |
if (column > 0) |
if (column > 0) |
putc('\n',stderr); |
putc('\n',stderr); |
error(0,0, | error(0,infile_error, |
/* TRANSLATORS: An error message. |
/* TRANSLATORS: An error message. |
The placeholder expands to the input file name. */ |
The placeholder expands to the input file name. */ |
_("%s: I/O error"), |
_("%s: I/O error"), |
Line 854 int main (int argc, char* argv[])
|
Line 861 int main (int argc, char* argv[])
|
bindtextdomain("libiconv",relocate(LOCALEDIR)); |
bindtextdomain("libiconv",relocate(LOCALEDIR)); |
#endif |
#endif |
textdomain("libiconv"); |
textdomain("libiconv"); |
|
/* No need to invoke the gnulib function stdopen() here, because |
|
(1) the only file descriptor allocations done by this program are |
|
fopen(...,"r"), |
|
(2) when such fopen() calls occur, stdin is not used, |
|
hence |
|
- when an fopen() call happens to open fd 0, it is harmless, by (2), |
|
- when an fopen() call happens to open fd 1 or 2, writing to |
|
stdout or stderr will produce an error, by (1). */ |
|
|
for (i = 1; i < argc;) { |
for (i = 1; i < argc;) { |
size_t len = strlen(argv[i]); |
size_t len = strlen(argv[i]); |
if (!strcmp(argv[i],"--")) { |
if (!strcmp(argv[i],"--")) { |
Line 952 int main (int argc, char* argv[])
|
Line 968 int main (int argc, char* argv[])
|
if /* --s ... --silent */ |
if /* --s ... --silent */ |
(len >= 3 && len <= 8 && !strncmp(argv[i],"--silent",len)) { |
(len >= 3 && len <= 8 && !strncmp(argv[i],"--silent",len)) { |
silent = 1; |
silent = 1; |
|
i++; |
continue; |
continue; |
} |
} |
if /* --h ... --help */ |
if /* --h ... --help */ |
Line 1076 int main (int argc, char* argv[])
|
Line 1093 int main (int argc, char* argv[])
|
hooks.data = NULL; |
hooks.data = NULL; |
iconvctl(cd, ICONV_SET_HOOKS, &hooks); |
iconvctl(cd, ICONV_SET_HOOKS, &hooks); |
if (i == argc) |
if (i == argc) |
status = convert(cd,stdin, | status = convert(cd,fileno(stdin), |
/* TRANSLATORS: A filename substitute denoting standard input. */ |
/* TRANSLATORS: A filename substitute denoting standard input. */ |
_("(stdin)")); |
_("(stdin)")); |
else { |
else { |
Line 1094 int main (int argc, char* argv[])
|
Line 1111 int main (int argc, char* argv[])
|
infilename); |
infilename); |
status = 1; |
status = 1; |
} else { |
} else { |
status |= convert(cd,infile,infilename); | status |= convert(cd,fileno(infile),infilename); |
fclose(infile); |
fclose(infile); |
} |
} |
} |
} |