Imported bzip2 modified to build a decompression only dll for use by the ramdisk...
[reactos.git] / rosapps / cmd / memory.c
1 /*
2 * MEMORY.C - internal command.
3 *
4 *
5 * History:
6 *
7 * 01-Sep-1999 (Eric Kohl)
8 * Started.
9 */
10
11 #include "config.h"
12
13 #ifdef INCLUDE_CMD_MEMORY
14
15 #include <windows.h>
16 #include <tchar.h>
17 #include <string.h>
18 #include <ctype.h>
19
20 #include "cmd.h"
21
22
23 /*
24 * convert
25 *
26 * insert commas into a number
27 */
28 static INT
29 ConvertDWord (DWORD num, LPTSTR des, INT len, BOOL bSeparator)
30 {
31 TCHAR temp[32];
32 INT c = 0;
33 INT n = 0;
34
35 if (num == 0)
36 {
37 des[0] = _T('0');
38 des[1] = _T('\0');
39 n = 1;
40 }
41 else
42 {
43 temp[31] = 0;
44 while (num > 0)
45 {
46 if (bSeparator && (((c + 1) % (nNumberGroups + 1)) == 0))
47 temp[30 - c++] = cThousandSeparator;
48 temp[30 - c++] = (TCHAR)(num % 10) + _T('0');
49 num /= 10;
50 }
51
52 for (n = 0; n <= c; n++)
53 des[n] = temp[31 - c + n];
54 }
55
56 return n;
57 }
58
59
60 INT CommandMemory (LPTSTR cmd, LPTSTR param)
61 {
62 MEMORYSTATUS ms;
63 TCHAR szMemoryLoad[20];
64 TCHAR szTotalPhys[20];
65 TCHAR szAvailPhys[20];
66 TCHAR szTotalPageFile[20];
67 TCHAR szAvailPageFile[20];
68 TCHAR szTotalVirtual[20];
69 TCHAR szAvailVirtual[20];
70
71 if (!_tcsncmp (param, _T("/?"), 2))
72 {
73 ConOutPuts (_T("Displays the amount of system memory.\n"
74 "\n"
75 "MEMORY"));
76 return 0;
77 }
78
79 ms.dwLength = sizeof(MEMORYSTATUS);
80
81 GlobalMemoryStatus (&ms);
82
83 ConvertDWord (ms.dwMemoryLoad, szMemoryLoad, 20, FALSE);
84 ConvertDWord (ms.dwTotalPhys, szTotalPhys, 20, TRUE);
85 ConvertDWord (ms.dwAvailPhys, szAvailPhys, 20, TRUE);
86 ConvertDWord (ms.dwTotalPageFile, szTotalPageFile, 20, TRUE);
87 ConvertDWord (ms.dwAvailPageFile, szAvailPageFile, 20, TRUE);
88 ConvertDWord (ms.dwTotalVirtual, szTotalVirtual, 20, TRUE);
89 ConvertDWord (ms.dwAvailVirtual, szAvailVirtual, 20, TRUE);
90
91 ConOutPrintf (_T("\n"
92 " %12s%% memory load.\n"
93 "\n"
94 " %13s bytes total physical RAM.\n"
95 " %13s bytes available physical RAM.\n"
96 "\n"
97 " %13s bytes total page file.\n"
98 " %13s bytes available page file.\n"
99 "\n"
100 " %13s bytes total virtual memory.\n"
101 " %13s bytes available virtual memory.\n"),
102 szMemoryLoad, szTotalPhys, szAvailPhys, szTotalPageFile,
103 szAvailPageFile, szTotalVirtual, szAvailVirtual);
104
105 return 0;
106 }
107
108 #endif /* INCLUDE_CMD_MEMORY */
109
110 /* EOF */