summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-03-10 21:56:51 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-03-10 21:56:51 +0300
commit126b33a9db9b44a56f2c62d18346746ec1330766 (patch)
treea1d651271c5210629ddfa0d63ccf7e1fce459c5f
parent1e4d86595be2b5595f343437f8bb74ea60af22f3 (diff)
downloadProject-Tick-126b33a9db9b44a56f2c62d18346746ec1330766.tar.gz
Project-Tick-126b33a9db9b44a56f2c62d18346746ec1330766.zip
add testcmd.c and add define SH_ERROR_H to error.h
Signed-off-by: Mehmet Samet Duman <yongdohyun@projecttick.org>
-rw-r--r--error.h5
-rw-r--r--testcmd.c34
2 files changed, 39 insertions, 0 deletions
diff --git a/error.h b/error.h
index 6db0bcde19..088baea429 100644
--- a/error.h
+++ b/error.h
@@ -43,6 +43,9 @@
* inner scope, and restore handler on exit from the scope.
*/
+#ifndef SH_ERROR_H
+#define SH_ERROR_H
+
#include <setjmp.h>
#include <signal.h>
@@ -92,3 +95,5 @@ void errorwithstatus(int, const char *, ...) __printf0like(2, 3) __dead2;
#define setjmp(jmploc) _setjmp(jmploc)
#define longjmp(jmploc, val) _longjmp(jmploc, val)
+
+#endif /* SH_ERROR_H */
diff --git a/testcmd.c b/testcmd.c
new file mode 100644
index 0000000000..d82d3c9e45
--- /dev/null
+++ b/testcmd.c
@@ -0,0 +1,34 @@
+/*
+ * Reuse the standalone test(1) parser as the shell builtin entry point.
+ * The external source now exports main() and exits on syntax errors, so
+ * provide a wrapper that maps its process-exit path back to a builtin
+ * return value.
+ */
+
+#include <setjmp.h>
+#include <stdio.h>
+
+static jmp_buf testcmd_jmp;
+static int testcmd_status;
+
+static void
+testcmd_exit(int status)
+{
+ testcmd_status = status;
+ fflush(NULL);
+ longjmp(testcmd_jmp, 1);
+}
+
+#define exit testcmd_exit
+#define main testcmd_main
+#include "../../bin/test/test.c"
+#undef main
+#undef exit
+
+int
+testcmd(int argc, char **argv)
+{
+ if (setjmp(testcmd_jmp) != 0)
+ return testcmd_status;
+ return testcmd_main(argc, argv);
+}