From 22530a31b15544f36d84d6930fd96410c272f391 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 14 May 2026 23:05:49 +0200 Subject: [PATCH 01/13] Add rev.c for reversing strings and file lines Implement a command-line utility to reverse strings or lines from a file. --- src/userland/cli/rev.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/userland/cli/rev.c diff --git a/src/userland/cli/rev.c b/src/userland/cli/rev.c new file mode 100644 index 0000000..4d1262f --- /dev/null +++ b/src/userland/cli/rev.c @@ -0,0 +1,43 @@ +// Copyright (c) 2026 janevers (https://github.com/zeyadhost) +// This software is released under the GNU General Public License v3.0. See LICENSE file for details. +// This header needs to maintain in any file it is present in, as per the GPL license terms. + +#include +#include +#include +#include + +// reverse function +void reverse(char *str) { + int len = strlen(str); + for (int i = 0; i < len / 2; i++) { + char tmp = str[i]; + str[i] = str[len - 1 - i]; + str[len - 1 - i] = tmp; + } +} + +int main(int argc, char *argv[]) { + // check if there are too much flags + if (argc != 2) { + printf("Wrong input, use --help for more info\n"); + return 1; + } + + FILE *fp = fopen(argv[1], "r"); + // check if the argument is a file or not by opening it + if (fp == NULL) { + reverse(argv[1]); + printf("%s\n", argv[1]); + return 0; + } + // reverse if flag is a file + char line[1024]; + while (fgets(line, sizeof(line), fp)) { + line[strcspn(line, "\n")] = '\0'; + reverse(line); + printf("%s\n", line); + } + fclose(fp); + return 0; +} From e5504c15f4a1f78c073215680ebc1f51f65f0087 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 16:53:59 +0200 Subject: [PATCH 02/13] Add help message for rev command usage --- src/userland/cli/rev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/userland/cli/rev.c b/src/userland/cli/rev.c index 4d1262f..ae05ed3 100644 --- a/src/userland/cli/rev.c +++ b/src/userland/cli/rev.c @@ -23,6 +23,12 @@ int main(int argc, char *argv[]) { printf("Wrong input, use --help for more info\n"); return 1; } + if (argc == 2 && strcmp(argv[1], "--help") == 0) { + printf("Reverses the contents of a file or text\n"); + printf("Usage: rev [file]\n"); + printf(" echo text | rev\n"); + return 0; + } FILE *fp = fopen(argv[1], "r"); // check if the argument is a file or not by opening it From bb09376ce56dba72cc3f8e2f402c2bf21a8676f0 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 16:56:26 +0200 Subject: [PATCH 03/13] Add head command to read lines from a file --- src/userland/cli/head.c | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/userland/cli/head.c diff --git a/src/userland/cli/head.c b/src/userland/cli/head.c new file mode 100644 index 0000000..ec67f99 --- /dev/null +++ b/src/userland/cli/head.c @@ -0,0 +1,54 @@ +// Copyright (c) 2026 janevers (https://github.com/janevers-sys) +// This software is released under the GNU General Public License v3.0. See LICENSE file for details. +// This header needs to maintain in any file it is present in, as per the GPL license terms. +#include +#include +#include + +int main(int argc, char *argv[]) { + if (argc == 2) { + if(strcmp(argv[1], "--help")) { + printf("-This command reads from the front of the file\n"); + printf("-Use: tail [-n] [-number of lines] [file]\n"); + return 0; + } + //print everything + FILE *fp = fopen(argv[1], "r"); + if (fp == NULL) { + printf("File not found\n"); + return 1; + } + char buf[1024]; + while (fgets(buf, sizeof(buf), fp)) { + printf("%s", buf); + } + fclose(fp); + return 0; + } + + if (argc == 4 && strcmp(argv[1], "-n") == 0) { + int lines = atoi(argv[2]); + if (lines <= 0) { + printf("Number of lines must be positive\n"); + return 1; + } + + FILE *fp = fopen(argv[3], "r"); + if (fp == NULL) { + printf("File not found\n"); + return 1; + } + + char buf[1024]; + while (lines > 0 && fgets(buf, sizeof(buf), fp)) { + printf("%s", buf); + lines--; + } + + fclose(fp); + return 0; + } + + printf("Wrong flag, --help for more info\n"); + return 1; +} From 94768017f106d158b756690e79a73368c2a97139 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 16:56:58 +0200 Subject: [PATCH 04/13] Update copyright notice in rev.c file --- src/userland/cli/rev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/userland/cli/rev.c b/src/userland/cli/rev.c index ae05ed3..5aea551 100644 --- a/src/userland/cli/rev.c +++ b/src/userland/cli/rev.c @@ -1,4 +1,4 @@ -// Copyright (c) 2026 janevers (https://github.com/zeyadhost) +// Copyright (c) 2026 janevers (https://github.com/janevers-sys) // This software is released under the GNU General Public License v3.0. See LICENSE file for details. // This header needs to maintain in any file it is present in, as per the GPL license terms. From c253ee0480210a61c2f25ecc82920d6a07896a6d Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 16:58:04 +0200 Subject: [PATCH 05/13] Implement tail command to read file lines --- src/userland/cli/tail.c | 68 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/userland/cli/tail.c diff --git a/src/userland/cli/tail.c b/src/userland/cli/tail.c new file mode 100644 index 0000000..4adcf21 --- /dev/null +++ b/src/userland/cli/tail.c @@ -0,0 +1,68 @@ +// Copyright (c) 2026 janevers (https://github.com/janevers-sys) +// This software is released under the GNU General Public License v3.0. See LICENSE file for details. +// This header needs to maintain in any file it is present in, as per the GPL license terms. +#include +#include +#include + +int main(int argc, char *argv[]) { + // print all lines + if (argc == 2) { + if(strcmp(argv[1], "--help")) { + printf("-This command reads from the back of the file\n"); + printf("-Use: tail [-n] [-number of lines] [file]\n"); + return 0; + } + FILE *fp = fopen(argv[1], "r"); + if (fp == NULL) { + printf("File not found\n"); + return 1; + } + char buf[1024]; + while (fgets(buf, sizeof(buf), fp)) { + printf("%s", buf); + } + fclose(fp); + return 0; + } + // only print last lines + if (argc == 4 && strcmp(argv[1], "-n") == 0) { + int lines = atoi(argv[2]); + if (lines <= 0) { + printf("Number of lines should be positive\n"); + return 1; + } + + FILE *fp = fopen(argv[3], "r"); + if (fp == NULL) { + printf("File not found\n"); + return 1; + } + + // count total lines + int count = 0; + char buf[1024]; + while (fgets(buf, sizeof(buf), fp)) { + count++; + } + + // back to start of file + fseek(fp, 0, SEEK_SET); + + // check if lines are the end lines + int skip = count - lines; + int i = 0; + while (fgets(buf, sizeof(buf), fp)) { + if (i >= skip) { + printf("%s", buf); + } + i++; + } + + fclose(fp); + return 0; + } + + printf("Wrong flag, --help for more info\n"); + return 1; +} From 09840e522a95262b22980c5c087e1b4730273177 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 17:20:20 +0200 Subject: [PATCH 06/13] Update tail command to read from the front of the file --- src/userland/cli/tail.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/userland/cli/tail.c b/src/userland/cli/tail.c index 4adcf21..83fe4f3 100644 --- a/src/userland/cli/tail.c +++ b/src/userland/cli/tail.c @@ -6,13 +6,13 @@ #include int main(int argc, char *argv[]) { - // print all lines if (argc == 2) { - if(strcmp(argv[1], "--help")) { - printf("-This command reads from the back of the file\n"); + if (strcmp(argv[1], "--help") == 0) { + printf("-This command reads from the front of the file\n"); printf("-Use: tail [-n] [-number of lines] [file]\n"); return 0; } + //print everything FILE *fp = fopen(argv[1], "r"); if (fp == NULL) { printf("File not found\n"); @@ -25,11 +25,11 @@ int main(int argc, char *argv[]) { fclose(fp); return 0; } - // only print last lines + // only print first lines if (argc == 4 && strcmp(argv[1], "-n") == 0) { int lines = atoi(argv[2]); if (lines <= 0) { - printf("Number of lines should be positive\n"); + printf("Number of lines must be positive\n"); return 1; } @@ -39,24 +39,10 @@ int main(int argc, char *argv[]) { return 1; } - // count total lines - int count = 0; char buf[1024]; - while (fgets(buf, sizeof(buf), fp)) { - count++; - } - - // back to start of file - fseek(fp, 0, SEEK_SET); - - // check if lines are the end lines - int skip = count - lines; - int i = 0; - while (fgets(buf, sizeof(buf), fp)) { - if (i >= skip) { - printf("%s", buf); - } - i++; + while (lines > 0 && fgets(buf, sizeof(buf), fp)) { + printf("%s", buf); + lines--; } fclose(fp); From 960f6922babcc98f781f35662b17381797c6d2f5 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 17:21:05 +0200 Subject: [PATCH 07/13] fixed --help --- src/userland/cli/tail.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/userland/cli/tail.c b/src/userland/cli/tail.c index 83fe4f3..3fba348 100644 --- a/src/userland/cli/tail.c +++ b/src/userland/cli/tail.c @@ -6,13 +6,13 @@ #include int main(int argc, char *argv[]) { + // print all lines if (argc == 2) { if (strcmp(argv[1], "--help") == 0) { - printf("-This command reads from the front of the file\n"); + printf("-This command reads from the back of the file\n"); printf("-Use: tail [-n] [-number of lines] [file]\n"); return 0; } - //print everything FILE *fp = fopen(argv[1], "r"); if (fp == NULL) { printf("File not found\n"); @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) { fclose(fp); return 0; } - // only print first lines + // only print last lines if (argc == 4 && strcmp(argv[1], "-n") == 0) { int lines = atoi(argv[2]); if (lines <= 0) { @@ -39,10 +39,24 @@ int main(int argc, char *argv[]) { return 1; } + // count total lines + int count = 0; char buf[1024]; - while (lines > 0 && fgets(buf, sizeof(buf), fp)) { - printf("%s", buf); - lines--; + while (fgets(buf, sizeof(buf), fp)) { + count++; + } + + // back to start of file + fseek(fp, 0, SEEK_SET); + + // check if lines are the end lines + int skip = count - lines; + int i = 0; + while (fgets(buf, sizeof(buf), fp)) { + if (i >= skip) { + printf("%s", buf); + } + i++; } fclose(fp); From 823b14d016613d749509dead6d75627d15a22798 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 17:27:58 +0200 Subject: [PATCH 08/13] Update help message in rev.c Removed example usage from help message. --- src/userland/cli/rev.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/userland/cli/rev.c b/src/userland/cli/rev.c index 5aea551..e39b396 100644 --- a/src/userland/cli/rev.c +++ b/src/userland/cli/rev.c @@ -26,7 +26,6 @@ int main(int argc, char *argv[]) { if (argc == 2 && strcmp(argv[1], "--help") == 0) { printf("Reverses the contents of a file or text\n"); printf("Usage: rev [file]\n"); - printf(" echo text | rev\n"); return 0; } From 72e6a8b6a786884f79ba1d0460191079a8d88e5a Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 17:43:45 +0200 Subject: [PATCH 09/13] updated help with rev head tail and find --- src/userland/cli/help.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/userland/cli/help.c b/src/userland/cli/help.c index 20ff62a..ac96e97 100644 --- a/src/userland/cli/help.c +++ b/src/userland/cli/help.c @@ -1,7 +1,6 @@ -// Copyright (c) 2023-2026 Chris (boreddevnl) +// Copyright (c) 2026 janevers (https://github.com/janevers-sys) // This software is released under the GNU General Public License v3.0. See LICENSE file for details. // This header needs to maintain in any file it is present in, as per the GPL license terms. -// BOREDOS_APP_DESC: Show command and system help. #include #include @@ -38,6 +37,10 @@ int main(int argc, char **argv) { printf("clear - Clear the screen\n"); printf("exit - Exit the terminal\n"); printf("net - Network tools\n"); + printf("find - find files or folders\n"); + printf("rev - Reverse a string or file\n"); + printf("head - print lines from the top down\n"); + printf("tail - print lines from te bottom up\n"); printf("\nHint: Use Ctrl+C to force quit any running application.\n"); return 0; } From 98368ffaaae0436e80de3f00e3f878b061703cdd Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 17:58:46 +0200 Subject: [PATCH 10/13] Fix formatting of help command descriptions --- src/userland/cli/help.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/userland/cli/help.c b/src/userland/cli/help.c index ac96e97..d7c09c4 100644 --- a/src/userland/cli/help.c +++ b/src/userland/cli/help.c @@ -37,10 +37,10 @@ int main(int argc, char **argv) { printf("clear - Clear the screen\n"); printf("exit - Exit the terminal\n"); printf("net - Network tools\n"); - printf("find - find files or folders\n"); - printf("rev - Reverse a string or file\n"); - printf("head - print lines from the top down\n"); - printf("tail - print lines from te bottom up\n"); + printf("find - find files or folders\n"); + printf("rev - Reverse a string or file\n"); + printf("head - print lines from the top down\n"); + printf("tail - print lines from the bottom up\n"); + printf("time - Measure command execution time\n"); printf("\nHint: Use Ctrl+C to force quit any running application.\n"); return 0; -} From b0a10d19d40ffbefa9ee12dfdf564674dae5913a Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 18:00:07 +0200 Subject: [PATCH 11/13] Align command descriptions in help output --- src/userland/cli/help.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/userland/cli/help.c b/src/userland/cli/help.c index d7c09c4..dadaab2 100644 --- a/src/userland/cli/help.c +++ b/src/userland/cli/help.c @@ -37,10 +37,10 @@ int main(int argc, char **argv) { printf("clear - Clear the screen\n"); printf("exit - Exit the terminal\n"); printf("net - Network tools\n"); - printf("find - find files or folders\n"); - printf("rev - Reverse a string or file\n"); - printf("head - print lines from the top down\n"); - printf("tail - print lines from the bottom up\n"); - printf("time - Measure command execution time\n"); + printf("find - find files or folders\n"); + printf("rev - Reverse a string or file\n"); + printf("head - print lines from the top down\n"); + printf("tail - print lines from the bottom up\n"); + printf("time - Measure command execution time\n"); printf("\nHint: Use Ctrl+C to force quit any running application.\n"); return 0; From 83daaee99b3185b1a5a6c465099edd0cd9d39372 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 18:01:59 +0200 Subject: [PATCH 12/13] Refactor help.c for better readability --- src/userland/cli/help.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/userland/cli/help.c b/src/userland/cli/help.c index dadaab2..ce09280 100644 --- a/src/userland/cli/help.c +++ b/src/userland/cli/help.c @@ -5,9 +5,13 @@ #include int main(int argc, char **argv) { - (void)argc; (void)argv; + (void)argc; + (void)argv; + uint64_t help_color = sys_get_shell_config("help_color"); - if (help_color != 0) sys_set_text_color(help_color); + if (help_color != 0) { + sys_set_text_color(help_color); + } printf("BoredOS CLI Help\n"); printf("---------------------------\n"); @@ -37,10 +41,12 @@ int main(int argc, char **argv) { printf("clear - Clear the screen\n"); printf("exit - Exit the terminal\n"); printf("net - Network tools\n"); - printf("find - find files or folders\n"); - printf("rev - Reverse a string or file\n"); - printf("head - print lines from the top down\n"); - printf("tail - print lines from the bottom up\n"); - printf("time - Measure command execution time\n"); + printf("find - find files or folders\n"); + printf("rev - Reverse a string or file\n"); + printf("head - print lines from the top down\n"); + printf("tail - print lines from the bottom up\n"); + printf("time - Measure command execution time\n"); printf("\nHint: Use Ctrl+C to force quit any running application.\n"); + return 0; +} From cc680e830f165c29756d563410330ec3ff6b0649 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 15 May 2026 18:04:41 +0200 Subject: [PATCH 13/13] Refactor help.c for copyright and message clarity Updated copyright information and improved formatting of help messages. --- src/userland/cli/help.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/userland/cli/help.c b/src/userland/cli/help.c index ce09280..2db5f0b 100644 --- a/src/userland/cli/help.c +++ b/src/userland/cli/help.c @@ -1,17 +1,14 @@ -// Copyright (c) 2026 janevers (https://github.com/janevers-sys) +// Copyright (c) 2023-2026 Chris (boreddevnl) // This software is released under the GNU General Public License v3.0. See LICENSE file for details. // This header needs to maintain in any file it is present in, as per the GPL license terms. +// BOREDOS_APP_DESC: Show command and system help. #include #include int main(int argc, char **argv) { - (void)argc; - (void)argv; - + (void)argc; (void)argv; uint64_t help_color = sys_get_shell_config("help_color"); - if (help_color != 0) { - sys_set_text_color(help_color); - } + if (help_color != 0) sys_set_text_color(help_color); printf("BoredOS CLI Help\n"); printf("---------------------------\n"); @@ -41,12 +38,11 @@ int main(int argc, char **argv) { printf("clear - Clear the screen\n"); printf("exit - Exit the terminal\n"); printf("net - Network tools\n"); - printf("find - find files or folders\n"); - printf("rev - Reverse a string or file\n"); - printf("head - print lines from the top down\n"); - printf("tail - print lines from the bottom up\n"); - printf("time - Measure command execution time\n"); + printf("time - Measure command execution time\n"); + printf("find - find files or dol") + printf("rev - Reverse a string or file\n"); + printf("head - print lines from the top down\n"); + printf("tail - print lines from te bottom up\n"); printf("\nHint: Use Ctrl+C to force quit any running application.\n"); - return 0; }