feat: base + display functions!!!!!

This commit is contained in:
mcolonna 2024-02-26 14:18:51 +01:00
parent ebb5931632
commit 664b18eb2e
187 changed files with 29451 additions and 0 deletions

View file

@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* conversions.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/11 16:45:39 by mcolonna #+# #+# */
/* Updated: 2024/02/12 13:31:08 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CONVERSIONS_H
# define CONVERSIONS_H
# include <stdlib.h>
# include <stdarg.h>
// Does a specific conversion.
// - flags: the flags of the conversion
// - args: the args given to ft_printf
// Return the number of chars written.
// ERROR: returns -1.
typedef int (t_put_function)(va_list args);
// Represents a possible conversion.
// Ex: {'c', &put_char} is the conversion to write a char.
// .name: Code to identify the conversion
// 'c' would mean you have to use it with "%c"
// .put_function: Function called with the argument to write the data.
// - flags: The flags to modify the way the content is wrote.
// - content: The arguments of printf.
// Returned value: The number of chars wrote, -1 if error.
typedef struct s_conversion
{
char name;
t_put_function *put_function;
} t_conversion;
// 'c' conversion.
int put_char(va_list args);
// 's' conversion.
int put_str(va_list args);
// '%' conversion.
int put_percent(va_list args);
// 'd' and 'i' conversions (it's the same).
int put_decimal(va_list args);
// 'u' conversion.
int put_unsigned(va_list args);
// 'x' conversion.
int put_hex_lower(va_list args);
// 'X' conversion.
int put_hex_upper(va_list args);
// 'p' conversion.
int put_pointer(va_list args);
#endif

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* do_conversion.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/13 14:25:00 by mcolonna #+# #+# */
/* Updated: 2023/11/20 15:19:10 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DO_CONVERSION_H
# define DO_CONVERSION_H
# include <stdarg.h>
// Do a conversion specified by its name.
// - args: arguments given to ft_printf()
// - name: name of the conversion
// Returns the number of chars written.
// ERROR: returns -1.
int do_conversion(va_list args, char name);
#endif

View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stream.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/26 18:11:25 by mcolonna #+# #+# */
/* Updated: 2024/02/12 13:27:20 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STREAM_H
# define STREAM_H
// Represents a stream.
// Allows to read a string char by char and remembering the position.
typedef struct s_stream_2
{
const char *str;
int i;
} t_stream_2;
// Return a new malloced t_stream_2 pointer, or NULL if malloc error.
t_stream_2 *stream_2_new(const char *str);
// Get the current char of the stream, '\0' if the string is finished.
char stream_2_getchar(t_stream_2 *stream);
// Goes to the next char (never after a '\0').
// Returns 1 if it isn't the end, or else 0.
int stream_2_next(t_stream_2 *stream);
// Returns 1 if it isn't the end, or else 0.
int stream_2_continues(t_stream_2 *stream);
// Skip 'n' chars.
void stream_2_skip(t_stream_2 *stream, int n);
// Return a pointer to the current char.
char *stream_2_pointer(t_stream_2 *stream);
#endif

View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tf_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/16 16:50:23 by mcolonna #+# #+# */
/* Updated: 2024/02/12 12:35:21 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TF_PRINTF_H
# define TF_PRINTF_H
int tf_printf(const char *format, ...);
#endif

View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/13 14:31:39 by mcolonna #+# #+# */
/* Updated: 2024/02/12 12:57:29 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef UTILS_H
# define UTILS_H
# include "stream.h"
char *ft_strjoin(char const *s1, char const *s2);
// Cast an int to a string (0 or /[1-9][0-9]*/).
// - n: number
char *ft_itoa(int n);
// Cast an unsigned int to a string (0 or /-?[1-9][0-9]*/).
// - n: number
char *ft_utoa(unsigned int n);
// Cast an unsigned int to a string in a specified base.
// - n: number
// - base: base chars (example: "01233456789abcdef")
char *ft_utoa_base(unsigned long n, const char *base);
// atoi for a stream.
unsigned int stream_atoi(t_stream_2 *stream);
#endif