Browse Source

tally: Adapt tally_histogram to Samba coding conventions

Autobuild-User: Volker Lendecke <vlendec@samba.org>
Autobuild-Date: Wed Aug 10 21:12:59 CEST 2011 on sn-devel-104

(Imported from SAMBA commit f7b820c3590ac78dd0dea67ac882f53ae6f550d9)
Volker Lendecke 14 years ago
parent
commit
0eb0295702
1 changed files with 16 additions and 10 deletions
  1. 16 10
      ccan/tally/tally.c

+ 16 - 10
ccan/tally/tally.c

@@ -451,15 +451,17 @@ char *tally_histogram(const struct tally *tally,
 		/* We create a temporary then renormalize so < height. */
 		/* We create a temporary then renormalize so < height. */
 		/* FIXME: Antialias properly! */
 		/* FIXME: Antialias properly! */
 		tmp = tally_new(tally->buckets);
 		tmp = tally_new(tally->buckets);
-		if (!tmp)
+		if (!tmp) {
 			return NULL;
 			return NULL;
+		}
 		tmp->min = tally->min;
 		tmp->min = tally->min;
 		tmp->max = tally->max;
 		tmp->max = tally->max;
 		tmp->step_bits = tally->step_bits;
 		tmp->step_bits = tally->step_bits;
 		memcpy(tmp->counts, tally->counts,
 		memcpy(tmp->counts, tally->counts,
 		       sizeof(tally->counts[0]) * tmp->buckets);
 		       sizeof(tally->counts[0]) * tmp->buckets);
-		while ((max_bucket = get_max_bucket(tmp)) >= height)
+		while ((max_bucket = get_max_bucket(tmp)) >= height) {
 			renormalize(tmp, tmp->min, tmp->max * 2);
 			renormalize(tmp, tmp->min, tmp->max * 2);
+		}
 		/* Restore max */
 		/* Restore max */
 		tmp->max = tally->max;
 		tmp->max = tally->max;
 		tally = tmp;
 		tally = tmp;
@@ -469,8 +471,9 @@ char *tally_histogram(const struct tally *tally,
 	/* Figure out longest line, for scale. */
 	/* Figure out longest line, for scale. */
 	largest_bucket = 0;
 	largest_bucket = 0;
 	for (i = 0; i < tally->buckets; i++) {
 	for (i = 0; i < tally->buckets; i++) {
-		if (tally->counts[i] > largest_bucket)
+		if (tally->counts[i] > largest_bucket) {
 			largest_bucket = tally->counts[i];
 			largest_bucket = tally->counts[i];
+		}
 	}
 	}
 
 
 	p = graph = (char *)malloc(height * (width + 1) + 1);
 	p = graph = (char *)malloc(height * (width + 1) + 1);
@@ -486,23 +489,26 @@ char *tally_histogram(const struct tally *tally,
 		row = height - i - 1;
 		row = height - i - 1;
 		count = (double)tally->counts[row] / largest_bucket * (width-1)+1;
 		count = (double)tally->counts[row] / largest_bucket * (width-1)+1;
 
 
-		if (row == 0)
+		if (row == 0) {
 			covered = snprintf(p, width, "%zi", tally->min);
 			covered = snprintf(p, width, "%zi", tally->min);
-		else if (row == height - 1)
+		} else if (row == height - 1) {
 			covered = snprintf(p, width, "%zi", tally->max);
 			covered = snprintf(p, width, "%zi", tally->max);
-		else if (row == bucket_of(tally->min, tally->step_bits, 0))
+		} else if (row == bucket_of(tally->min, tally->step_bits, 0)) {
 			*p = '+';
 			*p = '+';
-		else
+		} else {
 			*p = '|';
 			*p = '|';
+		}
 
 
-		if (covered > width)
+		if (covered > width) {
 			covered = width;
 			covered = width;
+		}
 		p += covered;
 		p += covered;
 
 
-		if (count > covered)
+		if (count > covered) {
 			count -= covered;
 			count -= covered;
-		else
+		} else {
 			count = 0;
 			count = 0;
+		}
 
 
 		memset(p, '*', count);
 		memset(p, '*', count);
 		p += count;
 		p += count;