[lcd4linux @ 2005-05-08 04:32:43 by reinelt]

CodingStyle added and applied

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@547 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
reinelt
2005-05-08 04:32:45 +00:00
parent a1c471e9fb
commit dbf5d92605
94 changed files with 16200 additions and 15384 deletions

View File

@@ -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;
}
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;
}
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);
}
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);
fclose(stream);
return 0;
}
int plugin_init_seti (void)
static void my_seti(RESULT * result, RESULT * arg1)
{
hash_create(&SETI);
AddFunction ("seti", 1, my_seti);
return 0;
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);
}
void plugin_exit_seti(void)
int plugin_init_seti(void)
{
hash_destroy(&SETI);
hash_create(&SETI);
AddFunction("seti", 1, my_seti);
return 0;
}
void plugin_exit_seti(void)
{
hash_destroy(&SETI);
}