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.

184 lines
3.5 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #define KEYWORD_BUF_SIZE 100
  4. #define STRINGS_BUF_SIZE 8096
  5. typedef struct _ITEM {
  6. TCHAR szKeyword[KEYWORD_BUF_SIZE];
  7. struct _ITEM * pNext;
  8. } ITEM, *LPITEM;
  9. LPITEM g_KeywordList = NULL;
  10. LPTSTR GetStringSection (LPCTSTR lpFileName)
  11. {
  12. DWORD dwSize, dwRead;
  13. LPTSTR lpStrings;
  14. //
  15. // Read in the default strings section
  16. //
  17. dwSize = STRINGS_BUF_SIZE;
  18. lpStrings = (TCHAR *) GlobalAlloc (GPTR, dwSize * sizeof(TCHAR));
  19. if (!lpStrings)
  20. {
  21. printf("(1) Failed to allocate memory with %d\n", GetLastError());
  22. return NULL;
  23. }
  24. do {
  25. dwRead = GetPrivateProfileSection (TEXT("Strings"),
  26. lpStrings,
  27. dwSize, lpFileName);
  28. if (dwRead != (dwSize - 2))
  29. {
  30. break;
  31. }
  32. GlobalFree (lpStrings);
  33. dwSize *= 2;
  34. lpStrings = (TCHAR *) GlobalAlloc (GPTR, dwSize * sizeof(TCHAR));
  35. if (!lpStrings)
  36. {
  37. printf("(2) Failed to allocate memory with %d\n", GetLastError());
  38. return FALSE;
  39. }
  40. } while (TRUE);
  41. if (dwRead == 0)
  42. {
  43. GlobalFree (lpStrings);
  44. lpStrings = NULL;
  45. }
  46. return lpStrings;
  47. }
  48. BOOL DoesKeywordExist (LPTSTR lpKeyword)
  49. {
  50. LPITEM lpTemp;
  51. lpTemp = g_KeywordList;
  52. while (lpTemp) {
  53. if (!lstrcmpi(lpKeyword, lpTemp->szKeyword)) {
  54. return TRUE;
  55. }
  56. lpTemp = lpTemp->pNext;
  57. }
  58. return FALSE;
  59. }
  60. BOOL AddKeywordToList (LPTSTR lpKeyword)
  61. {
  62. LPITEM lpTemp;
  63. lpTemp = LocalAlloc (LPTR, sizeof(ITEM));
  64. if (!lpTemp) {
  65. printf("(3) Failed to allocate memory with %d\n", GetLastError());
  66. return FALSE;
  67. }
  68. lstrcpyn (lpTemp->szKeyword, lpKeyword, KEYWORD_BUF_SIZE);
  69. lpTemp->pNext = g_KeywordList;
  70. g_KeywordList = lpTemp;
  71. return TRUE;
  72. }
  73. int __cdecl main( int argc, char *argv[])
  74. {
  75. LPTSTR lpStrings, lpTemp, lpChar, lpEnd;
  76. TCHAR szKeyword [KEYWORD_BUF_SIZE];
  77. DWORD dwIndex;
  78. if (argc != 2) {
  79. printf("usage: chkadm admfile\n");
  80. return 1;
  81. }
  82. lpStrings = GetStringSection(argv[1]);
  83. if (!lpStrings) {
  84. printf("No strings, or failure reading strings\n");
  85. return 1;
  86. }
  87. lpTemp = lpStrings;
  88. while (*lpTemp)
  89. {
  90. lpChar = szKeyword;
  91. dwIndex = 0;
  92. while (*lpTemp && (*lpTemp != TEXT('=')) && (*lpTemp != TEXT('\r'))
  93. && (*lpTemp != TEXT('\n')) && (dwIndex < (KEYWORD_BUF_SIZE - 1)) ) {
  94. *lpChar = *lpTemp;
  95. lpChar++;
  96. lpTemp++;
  97. dwIndex++;
  98. }
  99. *lpChar = TEXT('\0');
  100. if (*lpTemp == TEXT('=')) {
  101. if (DoesKeywordExist (szKeyword)) {
  102. printf(TEXT("Duplicate string name for: %s\n"), szKeyword);
  103. } else {
  104. if (!AddKeywordToList(szKeyword)) {
  105. return 1;
  106. }
  107. }
  108. } else {
  109. printf("==================\n");
  110. printf("\nThe following entry in the [Strings] section does not start with a variable name:\n\n%s\n\n", szKeyword);
  111. printf("==================\n");
  112. }
  113. lpEnd = lpTemp += lstrlen (lpTemp) - 1;
  114. lpTemp += lstrlen (lpTemp) + 1;
  115. while (*lpEnd == TEXT('\\')) {
  116. lpEnd = lpTemp += lstrlen (lpTemp) - 1;
  117. lpTemp += lstrlen (lpTemp) + 1;
  118. }
  119. }
  120. GlobalFree (lpStrings);
  121. return 0;
  122. }