tgrekov-ft_printf
HIVE printf Feb 2024
Loading...
Searching...
No Matches
string.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* string.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/11/01 08:25:24 by tgrekov #+# #+# */
9/* Updated: 2024/02/13 07:56:44 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include <stdarg.h>
21#include <unistd.h>
22#include "../sequence.h"
23#include "../../../../libft/libft.h"
24#include "../../utils/internal_types.h"
25
34static int process_string(t_sequence seq, int *fd, int total)
35{
36 (void) total;
37 return (write(*fd, (char *) seq.data, seq.total_len - seq.pad_len));
38}
39
50void pre_string(va_list args, t_sequence *seq)
51{
52 seq->data = (t_ubiggest) va_arg(args, char *);
53 if (!seq->data)
54 seq->data = (t_ubiggest) "(null)";
55 seq->total_len = (int) ft_strlen((char *) seq->data);
56 if (seq->subspec.precision > -1 && seq->subspec.precision < seq->total_len)
57 seq->total_len = seq->subspec.precision;
59}
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
static int process_string(t_sequence seq, int *fd, int total)
Process the string specifier by writing the string. (Rocket science)
Definition string.c:34
unsigned long long t_ubiggest
Convenience typedef for largest unsigned type I need to handle.
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
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 total_len
Total number of characters after padding.
Definition sequence.h:54
int pad_len
Number of characters to pad.
Definition sequence.h:55
int precision
Minimum number of digits to be printed, or maximum characters for strings.
Definition subspec.h:71