[Review] Class to namespace

This commit is contained in:
devdl11
2022-04-08 14:01:55 +02:00
parent ff40b8b862
commit 3c26035feb
6 changed files with 12 additions and 14 deletions

View File

@@ -26,8 +26,8 @@ void Boot::bootSlot(Bootloader::Slot s) {
// We are trying to boot epsilon, so we check the version and show an advertisement if needed
const char * version = s.userlandHeader()->version();
const char * min = "18.2.4";
int vsum = Bootloader::Utility::versionSum(version, strlen(version));
int minsum = Bootloader::Utility::versionSum(min, strlen(min));
int vsum = Utility::versionSum(version, strlen(version));
int minsum = Utility::versionSum(min, strlen(min));
if (vsum >= minsum) {
Interface::drawEpsilonAdvertisement();
uint64_t scan = 0;

View File

@@ -19,7 +19,7 @@ char* reverse(char *buffer, int i, int j) {
}
// Iterative function to implement `itoa()` function in C
char* Bootloader::Utility::itoa(int value, char* buffer, int base) {
char* Utility::itoa(int value, char* buffer, int base) {
// invalid input
if (base < 2 || base > 32) {
return buffer;

View File

@@ -24,9 +24,9 @@ const void(*KernelHeader::startPointer() const)() {
}
const bool KernelHeader::isAboveVersion16 () const {
int sum = Bootloader::Utility::versionSum(m_version, 2);
int sum = Utility::versionSum(m_version, 2);
char newVersion[] = "16";
int min = Bootloader::Utility::versionSum(newVersion, 2);
int min = Utility::versionSum(newVersion, 2);
return sum >= min;
}

View File

@@ -13,13 +13,13 @@ static char data[255];
const char * Bootloader::USBData::buildStringDescriptor(StringHeader header, uint32_t startAddress, uint32_t size) {
strlcpy(data, header.getString(), sizeof(data));
Bootloader::Utility::itoa((int32_t)startAddress, &data[strlen(header.getString())], 16);
Utility::itoa((int32_t)startAddress, &data[strlen(header.getString())], 16);
data[strlen(header.getString()) + 8] = '/';
data[strlen(header.getString()) + 8 + 1] = '0';
data[strlen(header.getString()) + 8 + 2] = '1';
data[strlen(header.getString()) + 8 + 3] = '*';
data[strlen(header.getString()) + 8 + 4] = '0';
Bootloader::Utility::itoa((int32_t)size/1024, &data[strlen(header.getString()) + 8 + 5], 10);
Utility::itoa((int32_t)size/1024, &data[strlen(header.getString()) + 8 + 5], 10);
data[strlen(header.getString()) + 8 + 5 + 2] = 'K';
data[strlen(header.getString()) + 8 + 5 + 2 + 1] = 'g';
data[strlen(header.getString()) + 8 + 5 + 2 + 2] = '\0';

View File

@@ -1,7 +1,7 @@
#include <bootloader/utility.h>
#include <string.h>
int Bootloader::Utility::versionSum(const char * version, int length) {
int Utility::versionSum(const char * version, int length) {
int sum = 0;
for (int i = 0; i < length; i++) {
sum += version[i] * (strlen(version) * 100 - i * 10);

View File

@@ -1,12 +1,10 @@
#ifndef _BOOTLOADER_ITOA_H_
#define _BOOTLOADER_ITOA_H_
namespace Bootloader {
class Utility {
public:
static char * itoa(int value, char * result, int base);
static int versionSum(const char * version, int length);
};
namespace Utility {
static char * itoa(int value, char * result, int base);
static int versionSum(const char * version, int length);
}
#endif