-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathversion.c
118 lines (102 loc) · 2.69 KB
/
version.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#define VERSION_AUTO_INCREASE 0
#define VERSION_DATA_FMT "S%04uH%04uC%04u"
typedef enum user_id_e
{
USER_ID_DEMO = 0,
USER_ID_XIUXIU,
USER_ID_WEIXIN,
USER_ID_YUHONGQIANG,
USER_ID_MAX,
} user_id_e;
char* user_cfg_name[USER_ID_MAX] = {
"CONFIG_PRODUCT_WNAVY",
"CONFIG_PRODUCT_XIUBAOBAO",
"CONFIG_PRODUCT_WEIXIN",
"CONFIG_PRODUCT_YUHONGQIANG",
};
int main(void)
{
int ret = 0;
FILE* fp = NULL;
FILE* fq = NULL;
time_t tm_t;
struct tm* year = NULL;
char output[512] = {0};
char input[512] = {0};
uint32_t ver_m = 0;
uint32_t ver_n = 0;
uint32_t usr_id = 0;
tm_t = time(NULL);
year = localtime(&tm_t);
if(year == NULL)
{
printf("Fail to get current time!");
ret = -1;
goto err;
}
fp = fopen("src\\version.h", "w+");
if(fp == NULL)
{
printf("Fail to open version header file!");
ret = -2;
goto err;
}
fq = fopen("version.dat", "r+");
if(fq == NULL)
{
printf("Fail to open version data file!");
ret = -2;
goto err;
}
if(fgets(input, sizeof(input), fq) == NULL)
{
printf("Fail to gets version data from file!");
ret = -3;
goto err;
}
if(sscanf(input, VERSION_DATA_FMT, &(ver_m), &(ver_n), &(usr_id)) <= 0)
{
printf("Fail to sscanf version data from file!");
ret = -4;
goto err;
}
#if VERSION_AUTO_INCREASE
ver_m++;
#endif
ver_m = ((ver_m > 9999) ? 0: ver_m);
ver_n = ((ver_n > 9999) ? 0: ver_n);
usr_id = ((usr_id >= USER_ID_MAX) ? 0: usr_id);
sprintf(output, "#ifndef __VERSION_H__\n"
"#define __VERSION_H__\n"
"#define SYSTEM_SOFTWARE_VERSION \"V:%04u\"\n"
"#define SYSTEM_HARDWARE_VERSION \"V:%04u\"\n"
"#define SYSTEM_RELVERSION_TIME \"%02u%02u%02u\"\n"
"#define %s 1\n"
"#endif\n",
ver_m, ver_n,
((year->tm_year) + 1900 - 2000),
(year->tm_mon + 1),
(year->tm_mday),
user_cfg_name[usr_id]);
printf("%s", output);
fprintf(fp, "%s", output);
#if VERSION_AUTO_INCREASE
fprintf(fq, VERSION_DATA_FMT, ver_m, ver_n, usr_id);
#endif
ret = 0;
err:
if(fp != NULL)
{
fclose(fp);
}
if(fq != NULL)
{
fclose(fq);
}
return ret;
}