indent all the rest of the code, and add some typedefs to indent.pro
[rrdtool.git] / bindings / ruby / main.c
index b2eaa68..32bd8cf 100644 (file)
@@ -7,33 +7,39 @@
 #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));
@@ -51,9 +57,10 @@ string_arr string_arr_new(VALUE rb_strings)
     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++) {
@@ -63,14 +70,17 @@ void string_arr_delete(string_arr a)
     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;
 
@@ -79,38 +89,42 @@ VALUE rrd_call(RRDFUNC func, VALUE args)
     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]);
@@ -120,7 +134,8 @@ VALUE rb_rrd_fetch(VALUE self, VALUE args)
     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++;
@@ -128,7 +143,7 @@ VALUE rb_rrd_fetch(VALUE self, VALUE args)
         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));
@@ -137,22 +152,23 @@ VALUE rb_rrd_fetch(VALUE self, VALUE args)
     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++) {
@@ -207,10 +223,12 @@ VALUE rb_rrd_info(VALUE self, VALUE args)
 }
 */
 
-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();
@@ -218,31 +236,39 @@ VALUE rb_rrd_last(VALUE self, VALUE args)
     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);