xref: /haiku/src/apps/diskusage/DiskUsage.cpp (revision e8cd7007416a323259791ac09c013dcce2956976)
1 /*
2  * Copyright (c) 1998-2007 Matthijs Hollemans
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "App.h"
8 
9 #include <stdio.h>
10 
11 #include <Catalog.h>
12 
13 #include "DiskUsage.h"
14 
15 #undef B_TRANSLATE_CONTEXT
16 #define B_TRANSLATE_CONTEXT "DiskUsage"
17 
18 entry_ref helpFileRef;
19 bool helpFileWasFound = false;
20 
21 void
22 size_to_string(off_t byteCount, char* name, int maxLength)
23 {
24 	struct {
25 		off_t		limit;
26 		float		divisor;
27 		const char*	format;
28 	} scale[] = {
29 		{ 0x100000,				1024.0,
30 			B_TRANSLATE("%.2f KiB") },
31 		{ 0x40000000,			1048576.0,
32 			B_TRANSLATE("%.2f MiB") },
33 		{ 0x10000000000ull,		1073741824.0,
34 			B_TRANSLATE("%.2f GiB") },
35 		{ 0x4000000000000ull,	1.09951162778e+12,
36 			B_TRANSLATE("%.2f TiB") }
37 	};
38 
39 	if (byteCount < 1024) {
40 		snprintf(name, maxLength, B_TRANSLATE("%lld bytes"),
41 			byteCount);
42 	} else {
43 		int i = 0;
44 		while (byteCount >= scale[i].limit)
45 			i++;
46 
47 		snprintf(name, maxLength, scale[i].format,
48 			byteCount / scale[i].divisor);
49 	}
50 }
51 
52 int
53 main()
54 {
55 	App app;
56 	app.Run();
57 	return 0;
58 }
59 
60