remove whitespace from end of lines
[reactos.git] / reactos / subsys / system / cmd / free.c
1 /*
2 * FREE.C - internal command.
3 *
4 *
5 * History:
6 *
7 * 01-Sep-1999 (Eric Kohl)
8 * Started.
9 *
10 * 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
11 * Remove all hardcode string to En.rc
12 */
13
14 #include "precomp.h"
15 #include "resource.h"
16
17 #ifdef INCLUDE_CMD_FREE
18
19
20 /*
21 * convert
22 *
23 * insert commas into a number
24 */
25
26 static INT
27 ConvertULargeInteger (ULARGE_INTEGER num, LPTSTR des, INT len)
28 {
29 TCHAR temp[32];
30 INT c = 0;
31 INT n = 0;
32
33 if (num.QuadPart == 0)
34 {
35 des[0] = _T('0');
36 des[1] = _T('\0');
37 n = 1;
38 }
39 else
40 {
41 temp[31] = 0;
42 while (num.QuadPart > 0)
43 {
44 if (((c + 1) % (nNumberGroups + 1)) == 0)
45 temp[30 - c++] = cThousandSeparator;
46 temp[30 - c++] = (TCHAR)(num.QuadPart % 10) + _T('0');
47 num.QuadPart /= 10;
48 }
49
50 for (n = 0; n <= c; n++)
51 des[n] = temp[31 - c + n];
52 }
53
54 return n;
55 }
56
57
58 static VOID
59 PrintDiskInfo (LPTSTR szDisk)
60 {
61 TCHAR szMsg[RC_STRING_MAX_SIZE];
62 TCHAR szRootPath[4] = _T("A:\\");
63 TCHAR szDrive[2] = _T("A");
64 TCHAR szVolume[64];
65 TCHAR szSerial[10];
66 TCHAR szTotal[40];
67 TCHAR szUsed[40];
68 TCHAR szFree[40];
69 DWORD dwSerial;
70 ULARGE_INTEGER uliSize;
71 DWORD dwSecPerCl;
72 DWORD dwBytPerSec;
73 DWORD dwFreeCl;
74 DWORD dwTotCl;
75
76 if (_tcslen (szDisk) < 2 || szDisk[1] != _T(':'))
77 {
78 LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
79 ConErrPrintf(szMsg);
80 return;
81 }
82
83 szRootPath[0] = szDisk[0];
84 szDrive[0] = _totupper (szRootPath[0]);
85
86 if (!GetVolumeInformation (szRootPath, szVolume, 64, &dwSerial,
87 NULL, NULL, NULL, 0))
88 {
89 LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
90 ConErrPrintf(_T("%s %s:\n"), szMsg, szDrive);
91 return;
92 }
93
94 if (szVolume[0] == _T('\0'))
95 {
96
97 LoadString(CMD_ModuleHandle, STRING_FREE_ERROR2, szMsg, RC_STRING_MAX_SIZE);
98 _tcscpy (szVolume, szMsg);
99 }
100
101 _stprintf (szSerial,
102 _T("%04X-%04X"),
103 HIWORD(dwSerial),
104 LOWORD(dwSerial));
105
106 if (!GetDiskFreeSpace (szRootPath, &dwSecPerCl,
107 &dwBytPerSec, &dwFreeCl, &dwTotCl))
108 {
109 LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
110 ConErrPrintf (_T("%s %s:\n"), szMsg, szDrive);
111 return;
112 }
113
114 uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwTotCl;
115 ConvertULargeInteger (uliSize, szTotal, 40);
116
117 uliSize.QuadPart = dwSecPerCl * dwBytPerSec * (dwTotCl - dwFreeCl);
118 ConvertULargeInteger (uliSize, szUsed, 40);
119
120 uliSize.QuadPart = dwSecPerCl * dwBytPerSec * dwFreeCl;
121 ConvertULargeInteger (uliSize, szFree, 40);
122
123
124 LoadString(CMD_ModuleHandle, STRING_FREE_HELP1, szMsg, RC_STRING_MAX_SIZE);
125 ConOutPrintf(szMsg, szDrive, szVolume, szSerial, szTotal, szUsed, szFree);
126 }
127
128
129 INT CommandFree (LPTSTR cmd, LPTSTR param)
130 {
131 LPTSTR szParam;
132 TCHAR szDefPath[MAX_PATH];
133 INT argc, i;
134 LPTSTR *arg;
135
136 if (!_tcsncmp (param, _T("/?"), 2))
137 {
138 ConOutResPuts(STRING_FREE_HELP2);
139 return 0;
140 }
141
142 if (!param || *param == _T('\0'))
143 {
144 GetCurrentDirectory (MAX_PATH, szDefPath);
145 szDefPath[2] = _T('\0');
146 szParam = szDefPath;
147 }
148 else
149 szParam = param;
150
151 arg = split (szParam, &argc, FALSE);
152
153 for (i = 0; i < argc; i++)
154 PrintDiskInfo (arg[i]);
155
156 freep (arg);
157
158 return 0;
159 }
160
161 #endif /* INCLUDE_CMD_FREE */
162
163 /* EOF */