aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_seti.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugin_seti.c')
-rw-r--r--plugin_seti.c177
1 files changed, 95 insertions, 82 deletions
diff --git a/plugin_seti.c b/plugin_seti.c
index 2f46a0e..c28746b 100644
--- a/plugin_seti.c
+++ b/plugin_seti.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_seti.c,v 1.6 2005/01/18 06:30:23 reinelt Exp $
+/* $Id: plugin_seti.c,v 1.7 2005/05/08 04:32:45 reinelt Exp $
*
* plugin for seti@home status reporting
*
@@ -27,6 +27,9 @@
*
*
* $Log: plugin_seti.c,v $
+ * Revision 1.7 2005/05/08 04:32:45 reinelt
+ * CodingStyle added and applied
+ *
* Revision 1.6 2005/01/18 06:30:23 reinelt
* added (C) to all copyright statements
*
@@ -81,97 +84,107 @@
static HASH SETI;
static int fatal = 0;
-static int parse_seti (void)
+static int parse_seti(void)
{
- static char fn[256] = "";
- FILE *stream;
- int age;
-
- /* if a fatal error occured, do nothing */
- if (fatal != 0) return -1;
-
- /* reread every 100 msec only */
- age=hash_age(&SETI, NULL);
- if (age>0 && age<=100) return 0;
-
- if (fn[0] == '\0') {
- char *dir = cfg_get (SECTION, DIRKEY, NULL);
- if (dir == NULL || *dir == '\0') {
- error ("no '%s.%s' entry from %s\n", SECTION, DIRKEY, cfg_source());
- fatal = 1;
- return -1;
+ static char fn[256] = "";
+ FILE *stream;
+ int age;
+
+ /* if a fatal error occured, do nothing */
+ if (fatal != 0)
+ return -1;
+
+ /* reread every 100 msec only */
+ age = hash_age(&SETI, NULL);
+ if (age > 0 && age <= 100)
+ return 0;
+
+ if (fn[0] == '\0') {
+ char *dir = cfg_get(SECTION, DIRKEY, NULL);
+ if (dir == NULL || *dir == '\0') {
+ error("no '%s.%s' entry from %s\n", SECTION, DIRKEY, cfg_source());
+ fatal = 1;
+ return -1;
+ }
+ if (strlen(dir) > sizeof(fn) - sizeof(STATEFILE) - 2) {
+ error("entry '%s.%s' too long from %s!\n", SECTION, DIRKEY, cfg_source());
+ fatal = 1;
+ free(dir);
+ return -1;
+ }
+ strcpy(fn, dir);
+ if (fn[strlen(fn) - 1] != '/')
+ strcat(fn, "/");
+ strcat(fn, STATEFILE);
+ free(dir);
}
- if (strlen(dir) > sizeof(fn)-sizeof(STATEFILE)-2) {
- error ("entry '%s.%s' too long from %s!\n", SECTION, DIRKEY, cfg_source());
- fatal = 1;
- free (dir);
- return -1;
+
+ stream = fopen(fn, "r");
+ if (stream == NULL) {
+ error("fopen(%s) failed: %s", fn, strerror(errno));
+ return -1;
+ }
+
+ while (!feof(stream)) {
+ char buffer[256];
+ char *c, *key, *val;
+ fgets(buffer, sizeof(buffer), stream);
+ c = strchr(buffer, '=');
+ if (c == NULL)
+ continue;
+ key = buffer;
+ 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';
+ /* add entry to hash table */
+ hash_put(&SETI, key, val);
}
- strcpy (fn, dir);
- if (fn[strlen(fn)-1]!='/')
- strcat (fn, "/");
- strcat (fn, STATEFILE);
- free (dir);
- }
-
- stream = fopen(fn, "r");
- if (stream == NULL) {
- error ("fopen(%s) failed: %s", fn, strerror(errno));
- return -1;
- }
-
- while (!feof(stream)) {
- char buffer[256];
- char *c, *key, *val;
- fgets (buffer, sizeof(buffer), stream);
- c=strchr(buffer, '=');
- if (c==NULL) continue;
- key=buffer; 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';
- /* add entry to hash table */
- hash_put (&SETI, key, val);
- }
-
- fclose (stream);
-
- return 0;
-}
-
-
-static void my_seti (RESULT *result, RESULT *arg1)
+
+ fclose(stream);
+
+ return 0;
+}
+
+
+static void my_seti(RESULT * result, RESULT * arg1)
{
- char *key, *val;
-
- if (parse_seti()<0) {
- SetResult(&result, R_STRING, "");
- return;
- }
-
- key=R2S(arg1);
- val=hash_get(&SETI, key, NULL);
- if (val==NULL) val="";
-
- SetResult(&result, R_STRING, val);
+ char *key, *val;
+
+ if (parse_seti() < 0) {
+ SetResult(&result, R_STRING, "");
+ return;
+ }
+
+ key = R2S(arg1);
+ val = hash_get(&SETI, key, NULL);
+ if (val == NULL)
+ val = "";
+
+ SetResult(&result, R_STRING, val);
}
-int plugin_init_seti (void)
+int plugin_init_seti(void)
{
- hash_create(&SETI);
- AddFunction ("seti", 1, my_seti);
- return 0;
+ hash_create(&SETI);
+ AddFunction("seti", 1, my_seti);
+ return 0;
}
-void plugin_exit_seti(void)
+void plugin_exit_seti(void)
{
- hash_destroy(&SETI);
+ hash_destroy(&SETI);
}