style: clang-format on all files

This commit is contained in:
0x35c 2024-09-18 22:30:11 +02:00
parent 083468240d
commit 9b3a6cb5a4
15 changed files with 104 additions and 111 deletions

9
.clang-format Normal file
View File

@ -0,0 +1,9 @@
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: AlignWithSpaces
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: Never
AllowShortFunctionsOnASingleLine: Empty
IndentCaseLabels: false
ColumnLimit: 80
AlignConsecutiveMacros: true

View File

@ -3,16 +3,16 @@
#include <stdarg.h>
enum print_level {
KERN_EMERG,
KERN_ALERT,
KERN_CRIT,
KERN_ERR,
KERN_WARNING,
KERN_NOTICE,
KERN_INFO,
KERN_DEBUG,
KERN_DEFAULT,
KERN_CONT
KERN_EMERG,
KERN_ALERT,
KERN_CRIT,
KERN_ERR,
KERN_WARNING,
KERN_NOTICE,
KERN_INFO,
KERN_DEBUG,
KERN_DEFAULT,
KERN_CONT
};
int kprintf(int level, const char *restrict format, ...);

View File

@ -2,32 +2,29 @@
#include <stdint.h>
#define SECOND_REGISTER 0x00
#define MINUTE_REGISTER 0x02
#define HOUR_REGISTER 0x04
#define DAY_OF_THE_WEEK_REGISTER 0x06
#define SECOND_REGISTER 0x00
#define MINUTE_REGISTER 0x02
#define HOUR_REGISTER 0x04
#define DAY_OF_THE_WEEK_REGISTER 0x06
#define DAY_OF_THE_MONTH_REGISTER 0x07
#define MONTH_REGISTER 0x08
#define YEAR_REGISTER 0x09
#define CENTURY_REGISTER 0x32
#define MONTH_REGISTER 0x08
#define YEAR_REGISTER 0x09
#define CENTURY_REGISTER 0x32
#define REGISTER_A 0x0A
#define REGISTER_B 0x0B
enum {
CMOS_ADDRESS = 0x70,
CMOS_DATA = 0x71
};
enum { CMOS_ADDRESS = 0x70, CMOS_DATA = 0x71 };
struct rtc_date {
uint8_t second;
uint8_t minute;
uint8_t hour;
uint8_t second;
uint8_t minute;
uint8_t hour;
uint8_t index_of_the_day;
uint8_t day;
uint8_t month;
uint32_t year;
uint8_t index_of_the_day;
uint8_t day;
uint8_t month;
uint32_t year;
};
struct rtc_date get_date(void);

View File

@ -53,7 +53,7 @@ typedef enum {
ECHO,
COLOR,
MERDELLA,
DATE,
DATE,
ERROR
} CMD_TOK;

View File

@ -1,4 +1,4 @@
int isdigit(int c)
{
return '9' >= c && c >= '0';
return '9' >= c && c >= '0';
}

View File

@ -1,4 +1,4 @@
int isprint(int c)
int isprint(int c)
{
return (32 <= c && c < 127);
}

View File

@ -2,5 +2,5 @@
int atoi(const char *str)
{
return atoll(str);
return atoll(str);
}

View File

@ -2,5 +2,5 @@
long atol(const char *str)
{
return atoll(str);
return atoll(str);
}

View File

@ -2,12 +2,12 @@
long long atoll(const char *str)
{
const char *start = str;
long long ret = 0;
const char *start = str;
long long ret = 0;
while (*start != '\0') {
if (isdigit(*str))
ret = ret * 10 + *str - '0';
}
return ret;
while (*start != '\0') {
if (isdigit(*str))
ret = ret * 10 + *str - '0';
}
return ret;
}

View File

@ -2,12 +2,13 @@
int memcmp(const void *s1, const void *s2, size_t n)
{
const char *str1 = s1;
const char *str2 = s2;
size_t i;
if (n == 0)
return 0;
for (i = 0; str1[i] == str2[i] && i < n - 1; i++);
return str1[i] - str2[i];
const char *str1 = s1;
const char *str2 = s2;
size_t i;
if (n == 0)
return 0;
for (i = 0; str1[i] == str2[i] && i < n - 1; i++)
;
return str1[i] - str2[i];
}

View File

@ -2,10 +2,9 @@
char *strchr(const char *str, int c)
{
char *start = (char *) str;
char *start = (char *)str;
while (*start)
{
while (*start) {
if (*start == c)
return start;
start++;

View File

@ -1,6 +1,6 @@
#include <stddef.h>
size_t strlen(const char *str)
size_t strlen(const char *str)
{
const char *start = str;

View File

@ -4,12 +4,11 @@
char *strstr(const char *haystack, const char *needle)
{
char *start = (char *) haystack;
char *start = (char *)haystack;
size_t len;
len = strlen(needle);
while (*start != '\0')
{
while (*start != '\0') {
if (strncmp(start, needle, len) == 0)
return start;
start++;

View File

@ -6,53 +6,53 @@
static uint16_t raw_read_register(uint16_t cmos_register)
{
//selecting the register
outb(CMOS_ADDRESS, cmos_register);
//read value of the selectect register
return inb(CMOS_DATA);
// selecting the register
outb(CMOS_ADDRESS, cmos_register);
// read value of the selectect register
return inb(CMOS_DATA);
}
static uint8_t update_is_in_progress(void)
{
return raw_read_register(REGISTER_A) & 0x80;
return raw_read_register(REGISTER_A) & 0x80;
}
static uint16_t read_register(uint16_t cmos_register)
{
while (update_is_in_progress())
kprintf(0, "%d\n", update_is_in_progress());
return raw_read_register(cmos_register);
while (update_is_in_progress())
kprintf(0, "%d\n", update_is_in_progress());
return raw_read_register(cmos_register);
}
uint8_t bcd_mode_to_bin(uint8_t value)
{
return (value & 0x0F) + ((value/ 16) * 10);
return (value & 0x0F) + ((value / 16) * 10);
}
struct rtc_date get_date(void)
{
struct rtc_date rv;
uint8_t century;
struct rtc_date rv;
uint8_t century;
rv.second = read_register(SECOND_REGISTER);
rv.minute = read_register(MINUTE_REGISTER);
rv.hour = read_register(HOUR_REGISTER);
rv.day = read_register(DAY_OF_THE_MONTH_REGISTER);
rv.index_of_the_day = read_register(DAY_OF_THE_WEEK_REGISTER) - 1;
rv.month = read_register(MONTH_REGISTER) - 1;
rv.year += read_register(YEAR_REGISTER);
century = read_register(CENTURY_REGISTER);
rv.second = read_register(SECOND_REGISTER);
rv.minute = read_register(MINUTE_REGISTER);
rv.hour = read_register(HOUR_REGISTER);
rv.day = read_register(DAY_OF_THE_MONTH_REGISTER);
rv.index_of_the_day = read_register(DAY_OF_THE_WEEK_REGISTER) - 1;
rv.month = read_register(MONTH_REGISTER) - 1;
rv.year += read_register(YEAR_REGISTER);
century = read_register(CENTURY_REGISTER);
if (!(read_register(REGISTER_B) & 0x04)) {
rv.second = bcd_mode_to_bin(rv.second);
rv.minute = bcd_mode_to_bin(rv.minute);
rv.hour = bcd_mode_to_bin(rv.hour);
rv.day = bcd_mode_to_bin(rv.day);
rv.index_of_the_day = bcd_mode_to_bin(rv.index_of_the_day);
rv.month = bcd_mode_to_bin(rv.month);
rv.year = bcd_mode_to_bin(rv.year);
century = bcd_mode_to_bin(century);
}
rv.year += century * 100 - 98; // -108 = bozo offset
return rv;
if (!(read_register(REGISTER_B) & 0x04)) {
rv.second = bcd_mode_to_bin(rv.second);
rv.minute = bcd_mode_to_bin(rv.minute);
rv.hour = bcd_mode_to_bin(rv.hour);
rv.day = bcd_mode_to_bin(rv.day);
rv.index_of_the_day = bcd_mode_to_bin(rv.index_of_the_day);
rv.month = bcd_mode_to_bin(rv.month);
rv.year = bcd_mode_to_bin(rv.year);
century = bcd_mode_to_bin(century);
}
rv.year += century * 100 - 98; // -108 = bozo offset
return rv;
}

View File

@ -1,30 +1,18 @@
#include "kprintf.h"
#include "rtc.h"
void date()
void date(void)
{
static const char *months[12] = {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December" };
static const char * week_days[] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday" };
struct rtc_date date = get_date();
static const char *months[12] = {"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"};
static const char *week_days[] = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday",
"Saturday"};
struct rtc_date date = get_date();
kprintf(0, "%s. %d %s. %d %d:%d:%d\n", week_days[date.index_of_the_day], date.day, months[date.month], date.year, date.hour, date.minute, date.second);
}
kprintf(0, "%s. %d %s. %d %d:%d:%d\n", week_days[date.index_of_the_day],
date.day, months[date.month], date.year, date.hour, date.minute,
date.second);
}