tgrekov-ft_printf
HIVE printf Feb 2024
Loading...
Searching...
No Matches
identify_sequence.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* identify_sequence.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/11/01 03:41:27 by tgrekov #+# #+# */
9/* Updated: 2024/02/13 07:16:49 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include "handlers/handlers.h"
21#include "sequence.h"
22
29static void init_sequence(t_sequence *sequence)
30{
31 sequence->sign = 0;
32 sequence->total_len = 0;
33 sequence->pad_len = 0;
34}
35
44void identify_sequence(va_list args, t_sequence *seq)
45{
46 init_sequence(seq);
47 if (seq->specifier == 'd' || seq->specifier == 'i')
48 return (pre_int(args, seq));
49 if (seq->specifier == 'u')
50 return (pre_uint(args, seq));
51 if (seq->specifier == 'o')
52 return (pre_uoct(args, seq));
53 if (seq->specifier == 'x' || seq->specifier == 'X')
54 return (pre_uhex(args, seq));
55 if (seq->specifier == 'c')
56 return (pre_char(args, seq));
57 if (seq->specifier == 's')
58 return (pre_string(args, seq));
59 if (seq->specifier == 'p')
60 return (pre_ptr(args, seq));
61 if (seq->specifier == '%')
62 return (pre_percent(args, seq));
63 if (seq->specifier == 'n')
64 return (pre_store(args, seq));
65 if (seq->specifier == '>')
66 return (pre_set_fd(args, seq));
67 seq->specifier = 0;
68}
void pre_char(va_list args, t_sequence *seq)
Preprocess the character specifier by retrieving the character, setting s_sequence::total_len to 1 an...
Definition char.c:47
void pre_uint(va_list args, t_sequence *seq)
Preprocess the unsigned integer specifier by retrieving the argument in the appropriate size,...
Definition uint.c:54
void pre_uoct(va_list args, t_sequence *seq)
Preprocess the unsigned octal specifier by retrieving the argument in the appropriate size,...
Definition uoct.c:55
void pre_uhex(va_list args, t_sequence *seq)
Preprocess the unsigned hexadecimal specifier by retrieving the argument in the appropriate size,...
Definition uhex.c:58
void pre_ptr(va_list args, t_sequence *seq)
Preprocess the pointer specifier by retrieving the address, setting the s_sequence::total_len with u_...
Definition pointer.c:38
void pre_string(va_list args, t_sequence *seq)
Preprocess the string specifier by retrieving the address, setting s_sequence::data to the address,...
Definition string.c:50
void pre_int(va_list args, t_sequence *seq)
Preprocess the signed integer specifier by retrieving the argument in the appropriate size,...
Definition int.c:88
void pre_percent(va_list args, t_sequence *seq)
Preprocess the percent specifier by setting s_sequence::data to %, s_sequence::total_len to 1,...
Definition percent.c:35
void pre_set_fd(va_list args, t_sequence *seq)
Preprocess the set file descriptor specifier by retrieving the argument, ensuring that s_subspec::min...
Definition set_fd.c:49
void pre_store(va_list args, t_sequence *seq)
Preprocess the store specifier by retrieving the address argument in the appropriate size dependent o...
Definition store.c:69
void identify_sequence(va_list args, t_sequence *seq)
Initialize a s_sequence and determine which specifier it needs to handle, and runs the preprocessing ...
static void init_sequence(t_sequence *sequence)
Sets initial values for a s_sequence that are not always set elsewhere.
Holds information regarding the current format specifier sequence.
Definition sequence.h:49
char specifier
The specifier character for this sequence.
Definition sequence.h:50
int total_len
Total number of characters after padding.
Definition sequence.h:54
char * sign
String containing the prefix for the value. Set during preprocessing for a format handler.
Definition sequence.h:52
int pad_len
Number of characters to pad.
Definition sequence.h:55