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 <TrackerAddOnAppLaunch.h>
10
11#include <stdio.h>
12
13#include <Catalog.h>
14
15#include "DiskUsage.h"
16
17#undef B_TRANSLATION_CONTEXT
18#define B_TRANSLATION_CONTEXT "DiskUsage"
19
20entry_ref helpFileRef;
21bool helpFileWasFound = false;
22
23void
24size_to_string(off_t byteCount, char* name, int maxLength)
25{
26	struct {
27		off_t		limit;
28		float		divisor;
29		const char*	format;
30	} scale[] = {
31		{ 0x100000,				1024.0,
32			B_TRANSLATE("%.2f KiB") },
33		{ 0x40000000,			1048576.0,
34			B_TRANSLATE("%.2f MiB") },
35		{ 0x10000000000ull,		1073741824.0,
36			B_TRANSLATE("%.2f GiB") },
37		{ 0x4000000000000ull,	1.09951162778e+12,
38			B_TRANSLATE("%.2f TiB") }
39	};
40
41	if (byteCount < 1024) {
42		snprintf(name, maxLength, B_TRANSLATE("%lld bytes"),
43			byteCount);
44	} else {
45		int i = 0;
46		while (byteCount >= scale[i].limit)
47			i++;
48
49		snprintf(name, maxLength, scale[i].format,
50			byteCount / scale[i].divisor);
51	}
52}
53
54int
55main()
56{
57	App app;
58	app.Run();
59	return 0;
60}
61
62