-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncs3.c
152 lines (132 loc) · 2.59 KB
/
funcs3.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "main.h"
/**
* for_flags - Calculates active flags
* @format: Formatted string in which to print the arguments
* @i: take a parameter.
* Return: Flags:
*/
int for_flags(const char *format, int *i)
{
/* - + 0 # ' ' */
/* 1 2 4 8 16 */
const int FLAGS_ARR[] = {F_MINUS, F_PLUS, F_ZERO, F_HASH, F_SPACE, 0};
int j, curr_i;
const char FLAGS_sign[] = {'-', '+', '0', '#', ' ', '\0'};
int flags = 0;
for (curr_i = *i + 1; format[curr_i] != '\0'; curr_i++)
{
for (j = 0; FLAGS_sign[j] != '\0'; j++)
if (format[curr_i] == FLAGS_sign[j])
{
flags |= FLAGS_ARR[j];
break;
}
if (FLAGS_sign[j] == 0)
break;
}
*i = curr_i - 1;
return (flags);
}
/**
* for_rot13str - Print a string in rot13.
* @buff: Buffer array to handle print
* @flags: Calculates active flags
* @width: get width
* @precision: Precision specification
* @size: Size specifier
* @args: Arguments
* Return: Numbers of chars printed
*/
int for_rot13str(va_list args, char buff[],
int flags, int width, int precision, int size)
{
unsigned int i, j;
char k;
char *str;
int p = 0;
char out_char[] = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
char in_char[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
str = va_arg(args, char *);
UNUSED(buff);
UNUSED(flags);
UNUSED(width);
UNUSED(precision);
UNUSED(size);
if (str == NULL)
str = "(AHYY)";
for (i = 0; str[i]; i++)
{
for (j = 0; in_char[j]; j++)
{
if (in_char[j] == str[i])
{
k = out_char[j];
write(1, &k, 1);
p++;
break;
}
}
if (!in_char[j])
{
k = str[i];
write(1, &k, 1);
p++;
}
}
return (p);
}
/**
* for_precision - Calculates the precision for printing
* @format: Formatted string in which to print the arguments
* @i: List of arguments to be printed.
* @args: Arguments
*
* Return: Precision.
*/
int for_precision(const char *format, int *i, va_list args)
{
int j = -1;
int k = *i + 1;
if (format[k] != '.')
return (j);
j = 0;
for (k += 1; format[k] != '\0'; k++)
{
if (is_digit(format[k]))
{
j *= 10;
j += format[k] - '0';
}
else if (format[k] == '*')
{
k++;
j = va_arg(args, int);
break;
}
else
break;
}
*i = k - 1;
return (j);
}
/**
* for_size - Calculates the size to cast the argument
* @format: Formatted string in which to print the arguments
* @i: List of arguments to be printed.
*
* Return: Precision.
*/
int for_size(const char *format, int *i)
{
int j = 0;
int k = *i + 1;
if (format[k] == 'l')
j = S_LONG;
else if (format[k] == 'h')
j = S_SHORT;
if (j == 0)
*i = k - 1;
else
*i = k;
return (j);
}