BSD 4_3_Net_2 release
[unix-history] / usr / src / libexec / getty / main.c
index 11dfc24..e95bdb1 100644 (file)
@@ -1,39 +1,64 @@
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1980 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
 char copyright[] =
  */
 
 #ifndef lint
 char copyright[] =
-"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+"@(#) Copyright (c) 1980 The Regents of the University of California.\n\
  All rights reserved.\n";
  All rights reserved.\n";
-#endif not lint
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.11 (Berkeley) 6/29/90";
-#endif not lint
-
-/*
- * getty -- adapt to terminal speed on dialup, and call login
- *
- * Melbourne getty, June 83, kre.
- */
+static char sccsid[] = "@(#)main.c     5.16 (Berkeley) 3/27/91";
+#endif /* not lint */
 
 #define USE_OLD_TTY
 
 #define USE_OLD_TTY
+
 #include <sys/param.h>
 #include <sys/param.h>
-#include <sys/signal.h>
-#include <sys/file.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <fcntl.h>
 #include <sgtty.h>
 #include <sgtty.h>
+#include <time.h>
 #include <ctype.h>
 #include <setjmp.h>
 #include <syslog.h>
 #include <ctype.h>
 #include <setjmp.h>
 #include <syslog.h>
+#include <unistd.h>
 #include <ctype.h>
 #include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
 #include "gettytab.h"
 #include "pathnames.h"
 
 #include "gettytab.h"
 #include "pathnames.h"
 
-extern char **environ;
-
 struct sgttyb tmode = {
        0, 0, CERASE, CKILL, 0
 };
 struct sgttyb tmode = {
        0, 0, CERASE, CKILL, 0
 };
@@ -46,10 +71,7 @@ struct       ltchars ltc = {
        CFLUSH, CWERASE, CLNEXT
 };
 
        CFLUSH, CWERASE, CLNEXT
 };
 
-int    crmod;
-int    upper;
-int    lower;
-int    digit;
+int crmod, digit, lower, upper;
 
 char   hostname[MAXHOSTNAMELEN];
 char   name[16];
 
 char   hostname[MAXHOSTNAMELEN];
 char   name[16];
@@ -93,6 +115,7 @@ char partab[] = {
 
 jmp_buf timeout;
 
 
 jmp_buf timeout;
 
+static void
 dingdong()
 {
 
 dingdong()
 {
 
@@ -103,6 +126,7 @@ dingdong()
 
 jmp_buf        intrupt;
 
 
 jmp_buf        intrupt;
 
+static void
 interrupt()
 {
 
 interrupt()
 {
 
@@ -111,8 +135,10 @@ interrupt()
 }
 
 main(argc, argv)
 }
 
 main(argc, argv)
-       char *argv[];
+       int argc;
+       char **argv;
 {
 {
+       extern  char **environ;
        char *tname;
        long allflags;
        int repcnt = 0;
        char *tname;
        long allflags;
        int repcnt = 0;
@@ -174,7 +200,7 @@ main(argc, argv)
                setdefaults();
                ioctl(0, TIOCFLUSH, 0);         /* clear out the crap */
                ioctl(0, FIONBIO, &off);        /* turn off non-blocking mode */
                setdefaults();
                ioctl(0, TIOCFLUSH, 0);         /* clear out the crap */
                ioctl(0, FIONBIO, &off);        /* turn off non-blocking mode */
-               ioctl(0, FIOASYNC, &off);       /* ditto for asynchronous mode */
+               ioctl(0, FIOASYNC, &off);       /* ditto for async mode */
                if (IS)
                        tmode.sg_ispeed = speed(IS);
                else if (SP)
                if (IS)
                        tmode.sg_ispeed = speed(IS);
                else if (SP)
@@ -261,8 +287,8 @@ main(argc, argv)
 
 getname()
 {
 
 getname()
 {
+       register int c;
        register char *np;
        register char *np;
-       register c;
        char cs;
 
        /*
        char cs;
 
        /*
@@ -283,14 +309,11 @@ getname()
                PF = 0;
        }
        ioctl(0, TIOCSETP, &tmode);
                PF = 0;
        }
        ioctl(0, TIOCSETP, &tmode);
-       crmod = 0;
-       upper = 0;
-       lower = 0;
-       digit = 0;
+       crmod = digit = lower = upper = 0;
        np = name;
        for (;;) {
                oflush();
        np = name;
        for (;;) {
                oflush();
-               if (read(0, &cs, 1) <= 0)
+               if (read(STDIN_FILENO, &cs, 1) <= 0)
                        exit(0);
                if ((c = cs&0177) == 0)
                        return (0);
                        exit(0);
                if ((c = cs&0177) == 0)
                        return (0);
@@ -301,9 +324,9 @@ getname()
                        break;
                }
                if (islower(c))
                        break;
                }
                if (islower(c))
-                       lower++;
+                       lower = 1;
                else if (isupper(c))
                else if (isupper(c))
-                       upper++;
+                       upper = 1;
                else if (c == ERASE || c == '#' || c == '\b') {
                        if (np > name) {
                                np--;
                else if (c == ERASE || c == '#' || c == '\b') {
                        if (np > name) {
                                np--;
@@ -334,7 +357,7 @@ getname()
        signal(SIGINT, SIG_IGN);
        *np = 0;
        if (c == '\r')
        signal(SIGINT, SIG_IGN);
        *np = 0;
        if (c == '\r')
-               crmod++;
+               crmod = 1;
        if (upper && !lower && !LC || UC)
                for (np = name; *np; np++)
                        if (isupper(*np))
        if (upper && !lower && !LC || UC)
                for (np = name; *np; np++)
                        if (isupper(*np))
@@ -377,11 +400,10 @@ putpad(s)
                return;
 
        /*
                return;
 
        /*
-        * Round up by a half a character frame,
-        * and then do the delay.
+        * Round up by a half a character frame, and then do the delay.
         * Too bad there are no user program accessible programmed delays.
         * Too bad there are no user program accessible programmed delays.
-        * Transmitting pad characters slows many
-        * terminals down and also loads the system.
+        * Transmitting pad characters slows many terminals down and also
+        * loads the system.
         */
        mspc10 = tmspc10[tmode.sg_ospeed];
        pad += mspc10 / 2;
         */
        mspc10 = tmspc10[tmode.sg_ospeed];
        pad += mspc10 / 2;
@@ -392,7 +414,6 @@ putpad(s)
 puts(s)
        register char *s;
 {
 puts(s)
        register char *s;
 {
-
        while (*s)
                putchr(*s++);
 }
        while (*s)
                putchr(*s++);
 }
@@ -405,21 +426,23 @@ putchr(cc)
        char c;
 
        c = cc;
        char c;
 
        c = cc;
-       c |= partab[c&0177] & 0200;
-       if (OP)
-               c ^= 0200;
+       if (!NP) {
+               c |= partab[c&0177] & 0200;
+               if (OP)
+                       c ^= 0200;
+       }
        if (!UB) {
                outbuf[obufcnt++] = c;
                if (obufcnt >= OBUFSIZ)
                        oflush();
        } else
        if (!UB) {
                outbuf[obufcnt++] = c;
                if (obufcnt >= OBUFSIZ)
                        oflush();
        } else
-               write(1, &c, 1);
+               write(STDOUT_FILENO, &c, 1);
 }
 
 oflush()
 {
        if (obufcnt)
 }
 
 oflush()
 {
        if (obufcnt)
-               write(1, outbuf, obufcnt);
+               write(STDOUT_FILENO, outbuf, obufcnt);
        obufcnt = 0;
 }
 
        obufcnt = 0;
 }
 
@@ -434,10 +457,9 @@ prompt()
 putf(cp)
        register char *cp;
 {
 putf(cp)
        register char *cp;
 {
-       char *slash;
-       char datebuffer[60];
        extern char editedhost[];
        extern char editedhost[];
-       extern char *rindex();
+       time_t t;
+       char *slash, db[100];
 
        while (*cp) {
                if (*cp != '%') {
 
        while (*cp) {
                if (*cp != '%') {
@@ -458,10 +480,15 @@ putf(cp)
                        puts(editedhost);
                        break;
 
                        puts(editedhost);
                        break;
 
-               case 'd':
-                       get_date(datebuffer);
-                       puts(datebuffer);
+               case 'd': {
+                       static char fmt[] = "%l:% %P on %A, %d %B %Y";
+
+                       fmt[4] = 'M';           /* I *hate* SCCS... */
+                       (void)time(&t);
+                       (void)strftime(db, sizeof(db), fmt, localtime(&t));
+                       puts(db);
                        break;
                        break;
+               }
 
                case '%':
                        putchr('%');
 
                case '%':
                        putchr('%');