From dbf5d92605a9db10e3e3cb154d03a515c5d5c5af Mon Sep 17 00:00:00 2001 From: reinelt Date: Sun, 8 May 2005 04:32:45 +0000 Subject: [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 --- plugin_cpuinfo.c | 133 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 60 deletions(-) (limited to 'plugin_cpuinfo.c') 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); } -- cgit v1.2.3