很多时候我们需要用版本号来辨别发布的软件,但每次手动地修改难免觉得麻烦,而且容易忘记,所以希望每次编译发布时执行一个程序使其自动修改最后一位的版本号。
例如,有这样的版本号定义:
<Version>1.0.0</Version>
我们希望编译发布时自动执行一个程序,使其变为
<Version>1.0.1</Version>
话不多说直接上代码:
token.h
#ifndef __TOKEN_H__
#define __TOKEN_H__
typedef struct TokenType {
char *token;
int size; // token的大小
char flag; // 版本号的分隔符号,为了方便只设置起始token即可
} TokenType;
// config.xml token信息
static char config_xml_start_token_str1[] = "<Version>";
static char config_xml_end_token_str1[] = "</Version>";
static TokenType config_xml_start_tokens[] = {
{
.token = config_xml_start_token_str1,
.size = sizeof(config_xml_start_token_str1),
.flag = '.',
}
};
static TokenType config_xml_end_tokens[] = {
{
.token = config_xml_end_token_str1