-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.h
116 lines (104 loc) · 3.98 KB
/
main.h
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
#ifndef MAIN_H
#define MAIN_H
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
/* Flag Modifier Macros */
#define PLUS 1
#define SPACE 2
#define HASH 4
#define ZERO 8
#define NEG 16
#define PLUS_FLAG (flags & 1)
#define SPACE_FLAG ((flags >> 1) & 1)
#define HASH_FLAG ((flags >> 2) & 1)
#define ZERO_FLAG ((flags >> 3) & 1)
#define NEG_FLAG ((flags >> 4) & 1)
/* Length Modifier Macros */
#define SHORT 1
#define LONG 2
/**
* struct buffer_s - A new type defining a buffer struct.
* @buffer: A pointer to a character array.
* @start: A pointer to the start of buffer.
* @len: The length of the string stored in buffer.
*/
typedef struct buffer_s
{
char *buffer;
char *start;
unsigned int len;
} buffer_t;
/**
* struct converter_s - A new type defining a converter struct.
* @specifier: A character representing a conversion specifier.
* @func: A pointer to a conversion function corresponding to specifier.
*/
typedef struct converter_s
{
unsigned char specifier;
unsigned int (*func)(va_list, buffer_t *,
unsigned char, int, int, unsigned char);
} converter_t;
/**
* struct flag_s - A new type defining a flags struct.
* @flag: A character representing a flag.
* @value: The integer value of the flag.
*/
typedef struct flag_s
{
unsigned char flag;
unsigned char value;
} flag_t;
int _printf(const char *format, ...);
/* Conversion Specifier Functions */
unsigned int convert_c(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_s(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_di(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_percent(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_b(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_u(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_o(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_x(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_X(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_S(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_p(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_r(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
unsigned int convert_R(va_list args, buffer_t *output,
unsigned char flags, int wid, int prec, unsigned char len);
/* Handlers */
unsigned char handle_flags(const char *flags, char *index);
unsigned char handle_length(const char *modifier, char *index);
int handle_width(va_list args, const char *modifier, char *index);
int handle_precision(va_list args, const char *modifier, char *index);
unsigned int (*handle_specifiers(const char *specifier))(va_list, buffer_t *,
unsigned char, int, int, unsigned char);
/* Modifiers */
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);
/* Helper Functions */
buffer_t *init_buffer(void);
void free_buffer(buffer_t *output);
unsigned int _memcpy(buffer_t *output, const char *src, unsigned int n);
unsigned int convert_sbase(buffer_t *output, long int num, char *base,
unsigned char flags, int wid, int prec);
unsigned int convert_ubase(buffer_t *output, unsigned long int num, char *base,
unsigned char flags, int wid, int prec);
#endif