diff options
author | reinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2005-05-08 04:32:45 +0000 |
---|---|---|
committer | reinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2005-05-08 04:32:45 +0000 |
commit | dbf5d92605a9db10e3e3cb154d03a515c5d5c5af (patch) | |
tree | 501d5dda3ce90fe924b893e487d9ef9f0683382b /plugin_cpuinfo.c | |
parent | a1c471e9fb7cadb68bb182ab2e9715a0aa092386 (diff) | |
download | lcd4linux-dbf5d92605a9db10e3e3cb154d03a515c5d5c5af.tar.gz |
[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
Diffstat (limited to 'plugin_cpuinfo.c')
-rw-r--r-- | plugin_cpuinfo.c | 133 |
1 files changed, 73 insertions, 60 deletions
diff --git a/plugin_cpuinfo.c b/plugin_cpuinfo.c index 3d9d9e9..e091383 100644 --- a/plugin_cpuinfo.c +++ b/plugin_cpuinfo.c @@ -1,4 +1,4 @@ -/* $Id: plugin_cpuinfo.c,v 1.13 2005/01/18 06:30:23 reinelt Exp $ +/* $Id: plugin_cpuinfo.c,v 1.14 2005/05/08 04:32:44 reinelt Exp $ * * plugin for /proc/cpuinfo parsing * @@ -23,6 +23,9 @@ * * * $Log: plugin_cpuinfo.c,v $ + * Revision 1.14 2005/05/08 04:32:44 reinelt + * CodingStyle added and applied + * * Revision 1.13 2005/01/18 06:30:23 reinelt * added (C) to all copyright statements * @@ -111,74 +114,84 @@ static HASH CPUinfo; static FILE *stream = NULL; -static int parse_cpuinfo (void) +static int parse_cpuinfo(void) { - int age; - - /* reread every second only */ - age = hash_age(&CPUinfo, NULL); - if (age > 0 && age <= 1000) return 0; - - if (stream == NULL) stream = fopen("/proc/cpuinfo", "r"); - if (stream == NULL) { - error ("fopen(/proc/cpuinfo) failed: %s", strerror(errno)); - return -1; - } - rewind(stream); - 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 (&CPUinfo, key, val); - - } - return 0; + int age; + + /* reread every second only */ + age = hash_age(&CPUinfo, NULL); + if (age > 0 && age <= 1000) + return 0; + + if (stream == NULL) + stream = fopen("/proc/cpuinfo", "r"); + if (stream == NULL) { + error("fopen(/proc/cpuinfo) failed: %s", strerror(errno)); + return -1; + } + rewind(stream); + 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(&CPUinfo, key, val); + + } + return 0; } - -static void my_cpuinfo (RESULT *result, RESULT *arg1) + +static void my_cpuinfo(RESULT * result, RESULT * arg1) { - char *key, *val; - - if (parse_cpuinfo() < 0) { - SetResult(&result, R_STRING, ""); - return; - } - - key = R2S(arg1); - val = hash_get(&CPUinfo, key, NULL); - if (val == NULL) val = ""; - - SetResult(&result, R_STRING, val); + char *key, *val; + + if (parse_cpuinfo() < 0) { + SetResult(&result, R_STRING, ""); + return; + } + + key = R2S(arg1); + val = hash_get(&CPUinfo, key, NULL); + if (val == NULL) + val = ""; + + SetResult(&result, R_STRING, val); } -int plugin_init_cpuinfo (void) +int plugin_init_cpuinfo(void) { - hash_create (&CPUinfo); - AddFunction ("cpuinfo", 1, my_cpuinfo); - return 0; + hash_create(&CPUinfo); + AddFunction("cpuinfo", 1, my_cpuinfo); + return 0; } -void plugin_exit_cpuinfo(void) +void plugin_exit_cpuinfo(void) { - if (stream != NULL) { - fclose (stream); - stream = NULL; - } - hash_destroy(&CPUinfo); + if (stream != NULL) { + fclose(stream); + stream = NULL; + } + hash_destroy(&CPUinfo); } |