From bc4fef4f2a38c1ea99fad6a177d8d646fe7de386 Mon Sep 17 00:00:00 2001 From: ZarTek Creole Date: Thu, 10 Apr 2025 13:31:05 +0000 Subject: [PATCH 1/4] feat(tcl): add timerexists and utimerexists commands Add new Tcl commands `timerexists` and `utimerexists` to check if a timer or utimer with a given name exists. This enhances scripting capabilities and debugging of timers. Patch by: ZarTek-Creole --- src/tclmisc.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/tclmisc.c b/src/tclmisc.c index d197af93f..2e2b33d8c 100644 --- a/src/tclmisc.c +++ b/src/tclmisc.c @@ -303,6 +303,29 @@ static int tcl_utimer STDVAR Tcl_AppendResult(irp, x, NULL); return TCL_OK; } +static int tcl_timerexists STDVAR +{ + BADARGS(2, 2, " timerName"); + + if (find_timer(timer, argv[1])) { + Tcl_AppendResult(irp, "1", NULL); + } else { + Tcl_AppendResult(irp, "0", NULL); + } + return TCL_OK; +} + +static int tcl_utimerexists STDVAR +{ + BADARGS(2, 2, " utimerName"); + + if (find_timer(utimer, argv[1])) { + Tcl_AppendResult(irp, "1", NULL); + } else { + Tcl_AppendResult(irp, "0", NULL); + } + return TCL_OK; +} static int tcl_killtimer STDVAR { @@ -822,6 +845,8 @@ tcl_cmds tclmisc_cmds[] = { {"putloglev", tcl_putloglev}, {"timer", tcl_timer}, {"utimer", tcl_utimer}, + {"timerexists", tcl_timerexists}, + {"utimerexists", tcl_utimerexists}, {"killtimer", tcl_killtimer}, {"killutimer", tcl_killutimer}, {"timers", tcl_timers}, From 41147db67c789a20149d2be2aa8aae170bc4846d Mon Sep 17 00:00:00 2001 From: "ZarTek @ CREOLE" <11725850+ZarTek-Creole@users.noreply.github.com> Date: Fri, 11 Apr 2025 16:10:45 +0000 Subject: [PATCH 2/4] `tclmisc.c: Replace Tcl_AppendResult with Tcl_SetResult in tcl_timerexists and tcl_utimerexists functions.` --- src/tclmisc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tclmisc.c b/src/tclmisc.c index 2e2b33d8c..0de2e7e11 100644 --- a/src/tclmisc.c +++ b/src/tclmisc.c @@ -308,9 +308,9 @@ static int tcl_timerexists STDVAR BADARGS(2, 2, " timerName"); if (find_timer(timer, argv[1])) { - Tcl_AppendResult(irp, "1", NULL); + Tcl_SetResult(irp, "1", TCL_STATIC); } else { - Tcl_AppendResult(irp, "0", NULL); + Tcl_SetResult(irp, "0", TCL_STATIC); } return TCL_OK; } @@ -320,9 +320,9 @@ static int tcl_utimerexists STDVAR BADARGS(2, 2, " utimerName"); if (find_timer(utimer, argv[1])) { - Tcl_AppendResult(irp, "1", NULL); + Tcl_SetResult(irp, "1", TCL_STATIC); } else { - Tcl_AppendResult(irp, "0", NULL); + Tcl_SetResult(irp, "0", TCL_STATIC); } return TCL_OK; } From 3aa8ed0b01cd8ba5cccab89725cc2dc50eeb49da Mon Sep 17 00:00:00 2001 From: "ZarTek @ CREOLE" <11725850+ZarTek-Creole@users.noreply.github.com> Date: Fri, 11 Apr 2025 17:00:43 +0000 Subject: [PATCH 3/4] DOCS: `Added timerexists and utimerexists commands to core module` --- doc/sphinx_source/using/tcl-commands.rst | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/doc/sphinx_source/using/tcl-commands.rst b/doc/sphinx_source/using/tcl-commands.rst index 6c4fb5667..365cca838 100644 --- a/doc/sphinx_source/using/tcl-commands.rst +++ b/doc/sphinx_source/using/tcl-commands.rst @@ -2359,6 +2359,46 @@ utimer [count [timerName]] Module: core +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +timerexists +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Description: Checks if a named minutely timer exists. + + Returns: + - "1" if the timer exists + - "0" if the timer doesn't exist + + Examples: + ```tcl + # Check timer existence + if {[timerexists "mytimer"]} { + putlog "Timer 'mytimer' exists" + } + ``` + + Module: core + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +utimerexists +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Description: Checks if a named secondly timer (utimer) exists. + + Returns: + - "1" if the utimer exists + - "0" if the utimer doesn't exist + + Examples: + ```tcl + # Check utimer existence + if {![utimerexists "myutimer"]} { + utimer 30 [list do_something] 0 "myutimer" + } + ``` + + Module: core + ^^^^^^ timers ^^^^^^ From b0631d537e4fd2cc3abb5309c1de1a3e0424bbde Mon Sep 17 00:00:00 2001 From: "ZarTek @ CREOLE" <11725850+ZarTek-Creole@users.noreply.github.com> Date: Tue, 22 Apr 2025 08:58:45 +0000 Subject: [PATCH 4/4] rename to timerexistsname and utimerexistsname --- doc/sphinx_source/using/tcl-commands.rst | 8 ++++---- src/tclmisc.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/sphinx_source/using/tcl-commands.rst b/doc/sphinx_source/using/tcl-commands.rst index 365cca838..abfe37ecd 100644 --- a/doc/sphinx_source/using/tcl-commands.rst +++ b/doc/sphinx_source/using/tcl-commands.rst @@ -2360,7 +2360,7 @@ utimer [count [timerName]] Module: core ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -timerexists +timerexistsname ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description: Checks if a named minutely timer exists. @@ -2372,7 +2372,7 @@ timerexists Examples: ```tcl # Check timer existence - if {[timerexists "mytimer"]} { + if {[timerexistsname "mytimer"]} { putlog "Timer 'mytimer' exists" } ``` @@ -2380,7 +2380,7 @@ timerexists Module: core ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -utimerexists +utimerexistsname ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description: Checks if a named secondly timer (utimer) exists. @@ -2392,7 +2392,7 @@ utimerexists Examples: ```tcl # Check utimer existence - if {![utimerexists "myutimer"]} { + if {![utimerexistsname "myutimer"]} { utimer 30 [list do_something] 0 "myutimer" } ``` diff --git a/src/tclmisc.c b/src/tclmisc.c index 0de2e7e11..b14e5bc75 100644 --- a/src/tclmisc.c +++ b/src/tclmisc.c @@ -303,7 +303,7 @@ static int tcl_utimer STDVAR Tcl_AppendResult(irp, x, NULL); return TCL_OK; } -static int tcl_timerexists STDVAR +static int tcl_timerexistsname STDVAR { BADARGS(2, 2, " timerName"); @@ -315,7 +315,7 @@ static int tcl_timerexists STDVAR return TCL_OK; } -static int tcl_utimerexists STDVAR +static int tcl_utimerexistsname STDVAR { BADARGS(2, 2, " utimerName"); @@ -845,8 +845,8 @@ tcl_cmds tclmisc_cmds[] = { {"putloglev", tcl_putloglev}, {"timer", tcl_timer}, {"utimer", tcl_utimer}, - {"timerexists", tcl_timerexists}, - {"utimerexists", tcl_utimerexists}, + {"timerexistsname", tcl_timerexistsname}, + {"utimerexistsname", tcl_utimerexistsname}, {"killtimer", tcl_killtimer}, {"killutimer", tcl_killutimer}, {"timers", tcl_timers},