Subject: Re: #ifdef CRAY in libexec/telnetd
To: None <tech-userlevel@netbsd.org>
From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
List: tech-userlevel
Date: 07/14/2003 05:00:00
>> 	even though, those #ifdef (convex, CRAY, SOLARIS, ...) degrades
>> 	readability and auditability seriously.
>I've believed for a long time that a standard part of our import
>process for certain programs should be running them through unifdef
>before importing them into the vendor branch.  Telnet was, in fact, the
>first one that made me think this would be a good idea...

	for instance, if we unifdef usr.bin/telnet/command.c, we can get this
	much of simplification.

itojun


Index: commands.c
===================================================================
RCS file: /cvsroot/src/usr.bin/telnet/commands.c,v
retrieving revision 1.53
diff -u -1 -r1.53 commands.c
--- commands.c	2003/07/12 14:29:35	1.53
+++ commands.c	2003/07/13 19:56:17
@@ -73,11 +73,4 @@
 
-#if	defined(unix)
 #include <sys/param.h>
-#if	defined(CRAY) || defined(sysV88)
-#include <sys/types.h>
-#endif
 #include <sys/file.h>
-#else
-#include <sys/types.h>
-#endif	/* defined(unix) */
 #include <sys/wait.h>
@@ -86,5 +79,2 @@
 #include <arpa/inet.h>
-#ifdef	CRAY
-#include <fcntl.h>
-#endif	/* CRAY */
 
@@ -115,8 +105,3 @@
 
-#if !defined(CRAY) && !defined(sysV88)
 #include <netinet/in_systm.h>
-# if (defined(vax) || defined(tahoe) || defined(hp300)) && !defined(ultrix)
-# include <machine/endian.h>
-# endif /* vax */
-#endif /* !defined(CRAY) && !defined(sysV88) */
 #include <netinet/ip.h>
@@ -187,5 +172,2 @@
 #endif
-#if	defined(unix) && defined(TN3270)
-static void filestuff(int);
-#endif
 static int status(int, char *[]);
@@ -563,3 +545,2 @@
 {
-#ifndef	NOT43
     if (net > 0 &&
@@ -568,9 +549,2 @@
     }
-#else	/* NOT43 */
-    if (debug) {
-	if (net > 0 && SetSockOpt(net, SOL_SOCKET, SO_DEBUG, 1) < 0)
-	    perror("setsockopt (SO_DEBUG)");
-    } else
-	printf("Cannot turn off socket debugging\n");
-#endif	/* NOT43 */
     return 1;
@@ -779,14 +753,2 @@
     { " ", "", 0 },		/* empty line */
-#if	defined(unix) && defined(TN3270)
-    { "apitrace",
-	"(debugging) toggle tracing of API transactions",
-	    0,
-		&apitrace,
-		    "trace API transactions" },
-    { "cursesdata",
-	"(debugging) toggle printing of hexadecimal curses data",
-	    0,
-		&cursesdata,
-		    "print hexadecimal representation of curses data" },
-#endif	/* defined(unix) && defined(TN3270) */
     { "debug",
@@ -811,3 +773,2 @@
 		    "show option processing" },
-#if	defined(unix)
     { "termdata",
@@ -817,3 +778,2 @@
 		    "print hexadecimal representation of terminal traffic" },
-#endif	/* defined(unix) */
     { "?",
@@ -909,5 +869,3 @@
 
-#ifdef	USE_TERMIO
 struct termio new_tc = { 0 };
-#endif
 
@@ -921,5 +879,3 @@
 static struct setlist Setlist[] = {
-#ifdef	KLUDGELINEMODE
     { "echo", 	"character to toggle local echoing on/off", 0, &echoc },
-#endif
     { "escape",	"character to escape back to telnet command mode", 0, &escape },
@@ -1105,3 +1061,2 @@
  */
-#ifdef	KLUDGELINEMODE
 extern int kludgelinemode;
@@ -1117,3 +1072,2 @@
 }
-#endif
 
@@ -1122,6 +1076,4 @@
 {
-#ifdef	KLUDGELINEMODE
     if (kludgelinemode)
 	send_dont(TELOPT_SGA, 1);
-#endif
     send_will(TELOPT_LINEMODE, 1);
@@ -1134,3 +1086,2 @@
 {
-#ifdef	KLUDGELINEMODE
     if (kludgelinemode)
@@ -1138,3 +1089,2 @@
     else
-#endif
     send_wont(TELOPT_LINEMODE, 1);
@@ -1187,9 +1137,5 @@
     { "character", "Disable LINEMODE option",	docharmode, 1 },
-#ifdef	KLUDGELINEMODE
     { "",	"(or disable obsolete line-by-line mode)", 0 },
-#endif
     { "line",	"Enable LINEMODE option",	dolinemode, 1 },
-#ifdef	KLUDGELINEMODE
     { "",	"(or enable obsolete line-by-line mode)", 0 },
-#endif
     { "", "", 0 },
@@ -1209,5 +1155,3 @@
     { "help",	0,				modehelp, 0 },
-#ifdef	KLUDGELINEMODE
     { "kludgeline", 0,				dokludgemode, 1 },
-#endif
     { "", "", 0 },
@@ -1373,3 +1317,2 @@
 {
-#ifdef	SIGTSTP
     setcommandmode();
@@ -1393,5 +1336,2 @@
     setconnmode(0);
-#else
-    printf("Suspend is not supported.  Try the '!' command instead\n");
-#endif
     return 1;
@@ -1399,3 +1339,2 @@
 
-#if	!defined(TN3270)
 /*ARGSUSED*/
@@ -1450,3 +1389,2 @@
 }
-#endif	/* !defined(TN3270) */
 
@@ -1469,5 +1407,2 @@
 	tninit();
-#if	defined(TN3270)
-	SetIn3270();		/* Get out of 3270 mode */
-#endif	/* defined(TN3270) */
     }
@@ -1593,6 +1528,2 @@
 						env_list,	0 },
-#if defined(OLD_ENVIRON) && defined(ENV_HACK)
-    { "varval", "Reverse VAR and VALUE (auto, right, wrong, status)",
-						env_varval,    1 },
-#endif
     { "help",	0,				env_help,		0 },
@@ -1795,7 +1726,3 @@
 
-	if (my_state_is_wont(TELOPT_NEW_ENVIRON)
-#ifdef	OLD_ENVIRON
-	    && my_state_is_wont(TELOPT_OLD_ENVIRON)
-#endif
-		) {
+	if (my_state_is_wont(TELOPT_NEW_ENVIRON)) {
 		fprintf(stderr,
@@ -1857,39 +1784,2 @@
 
-#if defined(OLD_ENVIRON) && defined(ENV_HACK)
-void
-env_varval(unsigned char *what)
-{
-	extern int old_env_var, old_env_value, env_auto;
-	int len = strlen((char *)what);
-
-	if (len == 0)
-		goto unknown;
-
-	if (strncasecmp((char *)what, "status", len) == 0) {
-		if (env_auto)
-			printf("%s%s", "VAR and VALUE are/will be ",
-					"determined automatically\n");
-		if (old_env_var == OLD_ENV_VAR)
-			printf("VAR and VALUE set to correct definitions\n");
-		else
-			printf("VAR and VALUE definitions are reversed\n");
-	} else if (strncasecmp((char *)what, "auto", len) == 0) {
-		env_auto = 1;
-		old_env_var = OLD_ENV_VALUE;
-		old_env_value = OLD_ENV_VAR;
-	} else if (strncasecmp((char *)what, "right", len) == 0) {
-		env_auto = 0;
-		old_env_var = OLD_ENV_VAR;
-		old_env_value = OLD_ENV_VALUE;
-	} else if (strncasecmp((char *)what, "wrong", len) == 0) {
-		env_auto = 0;
-		old_env_var = OLD_ENV_VALUE;
-		old_env_value = OLD_ENV_VAR;
-	} else {
-unknown:
-		printf("Unknown \"varval\" command. (\"auto\", \"right\", \"wrong\", \"status\")\n");
-	}
-}
-#endif
-
 #if	defined(AUTHENTICATION)
@@ -2082,34 +1972,2 @@
 
-#if	defined(unix) && defined(TN3270)
-static void
-filestuff(int fd)
-{
-    int res;
-
-#ifdef	F_GETOWN
-    setconnmode(0);
-    res = fcntl(fd, F_GETOWN, 0);
-    setcommandmode();
-
-    if (res == -1) {
-	perror("fcntl");
-	return;
-    }
-    printf("\tOwner is %d.\n", res);
-#endif
-
-    setconnmode(0);
-    res = fcntl(fd, F_GETFL, 0);
-    setcommandmode();
-
-    if (res == -1) {
-	perror("fcntl");
-	return;
-    }
-#ifdef notdef
-    printf("\tFlags are 0x%x: %s\n", res, decodeflags(res));
-#endif
-}
-#endif /* defined(unix) && defined(TN3270) */
-
 /*
@@ -2132,6 +1990,4 @@
 		slcstate();
-#ifdef	KLUDGELINEMODE
 	    } else if (kludgelinemode && my_want_state_is_dont(TELOPT_SGA)) {
 		printf("Operating in obsolete linemode\n");
-#endif
 	    } else {
@@ -2151,33 +2007,4 @@
     }
-#   if !defined(TN3270)
     printf("Escape character is '%s'.\n", control(escape));
     (void) fflush(stdout);
-#   else /* !defined(TN3270) */
-    if ((!In3270) && ((argc < 2) || strcmp(argv[1], "notmuch"))) {
-	printf("Escape character is '%s'.\n", control(escape));
-    }
-#   if defined(unix)
-    if ((argc >= 2) && !strcmp(argv[1], "everything")) {
-	printf("SIGIO received %d time%s.\n",
-				sigiocount, (sigiocount == 1)? "":"s");
-	if (In3270) {
-	    printf("Process ID %d, process group %d.\n",
-					    getpid(), getpgrp());
-	    printf("Terminal input:\n");
-	    filestuff(tin);
-	    printf("Terminal output:\n");
-	    filestuff(tout);
-	    printf("Network socket:\n");
-	    filestuff(net);
-	}
-    }
-    if (In3270 && transcom) {
-	printf("Transparent mode command is '%s'.\n", transcom);
-    }
-#   endif /* defined(unix) */
-    (void) fflush(stdout);
-    if (In3270) {
-	return 0;
-    }
-#   endif /* defined(TN3270) */
     return 1;
@@ -2185,3 +2012,2 @@
 
-#ifdef	SIGINFO
 /*
@@ -2194,3 +2020,2 @@
 }
-#endif
 
@@ -2200,7 +2025,3 @@
     static char addrbuf[NI_MAXHOST];
-#ifdef NI_WITHSCOPEID
-    const int niflags = NI_NUMERICHOST | NI_WITHSCOPEID;
-#else
     const int niflags = NI_NUMERICHOST;
-#endif
 
@@ -2471,5 +2292,2 @@
 	displayhelp[] =	"display operating parameters",
-#if	defined(TN3270) && defined(unix)
-	transcomhelp[] = "specify Unix command for transparent mode pipe",
-#endif	/* defined(TN3270) && defined(unix) */
 #if	defined(AUTHENTICATION)
@@ -2480,5 +2298,3 @@
 #endif	/* ENCRYPTION */
-#if	defined(unix)
 	zhelp[] =	"suspend telnet",
-#endif	/* defined(unix) */
 	shellhelp[] =	"invoke a subshell",
@@ -2500,5 +2316,2 @@
 	{ "slc",	slchelp,	slccmd,		0 },
-#if	defined(TN3270) && defined(unix)
-	{ "transcom",	transcomhelp,	settranscom,	0 },
-#endif	/* defined(TN3270) && defined(unix) */
 #if	defined(AUTHENTICATION)
@@ -2509,10 +2322,4 @@
 #endif
-#if	defined(unix)
 	{ "z",		zhelp,		suspend,	0 },
-#endif	/* defined(unix) */
-#if	defined(TN3270)
-	{ "!",		shellhelp,	shell,		1 },
-#else
 	{ "!",		shellhelp,	shell,		0 },
-#endif
 	{ "environ",	envhelp,	env_cmd,	0 },
@@ -2572,3 +2379,2 @@
 	putchar('\n');
-#if	defined(unix)
     } else {
@@ -2576,3 +2382,2 @@
 	(void) signal(SIGQUIT, SIG_DFL);
-#endif	/* defined(unix) */
     }
@@ -2596,5 +2401,2 @@
 		printf("%s> ", prompt);
-#if defined(TN3270)
-	    fflush(stdout);
-#endif
 	    if (fgets(line, sizeof(line), stdin) == NULL) {
@@ -2635,9 +2437,3 @@
 	}
-#if	defined(TN3270)
-	if (shell_active == 0) {
-	    setconnmode(0);
-	}
-#else	/* defined(TN3270) */
 	setconnmode(0);
-#endif	/* defined(TN3270) */
     }
@@ -2807,5 +2603,2 @@
 {
-#ifdef	sysV88
-	static IOPTN ipopt;
-#endif
 	char *cp, *cp2, *lsrp, *lsrep;
@@ -2849,3 +2642,2 @@
 		 */
-#ifndef	sysV88
 		if (*cp == '!') {
@@ -2855,15 +2647,6 @@
 			*lsrp++ = IPOPT_LSRR;
-#else
-		if (*cp == '!') {
-			cp++;
-			ipopt.io_type = IPOPT_SSRR;
-		} else
-			ipopt.io_type = IPOPT_LSRR;
-#endif
 		if (*cp != '@')
 			return -1;
-#ifndef	sysV88
 		lsrp++;		/* skip over length, we'll fill it in later */
 		*lsrp++ = 4;
-#endif
 		cp++;
@@ -2958,3 +2741,2 @@
 		lsrp += sizeof(struct in_addr);
-#ifndef	sysV88
 		lsr[IPOPT_OLEN] = lsrp - lsr;
@@ -2965,8 +2747,2 @@
 		*cpp = lsr;
-#else
-		ipopt.io_len = lsrp - lsr;
-		if (ipopt.io_len <= 5)	/*is 3 better?*/
-			return -1;
-		*cpp = (char 8)&ipopt;
-#endif
 	}