tgrekov-pipex
HIVE pipex May 2024
Loading...
Searching...
No Matches
handle_sequence.c
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* handle_sequence.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/11/01 00:41:01 by tgrekov #+# #+# */
9/* Updated: 2024/04/26 10:28:55 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include <stdarg.h>
14#include "sequence.h"
15#include "../utils/utils.h"
16#include "../../../../libft.h"
17
18void identify_sequence(va_list args, t_sequence *seq);
19
20int handle_sequence(const char **format, va_list args, int *fd, int total)
21{
22 t_sequence seq;
23 int res;
24
25 seq.specifier = **format;
26 identify_sequence(args, &seq);
27 if (!seq.specifier)
28 return (-1);
29 if (seq.sign)
30 seq.total_len += ft_strlen(seq.sign);
31 (*format)++;
32 res = 0;
33 if (seq.sign && !wrap_err(write(*fd, seq.sign, ft_strlen(seq.sign)), &res))
34 return (-1);
35 if (!wrap_err(seq.process(seq, fd, total + res), &res))
36 return (-1);
37 return (res);
38}
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 ...
int handle_sequence(const char **format, va_list args, int *fd, int total)
Prepares and executes a sequence.
int wrap_err(int n, int *total)
Wrapper for handling functions that return a positive integer on success and -1 on failure....
Definition wrap_err.c:29
size_t ft_strlen(const char *str)
Get length of str.
Definition ft_strlen.c:28
Holds information regarding the current format specifier sequence.
Definition sequence.h:49
int(* process)(struct s_sequence, int *, int)
Function to use for processing this sequence's value.
Definition sequence.h:56
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