From 3f23d0f1979d7dac1d68207250c66aec5ee3c19b Mon Sep 17 00:00:00 2001 From: xolatile Date: Sun, 12 Nov 2023 07:19:44 -0500 Subject: [PATCH] New chapter 3... --- chapters/chapter_1.c | 2 +- chapters/chapter_3.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ chapters/chapter_3.h | 20 ++++++++++++++++ compile.sh | 3 ++- xhartae.c | 3 +++ 5 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 chapters/chapter_3.c create mode 100644 chapters/chapter_3.h diff --git a/chapters/chapter_1.c b/chapters/chapter_1.c index 3ae5e97..b558392 100644 --- a/chapters/chapter_1.c +++ b/chapters/chapter_1.c @@ -209,7 +209,7 @@ int file_type (char * name) { } void * file_record (char * name) { - int file = -1; + int file = -1; // You can also initialize local variables in this way. int size = -1; char * data = NULL; diff --git a/chapters/chapter_3.c b/chapters/chapter_3.c new file mode 100644 index 0000000..fcc6fde --- /dev/null +++ b/chapters/chapter_3.c @@ -0,0 +1,67 @@ +/* +Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic + +Xhartae is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation. +And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version. +It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3. +*/ + +#ifndef CHAPTER_3_SOURCE +#define CHAPTER_3_SOURCE + +#include "chapter_3.h" + +void print (char * format, ...) { + va_list argument_array; + + int offset, length; + + int integer; + char * string; + double ieee754; + + length = string_length (format); + + va_start (argument_array, format); + + for (offset = 0; offset != length; ++offset) { + if (format [offset] == '%') { + ++offset; + if (format [offset] == '%') { + out ("%", 1); + } else if (format [offset] == 'i') { + integer = va_arg (argument_array, int); + echo (number_to_string (integer)); + } else if (format [offset] == 'F') { + ieee754 = va_arg (argument_array, double); + echo (number_to_string ((int) ieee754)); + } else if (format [offset] == 's') { + string = va_arg (argument_array, char *); + echo (string); + } else { + out ("?", 1); + } + } else if (format [offset] == '/') { + ++offset; + if (format [offset] == '/') { + out ("/", 1); + } + } else { + out (& format [offset], 1); + } + } + + va_end (argument_array); +} + +void file_print (char * format, ...) { + (void) format; + return; +} + +void string_print (char * format, ...) { + (void) format; + return; +} + +#endif diff --git a/chapters/chapter_3.h b/chapters/chapter_3.h new file mode 100644 index 0000000..62bc074 --- /dev/null +++ b/chapters/chapter_3.h @@ -0,0 +1,20 @@ +/* +Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic + +Xhartae is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation. +And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version. +It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3. +*/ + +#ifndef CHAPTER_3_HEADER +#define CHAPTER_3_HEADER + +#include + +#include "chapter_0.h" + +extern void print (char * format, ...); +extern void file_print (char * format, ...); +extern void string_print (char * format, ...); + +#endif diff --git a/compile.sh b/compile.sh index 9467a47..912693e 100644 --- a/compile.sh +++ b/compile.sh @@ -5,9 +5,10 @@ set -xe gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -c -o chapters/chapter_0.o chapters/chapter_0.c gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -c -o chapters/chapter_1.o chapters/chapter_1.c gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -c -o chapters/chapter_2.o chapters/chapter_2.c +gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -c -o chapters/chapter_3.o chapters/chapter_3.c gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -c -o xhartae.o xhartae.c -gcc -o xhartae xhartae.o chapters/chapter_0.o chapters/chapter_1.o chapters/chapter_2.o +gcc -o xhartae xhartae.o chapters/chapter_0.o chapters/chapter_1.o chapters/chapter_2.o chapters/chapter_3.o exit diff --git a/xhartae.c b/xhartae.c index cb78ecd..eade818 100644 --- a/xhartae.c +++ b/xhartae.c @@ -9,6 +9,7 @@ It is distributed in the hope that it will be useful or harmful, it really depen #include "chapters/chapter_0.h" #include "chapters/chapter_1.h" #include "chapters/chapter_2.h" +#include "chapters/chapter_3.h" /* About this "book": @@ -129,5 +130,7 @@ int main (int argc, char * * argv) { curses_synchronize (); } + print ("%F\n%s\n%i\n", 69.1, "Heyo", 420); + return (EXIT_SUCCESS); }