tgrekov-fdf
HIVE fdf May 2024
Loading...
Searching...
No Matches
identify_sequence.c
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/11 23:50:53 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "handlers/handlers.h"
14#include "sequence.h"
15
16static void init_sequence(t_sequence *sequence)
17{
18 sequence->sign = 0;
19 sequence->total_len = 0;
20}
21
22void identify_sequence(va_list args, t_sequence *seq)
23{
24 init_sequence(seq);
25 if (seq->specifier == 'd' || seq->specifier == 'i')
26 return (pre_int(args, seq));
27 if (seq->specifier == 'u')
28 return (pre_uint(args, seq));
29 if (seq->specifier == 'x' || seq->specifier == 'X')
30 return (pre_uhex(args, seq));
31 if (seq->specifier == 'c')
32 return (pre_char(args, seq));
33 if (seq->specifier == 's')
34 return (pre_string(args, seq));
35 if (seq->specifier == 'p')
36 return (pre_ptr(args, seq));
37 if (seq->specifier == '%')
38 return (pre_percent(args, seq));
39 seq->specifier = 0;
40}
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_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 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