libft
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
ft_printf.h File Reference

Internal definitions and declarations for ft_printf. More...

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  s_fmt
 Format specifier data. More...
 
struct  s_pf
 State struct for ft_printf. More...
 

Macros

#define FLAG_HASH   (1 << 0)
 
#define FLAG_MINUS   (1 << 2)
 
#define FLAG_PLUS   (1 << 3)
 
#define FLAG_SPACE   (1 << 4)
 
#define FLAG_ZERO   (1 << 1)
 

Typedefs

typedef struct s_fmt t_fmt
 
typedef struct s_pf t_pf
 

Functions

void format_and_print_c (t_fmt *fmt, va_list *args, t_pf *pf)
 Formats and prints a character (c).
 
void format_and_print_id (t_fmt *fmt, va_list *args, t_pf *pf)
 Handles d and i format specifiers for ft_printf.
 
void format_and_print_percent (t_fmt *fmt, t_pf *pf)
 Formats and prints a literal percent sign (%%).
 
void format_and_print_s (t_fmt *fmt, va_list *args, t_pf *pf)
 Formats and prints a string (s).
 
void format_and_print_u (t_fmt *fmt, va_list *args, t_pf *pf)
 Handles u format specifier for ft_printf.
 
void format_and_print_x (t_fmt *fmt, va_list *args, int upper, t_pf *pf)
 Handles x and X format specifiers for ft_printf.
 
int ft_printf (const char *format,...)
 Prints formatted output according to the format string.
 
int get_alternative_form_length (char specifier)
 Returns the prefix length for x and X when using # flag.
 
void handle_minus_flag_p (char *str, int padding, t_pf *pf)
 
char * handle_precision_int (t_fmt *fmt, char *str, int *len, t_pf *pf)
 Applies precision formatting to a numeric string.
 
char * handle_precision_p (t_fmt *fmt, char *str, int *len, t_pf *pf)
 
int handle_precision_s (t_fmt *fmt, int len)
 Applies precision limit to string length.
 
void handle_space_flag_p (t_pf *pf, int *padding)
 
int handle_width (t_fmt *fmt, size_t len)
 Computes the number of padding characters to apply.
 
int initialize_printf_structs (t_pf *pf)
 Allocates and initializes the structures required by ft_printf.
 
int is_valid_flag (char c)
 Checks if a character is a valid format flag.
 
char * prepend_alternative_form (char *str, char specifier, t_pf *pf)
 Prepends the 0x or 0X prefix to a hexadecimal string.
 
void print_formatted_number (t_fmt *fmt, char *str, int len, t_pf *pf)
 Final formatter and dispatcher for integer output.
 
void print_padding (int padding, char pad_char, t_pf *pf)
 Prints a series of padding characters.
 
void print_right_aligned_p (t_fmt *fmt, char *str, int padding, t_pf *pf)
 
void process_format_string (const char *format, va_list *args, t_pf *pf)
 Walks through the format string and dispatches format handlers.
 
int requires_alternative_form (char specifier, char *str)
 Checks whether the alternative form (#) should be applied.
 
int setup_format (const char **format, t_fmt *fmt)
 Parses a full format specification (flags, width, precision, specifier).
 
void write_char_safely (int fd, char c, t_pf *pf)
 Safely writes a single character to a file descriptor.
 
void write_safely (int fd, char *str, t_pf *pf)
 Safely writes a null-terminated string to a file descriptor.
 
void write_safely_len (int fd, char *str, size_t len, t_pf *pf)
 Safely writes len bytes from a string to a file descriptor.
 

Detailed Description

Internal definitions and declarations for ft_printf.

Author
Toonsa
Date
2025/04/05

This header contains all the structures, macros, and function prototypes required to implement a custom ft_printf. It supports parsing format strings, handling flags, and printing various types (characters, strings, integers, hexadecimal, pointers, etc.).

It also defines the FLAG_* macros for internal format flag management.