All: Clear lines with only whitspace in them

This commit is contained in:
Bananymous 2023-09-09 22:52:03 +03:00
parent d77f455065
commit 720bc418a6
67 changed files with 95 additions and 119 deletions

View File

@ -119,7 +119,7 @@ namespace BAN
m_size -= count;
m_data[m_size] = '\0';
}
void String::clear()
{
m_size = 0;

View File

@ -171,7 +171,7 @@ namespace BAN
{
return m_size;
}
const char* StringView::data() const
{
return m_data;

View File

@ -24,7 +24,7 @@ namespace BAN
leap_years++;
return leap_years;
}
static constexpr uint64_t month_days[] { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
uint64_t to_unix_time(const BAN::Time& time)

View File

@ -28,9 +28,8 @@ namespace BAN::Formatter
static size_t parse_format_and_print_argument(F putc, const char* format, T&& arg);
}
/*
IMPLEMENTATION
*/
@ -42,7 +41,7 @@ namespace BAN::Formatter
int fill = 0;
bool upper = false;
};
template<typename F>
void print(F putc, const char* format)
{
@ -232,7 +231,7 @@ namespace BAN::Formatter
}
/*
TEMPLATE SPECIALIZATIONS
*/
@ -245,5 +244,5 @@ namespace BAN::Formatter
template<typename F> void print_argument(F putc, bool value, const ValueFormat&) { print(putc, value ? "true" : "false"); }
template<typename F> void print_argument(F putc, const char* value, const ValueFormat&) { print(putc, value); }
template<typename F> void print_argument(F putc, char* value, const ValueFormat&) { print(putc, value); }
}

View File

@ -5,7 +5,7 @@
namespace BAN
{
template<typename, size_t> class Array;
template<typename> class ErrorOr;
template<typename> class Function;

View File

@ -85,8 +85,6 @@ namespace BAN
friend class HashSet<T, HASH>;
};
template<typename T, typename HASH>
HashSet<T, HASH>::HashSet(const HashSet<T, HASH>& other)
: m_buckets(other.m_buckets)
@ -231,8 +229,6 @@ namespace BAN
return m_buckets[index];
}
template<typename T, typename HASH>
HashSetIterator<T, HASH>& HashSetIterator<T, HASH>::operator++()
{

View File

@ -9,7 +9,7 @@ namespace BAN
template<typename T, bool CONST>
class LinkedListIterator;
template<typename T>
class LinkedList
{
@ -114,8 +114,6 @@ namespace BAN
friend class LinkedListIterator<T, !CONST>;
};
template<typename T>
LinkedList<T>& LinkedList<T>::operator=(const LinkedList<T>& other)
{
@ -293,8 +291,6 @@ namespace BAN
return node;
}
template<typename T, bool CONST>
template<bool C>
LinkedListIterator<T, CONST>::LinkedListIterator(const LinkedListIterator<T, C>& other, enable_if_t<C == CONST || !C>*)
@ -379,7 +375,7 @@ namespace BAN
ASSERT(m_current);
return &m_current->value;
}
template<typename T, bool CONST>
bool LinkedListIterator<T, CONST>::operator==(const LinkedListIterator<T, CONST>& other) const
{

View File

@ -132,7 +132,7 @@ namespace BAN
ASSERT(has_value());
return value();
}
template<typename T>
const T& Optional<T>::operator*() const
{
@ -160,7 +160,7 @@ namespace BAN
ASSERT(has_value());
return (const T&)m_storage;
}
template<typename T>
T& Optional<T>::value()
{

View File

@ -2,7 +2,7 @@
namespace BAN
{
template<typename T> struct remove_refenrece { using type = T; };
template<typename T> struct remove_refenrece<T&> { using type = T; };
template<typename T> struct remove_refenrece<T&&> { using type = T; };
@ -68,7 +68,7 @@ namespace BAN
template<typename T> struct is_const : false_type {};
template<typename T> struct is_const<const T> : true_type {};
template<typename T> inline constexpr bool is_const_v = is_const<T>::value;
template<typename T> struct is_arithmetic { static constexpr bool value = is_integral_v<T> || is_floating_point_v<T>; };
template<typename T> inline constexpr bool is_arithmetic_v = is_arithmetic<T>::value;

View File

@ -253,7 +253,7 @@ namespace BAN
return true;
return false;
}
template<typename T>
const T& Vector<T>::operator[](size_type index) const
{

View File

@ -158,7 +158,7 @@ namespace LibELF
bool ELF::is_x86_64() const { return m_data[EI_CLASS] == ELFCLASS64; }
/*
64 bit ELF
*/
@ -280,9 +280,8 @@ namespace LibELF
return *(const Elf64SectionHeader*)(m_data.data() + file_header.e_shoff + file_header.e_shentsize * index);
}
/*
32 bit ELF
*/
@ -404,5 +403,4 @@ namespace LibELF
return *(const Elf32SectionHeader*)(m_data.data() + file_header.e_shoff + file_header.e_shentsize * index);
}
}

View File

@ -78,7 +78,6 @@ namespace LibELF
Elf32Word p_align;
};
using Elf64Addr = uint64_t;
using Elf64Off = uint64_t;
using Elf64Half = uint16_t;

View File

@ -1,6 +1,6 @@
#!/bin/bash
set -e
BOCHS_CONFIG_FILE=bochsrc
COM1_TERMINAL=kitty
COM1_DEVICE_FILE=com1-term-device

View File

@ -154,7 +154,7 @@ found:
"popa;"
"iret;"
);
extern "C" void syscall_asm();
asm(
".global syscall_asm;"

View File

@ -207,7 +207,6 @@ namespace Kernel
unmap_page(page);
}
uint8_t MMU::get_page_flags(vaddr_t address) const
{
uint32_t pdpte = (address & 0xC0000000) >> 30;

View File

@ -16,7 +16,7 @@ extern uint8_t g_userspace_end[];
namespace Kernel
{
static PageTable* s_kernel = nullptr;
static PageTable* s_current = nullptr;
static bool s_has_nxe = false;

View File

@ -35,7 +35,7 @@
.skip 16384
.global g_boot_stack_top
g_boot_stack_top:
.global g_kernel_cmdline
g_kernel_cmdline:
.skip 4096

View File

@ -104,7 +104,7 @@ void __cxa_finalize(void *f)
**/
(*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr);
__atexit_funcs[i].destructor_func = 0;
/*
* Notice that we didn't decrement __atexit_func_count: this is because this algorithm
* requires patching to deal with the FIXME outlined above.
@ -113,8 +113,6 @@ void __cxa_finalize(void *f)
};
};
namespace __cxxabiv1
{
/* guard variables */
@ -122,19 +120,19 @@ namespace __cxxabiv1
/* The ABI requires a 64-bit type. */
__extension__ typedef int __guard __attribute__((mode(__DI__)));
int __cxa_guard_acquire (__guard* g)
{
Kernel::LockGuard lock_guard(s_spin_lock);
return !*(int*)g;
}
void __cxa_guard_release (__guard* g)
{
Kernel::LockGuard lock_guard(s_spin_lock);
*(int*)g = 1;
}
void __cxa_guard_abort (__guard*)
{
Kernel::panic("__cxa_guard_abort");

View File

@ -11,7 +11,7 @@ namespace Kernel::API
struct dirent dirent;
DirectoryEntry* next() const { return (DirectoryEntry*)((uintptr_t)this + rec_len); }
};
struct DirectoryEntryList
{
size_t entry_count { 0 };

View File

@ -73,7 +73,7 @@ namespace CPUID
const char* feature_string_ecx(uint32_t feat);
const char* feature_string_edx(uint32_t feat);
const char* get_vendor();
void get_features(uint32_t& ecx, uint32_t& edx);
bool is_64_bit();

View File

@ -11,7 +11,7 @@ namespace Kernel
{
BAN_NON_COPYABLE(CriticalScope);
BAN_NON_MOVABLE(CriticalScope);
public:
CriticalScope()
{

View File

@ -18,7 +18,7 @@ namespace Kernel
virtual BAN::ErrorOr<size_t> read_impl(off_t, void*, size_t) override { return 0; }
virtual BAN::ErrorOr<size_t> write_impl(off_t, const void*, size_t size) override { return size; };
private:
const dev_t m_rdev;
};

View File

@ -18,7 +18,7 @@ namespace Kernel
virtual BAN::ErrorOr<size_t> read_impl(off_t, void*, size_t) override;
virtual BAN::ErrorOr<size_t> write_impl(off_t, const void*, size_t size) override { return size; };
private:
const dev_t m_rdev;
};

View File

@ -5,7 +5,7 @@
namespace Kernel
{
class DevFileSystem final : public RamFileSystem
{
public:
@ -13,7 +13,7 @@ namespace Kernel
static DevFileSystem& get();
void initialize_device_updater();
void add_device(BAN::StringView path, BAN::RefPtr<RamInode>);
dev_t get_next_dev();

View File

@ -4,7 +4,7 @@
namespace Kernel
{
class FileSystem
{
public:

View File

@ -6,7 +6,7 @@
namespace Kernel
{
class RamInode;
class RamDirectoryInode;

View File

@ -14,7 +14,7 @@ namespace Kernel
public:
static BAN::ErrorOr<BAN::RefPtr<RamInode>> create(RamFileSystem&, mode_t, uid_t, gid_t);
virtual ~RamInode() = default;
virtual ino_t ino() const override { return m_inode_info.ino; }
virtual Mode mode() const override { return { m_inode_info.mode }; }
virtual nlink_t nlink() const override { return m_inode_info.nlink; }
@ -80,7 +80,7 @@ namespace Kernel
private:
RamDirectoryInode(RamFileSystem&, ino_t parent, mode_t, uid_t, gid_t);
private:
static constexpr size_t m_name_max = NAME_MAX;
struct Entry
@ -106,7 +106,7 @@ namespace Kernel
virtual off_t size() const override { return m_target.size(); }
BAN::ErrorOr<void> set_link_target(BAN::StringView);
protected:
virtual BAN::ErrorOr<BAN::String> link_target_impl() override;
@ -115,7 +115,7 @@ namespace Kernel
private:
BAN::String m_target;
friend class RamFileSystem;
};

View File

@ -22,7 +22,7 @@ namespace Kernel
{
m_lock.unlock();
}
private:
Lock& m_lock;
};

View File

@ -8,7 +8,7 @@
namespace Kernel
{
class Heap
{
BAN_NON_COPYABLE(Heap);

View File

@ -18,5 +18,5 @@ namespace Kernel
using vaddr_t = uintptr_t;
using paddr_t = uintptr_t;
}

View File

@ -30,7 +30,7 @@ namespace Kernel
virtual dev_t rdev() const override { return m_rdev; }
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) { return BAN::Error::from_errno(ENOTSUP); }
private:
const dev_t m_rdev;
};

View File

@ -52,7 +52,7 @@ namespace Kernel
protected:
virtual BAN::ErrorOr<size_t> read_impl(off_t, void*, size_t) override;
private:
const dev_t m_rdev;
};

View File

@ -42,7 +42,7 @@ namespace Kernel
virtual uint32_t width() const override;
virtual uint32_t height() const override;
virtual void putchar(uint8_t) override;
virtual void update() override;
protected:
@ -55,7 +55,7 @@ namespace Kernel
private:
BAN::String m_name;
Serial m_serial;
public:
virtual dev_t rdev() const override { return m_rdev; }
private:

View File

@ -11,7 +11,7 @@
namespace Kernel
{
class VirtualTTY : public TTY
{
public:

View File

@ -8,5 +8,5 @@ namespace Kernel
bool canonical { true };
bool echo { true };
};
}

View File

@ -118,5 +118,5 @@ namespace Kernel
friend class Scheduler;
};
}

View File

@ -9,7 +9,7 @@ namespace Kernel
{
public:
BAN::Time get_current_time();
private:
bool is_update_in_progress();
uint8_t read_register8(uint8_t reg);

View File

@ -12,7 +12,6 @@ namespace Kernel
return BAN::RefPtr<ZeroDevice>::adopt(result);
}
BAN::ErrorOr<size_t> ZeroDevice::read_impl(off_t, void* buffer, size_t bytes)
{
memset(buffer, 0, bytes);

View File

@ -12,7 +12,7 @@ namespace Kernel
return BAN::Error::from_errno(ENOMEM);
return BAN::RefPtr<Inode>::adopt(pipe);
}
Pipe::Pipe(const Credentials& credentials)
: m_uid(credentials.euid())
, m_gid(credentials.egid())
@ -29,7 +29,7 @@ namespace Kernel
ASSERT(m_writing_count > 0);
m_writing_count++;
}
void Pipe::close_writing()
{
LockGuard _(m_lock);
@ -63,7 +63,7 @@ namespace Kernel
return to_copy;
}
BAN::ErrorOr<size_t> Pipe::write_impl(off_t, const void* buffer, size_t count)
{
LockGuard _(m_lock);
@ -81,5 +81,5 @@ namespace Kernel
return count;
}
}

View File

@ -6,7 +6,7 @@ namespace Kernel
{
/*
RAM INODE
*/
@ -68,7 +68,7 @@ namespace Kernel
}
/*
RAM DIRECTORY INODE
*/
@ -217,7 +217,7 @@ namespace Kernel
}
/*
RAM SYMLINK INODE
*/

View File

@ -35,7 +35,7 @@ namespace Kernel
auto* tmpfs = MUST(RamFileSystem::create(1024 * 1024, tmpfs_mode, 0, 0));
MUST(s_instance->mount(root_creds, tmpfs, "/tmp"));
}
VirtualFileSystem& VirtualFileSystem::get()
{
ASSERT(s_instance);

View File

@ -245,7 +245,7 @@ namespace Kernel
result.m_pitch = header.glyph_size / header.height;
return result;
}
bool Font::has_glyph(uint32_t codepoint) const
{
return m_glyph_offsets.contains(codepoint);

View File

@ -121,7 +121,7 @@ namespace Kernel::Input
}
m_command_queue.push(byte);
}
void PS2Keyboard::append_command_queue(uint8_t byte1, uint8_t byte2)
{
if (m_command_queue.size() + 2 > m_command_queue.capacity())

View File

@ -59,7 +59,7 @@ namespace Kernel
return page;
return 0;
}
void Heap::release_page(paddr_t addr)
{
LockGuard _(m_lock);

View File

@ -192,7 +192,7 @@ static void* kmalloc_fixed()
// allocate the node on top of free list
auto* node = info.free_list_head;
ASSERT(node->next == kmalloc_fixed_info::node::invalid);
// remove the node from free list
if (info.free_list_head->prev != kmalloc_fixed_info::node::invalid)
{
@ -326,7 +326,7 @@ void* kmalloc(size_t size, size_t align, bool force_indentity_map)
if (ptrdiff_t rem = size % s_kmalloc_min_align)
size += s_kmalloc_min_align - rem;
if (void* res = kmalloc_impl(size, align))
return res;

View File

@ -7,7 +7,6 @@
namespace Kernel
{
OpenFileDescriptorSet::OpenFileDescriptorSet(const Credentials& credentials)
: m_credentials(credentials)
{

View File

@ -995,7 +995,7 @@ namespace Kernel
auto inode = TRY(m_open_file_descriptors.inode_of(fd));
if (!inode->is_tty())
return BAN::Error::from_errno(ENOTTY);
if ((TTY*)inode.ptr() != m_controlling_terminal.ptr())
return BAN::Error::from_errno(ENOTTY);

View File

@ -2,13 +2,13 @@
#include <stdint.h>
#include <stdlib.h>
#if UINT32_MAX == UINTPTR_MAX
#define STACK_CHK_GUARD 0xe2dee396
#else
#define STACK_CHK_GUARD 0x595e9fbd94fda766
#endif
uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
__BEGIN_DECLS

View File

@ -304,7 +304,7 @@ namespace Kernel
execute_current_thread();
ASSERT_NOT_REACHED();
}
void Scheduler::unblock_threads(Semaphore* semaphore)
{
CriticalScope critical;

View File

@ -323,5 +323,5 @@ namespace Kernel
return {};
}
}

View File

@ -181,7 +181,7 @@ namespace Kernel
{
return s_has_devices;
}
void Serial::putchar(char c)
{
while (!(IO::inb(m_port + 5) & 0x20))
@ -275,7 +275,7 @@ namespace Kernel
if (m_serial.port() == COM2_PORT)
update_com(s_com2, s_com2_input);
}
uint32_t SerialTTY::width() const
{
return m_serial.width();
@ -285,7 +285,7 @@ namespace Kernel
{
return m_serial.height();
}
void SerialTTY::putchar(uint8_t ch)
{
m_serial.putchar(ch);

View File

@ -57,7 +57,6 @@ VesaTerminalDriver* VesaTerminalDriver::create()
return driver;
}
VesaTerminalDriver::~VesaTerminalDriver()
{
PageTable::kernel().unmap_range(m_address, m_pitch * m_height);

View File

@ -25,7 +25,6 @@ namespace Kernel
memcpy((void*)rsp, (void*)&value, sizeof(uintptr_t));
}
Thread::TerminateBlocker::TerminateBlocker(Thread& thread)
: m_thread(thread)
{

View File

@ -47,7 +47,7 @@ namespace Kernel
void PIT::initialize()
{
constexpr uint16_t timer_reload = BASE_FREQUENCY / TICKS_PER_SECOND;
IO::outb(PIT_CTL, SELECT_CHANNEL0 | ACCESS_LO | ACCESS_HI | MODE_SQUARE_WAVE);
IO::outb(TIMER0_CTL, (timer_reload >> 0) & 0xff);

View File

@ -169,7 +169,7 @@ static void init2(void*)
PCI::initialize();
dprintln("PCI initialized");
VirtualFileSystem::initialize(cmdline.root);
if (auto res = PS2Controller::initialize(); res.is_error())

View File

@ -10,14 +10,14 @@ extern "C"
uint32_t line;
uint32_t column;
};
struct type_descriptor
{
uint16_t kind;
uint16_t info;
char name[1];
};
struct type_mismatch_data
{
source_location location;
@ -25,7 +25,7 @@ extern "C"
uint8_t alignment;
uint8_t type_check_kind;
};
struct out_of_bounds_data
{
source_location location;

View File

@ -24,7 +24,7 @@ int closedir(DIR* dirp)
errno = EBADF;
return -1;
}
close(dirp->fd);
dirp->fd = -1;
free(dirp);

View File

@ -49,7 +49,6 @@ size_t strxfrm_l(char* __restrict s1, const char* __restrict s2, size_t n, local
const char* strerrorname_np(int error);
const char* strerrordesc_np(int error);
__END_DECLS
#endif

View File

@ -87,7 +87,6 @@ struct stat
#define UTIME_NOW 1000000001
#define UTIME_OMIT 1000000002
int chmod(const char* path, mode_t mode);
int fchmod(int fildes, mode_t mode);
int fchmodat(int fd, const char* path, mode_t mode, int flag);

View File

@ -77,7 +77,7 @@ static void integer_to_string(char* buffer, T value, int base, bool upper, forma
prefix[1] = 'x';
}
}
while (value || offset < digits)
{
buffer[offset++] = digit_char(value % base, upper);
@ -171,7 +171,7 @@ static void floating_point_to_string(char* buffer, T value, bool upper, const fo
return;
}
buffer[offset++] = '.';
// Add the 'percision' digits after decimal point
for (int i = 0; i < percision; i++)
{
@ -193,7 +193,7 @@ static void floating_point_to_exponent_string(char* buffer, T value, bool upper,
int percision = 6;
if (options.percision != -1)
percision = options.percision;
int offset = 0;
// Add sign if needed
@ -465,7 +465,6 @@ extern "C" int printf_impl(const char* format, va_list arguments, int (*putc_fun
format++;
}
}
return written;
}

View File

@ -50,7 +50,7 @@ struct passwd* getpwent(void)
if (!open_pwent())
return nullptr;
clear_pwent(s_pwent_struct);
BAN::String line;
while (true)
{

View File

@ -62,7 +62,7 @@ FILE* fdopen(int fd, const char* mode)
return &s_files[i];
}
}
errno = EMFILE;
return nullptr;
}
@ -90,7 +90,7 @@ int fflush(FILE* file)
if (file->buffer_index == 0)
return 0;
if (syscall(SYS_WRITE, file->fd, file->buffer, file->buffer_index) < 0)
{
file->error = true;
@ -105,7 +105,7 @@ int fgetc(FILE* file)
{
if (file->eof)
return EOF;
unsigned char c;
long ret = syscall(SYS_READ, file->fd, &c, 1);
@ -114,7 +114,7 @@ int fgetc(FILE* file)
file->error = true;
return EOF;
}
if (ret == 0)
{
file->eof = true;
@ -217,7 +217,7 @@ FILE* fopen(const char* pathname, const char* mode)
return &s_files[i];
}
}
errno = EMFILE;
return nullptr;
}
@ -293,7 +293,7 @@ int fseeko(FILE* file, off_t offset, int whence)
long ret = syscall(SYS_SEEK, file->fd, offset, whence);
if (ret < 0)
return -1;
file->eof = false;
return 0;
}
@ -353,7 +353,7 @@ char* gets(char* buffer)
return nullptr;
unsigned char* ubuffer = (unsigned char*)buffer;
int first = fgetc(stdin);
if (first == EOF)
return nullptr;
@ -529,7 +529,7 @@ int vsprintf(char* buffer, const char* format, va_list arguments)
{
if (buffer == nullptr)
return printf_impl(format, arguments, [](int, void*) { return 0; }, nullptr);
int ret = printf_impl(format, arguments,
[](int c, void* _buffer)
{

View File

@ -205,7 +205,6 @@ void free(void* ptr)
syscall(SYS_FREE, ptr);
}
// Constants and algorithm from https://en.wikipedia.org/wiki/Permuted_congruential_generator
static uint64_t s_rand_state = 0x4d595df4d0f33173;

View File

@ -273,7 +273,6 @@ const char* strerrordesc_np(int error)
return "Unknown error";
}
size_t strlen(const char* str)
{
size_t len = 0;

View File

@ -32,11 +32,11 @@ long syscall(long syscall, ...)
uintptr_t arg3 = va_arg(args, uintptr_t);
uintptr_t arg4 = va_arg(args, uintptr_t);
uintptr_t arg5 = va_arg(args, uintptr_t);
va_end(args);
long ret = Kernel::syscall(syscall, arg1, arg2, arg3, arg4, arg5);
if (ret < 0)
{
errno = -ret;
@ -78,7 +78,7 @@ int execl(const char* pathname, const char* arg0, ...)
char* temp = nullptr;
return execv(pathname, &temp);
}
va_list ap;
va_start(ap, arg0);
int argc = 1;

View File

@ -1,6 +1,6 @@
#!/bin/bash
set -e
qemu-system-$BANAN_ARCH \
-m 128 \
-smp 2 \

View File

@ -51,9 +51,9 @@ void list_directory(const char* path)
DIR* dirp = opendir(path);
if (dirp == nullptr)
return perror("opendir");
errno = 0;
bool first = true;
while (auto* dirent = readdir(dirp))
{