--- /dev/null
+--blank-lines-after-declarations
+--blank-lines-after-procedures
+--break-before-boolean-operator
+--break-function-decl-args
+--no-blank-lines-after-commas
+--braces-on-if-line
+--braces-on-struct-decl-line
+--comment-indentation25
+--declaration-comment-column25
+--no-comment-delimiters-on-blank-lines
+--cuddle-else
+--continuation-indentation4
+--case-indentation0
+--else-endif-column33
+--space-after-cast
+--line-comments-indentation0
+--declaration-indentation10
+--dont-format-first-column-comments
+--dont-format-comments
+--honour-newlines
+--indent-level4
+/* changed from 0 to 4 */
+--parameter-indentation4
+--line-length78 /* changed from 75 */
+--continue-at-parentheses
+--no-space-after-function-call-names
+--dont-break-procedure-type
+--dont-star-comments
+--leave-optional-blank-lines
+--dont-space-special-semicolon
+--tab-size4
+/* additions by Mark */
+--case-brace-indentation0
+--leave-preprocessor-space
+--no-tabs
+-Trrd_t
+-Tinfo_t
+-Ttime_t
+-Toff_t
+-TTcl_Interp
+-Ttm
+-Tstring_arr_t
+-T_ArtRgbaSVPAlphaData
+-TFIFOqueue
+-Tgfx_color_t
+-Tgfx_node_t
+-Tgfx_canvas_t
+-Tvar_s
+-Tcgi_s
+-Tinfoval
+-Tinfo_t
+-TFnv32_t
+-Trpnp_t
+-Trpn_cdefds_t
+-Trpnstack_t
+-Tunival
+-Tstat_head_t
+-Tds_def_t
+-Trra_def_t
+-Tlive_head_t
+-Tpdp_prep_t
+-Tcdp_prep_t
+-Trra_ptr_t
+-Trrd_t
+-Ttext_prop_t
+-Tvdef_t
+-Txlab_t
+-Tygrid_scale_t
+-Tylab_t
+-Tgraph_desc_t
+-Timage_desc_t
+-Tafm_uint8
+-Tafm_sint8
+-Tafm_uint16
+-Tafm_sint16
+-Tafm_unicode
+-Tafm_uint8
+-Tafm_sint8
+-Tafm_uint16
+-Tafm_sint16
+-Tafm_unicode
+-Tafm_fontinfo
+-Told_afm_fontinfo
+-Tgfx_char_s
+-Tgfx_string_s
+-Tpdf_point
+-Tsvg_dash
+-Teps_font
+-Teps_state
+-Tpdf_buffer
+-Tpdf_font
+-Tpdf_state
+-Trrd_value_t
+-Trrd_file_t
+-Tva_list
site-python-install: all
cd bindings/python && $(PYTHON) setup.py install
+# find . -name "*.c" -or -name "*.h" | xargs perl -0777 -n -e 'while (s/typedef\s+(?:unsigned\s+|signed\s+|unival\s+)?\S+\s+\*?([^{}\s;(]+)//){print "-T$1\n"}'
+indent:
+ find . -name "*.c" -or -name "*.h" | xargs indent
+
##END##
*
*****************************************************************************/
#ifdef __cplusplus
-extern "C" {
+extern "C" {
#endif
#ifndef _RRD_EXTRA_H
#include "rrd_format.h"
#ifndef WIN32
-#ifndef isnan /* POSIX */
-int isnan(double value);
+#ifndef isnan /* POSIX */
+ int isnan(
+ double value);
#endif
-#else /* Windows only */
+#else /* Windows only */
#include <float.h>
#define isnan _isnan
#endif
-void rrd_free(rrd_t *rrd);
-void rrd_init(rrd_t *rrd);
+ void rrd_free(
+ rrd_t *rrd);
+ void rrd_init(
+ rrd_t *rrd);
-int rrd_open(char *file_name, FILE **in_file, rrd_t *rrd, int rdwr);
-int readfile(char *file, char **buffer, int skipfirst);
+ int rrd_open(
+ char *file_name,
+ FILE ** in_file,
+ rrd_t *rrd,
+ int rdwr);
+ int readfile(
+ char *file,
+ char **buffer,
+ int skipfirst);
#define RRD_READONLY 0
#define RRD_READWRITE 1
extern int opterr;
/* forward declaration to keep compiler happy */
-void initrrdtool(void);
-
-static int
-create_args(char *command, PyObject *args, int *argc, char ***argv)
+void initrrdtool(
+ void);
+
+static int create_args(
+ char *command,
+ PyObject * args,
+ int *argc,
+ char ***argv)
{
- PyObject *o;
- int size, i;
-
- size = PyTuple_Size(args);
- *argv = PyMem_New(char *, size + 1);
+ PyObject *o;
+ int size, i;
+
+ size = PyTuple_Size(args);
+ *argv = PyMem_New(char *,
+ size + 1);
+
if (*argv == NULL)
return -1;
return 0;
}
-static void
-destroy_args(char ***argv)
+static void destroy_args(
+ char ***argv)
{
PyMem_Del(*argv);
*argv = NULL;
}
static char PyRRD_create__doc__[] =
-"create(args..): Set up a new Round Robin Database\n\
+ "create(args..): Set up a new Round Robin Database\n\
create filename [--start|-b start time] \
[--step|-s step] [DS:ds-name:DST:heartbeat:min:max] \
[RRA:CF:xff:steps:rows]";
-static PyObject *
-PyRRD_create(PyObject UNUSED(*self), PyObject *args)
+static PyObject *PyRRD_create(
+ PyObject UNUSED(*self),
+ PyObject * args)
{
- PyObject *r;
- char **argv;
- int argc;
+ PyObject *r;
+ char **argv;
+ int argc;
if (create_args("create", args, &argc, &argv) < 0)
return NULL;
}
static char PyRRD_update__doc__[] =
-"update(args..): Store a new set of values into the rrd\n"
-" update filename [--template|-t ds-name[:ds-name]...] "
-"N|timestamp:value[:value...] [timestamp:value[:value...] ...]";
+ "update(args..): Store a new set of values into the rrd\n"
+ " update filename [--template|-t ds-name[:ds-name]...] "
+ "N|timestamp:value[:value...] [timestamp:value[:value...] ...]";
-static PyObject *
-PyRRD_update(PyObject UNUSED(*self), PyObject *args)
+static PyObject *PyRRD_update(
+ PyObject UNUSED(*self),
+ PyObject * args)
{
- PyObject *r;
- char **argv;
- int argc;
+ PyObject *r;
+ char **argv;
+ int argc;
if (create_args("update", args, &argc, &argv) < 0)
return NULL;
}
static char PyRRD_fetch__doc__[] =
-"fetch(args..): fetch data from an rrd.\n"
-" fetch filename CF [--resolution|-r resolution] "
-"[--start|-s start] [--end|-e end]";
+ "fetch(args..): fetch data from an rrd.\n"
+ " fetch filename CF [--resolution|-r resolution] "
+ "[--start|-s start] [--end|-e end]";
-static PyObject *
-PyRRD_fetch(PyObject UNUSED(*self), PyObject *args)
+static PyObject *PyRRD_fetch(
+ PyObject UNUSED(*self),
+ PyObject * args)
{
- PyObject *r;
- rrd_value_t *data, *datai;
- unsigned long step, ds_cnt;
- time_t start, end;
- int argc;
- char **argv, **ds_namv;
+ PyObject *r;
+ rrd_value_t *data, *datai;
+ unsigned long step, ds_cnt;
+ time_t start, end;
+ int argc;
+ char **argv, **ds_namv;
if (create_args("fetch", args, &argc, &argv) < 0)
return NULL;
r = NULL;
} else {
/* Return :
- ((start, end, step), (name1, name2, ...), [(data1, data2, ..), ...]) */
- PyObject *range_tup, *dsnam_tup, *data_list, *t;
- unsigned long i, j, row;
- rrd_value_t dv;
+ ((start, end, step), (name1, name2, ...), [(data1, data2, ..), ...]) */
+ PyObject *range_tup, *dsnam_tup, *data_list, *t;
+ unsigned long i, j, row;
+ rrd_value_t dv;
row = ((end - start) / step + 1);
datai = data;
- PyTuple_SET_ITEM(range_tup, 0, PyInt_FromLong((long)start));
- PyTuple_SET_ITEM(range_tup, 1, PyInt_FromLong((long)end));
- PyTuple_SET_ITEM(range_tup, 2, PyInt_FromLong((long)step));
+ PyTuple_SET_ITEM(range_tup, 0, PyInt_FromLong((long) start));
+ PyTuple_SET_ITEM(range_tup, 1, PyInt_FromLong((long) end));
+ PyTuple_SET_ITEM(range_tup, 2, PyInt_FromLong((long) step));
for (i = 0; i < ds_cnt; i++)
PyTuple_SET_ITEM(dsnam_tup, i, PyString_FromString(ds_namv[i]));
- for (i = 0; i < row; i ++) {
+ for (i = 0; i < row; i++) {
t = PyTuple_New(ds_cnt);
PyList_SET_ITEM(data_list, i, t);
PyTuple_SET_ITEM(t, j, Py_None);
Py_INCREF(Py_None);
} else {
- PyTuple_SET_ITEM(t, j, PyFloat_FromDouble((double)dv));
+ PyTuple_SET_ITEM(t, j, PyFloat_FromDouble((double) dv));
}
}
}
for (i = 0; i < ds_cnt; i++)
free(ds_namv[i]);
- free(ds_namv); /* rrdtool don't use PyMem_Malloc :) */
+ free(ds_namv); /* rrdtool don't use PyMem_Malloc :) */
free(data);
}
}
static char PyRRD_graph__doc__[] =
-"graph(args..): Create a graph based on data from one or several RRD\n"
-" graph filename [-s|--start seconds] "
-"[-e|--end seconds] [-x|--x-grid x-axis grid and label] "
-"[-y|--y-grid y-axis grid and label] [--alt-y-grid] [--alt-y-mrtg] "
-"[--alt-autoscale] [--alt-autoscale-max] [--units-exponent] value "
-"[-v|--vertical-label text] [-w|--width pixels] [-h|--height pixels] "
-"[-i|--interlaced] "
-"[-f|--imginfo formatstring] [-a|--imgformat GIF|PNG|GD] "
-"[-B|--background value] [-O|--overlay value] "
-"[-U|--unit value] [-z|--lazy] [-o|--logarithmic] "
-"[-u|--upper-limit value] [-l|--lower-limit value] "
-"[-g|--no-legend] [-r|--rigid] [--step value] "
-"[-b|--base value] [-c|--color COLORTAG#rrggbb] "
-"[-t|--title title] [DEF:vname=rrd:ds-name:CF] "
-"[CDEF:vname=rpn-expression] [PRINT:vname:CF:format] "
-"[GPRINT:vname:CF:format] [COMMENT:text] "
-"[HRULE:value#rrggbb[:legend]] [VRULE:time#rrggbb[:legend]] "
-"[LINE{1|2|3}:vname[#rrggbb[:legend]]] "
-"[AREA:vname[#rrggbb[:legend]]] "
-"[STACK:vname[#rrggbb[:legend]]]";
-
-static PyObject *
-PyRRD_graph(PyObject UNUSED(*self), PyObject *args)
+ "graph(args..): Create a graph based on data from one or several RRD\n"
+ " graph filename [-s|--start seconds] "
+ "[-e|--end seconds] [-x|--x-grid x-axis grid and label] "
+ "[-y|--y-grid y-axis grid and label] [--alt-y-grid] [--alt-y-mrtg] "
+ "[--alt-autoscale] [--alt-autoscale-max] [--units-exponent] value "
+ "[-v|--vertical-label text] [-w|--width pixels] [-h|--height pixels] "
+ "[-i|--interlaced] "
+ "[-f|--imginfo formatstring] [-a|--imgformat GIF|PNG|GD] "
+ "[-B|--background value] [-O|--overlay value] "
+ "[-U|--unit value] [-z|--lazy] [-o|--logarithmic] "
+ "[-u|--upper-limit value] [-l|--lower-limit value] "
+ "[-g|--no-legend] [-r|--rigid] [--step value] "
+ "[-b|--base value] [-c|--color COLORTAG#rrggbb] "
+ "[-t|--title title] [DEF:vname=rrd:ds-name:CF] "
+ "[CDEF:vname=rpn-expression] [PRINT:vname:CF:format] "
+ "[GPRINT:vname:CF:format] [COMMENT:text] "
+ "[HRULE:value#rrggbb[:legend]] [VRULE:time#rrggbb[:legend]] "
+ "[LINE{1|2|3}:vname[#rrggbb[:legend]]] "
+ "[AREA:vname[#rrggbb[:legend]]] " "[STACK:vname[#rrggbb[:legend]]]";
+
+static PyObject *PyRRD_graph(
+ PyObject UNUSED(*self),
+ PyObject * args)
{
- PyObject *r;
- char **argv, **calcpr;
- int argc, xsize, ysize, i;
- double ymin, ymax;
+ PyObject *r;
+ char **argv, **calcpr;
+ int argc, xsize, ysize, i;
+ double ymin, ymax;
+
if (create_args("graph", args, &argc, &argv) < 0)
return NULL;
- if (rrd_graph(argc, argv, &calcpr, &xsize, &ysize, NULL, &ymin, &ymax) == -1) {
+ if (rrd_graph(argc, argv, &calcpr, &xsize, &ysize, NULL, &ymin, &ymax) ==
+ -1) {
PyErr_SetString(ErrorObject, rrd_get_error());
rrd_clear_error();
r = NULL;
} else {
r = PyTuple_New(3);
- PyTuple_SET_ITEM(r, 0, PyInt_FromLong((long)xsize));
- PyTuple_SET_ITEM(r, 1, PyInt_FromLong((long)ysize));
+ PyTuple_SET_ITEM(r, 0, PyInt_FromLong((long) xsize));
+ PyTuple_SET_ITEM(r, 1, PyInt_FromLong((long) ysize));
if (calcpr) {
- PyObject *e, *t;
-
+ PyObject *e, *t;
+
e = PyList_New(0);
PyTuple_SET_ITEM(r, 2, e);
- for(i = 0; calcpr[i]; i++) {
+ for (i = 0; calcpr[i]; i++) {
t = PyString_FromString(calcpr[i]);
PyList_Append(e, t);
Py_DECREF(t);
}
static char PyRRD_tune__doc__[] =
-"tune(args...): Modify some basic properties of a Round Robin Database\n"
-" tune filename [--heartbeat|-h ds-name:heartbeat] "
-"[--minimum|-i ds-name:min] [--maximum|-a ds-name:max] "
-"[--data-source-type|-d ds-name:DST] [--data-source-rename|-r old-name:new-name]";
-
-static PyObject *
-PyRRD_tune(PyObject UNUSED(*self), PyObject *args)
+ "tune(args...): Modify some basic properties of a Round Robin Database\n"
+ " tune filename [--heartbeat|-h ds-name:heartbeat] "
+ "[--minimum|-i ds-name:min] [--maximum|-a ds-name:max] "
+ "[--data-source-type|-d ds-name:DST] [--data-source-rename|-r old-name:new-name]";
+
+static PyObject *PyRRD_tune(
+ PyObject UNUSED(*self),
+ PyObject * args)
{
- PyObject *r;
- char **argv;
- int argc;
+ PyObject *r;
+ char **argv;
+ int argc;
if (create_args("tune", args, &argc, &argv) < 0)
return NULL;
}
static char PyRRD_first__doc__[] =
-"first(filename): Return the timestamp of the first data sample in an RRD";
+ "first(filename): Return the timestamp of the first data sample in an RRD";
-static PyObject *
-PyRRD_first(PyObject UNUSED(*self), PyObject *args)
+static PyObject *PyRRD_first(
+ PyObject UNUSED(*self),
+ PyObject * args)
{
- PyObject *r;
- int argc, ts;
- char **argv;
+ PyObject *r;
+ int argc, ts;
+ char **argv;
if (create_args("first", args, &argc, &argv) < 0)
return NULL;
rrd_clear_error();
r = NULL;
} else
- r = PyInt_FromLong((long)ts);
+ r = PyInt_FromLong((long) ts);
destroy_args(&argv);
return r;
}
static char PyRRD_last__doc__[] =
-"last(filename): Return the timestamp of the last data sample in an RRD";
+ "last(filename): Return the timestamp of the last data sample in an RRD";
-static PyObject *
-PyRRD_last(PyObject UNUSED(*self), PyObject *args)
+static PyObject *PyRRD_last(
+ PyObject UNUSED(*self),
+ PyObject * args)
{
- PyObject *r;
- int argc, ts;
- char **argv;
+ PyObject *r;
+ int argc, ts;
+ char **argv;
if (create_args("last", args, &argc, &argv) < 0)
return NULL;
rrd_clear_error();
r = NULL;
} else
- r = PyInt_FromLong((long)ts);
+ r = PyInt_FromLong((long) ts);
destroy_args(&argv);
return r;
}
static char PyRRD_resize__doc__[] =
-"resize(args...): alters the size of an RRA.\n"
-" resize filename rra-num GROW|SHRINK rows";
+ "resize(args...): alters the size of an RRA.\n"
+ " resize filename rra-num GROW|SHRINK rows";
-static PyObject *
-PyRRD_resize(PyObject UNUSED(*self), PyObject *args)
+static PyObject *PyRRD_resize(
+ PyObject UNUSED(*self),
+ PyObject * args)
{
- PyObject *r;
- char **argv;
- int argc, ts;
+ PyObject *r;
+ char **argv;
+ int argc, ts;
if (create_args("resize", args, &argc, &argv) < 0)
return NULL;
}
static char PyRRD_info__doc__[] =
-"info(filename): extract header information from an rrd";
+ "info(filename): extract header information from an rrd";
-static PyObject *
-PyRRD_info(PyObject UNUSED(*self), PyObject *args)
+static PyObject *PyRRD_info(
+ PyObject UNUSED(*self),
+ PyObject * args)
{
- PyObject *r, *t, *ds;
- rrd_t rrd;
- FILE *in_file;
- char *filename;
- unsigned long i, j;
+ PyObject *r, *t, *ds;
+ rrd_t rrd;
+ FILE *in_file;
+ char *filename;
+ unsigned long i, j;
- if (! PyArg_ParseTuple(args, "s:info", &filename))
+ if (!PyArg_ParseTuple(args, "s:info", &filename))
return NULL;
if (rrd_open(filename, &in_file, &rrd, RRD_READONLY) == -1) {
Py_DECREF(ds);
for (i = 0; i < rrd.stat_head->ds_cnt; i++) {
- PyObject *d;
+ PyObject *d;
d = PyDict_New();
PyDict_SetItemString(ds, rrd.ds_def[i].ds_nam, d);
DICTSET_STR(d, "ds_name", rrd.ds_def[i].ds_nam);
DICTSET_STR(d, "type", rrd.ds_def[i].dst);
- DICTSET_CNT(d, "minimal_heartbeat", rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt);
+ DICTSET_CNT(d, "minimal_heartbeat",
+ rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt);
DICTSET_VAL(d, "min", rrd.ds_def[i].par[DS_min_val].u_val);
DICTSET_VAL(d, "max", rrd.ds_def[i].par[DS_max_val].u_val);
DICTSET_STR(d, "last_ds", rrd.pdp_prep[i].last_ds);
DICTSET_VAL(d, "value", rrd.pdp_prep[i].scratch[PDP_val].u_val);
- DICTSET_CNT(d, "unknown_sec", rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt);
+ DICTSET_CNT(d, "unknown_sec",
+ rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt);
}
ds = PyList_New(rrd.stat_head->rra_cnt);
Py_DECREF(ds);
for (i = 0; i < rrd.stat_head->rra_cnt; i++) {
- PyObject *d, *cdp;
+ PyObject *d, *cdp;
d = PyDict_New();
PyList_SET_ITEM(ds, i, d);
Py_DECREF(cdp);
for (j = 0; j < rrd.stat_head->ds_cnt; j++) {
- PyObject *cdd;
+ PyObject *cdd;
cdd = PyDict_New();
PyList_SET_ITEM(cdp, j, cdd);
DICTSET_VAL(cdd, "value",
- rrd.cdp_prep[i*rrd.stat_head->ds_cnt+j].scratch[CDP_val].u_val);
+ rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
+ j].scratch[CDP_val].u_val);
DICTSET_CNT(cdd, "unknown_datapoints",
- rrd.cdp_prep[i*rrd.stat_head->ds_cnt+j].scratch[CDP_unkn_pdp_cnt].u_cnt);
+ rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
+ j].scratch[CDP_unkn_pdp_cnt].u_cnt);
}
}
#define meth(name, func, doc) {name, (PyCFunction)func, METH_VARARGS, doc}
static PyMethodDef _rrdtool_methods[] = {
- meth("create", PyRRD_create, PyRRD_create__doc__),
- meth("update", PyRRD_update, PyRRD_update__doc__),
- meth("fetch", PyRRD_fetch, PyRRD_fetch__doc__),
- meth("graph", PyRRD_graph, PyRRD_graph__doc__),
- meth("tune", PyRRD_tune, PyRRD_tune__doc__),
- meth("first", PyRRD_first, PyRRD_first__doc__),
- meth("last", PyRRD_last, PyRRD_last__doc__),
- meth("resize", PyRRD_resize, PyRRD_resize__doc__),
- meth("info", PyRRD_info, PyRRD_info__doc__),
- {NULL, NULL,0,NULL}
+ meth("create", PyRRD_create, PyRRD_create__doc__),
+ meth("update", PyRRD_update, PyRRD_update__doc__),
+ meth("fetch", PyRRD_fetch, PyRRD_fetch__doc__),
+ meth("graph", PyRRD_graph, PyRRD_graph__doc__),
+ meth("tune", PyRRD_tune, PyRRD_tune__doc__),
+ meth("first", PyRRD_first, PyRRD_first__doc__),
+ meth("last", PyRRD_last, PyRRD_last__doc__),
+ meth("resize", PyRRD_resize, PyRRD_resize__doc__),
+ meth("info", PyRRD_info, PyRRD_info__doc__),
+ {NULL, NULL, 0, NULL}
};
#define SET_INTCONSTANT(dict, value) \
Py_DECREF(t);
/* Initialization function for the module */
-void
-initrrdtool(void)
+void initrrdtool(
+ void)
{
- PyObject *m, *d, *t;
+ PyObject *m, *d, *t;
/* Create the module and add the functions */
m = Py_InitModule("rrdtool", _rrdtool_methods);
#include <rrd.h>
typedef struct string_arr_t {
- int len;
- char **strings;
+ int len;
+ char **strings;
} string_arr;
-VALUE mRRD;
-VALUE rb_eRRDError;
+VALUE mRRD;
+VALUE rb_eRRDError;
+
+typedef int (
+ *RRDFUNC) (
+ int argc,
+ char **argv);
-typedef int (*RRDFUNC)(int argc, char ** argv);
#define RRD_CHECK_ERROR \
if (rrd_test_error()) \
rb_raise(rb_eRRDError, rrd_get_error()); \
rrd_clear_error();
-string_arr string_arr_new(VALUE rb_strings)
+string_arr string_arr_new(
+ VALUE rb_strings)
{
string_arr a;
- char buf[64];
- int i;
-
+ char buf[64];
+ int i;
+
Check_Type(rb_strings, T_ARRAY);
a.len = RARRAY(rb_strings)->len + 1;
a.strings = malloc(a.len * sizeof(char *));
- a.strings[0] = "dummy"; /* first element is a dummy element */
+ a.strings[0] = "dummy"; /* first element is a dummy element */
for (i = 0; i < a.len - 1; i++) {
- VALUE v = rb_ary_entry(rb_strings, i);
+ VALUE v = rb_ary_entry(rb_strings, i);
+
switch (TYPE(v)) {
case T_STRING:
a.strings[i + 1] = strdup(STR2CSTR(v));
return a;
}
-void string_arr_delete(string_arr a)
+void string_arr_delete(
+ string_arr a)
{
- int i;
+ int i;
/* skip dummy first entry */
for (i = 1; i < a.len; i++) {
free(a.strings);
}
-void reset_rrd_state()
+void reset_rrd_state(
+ )
{
- optind = 0;
+ optind = 0;
opterr = 0;
rrd_clear_error();
}
-VALUE rrd_call(RRDFUNC func, VALUE args)
+VALUE rrd_call(
+ RRDFUNC func,
+ VALUE args)
{
string_arr a;
func(a.len, a.strings);
string_arr_delete(a);
- RRD_CHECK_ERROR
-
- return Qnil;
+ RRD_CHECK_ERROR return Qnil;
}
-VALUE rb_rrd_create(VALUE self, VALUE args)
+VALUE rb_rrd_create(
+ VALUE self,
+ VALUE args)
{
return rrd_call(rrd_create, args);
}
-VALUE rb_rrd_dump(VALUE self, VALUE args)
+VALUE rb_rrd_dump(
+ VALUE self,
+ VALUE args)
{
return rrd_call(rrd_dump, args);
}
-VALUE rb_rrd_fetch(VALUE self, VALUE args)
+VALUE rb_rrd_fetch(
+ VALUE self,
+ VALUE args)
{
string_arr a;
unsigned long i, j, k, step, ds_cnt;
rrd_value_t *raw_data;
- char **raw_names;
- VALUE data, names, result;
- time_t start, end;
+ char **raw_names;
+ VALUE data, names, result;
+ time_t start, end;
a = string_arr_new(args);
reset_rrd_state();
- rrd_fetch(a.len, a.strings, &start, &end, &step, &ds_cnt, &raw_names, &raw_data);
+ rrd_fetch(a.len, a.strings, &start, &end, &step, &ds_cnt, &raw_names,
+ &raw_data);
string_arr_delete(a);
- RRD_CHECK_ERROR
+ RRD_CHECK_ERROR names = rb_ary_new();
- names = rb_ary_new();
for (i = 0; i < ds_cnt; i++) {
rb_ary_push(names, rb_str_new2(raw_names[i]));
free(raw_names[i]);
k = 0;
data = rb_ary_new();
for (i = start; i <= end; i += step) {
- VALUE line = rb_ary_new2(ds_cnt);
+ VALUE line = rb_ary_new2(ds_cnt);
+
for (j = 0; j < ds_cnt; j++) {
rb_ary_store(line, j, rb_float_new(raw_data[k]));
k++;
rb_ary_push(data, line);
}
free(raw_data);
-
+
result = rb_ary_new2(4);
rb_ary_store(result, 0, INT2FIX(start));
rb_ary_store(result, 1, INT2FIX(end));
return result;
}
-VALUE rb_rrd_graph(VALUE self, VALUE args)
+VALUE rb_rrd_graph(
+ VALUE self,
+ VALUE args)
{
string_arr a;
- char **calcpr, **p;
- VALUE result, print_results;
- int xsize, ysize;
- double ymin, ymax;
+ char **calcpr, **p;
+ VALUE result, print_results;
+ int xsize, ysize;
+ double ymin, ymax;
a = string_arr_new(args);
reset_rrd_state();
rrd_graph(a.len, a.strings, &calcpr, &xsize, &ysize, NULL, &ymin, &ymax);
string_arr_delete(a);
- RRD_CHECK_ERROR
+ RRD_CHECK_ERROR result = rb_ary_new2(3);
- result = rb_ary_new2(3);
print_results = rb_ary_new();
p = calcpr;
for (p = calcpr; p && *p; p++) {
}
*/
-VALUE rb_rrd_last(VALUE self, VALUE args)
+VALUE rb_rrd_last(
+ VALUE self,
+ VALUE args)
{
string_arr a;
- time_t last;
+ time_t last;
a = string_arr_new(args);
reset_rrd_state();
string_arr_delete(a);
RRD_CHECK_ERROR
-
- return rb_funcall(rb_cTime, rb_intern("at"), 1, INT2FIX(last));
+ return rb_funcall(rb_cTime, rb_intern("at"), 1, INT2FIX(last));
}
-VALUE rb_rrd_resize(VALUE self, VALUE args)
+VALUE rb_rrd_resize(
+ VALUE self,
+ VALUE args)
{
return rrd_call(rrd_resize, args);
}
-VALUE rb_rrd_restore(VALUE self, VALUE args)
+VALUE rb_rrd_restore(
+ VALUE self,
+ VALUE args)
{
return rrd_call(rrd_restore, args);
}
-VALUE rb_rrd_tune(VALUE self, VALUE args)
+VALUE rb_rrd_tune(
+ VALUE self,
+ VALUE args)
{
return rrd_call(rrd_tune, args);
}
-VALUE rb_rrd_update(VALUE self, VALUE args)
+VALUE rb_rrd_update(
+ VALUE self,
+ VALUE args)
{
return rrd_call(rrd_update, args);
}
-void Init_RRD()
+void Init_RRD(
+ )
{
mRRD = rb_define_module("RRD");
rb_eRRDError = rb_define_class("RRDError", rb_eStandardError);
# define CONST84
#endif
-extern int Tclrrd_Init(Tcl_Interp *interp);
-extern int Tclrrd_SafeInit(Tcl_Interp *interp);
+extern int Tclrrd_Init(
+ Tcl_Interp *interp);
+extern int Tclrrd_SafeInit(
+ Tcl_Interp *interp);
/*
* Hence, we need to do some preparation before
* calling the rrd library functions.
*/
-static char ** getopt_init(int argc, CONST84 char *argv[])
+static char **getopt_init(
+ int argc,
+ CONST84 char *argv[])
{
- char **argv2;
- int i;
-
+ char **argv2;
+ int i;
+
argv2 = calloc(argc, sizeof(char *));
for (i = 0; i < argc; i++) {
- argv2[i] = strdup(argv[i]);
+ argv2[i] = strdup(argv[i]);
}
return argv2;
}
-static void getopt_cleanup(int argc, char **argv2)
+static void getopt_cleanup(
+ int argc,
+ char **argv2)
{
- int i;
-
+ int i;
+
for (i = 0; i < argc; i++) {
- if (argv2[i] != NULL) {
- free(argv2[i]);
- }
+ if (argv2[i] != NULL) {
+ free(argv2[i]);
+ }
}
free(argv2);
}
-static void getopt_free_element(argv2, argn)
- char *argv2[];
- int argn;
+static void getopt_free_element(
+ argv2,
+ argn)
+ char *argv2[];
+ int argn;
{
if (argv2[argn] != NULL) {
- free(argv2[argn]);
- argv2[argn] = NULL;
+ free(argv2[argn]);
+ argv2[argn] = NULL;
}
}
-static void getopt_squieeze(argc, argv2)
- int *argc;
- char *argv2[];
+static void getopt_squieeze(
+ argc,
+ argv2)
+ int *argc;
+ char *argv2[];
{
- int i, null_i = 0, argc_tmp = *argc;
+ int i, null_i = 0, argc_tmp = *argc;
for (i = 0; i < argc_tmp; i++) {
- if (argv2[i] == NULL) {
- (*argc)--;
- } else {
- argv2[null_i++] = argv2[i];
- }
+ if (argv2[i] == NULL) {
+ (*argc)--;
+ } else {
+ argv2[null_i++] = argv2[i];
+ }
}
}
/* Thread-safe version */
-static int
-Rrd_Create(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
+static int Rrd_Create(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int argc,
+ CONST84 char *argv[])
{
- int argv_i;
- char **argv2;
- char *parsetime_error = NULL;
- time_t last_up = time(NULL) - 10;
- long int long_tmp;
- unsigned long int pdp_step = 300;
- struct rrd_time_value last_up_tv;
+ int argv_i;
+ char **argv2;
+ char *parsetime_error = NULL;
+ time_t last_up = time(NULL) - 10;
+ long int long_tmp;
+ unsigned long int pdp_step = 300;
+ struct rrd_time_value last_up_tv;
argv2 = getopt_init(argc, argv);
for (argv_i = 1; argv_i < argc; argv_i++) {
- if (!strcmp(argv2[argv_i], "--start") || !strcmp(argv2[argv_i], "-b")) {
- if (argv_i++>=argc) {
- Tcl_AppendResult(interp, "RRD Error: option '",
- argv2[argv_i - 1], "' needs an argument", (char *) NULL);
- getopt_cleanup(argc, argv2);
- return TCL_ERROR;
- }
- if ((parsetime_error = parsetime(argv2[argv_i], &last_up_tv))) {
- Tcl_AppendResult(interp, "RRD Error: invalid time format: '",
- argv2[argv_i], "'", (char *) NULL);
- getopt_cleanup(argc, argv2);
- return TCL_ERROR;
- }
- if (last_up_tv.type == RELATIVE_TO_END_TIME ||
- last_up_tv.type == RELATIVE_TO_START_TIME) {
- Tcl_AppendResult(interp, "RRD Error: specifying time relative to the 'start' ",
- "or 'end' makes no sense here", (char *) NULL);
- getopt_cleanup(argc, argv2);
- return TCL_ERROR;
- }
- last_up = mktime(&last_up_tv.tm) + last_up_tv.offset;
- if (last_up < 3600*24*365*10) {
- Tcl_AppendResult(interp, "RRD Error: the first entry to the RRD should be after 1980",
- (char *) NULL);
- getopt_cleanup(argc, argv2);
- return TCL_ERROR;
- }
- getopt_free_element(argv2, argv_i - 1);
- getopt_free_element(argv2, argv_i);
- } else if (!strcmp(argv2[argv_i], "--step") || !strcmp(argv2[argv_i], "-s")) {
- if (argv_i++>=argc) {
- Tcl_AppendResult(interp, "RRD Error: option '",
- argv2[argv_i - 1], "' needs an argument", (char *) NULL);
- getopt_cleanup(argc, argv2);
- return TCL_ERROR;
- }
- long_tmp = atol(argv2[argv_i]);
- if (long_tmp < 1) {
- Tcl_AppendResult(interp, "RRD Error: step size should be no less than one second",
- (char *) NULL);
- getopt_cleanup(argc, argv2);
- return TCL_ERROR;
- }
- pdp_step = long_tmp;
- getopt_free_element(argv2, argv_i - 1);
- getopt_free_element(argv2, argv_i);
- } else if (!strcmp(argv2[argv_i], "--")) {
- getopt_free_element(argv2, argv_i);
- break;
- } else if (argv2[argv_i][0]=='-') {
- Tcl_AppendResult(interp, "RRD Error: unknown option '",
- argv2[argv_i], "'", (char *) NULL);
- getopt_cleanup(argc, argv2);
- return TCL_ERROR;
- }
+ if (!strcmp(argv2[argv_i], "--start") || !strcmp(argv2[argv_i], "-b")) {
+ if (argv_i++ >= argc) {
+ Tcl_AppendResult(interp, "RRD Error: option '",
+ argv2[argv_i - 1], "' needs an argument",
+ (char *) NULL);
+ getopt_cleanup(argc, argv2);
+ return TCL_ERROR;
+ }
+ if ((parsetime_error = parsetime(argv2[argv_i], &last_up_tv))) {
+ Tcl_AppendResult(interp, "RRD Error: invalid time format: '",
+ argv2[argv_i], "'", (char *) NULL);
+ getopt_cleanup(argc, argv2);
+ return TCL_ERROR;
+ }
+ if (last_up_tv.type == RELATIVE_TO_END_TIME ||
+ last_up_tv.type == RELATIVE_TO_START_TIME) {
+ Tcl_AppendResult(interp,
+ "RRD Error: specifying time relative to the 'start' ",
+ "or 'end' makes no sense here",
+ (char *) NULL);
+ getopt_cleanup(argc, argv2);
+ return TCL_ERROR;
+ }
+ last_up = mktime(&last_up_tv.tm) +last_up_tv.offset;
+ if (last_up < 3600 * 24 * 365 * 10) {
+ Tcl_AppendResult(interp,
+ "RRD Error: the first entry to the RRD should be after 1980",
+ (char *) NULL);
+ getopt_cleanup(argc, argv2);
+ return TCL_ERROR;
+ }
+ getopt_free_element(argv2, argv_i - 1);
+ getopt_free_element(argv2, argv_i);
+ } else if (!strcmp(argv2[argv_i], "--step")
+ || !strcmp(argv2[argv_i], "-s")) {
+ if (argv_i++ >= argc) {
+ Tcl_AppendResult(interp, "RRD Error: option '",
+ argv2[argv_i - 1], "' needs an argument",
+ (char *) NULL);
+ getopt_cleanup(argc, argv2);
+ return TCL_ERROR;
+ }
+ long_tmp = atol(argv2[argv_i]);
+ if (long_tmp < 1) {
+ Tcl_AppendResult(interp,
+ "RRD Error: step size should be no less than one second",
+ (char *) NULL);
+ getopt_cleanup(argc, argv2);
+ return TCL_ERROR;
+ }
+ pdp_step = long_tmp;
+ getopt_free_element(argv2, argv_i - 1);
+ getopt_free_element(argv2, argv_i);
+ } else if (!strcmp(argv2[argv_i], "--")) {
+ getopt_free_element(argv2, argv_i);
+ break;
+ } else if (argv2[argv_i][0] == '-') {
+ Tcl_AppendResult(interp, "RRD Error: unknown option '",
+ argv2[argv_i], "'", (char *) NULL);
+ getopt_cleanup(argc, argv2);
+ return TCL_ERROR;
+ }
}
getopt_squieeze(&argc, argv2);
if (argc < 2) {
- Tcl_AppendResult(interp, "RRD Error: needs rrd filename",
- (char *) NULL);
- getopt_cleanup(argc, argv2);
- return TCL_ERROR;
+ Tcl_AppendResult(interp, "RRD Error: needs rrd filename",
+ (char *) NULL);
+ getopt_cleanup(argc, argv2);
+ return TCL_ERROR;
}
rrd_create_r(argv2[1], pdp_step, last_up, argc - 2, argv2 + 2);
getopt_cleanup(argc, argv2);
-
+
if (rrd_test_error()) {
- Tcl_AppendResult(interp, "RRD Error: ",
- rrd_get_error(), (char *) NULL);
+ Tcl_AppendResult(interp, "RRD Error: ",
+ rrd_get_error(), (char *) NULL);
rrd_clear_error();
- return TCL_ERROR;
+ return TCL_ERROR;
}
return TCL_OK;
/* Thread-safe version */
-static int
-Rrd_Dump(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
+static int Rrd_Dump(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int argc,
+ CONST84 char *argv[])
{
if (argc < 2) {
- Tcl_AppendResult(interp, "RRD Error: needs rrd filename",
- (char *) NULL);
- return TCL_ERROR;
+ Tcl_AppendResult(interp, "RRD Error: needs rrd filename",
+ (char *) NULL);
+ return TCL_ERROR;
}
rrd_dump_r(argv[1], NULL);
/* NOTE: rrd_dump() writes to stdout. No interaction with TCL. */
if (rrd_test_error()) {
- Tcl_AppendResult(interp, "RRD Error: ",
- rrd_get_error(), (char *) NULL);
+ Tcl_AppendResult(interp, "RRD Error: ",
+ rrd_get_error(), (char *) NULL);
rrd_clear_error();
- return TCL_ERROR;
+ return TCL_ERROR;
}
return TCL_OK;
/* Thread-safe version */
-static int
-Rrd_Last(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
+static int Rrd_Last(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int argc,
+ CONST84 char *argv[])
{
- time_t t;
-
+ time_t t;
+
if (argc < 2) {
- Tcl_AppendResult(interp, "RRD Error: needs rrd filename",
- (char *) NULL);
- return TCL_ERROR;
+ Tcl_AppendResult(interp, "RRD Error: needs rrd filename",
+ (char *) NULL);
+ return TCL_ERROR;
}
t = rrd_last_r(argv[1]);
if (rrd_test_error()) {
- Tcl_AppendResult(interp, "RRD Error: ",
- rrd_get_error(), (char *) NULL);
+ Tcl_AppendResult(interp, "RRD Error: ",
+ rrd_get_error(), (char *) NULL);
rrd_clear_error();
- return TCL_ERROR;
+ return TCL_ERROR;
}
Tcl_SetIntObj(Tcl_GetObjResult(interp), t);
/* Thread-safe version */
-static int
-Rrd_Update(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
+static int Rrd_Update(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int argc,
+ CONST84 char *argv[])
{
- int argv_i;
- char **argv2, *template = NULL;
-
+ int argv_i;
+ char **argv2, *template = NULL;
+
argv2 = getopt_init(argc, argv);
for (argv_i = 1; argv_i < argc; argv_i++) {
- if (!strcmp(argv2[argv_i], "--template") || !strcmp(argv2[argv_i], "-t")) {
- if (argv_i++>=argc) {
- Tcl_AppendResult(interp, "RRD Error: option '",
- argv2[argv_i - 1], "' needs an argument", (char *) NULL);
- if (template != NULL) {
- free(template);
- }
- getopt_cleanup(argc, argv2);
- return TCL_ERROR;
- }
- if (template != NULL) {
- free(template);
- }
- template = strdup(argv2[argv_i]);
- getopt_free_element(argv2, argv_i - 1);
- getopt_free_element(argv2, argv_i);
- } else if (!strcmp(argv2[argv_i], "--")) {
- getopt_free_element(argv2, argv_i);
- break;
- } else if (argv2[argv_i][0]=='-') {
- Tcl_AppendResult(interp, "RRD Error: unknown option '",
- argv2[argv_i], "'", (char *) NULL);
- if (template != NULL) {
- free(template);
- }
- getopt_cleanup(argc, argv2);
- return TCL_ERROR;
- }
+ if (!strcmp(argv2[argv_i], "--template")
+ || !strcmp(argv2[argv_i], "-t")) {
+ if (argv_i++ >= argc) {
+ Tcl_AppendResult(interp, "RRD Error: option '",
+ argv2[argv_i - 1], "' needs an argument",
+ (char *) NULL);
+ if (template != NULL) {
+ free(template);
+ }
+ getopt_cleanup(argc, argv2);
+ return TCL_ERROR;
+ }
+ if (template != NULL) {
+ free(template);
+ }
+ template = strdup(argv2[argv_i]);
+ getopt_free_element(argv2, argv_i - 1);
+ getopt_free_element(argv2, argv_i);
+ } else if (!strcmp(argv2[argv_i], "--")) {
+ getopt_free_element(argv2, argv_i);
+ break;
+ } else if (argv2[argv_i][0] == '-') {
+ Tcl_AppendResult(interp, "RRD Error: unknown option '",
+ argv2[argv_i], "'", (char *) NULL);
+ if (template != NULL) {
+ free(template);
+ }
+ getopt_cleanup(argc, argv2);
+ return TCL_ERROR;
+ }
}
getopt_squieeze(&argc, argv2);
if (argc < 2) {
- Tcl_AppendResult(interp, "RRD Error: needs rrd filename",
- (char *) NULL);
- if (template != NULL) {
- free(template);
- }
- getopt_cleanup(argc, argv2);
- return TCL_ERROR;
+ Tcl_AppendResult(interp, "RRD Error: needs rrd filename",
+ (char *) NULL);
+ if (template != NULL) {
+ free(template);
+ }
+ getopt_cleanup(argc, argv2);
+ return TCL_ERROR;
}
rrd_update_r(argv2[1], template, argc - 2, argv2 + 2);
if (template != NULL) {
- free(template);
+ free(template);
}
getopt_cleanup(argc, argv2);
if (rrd_test_error()) {
- Tcl_AppendResult(interp, "RRD Error: ",
- rrd_get_error(), (char *) NULL);
+ Tcl_AppendResult(interp, "RRD Error: ",
+ rrd_get_error(), (char *) NULL);
rrd_clear_error();
- return TCL_ERROR;
+ return TCL_ERROR;
}
return TCL_OK;
}
-static int
-Rrd_Lastupdate(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
+static int Rrd_Lastupdate(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int argc,
+ CONST84 char *argv[])
{
- time_t last_update;
- char **argv2;
- char **ds_namv;
- char **last_ds;
- char s[30];
- Tcl_Obj *listPtr;
- unsigned long ds_cnt, i;
-
- argv2 = getopt_init(argc, argv);
- if (rrd_lastupdate(argc-1, argv2, &last_update,
- &ds_cnt, &ds_namv, &last_ds) == 0) {
- listPtr = Tcl_GetObjResult(interp);
- for (i=0; i<ds_cnt; i++) {
- sprintf(s, " %28s", ds_namv[i]);
- Tcl_ListObjAppendElement(interp, listPtr,
- Tcl_NewStringObj(s, -1));
- sprintf(s, "\n\n%10lu:", last_update);
- Tcl_ListObjAppendElement(interp, listPtr,
- Tcl_NewStringObj(s, -1));
- for (i=0; i<ds_cnt; i++) {
- sprintf(s, " %s", last_ds[i]);
- Tcl_ListObjAppendElement(interp, listPtr,
- Tcl_NewStringObj(s, -1));
- free(last_ds[i]);
- free(ds_namv[i]);
- }
- sprintf(s, "\n");
- Tcl_ListObjAppendElement(interp, listPtr,
- Tcl_NewStringObj(s, -1));
- free(last_ds);
- free(ds_namv);
- }
+ time_t last_update;
+ char **argv2;
+ char **ds_namv;
+ char **last_ds;
+ char s[30];
+ Tcl_Obj *listPtr;
+ unsigned long ds_cnt, i;
+
+ argv2 = getopt_init(argc, argv);
+ if (rrd_lastupdate(argc - 1, argv2, &last_update,
+ &ds_cnt, &ds_namv, &last_ds) == 0) {
+ listPtr = Tcl_GetObjResult(interp);
+ for (i = 0; i < ds_cnt; i++) {
+ sprintf(s, " %28s", ds_namv[i]);
+ Tcl_ListObjAppendElement(interp, listPtr,
+ Tcl_NewStringObj(s, -1));
+ sprintf(s, "\n\n%10lu:", last_update);
+ Tcl_ListObjAppendElement(interp, listPtr,
+ Tcl_NewStringObj(s, -1));
+ for (i = 0; i < ds_cnt; i++) {
+ sprintf(s, " %s", last_ds[i]);
+ Tcl_ListObjAppendElement(interp, listPtr,
+ Tcl_NewStringObj(s, -1));
+ free(last_ds[i]);
+ free(ds_namv[i]);
+ }
+ sprintf(s, "\n");
+ Tcl_ListObjAppendElement(interp, listPtr,
+ Tcl_NewStringObj(s, -1));
+ free(last_ds);
+ free(ds_namv);
+ }
}
return TCL_OK;
}
-static int
-Rrd_Fetch(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
+static int Rrd_Fetch(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int argc,
+ CONST84 char *argv[])
{
- time_t start, end, j;
+ time_t start, end, j;
unsigned long step, ds_cnt, i, ii;
rrd_value_t *data, *datai;
- char **ds_namv;
- Tcl_Obj *listPtr;
- char s[30];
- char **argv2;
-
+ char **ds_namv;
+ Tcl_Obj *listPtr;
+ char s[30];
+ char **argv2;
+
argv2 = getopt_init(argc, argv);
if (rrd_fetch(argc, argv2, &start, &end, &step,
- &ds_cnt, &ds_namv, &data) != -1) {
+ &ds_cnt, &ds_namv, &data) != -1) {
datai = data;
listPtr = Tcl_GetObjResult(interp);
for (j = start; j <= end; j += step) {
for (ii = 0; ii < ds_cnt; ii++) {
- sprintf(s, "%.2f", *(datai++));
+ sprintf(s, "%.2f", *(datai++));
Tcl_ListObjAppendElement(interp, listPtr,
- Tcl_NewStringObj(s, -1));
+ Tcl_NewStringObj(s, -1));
}
}
- for (i=0; i<ds_cnt; i++) free(ds_namv[i]);
+ for (i = 0; i < ds_cnt; i++)
+ free(ds_namv[i]);
free(ds_namv);
free(data);
}
getopt_cleanup(argc, argv2);
if (rrd_test_error()) {
- Tcl_AppendResult(interp, "RRD Error: ",
- rrd_get_error(), (char *) NULL);
+ Tcl_AppendResult(interp, "RRD Error: ",
+ rrd_get_error(), (char *) NULL);
rrd_clear_error();
- return TCL_ERROR;
+ return TCL_ERROR;
}
return TCL_OK;
-static int
-Rrd_Graph(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
+static int Rrd_Graph(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int argc,
+ CONST84 char *argv[])
{
Tcl_Channel channel;
- int mode, fd2;
+ int mode, fd2;
ClientData fd1;
- FILE *stream = NULL;
- char **calcpr = NULL;
- int rc, xsize, ysize;
- double ymin, ymax;
- char dimensions[50];
- char **argv2;
+ FILE *stream = NULL;
+ char **calcpr = NULL;
+ int rc, xsize, ysize;
+ double ymin, ymax;
+ char dimensions[50];
+ char **argv2;
CONST84 char *save;
-
+
/*
* If the "filename" is a Tcl fileID, then arrange for rrd_graph() to write to
* that file descriptor. Will this work with windoze? I have no idea.
*/
if ((channel = Tcl_GetChannel(interp, argv[1], &mode)) != NULL) {
- /*
- * It >is< a Tcl fileID
- */
- if (!(mode & TCL_WRITABLE)) {
- Tcl_AppendResult(interp, "channel \"", argv[1],
- "\" wasn't opened for writing", (char *) NULL);
- return TCL_ERROR;
- }
- /*
- * Must flush channel to make sure any buffered data is written before
- * rrd_graph() writes to the stream
- */
- if (Tcl_Flush(channel) != TCL_OK) {
- Tcl_AppendResult(interp, "flush failed for \"", argv[1], "\": ",
- strerror(Tcl_GetErrno()), (char *) NULL);
- return TCL_ERROR;
- }
- if (Tcl_GetChannelHandle(channel, TCL_WRITABLE, &fd1) != TCL_OK) {
- Tcl_AppendResult(interp, "cannot get file descriptor associated with \"",
- argv[1], "\"", (char *) NULL);
- return TCL_ERROR;
- }
- /*
- * Must dup() file descriptor so we can fclose(stream), otherwise the fclose()
- * would close Tcl's file descriptor
- */
- if ((fd2 = dup((int)fd1)) == -1) {
- Tcl_AppendResult(interp, "dup() failed for file descriptor associated with \"",
- argv[1], "\": ", strerror(errno), (char *) NULL);
- return TCL_ERROR;
- }
- /*
- * rrd_graph() wants a FILE*
- */
- if ((stream = fdopen(fd2, "wb")) == NULL) {
- Tcl_AppendResult(interp, "fdopen() failed for file descriptor associated with \"",
- argv[1], "\": ", strerror(errno), (char *) NULL);
- close(fd2); /* plug potential file descriptor leak */
- return TCL_ERROR;
- }
-
- save = argv[1];
- argv[1] = "-";
- argv2 = getopt_init(argc, argv);
- argv[1] = save;
+ /*
+ * It >is< a Tcl fileID
+ */
+ if (!(mode & TCL_WRITABLE)) {
+ Tcl_AppendResult(interp, "channel \"", argv[1],
+ "\" wasn't opened for writing", (char *) NULL);
+ return TCL_ERROR;
+ }
+ /*
+ * Must flush channel to make sure any buffered data is written before
+ * rrd_graph() writes to the stream
+ */
+ if (Tcl_Flush(channel) != TCL_OK) {
+ Tcl_AppendResult(interp, "flush failed for \"", argv[1], "\": ",
+ strerror(Tcl_GetErrno()), (char *) NULL);
+ return TCL_ERROR;
+ }
+ if (Tcl_GetChannelHandle(channel, TCL_WRITABLE, &fd1) != TCL_OK) {
+ Tcl_AppendResult(interp,
+ "cannot get file descriptor associated with \"",
+ argv[1], "\"", (char *) NULL);
+ return TCL_ERROR;
+ }
+ /*
+ * Must dup() file descriptor so we can fclose(stream), otherwise the fclose()
+ * would close Tcl's file descriptor
+ */
+ if ((fd2 = dup((int) fd1)) == -1) {
+ Tcl_AppendResult(interp,
+ "dup() failed for file descriptor associated with \"",
+ argv[1], "\": ", strerror(errno), (char *) NULL);
+ return TCL_ERROR;
+ }
+ /*
+ * rrd_graph() wants a FILE*
+ */
+ if ((stream = fdopen(fd2, "wb")) == NULL) {
+ Tcl_AppendResult(interp,
+ "fdopen() failed for file descriptor associated with \"",
+ argv[1], "\": ", strerror(errno), (char *) NULL);
+ close(fd2); /* plug potential file descriptor leak */
+ return TCL_ERROR;
+ }
+
+ save = argv[1];
+ argv[1] = "-";
+ argv2 = getopt_init(argc, argv);
+ argv[1] = save;
} else {
- Tcl_ResetResult(interp); /* clear error from Tcl_GetChannel() */
- argv2 = getopt_init(argc, argv);
+ Tcl_ResetResult(interp); /* clear error from Tcl_GetChannel() */
+ argv2 = getopt_init(argc, argv);
}
- rc = rrd_graph(argc, argv2, &calcpr, &xsize, &ysize, stream, &ymin, &ymax);
+ rc = rrd_graph(argc, argv2, &calcpr, &xsize, &ysize, stream, &ymin,
+ &ymax);
getopt_cleanup(argc, argv2);
if (stream != NULL)
- fclose(stream); /* plug potential malloc & file descriptor leak */
+ fclose(stream); /* plug potential malloc & file descriptor leak */
if (rc != -1) {
sprintf(dimensions, "%d %d", xsize, ysize);
Tcl_AppendResult(interp, dimensions, (char *) NULL);
if (calcpr) {
#if 0
- int i;
-
- for(i = 0; calcpr[i]; i++){
+ int i;
+
+ for (i = 0; calcpr[i]; i++) {
printf("%s\n", calcpr[i]);
free(calcpr[i]);
- }
+ }
#endif
free(calcpr);
}
}
if (rrd_test_error()) {
- Tcl_AppendResult(interp, "RRD Error: ",
- rrd_get_error(), (char *) NULL);
+ Tcl_AppendResult(interp, "RRD Error: ",
+ rrd_get_error(), (char *) NULL);
rrd_clear_error();
- return TCL_ERROR;
+ return TCL_ERROR;
}
return TCL_OK;
-static int
-Rrd_Tune(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
+static int Rrd_Tune(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int argc,
+ CONST84 char *argv[])
{
- char **argv2;
-
+ char **argv2;
+
argv2 = getopt_init(argc, argv);
rrd_tune(argc, argv2);
getopt_cleanup(argc, argv2);
if (rrd_test_error()) {
- Tcl_AppendResult(interp, "RRD Error: ",
- rrd_get_error(), (char *) NULL);
+ Tcl_AppendResult(interp, "RRD Error: ",
+ rrd_get_error(), (char *) NULL);
rrd_clear_error();
- return TCL_ERROR;
+ return TCL_ERROR;
}
return TCL_OK;
-static int
-Rrd_Resize(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
+static int Rrd_Resize(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int argc,
+ CONST84 char *argv[])
{
- char **argv2;
-
+ char **argv2;
+
argv2 = getopt_init(argc, argv);
rrd_resize(argc, argv2);
getopt_cleanup(argc, argv2);
if (rrd_test_error()) {
- Tcl_AppendResult(interp, "RRD Error: ",
- rrd_get_error(), (char *) NULL);
+ Tcl_AppendResult(interp, "RRD Error: ",
+ rrd_get_error(), (char *) NULL);
rrd_clear_error();
- return TCL_ERROR;
+ return TCL_ERROR;
}
return TCL_OK;
-static int
-Rrd_Restore(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
+static int Rrd_Restore(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ int argc,
+ CONST84 char *argv[])
{
- char **argv2;
-
+ char **argv2;
+
argv2 = getopt_init(argc, argv);
rrd_restore(argc, argv2);
getopt_cleanup(argc, argv2);
if (rrd_test_error()) {
- Tcl_AppendResult(interp, "RRD Error: ",
- rrd_get_error(), (char *) NULL);
+ Tcl_AppendResult(interp, "RRD Error: ",
+ rrd_get_error(), (char *) NULL);
rrd_clear_error();
- return TCL_ERROR;
+ return TCL_ERROR;
}
return TCL_OK;
*/
typedef struct {
- char *name; /* Name of the command. */
- Tcl_CmdProc *proc; /* Procedure for command. */
- int hide; /* Hide if safe interpreter */
+ char *name; /* Name of the command. */
+ Tcl_CmdProc *proc; /* Procedure for command. */
+ int hide; /* Hide if safe interpreter */
} CmdInfo;
static CmdInfo rrdCmds[] = {
- { "Rrd::create", Rrd_Create, 1 }, /* Thread-safe version */
- { "Rrd::dump", Rrd_Dump, 0 }, /* Thread-safe version */
- { "Rrd::last", Rrd_Last, 0 }, /* Thread-safe version */
- { "Rrd::lastupdate", Rrd_Lastupdate, 0 }, /* Thread-safe version */
- { "Rrd::update", Rrd_Update, 1 }, /* Thread-safe version */
- { "Rrd::fetch", Rrd_Fetch, 0 },
- { "Rrd::graph", Rrd_Graph, 1 }, /* Due to RRD's API, a safe
- interpreter cannot create
- a graph since it writes to
- a filename supplied by the
- caller */
- { "Rrd::tune", Rrd_Tune, 1 },
- { "Rrd::resize", Rrd_Resize, 1 },
- { "Rrd::restore", Rrd_Restore, 1 },
- { (char *) NULL, (Tcl_CmdProc *) NULL, 0 }
+ {"Rrd::create", Rrd_Create, 1}, /* Thread-safe version */
+ {"Rrd::dump", Rrd_Dump, 0}, /* Thread-safe version */
+ {"Rrd::last", Rrd_Last, 0}, /* Thread-safe version */
+ {"Rrd::lastupdate", Rrd_Lastupdate, 0}, /* Thread-safe version */
+ {"Rrd::update", Rrd_Update, 1}, /* Thread-safe version */
+ {"Rrd::fetch", Rrd_Fetch, 0},
+ {"Rrd::graph", Rrd_Graph, 1}, /* Due to RRD's API, a safe
+ interpreter cannot create
+ a graph since it writes to
+ a filename supplied by the
+ caller */
+ {"Rrd::tune", Rrd_Tune, 1},
+ {"Rrd::resize", Rrd_Resize, 1},
+ {"Rrd::restore", Rrd_Restore, 1},
+ {(char *) NULL, (Tcl_CmdProc *) NULL, 0}
};
-static int
-init(Tcl_Interp *interp, int safe)
-{
- CmdInfo *cmdInfoPtr;
+static int init(
+ Tcl_Interp *interp,
+ int safe)
+{
+ CmdInfo *cmdInfoPtr;
Tcl_CmdInfo info;
- if ( Tcl_InitStubs(interp,TCL_VERSION,0) == NULL )
- return TCL_ERROR;
+ if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL)
+ return TCL_ERROR;
if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 1) == NULL) {
return TCL_ERROR;
Tcl_SetVar2(interp, "rrd", "version", VERSION, TCL_GLOBAL_ONLY);
for (cmdInfoPtr = rrdCmds; cmdInfoPtr->name != NULL; cmdInfoPtr++) {
- /*
- * Check if the command already exists and return an error
- * to ensure we detect name clashes while loading the Rrd
- * extension.
- */
- if (Tcl_GetCommandInfo(interp, cmdInfoPtr->name, &info)) {
- Tcl_AppendResult(interp, "command \"", cmdInfoPtr->name,
- "\" already exists", (char *) NULL);
- return TCL_ERROR;
- }
- if (safe && cmdInfoPtr->hide) {
+ /*
+ * Check if the command already exists and return an error
+ * to ensure we detect name clashes while loading the Rrd
+ * extension.
+ */
+ if (Tcl_GetCommandInfo(interp, cmdInfoPtr->name, &info)) {
+ Tcl_AppendResult(interp, "command \"", cmdInfoPtr->name,
+ "\" already exists", (char *) NULL);
+ return TCL_ERROR;
+ }
+ if (safe && cmdInfoPtr->hide) {
#if 0
- /*
- * Turns out the one cannot hide a command in a namespace
- * due to a limitation of Tcl, one can only hide global
- * commands. Thus, if we created the commands without
- * the Rrd:: namespace in a safe interpreter, then the
- * "unsafe" commands could be hidden -- which would allow
- * an owning interpreter either un-hiding them or doing
- * an "interp invokehidden". If the Rrd:: namespace is
- * used, then it's still possible for the owning interpreter
- * to fake out the missing commands:
- *
- * # Make all Rrd::* commands available in master interperter
- * package require Rrd
- * set safe [interp create -safe]
- * # Make safe Rrd::* commands available in safe interperter
- * interp invokehidden $safe -global load ./tclrrd1.2.11.so
- * # Provide the safe interpreter with the missing commands
- * $safe alias Rrd::update do_update $safe
- * proc do_update {which_interp $args} {
- * # Do some checking maybe...
- * :
- * return [eval Rrd::update $args]
- * }
- *
- * Our solution for now is to just not create the "unsafe"
- * commands in a safe interpreter.
- */
- if (Tcl_HideCommand(interp, cmdInfoPtr->name, cmdInfoPtr->name) != TCL_OK)
- return TCL_ERROR;
+ /*
+ * Turns out the one cannot hide a command in a namespace
+ * due to a limitation of Tcl, one can only hide global
+ * commands. Thus, if we created the commands without
+ * the Rrd:: namespace in a safe interpreter, then the
+ * "unsafe" commands could be hidden -- which would allow
+ * an owning interpreter either un-hiding them or doing
+ * an "interp invokehidden". If the Rrd:: namespace is
+ * used, then it's still possible for the owning interpreter
+ * to fake out the missing commands:
+ *
+ * # Make all Rrd::* commands available in master interperter
+ * package require Rrd
+ * set safe [interp create -safe]
+ * # Make safe Rrd::* commands available in safe interperter
+ * interp invokehidden $safe -global load ./tclrrd1.2.11.so
+ * # Provide the safe interpreter with the missing commands
+ * $safe alias Rrd::update do_update $safe
+ * proc do_update {which_interp $args} {
+ * # Do some checking maybe...
+ * :
+ * return [eval Rrd::update $args]
+ * }
+ *
+ * Our solution for now is to just not create the "unsafe"
+ * commands in a safe interpreter.
+ */
+ if (Tcl_HideCommand(interp, cmdInfoPtr->name, cmdInfoPtr->name) !=
+ TCL_OK)
+ return TCL_ERROR;
#endif
- }
- else
- Tcl_CreateCommand(interp, cmdInfoPtr->name, cmdInfoPtr->proc,
- (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
+ } else
+ Tcl_CreateCommand(interp, cmdInfoPtr->name, cmdInfoPtr->proc,
+ (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
}
if (Tcl_PkgProvide(interp, "Rrd", VERSION) != TCL_OK) {
- return TCL_ERROR;
+ return TCL_ERROR;
}
return TCL_OK;
}
-int
-Tclrrd_Init(Tcl_Interp *interp)
-{
- return init(interp, 0);
+int Tclrrd_Init(
+ Tcl_Interp *interp)
+{
+ return init(interp, 0);
}
/*
* Using rrdtool in a safe interpreter has very limited functionality. It's
* tempting to just return TCL_ERROR and forget about it.
*/
-int
-Tclrrd_SafeInit(Tcl_Interp *interp)
-{
- return init(interp, 1);
+int Tclrrd_SafeInit(
+ Tcl_Interp *interp)
+{
+ return init(interp, 1);
}
#include "rrd_afm.h"
#include <stdio.h>
-FILE *fp;
+FILE *fp;
+
+static void make_tests(
+ void);
+static void print(
+ const char *s);
+double y = 0;
-static void make_tests(void);
-static void print(const char *s);
-double y = 0;
//static const char *font = "Times-Roman";
static const char *font = "Times Bold Italic";
+
//static const char *font = "Courier";
//static const char *font = "Courier Bold Oblique";
-void make_tests()
+void make_tests(
+ )
{
#ifdef __APPLE__
#define charset_legend "Macintosh charset"
#define aa "\xA5"
#define NBSP "\x00A0"
#endif
- print(AE); /* very wide char */
- print(AE AE AE AE AE AE AE AE AE AE AE AE AE AE AE);
- print(charset_legend);
- print("S,");
- print("sfil");
- print("Hello, world");
- print("AVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV");
- print("AAAAAAAAAAAAAAAAAAVVVVVVVVVVVVVVVVVV");
- print("fiffififfififfififfififfififfififfi");
- print("fi");
- print("fil");
- print("fifififififififififififififififififififififififififi");
- print(AE "bleskiver med gl"oe"gg. " NBSP NBSP NBSP NBSP NBSP NBSP NBSP
- AE" Fywerhus: 'A "ae" u "aa" "ae" "oe" i "ae" fywer'.");
- print("Ingef"ae"rp"ae"rer med karamelsauce. R"oe"dgr"oe"d med fl"oe"de.");
- print("(Optional.) Ligature sequence where successor and ligature are both names. The current character may join ...");
+ print(AE); /* very wide char */
+ print(AE AE AE AE AE AE AE AE AE AE AE AE AE AE AE);
+ print(charset_legend);
+ print("S,");
+ print("sfil");
+ print("Hello, world");
+ print("AVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAVAV");
+ print("AAAAAAAAAAAAAAAAAAVVVVVVVVVVVVVVVVVV");
+ print("fiffififfififfififfififfififfififfi");
+ print("fi");
+ print("fil");
+ print("fifififififififififififififififififififififififififi");
+ print(AE "bleskiver med gl" oe "gg. " NBSP NBSP NBSP NBSP NBSP NBSP NBSP
+ AE " Fywerhus: 'A " ae " u " aa " " ae " " oe " i " ae " fywer'.");
+ print("Ingef" ae "rp" ae "rer med karamelsauce. R" oe "dgr" oe "d med fl"
+ oe "de.");
+ print
+ ("(Optional.) Ligature sequence where successor and ligature are both names. The current character may join ...");
}
-static void vline(double x, double y1, double y2)
+static void vline(
+ double x,
+ double y1,
+ double y2)
{
- fprintf(fp, "<line x1=\"%.2f\" y1=\"%.2f\" x2=\"%.2f\" y2=\"%.2f\""
- " stroke-width=\"1\" stroke=\"#000\"/>\n",
- x, y1, x, y2);
+ fprintf(fp, "<line x1=\"%.2f\" y1=\"%.2f\" x2=\"%.2f\" y2=\"%.2f\""
+ " stroke-width=\"1\" stroke=\"#000\"/>\n", x, y1, x, y2);
}
-static void print(const char *s)
+static void print(
+ const char *s)
{
- double size = 12;
- double x = 10;
- double width = afm_get_text_width(0, font, size, 4, s);
- unsigned char *up = (unsigned char*)s;
- fprintf(stderr, "Width = %f for '%s'\n", width, s);
- y += 10;
- vline(x, y, y + 5);
- fprintf(fp, "<text x=\"%.2f\" y=\"%.2f\" font-size=\"%.2f\">", x, y, size);
- while (*up) {
- unsigned char ch = afm_host2unicode(*up);
- if (ch < 127)
- putc(ch, fp);
- else
- fprintf(fp, "&#%d;", ch);
- up++;
- }
- fputs("</text>\n", fp);
- vline(x + width, y, y + 5);
- y += 1.1 * size;
+ double size = 12;
+ double x = 10;
+ double width = afm_get_text_width(0, font, size, 4, s);
+ unsigned char *up = (unsigned char *) s;
+
+ fprintf(stderr, "Width = %f for '%s'\n", width, s);
+ y += 10;
+ vline(x, y, y + 5);
+ fprintf(fp, "<text x=\"%.2f\" y=\"%.2f\" font-size=\"%.2f\">", x, y,
+ size);
+ while (*up) {
+ unsigned char ch = afm_host2unicode(*up);
+
+ if (ch < 127)
+ putc(ch, fp);
+ else
+ fprintf(fp, "&#%d;", ch);
+ up++;
+ }
+ fputs("</text>\n", fp);
+ vline(x + width, y, y + 5);
+ y += 1.1 * size;
}
-static void header()
+static void header(
+ )
{
- fprintf(fp,
- "<?xml version=\"1.0\" standalone=\"no\"?>\n"
- "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\"\n"
- " \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
- "<svg width=\"650\" height=\"400\" preserveAspectRatio=\"xMidYMid\"\n"
- " font-family=\"%s\">\n", font);
- }
+ fprintf(fp,
+ "<?xml version=\"1.0\" standalone=\"no\"?>\n"
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\"\n"
+ " \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
+ "<svg width=\"650\" height=\"400\" preserveAspectRatio=\"xMidYMid\"\n"
+ " font-family=\"%s\">\n", font);
+}
-static void footer()
+static void footer(
+ )
{
- fputs("</svg>\n", fp);
+ fputs("</svg>\n", fp);
}
-int main()
+int main(
+ )
{
- fp = fopen("test.svg", "w");
- if (fp == NULL) {
- fprintf(stderr, "Can't create output.\n");
- exit(1);
- }
- header();
- make_tests();
- footer();
- fclose(fp);
- return 0;
+ fp = fopen("test.svg", "w");
+ if (fp == NULL) {
+ fprintf(stderr, "Can't create output.\n");
+ exit(1);
+ }
+ header();
+ make_tests();
+ footer();
+ fclose(fp);
+ return 0;
}
-
+++ /dev/null
---blank-lines-after-declarations
---blank-lines-after-procedures
---break-before-boolean-operator
---break-function-decl-args
---no-blank-lines-after-commas
---braces-on-if-line
---braces-on-struct-decl-line
---comment-indentation25
---declaration-comment-column25
---no-comment-delimiters-on-blank-lines
---cuddle-else
---continuation-indentation4
---case-indentation0
---else-endif-column33
---space-after-cast
---line-comments-indentation0
---declaration-indentation10
---dont-format-first-column-comments
---dont-format-comments
---honour-newlines
---indent-level4
-/* changed from 0 to 4 */
---parameter-indentation4
---line-length78 /* changed from 75 */
---continue-at-parentheses
---no-space-after-function-call-names
---dont-break-procedure-type
---dont-star-comments
---leave-optional-blank-lines
---dont-space-special-semicolon
---tab-size4
-/* additions by Mark */
---case-brace-indentation0
---leave-preprocessor-space
---no-tabs
--T rrd_t
--T info_t
--T time_t
--T off_t
hval *= FNV_32_PRIME;
/* xor the bottom with the current octet */
- hval ^= (Fnv32_t) * bp++;
+ hval ^= (Fnv32_t) *bp++;
}
/* return our new hash value */
hval *= FNV_32_PRIME;
/* xor the bottom with the current octet */
- hval ^= (Fnv32_t) * s++;
+ hval ^= (Fnv32_t) *s++;
}
/* return our new hash value */
prev_multiplier = sc_tokid;
switch (sc_tokid) {
case YEARS:
- ptv->tm.tm_year += (op == PLUS) ? delta : -delta;
+ ptv->tm. tm_year += (
+ op == PLUS) ? delta : -delta;
+
return TIME_OK;
case MONTHS:
- ptv->tm.tm_mon += (op == PLUS) ? delta : -delta;
+ ptv->tm. tm_mon += (
+ op == PLUS) ? delta : -delta;
+
return TIME_OK;
case WEEKS:
delta *= 7;
/* FALLTHRU */
case DAYS:
- ptv->tm.tm_mday += (op == PLUS) ? delta : -delta;
+ ptv->tm. tm_mday += (
+ op == PLUS) ? delta : -delta;
+
return TIME_OK;
case HOURS:
ptv->offset += (op == PLUS) ? delta * 60 * 60 : -delta * 60 * 60;
sprintf(sc_token, "%d", hour);
return TIME_OK;
}
- ptv->tm.tm_hour = hour;
- ptv->tm.tm_min = minute;
- ptv->tm.tm_sec = 0;
+ ptv->tm. tm_hour = hour;
+ ptv->tm. tm_min = minute;
+ ptv->tm. tm_sec = 0;
+
if (ptv->tm.tm_hour == 24) {
- ptv->tm.tm_hour = 0;
- ptv->tm.tm_mday++;
+ ptv->tm. tm_hour = 0;
+ ptv->tm. tm_mday++;
}
return TIME_OK;
} /* tod */
panic(e("won't handle dates before epoch (01/01/1970), sorry"));
}
- ptv->tm.tm_mday = mday;
- ptv->tm.tm_mon = mon;
- ptv->tm.tm_year = year;
+ ptv->tm. tm_mday = mday;
+ ptv->tm. tm_mon = mon;
+ ptv->tm. tm_year = year;
+
return TIME_OK;
} /* assign_date */
switch (sc_tokid) {
case YESTERDAY:
- ptv->tm.tm_mday--;
+ ptv->tm. tm_mday--;
+
/* FALLTRHU */
case TODAY: /* force ourselves to stay in today - no further processing */
token();
break;
case TOMORROW:
- ptv->tm.tm_mday++;
+ ptv->tm. tm_mday++;
+
token();
break;
token();
} else
year = ptv->tm.tm_year;
+
try(assign_date(ptv, mday, mon, year));
break;
/* do a particular day of the week
*/
wday = (sc_tokid - SUN);
- ptv->tm.tm_mday += (wday - ptv->tm.tm_wday);
+ ptv->tm. tm_mday += (
+ wday - ptv->tm.tm_wday);
+
token();
break;
/*
mon = atol(sc_token);
if (mon > 10 * 365 * 24 * 60 * 60) {
ptv->tm = *localtime(&mon);
+
token();
break;
}
ptv->type = ABSOLUTE_TIME;
ptv->offset = 0;
ptv->tm = *localtime(&now);
- ptv->tm.tm_isdst = -1; /* mk time can figure this out for us ... */
+ ptv->tm. tm_isdst = -1; /* mk time can figure this out for us ... */
token();
switch (sc_tokid) {
case END:
ptv->type = RELATIVE_TO_END_TIME;
KeepItRelative:
- ptv->tm.tm_sec = 0;
- ptv->tm.tm_min = 0;
- ptv->tm.tm_hour = 0;
- ptv->tm.tm_mday = 0;
- ptv->tm.tm_mon = 0;
- ptv->tm.tm_year = 0;
+ ptv->tm. tm_sec = 0;
+ ptv->tm. tm_min = 0;
+ ptv->tm. tm_hour = 0;
+ ptv->tm. tm_mday = 0;
+ ptv->tm. tm_mon = 0;
+ ptv->tm. tm_year = 0;
+
/* FALLTHRU */
case NOW:
{
long hour_sv = ptv->tm.tm_hour;
long year_sv = ptv->tm.tm_year;
- ptv->tm.tm_hour = 30;
- ptv->tm.tm_year = 30000;
+ ptv->tm. tm_hour = 30;
+ ptv->tm. tm_year = 30000;
+
try(tod(ptv))
try(day(ptv))
if (ptv->tm.tm_hour == 30 && ptv->tm.tm_year != 30000) {
try(tod(ptv))
}
if (ptv->tm.tm_hour == 30) {
- ptv->tm.tm_hour = hour_sv;
+ ptv->tm. tm_hour = hour_sv;
}
if (ptv->tm.tm_year == 30000) {
- ptv->tm.tm_year = year_sv;
+ ptv->tm. tm_year = year_sv;
}
};
break;
ptv->tm.tm_mday++;
ptv->tm.tm_wday++;
} *//* shifting does not makes sense here ... noon is noon */
- ptv->tm.tm_hour = hr;
- ptv->tm.tm_min = 0;
- ptv->tm.tm_sec = 0;
+ ptv->tm. tm_hour = hr;
+ ptv->tm. tm_min = 0;
+ ptv->tm. tm_sec = 0;
+
token();
try(day(ptv));
break;
panic(e("unparsable trailing text: '...%s%s'", sc_token, sct));
}
- ptv->tm.tm_isdst = -1; /* for mktime to guess DST status */
+ ptv->tm. tm_isdst = -1; /* for mktime to guess DST status */
+
if (ptv->type == ABSOLUTE_TIME)
if (mktime(&ptv->tm) == -1) { /* normalize & check */
/* can happen for "nonexistent" times, e.g. around 3am */
tmtmp.tm_mday += start_tv->tm.tm_mday;
tmtmp.tm_mon += start_tv->tm.tm_mon;
tmtmp.tm_year += start_tv->tm.tm_year;
+
*start = mktime(&tmtmp) + start_tv->offset;
} else {
*start = mktime(&(start_tv->tm)) + start_tv->offset;
tmtmp.tm_mday += end_tv->tm.tm_mday;
tmtmp.tm_mon += end_tv->tm.tm_mon;
tmtmp.tm_year += end_tv->tm.tm_year;
+
*end = mktime(&tmtmp) + end_tv->offset;
} else {
*end = mktime(&(end_tv->tm)) + end_tv->offset;
unsigned long *step,
unsigned long *ds_cnt,
char ***ds_namv,
- rrd_value_t ** data);
+ rrd_value_t **data);
int rrd_dump_r(
const char *filename,
char *outname);
}
static int afm_find_char_index(
- const afm_fontinfo * fontinfo,
+ const afm_fontinfo *fontinfo,
afm_cunicode ch1)
{
int idx = ch1 - 32;
#if ENABLE_LIGATURES
static afm_cunicode afm_find_combined_ligature(
- const afm_fontinfo * fontinfo,
+ const afm_fontinfo *fontinfo,
afm_cunicode ch1,
afm_cunicode ch2)
{
static long afm_find_kern(
- const afm_fontinfo * fontinfo,
+ const afm_fontinfo *fontinfo,
int kern_idx,
afm_cunicode ch2)
{
return (-1);
}
- last_up = mktime(&last_up_tv.tm) + last_up_tv.offset;
+ last_up = mktime(&last_up_tv.tm) +last_up_tv.offset;
if (last_up < 3600 * 24 * 365 * 10) {
rrd_set_error
} else { /* DST_CDEF */
char *str = NULL;
- rpn_compact2str((rpn_cdefds_t *) & (rrd.ds_def[i].par[DS_cdef]),
+ rpn_compact2str((rpn_cdefds_t *) &(rrd.ds_def[i].par[DS_cdef]),
rrd.ds_def, &str);
fprintf(out_file, "\t\t<cdef> %s </cdef>\n", str);
free(str);
* will be changed to represent reality */
unsigned long *ds_cnt, /* number of data sources in file */
char ***ds_namv, /* names of data sources */
- rrd_value_t ** data)
+ rrd_value_t **data)
{ /* two dimensional array containing the data */
* will be changed to represent reality */
unsigned long *ds_cnt, /* number of data sources in file */
char ***ds_namv, /* names of data_sources */
- rrd_value_t ** data)
+ rrd_value_t **data)
{ /* two dimensional array containing the data */
enum cf_en cf_idx;
* will be changed to represent reality */
unsigned long *ds_cnt, /* number of data sources in file */
char ***ds_namv, /* names of data_sources */
- rrd_value_t ** data)
+ rrd_value_t **data)
{ /* two dimensional array containing the data */
long i, ii;
time_t cal_start, cal_end, rra_start_time, rra_end_time;
/* create a freetype glyph string */
gfx_string gfx_string_create(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
FT_Face face,
const char *text,
int rotation,
static
gfx_node_t *gfx_new_node(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
enum gfx_en type)
{
gfx_node_t *node = art_new(gfx_node_t, 1);
/* create a new line */
gfx_node_t *gfx_new_line(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double X0,
double Y0,
double X1,
}
gfx_node_t *gfx_new_dashed_line(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double X0,
double Y0,
double X1,
/* create a new area */
gfx_node_t *gfx_new_area(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double X0,
double Y0,
double X1,
/* add a point to a line or to an area */
int gfx_add_point(
- gfx_node_t * node,
+ gfx_node_t *node,
double x,
double y)
{
}
void gfx_close_path(
- gfx_node_t * node)
+ gfx_node_t *node)
{
node->closed_path = 1;
if (node->path[0].code == ART_MOVETO_OPEN)
/* create a text node */
gfx_node_t *gfx_new_text(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double x,
double y,
gfx_color_t color,
}
int gfx_render(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
art_u32 width,
art_u32 height,
gfx_color_t background,
double gfx_get_text_width(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double start,
char *font,
double size,
}
double gfx_get_text_width_libart(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double UNUSED(start),
char *font,
double size,
}
static void gfx_libart_close_path(
- gfx_node_t * node,
+ gfx_node_t *node,
ArtVpath ** vec)
{
/* libart must have end==start for closed paths,
/* create a free type glyph string */
gfx_string gfx_string_create(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
FT_Face face,
const char *text,
int rotation,
/* render grafics into png image */
int gfx_render_png(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
art_u32 width,
art_u32 height,
gfx_color_t background,
/* free memory used by nodes this will also remove memory required for
associated paths and svcs ... but not for text strings */
int gfx_destroy(
- gfx_canvas_t * canvas)
+ gfx_canvas_t *canvas)
{
gfx_node_t *next, *node = canvas->firstnode;
#if PDF_CALC_DEBUG
static void pdf_dump_calc(
- gfx_node_t * node,
+ gfx_node_t *node,
pdf_coords * g)
{
fprintf(stderr, "PDF CALC =============================\n");
static void pdf_rotate(
pdf_coords * g,
- pdf_point * p)
+ pdf_point *p)
{
double x2 = g->cos_r * p->x - g->sin_r * p->y;
double y2 = g->sin_r * p->x + g->cos_r * p->y;
static void pdf_calc(
int page_height,
- gfx_node_t * node,
+ gfx_node_t *node,
pdf_coords * g)
{
pdf_point a, b, c;
}
static void svg_get_dash(
- gfx_node_t * node,
- svg_dash * d)
+ gfx_node_t *node,
+ svg_dash *d)
{
double offset;
int mult;
}
static int svg_dash_equal(
- svg_dash * a,
- svg_dash * b)
+ svg_dash *a,
+ svg_dash *b)
{
if (a->dash_enable != b->dash_enable)
return 0;
static void svg_common_path_attributes(
FILE * fp,
- gfx_node_t * node)
+ gfx_node_t *node)
{
svg_dash dash_info;
double lastA,
double currentA,
double currentB,
- gfx_node_t * node,
+ gfx_node_t *node,
int segment_idx,
int isx,
char absChar,
static void svg_path(
FILE * fp,
- gfx_node_t * node,
+ gfx_node_t *node,
int multi)
{
int i;
static void svg_multi_path(
FILE * fp,
- gfx_node_t ** nodeR)
+ gfx_node_t **nodeR)
{
/* optimize for multiple paths with the same color, penwidth, etc. */
int num = 1;
static void svg_area(
FILE * fp,
- gfx_node_t * node)
+ gfx_node_t *node)
{
int i;
double startX = 0, startY = 0;
static void svg_text(
FILE * fp,
- gfx_node_t * node)
+ gfx_node_t *node)
{
pdf_coords g;
const char *fontname;
}
int gfx_render_svg(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
art_u32 width,
art_u32 height,
gfx_color_t background,
} eps_state;
static void eps_set_color(
- eps_state * state,
+ eps_state *state,
gfx_color_t color)
{
#if USE_EPS_FAKE_ALPHA
}
static int eps_add_font(
- eps_state * state,
- gfx_node_t * node)
+ eps_state *state,
+ gfx_node_t *node)
{
/* The fonts list could be postponed to the end using
(atend), but let's be nice and have them in the header. */
}
static void eps_list_fonts(
- eps_state * state,
+ eps_state *state,
const char *dscName)
{
eps_font *ef;
}
static void eps_define_fonts(
- eps_state * state)
+ eps_state *state)
{
eps_font *ef;
}
static int eps_prologue(
- eps_state * state)
+ eps_state *state)
{
gfx_node_t *node;
}
static void eps_clear_dash(
- eps_state * state)
+ eps_state *state)
{
if (!state->has_dash)
return;
}
static void eps_write_linearea(
- eps_state * state,
- gfx_node_t * node)
+ eps_state *state,
+ gfx_node_t *node)
{
int i;
FILE *fp = state->fp;
}
static void eps_write_text(
- eps_state * state,
- gfx_node_t * node)
+ eps_state *state,
+ gfx_node_t *node)
{
FILE *fp = state->fp;
const char *ps_font = afm_get_font_postscript_name(node->filename);
}
static int eps_write_content(
- eps_state * state)
+ eps_state *state)
{
gfx_node_t *node;
}
int gfx_render_eps(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
art_u32 width,
art_u32 height,
gfx_color_t background,
} pdf_state;
static void pdf_init_buffer(
- pdf_state * state,
- pdf_buffer * buf)
+ pdf_state *state,
+ pdf_buffer *buf)
{
int initial_size = 32;
}
static void pdf_put(
- pdf_buffer * buf,
+ pdf_buffer *buf,
const char *text,
int len)
{
}
static void pdf_put_char(
- pdf_buffer * buf,
+ pdf_buffer *buf,
char c)
{
if (buf->alloc_size >= buf->current_size + 1) {
}
static void pdf_puts(
- pdf_buffer * buf,
+ pdf_buffer *buf,
const char *text)
{
pdf_put(buf, text, strlen(text));
}
static void pdf_indent(
- pdf_buffer * buf)
+ pdf_buffer *buf)
{
pdf_puts(buf, "\t");
}
static void pdf_putsi(
- pdf_buffer * buf,
+ pdf_buffer *buf,
const char *text)
{
pdf_indent(buf);
}
static void pdf_putint(
- pdf_buffer * buf,
+ pdf_buffer *buf,
int i)
{
char tmp[20];
}
static void pdf_putnumber(
- pdf_buffer * buf,
+ pdf_buffer *buf,
double d)
{
char tmp[50];
}
static void pdf_put_string_contents_wide(
- pdf_buffer * buf,
+ pdf_buffer *buf,
const afm_char * text)
{
const afm_char *p = text;
}
static void pdf_put_string_contents(
- pdf_buffer * buf,
+ pdf_buffer *buf,
const char *text)
{
#ifdef HAVE_MBSTOWCS
}
static void pdf_init_object(
- pdf_state * state,
- pdf_buffer * buf)
+ pdf_state *state,
+ pdf_buffer *buf)
{
pdf_init_buffer(state, buf);
buf->id = ++state->last_obj_id;
}
static void pdf_init_dict(
- pdf_state * state,
- pdf_buffer * buf)
+ pdf_state *state,
+ pdf_buffer *buf)
{
pdf_init_object(state, buf);
buf->is_dict = 1;
}
static void pdf_set_color(
- pdf_buffer * buf,
+ pdf_buffer *buf,
gfx_color_t color,
- gfx_color_t * current_color,
+ gfx_color_t *current_color,
const char *op)
{
#if USE_PDF_FAKE_ALPHA
}
static void pdf_set_stroke_color(
- pdf_buffer * buf,
+ pdf_buffer *buf,
gfx_color_t color)
{
pdf_set_color(buf, color, &buf->state->stroke_color, "RG");
}
static void pdf_set_fill_color(
- pdf_buffer * buf,
+ pdf_buffer *buf,
gfx_color_t color)
{
pdf_set_color(buf, color, &buf->state->fill_color, "rg");
}
static pdf_font *pdf_find_font(
- pdf_state * state,
- gfx_node_t * node)
+ pdf_state *state,
+ gfx_node_t *node)
{
const char *ps_font = afm_get_font_postscript_name(node->filename);
pdf_font *ef;
}
static void pdf_add_font(
- pdf_state * state,
- gfx_node_t * node)
+ pdf_state *state,
+ gfx_node_t *node)
{
pdf_font *ef = pdf_find_font(state, node);
}
static void pdf_create_fonts(
- pdf_state * state)
+ pdf_state *state)
{
gfx_node_t *node;
}
static void pdf_write_linearea(
- pdf_state * state,
- gfx_node_t * node)
+ pdf_state *state,
+ gfx_node_t *node)
{
int i;
pdf_buffer *s = &state->graph_stream;
static void pdf_write_matrix(
- pdf_state * state,
- gfx_node_t * node,
+ pdf_state *state,
+ gfx_node_t *node,
pdf_coords * g,
int useTM)
{
}
static void pdf_write_text(
- pdf_state * state,
- gfx_node_t * node,
+ pdf_state *state,
+ gfx_node_t *node,
int last_was_text,
int next_is_text)
{
}
static void pdf_write_content(
- pdf_state * state)
+ pdf_state *state)
{
gfx_node_t *node;
int last_was_text = 0, next_is_text;
}
static void pdf_init_document(
- pdf_state * state)
+ pdf_state *state)
{
pdf_init_buffer(state, &state->pdf_header);
pdf_init_dict(state, &state->catalog_obj);
}
static void pdf_setup_document(
- pdf_state * state)
+ pdf_state *state)
{
const char *creator =
"RRDtool " PACKAGE_VERSION " Tobias Oetiker, http://tobi.oetiker.ch";
}
static void pdf_write_string_to_file(
- pdf_state * state,
+ pdf_state *state,
const char *text)
{
fputs(text, state->fp);
}
static void pdf_write_buf_to_file(
- pdf_state * state,
- pdf_buffer * buf)
+ pdf_state *state,
+ pdf_buffer *buf)
{
char tmp[40];
}
static void pdf_write_to_file(
- pdf_state * state)
+ pdf_state *state)
{
pdf_buffer *buf = state->first_buffer;
int xref_pos;
}
static void pdf_free_resources(
- pdf_state * state)
+ pdf_state *state)
{
pdf_buffer *buf = state->first_buffer;
}
int gfx_render_pdf(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
art_u32 width,
art_u32 height,
gfx_color_t UNUSED(background),
/* create a new line */
gfx_node_t *gfx_new_line(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double X0,
double Y0,
double X1,
gfx_color_t color);
gfx_node_t *gfx_new_dashed_line(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double X0,
double Y0,
double X1,
/* create a new area */
gfx_node_t *gfx_new_area(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double X0,
double Y0,
double X1,
/* add a point to a line or to an area */
int gfx_add_point(
- gfx_node_t * node,
+ gfx_node_t *node,
double x,
double y);
/* close current path so it ends at the same point as it started */
void gfx_close_path(
- gfx_node_t * node);
+ gfx_node_t *node);
/* create a text node */
gfx_node_t *gfx_new_text(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double x,
double y,
gfx_color_t color,
/* measure width of a text string */
double gfx_get_text_width(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double start,
char *font,
double size,
/* save image to file */
int gfx_render(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
art_u32 width,
art_u32 height,
gfx_color_t background,
/* free memory used by nodes this will also remove memory required for
node chain and associated material */
int gfx_destroy(
- gfx_canvas_t * canvas);
+ gfx_canvas_t *canvas);
/* PNG support*/
int gfx_render_png(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
art_u32 width,
art_u32 height,
gfx_color_t background,
FILE * fo);
double gfx_get_text_width_libart(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
double start,
char *font,
double size,
/* SVG support */
int gfx_render_svg(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
art_u32 width,
art_u32 height,
gfx_color_t background,
/* EPS support */
int gfx_render_eps(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
art_u32 width,
art_u32 height,
gfx_color_t background,
/* PDF support */
int gfx_render_pdf(
- gfx_canvas_t * canvas,
+ gfx_canvas_t *canvas,
art_u32 width,
art_u32 height,
gfx_color_t background,
/* initialize with xtr(im,0); */
int xtr(
- image_desc_t * im,
+ image_desc_t *im,
time_t mytime)
{
static double pixie;
/* translate data values into y coordinates */
double ytr(
- image_desc_t * im,
+ image_desc_t *im,
double value)
{
static double pixie;
#undef conv_if
int im_free(
- image_desc_t * im)
+ image_desc_t *im)
{
unsigned long i, ii;
/* find SI magnitude symbol for the given number*/
void auto_scale(
- image_desc_t * im, /* image description */
+ image_desc_t *im, /* image description */
double *value,
char **symb_ptr,
double *magfact)
/* find SI magnitude symbol for the numbers on the y-axis*/
void si_unit(
- image_desc_t * im /* image description */
+ image_desc_t *im /* image description */
)
{
/* move min and max values around to become sensible */
void expand_range(
- image_desc_t * im)
+ image_desc_t *im)
{
double sensiblevalues[] = { 1000.0, 900.0, 800.0, 750.0, 700.0,
600.0, 500.0, 400.0, 300.0, 250.0,
}
void apply_gridfit(
- image_desc_t * im)
+ image_desc_t *im)
{
if (isnan(im->minval) || isnan(im->maxval))
return;
time_t *end, /* ... by the application will be ... */
unsigned long *step, /* ... adjusted to represent reality */
unsigned long *ds_cnt, /* number of data sources in file */
- rrd_value_t ** data)
+ rrd_value_t **data)
{ /* two dimensional array containing the data */
int i, reduce_factor = ceil((double) (*step) / (double) cur_step);
unsigned long col, dst_row, row_cnt, start_offset, end_offset, skiprows =
relevant rrds ... */
int data_fetch(
- image_desc_t * im)
+ image_desc_t *im)
{
int i, ii;
int skip;
/* find gdes containing var*/
long find_var(
- image_desc_t * im,
+ image_desc_t *im,
char *key)
{
long ii;
/* run the rpn calculator on all the VDEF and CDEF arguments */
int data_calc(
- image_desc_t * im)
+ image_desc_t *im)
{
int gdi;
/* massage data so, that we get one value for each x coordinate in the graph */
int data_proc(
- image_desc_t * im)
+ image_desc_t *im)
{
long i, ii;
double pixstep = (double) (im->end - im->start)
struct tm tm;
localtime_r(&start, &tm);
+
switch (baseint) {
case TMT_SECOND:
- tm.tm_sec -= tm.tm_sec % basestep;
+ tm. tm_sec -= tm.tm_sec % basestep;
+
break;
case TMT_MINUTE:
- tm.tm_sec = 0;
- tm.tm_min -= tm.tm_min % basestep;
+ tm. tm_sec = 0;
+ tm. tm_min -= tm.tm_min % basestep;
+
break;
case TMT_HOUR:
- tm.tm_sec = 0;
- tm.tm_min = 0;
- tm.tm_hour -= tm.tm_hour % basestep;
+ tm. tm_sec = 0;
+ tm. tm_min = 0;
+ tm. tm_hour -= tm.tm_hour % basestep;
+
break;
case TMT_DAY:
/* we do NOT look at the basestep for this ... */
- tm.tm_sec = 0;
- tm.tm_min = 0;
- tm.tm_hour = 0;
+ tm. tm_sec = 0;
+ tm. tm_min = 0;
+ tm. tm_hour = 0;
+
break;
case TMT_WEEK:
/* we do NOT look at the basestep for this ... */
- tm.tm_sec = 0;
- tm.tm_min = 0;
- tm.tm_hour = 0;
- tm.tm_mday -= tm.tm_wday - 1; /* -1 because we want the monday */
+ tm. tm_sec = 0;
+ tm. tm_min = 0;
+ tm. tm_hour = 0;
+ tm. tm_mday -= tm.tm_wday - 1; /* -1 because we want the monday */
+
if (tm.tm_wday == 0)
- tm.tm_mday -= 7; /* we want the *previous* monday */
+ tm. tm_mday -= 7; /* we want the *previous* monday */
+
break;
case TMT_MONTH:
- tm.tm_sec = 0;
- tm.tm_min = 0;
- tm.tm_hour = 0;
- tm.tm_mday = 1;
- tm.tm_mon -= tm.tm_mon % basestep;
+ tm. tm_sec = 0;
+ tm. tm_min = 0;
+ tm. tm_hour = 0;
+ tm. tm_mday = 1;
+ tm. tm_mon -= tm.tm_mon % basestep;
+
break;
case TMT_YEAR:
- tm.tm_sec = 0;
- tm.tm_min = 0;
- tm.tm_hour = 0;
- tm.tm_mday = 1;
- tm.tm_mon = 0;
- tm.tm_year -= (tm.tm_year + 1900) % basestep;
+ tm. tm_sec = 0;
+ tm. tm_min = 0;
+ tm. tm_hour = 0;
+ tm. tm_mday = 1;
+ tm. tm_mon = 0;
+ tm. tm_year -= (
+ tm.tm_year + 1900) %basestep;
}
return mktime(&tm);
time_t madetime;
localtime_r(¤t, &tm);
+
do {
switch (baseint) {
case TMT_SECOND:
- tm.tm_sec += basestep;
+ tm. tm_sec += basestep;
+
break;
case TMT_MINUTE:
- tm.tm_min += basestep;
+ tm. tm_min += basestep;
+
break;
case TMT_HOUR:
- tm.tm_hour += basestep;
+ tm. tm_hour += basestep;
+
break;
case TMT_DAY:
- tm.tm_mday += basestep;
+ tm. tm_mday += basestep;
+
break;
case TMT_WEEK:
- tm.tm_mday += 7 * basestep;
+ tm. tm_mday += 7 * basestep;
+
break;
case TMT_MONTH:
- tm.tm_mon += basestep;
+ tm. tm_mon += basestep;
+
break;
case TMT_YEAR:
- tm.tm_year += basestep;
+ tm. tm_year += basestep;
}
madetime = mktime(&tm);
} while (madetime == -1); /* this is necessary to skip impssible times
/* calculate values required for PRINT and GPRINT functions */
int print_calc(
- image_desc_t * im,
+ image_desc_t *im,
char ***prdata)
{
long i, ii, validsteps;
/* place legends with color spots */
int leg_place(
- image_desc_t * im)
+ image_desc_t *im)
{
/* graph labels */
int interleg = im->text_prop[TEXT_PROP_LEGEND].size * 2.0;
int calc_horizontal_grid(
- image_desc_t * im)
+ image_desc_t *im)
{
double range;
double scaledrange;
}
int draw_horizontal_grid(
- image_desc_t * im)
+ image_desc_t *im)
{
int i;
double scaledstep;
/* logaritmic horizontal grid */
int horizontal_log_grid(
- image_desc_t * im)
+ image_desc_t *im)
{
double yloglab[][10] = {
{1.0, 10., 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
void vertical_grid(
- image_desc_t * im)
+ image_desc_t *im)
{
int xlab_sel; /* which sort of label and grid ? */
time_t ti, tilab, timajor;
void axis_paint(
- image_desc_t * im)
+ image_desc_t *im)
{
/* draw x and y axis */
/* gfx_new_line ( im->canvas, im->xorigin+im->xsize,im->yorigin,
}
void grid_paint(
- image_desc_t * im)
+ image_desc_t *im)
{
long i;
int res = 0;
*****************************************************/
int lazy_check(
- image_desc_t * im)
+ image_desc_t *im)
{
FILE *fd = NULL;
int size = 1;
#ifdef WITH_PIECHART
void pie_part(
- image_desc_t * im,
+ image_desc_t *im,
gfx_color_t color,
double PieCenterX,
double PieCenterY,
#endif
int graph_size_location(
- image_desc_t * im,
+ image_desc_t *im,
int elements
#ifdef WITH_PIECHART
,
/* draw that picture thing ... */
int graph_paint(
- image_desc_t * im,
+ image_desc_t *im,
char ***calcpr)
{
int i, ii;
*****************************************************/
int gdes_alloc(
- image_desc_t * im)
+ image_desc_t *im)
{
im->gdes_c++;
}
void rrd_graph_init(
- image_desc_t * im)
+ image_desc_t *im)
{
unsigned int i;
void rrd_graph_options(
int argc,
char *argv[],
- image_desc_t * im)
+ image_desc_t *im)
{
int stroff;
char *parsetime_error = NULL;
}
int rrd_graph_color(
- image_desc_t * im,
+ image_desc_t *im,
char *var,
char *err,
int optional)
int rrd_parse_find_gf(
const char *const,
unsigned int *const,
- graph_desc_t * const);
+ graph_desc_t *const);
int rrd_parse_legend(
const char *const,
unsigned int *const,
- graph_desc_t * const);
+ graph_desc_t *const);
int rrd_parse_color(
const char *const,
- graph_desc_t * const);
+ graph_desc_t *const);
int rrd_parse_CF(
const char *const,
unsigned int *const,
- graph_desc_t * const,
+ graph_desc_t *const,
enum cf_en *const);
int rrd_parse_print(
const char *const,
unsigned int *const,
- graph_desc_t * const,
- image_desc_t * const);
+ graph_desc_t *const,
+ image_desc_t *const);
int rrd_parse_shift(
const char *const,
unsigned int *const,
- graph_desc_t * const,
- image_desc_t * const);
+ graph_desc_t *const,
+ image_desc_t *const);
int rrd_parse_xport(
const char *const,
unsigned int *const,
- graph_desc_t * const,
- image_desc_t * const);
+ graph_desc_t *const,
+ image_desc_t *const);
int rrd_parse_PVHLAST(
const char *const,
unsigned int *const,
- graph_desc_t * const,
- image_desc_t * const);
+ graph_desc_t *const,
+ image_desc_t *const);
int rrd_parse_make_vname(
const char *const,
unsigned int *const,
- graph_desc_t * const,
- image_desc_t * const);
+ graph_desc_t *const,
+ image_desc_t *const);
int rrd_parse_find_vname(
const char *const,
unsigned int *const,
- graph_desc_t * const,
- image_desc_t * const);
+ graph_desc_t *const,
+ image_desc_t *const);
int rrd_parse_def(
const char *const,
unsigned int *const,
- graph_desc_t * const,
- image_desc_t * const);
+ graph_desc_t *const,
+ image_desc_t *const);
int rrd_parse_vdef(
const char *const,
unsigned int *const,
- graph_desc_t * const,
- image_desc_t * const);
+ graph_desc_t *const,
+ image_desc_t *const);
int rrd_parse_cdef(
const char *const,
unsigned int *const,
- graph_desc_t * const,
- image_desc_t * const);
+ graph_desc_t *const,
+ image_desc_t *const);
int rrd_parse_find_gf(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp)
+ graph_desc_t *const gdp)
{
char funcname[11], c1 = 0;
int i = 0;
int rrd_parse_legend(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp)
+ graph_desc_t *const gdp)
{
int i;
int rrd_parse_color(
const char *const string,
- graph_desc_t * const gdp)
+ graph_desc_t *const gdp)
{
unsigned int r = 0, g = 0, b = 0, a = 0, i;
int rrd_parse_CF(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp,
+ graph_desc_t *const gdp,
enum cf_en *cf)
{
char symname[CF_NAM_SIZE];
int rrd_parse_find_vname(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp,
- image_desc_t * const im)
+ graph_desc_t *const gdp,
+ image_desc_t *const im)
{
char tmpstr[MAX_VNAME_LEN + 1];
int i;
int rrd_parse_print(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp,
- image_desc_t * const im)
+ graph_desc_t *const gdp,
+ image_desc_t *const im)
{
/* vname:CF:format in case of DEF-based vname
** vname:CF:format in case of CDEF-based vname
int rrd_parse_shift(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp,
- image_desc_t * const im)
+ graph_desc_t *const gdp,
+ image_desc_t *const im)
{
int i;
int rrd_parse_xport(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp,
- image_desc_t * const im)
+ graph_desc_t *const gdp,
+ image_desc_t *const im)
{
if ((gdp->vidx = rrd_parse_find_vname(line, eaten, gdp, im)) < 0)
return 1;
int rrd_parse_PVHLAST(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp,
- image_desc_t * const im)
+ graph_desc_t *const gdp,
+ image_desc_t *const im)
{
int i, j, k;
int colorfound = 0;
int rrd_parse_make_vname(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp,
- image_desc_t * const im)
+ graph_desc_t *const gdp,
+ image_desc_t *const im)
{
char tmpstr[MAX_VNAME_LEN + 10];
int i = 0;
int rrd_parse_def(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp,
- image_desc_t * const im)
+ graph_desc_t *const gdp,
+ image_desc_t *const im)
{
int i = 0;
char command[7]; /* step, start, end, reduce */
int rrd_parse_vdef(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp,
- image_desc_t * const im)
+ graph_desc_t *const gdp,
+ image_desc_t *const im)
{
char tmpstr[MAX_VNAME_LEN + 1]; /* vname\0 */
int i = 0;
int rrd_parse_cdef(
const char *const line,
unsigned int *const eaten,
- graph_desc_t * const gdp,
- image_desc_t * const im)
+ graph_desc_t *const gdp,
+ image_desc_t *const im)
{
dprintf("- parsing '%s'\n", &line[*eaten]);
if (rrd_parse_make_vname(line, eaten, gdp, im))
void rrd_graph_script(
int argc,
char *argv[],
- image_desc_t * const im,
+ image_desc_t *const im,
int optno)
{
int i;
unsigned long rra_idx,
unsigned long ds_idx,
unsigned short CDP_scratch_idx,
- rrd_value_t * seasonal_coef);
+ rrd_value_t *seasonal_coef);
int update_devpredict(
rrd_t *rrd,
unsigned long cdp_idx,
unsigned long rra_idx,
unsigned long ds_idx,
unsigned short CDP_scratch_idx,
- rrd_value_t * seasonal_dev);
+ rrd_value_t *seasonal_dev);
int update_failures(
rrd_t *rrd,
unsigned long cdp_idx,
rrd_t *rrd,
unsigned long rra_idx,
unsigned long rra_start,
- rrd_file_t * rrd_file,
+ rrd_file_t *rrd_file,
unsigned long offset,
- rrd_value_t ** seasonal_coef)
+ rrd_value_t **seasonal_coef)
{
unsigned long pos_tmp;
unsigned long rra_idx,
unsigned long ds_idx,
unsigned short CDP_scratch_idx,
- rrd_value_t * seasonal_coef)
+ rrd_value_t *seasonal_coef)
{
/* TODO: extract common if subblocks in the wake of I/O optimization */
rrd_value_t intercept, seasonal;
unsigned long rra_idx,
unsigned long ds_idx,
unsigned short CDP_scratch_idx,
- rrd_value_t * seasonal_dev)
+ rrd_value_t *seasonal_dev)
{
rrd_value_t prediction = 0, seasonal_coef = DNAN;
rra_def_t *current_rra = &(rrd->rra_def[rra_idx]);
rrd_t *rrd,
unsigned long rra_idx,
unsigned long rra_start,
- rrd_file_t * rrd_file)
+ rrd_file_t *rrd_file)
{
unsigned long i, j, k;
unsigned long totalbytes;
* seasonal, and seasonal deviation for the specified data source. */
void reset_aberrant_coefficients(
rrd_t *rrd,
- rrd_file_t * rrd_file,
+ rrd_file_t *rrd_file,
unsigned long ds_idx)
{
unsigned long cdp_idx, rra_idx, i;
}
void init_hwpredict_cdp(
- cdp_prep_t * cdp)
+ cdp_prep_t *cdp)
{
cdp->scratch[CDP_hw_intercept].u_val = DNAN;
cdp->scratch[CDP_hw_last_intercept].u_val = DNAN;
}
void init_seasonal_cdp(
- cdp_prep_t * cdp)
+ cdp_prep_t *cdp)
{
cdp->scratch[CDP_hw_seasonal].u_val = DNAN;
cdp->scratch[CDP_hw_last_seasonal].u_val = DNAN;
unsigned long rra_idx,
unsigned long ds_idx,
unsigned short CDP_scratch_idx,
- rrd_value_t * seasonal_coef)
+ rrd_value_t *seasonal_coef)
{
rrd->cdp_prep[cdp_idx].scratch[CDP_scratch_idx].u_val = pdp_val;
switch (current_cf) {
/* a standard fixed-capacity FIF0 queue implementation
* No overflow checking is performed. */
int queue_alloc(
- FIFOqueue ** q,
+ FIFOqueue **q,
int capacity)
{
*q = (FIFOqueue *) malloc(sizeof(FIFOqueue));
}
int queue_isempty(
- FIFOqueue * q)
+ FIFOqueue *q)
{
return (q->head % q->capacity == q->tail);
}
void queue_push(
- FIFOqueue * q,
+ FIFOqueue *q,
rrd_value_t value)
{
q->queue[(q->tail)++] = value;
}
rrd_value_t queue_pop(
- FIFOqueue * q)
+ FIFOqueue *q)
{
q->head = q->head % q->capacity;
return q->queue[(q->head)++];
}
void queue_dealloc(
- FIFOqueue * q)
+ FIFOqueue *q)
{
free(q->queue);
free(q);
unsigned long rra_idx,
unsigned long ds_idx,
unsigned short CDP_scratch_idx,
- rrd_value_t * seasonal_coef);
+ rrd_value_t *seasonal_coef);
int create_hw_contingent_rras(
rrd_t *rrd,
unsigned short period,
rrd_t *rrd,
unsigned long rra_idx,
unsigned long rra_start,
- rrd_file_t * rrd_file,
+ rrd_file_t *rrd_file,
unsigned long offset,
- rrd_value_t ** seasonal_coef);
+ rrd_value_t **seasonal_coef);
void erase_violations(
rrd_t *rrd,
unsigned long cdp_idx,
rrd_t *rrd,
unsigned long rra_idx,
unsigned long rra_start,
- rrd_file_t * rrd_file);
+ rrd_file_t *rrd_file);
void reset_aberrant_coefficients(
rrd_t *rrd,
- rrd_file_t * rrd_file,
+ rrd_file_t *rrd_file,
unsigned long ds_idx);
void init_hwpredict_cdp(
cdp_prep_t *);
} FIFOqueue;
int queue_alloc(
- FIFOqueue ** q,
+ FIFOqueue **q,
int capacity);
void queue_dealloc(
- FIFOqueue * q);
+ FIFOqueue *q);
void queue_push(
- FIFOqueue * q,
+ FIFOqueue *q,
rrd_value_t value);
int queue_isempty(
- FIFOqueue * q);
+ FIFOqueue *q);
rrd_value_t queue_pop(
- FIFOqueue * q);
+ FIFOqueue *q);
{
char *buffer = NULL;
- rpn_compact2str((rpn_cdefds_t *) & (rrd.ds_def[i].par[DS_cdef]),
+ rpn_compact2str((rpn_cdefds_t *) &(rrd.ds_def[i].par[DS_cdef]),
rrd.ds_def, &buffer);
info.u_str = buffer;
cd = info_push(cd,
/* Close a reference to an rrd_file. */
int rrd_close(
- rrd_file_t * rrd_file)
+ rrd_file_t *rrd_file)
{
int ret = 0;
/* Set position of rrd_file. */
off_t rrd_seek(
- rrd_file_t * rrd_file,
+ rrd_file_t *rrd_file,
off_t off,
int whence)
{
/* Get current position in rrd_file. */
off_t rrd_tell(
- rrd_file_t * rrd_file)
+ rrd_file_t *rrd_file)
{
return rrd_file->pos;
}
/* read count bytes into buffer buf, starting at rrd_file->pos.
* Returns the number of bytes read. */
ssize_t rrd_read(
- rrd_file_t * rrd_file,
+ rrd_file_t *rrd_file,
void *buf,
size_t count)
{
/* write count bytes from buffer buf to the current position
* rrd_file->pos of rrd_file->fd. */
ssize_t rrd_write(
- rrd_file_t * rrd_file,
+ rrd_file_t *rrd_file,
const void *buf,
size_t count)
{
/* flush all data pending to be written to FD. */
void rrd_flush(
- rrd_file_t * rrd_file)
+ rrd_file_t *rrd_file)
{
if (fdatasync(rrd_file->fd) != 0) {
rrd_set_error("flushing fd %d: %s", rrd_file->fd,
time_t); /* used to implement LTIME */
short rpn_compact(
- rpnp_t * rpnp,
- rpn_cdefds_t ** rpnc,
+ rpnp_t *rpnp,
+ rpn_cdefds_t **rpnc,
short *count)
{
short i;
}
rpnp_t *rpn_expand(
- rpn_cdefds_t * rpnc)
+ rpn_cdefds_t *rpnc)
{
short i;
rpnp_t *rpnp;
* str: out string, memory is allocated by the function, must be freed by the
* the caller */
void rpn_compact2str(
- rpn_cdefds_t * rpnc,
- ds_def_t * ds_def,
+ rpn_cdefds_t *rpnc,
+ ds_def_t *ds_def,
char **str)
{
unsigned short i, offset = 0;
rpnp_t *rpn_parse(
void *key_hash,
const char *const expr_const,
- long (*lookup) (void *,
- char *))
+ long (*lookup) (void *,
+ char *))
{
int pos = 0;
char *expr;
}
void rpnstack_init(
- rpnstack_t * rpnstack)
+ rpnstack_t *rpnstack)
{
rpnstack->s = NULL;
rpnstack->dc_stacksize = 0;
}
void rpnstack_free(
- rpnstack_t * rpnstack)
+ rpnstack_t *rpnstack)
{
if (rpnstack->s != NULL)
free(rpnstack->s);
* 0 on success
*/
short rpn_calc(
- rpnp_t * rpnp,
- rpnstack_t * rpnstack,
+ rpnp_t *rpnp,
+ rpnstack_t *rpnstack,
long data_idx,
- rrd_value_t * output,
+ rrd_value_t *output,
int output_idx)
{
int rpi;
} rpnstack_t;
void rpnstack_init(
- rpnstack_t * rpnstack);
+ rpnstack_t *rpnstack);
void rpnstack_free(
- rpnstack_t * rpnstack);
+ rpnstack_t *rpnstack);
void parseCDEF_DS(
const char *def,
char *ds_name);
short rpn_compact(
- rpnp_t * rpnp,
- rpn_cdefds_t ** rpnc,
+ rpnp_t *rpnp,
+ rpn_cdefds_t **rpnc,
short *count);
rpnp_t *rpn_expand(
- rpn_cdefds_t * rpnc);
+ rpn_cdefds_t *rpnc);
void rpn_compact2str(
- rpn_cdefds_t * rpnc,
- ds_def_t * ds_def,
+ rpn_cdefds_t *rpnc,
+ ds_def_t *ds_def,
char **str);
rpnp_t *rpn_parse(
void *key_hash,
long (*lookup) (void *,
char *));
short rpn_calc(
- rpnp_t * rpnp,
- rpnstack_t * rpnstack,
+ rpnp_t *rpnp,
+ rpnstack_t *rpnstack,
long data_idx,
- rrd_value_t * output,
+ rrd_value_t *output,
int output_idx);
#endif
unsigned long *step,
unsigned long *ds_cnt,
char ***ds_namv,
- rrd_value_t ** data);
+ rrd_value_t **data);
void rrd_free(
rrd_t *rrd);
rrd_t *rrd,
unsigned rdwr);
int rrd_close(
- rrd_file_t * rrd_file);
+ rrd_file_t *rrd_file);
ssize_t rrd_read(
- rrd_file_t * rrd_file,
+ rrd_file_t *rrd_file,
void *buf,
size_t count);
ssize_t rrd_write(
- rrd_file_t * rrd_file,
+ rrd_file_t *rrd_file,
const void *buf,
size_t count);
void rrd_flush(
- rrd_file_t * rrd_file);
+ rrd_file_t *rrd_file);
off_t rrd_seek(
- rrd_file_t * rrd_file,
+ rrd_file_t *rrd_file,
off_t off,
int whence);
off_t rrd_tell(
- rrd_file_t * rrd_file);
+ rrd_file_t *rrd_file);
int readfile(
const char *file,
char **buffer,
}
current_time = mktime(&ds_tv.tm) + ds_tv.offset;
+
current_time_usec = 0; /* FIXME: how to handle usecs here ? */
} else if (strcmp(updvals[0], "N") == 0) {
* will be changed to represent reality */
unsigned long *col_cnt, /* number of data columns in the result */
char ***legend_v, /* legend entries */
- rrd_value_t ** data)
+ rrd_value_t **data)
{ /* two dimensional array containing the data */
image_desc_t im;
int rrd_xport_fn(
- image_desc_t * im,
+ image_desc_t *im,
time_t *start,
time_t *end, /* which time frame do you want ?
* will be changed to represent reality */
* will be changed to represent reality */
unsigned long *col_cnt, /* number of data columns in the result */
char ***legend_v, /* legend entries */
- rrd_value_t ** data)
+ rrd_value_t **data)
{ /* two dimensional array containing the data */
int i = 0, j = 0;
#define finite _finite
#define snprintf _snprintf
#define vsnprintf _vsnprintf
-#define strftime strftime_
+#define strftime strftime_
#define NO_NULL_REALLOC 1
#if NO_NULL_REALLOC
# define rrd_realloc(a,b) ( (a) == NULL ? malloc( (b) ) : realloc( (a) , (b) ))
#else
# define rrd_realloc(a,b) realloc((a), (b))
-#endif
+#endif
/* Vertical label angle: 90.0 (default) or 270.0 */
#define RRDGRAPH_YLEGEND_ANGLE 90.0
/* #define DEBUG 1 */
-#endif /* CONFIG_H */
-
+#endif /* CONFIG_H */