From fdf16eb65872b3bee02fb9e25c80ea32cf59f8e9 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Sun, 3 Jul 2011 19:43:30 +0200 Subject: Prints full community lists during 'show route all'. --- nest/a-set.c | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'nest/a-set.c') diff --git a/nest/a-set.c b/nest/a-set.c index f41b163..3cbd635 100644 --- a/nest/a-set.c +++ b/nest/a-set.c @@ -13,33 +13,53 @@ #include "lib/resource.h" #include "lib/string.h" -void -int_set_format(struct adata *set, int way, byte *buf, unsigned int size) +/** + * int_set_format - format an &set for printing + * @set: set attribute to be formatted + * @way: style of format (0 for router ID list, 1 for community list) + * @from: starting position in set + * @buf: destination buffer + * @size: size of buffer + * + * This function takes a set attribute and formats it. @way specifies + * the style of format (router ID / community). @from argument can be + * used to specify the first printed value for the purpose of printing + * untruncated sets even with smaller buffers. If the output fits in + * the buffer, 0 is returned, otherwise the position of the first not + * printed item is returned. This value can be used as @from argument + * in subsequent calls. If truncated output suffices, -1 can be + * instead used as @from, in that case " ..." is eventually added at + * the buffer to indicate truncation. + */ +int +int_set_format(struct adata *set, int way, int from, byte *buf, unsigned int size) { u32 *z = (u32 *) set->data; - int l = set->length / 4; - int sp = 1; - byte *end = buf + size - 16; + byte *end = buf + size - 24; + int to = set->length / 4; + int i; - while (l--) + for (i = MAX(from, 0); i < to; i++) { - if (!sp) - *buf++ = ' '; if (buf > end) { - strcpy(buf, "..."); - return; + if (from < 0) + strcpy(buf, " ..."); + else + *buf = 0; + return i; } + if (i > from) + *buf++ = ' '; + if (way) - buf += bsprintf(buf, "(%d,%d)", *z >> 16, *z & 0xffff); + buf += bsprintf(buf, "(%d,%d)", z[i] >> 16, z[i] & 0xffff); else - buf += bsprintf(buf, "%R", *z); - - z++; - sp = 0; + buf += bsprintf(buf, "%R", z[i]); } *buf = 0; + return 0; } int -- cgit v1.2.3