1 Star 2 Fork 7

kerrydu/malmq2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
_get_version.ado 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
kerrydu 提交于 2021-08-01 16:57 . autocompiled
*! version 2.9.0 28mar2017
program _get_version
syntax anything(name=ado), [min_version(string) min_date(string)]
mata: st_local("package_version", get_version("`ado'"))
c_local package_version "`package_version'"
loc _ `package_version'
gettoken version_number _ : _
gettoken version_date _ : _
c_local version_number "`version_number'"
c_local version_date "`version_date'"
if ("`min_version'" != "") {
* This is not very flexible; only accepts x.y.z versioning schemes
loc ok 0
cap mata: st_local("ok", strofreal(strtoreal(tokens(subinstr("`version_number'", ".", " "))) * (1e5, 1e3, 1)' >= strtoreal(tokens(subinstr("`min_version'", ".", " "))) * (1e5, 1e3, 1)'))
_assert `ok', msg("you are using version `version_number' of `ado', but require version `min_version'")
}
if ("`min_date'" != "") {
* This is not very flexible; only accepts 1jan2018/01Jan2018 versioning schemes
loc ok = !mi(date("`version_date'", "DMY")) & (date("`version_date'", "DMY") >= date("`min_date'", "DMY"))
_assert `ok', msg("you are using `ado' from `version_date', but require a version from at `min_date' or later")
}
end
mata:
string scalar get_version(string scalar ado)
{
real scalar fh
string scalar line
string scalar fn
fn = findfile(ado + ".ado", c("adopath"))
if (fn == "") {
printf("{err}file not found: %s.ado\n", ado)
exit(123)
}
fh = fopen(fn, "r")
line = fget(fh)
fclose(fh)
line = strtrim(line)
if (strpos(line, "*! version ")) {
line = strtrim(substr(line, 1 + strlen("*! version "), .))
return(line)
}
if (strpos(line, sprintf("*! %s ", ado) )) {
line = strtrim(substr(line, 1 + strlen(sprintf("*! %s ", ado) ), .))
return(line)
}
else {
printf("{err}no version line found for %s\n", ado)
return("")
}
}
end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kerrydu/malmq2.git
git@gitee.com:kerrydu/malmq2.git
kerrydu
malmq2
malmq2
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385