Source code of Windows XP (NT5)
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.

136 lines
3.2 KiB

  1. #include "stdafx.h"
  2. #include "mymfile.h"
  3. #include "myinf.h"
  4. #include "mycmd.h"
  5. CMyCmd::CMyCmd()
  6. {
  7. }
  8. CMyCmd::~CMyCmd()
  9. {
  10. }
  11. BOOL CMyCmd::ProcessToken(LPTSTR lpszStr)
  12. {
  13. LPTSTR pszPair1,pszPair2;
  14. if (lpszStr && (*lpszStr == TEXT('-') || *lpszStr == TEXT('/'))) {
  15. lpszStr++;
  16. pszPair1 = pszPair2 = NULL;
  17. if (*(lpszStr+1)) {
  18. pszPair1 = lpszStr+1;
  19. pszPair2 = _tcsstr(lpszStr+1,TEXT(","));
  20. if (pszPair2) {
  21. *pszPair2 = TEXT('\0');
  22. pszPair2++;
  23. }
  24. }
  25. switch(*lpszStr) {
  26. case TEXT('t'):
  27. case TEXT('T'):
  28. if (pszPair1) {
  29. m_TargetFile = CString(pszPair1);
  30. }
  31. break;
  32. case TEXT('s'):
  33. case TEXT('S'):
  34. if (!pszPair1 || GetFileAttributes(pszPair1) == 0xFFFFFFFF) {
  35. fprintf(stderr,"Source file doesn't exist %s!\n",pszPair1);
  36. return FALSE;
  37. }
  38. m_SourceFile = CString(pszPair1);
  39. m_SourceLocale = CString(pszPair2);
  40. break;
  41. case TEXT('a'):
  42. case TEXT('A'):
  43. if (!pszPair1 || GetFileAttributes(pszPair1) == 0xFFFFFFFF) {
  44. fprintf(stderr,"Appended file doesn't exist !\n");
  45. return FALSE;
  46. }
  47. m_FileNameList.Add(pszPair1);
  48. m_LocaleList.Add(pszPair2);
  49. break;
  50. default:
  51. return FALSE;
  52. }
  53. return TRUE;
  54. } else {
  55. return FALSE;
  56. }
  57. }
  58. BOOL CMyCmd::GetParam(INT i,LPCTSTR& Locale, LPCTSTR& FileName)
  59. {
  60. if (i > m_LocaleList.GetSize()) {
  61. return FALSE;
  62. }
  63. Locale = (LPCTSTR) m_LocaleList[i];
  64. FileName = (LPCTSTR) m_FileNameList[i];
  65. return TRUE;
  66. }
  67. BOOL CMyCmd::Do()
  68. {
  69. CMyMemFile Target;
  70. CMyInf Source;
  71. CMyInf* AppendedSource;
  72. BOOL bRet = FALSE;
  73. int i;
  74. if (! Target.bOpen(m_TargetFile)) {
  75. goto Exit1;
  76. }
  77. if (! Source.bOpen(m_SourceFile,m_SourceLocale)) {
  78. goto Exit2;
  79. }
  80. Source.AppendNonStringSectionPart(Target);
  81. Source.AppendStringSectionPart(Target);
  82. Source.bClose();
  83. Target.Write(L"\r\n",4);
  84. for (i=0; i< m_LocaleList.GetSize(); i++) {
  85. AppendedSource = (CMyInf *) new CMyInf;
  86. if (AppendedSource ) {
  87. if (AppendedSource->bOpen(m_FileNameList[i],m_LocaleList[i])) {
  88. AppendedSource->AppendStringSectionPart(Target);
  89. AppendedSource->bClose();
  90. }
  91. delete AppendedSource;
  92. } else {
  93. goto Exit2;
  94. }
  95. }
  96. bRet = TRUE;
  97. Exit2:
  98. Target.bClose();
  99. Exit1:
  100. return bRet;
  101. }
  102. void CMyCmd::Help()
  103. {
  104. printf("infcat : localization tool for International team.\n\n");
  105. printf("infcat.exe -t[Dst] -s[Src|,Loc] -a[Src1|,Loc] -a[Src|,Loc] ...\n\n");
  106. printf(" -t - specify target file\n");
  107. printf(" -s - specify source file\n");
  108. printf(" -a - specify appended files\n");
  109. printf(" Dst - destination file name\n");
  110. printf(" Src - source file name\n");
  111. printf(" Loc - locale ID\n");
  112. }