I'm not sure why cmp.c is an editor, but ok.

Turn #if ENABLE_DESKTOP preprocessor blocks into normal C code using if 
(ENABLE_DESKTOP) and let the compiler's dead code elimination drop out the 
code.

With ENABLE_DESKTOP switched off (both before and after), make bloatcheck 
reports no size change:

function                                             old     new   delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0)                 Total: 0 bytes

Posssibly for this block:

-       opt_complementary = "-1"
-                       IF_DESKTOP(":?4")
-                       IF_NOT_DESKTOP(":?2")
+       opt_complementary = "-1:?"IF_DESKTOP("4")IF_NOT_DESKTOP("2")

What we really need is some kind of IF_ELSE_DESKTOP("4","2").  It wouldn't be 
able to handle stuff with commas in it, but in cases like this it might be 
useful...

By the way, this block near the start:

/* Mar 16, 2003      Manuel Novoa III   ([email protected])
 *
 * Original version majorly reworked for SUSv3 compliance, bug fixes, and
 * size optimizations.  Changes include:
 * 1) Now correctly distinguishes between errors and actual file differences.
 * 2) Proper handling of '-' args.
 * 3) Actual error checking of i/o.
 * 4) Accept SUSv3 -l option.  Note that we use the slightly nicer gnu format
 *    in the '-l' case.
 */

Is really a repository comment, not something that belongs in the source.  
(What I'd do is have a separate commit that removes that, and the comment for 
the commit should have the complete text of the comment it's removing from the 
source.)

Denys: should I set up a git tree you can pull from for this sort of thing?  I 
vaguely plan to make some time to do random cleanups like this to get back up 
to speed on busybox development...

Rob
-- 
Latency is more important than throughput. It's that simple. - Linus Torvalds
diff --git a/editors/cmp.c b/editors/cmp.c
index 0cb80f2..591b908 100644
--- a/editors/cmp.c
+++ b/editors/cmp.c
@@ -37,8 +37,7 @@ int cmp_main(int argc UNUSED_PARAM, char **argv)
 {
 	FILE *fp1, *fp2, *outfile = stdout;
 	const char *filename1, *filename2 = "-";
-	IF_DESKTOP(off_t skip1 = 0, skip2 = 0;)
-	off_t char_pos = 0;
+	off_t skip1 = 0, skip2 = 0, char_pos = 0;
 	int line_pos = 1; /* Hopefully won't overflow... */
 	const char *fmt;
 	int c1, c2;
@@ -47,9 +46,7 @@ int cmp_main(int argc UNUSED_PARAM, char **argv)
 
 	xfunc_error_retval = 2;	/* 1 is returned if files are different. */
 
-	opt_complementary = "-1"
-			IF_DESKTOP(":?4")
-			IF_NOT_DESKTOP(":?2")
+	opt_complementary = "-1:?"IF_DESKTOP("4")IF_NOT_DESKTOP("2")
 			":l--s:s--l";
 	opt = getopt32(argv, opt_chars);
 	argv += optind;
@@ -59,14 +56,12 @@ int cmp_main(int argc UNUSED_PARAM, char **argv)
 
 	if (*++argv) {
 		filename2 = *argv;
-#if ENABLE_DESKTOP
-		if (*++argv) {
+		if (ENABLE_DESKTOP && *++argv) {
 			skip1 = XATOOFF(*argv);
 			if (*++argv) {
 				skip2 = XATOOFF(*argv);
 			}
 		}
-#endif
 	}
 
 	fp2 = xfopen_stdin(filename2);
@@ -83,10 +78,10 @@ int cmp_main(int argc UNUSED_PARAM, char **argv)
 	else
 		fmt = fmt_differ;
 
-#if ENABLE_DESKTOP
-	while (skip1) { getc(fp1); skip1--; }
-	while (skip2) { getc(fp2); skip2--; }
-#endif
+	if (ENABLE_DESKTOP) {
+		while (skip1) { getc(fp1); skip1--; }
+		while (skip2) { getc(fp2); skip2--; }
+	}
 	do {
 		c1 = getc(fp1);
 		c2 = getc(fp2);
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to