Commit: 9074d06ac54b924b2d24df2b5fb03420563691c8
Parent: b870f8fde71de0bd410d083f768ec3d9ac183282
Author: Randy Palamar
Date: Mon, 23 Aug 2021 17:51:02 -0600
add script() block
no example usage given on purpose
Diffstat:
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/blocks/script.c b/blocks/script.c
@@ -0,0 +1,24 @@
+/* See LICENSE for license details. */
+#include <stdio.h>
+#include <string.h>
+
+#include "../status.h"
+#include "../util.h"
+#include "script.h"
+
+size_t
+script(struct Block *b)
+{
+ FILE *fp;
+
+ if ((fp = popen(b->u.s, "r")) == NULL)
+ die("popen()\n");
+
+ fgets(buf, sizeof(buf), fp);
+ pclose(fp);
+
+ if (buf[strlen(buf) - 1] == '\n')
+ buf[strlen(buf) - 1] = 0;
+
+ return snprintf(b->curstr, LEN(b->curstr), b->fmt, buf);
+}
diff --git a/blocks/script.h b/blocks/script.h
@@ -0,0 +1 @@
+size_t script(struct Block *);