-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifiers.c
84 lines (74 loc) · 2.13 KB
/
modifiers.c
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
#include "main.h"
unsigned int print_width(buffer_t *output, unsigned int printed,
unsigned char flags, int wid);
unsigned int print_string_width(buffer_t *output,
unsigned char flags, int wid, int prec, int size);
unsigned int print_neg_width(buffer_t *output, unsigned int printed,
unsigned char flags, int wid);
/**
* print_width - Stores leading spaces to a buffer for a width modifier.
* @output: A buffer_t struct containing a character array.
* @printed: The current number of characters already printed to output
* for a given number specifier.
* @flags: Flag modifiers.
* @wid: A width modifier.
*
* Return: The number of bytes stored to the buffer.
*/
unsigned int print_width(buffer_t *output, unsigned int printed,
unsigned char flags, int wid)
{
unsigned int ret = 0;
char width = ' ';
if (NEG_FLAG == 0)
{
for (wid -= printed; wid > 0;)
ret += _memcpy(output, &width, 1);
}
return (ret);
}
/**
* print_string_width - Stores leading spaces to a buffer for a width modifier.
* @output: A buffer_t struct containing a character array.
* @flags: Flag modifiers.
* @wid: A width modifier.
* @prec: A precision modifier.
* @size: The size of the string.
*
* Return: The number of bytes stored to the buffer.
*/
unsigned int print_string_width(buffer_t *output,
unsigned char flags, int wid, int prec, int size)
{
unsigned int ret = 0;
char width = ' ';
if (NEG_FLAG == 0)
{
wid -= (prec == -1) ? size : prec;
for (; wid > 0; wid--)
ret += _memcpy(output, &width, 1);
}
return (ret);
}
/**
* print_neg_width - Stores trailing spaces to a buffer for a '-' flag.
* @output: A buffer_t struct containing a character array.
* @printed: The current number of bytes already stored to output
* for a given specifier.
* @flags: Flag modifiers.
* @wid: A width modifier.
*
* Return: The number of bytes stored to the buffer.
*/
unsigned int print_neg_width(buffer_t *output, unsigned int printed,
unsigned char flags, int wid)
{
unsigned int ret = 0;
char width = ' ';
if (NEG_FLAG == 1)
{
for (wid -= printed; wid > 0; wid--)
ret += _memcpy(output, &width, 1);
}
return (ret);
}