tgrekov-ft_printf
HIVE printf Feb 2024
Loading...
Searching...
No Matches
uoct.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* uoct.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/11/01 06:59:50 by tgrekov #+# #+# */
9/* Updated: 2024/02/13 08:21:03 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
36static int process_uoct(t_sequence seq, int *fd, int total)
37{
38 (void) total;
39 return (u_print_base(seq, *fd, "01234567"));
40}
41
55void pre_uoct(va_list args, t_sequence *seq)
56{
57 seq->data = unsigned_arg(args, seq->subspec.lenmod);
58 seq->total_len = u_len_base(seq->data, 8)
59 - (!seq->subspec.precision && !seq->data);
60 if (seq->subspec.precision > seq->total_len)
61 seq->total_len = seq->subspec.precision;
62 if (seq->subspec.precision != -1)
63 seq->subspec.pad_str = " ";
64 if (seq->subspec.force_decimal && seq->data)
65 seq->sign = "0";
66 seq->process = process_uoct;
67}
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
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
void pre_uoct(va_list args, t_sequence *seq)
Preprocess the unsigned octal specifier by retrieving the argument in the appropriate size,...
Definition uoct.c:55
static int process_uoct(t_sequence seq, int *fd, int total)
Process the unsigned octal specifier by printing the number in base 8.
Definition uoct.c:36