tgrekov-ft_printf
HIVE printf Feb 2024
Loading...
Searching...
No Matches
uhex.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* uhex.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/11/01 07:07:16 by tgrekov #+# #+# */
9/* Updated: 2024/02/13 08:23:23 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include <stdarg.h>
21#include <unistd.h>
22#include "../sequence.h"
23#include "../../utils/utils.h"
24#include "../../utils/internal_types.h"
25#include "utils/handler_utils.h"
26
37int process_uhex(t_sequence seq, int *fd, int total)
38{
39 (void) total;
40 if (seq.specifier == 'X')
41 return (u_print_base(seq, *fd, "0123456789ABCDEF"));
42 return (u_print_base(seq, *fd, "0123456789abcdef"));
43}
44
58void pre_uhex(va_list args, t_sequence *seq)
59{
60 seq->data = unsigned_arg(args, seq->subspec.lenmod);
61 seq->total_len = u_len_base(seq->data, 16)
62 - (!seq->subspec.precision && !seq->data);
63 if (seq->subspec.precision > seq->total_len)
64 seq->total_len = seq->subspec.precision;
65 if (seq->subspec.precision != -1)
66 seq->subspec.pad_str = " ";
67 if (seq->subspec.force_decimal && seq->data)
68 {
69 seq->sign = "0x";
70 if (seq->specifier == 'X')
71 seq->sign = "0X";
72 }
73 seq->process = process_uhex;
74}
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
int process_uhex(t_sequence seq, int *fd, int total)
Process the unsigned octal specifier by printing the number in uppercase or lowercase base 16 dependi...
Definition uhex.c:37
int u_len_base(t_ubiggest n, int base)
Determine the length of unsigned number n in base base.
Definition u_len_base.c:29
t_ubiggest unsigned_arg(va_list args, t_lenmod lenmod)
Retrieves the next unsigned variable argument in the appropriate size dependent on the length modifie...
int u_print_base(t_sequence seq, int fd, char *base)
Writes an unsigned integer in base base on descriptor fd, with respect to the s_subspec::precision.
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
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
char * sign
String containing the prefix for the value. Set during preprocessing for a format handler.
Definition sequence.h:52
int precision
Minimum number of digits to be printed, or maximum characters for strings.
Definition subspec.h:71
char force_decimal
1 or 0, whether or not to prefix octals or hexadecimals with their respective prefixes....
Definition subspec.h:68
t_lenmod lenmod
Represents the length modifiers for a format specifier's variable argument.
Definition subspec.h:72
char * pad_str
String used when padding values.
Definition subspec.h:69