Simplify printing

parent a1dca226
......@@ -9,6 +9,7 @@ lib/Package.o
lib/Repository.o
lib/libparcel.a
lib/libparcel.so*
lib/test/installedmsg
lib/test/packageversion
lib/test/repoquery
lib/test/repository
......@@ -11,12 +11,8 @@ Repository *make_repo_from_file(string filename) {
return new Repository(my_file);
}
static const char prefixes[7] = {' ', 'K', 'M', 'G', 'T' , 'E', 'Z'};
int main(void) {
uint64_t size = 0;
char prefix = 0;
string prefix_str;
Repository *test_repo = make_repo_from_file("/lib/apk/db/installed");
if(test_repo == nullptr) {
......@@ -28,20 +24,9 @@ int main(void) {
size += pkg->size();
}
/* Wow, this is ugly */
while(size > 10240) {
size /= 1024;
prefix++;
}
while(prefix > sizeof(prefixes)) {
size *= 1024;
prefix--;
}
if(prefix == 0) prefix_str = "bytes";
else prefix_str = string("") + prefixes[prefix] + "iB";
size /= 1048576;
std::cout << "OK: " << size << " " << prefix_str << " in " << test_repo->package_count() << " packages" << std::endl;
std::cout << "OK: " << size << " MiB in " << test_repo->package_count() << " packages" << std::endl;
delete test_repo;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment