-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.h
73 lines (58 loc) · 1.88 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
#ifndef MAIN_H_
#define MAIN_H_
#include <stdarg.h> /* For variadic functions*/
#include <limits.h> /* For useful limits that should not be reached*/
#include <stdio.h>
#include <unistd.h>
/* Printf prototype (Takes in variable arguments)*/
int _printf(const char *format, ...);
/**
* struct fmt_specifiers - A blueprint for declaring printf formats
*
* @fmt: This is the format that will be handled by the printf function.
* Examples of values that fmt should take are s and c.
*
*
* @function: This is the format of the functions that will be used
* to handle @fmt. It should return an int value (as seen in the first part)
* and the name of the function is user defined but should be descriptive.
* Function names should be nouns if represent something (which is rare)
* and verbs when performing an action (most of the time)
* An example can be "handle_string"
*
* An example of a function that can be made using this struct is
* int handle_string(va_list args)
*
* It is not mandatory to use this format for all the function
* implemented but should be used for all format specifiers
*
* Exceptions include _putchar(char x) and family
*
*/
typedef struct fmt_specifiers
{
char *fmt;
int (*function)(va_list);
} fmt_specifier;
/* Preprocessor Definations */
#define BUFFER_S 1024
/**
* _F_NAME_ - Get function name
* If __func__ is available use it (Recommended by Betty)
* Else use __FUNCTION__ (Available for gcc only)
* This operation causes Betty to raise a Warning
* You can remove the operation and replace it with
* #define _F_NAME_ __func__ and everything will work just fine
* and as an added bonus no Betty to deal with
*/
#ifdef __func__
#define _F_NAME__ __func__
#else
#define _F_NAME__ __FUNCTION__
#endif
/* Helper Functions */
int _putchar(char x);
int _strlen(const char *str);
/* Format specifiers */
int handle_char(va_list args);
#endif /* End of MAIN_H_ */