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) 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 sprintf(name, B_TRANSLATE("%lld bytes"), byteCount); 41 } else { 42 int i = 0; 43 while (byteCount >= scale[i].limit) 44 i++; 45 46 sprintf(name, scale[i].format, byteCount / scale[i].divisor); 47 } 48 } 49 50 int 51 main() 52 { 53 App app; 54 app.Run(); 55 return 0; 56 } 57 58