aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-01-16 11:12:26 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-01-16 11:12:26 +0000
commitd672d4d499f0df79bc371b0ca9ca4a7f44477311 (patch)
tree14098d862eb2cef91f9c813eeedd8b1362cb1b58
parentc12ec4c53a04bdb0424ea1562be46df1f14f3614 (diff)
downloadlcd4linux-d672d4d499f0df79bc371b0ca9ca4a7f44477311.tar.gz
[lcd4linux @ 2004-01-16 11:12:26 by reinelt]
some bugs in plugin_xmms fixed, parsing moved to own function plugin_proc_stat nearly finished git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@317 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r--hash.h8
-rw-r--r--plugin_cpuinfo.c8
-rw-r--r--plugin_proc_stat.c80
-rw-r--r--plugin_xmms.c81
4 files changed, 128 insertions, 49 deletions
diff --git a/hash.h b/hash.h
index d410d3d..7ab1634 100644
--- a/hash.h
+++ b/hash.h
@@ -1,4 +1,4 @@
-/* $Id: hash.h,v 1.3 2004/01/16 07:26:25 reinelt Exp $
+/* $Id: hash.h,v 1.4 2004/01/16 11:12:26 reinelt Exp $
*
* hashes (associative arrays)
*
@@ -23,6 +23,10 @@
*
*
* $Log: hash.h,v $
+ * Revision 1.4 2004/01/16 11:12:26 reinelt
+ * some bugs in plugin_xmms fixed, parsing moved to own function
+ * plugin_proc_stat nearly finished
+ *
* Revision 1.3 2004/01/16 07:26:25 reinelt
* moved various /proc parsing to own functions
* made some progress with /proc/stat parsing
@@ -56,7 +60,7 @@ typedef struct {
typedef struct {
- struct timeval time;
+ // struct timeval time;
double val;
} FILTER_SLOT;
diff --git a/plugin_cpuinfo.c b/plugin_cpuinfo.c
index efa5d4a..1102056 100644
--- a/plugin_cpuinfo.c
+++ b/plugin_cpuinfo.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_cpuinfo.c,v 1.4 2004/01/16 07:26:25 reinelt Exp $
+/* $Id: plugin_cpuinfo.c,v 1.5 2004/01/16 11:12:26 reinelt Exp $
*
* plugin for /proc/cpuinfo parsing
*
@@ -23,6 +23,10 @@
*
*
* $Log: plugin_cpuinfo.c,v $
+ * Revision 1.5 2004/01/16 11:12:26 reinelt
+ * some bugs in plugin_xmms fixed, parsing moved to own function
+ * plugin_proc_stat nearly finished
+ *
* Revision 1.4 2004/01/16 07:26:25 reinelt
* moved various /proc parsing to own functions
* made some progress with /proc/stat parsing
@@ -100,7 +104,7 @@ static int parse_cpuinfo (void)
// strip trailing blanks from value
for (c=val; *c!='\0';c++);
while (isspace(*--c)) *c='\0';
-
+
// add entry to hash table
hash_set (&CPUinfo, key, val);
diff --git a/plugin_proc_stat.c b/plugin_proc_stat.c
index e7b9bf8..90ddd45 100644
--- a/plugin_proc_stat.c
+++ b/plugin_proc_stat.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_proc_stat.c,v 1.2 2004/01/16 07:26:25 reinelt Exp $
+/* $Id: plugin_proc_stat.c,v 1.3 2004/01/16 11:12:26 reinelt Exp $
*
* plugin for /proc/stat parsing
*
@@ -23,6 +23,10 @@
*
*
* $Log: plugin_proc_stat.c,v $
+ * Revision 1.3 2004/01/16 11:12:26 reinelt
+ * some bugs in plugin_xmms fixed, parsing moved to own function
+ * plugin_proc_stat nearly finished
+ *
* Revision 1.2 2004/01/16 07:26:25 reinelt
* moved various /proc parsing to own functions
* made some progress with /proc/stat parsing
@@ -79,12 +83,26 @@ static int renew(int msec)
}
-static void my_hash_set (char *key1, char *key2, char *val)
+static void hash_set1 (char *key1, char *val)
{
- char key[16];
+ hash_set (&Stat, key1, val);
+}
+
+static void hash_set2 (char *key1, char *key2, char *val)
+{
+ char key[32];
snprintf (key, sizeof(key), "%s.%s", key1, key2);
- debug ("Michi: hash_set(%s, %s)", key, val);
+ // debug ("Michi: hash_set(%s, %s)", key, val);
+ hash_set (&Stat, key, val);
+}
+
+static void hash_set3 (char *key1, char *key2, char *key3, char *val)
+{
+ char key[32];
+
+ snprintf (key, sizeof(key), "%s.%s.%s", key1, key2, key3);
+ debug ("Michi: hash_set(%s)=<%s>", key, val);
hash_set (&Stat, key, val);
}
@@ -103,34 +121,64 @@ static int parse_proc_stat (void)
}
while (!feof(stream)) {
- char buffer[256];
- fgets (buffer, sizeof(buffer), stream);
-
+ char buffer[1024];
+ if (fgets (buffer, sizeof(buffer), stream) ==NULL) break;
if (strncmp(buffer, "cpu", 3)==0) {
char *cpu;
- cpu=strtok(buffer, " \t");
- my_hash_set (cpu, "user", strtok(NULL, " \t"));
- my_hash_set (cpu, "nice", strtok(NULL, " \t"));
- my_hash_set (cpu, "system", strtok(NULL, " \t"));
- my_hash_set (cpu, "idle", strtok(NULL, " \t"));
+ cpu=strtok(buffer, " \t\n");
+ hash_set2 (cpu, "user", strtok(NULL, " \t\n"));
+ hash_set2 (cpu, "nice", strtok(NULL, " \t\n"));
+ hash_set2 (cpu, "system", strtok(NULL, " \t\n"));
+ hash_set2 (cpu, "idle", strtok(NULL, " \t\n"));
}
else if (strncmp(buffer, "page ", 5)==0) {
-
+ strtok(buffer, " \t\n");
+ hash_set2 ("page", "in", strtok(NULL, " \t\n"));
+ hash_set2 ("page", "out", strtok(NULL, " \t\n"));
}
else if (strncmp(buffer, "swap ", 5)==0) {
+ strtok(buffer, " \t\n");
+ hash_set2 ("swap", "in", strtok(NULL, " \t\n"));
+ hash_set2 ("swap", "out", strtok(NULL, " \t\n"));
}
else if (strncmp(buffer, "intr ", 5)==0) {
+ int i;
+ strtok(buffer, " \t\n");
+ hash_set2 ("intr", "sum", strtok(NULL, " \t\n"));
+ for (i=0; i<16; i++) {
+ char buffer[3];
+ snprintf(buffer, sizeof(buffer), "%d", i);
+ hash_set2 ("intr", buffer, strtok(NULL, " \t\n"));
+ }
}
else if (strncmp(buffer, "disk_io:", 8)==0) {
+ char *dev=strtok(buffer+8, " \t\n:()");
+ while (dev!=NULL) {
+ char *p;
+ while ((p=strchr(dev, ','))!=NULL) *p=':';
+ hash_set3 ("disk_io", dev, "io", strtok(NULL, " :(,"));
+ hash_set3 ("disk_io", dev, "rio", strtok(NULL, " ,"));
+ hash_set3 ("disk_io", dev, "rblk", strtok(NULL, " ,"));
+ hash_set3 ("disk_io", dev, "wio", strtok(NULL, " ,"));
+ hash_set3 ("disk_io", dev, "wblk", strtok(NULL, " ,)"));
+ // Fixme: check this one...
+ dev=strtok(NULL, " \t\n:()");
+ }
}
else if (strncmp(buffer, "ctxt ", 5)==0) {
+ strtok(buffer, " \t\n");
+ hash_set2 ("ctxt", NULL, strtok(NULL, " \t\n"));
}
- else if (strncmp(buffer, "btime ", 5)==0) {
+ else if (strncmp(buffer, "btime ", 6)==0) {
+ strtok(buffer, " \t\n");
+ hash_set2 ("btime", NULL, strtok(NULL, " \t\n"));
}
- else if (strncmp(buffer, "processes ", 5)==0) {
+ else if (strncmp(buffer, "processes ", 10)==0) {
+ strtok(buffer, " \t\n");
+ hash_set1 ("processes", strtok(NULL, " \t\n"));
}
else {
- error ("unknown line <%s> from /proc/stat");
+ error ("internal error: unhandled entry '%s' from /proc/stat", strtok(buffer, " \t\n"));
}
}
fclose (stream);
diff --git a/plugin_xmms.c b/plugin_xmms.c
index 700b828..4759196 100644
--- a/plugin_xmms.c
+++ b/plugin_xmms.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_xmms.c,v 1.3 2004/01/16 10:09:49 mkeil Exp $
+/* $Id: plugin_xmms.c,v 1.4 2004/01/16 11:12:26 reinelt Exp $
*
* XMMS-Plugin for LCD4Linux
* Copyright 2003 Markus Keil <markus_keil@t-online.de>
@@ -21,6 +21,10 @@
*
*
* $Log: plugin_xmms.c,v $
+ * Revision 1.4 2004/01/16 11:12:26 reinelt
+ * some bugs in plugin_xmms fixed, parsing moved to own function
+ * plugin_proc_stat nearly finished
+ *
* Revision 1.3 2004/01/16 10:09:49 mkeil
* -include caching for values
*
@@ -63,53 +67,72 @@
#include <string.h>
#include <stdio.h>
+#include <ctype.h>
#include <time.h>
#include "hash.h"
#include "debug.h"
#include "plugin.h"
-static void my_xmms (RESULT *result, RESULT *arg1)
-{
- static HASH xmms = { 0, 0, NULL };
- char *hash_key, *val;
+
+static HASH xmms = { 0, 0, NULL };
+
+
+static int parse_xmms_info (void)
+{
static time_t now=0;
FILE *xmms_stream;
char zeile[200];
- char *key=R2S(arg1);
- int len=strlen(key);
// reread every second only
- if (time(NULL)!=now) {
-
- //Open Filestream for '/tmp/xmms-info'
+ if (time(NULL)==now) return 0;
+ time(&now);
+
+ // Open Filestream for '/tmp/xmms-info'
xmms_stream = fopen("/tmp/xmms-info","r");
- //Check for File
+ // Check for File
if( !xmms_stream ) {
error("Error: Cannot open XMMS-Info Stream! Is XMMS started?");
- SetResult(&result, R_STRING, "");
- return;
+ return -1;
}
- //Read Lines from the Stream
- while(fgets(zeile,200,xmms_stream)) {
- hash_key=key; val=zeile;
- if (strncmp(key, zeile, len)==0 && zeile[len]==':') {
- // remove trailing newline
- zeile[strlen(zeile)-1]='\0';
- // add entry to hash table
- val=zeile+len+2;
- hash_set (&xmms, hash_key, val);
- time(&now);
- fclose(xmms_stream);
- }
- }
+ // Read Lines from the Stream
+ while(fgets(zeile,sizeof(zeile),xmms_stream)) {
+ char *c, *key, *val;
+ c=strchr(zeile, ':');
+ if (c==NULL) continue;
+ key=zeile; val=c+1;
+ // strip leading blanks from key
+ while (isspace(*key)) *key++='\0';
+ // strip trailing blanks from key
+ do *c='\0'; while (isspace(*--c));
+ // strip leading blanks from value
+ while (isspace(*val)) *val++='\0';
+ // strip trailing blanks from value
+ for (c=val; *c!='\0';c++);
+ while (isspace(*--c)) *c='\0';
+ hash_set (&xmms, key, val);
}
- hash_key=R2S(arg1);
- val=hash_get(&xmms, hash_key);
- if (val==NULL) val="";
+
+ fclose(xmms_stream);
+ return 0;
+
+}
+static void my_xmms (RESULT *result, RESULT *arg1)
+{
+ char *key, *val;
+
+ if (parse_xmms_info()<0) {
+ SetResult(&result, R_STRING, "");
+ return;
+ }
+
+ key=R2S(arg1);
+ val=hash_get(&xmms, key);
+ if (val==NULL) val="";
+
SetResult(&result, R_STRING, val);
}