tgrekov-ft_printf
HIVE printf Feb 2024
Loading...
Searching...
No Matches
store.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* store.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/12/16 18:18:34 by tgrekov #+# #+# */
9/* Updated: 2024/02/13 08:47:35 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include <stdarg.h>
21#include <unistd.h>
22#include <stdlib.h>
23#include "../sequence.h"
24#include "../../utils/internal_types.h"
25
36static int process_store(t_sequence seq, int *fd, int total)
37{
38 (void) fd;
39 if (!seq.data)
40 return (-1);
41 if (seq.subspec.lenmod == hh)
42 *((signed char *) seq.data) = total;
43 else if (seq.subspec.lenmod == h)
44 *((short *) seq.data) = total;
45 else if (seq.subspec.lenmod == l)
46 *((long *) seq.data) = total;
47 else if (seq.subspec.lenmod == ll)
48 *((long long *) seq.data) = total;
49 else if (seq.subspec.lenmod == j)
50 *((intmax_t *) seq.data) = total;
51 else if (seq.subspec.lenmod == z)
52 *((size_t *) seq.data) = total;
53 else if (seq.subspec.lenmod == t)
54 *((t_ptrdiff_t *) seq.data) = total;
55 else
56 *((int *) seq.data) = total;
57 return (0);
58}
59
69void pre_store(va_list args, t_sequence *seq)
70{
71 if (seq->subspec.lenmod == hh)
72 seq->data = (t_ubiggest) va_arg(args, int *);
73 else if (seq->subspec.lenmod == h)
74 seq->data = (t_ubiggest) va_arg(args, int *);
75 else if (seq->subspec.lenmod == l)
76 seq->data = (t_ubiggest) va_arg(args, long *);
77 else if (seq->subspec.lenmod == ll)
78 seq->data = (t_ubiggest) va_arg(args, long long *);
79 else if (seq->subspec.lenmod == j)
80 seq->data = (t_ubiggest) va_arg(args, intmax_t *);
81 else if (seq->subspec.lenmod == z)
82 seq->data = (t_ubiggest) va_arg(args, size_t *);
83 else if (seq->subspec.lenmod == t)
84 seq->data = (t_ubiggest) va_arg(args, t_ptrdiff_t *);
85 else
86 seq->data = (t_ubiggest) va_arg(args, int *);
87 seq->subspec.min_width = 0;
89}
unsigned long long t_ubiggest
Convenience typedef for largest unsigned type I need to handle.
long t_ptrdiff_t
If _PTRDIFF_T is defined, set to ptrdiff_t. Set to long otherwise.
static int process_store(t_sequence seq, int *fd, int total)
Processes the store specifier by setting the value at the retrieved address to the number of characte...
Definition store.c:36
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
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
t_ubiggest data
Retrieved variable argument.
Definition sequence.h:53
t_subspec subspec
Holds subspecifier options for a format specifier.
Definition sequence.h:51
int min_width
Minimum number of characters to be printed.
Definition subspec.h:70
t_lenmod lenmod
Represents the length modifiers for a format specifier's variable argument.
Definition subspec.h:72