-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
118 lines (105 loc) · 4.27 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
117
118
#ifndef MAIN_H
#define MAIN_H
#include <stdarg.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define BUFFER_SIZE 1024
#define UNUSED(x) (void)(x)
/**
* struct fmt_specifier - A structure of a specifier
* and its corresponding function pointer
* @spec: A specifier (s, c, i, d,...)
* @hndlr: A pointer to a function that doesn't return a value
*/
typedef struct fmt_specifier
{
char spec;
void (*hndlr)(va_list ap, int *count, int *total, char *buffer,
int field_width);
} fmt_spec;
int _printf(const char *format, ...);
int find_length(char *s);
int find_const_length(const char *s);
char hex_to_ascii(int digit);
void fill_buffer(const char *format, int *count, int *total, char *buffer);
int handle_all(const char *format, va_list ap, int *count, int *total,
char *buffer, fmt_spec *spec);
int handle_struct(const char *format, fmt_spec *spec, va_list ap, int *count,
int *total, char *buffer, int field_width);
void buffer_status_handler(int *count, int *total, char *buffer);
void field_width_handler(int field_width, char *buffer, int *count,
int *total);
int precision_handler(const char *format, int precision, va_list ap,
char *buffer, int *count, int *total);
void char_format_handler(va_list ap, int *count, int *total, char *buffer,
int field_width);
void str_format_handler(va_list ap, int *count, int *total, char *buffer,
int field_width);
void ptr_format_handler(va_list ap, int *count, int *total, char *buffer,
int field_width);
void percent_handler(int *count, int *total, char *buffer);
void handle_zero_number(int *count, int *total, char *buffer);
/* --------- Numbers ------*/
void int_format_handler(va_list ap, int *count, int *total, char *buffer,
int field_width);
void u_format_handler(va_list ap, int *count, int *total, char *buffer,
int field_width);
void o_format_handler(va_list ap, int *count, int *total, char *buffer,
int field_width);
void x_format_handler(va_list ap, int *count, int *total, char *buffer,
int field_width);
void printUpperHex(va_list ap, int *count, int *total, char *buffer,
int field_width);
/* --------- Helper functions ----*/
int my_itoa(const char *format, char *buffer, int num, int base);
int our_putchar(char c);
/*--- Custom Format Specifiers ---*/
void custom_b_handler(va_list ap, int *count, int *total, char *buffer,
int field_width);
void custom_S_handler(va_list ap, int *count, int *total, char *buffer,
int field_width);
void custom_r_handler(va_list ap, int *count, int *total, char *buffer,
int field_width);
void custom_R_handler(va_list ap, int *count, int *total, char *buffer,
int field_width);
/*--- Length Modifiers ---*/
void long_modifier_handler(const char *format, va_list ap, int *count,
int *total, char *buffer);
void long_int_handler(long number, int *count, int *total, char *buffer);
void long_u_handler(unsigned long number, int *count,
int *total, char *buffer);
void long_o_handler(unsigned long number, int *count,
int *total, char *buffer);
void long_x_handler(unsigned long number, int *count,
int *total, char *buffer);
void long_upper_x_handler(unsigned long number, int *count,
int *total, char *buffer);
void short_modifier_handler(const char *format, va_list ap,
int *count, int *total, char *buffer);
void short_int_handler(short number, int *count, int *total, char *buffer);
void short_u_handler(unsigned short number, int *count,
int *total, char *buffer);
void short_o_handler(unsigned short number, int *count,
int *total, char *buffer);
void short_x_handler(unsigned short number, int *count,
int *total, char *buffer);
void short_upper_x_handler(unsigned short number, int *count,
int *total, char *buffer);
/*--- Error ---*/
int trailing_percent_error(const char *format);
/*--- Flags -----*/
int flag_handler(const char *format, va_list ap, int *count,
int *total, char *buffer);
int f_plus_handler(const char *format, va_list ap, int *count,
int *total, char *buffer);
int f_space_handler(const char *format, va_list ap, int *count,
int *total, char *buffer);
int f_hash_handler(const char *format, va_list ap, int *count,
int *total, char *buffer);
int f_minus_handler(const char *format, va_list ap, int *count,
int *total, char *buffer);
int f_zero_handler(const char *format, va_list ap, int *count,
int *total, char *buffer);
#endif