summaryrefslogtreecommitdiffstats
path: root/generic/tclBasic.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2021-07-13 15:56:33 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2021-07-13 15:56:33 (GMT)
commitce04bad35e4aa0a36a2d3d9ce604852a391184b6 (patch)
tree3623870c360e2738639debf758ffe9b859087804 /generic/tclBasic.c
parent83e8931185384d0b34fe4fb395c1f3d8c366996a (diff)
downloadtcl-ce04bad35e4aa0a36a2d3d9ce604852a391184b6.zip
tcl-ce04bad35e4aa0a36a2d3d9ce604852a391184b6.tar.gz
tcl-ce04bad35e4aa0a36a2d3d9ce604852a391184b6.tar.bz2
More advanced tcl::build-info string parsing
Diffstat (limited to 'generic/tclBasic.c')
-rw-r--r--generic/tclBasic.c72
1 files changed, 65 insertions, 7 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index a7f89a4..60160f7 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -632,15 +632,73 @@ buildInfoObjCmd(
return TCL_ERROR;
}
if (objc == 2) {
- const char *arg = Tcl_GetString(objv[1]);
- const char *p = strstr((char *)clientData, arg);
- size_t len = strlen(arg);
- if ((p > (char *)clientData) && p[-1] == '.'
- && ((p[len] == '.') || (p[len] == '\0'))) {
- Tcl_AppendResult(interp, "1", NULL);
- } else {
+ int len;
+ const char *arg = TclGetStringFromObj(objv[1], &len);
+ if (len == 7 && !strcmp(arg, "version")) {
+ char buf[80];
+ const char *p = strchr((char *)clientData, '.');
+ if (p) {
+ const char *q = strchr(p+1, '.');
+ const char *r = strchr(p+1, '+');
+ p = (q < r) ? q : r;
+ }
+ if (p) {
+ memcpy(buf, (char *)clientData, p - (char *)clientData);
+ buf[p - (char *)clientData] = '\0';
+ Tcl_AppendResult(interp, buf, NULL);
+ }
+ return TCL_OK;
+ } else if (len == 11 && !strcmp(arg, "fullversion")) {
+ char buf[80];
+ const char *p = strchr((char *)clientData, '+');
+ if (p) {
+ memcpy(buf, (char *)clientData, p - (char *)clientData);
+ buf[p - (char *)clientData] = '\0';
+ Tcl_AppendResult(interp, buf, NULL);
+ }
+ return TCL_OK;
+ } else if (len == 6 && !strcmp(arg, "commit")) {
+ const char *q, *p = strchr((char *)clientData, '+');
+ if (p) {
+ if ((q = strchr(p, '.'))) {
+ char buf[80];
+ memcpy(buf, p+1, q - p - 1);
+ buf[q - p - 1] = '\0';
+ Tcl_AppendResult(interp, buf, NULL);
+ } else {
+ Tcl_AppendResult(interp, p+1, NULL);
+ }
+ }
+ return TCL_OK;
+ } else if (len == 8 && !strcmp(arg, "compiler")) {
+ const char *p = strchr((char *)clientData, '.');
+ while (p) {
+ if (!strncmp(p+1, "clang-", 6) || !strncmp(p+1, "gcc-", 4) || !strncmp(p+1, "msvc-", 5)) {
+ const char *q = strchr(p+1, '.');
+ if (q) {
+ char buf[16];
+ memcpy(buf, p+1, q - p - 1);
+ buf[q - p - 1] = '\0';
+ Tcl_AppendResult(interp, buf, NULL);
+ } else {
+ Tcl_AppendResult(interp, p+1, NULL);
+ }
+ return TCL_OK;
+ }
+ p = strchr(p+1, '.');
+ }
Tcl_AppendResult(interp, "0", NULL);
+ return TCL_OK;
+ }
+ const char *p = strchr((char *)clientData, '.');
+ while (p) {
+ if (!strncmp(p+1, arg, len) && ((p[len+1] == '.') || (p[len+1] == '\0'))) {
+ Tcl_AppendResult(interp, "1", NULL);
+ return TCL_OK;
+ }
+ p = strchr(p+1, '.');
}
+ Tcl_AppendResult(interp, "0", NULL);
return TCL_OK;
}
Tcl_AppendResult(interp, (char *)clientData, NULL);