OSDN Git Service

Fix line feed codes.
[ffftp/ffftp.git] / encutf8 / encutf8.cpp
1 // encutf8.cpp : \83R\83\93\83\\81[\83\8b \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82Ì\83G\83\93\83g\83\8a \83|\83C\83\93\83g\82ð\92è\8b`\82µ\82Ü\82·\81B\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 \r
6 \r
7 int _tmain(int argc, _TCHAR* argv[])\r
8 {\r
9         FILE* fpIn;\r
10         FILE* fpOut;\r
11         fpos_t Length;\r
12         int InLength;\r
13         char* pInBuffer;\r
14         int UTF16Length;\r
15         wchar_t* pUTF16Buffer;\r
16         int OutLength;\r
17         char* pOutBuffer;\r
18         _tsetlocale(LC_ALL, _T(""));\r
19         if(argc != 3)\r
20         {\r
21                 _tprintf(_T("\83}\83\8b\83`\83o\83C\83g\95\8e\9a\81i\83R\81[\83h\83y\81[\83W932\82Ü\82½\82ÍShift JIS\81j\82Å\8f\91\82©\82ê\82½\83e\83L\83X\83g\83t\83@\83C\83\8b\82ðUTF-8\82É\83G\83\93\83R\81[\83h\82µ\82Ü\82·\81B\n"));\r
22                 _tprintf(_T("\83R\83}\83\93\83h\83\89\83C\83\93\n"));\r
23                 _tprintf(_T("encutf8 [in] [out]\n"));\r
24                 _tprintf(_T("[in]    \8c³\82Ì\83\\81[\83X\83t\83@\83C\83\8b\82Ì\83t\83@\83C\83\8b\96¼\n"));\r
25                 _tprintf(_T("[out]   \95Û\91\90æ\82Ì\83t\83@\83C\83\8b\96¼\n"));\r
26                 return 0;\r
27         }\r
28         fpIn = _tfopen(argv[1], _T("rb"));\r
29         if(!fpIn)\r
30         {\r
31                 _tprintf(_T("\83t\83@\83C\83\8b\"%s\"\82ª\8aJ\82¯\82Ü\82¹\82ñ\81B\n"), argv[1]);\r
32                 return 0;\r
33         }\r
34         fseek(fpIn, 0, SEEK_END);\r
35         fgetpos(fpIn, &Length);\r
36         fseek(fpIn, 0, SEEK_SET);\r
37         InLength = Length / sizeof(char);\r
38         pInBuffer = new char[InLength];\r
39         UTF16Length = InLength;\r
40         pUTF16Buffer = new wchar_t[InLength];\r
41         OutLength = InLength * 4;\r
42         pOutBuffer = new char[OutLength];\r
43         if(!pInBuffer || !pUTF16Buffer || !pOutBuffer)\r
44         {\r
45                 _tprintf(_T("\83\81\83\82\83\8a\82ª\8am\95Û\82Å\82«\82Ü\82¹\82ñ\81B\n"));\r
46                 return 0;\r
47         }\r
48         fread(pInBuffer, 1, InLength, fpIn);\r
49         fclose(fpIn);\r
50         fpOut = _tfopen(argv[2], _T("wb"));\r
51         if(!fpIn)\r
52         {\r
53                 _tprintf(_T("\83t\83@\83C\83\8b\"%s\"\82ª\8dì\90¬\82Å\82«\82Ü\82¹\82ñ\81B\n"), argv[2]);\r
54                 return 0;\r
55         }\r
56         fwrite("\xEF\xBB\xBF", 1, 3, fpOut);\r
57         UTF16Length = MultiByteToWideChar(CP_ACP, 0, pInBuffer, InLength / sizeof(char), pUTF16Buffer, UTF16Length);\r
58         OutLength = WideCharToMultiByte(CP_UTF8, 0, pUTF16Buffer, UTF16Length, pOutBuffer, OutLength / sizeof(char), NULL, NULL);\r
59         fwrite(pOutBuffer, sizeof(char), OutLength, fpOut);\r
60         fclose(fpOut);\r
61         return 0;\r
62 }\r
63 \r