From 7d0d6b07c9f5bd5dfd99aa7fe9826eebf2181f1f Mon Sep 17 00:00:00 2001 From: oetiker Date: Mon, 18 Jun 2007 16:05:07 +0000 Subject: [PATCH] Bernhard Fischer: - move several static struct option out of loops and makes them non-static - moves some functions from old-style definitions into new-style definitions git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1133 a5681a0c-68f1-0310-ab6d-d61299d08faa --- configure.ac | 2 +- src/parsetime.c | 12 ++--- src/rrd_cgi.c | 20 ++++---- src/rrd_create.c | 15 +++--- src/rrd_fetch.c | 14 +++--- src/rrd_first.c | 8 +-- src/rrd_getopt.c | 2 +- src/rrd_getopt1.c | 18 +++---- src/rrd_graph.c | 111 ++++++++++++++++++++---------------------- src/rrd_open.c | 56 --------------------- src/rrd_restore.c | 11 ++--- src/rrd_thread_safe.c | 2 +- src/rrd_tune.c | 36 +++++++------- src/rrd_update.c | 8 +-- src/rrd_xport.c | 16 +++--- 15 files changed, 130 insertions(+), 201 deletions(-) diff --git a/configure.ac b/configure.ac index 269665c..bac2165 100644 --- a/configure.ac +++ b/configure.ac @@ -331,7 +331,7 @@ CFLAGS="$CFLAGS -D_GNU_SOURCE" dnl which flags does the compiler support? if test "x$GCC" = "xyes"; then - for flag in -fno-strict-aliasing -Wall -std=c99 -pedantic -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -W; do + for flag in -fno-strict-aliasing -Wall -std=c99 -pedantic -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -Wc++-compat -Wold-style-definition -W; do oCFLAGS="$CFLAGS" CFLAGS="$CFLAGS $flag" cachename=rd_cv_gcc_flag_`echo $flag|sed 's/[[^A-Za-z]]/_/g'` diff --git a/src/parsetime.c b/src/parsetime.c index 71af065..a2b76ed 100644 --- a/src/parsetime.c +++ b/src/parsetime.c @@ -139,7 +139,7 @@ struct SpecialToken { char *name; /* token name */ int value; /* token id */ }; -static struct SpecialToken VariousWords[] = { +static const struct SpecialToken VariousWords[] = { {"midnight", MIDNIGHT}, /* 00:00:00 of today or tomorrow */ {"noon", NOON}, /* 12:00:00 of today or tomorrow */ {"teatime", TEATIME}, /* 16:00:00 of today or tomorrow */ @@ -196,7 +196,7 @@ static struct SpecialToken VariousWords[] = { {NULL, 0} /*** SENTINEL ***/ }; -static struct SpecialToken TimeMultipliers[] = { +static const struct SpecialToken TimeMultipliers[] = { {"second", SECONDS}, /* seconds multiplier */ {"seconds", SECONDS}, /* (pluralized) */ {"sec", SECONDS}, /* (generic) */ @@ -326,10 +326,8 @@ static char *e( greater than zero if S1 is lexicographically less than, equal to or greater than S2. -- copied from GNU libc*/ static int mystrcasecmp( - s1, - s2) - const char *s1; - const char *s2; + const char *s1, + const char *s2) { const unsigned char *p1 = (const unsigned char *) s1; const unsigned char *p2 = (const unsigned char *) s2; @@ -391,7 +389,7 @@ static char *init_scanner( * token() fetches a token from the input stream */ static int token( - ) + void) { int idx; diff --git a/src/rrd_cgi.c b/src/rrd_cgi.c index 75dabf4..846397f 100644 --- a/src/rrd_cgi.c +++ b/src/rrd_cgi.c @@ -220,8 +220,7 @@ static vardata *varheap = NULL; static size_t varheap_size = 0; /* allocate and initialize variable heap */ -static int initvar( - ) +static int initvar(void) { varheap = (vardata *) malloc(sizeof(vardata) * INIT_VARSTORE_SIZE); if (varheap == NULL) { @@ -234,8 +233,7 @@ static int initvar( } /* cleanup: free allocated memory */ -static void donevar( - ) +static void donevar(void) { int i; @@ -288,13 +286,13 @@ static const char *putvar( if (0 == strcmp(name, varheap[i].name)) { /* overwrite existing entry */ if (varheap[i].is_const) { -#ifdef DEBUG_VARS +#ifdef DEBUG_VARS printf("\n", name, value); -# endif +#endif return varheap[i].value; } -#ifdef DEBUG_VARS +#ifdef DEBUG_VARS printf("\n", name, value, varheap[i].value); #endif @@ -398,6 +396,10 @@ int main( char *server_url = NULL; long i; long filter = 0; + struct option long_options[] = { + {"filter", no_argument, 0, 'f'}, + {0, 0, 0, 0} + }; #ifdef MUST_DISABLE_SIGFPE signal(SIGFPE, SIG_IGN); @@ -412,10 +414,6 @@ int main( for (i=0;i - * - * Revision 1.9 2003/04/29 21:56:49 oetiker - * readline in rrd_open.c reads the file in 8 KB blocks, and calls realloc for - * each block. realloc is very slow in Mac OS X for huge blocks, e.g. when - * restoring databases from huge xml files. This patch finds the size of the - * file, and starts out with malloc'ing the full size. - * -- Peter Speck - * - * Revision 1.8 2003/04/11 19:43:44 oetiker - * New special value COUNT which allows calculations based on the position of a - * value within a data set. Bug fix in rrd_rpncalc.c. PREV returned erroneus - * value for the second value. Bug fix in rrd_restore.c. Bug causing seek error - * when accesing an RRD restored from an xml that holds an RRD version <3. - * -- Ruben Justo - * - * Revision 1.7 2003/03/31 21:22:12 oetiker - * enables RRDtool updates with microsecond or in case of windows millisecond - * precision. This is needed to reduce time measurement error when archive step - * is small. (<30s) -- Sasha Mikheev - * - * Revision 1.6 2003/02/13 07:05:27 oetiker - * Find attached the patch I promised to send to you. Please note that there - * are three new source files (src/rrd_is_thread_safe.h, src/rrd_thread_safe.c - * and src/rrd_not_thread_safe.c) and the introduction of librrd_th. This - * library is identical to librrd, but it contains support code for per-thread - * global variables currently used for error information only. This is similar - * to how errno per-thread variables are implemented. librrd_th must be linked - * alongside of libpthred - * - * There is also a new file "THREADS", holding some documentation. - * - * -- Peter Stamfest - * - * Revision 1.5 2002/06/20 00:21:03 jake - * More Win32 build changes; thanks to Kerry Calvert. - * - * Revision 1.4 2002/02/01 20:34:49 oetiker - * fixed version number and date/time - * - * Revision 1.3 2001/03/04 13:01:55 oetiker - * Aberrant Behavior Detection support. A brief overview added to rrdtool.pod. - * Major updates to rrd_update.c, rrd_create.c. Minor update to other core files. - * This is backwards compatible! But new files using the Aberrant stuff are not readable - * by old rrdtool versions. See http://cricket.sourceforge.net/aberrant/rrd_hw.htm - * -- Jake Brutlag - * - * Revision 1.2 2001/03/04 10:29:20 oetiker - * fixed filedescriptor leak - * -- Mike Franusich - * - * Revision 1.1.1.1 2001/02/25 22:25:05 oetiker - * checkin - * *****************************************************************************/ #include "rrd_tool.h" diff --git a/src/rrd_restore.c b/src/rrd_restore.c index 68a037f..65bbb10 100644 --- a/src/rrd_restore.c +++ b/src/rrd_restore.c @@ -708,20 +708,19 @@ int rrd_restore( char *buf; char rc = 0; char force_overwrite = 0; + struct option long_options[] = { + {"range-check", no_argument, 0, 'r'}, + {"force-overwrite", no_argument, 0, 'f'}, + {0, 0, 0, 0} + }; /* init rrd clean */ optind = 0; opterr = 0; /* initialize getopt */ while (1) { - static struct option long_options[] = { - {"range-check", no_argument, 0, 'r'}, - {"force-overwrite", no_argument, 0, 'f'}, - {0, 0, 0, 0} - }; int option_index = 0; int opt; - opt = getopt_long(argc, argv, "rf", long_options, &option_index); if (opt == EOF) diff --git a/src/rrd_thread_safe.c b/src/rrd_thread_safe.c index 074a873..7e58ca6 100644 --- a/src/rrd_thread_safe.c +++ b/src/rrd_thread_safe.c @@ -35,7 +35,7 @@ static void context_destroy_context( /* Allocate the key */ static void context_get_key( - ) + void) { pthread_key_create(&context_key, context_destroy_context); } diff --git a/src/rrd_tune.c b/src/rrd_tune.c index 160b32a..714e7d4 100644 --- a/src/rrd_tune.c +++ b/src/rrd_tune.c @@ -72,6 +72,24 @@ int rrd_tune( double max; char dst[DST_SIZE]; rrd_file_t *rrd_file; + struct option long_options[] = { + {"heartbeat", required_argument, 0, 'h'}, + {"minimum", required_argument, 0, 'i'}, + {"maximum", required_argument, 0, 'a'}, + {"data-source-type", required_argument, 0, 'd'}, + {"data-source-rename", required_argument, 0, 'r'}, + /* added parameter tuning options for aberrant behavior detection */ + {"deltapos", required_argument, 0, 'p'}, + {"deltaneg", required_argument, 0, 'n'}, + {"window-length", required_argument, 0, 'w'}, + {"failure-threshold", required_argument, 0, 'f'}, + {"alpha", required_argument, 0, 'x'}, + {"beta", required_argument, 0, 'y'}, + {"gamma", required_argument, 0, 'z'}, + {"gamma-deviation", required_argument, 0, 'v'}, + {"aberrant-reset", required_argument, 0, 'b'}, + {0, 0, 0, 0} + }; optind = 0; opterr = 0; /* initialize getopt */ @@ -84,24 +102,6 @@ int rrd_tune( } while (1) { - static struct option long_options[] = { - {"heartbeat", required_argument, 0, 'h'}, - {"minimum", required_argument, 0, 'i'}, - {"maximum", required_argument, 0, 'a'}, - {"data-source-type", required_argument, 0, 'd'}, - {"data-source-rename", required_argument, 0, 'r'}, - /* added parameter tuning options for aberrant behavior detection */ - {"deltapos", required_argument, 0, 'p'}, - {"deltaneg", required_argument, 0, 'n'}, - {"window-length", required_argument, 0, 'w'}, - {"failure-threshold", required_argument, 0, 'f'}, - {"alpha", required_argument, 0, 'x'}, - {"beta", required_argument, 0, 'y'}, - {"gamma", required_argument, 0, 'z'}, - {"gamma-deviation", required_argument, 0, 'v'}, - {"aberrant-reset", required_argument, 0, 'b'}, - {0, 0, 0, 0} - }; int option_index = 0; int opt; diff --git a/src/rrd_update.c b/src/rrd_update.c index 1feecac..fa60c0b 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -135,16 +135,16 @@ info_t *rrd_update_v( char *tmplt = NULL; info_t *result = NULL; infoval rc; + struct option long_options[] = { + {"template", required_argument, 0, 't'}, + {0, 0, 0, 0} + }; rc.u_int = -1; optind = 0; opterr = 0; /* initialize getopt */ while (1) { - static struct option long_options[] = { - {"template", required_argument, 0, 't'}, - {0, 0, 0, 0} - }; int option_index = 0; int opt; diff --git a/src/rrd_xport.c b/src/rrd_xport.c index ac2295b..21110b8 100644 --- a/src/rrd_xport.c +++ b/src/rrd_xport.c @@ -58,6 +58,14 @@ int rrd_xport( time_t start_tmp = 0, end_tmp = 0; struct rrd_time_value start_tv, end_tv; char *parsetime_error = NULL; + struct option long_options[] = { + {"start", required_argument, 0, 's'}, + {"end", required_argument, 0, 'e'}, + {"maxrows", required_argument, 0, 'm'}, + {"step", required_argument, 0, 261}, + {"enumds", no_argument, 0, 262}, /* these are handled in the frontend ... */ + {0, 0, 0, 0} + }; optind = 0; opterr = 0; /* initialize getopt */ @@ -68,14 +76,6 @@ int rrd_xport( parsetime("now", &end_tv); while (1) { - static struct option long_options[] = { - {"start", required_argument, 0, 's'}, - {"end", required_argument, 0, 'e'}, - {"maxrows", required_argument, 0, 'm'}, - {"step", required_argument, 0, 261}, - {"enumds", no_argument, 0, 262}, /* these are handled in the frontend ... */ - {0, 0, 0, 0} - }; int option_index = 0; int opt; -- 2.30.2