% diff ps.c.old ps.c
21a22,24
> #ifdef ECN
> #include <sys/file.h>
> #endif
23a27
> #ifdef ECN /* share nlist with w so keep fields same */
48a53,58
> 	{ "_swapdev" },
> #define	X_SWAPDEV	12
> 	{ "_avenrun" },
> #define	X_AVENRUN	13
> 	{ "_boottime" },
> #define	X_BOOTTIME	14
50a61,89
> #else
> struct nlist nl[] = {
> 	{ "_proc" },
> #define	X_PROC		0
> 	{ "_Usrptmap" },
> #define	X_USRPTMA	1
> 	{ "_usrpt" },
> #define	X_USRPT		2
> 	{ "_text" },
> #define	X_TEXT		3
> 	{ "_nswap" },
> #define	X_NSWAP		4
> 	{ "_maxslp" },
> #define	X_MAXSLP	5
> 	{ "_ccpu" },
> #define	X_CCPU		6
> 	{ "_ecmx" },
> #define	X_ECMX		7
> 	{ "_nproc" },
> #define	X_NPROC		8
> 	{ "_ntext" },
> #define	X_NTEXT		9
> 	{ "_dmmin" },
> #define	X_DMMIN		10
> 	{ "_dmmax" },
> #define	X_DMMAX		11
> 	{ "" },
> };
> #endif
91a131,133
> #ifdef ECN
> struct	proc proc[400];		/* 400 = a few, for less syscalls */
> #else
92a135
> #endif
106a150,153
> #ifdef ECN
> int	Rflg, Nflg, nvalue, Uflg;
> char	*mylogin, *lptr;
> #endif
139a187,189
> #ifdef ECN
> char bigoutbuf[BUFSIZ];
> #endif ECN
150a201,203
> #ifdef ECN
> 	setbuffer(stdout, bigoutbuf, BUFSIZ);
> #endif ECN
198a252,280
> #ifdef ECN
> 		case 'R':
> 			Rflg++;
> 			xflg++;
> 			gflg++;
> 			aflg++;
> 			break;
> 		case 'L':
> 			if (*ap)
> 				lptr = ap;
> 			xflg++;
> 			gflg++;
> 			while (*ap)
> 				ap++;
> 			break;
> 		case 'N':
> 			if (*ap)
> 				nvalue = atoi(ap) + 20;
> 			aflg++;
> 			gflg++;
> 			xflg++;
> 			Nflg++;
> 			while (*ap)
> 				ap++;
> 			break;
> 		case 'U':
> 			Uflg++;
> 			break;
> #endif
231a314,325
> #ifdef ECN
> 	if (lptr) {
> 		struct passwd *pw, *getpwnam();
> 		if ((pw = getpwnam(lptr)) == NULL) {
> 			fprintf(stderr, "Unknown user: %s\n", lptr);
> 			exit(1);
> 		} else {
> 			uid = pw->pw_uid;
> 		}
> 	} else
> 		uid = getuid();
> #else
232a327
> #endif ECN
236a332,334
> #ifdef ECN
> 	for (i=0; i<nproc; i += 400) {
> #else
237a336
> #endif
240,241c339,345
< 		if (j > 8)
< 			j = 8;
---
> #ifdef ECN
> 		if (j > 400)
> 			j = 400;
> #else
> 		if (j > 400)
> 			j = 400;
> #endif
252a357,367
> 			if (Rflg) {
> 				if (mproc->p_stat == SRUN)
> 					save();
> 				continue;
> 			}
> 			if (Nflg) {
> 				if ((int)mproc->p_nice >= nvalue) {
> 					save();
> 				}
> 				continue;
> 			}
358a474,490
> #ifdef ECN
> 	register int fd;
> 	if (Uflg)
> 		return;
> 	else {
> 		if (argc > 1)
> 			nlist(argv[1],nl);
> 		else {
> 			if ((fd = open("/etc/psnlist", O_RDONLY)) < 0)
> 				nlist("/vmunix", nl);
> 			else {
> 				read(fd, nl, sizeof(nl));
> 				close(fd);
> 			}
> 		}
> 	}
> #else
360a493
> #endif ECN
436a570,575
> #ifdef ECN
> #define MAXTTYS 150
> struct ttys *hash_ttys[256]; /* 256 used to find minor */
> struct ttys saved_tty_stat[MAXTTYS]; /* fixed sized used to quickly read in */
> int next_stty = 0;
> 
438a578,667
> 	register int fd;
> 
> 	if (Uflg) {
> 		if ((fd = open("/etc/psnlist", O_CREAT|O_RDWR, 0444)) >= 0) {
> 			nlist("/vmunix", nl);
> 			write(fd, nl, sizeof(nl));
> 			close(fd);
> 		} else {
> 			perror("/etc/psnlist");
> 			exit(1);
> 		}
> 		domanual();
> 		dosavettys();
> 	}
> 
> 	if ((fd = open("/etc/psdatabase", O_RDONLY)) <= 0) {
> 		domanual();
> 		return;
> 	}
> 	read(fd, hash_ttys, sizeof(hash_ttys));
> 	read(fd, saved_tty_stat, sizeof(saved_tty_stat));
> 	close(fd);
> }
> 
> dosavettys()
> {
> 	register int fd;
> 
> 	if ((fd = open("/etc/psdatabase", O_CREAT|O_RDWR, 0444)) <= 0)
> 		return;
> 	write(fd, hash_ttys, sizeof(hash_ttys));
> 	write(fd, saved_tty_stat, sizeof(saved_tty_stat));
> 	close(fd);
> 	exit(0);
> }
> 
> domanual()
> {
> 	register FILE *fp;
> 	register int i;
> 	register char c;
> 	struct stat sbuf;
> 
> 	if ((fp = fopen("/etc/ttys", "r")) == NULL) {
> 		perror("/etc/ttys");
> 		exit(1);
> 	}
> 	i = 0;
> 	while((c = getc(fp)) != EOF) {
> 		if (c == '\n') {	/* jump the first 2 chars */
> 			saved_tty_stat[next_stty].name[i] = '\0';
> 			i = 0;
> 			if (stat(saved_tty_stat[next_stty].name,&sbuf)==0 &&
> 				(sbuf.st_mode & S_IFMT) == S_IFCHR)
> 				saved_tty_stat[next_stty].ttyd = sbuf.st_rdev;
> 			else
> 				saved_tty_stat[next_stty].ttyd = -2;
> 			saved_tty_stat[next_stty].next =
> 				hash_ttys[saved_tty_stat[next_stty].ttyd % 256];
> 			hash_ttys[saved_tty_stat[next_stty].ttyd % 256] =
> 				&saved_tty_stat[next_stty];
> 			next_stty++;
> 			if ((c = getc(fp)) == EOF)
> 				return;
> 			if ((c = getc(fp)) == EOF)
> 				return;
> 		} else
> 			saved_tty_stat[next_stty].name[i++] = c;
> 	}
> }
> 
> char *
> gettty()
> {
> 	register struct ttys *dp;
> 	register char *p;
> 
> 	for(dp = hash_ttys[u.u_ttyd % 256]; dp; dp = dp->next)
> 		if (dp->ttyd == u.u_ttyd) {
> 			p = dp->name;
> 			if (p[0] == 't' && p[1] == 't' && p[2] == 'y')
> 				p += 3;
> 			return(p);
> 		}
> 	return("?");
> }
> 
> #else ECN
> getdev()
> {
596a826
> #endif ECN
1103a1334,1336
> #ifdef ECN
> 	struct passwd			*getpwuid();
> #else
1105a1339
> #endif
1118a1353,1359
> #ifdef ECN
> 	if ((pw = getpwuid(uid)) == NULL)
> 		return((char *)NULL);
> 	strncpy(n->nt_name, pw->pw_name, NMAX);
> 	n->nt_uid = uid;
> 	return(n->nt_name);
> #else
1145a1387
> #endif
