代码拉取完成,页面将自动刷新
*! 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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。