Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
4.3 KiB

  1. // convert.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "tchar.h"
  5. #include "stdio.h"
  6. #include "convert.h"
  7. #include "convertDlg.h"
  8. #include "FileConv.h"
  9. #include "Msg.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. BOOL CConvertApp::CommandLineHandle()
  16. {
  17. // GBTOUNIC.EXE [/U] [/G] [/?] [/H] Filename1 [Filename2]
  18. // If Filename2 is not provided, the tool should create a file named
  19. // Filename1.old as the copy of Filename1, and perform the appropriate
  20. // conversion from Filename1.old to Filename1,
  21. // Filename1 as the final converted destination file.
  22. //
  23. // /U or /u performing GB18030 to Unicode conversion
  24. // /G or /g performing Unicode to GB18030 conversion
  25. // /H or /? Displaying help message.
  26. TCHAR* tszFlag = NULL;
  27. TCHAR* tszSrc = NULL;
  28. CString strTar;
  29. BOOL fAnsiToUnicode;
  30. BOOL fRet = FALSE;
  31. FILE* pFile = NULL;
  32. if (__argc > 4 || __argc < 3) {
  33. MsgUsage();
  34. goto Exit;
  35. }
  36. tszFlag = __targv[1];
  37. if (*tszFlag != TEXT('-') && *tszFlag != TEXT('/')) {
  38. MsgUsage();
  39. goto Exit;
  40. }
  41. if (lstrlen(tszFlag) != 2) {
  42. MsgUsage();
  43. goto Exit;
  44. }
  45. // Convert direct
  46. if (tszFlag[1] == TEXT('U') || tszFlag[1] == TEXT('u')) {
  47. fAnsiToUnicode = TRUE;
  48. } else if (tszFlag[1] == TEXT('G') || tszFlag[1] == TEXT('g')) {
  49. fAnsiToUnicode = FALSE;
  50. } else {
  51. MsgUsage();
  52. goto Exit;
  53. }
  54. tszSrc = __targv[2];
  55. /*
  56. pFile = _tfopen(tszSrc, TEXT("r"));
  57. if (!pFile) {
  58. MsgOpenSourceFileError(tszSrc);
  59. return FALSE;
  60. }
  61. fclose(pFile);
  62. */
  63. // Source and Target file name
  64. if (__argc == 3) {
  65. /*
  66. // Hasn't give target file name
  67. // Save source file set target file name
  68. tszBuf = new TCHAR[lstrlen(tszSrc) + 5]; // 5, sizeof(TEXT(".old"))/sizeof(TCHAR)
  69. lstrcpy(tszBuf, tszSrc);
  70. lstrcat(tszBuf, TEXT(".old"));
  71. BOOL f = CopyFile (tszSrc, tszBuf, TRUE);
  72. if (f) {
  73. tszTar = tszSrc;
  74. tszSrc = tszBuf;
  75. } else {
  76. MsgFailToBackupFile(tszSrc, tszBuf);
  77. goto Exit;
  78. }
  79. */
  80. if (!GenerateTargetFileName(tszSrc, &strTar, fAnsiToUnicode)) {
  81. goto Exit;
  82. }
  83. } else if (__argc == 4) {
  84. strTar = __targv[3];
  85. } else {
  86. ASSERT(FALSE);
  87. }
  88. fRet = Convert(tszSrc, strTar, fAnsiToUnicode);
  89. Exit:
  90. /*
  91. if (tszBuf) {
  92. delete[] tszBuf;
  93. tszBuf = NULL;
  94. }
  95. */
  96. return fRet;
  97. }
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CConvertApp
  100. BEGIN_MESSAGE_MAP(CConvertApp, CWinApp)
  101. //{{AFX_MSG_MAP(CConvertApp)
  102. // NOTE - the ClassWizard will add and remove mapping macros here.
  103. // DO NOT EDIT what you see in these blocks of generated code!
  104. //}}AFX_MSG
  105. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  106. END_MESSAGE_MAP()
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CConvertApp construction
  109. CConvertApp::CConvertApp()
  110. {
  111. }
  112. /////////////////////////////////////////////////////////////////////////////
  113. // The one and only CConvertApp object
  114. CConvertApp theApp;
  115. /////////////////////////////////////////////////////////////////////////////
  116. // CConvertApp initialization
  117. BOOL CConvertApp::InitInstance()
  118. {
  119. AfxEnableControlContainer();
  120. // Standard initialization
  121. // If you are not using these features and wish to reduce the size
  122. // of your final executable, you should remove from the following
  123. // the specific initialization routines you do not need.
  124. #ifdef _AFXDLL
  125. Enable3dControls(); // Call this when using MFC in a shared DLL
  126. #else
  127. Enable3dControlsStatic(); // Call this when linking to MFC statically
  128. #endif
  129. if (__argc >= 2) {
  130. CommandLineHandle();
  131. return FALSE;
  132. }
  133. CConvertDlg dlg;
  134. m_pMainWnd = &dlg;
  135. INT_PTR nResponse = dlg.DoModal();
  136. // Since the dialog has been closed, return FALSE so that we exit the
  137. // application, rather than start the application's message pump.
  138. return FALSE;
  139. }