Format files

This commit is contained in:
Jessica Creighton 2019-04-03 17:46:58 -04:00
parent bc6f94e353
commit 3fe2d7aa33
21 changed files with 1117 additions and 1125 deletions

10
.clang-format Normal file
View File

@ -0,0 +1,10 @@
---
DerivePointerAlignment: 'true'
SpaceBeforeParens: ControlStatements
UseTab: ForIndentation
IndentWidth: 2
TabWidth: 2
ColumnLimit: 120
BreakBeforeBraces: Attach
...

65
arch/i386/tty.c Executable file → Normal file
View File

@ -31,9 +31,7 @@ void screen_initialize(void) {
}
}
void term_setcolor(enum vga_colors color) {
current_color = color;
}
void term_setcolor(enum vga_colors color) { current_color = color; }
void term_putentryat(char c, uint8_t color, size_t x, size_t y) {
const size_t offset = y * TERM_WIDTH + x;
@ -60,21 +58,18 @@ void term_putchar(char c) {
}
break;
}
}
struct csi_sequence parse_csi(const char* data, size_t size) {
enum State { PARAMETER, INTERMEDIATE, FINAL, INVALID };
enum State state = PARAMETER;
struct csi_sequence sequence = {
.parameter = NULL,
struct csi_sequence sequence = {.parameter = NULL,
.parameter_len = 0,
.intermediate = NULL,
.intermediate_len = 0,
.final = NULL,
.valid = false
};
.valid = false};
for (size_t j = 0; j < size; j++) {
uint8_t c = data[j];
@ -121,8 +116,7 @@ void term_write(const char* data, size_t size) {
handleControlSequence(sequence);
i += sequence.parameter_len + sequence.intermediate_len + 2; // Move past sequence
}
}
break;
} break;
// Single shifts are not handled, so just print them and exit
case 'N': // SS2 - Single Shift Two
term_writes("Single Shift Two\n");
@ -161,9 +155,7 @@ void term_write(const char* data, size_t size) {
}
}
void term_writes(const char* data) {
term_write(data, strlen(data));
}
void term_writes(const char* data) { term_write(data, strlen(data)); }
void puts(const char* string) {
term_write(string, strlen(string));
@ -193,43 +185,53 @@ void handleControlSequence(struct csi_sequence sequence) {
}
switch (*(sequence.final)) {
case 'H': case 'f': // CUP - Cursor Position
case 'H':
case 'f': // CUP - Cursor Position
// TODO: Check to see if we have 2 paramaters
if (params[0]) params[0]--;
if (params[1]) params[1]--;
if (params[0])
params[0]--;
if (params[1])
params[1]--;
set_cursor(params[0], params[1]);
break;
case 'A': // CUU - Cursor Up
if (!params[0]) params[0] = 1;
if (!params[0])
params[0] = 1;
set_cursor(terminal_column, terminal_row - params[0]);
break;
case 'B': // CUD - Cursor Down
if (!params[0]) params[0] = 1;
if (!params[0])
params[0] = 1;
set_cursor(terminal_column, terminal_row + params[0]);
break;
case 'C': // CUF - Cursor Forward
if (!params[0]) params[0] = 1;
if (!params[0])
params[0] = 1;
set_cursor(terminal_column + params[0], terminal_row);
break;
case 'D': // CUB - Cursor Back
if (!params[0]) params[0] = 1;
if (!params[0])
params[0] = 1;
set_cursor(terminal_column - params[0], terminal_row);
break;
case 'E': // CNL - Cursor Next Line
if (!params[0]) params[0] = 1;
if (!params[0])
params[0] = 1;
set_cursor(0, terminal_row + params[0]);
break;
case 'F': // CPL - Cursor Previous Line
if (!params[0]) params[0] = 1;
if (!params[0])
params[0] = 1;
set_cursor(0, terminal_row - params[0]);
break;
case 'G': // CHA - Cursor Horizontal Absolute
if (params[0]) params[0]--;
if (params[0])
params[0]--;
set_cursor(params[0], terminal_row);
break;
case 'J': // ED - Erase in Display
//current cursor pos = y * width + x
{
// current cursor pos = y * width + x
int pos = terminal_row * 80 + terminal_column;
if (params[0] == 0) { // Clear from cursor to end of screen
for (; pos < (25 * 80); pos++) {
@ -245,8 +247,8 @@ void handleControlSequence(struct csi_sequence sequence) {
vga_buffer[0] = '\0';
}
}
}
break;
}
case 'K': // EL - Erase in Line
{
int pos = terminal_row * 80 + terminal_column;
@ -267,8 +269,8 @@ void handleControlSequence(struct csi_sequence sequence) {
vga_buffer[pos] = '\0';
}
}
}
break;
}
case 'S': // SU - Scroll Up
term_scroll(true);
break;
@ -277,12 +279,9 @@ void handleControlSequence(struct csi_sequence sequence) {
break;
}
}
}
bool isDigit(char c) {
return c >= '0' && c <= '9';
}
bool isDigit(char c) { return c >= '0' && c <= '9'; }
void set_cursor(int n, int m) {
terminal_column = n;
@ -308,8 +307,10 @@ void term_scroll(bool down) {
}
} else {
while (current_pos <= 4000) {
term_buffer[current_pos - 160 /*The character immediately below it*/] = vga_buffer[current_pos]; //Move each character up a line
term_buffer[current_pos - 159 /*The color of the character below*/] = vga_buffer[current_pos + 1]; //As well as its color
term_buffer[current_pos - 160 /*The character immediately below it*/] =
vga_buffer[current_pos]; // Move each character up a line
term_buffer[current_pos - 159 /*The color of the character below*/] =
vga_buffer[current_pos + 1]; // As well as its color
current_pos += 2; // Move to next char
}
}

9
include/arch/i386/vga.h Executable file → Normal file
View File

@ -3,7 +3,6 @@
#include <stdint.h>
enum vga_colors {
BLACK = 0,
BLUE = 1,
@ -23,12 +22,8 @@ enum vga_colors {
WHITE = 15
};
static inline uint8_t vga_color_set(enum vga_colors fg, enum vga_colors bg) {
return fg | bg << 4;
}
static inline uint8_t vga_color_set(enum vga_colors fg, enum vga_colors bg) { return fg | bg << 4; }
static inline uint16_t vga_entry(unsigned char uc, uint8_t color) {
return (uint16_t) uc | (uint16_t) color << 8;
}
static inline uint16_t vga_entry(unsigned char uc, uint8_t color) { return (uint16_t)uc | (uint16_t)color << 8; }
#endif

1
include/kernel/tty.h Executable file → Normal file
View File

@ -15,7 +15,6 @@ struct csi_sequence {
bool valid;
};
void term_setcolor(enum vga_colors);
void screen_initialize(void);
void term_putentryat(char, uint8_t, size_t, size_t);

9
include/vga.h Executable file → Normal file
View File

@ -2,7 +2,6 @@
#include <stdint.h>
enum vga_colors {
BLACK = 0,
BLUE = 1,
@ -22,10 +21,6 @@ enum vga_colors {
WHITE = 15
};
static inline uint8_t vga_color_set(enum vga_colors fg, enum vga_colors bg) {
return fg | bg << 4;
}
static inline uint8_t vga_color_set(enum vga_colors fg, enum vga_colors bg) { return fg | bg << 4; }
static inline uint16_t vga_entry(unsigned char uc, uint8_t color) {
return (uint16_t) uc | (uint16_t) color << 8;
}
static inline uint16_t vga_entry(unsigned char uc, uint8_t color) { return (uint16_t)uc | (uint16_t)color << 8; }

3
kernel/kernel.c Executable file → Normal file
View File

@ -15,6 +15,7 @@ int kernel_main(void) {
term_setcolor(WHITE);
term_writes(", 2019\n");
for(;;) {}
for (;;) {
}
return 0;
}

10
kernel/syscalls.c Executable file → Normal file
View File

@ -1,10 +1,10 @@
/*#include <sys/stat.h>
#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/times.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <stdio.h>
#include <sys/errno.h>
#include <sys/fcntl.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
//prototypes; these are the bare minimum for newlib to compile.

0
kernel/utils.c Executable file → Normal file
View File

17
libc/include/stdlib.h Executable file → Normal file
View File

@ -3,8 +3,7 @@
#include <sys/cdefs.h>
__attribute__((__noreturn__))
void abort(void);
__attribute__((__noreturn__)) void abort(void);
/*
Default header file for malloc-2.8.x, written by Doug Lea
@ -202,7 +201,6 @@ int mallopt(int, int);
#define M_GRANULARITY (-2)
#define M_MMAP_THRESHOLD (-3)
/*
malloc_footprint();
Returns the number of bytes obtained from the system. The total
@ -280,8 +278,7 @@ size_t malloc_set_footprint_limit(size_t bytes);
malloc_inspect_all is compiled only if MALLOC_INSPECT_ALL is defined.
*/
void malloc_inspect_all(void(*handler)(void*, void *, size_t, void*),
void* arg);
void malloc_inspect_all(void (*handler)(void*, void*, size_t, void*), void* arg);
#if !NO_MALLINFO
/*
@ -577,10 +574,8 @@ void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
void* mspace_realloc(mspace msp, void* mem, size_t newsize);
void* mspace_realloc_in_place(mspace msp, void* mem, size_t newsize);
void* mspace_memalign(mspace msp, size_t alignment, size_t bytes);
void** mspace_independent_calloc(mspace msp, size_t n_elements,
size_t elem_size, void* chunks[]);
void** mspace_independent_comalloc(mspace msp, size_t n_elements,
size_t sizes[], void* chunks[]);
void** mspace_independent_calloc(mspace msp, size_t n_elements, size_t elem_size, void* chunks[]);
void** mspace_independent_comalloc(mspace msp, size_t n_elements, size_t sizes[], void* chunks[]);
size_t mspace_bulk_free(mspace msp, void**, size_t n_elements);
size_t mspace_usable_size(const void* mem);
void mspace_malloc_stats(mspace msp);
@ -589,9 +584,7 @@ size_t mspace_footprint(mspace msp);
size_t mspace_max_footprint(mspace msp);
size_t mspace_footprint_limit(mspace msp);
size_t mspace_set_footprint_limit(mspace msp, size_t bytes);
void mspace_inspect_all(mspace msp,
void(*handler)(void *, void *, size_t, void*),
void* arg);
void mspace_inspect_all(mspace msp, void (*handler)(void*, void*, size_t, void*), void* arg);
#endif /* MSPACES */
#ifdef __cplusplus

2
libc/include/string.h Executable file → Normal file
View File

@ -1,8 +1,8 @@
#ifndef _STRING_H
#define _STRING_H 1
#include <sys/cdefs.h>
#include <stddef.h>
#include <sys/cdefs.h>
int memcmp(const void*, const void*, size_t);
void* memcpy(void* __restrict, const void* __restrict, size_t);

5
libc/stdio/printf.c Executable file → Normal file
View File

@ -1,6 +1,6 @@
#include <limits.h>
#include <stdbool.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
@ -8,8 +8,7 @@ static bool print(const char* data, size_t length) {
const unsigned char* bytes = (const unsigned char*)data;
for (size_t i = 0; i < length; i++)
if (putchar(bytes[i]) == EOF)
return false'
return true;
return false' return true;
}
int printf(const char* restrict format, ...) {

0
libc/stdio/putchar.c Executable file → Normal file
View File

6
libc/stdlib/abort.c Executable file → Normal file
View File

@ -1,8 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
__attribute__((__noreturn__))
void abort(void) {
__attribute__((__noreturn__)) void abort(void) {
#if defined(__is_libk)
// TODO: Kernel panic.
@ -10,6 +9,7 @@ void abort(void) {
#else
printf("abort() called\n");
#endif
while(1) {}
while (1) {
}
__builtin_unreachable();
}

0
libc/string/memcmp.c Executable file → Normal file
View File

0
libc/string/memmove.c Executable file → Normal file
View File

0
libc/string/memset.c Executable file → Normal file
View File

3
libc/string/strlen.c Executable file → Normal file
View File

@ -3,6 +3,5 @@
size_t strlen(const char* str) {
size_t len = 0;
while (str[len])
len++
return len;
len++ return len;
}