Natanael Copa
Thu, 05 Jun 2008 04:55:22 -0700
On Wed, 2008-06-04 at 22:06 +0200, Bernhard Fischer wrote: > On Wed, Jun 04, 2008 at 08:29:56PM +0200, Natanael Copa wrote: > > Hi, > > > > Attatched is a patch for the LOWER_UP flag in 'ip link/addr' output. > > Useful to check if network cable is inserted or not. > > > > The code does an ugly ifdef to check if IFF_LOWER_UP is declared or not. > > On my zenwalk desktop it was not. It looks like iproute2 maintain their > > own copies of the linux headers so I suppose we cannot expect the flag > > be there. (should mabe be in one of the include files rather than in the > > .c file?) > > > > The patch does increase the size a bit due to a macro. Maybe should have > > a config option for it? > > no config, no. > > I was about to apply it but looking at the macro i'd be curious if we > have more occurances of the > if (foo & flag) > emit(#flag) > pattern so we should provide something like the reversed form of > index_in_strings() like string_in_index(int state) that emits the > corresponding string?
maybe string_in_mask()/string_in_flags()?
> Could you try that and convert some users to that scheme? I'd be
> surprised if this would not be an overall win.
I think that we maybe want something like this:
struct mask_string {
int mask;
const char *string;
}
void print_flags(struct mask_string* ms, int flags, const char *separator)
{
int need_separator = 0;
while (ms) {
if (flags, ms->mask) {
printf("%s%s", need_separator ? separator : "",
ms->string)
need_separator = 1;
}
ms++;
}
}
I checked and atleast the following files would benefit from something like
that:
./miscutils/hdparm.c:1231: if (id->eide_pio_modes & 1)
printf("pio3 ");
...
./networking/arp.c:336: if (arp_flags & ATF_PERM)
./networking/arp.c:337: printf("PERM ");
./networking/arp.c:338: if (arp_flags & ATF_PUBL)
./networking/arp.c:339: printf("PUP ");
...
./util-linux/fdisk_osf.c:517: if (lp->d_flags & BSD_D_REMOVABLE)
./util-linux/fdisk_osf.c:518: printf(" removable");
./util-linux/fdisk_osf.c:519: if (lp->d_flags & BSD_D_ECC)
./util-linux/fdisk_osf.c:520: printf(" ecc");
...
-nc
_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox