summaryrefslogtreecommitdiff
path: root/common.c
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2019-01-10 14:08:23 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2019-01-10 14:36:56 +0900
commit3e04d82fa8da3f9c3077d4d06b334cdc2c947a61 (patch)
tree8682677660f63cc17352be86698a04f2e5d7ca95 /common.c
parenta43ffe7b214336b5ff551c8965d6fd16c63b13ed (diff)
downloaddos2unix-upstream/7.4.0.tar.gz
dos2unix-upstream/7.4.0.tar.bz2
dos2unix-upstream/7.4.0.zip
Imported Upstream version 7.4.0upstream/7.4.0
Change-Id: I567718db10506669896b057a505586ec6e1d18d7 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'common.c')
-rw-r--r--common.c284
1 files changed, 135 insertions, 149 deletions
diff --git a/common.c b/common.c
index e43e4bb..d76c128 100644
--- a/common.c
+++ b/common.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2016 Erwin Waterlander
+ * Copyright (C) 2009-2017 Erwin Waterlander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,6 @@
#ifdef D2U_UNIFILE
int d2u_display_encoding = D2U_DISPLAY_ANSI ;
#endif
-int header_done = 0;
/* Copy string src to dest, and null terminate dest.
dest_size must be the buffer size of dest. */
@@ -645,6 +644,9 @@ int is_dos2unix(const char *progname)
void PrintUsage(const char *progname)
{
D2U_ANSI_FPRINTF(stdout,_("Usage: %s [options] [file ...] [-n infile outfile ...]\n"), progname);
+#ifndef NO_CHOWN
+ D2U_ANSI_FPRINTF(stdout,_(" --allow-chown allow file ownership change\n"));
+#endif
D2U_ANSI_FPRINTF(stdout,_(" -ascii convert only line breaks (default)\n"));
D2U_ANSI_FPRINTF(stdout,_(" -iso conversion between DOS and ISO-8859-1 character set\n"));
D2U_ANSI_FPRINTF(stdout,_(" -1252 use Windows code page 1252 (Western European)\n"));
@@ -680,6 +682,9 @@ void PrintUsage(const char *progname)
D2U_ANSI_FPRINTF(stdout,_(" -n, --newfile write to new file\n\
infile original file in new-file mode\n\
outfile output file in new-file mode\n"));
+#ifndef NO_CHOWN
+ D2U_ANSI_FPRINTF(stdout,_(" --no-allow-chown don't allow file ownership change (default)\n"));
+#endif
D2U_ANSI_FPRINTF(stdout,_(" -o, --oldfile write to old file (default)\n\
file ... files to convert in old-file mode\n"));
D2U_ANSI_FPRINTF(stdout,_(" -q, --quiet quiet mode, suppress all warnings\n"));
@@ -764,6 +769,11 @@ void PrintVersion(const char *progname, const char *localedir)
#else
D2U_ANSI_FPRINTF(stdout,"%s", "Without native language support.\n");
#endif
+#ifndef NO_CHOWN
+ D2U_ANSI_FPRINTF(stdout,"%s", _("With support to preserve the user and group ownership of files.\n"));
+#else
+ D2U_ANSI_FPRINTF(stdout,"%s", _("Without support to preserve the user and group ownership of files.\n"));
+#endif
#ifdef ENABLE_NLS
D2U_ANSI_FPRINTF(stdout,"LOCALEDIR: %s\n", localedir);
#endif
@@ -771,8 +781,8 @@ void PrintVersion(const char *progname, const char *localedir)
}
/* opens file of name ipFN in read only mode
- * RetVal: NULL if failure
- * file stream otherwise
+ * returns: NULL if failure
+ * file stream otherwise
*/
FILE* OpenInFile(char *ipFN)
{
@@ -788,8 +798,8 @@ FILE* OpenInFile(char *ipFN)
/* opens file of name opFN in write only mode
- * RetVal: NULL if failure
- * file stream otherwise
+ * returns: NULL if failure
+ * file stream otherwise
*/
FILE* OpenOutFile(char *opFN)
{
@@ -804,8 +814,8 @@ FILE* OpenOutFile(char *opFN)
}
/* opens file descriptor in write only mode
- * RetVal: NULL if failure
- * file stream otherwise
+ * returns: NULL if failure
+ * file stream otherwise
*/
FILE* OpenOutFiled(int fd)
{
@@ -1004,8 +1014,8 @@ FILE* MakeTempFileFrom(const char *OutFN, char **fname_ret)
* Note that if symbolic links are not supported, then 0 is always returned
* and *rFN = lFN.
*
- * RetVal: 0 if success, and *lFN is not a symlink
- * 1 if success, and *lFN is a symlink
+ * returns: 0 if success, and *lFN is not a symlink
+ * 1 if success, and *lFN is a symlink
* -1 otherwise
*/
int ResolveSymbolicLink(char *lFN, char **rFN, CFlag *ipFlag, const char *progname)
@@ -1290,10 +1300,15 @@ void print_bom_info (const int bomtype)
}
}
+/* check_unicode_info()
+ * Print assumed encoding and read file's BOM. Return file's BOM in *bomtype_orig.
+ * Set ipFlag->bomtype to assumed BOM type, when file's BOM == FILE_MBS.
+ * Return -1 when a read error occurred, or when whar_t < 32 bit on non-Windows OS.
+ * Return 0 when everything is OK.
+ */
+
int check_unicode_info(FILE *InF, CFlag *ipFlag, const char *progname, int *bomtype_orig)
{
- int RetVal = 0;
-
#ifdef D2U_UNICODE
if (ipFlag->verbose > 1) {
if (ipFlag->ConvMode == CONVMODE_UTF16LE) {
@@ -1324,13 +1339,13 @@ int check_unicode_info(FILE *InF, CFlag *ipFlag, const char *progname, int *bomt
/* A decoded UTF-16 surrogate pair must fit in a wchar_t */
ipFlag->status |= WCHAR_T_TOO_SMALL ;
if (!ipFlag->error) ipFlag->error = 1;
- RetVal = -1;
+ return -1;
}
}
#endif
#endif
- return RetVal;
+ return 0;
}
int check_unicode(FILE *InF, FILE *TempF, CFlag *ipFlag, const char *ipInFN, const char *progname)
@@ -1395,7 +1410,7 @@ int check_unicode(FILE *InF, FILE *TempF, CFlag *ipFlag, const char *ipInFN, co
}
/* convert file ipInFN and write to file ipOutFN
- * RetVal: 0 if success
+ * returns: 0 if success
* -1 otherwise
*/
int ConvertNewFile(char *ipInFN, char *ipOutFN, CFlag *ipFlag, const char *progname,
@@ -1509,7 +1524,7 @@ int ConvertNewFile(char *ipInFN, char *ipOutFN, CFlag *ipFlag, const char *progn
if (check_unicode(InF, TempF, ipFlag, ipInFN, progname))
RetVal = -1;
- /* conversion sucessful? */
+ /* conversion successful? */
#ifdef D2U_UNICODE
if ((ipFlag->bomtype == FILE_UTF16LE) || (ipFlag->bomtype == FILE_UTF16BE)) {
if ((!RetVal) && (ConvertW(InF, TempF, ipFlag, progname)))
@@ -1566,14 +1581,36 @@ int ConvertNewFile(char *ipInFN, char *ipOutFN, CFlag *ipFlag, const char *progn
/* Required when a different user (e.g. root) has write permission on the original file. */
/* Make sure that the original owner can still access the file. */
if (chown(TempPath, StatBuf.st_uid, StatBuf.st_gid)) {
- if (ipFlag->verbose) {
- ipFlag->error = errno;
- errstr = strerror(errno);
- D2U_UTF8_FPRINTF(stderr, "%s: ", progname);
- D2U_UTF8_FPRINTF(stderr, _("Failed to change the owner and group of temporary output file %s:"), TempPath);
- D2U_ANSI_FPRINTF(stderr, " %s\n", errstr);
+ if (ipFlag->AllowChown) {
+ if (ipFlag->verbose) {
+ D2U_UTF8_FPRINTF(stderr, "%s: ", progname);
+ D2U_UTF8_FPRINTF(stderr, _("The user and/or group ownership of file %s is not preserved.\n"), ipOutFN);
+ }
+#ifndef NO_CHMOD
+ /* Set read/write permissions same as in new file mode. */
+ mask = umask(0); /* get process's umask */
+ umask(mask); /* set umask back to original */
+ RetVal = chmod(TempPath, StatBuf.st_mode & ~mask); /* set original permissions, minus umask */
+ if (RetVal) {
+ if (ipFlag->verbose) {
+ ipFlag->error = errno;
+ errstr = strerror(errno);
+ D2U_UTF8_FPRINTF(stderr, "%s: ", progname);
+ D2U_UTF8_FPRINTF(stderr, _("Failed to change the permissions of temporary output file %s:"), TempPath);
+ D2U_ANSI_FPRINTF(stderr, " %s\n", errstr);
+ }
+ }
+#endif
+ } else {
+ if (ipFlag->verbose) {
+ ipFlag->error = errno;
+ errstr = strerror(errno);
+ D2U_UTF8_FPRINTF(stderr, "%s: ", progname);
+ D2U_UTF8_FPRINTF(stderr, _("Failed to change the owner and group of temporary output file %s:"), TempPath);
+ D2U_ANSI_FPRINTF(stderr, " %s\n", errstr);
+ }
+ RetVal = -1;
}
- RetVal = -1;
}
}
#endif
@@ -1663,7 +1700,7 @@ int ConvertNewFile(char *ipInFN, char *ipOutFN, CFlag *ipFlag, const char *progn
}
/* convert stdin and write to stdout
- * RetVal: 0 if success
+ * returns: 0 if success
* -1 otherwise
*/
int ConvertStdio(CFlag *ipFlag, const char *progname,
@@ -1766,7 +1803,7 @@ void print_format(const CFlag *pFlag, char *informat, char *outformat, size_t li
#endif
}
-void print_messages_newfile(const CFlag *pFlag, const char *infile, const char *outfile, const char *progname, const int RetVal)
+void print_messages(const CFlag *pFlag, const char *infile, const char *outfile, const char *progname, const int conversion_error)
{
char informat[32];
char outformat[64];
@@ -1794,11 +1831,14 @@ void print_messages_newfile(const CFlag *pFlag, const char *infile, const char *
D2U_UTF8_FPRINTF(stderr, _("Skipping %s, not a regular file.\n"), infile);
} else if (pFlag->status & OUTPUTFILE_SYMLINK) {
D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- D2U_UTF8_FPRINTF(stderr, _("Skipping %s, output file %s is a symbolic link.\n"), infile, outfile);
+ if (outfile)
+ D2U_UTF8_FPRINTF(stderr, _("Skipping %s, output file %s is a symbolic link.\n"), infile, outfile);
+ else
+ D2U_UTF8_FPRINTF(stderr, _("Skipping symbolic link %s.\n"), infile);
} else if (pFlag->status & INPUT_TARGET_NO_REGFILE) {
D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
D2U_UTF8_FPRINTF(stderr, _("Skipping symbolic link %s, target is not a regular file.\n"), infile);
- } else if (pFlag->status & OUTPUT_TARGET_NO_REGFILE) {
+ } else if ((pFlag->status & OUTPUT_TARGET_NO_REGFILE) && outfile) {
D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
D2U_UTF8_FPRINTF(stderr, _("Skipping %s, target of symbolic link %s is not a regular file.\n"), infile, outfile);
} else if (pFlag->status & BINARY_FILE) {
@@ -1820,122 +1860,64 @@ void print_messages_newfile(const CFlag *pFlag, const char *infile, const char *
D2U_UTF8_FPRINTF(stderr, _("Skipping UTF-16 file %s, UTF-16 conversion is not supported in this version of %s.\n"), infile, progname);
#endif
} else {
- D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- if (informat[0] == '\0') {
- if (is_dos2unix(progname)) {
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting file %s to file %s in Unix format...\n"), infile, outfile);
- } else {
- if (pFlag->FromToMode == FROMTO_UNIX2MAC) {
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting file %s to file %s in Mac format...\n"), infile, outfile);
+ if (!conversion_error) {
+ D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
+ if (informat[0] == '\0') {
+ if (is_dos2unix(progname)) {
+ if (outfile)
+ D2U_UTF8_FPRINTF(stderr, _("converting file %s to file %s in Unix format...\n"), infile, outfile);
+ else
+ D2U_UTF8_FPRINTF(stderr, _("converting file %s to Unix format...\n"), infile);
} else {
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting file %s to file %s in DOS format...\n"), infile, outfile);
+ if (pFlag->FromToMode == FROMTO_UNIX2MAC) {
+ if (outfile)
+ D2U_UTF8_FPRINTF(stderr, _("converting file %s to file %s in Mac format...\n"), infile, outfile);
+ else
+ D2U_UTF8_FPRINTF(stderr, _("converting file %s to Mac format...\n"), infile);
+ } else {
+ if (outfile)
+ D2U_UTF8_FPRINTF(stderr, _("converting file %s to file %s in DOS format...\n"), infile, outfile);
+ else
+ D2U_UTF8_FPRINTF(stderr, _("converting file %s to DOS format...\n"), infile);
+ }
}
- }
- } else {
- if (is_dos2unix(progname)) {
+ } else {
+ if (is_dos2unix(progname)) {
+ if (outfile)
/* TRANSLATORS:
1st %s is encoding of input file.
2nd %s is name of input file.
3rd %s is encoding of output file.
4th %s is name of output file.
E.g.: converting UTF-16LE file in.txt to UTF-8 file out.txt in Unix format... */
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s file %s in Unix format...\n"), informat, infile, outformat, outfile);
- } else {
- if (pFlag->FromToMode == FROMTO_UNIX2MAC) {
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s file %s in Mac format...\n"), informat, infile, outformat, outfile);
- } else {
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s file %s in DOS format...\n"), informat, infile, outformat, outfile);
- }
- }
- }
- if (RetVal) {
- D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- D2U_UTF8_FPRINTF(stderr, _("problems converting file %s to file %s\n"), infile, outfile);
- }
- }
-}
-
-void print_messages_oldfile(const CFlag *pFlag, const char *infile, const char *progname, const int RetVal)
-{
- char informat[10];
- char outformat[32];
-# ifdef D2U_UNIFILE
- wchar_t informatw[32];
- wchar_t outformatw[64];
-#endif
-
- print_format(pFlag, informat, outformat, sizeof(informat), sizeof(outformat));
-
-/* Change informat and outformat to UTF-8 for d2u_utf8_fprintf. */
-# ifdef D2U_UNIFILE
- /* The format string is encoded in the system default
- * Windows ANSI code page. May have been translated
- * by gettext. Convert it to wide characters. */
- d2u_MultiByteToWideChar(CP_ACP,0, informat, -1, informatw, sizeof(informat));
- d2u_MultiByteToWideChar(CP_ACP,0, outformat, -1, outformatw, sizeof(outformat));
- /* then convert the format string to UTF-8 */
- d2u_WideCharToMultiByte(CP_UTF8, 0, informatw, -1, informat, sizeof(informat), NULL, NULL);
- d2u_WideCharToMultiByte(CP_UTF8, 0, outformatw, -1, outformat, sizeof(outformat), NULL, NULL);
-#endif
-
- if (pFlag->status & NO_REGFILE) {
- D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- D2U_UTF8_FPRINTF(stderr, _("Skipping %s, not a regular file.\n"), infile);
- } else if (pFlag->status & OUTPUTFILE_SYMLINK) {
- D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- D2U_UTF8_FPRINTF(stderr, _("Skipping symbolic link %s.\n"), infile);
- } else if (pFlag->status & INPUT_TARGET_NO_REGFILE) {
- D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- D2U_UTF8_FPRINTF(stderr, _("Skipping symbolic link %s, target is not a regular file.\n"), infile);
- } else if (pFlag->status & BINARY_FILE) {
- D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- D2U_UTF8_FPRINTF(stderr, _("Skipping binary file %s\n"), infile);
- } else if (pFlag->status & WRONG_CODEPAGE) {
- D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- D2U_UTF8_FPRINTF(stderr, _("code page %d is not supported.\n"), pFlag->ConvMode);
-#ifdef D2U_UNICODE
- } else if (pFlag->status & WCHAR_T_TOO_SMALL) {
- D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- D2U_UTF8_FPRINTF(stderr, _("Skipping UTF-16 file %s, the size of wchar_t is %d bytes.\n"), infile, (int)sizeof(wchar_t));
- } else if (pFlag->status & UNICODE_CONVERSION_ERROR) {
- D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- D2U_UTF8_FPRINTF(stderr, _("Skipping UTF-16 file %s, an UTF-16 conversion error occurred on line %u.\n"), infile, pFlag->line_nr);
-#else
- } else if (pFlag->status & UNICODE_NOT_SUPPORTED) {
- D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- D2U_UTF8_FPRINTF(stderr, _("Skipping UTF-16 file %s, UTF-16 conversion is not supported in this version of %s.\n"), infile, progname);
-#endif
- } else {
- D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- if (informat[0] == '\0') {
- if (is_dos2unix(progname)) {
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting file %s to Unix format...\n"), infile);
- } else {
- if (pFlag->FromToMode == FROMTO_UNIX2MAC) {
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting file %s to Mac format...\n"), infile);
- } else {
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting file %s to DOS format...\n"), infile);
- }
- }
- } else {
- if (is_dos2unix(progname)) {
+ D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s file %s in Unix format...\n"), informat, infile, outformat, outfile);
+ else
/* TRANSLATORS:
1st %s is encoding of input file.
2nd %s is name of input file.
3rd %s is encoding of output (input file is overwritten).
E.g.: converting UTF-16LE file foo.txt to UTF-8 Unix format... */
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s Unix format...\n"), informat, infile, outformat);
- } else {
- if (pFlag->FromToMode == FROMTO_UNIX2MAC) {
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s Mac format...\n"), informat, infile, outformat);
+ D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s Unix format...\n"), informat, infile, outformat);
} else {
- if (!RetVal) D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s DOS format...\n"), informat, infile, outformat);
+ if (pFlag->FromToMode == FROMTO_UNIX2MAC) {
+ if (outfile)
+ D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s file %s in Mac format...\n"), informat, infile, outformat, outfile);
+ else
+ D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s Mac format...\n"), informat, infile, outformat);
+ } else {
+ if (outfile)
+ D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s file %s in DOS format...\n"), informat, infile, outformat, outfile);
+ else
+ D2U_UTF8_FPRINTF(stderr, _("converting %s file %s to %s DOS format...\n"), informat, infile, outformat);
+ }
}
}
- }
- if (RetVal) {
+ } else {
D2U_UTF8_FPRINTF(stderr,"%s: ",progname);
- D2U_UTF8_FPRINTF(stderr, _("problems converting file %s\n"), infile);
+ if (outfile)
+ D2U_UTF8_FPRINTF(stderr, _("problems converting file %s to file %s\n"), infile, outfile);
+ else
+ D2U_UTF8_FPRINTF(stderr, _("problems converting file %s\n"), infile);
}
}
}
@@ -1964,6 +1946,8 @@ void print_messages_info(const CFlag *pFlag, const char *infile, const char *pro
void printInfo(CFlag *ipFlag, const char *filename, int bomtype, unsigned int lb_dos, unsigned int lb_unix, unsigned int lb_mac)
{
+ static int header_done = 0;
+
if (ipFlag->file_info & INFO_CONVERT) {
if ((ipFlag->FromToMode == FROMTO_DOS2UNIX) && (lb_dos == 0))
return;
@@ -2167,7 +2151,7 @@ int GetFileInfo(char *ipInFN, CFlag *ipFlag, const char *progname)
return -1;
}
- /* info sucessful? */
+ /* info successful? */
#ifdef D2U_UNICODE
if ((ipFlag->bomtype == FILE_UTF16LE) || (ipFlag->bomtype == FILE_UTF16BE)) {
FileInfoW(InF, ipFlag, ipInFN, bomtype_orig, progname);
@@ -2187,7 +2171,6 @@ int GetFileInfo(char *ipInFN, CFlag *ipFlag, const char *progname)
int GetFileInfoStdio(CFlag *ipFlag, const char *progname)
{
- int RetVal = 0;
int bomtype_orig = FILE_MBS; /* messages must print the real bomtype, not the assumed bomtype */
ipFlag->status = 0 ;
@@ -2208,23 +2191,20 @@ int GetFileInfoStdio(CFlag *ipFlag, const char *progname)
#endif
if (check_unicode_info(stdin, ipFlag, progname, &bomtype_orig))
- RetVal = -1;
+ return -1;
- /* info sucessful? */
+ /* info successful? */
#ifdef D2U_UNICODE
- if (!RetVal) {
- if ((ipFlag->bomtype == FILE_UTF16LE) || (ipFlag->bomtype == FILE_UTF16BE)) {
- FileInfoW(stdin, ipFlag, "", bomtype_orig, progname);
- } else {
- FileInfo(stdin, ipFlag, "", bomtype_orig, progname);
- }
+ if ((ipFlag->bomtype == FILE_UTF16LE) || (ipFlag->bomtype == FILE_UTF16BE)) {
+ FileInfoW(stdin, ipFlag, "", bomtype_orig, progname);
+ } else {
+ FileInfo(stdin, ipFlag, "", bomtype_orig, progname);
}
#else
- if (!RetVal)
- FileInfo(stdin, ipFlag, "", bomtype_orig, progname);
+ FileInfo(stdin, ipFlag, "", bomtype_orig, progname);
#endif
- return RetVal;
+ return 0;
}
void get_info_options(char *option, CFlag *pFlag, const char *progname)
@@ -2301,7 +2281,6 @@ int parse_options(int argc, char *argv[],
int ShouldExit = 0;
int CanSwitchFileMode = 1;
int process_options = 1;
- int RetVal = 0;
#ifdef D2U_UNIFILE
char *ptr;
#endif
@@ -2358,6 +2337,12 @@ int parse_options(int argc, char *argv[],
pFlag->KeepDate = 1;
else if ((strcmp(argv[ArgIdx],"-f") == 0) || (strcmp(argv[ArgIdx],"--force") == 0))
pFlag->Force = 1;
+#ifndef NO_CHOWN
+ else if (strcmp(argv[ArgIdx],"--allow-chown") == 0)
+ pFlag->AllowChown = 1;
+ else if (strcmp(argv[ArgIdx],"--no-allow-chown") == 0)
+ pFlag->AllowChown = 0;
+#endif
#ifdef D2U_UNICODE
#if (defined(_WIN32) && !defined(__CYGWIN__))
else if ((strcmp(argv[ArgIdx],"-gb") == 0) || (strcmp(argv[ArgIdx],"--gb18030") == 0))
@@ -2536,33 +2521,34 @@ int parse_options(int argc, char *argv[],
pFlag->stdio_mode = 0;
}
} else {
- pFlag->stdio_mode = 0;
/* not an option */
+ int conversion_error;
+ pFlag->stdio_mode = 0;
if (pFlag->NewFile) {
if (CanSwitchFileMode)
CanSwitchFileMode = 0;
else {
#ifdef D2U_UNICODE
- RetVal = ConvertNewFile(argv[ArgIdx-1], argv[ArgIdx], pFlag, progname, Convert, ConvertW);
+ conversion_error = ConvertNewFile(argv[ArgIdx-1], argv[ArgIdx], pFlag, progname, Convert, ConvertW);
#else
- RetVal = ConvertNewFile(argv[ArgIdx-1], argv[ArgIdx], pFlag, progname, Convert);
+ conversion_error = ConvertNewFile(argv[ArgIdx-1], argv[ArgIdx], pFlag, progname, Convert);
#endif
if (pFlag->verbose)
- print_messages_newfile(pFlag, argv[ArgIdx-1], argv[ArgIdx], progname, RetVal);
+ print_messages(pFlag, argv[ArgIdx-1], argv[ArgIdx], progname, conversion_error);
CanSwitchFileMode = 1;
}
} else {
if (pFlag->file_info) {
- RetVal = GetFileInfo(argv[ArgIdx], pFlag, progname);
+ conversion_error = GetFileInfo(argv[ArgIdx], pFlag, progname);
print_messages_info(pFlag, argv[ArgIdx], progname);
} else {
#ifdef D2U_UNICODE
- RetVal = ConvertNewFile(argv[ArgIdx], argv[ArgIdx], pFlag, progname, Convert, ConvertW);
+ conversion_error = ConvertNewFile(argv[ArgIdx], argv[ArgIdx], pFlag, progname, Convert, ConvertW);
#else
- RetVal = ConvertNewFile(argv[ArgIdx], argv[ArgIdx], pFlag, progname, Convert);
+ conversion_error = ConvertNewFile(argv[ArgIdx], argv[ArgIdx], pFlag, progname, Convert);
#endif
if (pFlag->verbose)
- print_messages_oldfile(pFlag, argv[ArgIdx], progname, RetVal);
+ print_messages(pFlag, argv[ArgIdx], NULL, progname, conversion_error);
}
}
}
@@ -2744,7 +2730,7 @@ wint_t d2u_putwc(wint_t wc, FILE *f, CFlag *ipFlag, const char *progname)
* Surrogate halves in UTF-8 are invalid. See also
* http://en.wikipedia.org/wiki/UTF-8#Invalid_code_points
* http://tools.ietf.org/html/rfc3629#page-5
- * It is a bug in (some implemenatations of) wcstombs().
+ * It is a bug in (some implementations of) wcstombs().
* On Cygwin 1.7 wcstombs() produces correct UTF-8 from UTF-16 surrogate pairs.
*/
/* Decode UTF-16 surrogate pair */