[hackers] [wmii] Add clientutil.c || Kris Maglione

From: <hg_AT_suckless.org>
Date: Thu, 14 May 2009 03:44:44 +0000 (UTC)

changeset: 2448:29210d91d76a
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Wed May 13 23:44:42 2009 -0400
files: cmd/clientutil.c include/clientutil.h
description:
Add clientutil.c

diff -r 06cbf1f654d4 -r 29210d91d76a cmd/clientutil.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/clientutil.c Wed May 13 23:44:42 2009 -0400
@@ -0,0 +1,50 @@
+#define IXP_NO_P9_
+#define IXP_P9_STRUCTS
+#define CLIENTEXTERN
+#include <string.h>
+#include <ixp.h>
+#include <clientutil.h>
+#include <util.h>
+
+static IxpCFid* ctlfid;
+static char ctl[1024];
+static char* ectl;
+
+char*
+readctl(char *key) {
+ char *s, *p;
+ int nkey, n;
+
+ if(ctlfid == nil) {
+ ctlfid = ixp_open(client, "ctl", OREAD);
+ n = ixp_read(ctlfid, ctl, 1023);
+ ectl = ctl + n;
+ ixp_close(ctlfid);
+ }
+
+ nkey = strlen(key);
+ p = ctl - 1;
+ do {
+ p++;
+ if(!strncmp(p, key, nkey)) {
+ p += nkey;
+ s = strchr(p, '\n');
+ n = (s ? s : ectl) - p;
+ s = freelater(emalloc(n + 1));
+ s[n] = '\0';
+ return strncpy(s, p, n);
+ }
+ } while((p = strchr(p, '\n')));
+ return "";
+}
+
+void
+client_init(char* address) {
+ if(address && *address)
+ client = ixp_mount(address);
+ else
+ client = ixp_nsmount("wmii");
+ if(client == nil)
+ fatal("can't mount: %r\n");
+}
+
diff -r 06cbf1f654d4 -r 29210d91d76a include/clientutil.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/clientutil.h Wed May 13 23:44:42 2009 -0400
@@ -0,0 +1,9 @@
+#ifndef CLIENTEXTERN
+# define CLIENTEXTERN extern
+#endif
+
+char* readctl(char*);
+void client_init(char*);
+
+CLIENTEXTERN IxpClient* client;
+
Received on Thu May 14 2009 - 03:44:44 UTC

This archive was generated by hypermail 2.2.0 : Thu May 14 2009 - 03:48:03 UTC