From 9b3a6cb5a44b0b7d2e4b4778d586aad8a2a97e65 Mon Sep 17 00:00:00 2001 From: 0x35c Date: Wed, 18 Sep 2024 22:30:11 +0200 Subject: [PATCH] style: clang-format on all files --- .clang-format | 9 ++++++ headers/kprintf.h | 20 ++++++------ headers/rtc.h | 33 +++++++++----------- headers/shell.h | 2 +- libbozo/src/ctype/isdigit.c | 2 +- libbozo/src/ctype/isprint.c | 2 +- libbozo/src/stdlib/atoi.c | 2 +- libbozo/src/stdlib/atol.c | 2 +- libbozo/src/stdlib/atoll.c | 14 ++++----- libbozo/src/string/memcmp.c | 17 +++++----- libbozo/src/string/strchr.c | 5 ++- libbozo/src/string/strlen.c | 2 +- libbozo/src/string/strstr.c | 5 ++- src/rtc/rtc.c | 62 ++++++++++++++++++------------------- src/shell/date.c | 38 ++++++++--------------- 15 files changed, 104 insertions(+), 111 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..edb6674 --- /dev/null +++ b/.clang-format @@ -0,0 +1,9 @@ +BasedOnStyle: LLVM +IndentWidth: 8 +UseTab: AlignWithSpaces +BreakBeforeBraces: Linux +AllowShortIfStatementsOnASingleLine: Never +AllowShortFunctionsOnASingleLine: Empty +IndentCaseLabels: false +ColumnLimit: 80 +AlignConsecutiveMacros: true diff --git a/headers/kprintf.h b/headers/kprintf.h index 83fc8f0..864ef52 100644 --- a/headers/kprintf.h +++ b/headers/kprintf.h @@ -3,16 +3,16 @@ #include 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, ...); diff --git a/headers/rtc.h b/headers/rtc.h index 146263a..c2ef476 100644 --- a/headers/rtc.h +++ b/headers/rtc.h @@ -2,32 +2,29 @@ #include -#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); \ No newline at end of file diff --git a/headers/shell.h b/headers/shell.h index 97bdb9c..481b078 100644 --- a/headers/shell.h +++ b/headers/shell.h @@ -53,7 +53,7 @@ typedef enum { ECHO, COLOR, MERDELLA, - DATE, + DATE, ERROR } CMD_TOK; diff --git a/libbozo/src/ctype/isdigit.c b/libbozo/src/ctype/isdigit.c index 38f1afd..ab8b14d 100644 --- a/libbozo/src/ctype/isdigit.c +++ b/libbozo/src/ctype/isdigit.c @@ -1,4 +1,4 @@ int isdigit(int c) { - return '9' >= c && c >= '0'; + return '9' >= c && c >= '0'; } \ No newline at end of file diff --git a/libbozo/src/ctype/isprint.c b/libbozo/src/ctype/isprint.c index 13781b1..20c825e 100644 --- a/libbozo/src/ctype/isprint.c +++ b/libbozo/src/ctype/isprint.c @@ -1,4 +1,4 @@ -int isprint(int c) +int isprint(int c) { return (32 <= c && c < 127); } \ No newline at end of file diff --git a/libbozo/src/stdlib/atoi.c b/libbozo/src/stdlib/atoi.c index 7d8595f..1d2f0df 100644 --- a/libbozo/src/stdlib/atoi.c +++ b/libbozo/src/stdlib/atoi.c @@ -2,5 +2,5 @@ int atoi(const char *str) { - return atoll(str); + return atoll(str); } \ No newline at end of file diff --git a/libbozo/src/stdlib/atol.c b/libbozo/src/stdlib/atol.c index 2ce9be3..f59c536 100644 --- a/libbozo/src/stdlib/atol.c +++ b/libbozo/src/stdlib/atol.c @@ -2,5 +2,5 @@ long atol(const char *str) { - return atoll(str); + return atoll(str); } \ No newline at end of file diff --git a/libbozo/src/stdlib/atoll.c b/libbozo/src/stdlib/atoll.c index 5355305..be5fa2f 100644 --- a/libbozo/src/stdlib/atoll.c +++ b/libbozo/src/stdlib/atoll.c @@ -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; } \ No newline at end of file diff --git a/libbozo/src/string/memcmp.c b/libbozo/src/string/memcmp.c index 4878061..bd4ac63 100644 --- a/libbozo/src/string/memcmp.c +++ b/libbozo/src/string/memcmp.c @@ -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]; } \ No newline at end of file diff --git a/libbozo/src/string/strchr.c b/libbozo/src/string/strchr.c index 4de6e27..2679bf5 100644 --- a/libbozo/src/string/strchr.c +++ b/libbozo/src/string/strchr.c @@ -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++; diff --git a/libbozo/src/string/strlen.c b/libbozo/src/string/strlen.c index 5cad17d..6482e6d 100644 --- a/libbozo/src/string/strlen.c +++ b/libbozo/src/string/strlen.c @@ -1,6 +1,6 @@ #include -size_t strlen(const char *str) +size_t strlen(const char *str) { const char *start = str; diff --git a/libbozo/src/string/strstr.c b/libbozo/src/string/strstr.c index 7353632..dc71691 100644 --- a/libbozo/src/string/strstr.c +++ b/libbozo/src/string/strstr.c @@ -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++; diff --git a/src/rtc/rtc.c b/src/rtc/rtc.c index 9204273..ff0164b 100644 --- a/src/rtc/rtc.c +++ b/src/rtc/rtc.c @@ -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; } \ No newline at end of file diff --git a/src/shell/date.c b/src/shell/date.c index 22d86c3..5d9bcb7 100644 --- a/src/shell/date.c +++ b/src/shell/date.c @@ -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); -} \ No newline at end of file + 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); +}