-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.c
More file actions
62 lines (50 loc) · 1.43 KB
/
cli.c
File metadata and controls
62 lines (50 loc) · 1.43 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
52
53
54
55
56
57
58
59
60
61
62
/**
* Tiny BinaryXML parser library usage example
*
* Richard Boldiš <richard@boldis.dev>
* https://github.com/Richardds
*
*/
#include <stdio.h>
#include "src/bxml.h"
int main(int argc, char * argv[])
{
struct BinaryXML binaryXML;
if (argc < 2) {
printf("bxml <filename>\n");
return 1;
}
FILE * fileHandle = fopen(argv[1], "rb");
if (fileHandle == NULL) {
printf("Input file does not exist\n");
return 1;
}
fseek(fileHandle, 0, SEEK_END);
size_t fileSize = ftell(fileHandle);
fseek(fileHandle, 0, SEEK_SET);
enum BinaryXMLStatus parseStatus = readBinaryXML(fileHandle, fileSize, &binaryXML);
if (parseStatus == NO_ERROR) {
printBinaryXMLNode(&binaryXML, binaryXML.nodes, 0);
} else {
switch (parseStatus) {
case INVALID_FILE_HEADER_MAGIC:
fprintf(stderr, "File format magic mismatch\n");
break;
case MEMORY_ALLOCATION_FAILED:
fprintf(stderr, "Failed to allocate memory\n");
break;
case FILE_CORRUPTED:
fprintf(stderr, "Input file is corrupted\n");
break;
default:
fprintf(stderr, "Unknown error\n");
break;
}
fclose(fileHandle);
freeBinaryXML(&binaryXML);
return 1;
}
fclose(fileHandle);
freeBinaryXML(&binaryXML);
return 0;
}