New chapter 3...

This commit is contained in:
Ognjen Milan Robovic 2023-11-12 07:19:44 -05:00
vanhempi c5cc2c8567
commit 3f23d0f197
5 muutettua tiedostoa jossa 93 lisäystä ja 2 poistoa

Näytä tiedosto

@ -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;

67
chapters/chapter_3.c Normal file
Näytä tiedosto

@ -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

20
chapters/chapter_3.h Normal file
Näytä tiedosto

@ -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 <stdarg.h>
#include "chapter_0.h"
extern void print (char * format, ...);
extern void file_print (char * format, ...);
extern void string_print (char * format, ...);
#endif

Näytä tiedosto

@ -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

Näytä tiedosto

@ -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);
}