-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_version.c
59 lines (53 loc) · 1.28 KB
/
update_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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
FILE *fp;
char *line = NULL;
size_t len = 0;
ssize_t read;
const char s[2] = ".";
char *token;
unsigned int version[3];
unsigned short int i = 0;
int count = 0;
fp = fopen("current_version.txt", "r");
if (fp == NULL)
exit(EXIT_FAILURE);
while ((read = getline(&line, &len, fp)) != -1)
{
token = strtok(line, s);
while (token != NULL)
{
version[i] = atoi(token);
i++;
token = strtok(NULL, s);
}
}
fclose(fp);
if (line)
free(line);
line = NULL;
len = 0;
fp = fopen("current_version.txt", "w");
if (fp == NULL)
exit(EXIT_FAILURE);
printf("%d\n", version[2]);
version[2] = version[2] + 1;
printf("%d\n", version[2]);
fprintf(fp, "%u.%u.%u", version[0], version[1], version[2]);
fclose(fp);
i = 0;
fp = fopen("include/version.h", "w");
if (fp == NULL)
exit(EXIT_FAILURE);
fprintf(fp, "#ifndef _VERSION_H\n");
fprintf(fp, "#define _VERSION_H 1\n\n");
for (i = 0; i < 3; i++)
{
fprintf(fp, "#define V%d %u\n", i + 1, version[i]);
}
fprintf(fp, "\n#endif");
return 0;
}