- bcopy(ut->ut_line, pn->tty, UT_LINESIZE);
- pn->tty[UT_LINESIZE] = 0;
- bcopy(ut->ut_host, pn->host, UT_HOSTSIZE);
- pn->host[UT_HOSTSIZE] = 0;
- pn->loginat = (time_t)ut->ut_time;
+ register WHERE *w = walloc(pn);
+
+ w->info = LOGGEDIN;
+ bcopy(ut->ut_line, w->tty, UT_LINESIZE);
+ w->tty[UT_LINESIZE] = 0;
+ bcopy(ut->ut_host, w->host, UT_HOSTSIZE);
+ w->host[UT_HOSTSIZE] = 0;
+ w->loginat = (time_t)ut->ut_time;
+ find_idle_and_ttywrite(w);
+}
+
+PERSON *
+enter_person(pw)
+ register struct passwd *pw;
+{
+ register PERSON *pn, **pp;
+
+ for (pp = htab + hash(pw->pw_name);
+ *pp != NULL && strcmp((*pp)->name, pw->pw_name) != 0;
+ pp = &(*pp)->hlink)
+ ;
+ if ((pn = *pp) == NULL) {
+ pn = palloc();
+ entries++;
+ if (phead == NULL)
+ phead = ptail = pn;
+ else {
+ ptail->next = pn;
+ ptail = pn;
+ }
+ pn->next = NULL;
+ pn->hlink = NULL;
+ *pp = pn;
+ userinfo(pn, pw);
+ pn->whead = NULL;
+ }
+ return(pn);
+}
+
+PERSON *
+find_person(name)
+ char *name;
+{
+ register PERSON *pn;
+
+ /* name may be only UT_NAMESIZE long and not terminated */
+ for (pn = htab[hash(name)];
+ pn != NULL && strncmp(pn->name, name, UT_NAMESIZE) != 0;
+ pn = pn->hlink)
+ ;
+ return(pn);
+}
+
+hash(name)
+ register char *name;
+{
+ register int h, i;
+
+ h = 0;
+ /* name may be only UT_NAMESIZE long and not terminated */
+ for (i = UT_NAMESIZE; --i >= 0 && *name;)
+ h = ((h << 2 | h >> HBITS - 2) ^ *name++) & HMASK;
+ return(h);
+}
+
+PERSON *
+palloc()
+{
+ PERSON *p;
+
+ if ((p = (PERSON *)malloc((u_int) sizeof(PERSON))) == NULL) {
+ (void)fprintf(stderr, "finger: out of space.\n");
+ exit(1);
+ }
+ return(p);
+}
+
+WHERE *
+walloc(pn)
+ register PERSON *pn;
+{
+ register WHERE *w;
+
+ if ((w = (WHERE *)malloc((u_int) sizeof(WHERE))) == NULL) {
+ (void)fprintf(stderr, "finger: out of space.\n");
+ exit(1);
+ }
+ if (pn->whead == NULL)
+ pn->whead = pn->wtail = w;
+ else {
+ pn->wtail->next = w;
+ pn->wtail = w;
+ }
+ w->next = NULL;
+ return(w);