-
Notifications
You must be signed in to change notification settings - Fork 0
/
wm_getver.c
87 lines (76 loc) · 1.72 KB
/
wm_getver.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
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LINE_LEN_MAX 1024
int main(int argc, char *argv[])
{
FILE *fp;
char buf[LINE_LEN_MAX];
char *pos;
unsigned char major = 0;
unsigned char minor = 0;
unsigned char patch = 0;
int done = 0;
if (2 != argc)
{
printf("error: parameters please pass wm_main.c path\r\n");
return -1;
}
fp = fopen(argv[1], "rb");
if (!fp)
{
printf("error: failed to open %s\r\n", argv[1]);
return -2;
}
while (fgets(buf, LINE_LEN_MAX, fp))
{
if (0 == done)
{
pos = strstr(buf, "FW_MAJOR_VER");
if (pos)
{
pos = strchr(pos, '0');
if (pos)
{
major = strtol(pos, NULL, 16);
done = 1;
}
}
}
if (1 == done)
{
pos = strstr(buf, "FW_MINOR_VER");
if (pos)
{
pos = strchr(pos, '0');
if (pos)
{
minor = strtol(pos, NULL, 16);
done = 2;
}
}
}
if (2 == done)
{
pos = strstr(buf, "FW_PATCH_VER");
if (pos)
{
pos = strchr(pos, '0');
if (pos)
{
patch = strtol(pos, NULL, 16);
done = 3;
break;
}
}
}
}
fclose(fp);
if (3 == done)
{
sprintf(buf, "G%02X.%02X.%02X", major, minor, patch);
printf("%s", buf);
return 0;
}
return -4;
}