summaryrefslogtreecommitdiff
path: root/unix2dos.c
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2016-10-20 13:27:40 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2016-10-20 13:27:44 +0900
commit842ebc0fa15fca613e0c9fce10dd63fa09d27666 (patch)
treeac48c8ec511c025b1b479462056510eedc3ac6bc /unix2dos.c
parent3d6ee8c3ccc0f65c7c87122dba80908ae751aa16 (diff)
downloaddos2unix-842ebc0fa15fca613e0c9fce10dd63fa09d27666.tar.gz
dos2unix-842ebc0fa15fca613e0c9fce10dd63fa09d27666.tar.bz2
dos2unix-842ebc0fa15fca613e0c9fce10dd63fa09d27666.zip
Imported Upstream version 6.0.4
Change-Id: I3ce28283323425d17877da03683ac6a2b70f2382 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'unix2dos.c')
-rw-r--r--unix2dos.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/unix2dos.c b/unix2dos.c
index d0cdf80..cd5b518 100644
--- a/unix2dos.c
+++ b/unix2dos.c
@@ -129,7 +129,7 @@ int ConvertUnixToDosW(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
if (!ipFlag->Quiet)
{
fprintf(stderr, "%s: ", progname);
- fprintf(stderr, _("Binary symbol found at line %d\n"), line_nr);
+ fprintf(stderr, _("Binary symbol 0x00%02X found at line %d\n"),TempChar, line_nr);
}
break;
}
@@ -182,7 +182,7 @@ int ConvertUnixToDosW(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
if (!ipFlag->Quiet)
{
fprintf(stderr, "%s: ", progname);
- fprintf(stderr, _("Binary symbol found at line %d\n"), line_nr);
+ fprintf(stderr, _("Binary symbol 0x00%02X found at line %d\n"),TempChar, line_nr);
}
break;
}
@@ -276,6 +276,8 @@ int ConvertUnixToDos(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
switch (ipFlag->ConvMode)
{
case CONVMODE_ASCII: /* ascii */
+ case CONVMODE_UTF16LE: /* Assume UTF-16LE */
+ case CONVMODE_UTF16BE: /* Assume UTF-16BE */
ConvTable = U2DAsciiTable;
break;
case CONVMODE_7BIT: /* 7bit */
@@ -329,7 +331,7 @@ int ConvertUnixToDos(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
if (!ipFlag->Quiet)
{
fprintf(stderr, "%s: ", progname);
- fprintf(stderr, _("Binary symbol found at line %d\n"), line_nr);
+ fprintf(stderr, _("Binary symbol 0x%02X found at line %d\n"),TempChar, line_nr);
}
break;
}
@@ -379,7 +381,7 @@ int ConvertUnixToDos(FILE* ipInF, FILE* ipOutF, CFlag *ipFlag, char *progname)
if (!ipFlag->Quiet)
{
fprintf(stderr, "%s: ", progname);
- fprintf(stderr, _("Binary symbol found at line %d\n"), line_nr);
+ fprintf(stderr, _("Binary symbol 0x%02X found at line %d\n"),TempChar, line_nr);
}
break;
}
@@ -569,6 +571,12 @@ int ConvertUnixToDosNewFile(char *ipInFN, char *ipOutFN, CFlag *ipFlag, char *pr
}
InF = read_bom(InF, &ipFlag->bomtype);
+#ifdef D2U_UNICODE
+ if ((ipFlag->bomtype == FILE_MBS) && (ipFlag->ConvMode == CONVMODE_UTF16LE))
+ ipFlag->bomtype = FILE_UTF16LE;
+ if ((ipFlag->bomtype == FILE_MBS) && (ipFlag->ConvMode == CONVMODE_UTF16BE))
+ ipFlag->bomtype = FILE_UTF16BE;
+#endif
#ifdef D2U_UNICODE
#if !defined(__MSDOS__) && !defined(_WIN32) && !defined(__OS2__) /* Unix, Cygwin */
@@ -602,7 +610,8 @@ int ConvertUnixToDosNewFile(char *ipInFN, char *ipOutFN, CFlag *ipFlag, char *pr
fprintf(TempF, "%s", "\xEF\xBB\xBF"); /* UTF-8 BOM */
/* Turn off ISO and 7-bit conversion for Unicode text files */
- if (ipFlag->bomtype > 0)
+ /* When we assume UTF16, don't change the conversion mode. We need to remember it. */
+ if ((ipFlag->bomtype > 0) && (ipFlag->ConvMode != CONVMODE_UTF16LE) && (ipFlag->ConvMode != CONVMODE_UTF16BE))
ipFlag->ConvMode = CONVMODE_ASCII;
/* conversion sucessful? */
@@ -822,6 +831,12 @@ int ConvertUnixToDosStdio(CFlag *ipFlag, char *progname)
#endif
read_bom(stdin, &ipFlag->bomtype);
+#ifdef D2U_UNICODE
+ if ((ipFlag->bomtype == FILE_MBS) && (ipFlag->ConvMode == CONVMODE_UTF16LE))
+ ipFlag->bomtype = FILE_UTF16LE;
+ if ((ipFlag->bomtype == FILE_MBS) && (ipFlag->ConvMode == CONVMODE_UTF16BE))
+ ipFlag->bomtype = FILE_UTF16BE;
+#endif
if ((ipFlag->add_bom) || (ipFlag->bomtype > 0))
fprintf(stdout, "%s", "\xEF\xBB\xBF"); /* UTF-8 BOM */
@@ -991,6 +1006,12 @@ int main (int argc, char *argv[])
pFlag->ConvMode = CONVMODE_865;
else if (strcmp(argv[ArgIdx],"-1252") == 0)
pFlag->ConvMode = CONVMODE_1252;
+#ifdef D2U_UNICODE
+ else if ((strcmp(argv[ArgIdx],"-ul") == 0) || (strcmp(argv[ArgIdx],"--assume-utf16le") == 0))
+ pFlag->ConvMode = CONVMODE_UTF16LE;
+ else if ((strcmp(argv[ArgIdx],"-ub") == 0) || (strcmp(argv[ArgIdx],"--assume-utf16be") == 0))
+ pFlag->ConvMode = CONVMODE_UTF16BE;
+#endif
else if ((strcmp(argv[ArgIdx],"-c") == 0) || (strcmp(argv[ArgIdx],"--convmode") == 0))
{
if (++ArgIdx < argc)