aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--layout.c21
-rw-r--r--plugin_cfg.c27
-rw-r--r--plugin_netdev.c21
-rw-r--r--plugin_proc_stat.c122
4 files changed, 133 insertions, 58 deletions
diff --git a/layout.c b/layout.c
index 7fb01de..451d80a 100644
--- a/layout.c
+++ b/layout.c
@@ -1,4 +1,4 @@
-/* $Id: layout.c,v 1.8 2004/02/01 18:08:50 reinelt Exp $
+/* $Id: layout.c,v 1.9 2004/02/01 19:37:40 reinelt Exp $
*
* new layouter framework
*
@@ -23,6 +23,9 @@
*
*
* $Log: layout.c,v $
+ * Revision 1.9 2004/02/01 19:37:40 reinelt
+ * got rid of every strtok() incarnation.
+ *
* Revision 1.8 2004/02/01 18:08:50 reinelt
* removed strtok() from layout processing (took me hours to find this bug)
* further strtok() removind should be done!
@@ -111,20 +114,22 @@ int layout_init (char *layout)
// map to lower char for scanf()
for (l=list; *l!='\0'; l++) *l=tolower(*l);
- while (list!=NULL) {
- char *pipe;
+ l=list;
+ while (l!=NULL) {
+ char *p;
int i, n;
// list is delimited by |
- if ((pipe=strchr(list, '|'))!=NULL) *pipe='\0';
- i=sscanf (list, "row%d.col%d%n", &row, &col, &n);
- if (i==2 && list[n]=='\0') {
- widget=cfg_get(section, list, NULL);
+ while (*l=='|') l++;
+ if ((p=strchr(l, '|'))!=NULL) *p='\0';
+ i=sscanf (l, "row%d.col%d%n", &row, &col, &n);
+ if (i==2 && l[n]=='\0') {
+ widget=cfg_get(section, l, NULL);
if (widget!=NULL && *widget!='\0') {
layout_addItem (widget, row, col);
}
}
// next field
- list=pipe?pipe+1:NULL;
+ l=p?p+1:NULL;
}
free (list);
diff --git a/plugin_cfg.c b/plugin_cfg.c
index 14296c4..0a9f9c6 100644
--- a/plugin_cfg.c
+++ b/plugin_cfg.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_cfg.c,v 1.4 2004/01/30 20:57:56 reinelt Exp $
+/* $Id: plugin_cfg.c,v 1.5 2004/02/01 19:37:40 reinelt Exp $
*
* plugin for config file access
*
@@ -23,6 +23,9 @@
*
*
* $Log: plugin_cfg.c,v $
+ * Revision 1.5 2004/02/01 19:37:40 reinelt
+ * got rid of every strtok() incarnation.
+ *
* Revision 1.4 2004/01/30 20:57:56 reinelt
* HD44780 patch from Martin Hejl
* dmalloc integrated
@@ -70,28 +73,30 @@
static void load_variables (void)
{
char *section="Variables";
- char *list, *key;
+ char *list, *l, *p;
char *expression;
RESULT result = {0, 0.0, NULL};
list=cfg_list(section);
- key=strtok(list, "|");
- while (key!=NULL) {
- if (strchr(key, '.')!=NULL || strchr(key, ':') !=0) {
- error ("ignoring variable '%s' from %s: structures not allowed", key, cfg_source());
+ l=list;
+ while (l!=NULL) {
+ while (*l=='|') l++;
+ if ((p=strchr(l, '|'))!=NULL) *p='\0';
+ if (strchr(l, '.')!=NULL || strchr(l, ':') !=0) {
+ error ("ignoring variable '%s' from %s: structures not allowed", l, cfg_source());
} else {
- expression=cfg_get_raw (section, key, "");
+ expression=cfg_get_raw (section, l, "");
if (expression!=NULL && *expression!='\0') {
if (Eval(expression, &result)==0) {
- debug ("Variable %s = '%s' (%f)", key, R2S(&result), R2N(&result));
- SetVariable (key, &result);
+ debug ("Variable %s = '%s' (%f)", l, R2S(&result), R2N(&result));
+ SetVariable (l, &result);
DelResult (&result);
} else {
- error ("error evaluating variable '%s' from %s", key, cfg_source());
+ error ("error evaluating variable '%s' from %s", list, cfg_source());
}
}
}
- key=strtok(NULL, "|");
+ l=p?p+1:NULL;
}
free (list);
diff --git a/plugin_netdev.c b/plugin_netdev.c
index edfe1c4..2d49e3f 100644
--- a/plugin_netdev.c
+++ b/plugin_netdev.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_netdev.c,v 1.2 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_netdev.c,v 1.3 2004/02/01 19:37:40 reinelt Exp $
*
* plugin for /proc/net/dev parsing
*
@@ -23,6 +23,9 @@
*
*
* $Log: plugin_netdev.c,v $
+ * Revision 1.3 2004/02/01 19:37:40 reinelt
+ * got rid of every strtok() incarnation.
+ *
* Revision 1.2 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
@@ -86,8 +89,9 @@ static int parse_netdev (void)
line=0;
while (!feof(stream)) {
char buffer[256];
- char header[256];
+ char header[256], *h, *t;
char *head[32];
+ char delim[]=" :|\t\n";
int col;
if (fgets (buffer, sizeof(buffer), stream) == NULL) break;
@@ -97,26 +101,29 @@ static int parse_netdev (void)
// line 2 used for headers
if (line==2) {
- char *h;
strncpy(header, buffer, sizeof(header));
RxTx=(strrchr(header, '|') - header);
col=0;
- h=strtok(header, "| \t\n");
+ h=header;
while (h!=NULL) {
+ while (strchr(delim, *h)) h++;
+ if ((t=strpbrk(h, delim))!=NULL) *t='\0';
head[col++]=h;
- h=strtok(NULL, "| \t\n");
+ h=t?t+1:NULL;
}
} else {
char *h, *iface=NULL;
col=0;
- h=strtok(buffer, ":| \t\n");
+ h=buffer;
while (h!=NULL) {
+ while (strchr(delim, *h)) h++;
+ if ((t=strpbrk(h, delim))!=NULL) *t='\0';
if (col==0) {
iface=h;
} else {
hash_set3 (iface, (h-buffer) < RxTx ? "Rx" : "Tx", head[col], h);
}
- h=strtok(NULL, "| \t\n");
+ h=t?t+1:NULL;
col++;
}
}
diff --git a/plugin_proc_stat.c b/plugin_proc_stat.c
index 5053787..48a19a0 100644
--- a/plugin_proc_stat.c
+++ b/plugin_proc_stat.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_proc_stat.c,v 1.13 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_proc_stat.c,v 1.14 2004/02/01 19:37:40 reinelt Exp $
*
* plugin for /proc/stat parsing
*
@@ -23,6 +23,9 @@
*
*
* $Log: plugin_proc_stat.c,v $
+ * Revision 1.14 2004/02/01 19:37:40 reinelt
+ * got rid of every strtok() incarnation.
+ *
* Revision 1.13 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
@@ -97,6 +100,7 @@ static HASH Stat = { 0, };
static void hash_set1 (char *key1, char *val)
{
+ debug ("Michi: hash_set (<%s>=<%s>)", key1, val);
hash_set_delta (&Stat, key1, val);
}
@@ -137,51 +141,105 @@ static int parse_proc_stat (void)
while (!feof(stream)) {
char buffer[1024];
if (fgets (buffer, sizeof(buffer), stream) == NULL) break;
-
+
if (strncmp(buffer, "cpu", 3)==0) {
- char *cpu;
- 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"));
+ char *key[] = { "user", "nice", "system", "idle" };
+ char delim[] = " \t\n";
+ char *cpu, *beg, *end;
+ int i;
+
+ cpu=buffer;
+
+ // skip "cpu" or "cpu0" block
+ if ((end=strpbrk(buffer, delim))!=NULL) *end='\0';
+ beg=end?end+1:NULL;
+
+ for (i=0; i<4 && beg!=NULL; i++) {
+ while (strchr(delim, *beg)) beg++;
+ if ((end=strpbrk(beg, delim))) *end='\0';
+ hash_set2 (cpu, key[i], beg);
+ beg=end?end+1:NULL;
+ }
}
+
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"));
+ char *key[] = { "in", "out" };
+ char delim[] = " \t\n";
+ char *beg, *end;
+ int i;
+
+ for (i=0, beg=buffer+5; i<2 && beg!=NULL; i++) {
+ while (strchr(delim, *beg)) beg++;
+ if ((end=strpbrk(beg, delim))) *end='\0';
+ hash_set2 ("page", key[i], beg);
+ beg=end?end+1:NULL;
+ }
}
+
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"));
+ char *key[] = { "in", "out" };
+ char delim[] = " \t\n";
+ char *beg, *end;
+ int i;
+
+ for (i=0, beg=buffer+5; i<2 && beg!=NULL; i++) {
+ while (strchr(delim, *beg)) beg++;
+ if ((end=strpbrk(beg, delim))) *end='\0';
+ hash_set2 ("swap", key[i], beg);
+ beg=end?end+1:NULL;
+ }
}
+
else if (strncmp(buffer, "intr ", 5)==0) {
+ char delim[]=" \t\n";
+ char *beg, *end, num[4];
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"));
+
+ for (i=0, beg=buffer+5; i<17 && beg!=NULL; i++) {
+ while (strchr(delim, *beg)) beg++;
+ if ((end=strpbrk(beg, delim))) *end='\0';
+ if (i==0)
+ snprintf(num, sizeof(num), "sum");
+ else
+ snprintf(num, sizeof(num), "%d", i-1);
+ hash_set2 ("intr", num, beg);
+ beg=end?end+1:NULL;
}
}
+
+
else if (strncmp(buffer, "disk_io:", 8)==0) {
- char *dev=strtok(buffer+8, " \t\n:()");
+ char *key[] = { "io", "rio", "rblk", "wio", "wblk" };
+ char delim[] = " ():,\t\n";
+ char *dev, *beg, *end, *p;
+ int i;
+
+ dev=buffer+8;
while (dev!=NULL) {
- char *p;
+ while (strchr(delim, *dev)) dev++;
+ if ((end=strchr(dev, ')'))) *end='\0';
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, " ,)"));
- dev=strtok(NULL, " \t\n:()");
- }
- }
+ beg=end?end+1:NULL;
+ for (i=0; i<5 && beg!=NULL; i++) {
+ while (strchr(delim, *beg)) beg++;
+ if ((end=strpbrk(beg, delim))) *end='\0';
+ hash_set3 ("disk_io", dev, key[i], beg);
+ beg=end?end+1:NULL;
+ }
+ dev=beg;
+ }
+ }
+
else {
- char *key=strtok(buffer, " \t\n");
- hash_set2 (key, NULL, strtok(NULL, " \t\n"));
+ char delim[] = " \t\n";
+ char *beg, *end;
+
+ beg=buffer;
+ if ((end=strpbrk(beg, delim))) *end='\0';
+ beg=end?end+1:NULL;
+ if ((end=strpbrk(beg, delim))) *end='\0';
+ while (strchr(delim, *beg)) beg++;
+ hash_set1 (buffer, beg);
}
}
fclose (stream);