diff --git a/documents/references.md b/documents/references.md index ab0480589d5bc0ace810f0380f54444d7e23775c..d999b70c4946a4b2d06d78d8e9113f978d4010aa 100644 --- a/documents/references.md +++ b/documents/references.md @@ -26,3 +26,10 @@ Most parallelization logic is from the book "Introduction to Parallel Programmin ### Other #### strtol Function <https://www.tutorialspoint.com/c_standard_library/c_function_strtol.htm> + +#### Pointer to Pointer +<https://www.tutorialspoint.com/cprogramming/c_pointer_to_pointer.htm> + +#### Moving Cursor in Terminal +<https://stackoverflow.com/a/35190285> +<https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html> diff --git a/makefile b/makefile index f98ed0e6d24ee6cd380919480945fe4b9a060abe..55bfd53853409298bc31056eb509df079d6be306 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,3 @@ all: - gcc -Wall -Wpedantic -std=c99 src/main.c src/structs.c src/simulate_loads.c -g -o main.out -pthread + gcc -Wall -Wpedantic -std=c99 src/main.c src/structs.c src/simulate_loads.c src/terminal_commands.c -g -o main.out -pthread diff --git a/src/main.c b/src/main.c index 6c86b1ae7d0e5297ffaa498543129a0f24c62717..d512d6b893ae3a3678d44eb6fc5f10d616899026 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,7 @@ #define user_headers #include "simulate_loads.h" #include "structs.h" + #include "terminal_commands.h" #endif @@ -93,8 +94,8 @@ void validate_args(int argc, char* argv[]) { // Validate "indexes_per_load" value. Should be between 100 and 10,000. indexes_per_load = strtol(argv[2], NULL, 10); - if ((indexes_per_load < 100) || (indexes_per_load > 10000)) { - printf("Arg2 (indexes_per_load) should be int between 100 and 10,000.\n"); + if ((indexes_per_load < 10) || (indexes_per_load > 10000)) { + printf("Arg2 (indexes_per_load) should be int between 10 and 10,000.\n"); printf("\n"); printf("Terminating program.\n"); exit(1); @@ -102,8 +103,8 @@ void validate_args(int argc, char* argv[]) { // Validate "total_loads" value. Should be between 100 and 10,000. total_loads = strtol(argv[3], NULL, 10); - if ((total_loads < 100) || (total_loads > 10000)) { - printf("Arg3 (total_loads) should be int between 100 and 10,000.\n"); + if ((total_loads < 10) || (total_loads > 10000)) { + printf("Arg3 (total_loads) should be int between 10 and 10,000.\n"); printf("\n"); printf("Terminating program.\n"); exit(1); diff --git a/src/simulate_loads.c b/src/simulate_loads.c index ea3a6d4494d7525040299ebf93ac8a832abe98d0..5d3cb5d13f98c4659c2a69ec16882c991ef09096 100644 --- a/src/simulate_loads.c +++ b/src/simulate_loads.c @@ -8,6 +8,7 @@ #define user_headers #include "simulate_loads.h" #include "structs.h" + #include "terminal_commands.h" #endif diff --git a/src/terminal_commands.c b/src/terminal_commands.c new file mode 100644 index 0000000000000000000000000000000000000000..a44a46ba4289c4e7b896ea27b503ce749087651c --- /dev/null +++ b/src/terminal_commands.c @@ -0,0 +1,102 @@ +/** + * File for terminal logic. + * + * Note that all of these are in relation to the line the cursor is currently on. + */ + +// User Import Headers. +#ifndef user_headers + #define user_headers + #include "simulate_loads.h" + #include "structs.h" + #include "terminal_commands.h" +#endif + + +/** + * Move to start of current line. + * Note that this does not erase, but any output will write over the respective character. + */ +void terminal_line_start() { + printf("\r"); +} + + +/** + * Move to end of current line. + * Note that th is does appear to erase, from where cursor was, up until end of line. + */ +void terminal_line_end() { + printf("\033[K"); +} + + +/** + * Moves cursor up one single line. + * Cursor will stay at the current column place. + */ +void terminal_line_up() { + printf("\033[A"); +} + + +/** + * Moves cursor down one single line. + * Cursor will stay at the current column place. + */ +void terminal_line_down() { + printf("\033[B"); +} + + +/** + * Moves curor left by one place. + */ +void terminal_arrow_left() { + printf("\033[D"); +} + + +/** + * Moves cursor right by one place. + */ +void terminal_arrow_right() { + printf("\033[C"); +} + + +/** + * Erases entire line cursor is on, and moves cursor back to start of line. + */ +void terminal_line_erase() { + printf("\33[2K"); + terminal_line_start(); +} + + +/** + * Prints full Lorem Ipsum paragraph, with no break characters. + */ +void print_lorem_ipsum_paragraph() { + printf("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque tristique lacus vitae pharetra" + "lacinia. Cras eu odio eros. Aliquam erat volutpat. Pellentesque habitant morbi tristique senectus et netus " + "et malesuada fames ac turpis egestas. Mauris neque lacus, tristique eu arcu vel, auctor vehicula sapien. " + "Cras blandit pretium aliquam. Integer malesuada, purus eget interdum placerat, est ipsum auctor lorem, quis" + " mattis magna libero in neque. Morbi eget nunc lobortis, venenatis purus ac, mollis diam."); +} + + +/** + * Prints full Lorem Ipsum paragraph, with each sentence on its own line. + */ +void print_lorem_ipsum_lines() { + printf("Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"); + printf("Pellentesque tristique lacus vitae pharetra lacinia.\n"); + printf("Cras eu odio eros.\n"); + printf("Aliquam erat volutpat.\n"); + printf("Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n"); + printf("Mauris neque lacus, tristique eu arcu vel, auctor vehicula sapien.\n"); + printf("Cras blandit pretium aliquam.\n"); + printf("Integer malesuada, purus eget interdum placerat, est ipsum auctor lorem, quis mattis magna libero in neque.\n"); + printf("Morbi eget nunc lobortis, venenatis purus ac, mollis diam.\n"); +} diff --git a/src/terminal_commands.h b/src/terminal_commands.h new file mode 100644 index 0000000000000000000000000000000000000000..8a9aca65d1f8f60f21a6a574923512504656afad --- /dev/null +++ b/src/terminal_commands.h @@ -0,0 +1,23 @@ +/** + * Header file for project terminal logic. + */ + + +// System Import Headers. +#include <ctype.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + +// Function Prototypes. +void terminal_line_start(); +void terminal_line_end(); +void terminal_line_up(); +void terminal_line_down(); +void terminal_arrow_left(); +void terminal_arrow_right(); +void terminal_line_erase(); +void print_lorem_ipsum_paragraph(); +void print_lorem_ipsum_lines();