wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit c9162ecb451f0d44eb851bff6cd84e0a2931348e
parent e3bea241be281c68cc80c8de36e2e91375041e25
Author: Kris Maglione <jg@suckless.org>
Date:   Wed, 13 May 2009 23:44:42 -0400

Add clientutil.c

Diffstat:
cmd/clientutil.c | 50++++++++++++++++++++++++++++++++++++++++++++++++++
include/clientutil.h | 9+++++++++
2 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/cmd/clientutil.c b/cmd/clientutil.c @@ -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 --git a/include/clientutil.h b/include/clientutil.h @@ -0,0 +1,9 @@ +#ifndef CLIENTEXTERN +# define CLIENTEXTERN extern +#endif + +char* readctl(char*); +void client_init(char*); + +CLIENTEXTERN IxpClient* client; +