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.

165 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1993-1994 Microsoft Corporation
  3. Module Name:
  4. common.c
  5. Abstract:
  6. Utility routines used by IniToDat.exe
  7. Author:
  8. HonWah Chan (a-honwah) October, 1993
  9. Revision History:
  10. --*/
  11. //
  12. // "C" Include files
  13. //
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <malloc.h>
  18. //
  19. // Windows Include files
  20. //
  21. #include <windows.h>
  22. #include <winperf.h>
  23. #include <tchar.h>
  24. //
  25. // local include files
  26. //
  27. #include "common.h"
  28. #include "strids.h"
  29. // Global Buffers
  30. //
  31. TCHAR DisplayStringBuffer[DISP_BUFF_SIZE];
  32. CHAR TextFormat[DISP_BUFF_SIZE];
  33. HANDLE hMod;
  34. DWORD dwLastError;
  35. const LPTSTR BlankString = (const LPTSTR)TEXT(" ");
  36. const LPSTR BlankAnsiString = " ";
  37. LPTSTR
  38. GetStringResource (
  39. UINT wStringId
  40. )
  41. /*++
  42. Retrived UNICODE strings from the resource file for display
  43. --*/
  44. {
  45. if (!hMod) {
  46. hMod = (HINSTANCE)GetModuleHandle(NULL); // get instance ID of this module;
  47. }
  48. if (hMod) {
  49. if ((LoadString(hMod, wStringId, DisplayStringBuffer, DISP_BUFF_SIZE)) > 0) {
  50. return (LPTSTR)&DisplayStringBuffer[0];
  51. } else {
  52. dwLastError = GetLastError();
  53. return BlankString;
  54. }
  55. } else {
  56. return BlankString;
  57. }
  58. }
  59. LPSTR
  60. GetFormatResource (
  61. UINT wStringId
  62. )
  63. /*++
  64. Returns an ANSI string for use as a format string in a printf fn.
  65. --*/
  66. {
  67. if (!hMod) {
  68. hMod = (HINSTANCE)GetModuleHandle(NULL); // get instance ID of this module;
  69. }
  70. if (hMod) {
  71. if ((LoadStringA(hMod, wStringId, TextFormat, DISP_BUFF_SIZE)) > 0) {
  72. return (LPSTR)&TextFormat[0];
  73. } else {
  74. dwLastError = GetLastError();
  75. return BlankAnsiString;
  76. }
  77. } else {
  78. return BlankAnsiString;
  79. }
  80. }
  81. VOID
  82. DisplayCommandHelp (
  83. UINT iFirstLine,
  84. UINT iLastLine
  85. )
  86. /*++
  87. DisplayCommandHelp
  88. displays usage of command line arguments
  89. Arguments
  90. NONE
  91. Return Value
  92. NONE
  93. --*/
  94. {
  95. UINT iThisLine;
  96. for (iThisLine = iFirstLine;
  97. iThisLine <= iLastLine;
  98. iThisLine++) {
  99. printf ("\n%ws", GetStringResource(iThisLine));
  100. }
  101. } // DisplayCommandHelp
  102. VOID
  103. DisplaySummary (
  104. LPTSTR lpLastID,
  105. LPTSTR lpLastText,
  106. UINT NumOfID
  107. )
  108. {
  109. printf ("%ws", GetStringResource(LC_SUMMARY));
  110. printf ("%ws", GetStringResource(LC_NUM_OF_ID));
  111. printf ("%ld\n", NumOfID);
  112. printf ("%ws", GetStringResource(LC_LAST_ID));
  113. printf ("%ws\n", lpLastID ? lpLastID : (LPCTSTR)TEXT(""));
  114. printf ("%ws", GetStringResource(LC_LAST_TEXT));
  115. printf ("%ws\n", lpLastText ? lpLastText : (LPCTSTR)TEXT(""));
  116. }
  117. VOID
  118. DisplaySummaryError (
  119. LPTSTR lpLastID,
  120. LPTSTR lpLastText,
  121. UINT NumOfID
  122. )
  123. {
  124. printf ("%ws", GetStringResource(LC_BAD_ID));
  125. printf ("%ws\n", lpLastID ? lpLastID : (LPCTSTR)TEXT(""));
  126. printf ("%ws\n", GetStringResource(LC_MISSING_DEL));
  127. DisplaySummary (lpLastID, lpLastText, NumOfID);
  128. }
  129.