-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexdecode.c
More file actions
51 lines (42 loc) · 1.51 KB
/
exdecode.c
File metadata and controls
51 lines (42 loc) · 1.51 KB
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
// SPDX-License-Identifier: MIT
#include "../../amp.h"
int main(int, char **) {
const char *error_message = nullptr;
static const char doc[] =
"╔════════════════╗\n"
"╠════════════════╣\n"
"║ WS SW AA║\n"
"║ OOOOOOOO AA║\n"
"║ OOMRLLMR OO║\n"
"║ CCLLLLLL OO║\n"
"║OOCCOOCCOOCCOOLL║\n"
"║LLLLCCOOCCOO OO║\n"
"║ MMMMMMMMMM OO║\n"
"║ CC CC OO║\n"
"╚════════════════╝";
uint32_t w, h;
size_t data_size = amp_doc_parse_size(doc, sizeof(doc), &w, &h);
uint8_t *data = nullptr;
if (data_size) {
data = malloc(data_size);
if (data) {
struct amp_type amp;
if (amp_init(&, w, h, data, data_size) <= data_size) {
if (amp_decode(&, doc, sizeof(doc))) {
amp_to_ans(&, nullptr, 0);
amp_stdout("\n", 1);
}
else error_message = "amp_decode: parse error\n";
}
else error_message = "amp_init: not enough memory provided\n";
}
else error_message = "malloc: allocation failed\n";
}
else error_message = "amp_parse_size: parse error\n";
free(data);
if (error_message) {
write(2, error_message, strlen(error_message));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}