svn commit: trunk/busybox/util-linux

Bernhard Fischer rep.nop at aon.at
Wed Sep 20 16:10:01 UTC 2006


Denis,

On Tue, Sep 19, 2006 at 10:40:32AM -0700, vda at busybox.net wrote:
>Author: vda
>Date: 2006-09-19 10:40:31 -0700 (Tue, 19 Sep 2006)
>New Revision: 16160
>
>Log:
>ipcs: getopt_ulflag'ification, -170 bytes
>
>
>Modified:
>   trunk/busybox/util-linux/ipcs.c
>
>
>Changeset:
>Modified: trunk/busybox/util-linux/ipcs.c
>===================================================================
>--- trunk/busybox/util-linux/ipcs.c	2006-09-19 15:16:55 UTC (rev 16159)
>+++ trunk/busybox/util-linux/ipcs.c	2006-09-19 17:40:31 UTC (rev 16160)
>@@ -570,52 +570,29 @@
> 
> int ipcs_main(int argc, char **argv)
> {
>-	int opt, id = 0;
>+	int id = 0;
> 	unsigned flags = 0;
>+	unsigned long opt;
>+	char *opt_i;
> #define flag_print	(1<<0)
> #define flag_msg	(1<<1)
> #define flag_sem	(1<<2)
> #define flag_shm	(1<<3)

These should of course be IN CAPS and before the main (my fault, i know).

>-	const char *const options = "atclupsmqi:ih?";
> 
>-	while ((opt = getopt(argc, argv, options)) != -1) {
>-		switch (opt) {
>-		case 'i':
>-			id = atoi(optarg);
>-			flags |= flag_print;
>-			break;
>-		case 'a':
>-			flags |= flag_msg | flag_sem | flag_shm;
>-			break;
>-		case 'q':
>-			flags |= flag_msg;
>-			break;
>-		case 's':
>-			flags |= flag_sem;
>-			break;
>-		case 'm':
>-			flags |= flag_shm;
>-			break;
>-		case 't':
>-			format = TIME;
>-			break;
>-		case 'c':
>-			format = CREATOR;
>-			break;
>-		case 'p':
>-			format = PID;
>-			break;
>-		case 'l':
>-			format = LIMITS;
>-			break;
>-		case 'u':
>-			format = STATUS;
>-			break;
>-		case 'h':
>-		case '?':
>-			bb_show_usage();
>-		}
>+	opt = bb_getopt_ulflags(argc, argv, "i:aqsmtcplu", &opt_i);
>+	if (opt & 0x1) { // -i
>+		id = atoi(optarg);
>+		flags |= flag_print;
> 	}
>+	if (opt & 0x2) flags |= flag_msg | flag_sem | flag_shm; // -a

Didn't look closely, but could the flags be overlayed with "opt"? Having
both flags and opt sounds a bit too much, size-wise.

Also that would eleminate the use of the ugly magic numbers below..
>+	if (opt & 0x4) flags |= flag_msg; // -q
>+	if (opt & 0x8) flags |= flag_sem; // -s
>+	if (opt & 0x10) flags |= flag_shm; // -m
>+	if (opt & 0x20) format = TIME; // -t
>+	if (opt & 0x40) format = CREATOR; // -c
>+	if (opt & 0x80) format = PID; // -p
>+	if (opt & 0x100) format = LIMITS; // -l
>+	if (opt & 0x200) format = STATUS; // -u
> 
> 	if (flags & flag_print) {
> 		if (flags & flag_shm) {



More information about the busybox mailing list