-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
47 lines (38 loc) · 1.3 KB
/
main.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
#include "ezmanpages.h"
// Use this instead
//#include <ezmanpages/ezmanpages.h>
#define BUFFER_SIZE 1024
void check_ret(parser_error_t ret) {
switch (ret) {
case E_PARSER_SUCCESS:
break;
case E_PARSER_TRUNC:
ezmanpages_perror("[info]", ret);
break;
default:
ezmanpages_perror("[error] parser error", ret);
exit(EXIT_FAILURE);
}
}
int main(void) {
// Return code to check errors
parser_error_t ret;
// Define the `ezmanpages_t` struct
ezmanpages_t ezmanpages;
// Init the ezmanpages
ret = ezmanpages_init(&ezmanpages, "mv", 1, "SYNOPSIS");
fprintf(stdout, "ezmanpages struct:\n%s %s %s\n", ezmanpages.name, ezmanpages.page, ezmanpages.section);
check_ret(ret);
// Use those functions to change the `ezmanpages_t` structure
ezmanpages_set_name(&ezmanpages, "free");
ezmanpages_set_page(&ezmanpages, 3);
ezmanpages_set_section(&ezmanpages, "DESCRIPTION");
fprintf(stdout, "ezmanpages struct:\n%s %s %s\n", ezmanpages.name, ezmanpages.page, ezmanpages.section);
// Now parse the man page
char result[BUFFER_SIZE];
ret = ezmanpages_parse(ezmanpages, result, BUFFER_SIZE);
check_ret(ret);
// Print the results
fprintf(stdout, "%s", result);
return 0;
}