-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec.c
More file actions
100 lines (79 loc) · 2.67 KB
/
spec.c
File metadata and controls
100 lines (79 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* spec.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dlesieur <dlesieur@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/02 13:08:07 by dlesieur #+# #+# */
/* Updated: 2025/07/02 13:22:59 by dlesieur ### ########.fr */
/* */
/* ************************************************************************** */
#include "auto_parser.h"
void spec_string(t_parser_ctx *ctx)
{
char *str;
str = va_arg(*ctx->args, char *);
if (!str)
str = "(null)";
buffer_append_str_formatted(ctx->buffer, ctx->pos, str, &ctx->spec);
}
void spec_decimal(t_parser_ctx *ctx)
{
int num;
num = va_arg(*ctx->args, int);
buffer_append_int_formatted(ctx->buffer, ctx->pos, num, &ctx->spec, 10);
}
void spec_integer(t_parser_ctx *ctx)
{
int num;
num = va_arg(*ctx->args, int);
buffer_append_int_formatted(ctx->buffer, ctx->pos, num, &ctx->spec, 10);
}
void spec_unsigned(t_parser_ctx *ctx)
{
unsigned int num;
num = va_arg(*ctx->args, unsigned int);
buffer_append_int_formatted(ctx->buffer, ctx->pos, num, &ctx->spec, 10);
}
void spec_hex_lower(t_parser_ctx *ctx)
{
unsigned int num;
num = va_arg(*ctx->args, unsigned int);
buffer_append_int_formatted(ctx->buffer, ctx->pos, num, &ctx->spec, 16);
}
void spec_hex_upper(t_parser_ctx *ctx)
{
unsigned int num;
num = va_arg(*ctx->args, unsigned int);
buffer_append_int_formatted(ctx->buffer, ctx->pos, num, &ctx->spec, 16);
}
void spec_octal(t_parser_ctx *ctx)
{
unsigned int num;
num = va_arg(*ctx->args, unsigned int);
buffer_append_int_formatted(ctx->buffer, ctx->pos, num, &ctx->spec, 8);
}
void spec_char(t_parser_ctx *ctx)
{
char ch;
ch = (char)va_arg(*ctx->args, int);
buffer_append_char(ctx->buffer, ctx->pos, ch);
}
void spec_float(t_parser_ctx *ctx)
{
double num;
int int_part;
num = va_arg(*ctx->args, double);
int_part = (int)num;
buffer_append_int_formatted(ctx->buffer, ctx->pos, int_part, &ctx->spec, 10);
}
void spec_pointer(t_parser_ctx *ctx)
{
void *ptr;
unsigned long addr;
ptr = va_arg(*ctx->args, void *);
addr = (unsigned long)ptr;
buffer_append_str(ctx->buffer, ctx->pos, "0x");
buffer_append_int_formatted(ctx->buffer, ctx->pos, addr, &ctx->spec, 16);
}