4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / libexec / getty / main.c
index 4662ab6..486f44b 100644 (file)
@@ -12,23 +12,29 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     8.1 (Berkeley) %G%";
 #endif /* not lint */
 
 #define USE_OLD_TTY
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #define USE_OLD_TTY
 
 #include <sys/param.h>
-#include <sys/signal.h>
-#include <sys/file.h>
-#include <sgtty.h>
+#include <sys/stat.h>
+
+#include <ctype.h>
 #include <ctype.h>
 #include <ctype.h>
+#include <fcntl.h>
 #include <setjmp.h>
 #include <setjmp.h>
+#include <sgtty.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
 #include <syslog.h>
 #include <syslog.h>
+#include <time.h>
 #include <unistd.h>
 #include <unistd.h>
-#include <ctype.h>
-#include <string.h>
+
 #include "gettytab.h"
 #include "pathnames.h"
 #include "gettytab.h"
 #include "pathnames.h"
+#include "extern.h"
 
 struct sgttyb tmode = {
        0, 0, CERASE, CKILL, 0
 
 struct sgttyb tmode = {
        0, 0, CERASE, CKILL, 0
@@ -55,9 +61,7 @@ char  *ttyname();
 #define        TABBUFSIZ       512
 
 char   defent[TABBUFSIZ];
 #define        TABBUFSIZ       512
 
 char   defent[TABBUFSIZ];
-char   defstrs[TABBUFSIZ];
 char   tabent[TABBUFSIZ];
 char   tabent[TABBUFSIZ];
-char   tabstrs[TABBUFSIZ];
 
 char   *env[128];
 
 
 char   *env[128];
 
@@ -86,6 +90,7 @@ char partab[] = {
 
 jmp_buf timeout;
 
 
 jmp_buf timeout;
 
+static void
 dingdong()
 {
 
 dingdong()
 {
 
@@ -96,6 +101,7 @@ dingdong()
 
 jmp_buf        intrupt;
 
 
 jmp_buf        intrupt;
 
+static void
 interrupt()
 {
 
 interrupt()
 {
 
@@ -103,11 +109,20 @@ interrupt()
        longjmp(intrupt, 1);
 }
 
        longjmp(intrupt, 1);
 }
 
+static int     getname __P((void));
+static void    oflush __P((void));
+static void    prompt __P((void));
+static void    putchr __P((int));
+static void    putf __P((char *));
+static void    putpad __P((char *));
+static void    puts __P((char *));
+
+int
 main(argc, argv)
        int argc;
 main(argc, argv)
        int argc;
-       char **argv;
+       char *argv[];
 {
 {
-       extern  char **environ;
+       extern char **environ;
        char *tname;
        long allflags;
        int repcnt = 0;
        char *tname;
        long allflags;
        int repcnt = 0;
@@ -154,20 +169,20 @@ main(argc, argv)
            }
        }
 
            }
        }
 
-       gettable("default", defent, defstrs);
+       gettable("default", defent);
        gendefaults();
        tname = "default";
        if (argc > 1)
                tname = argv[1];
        for (;;) {
        gendefaults();
        tname = "default";
        if (argc > 1)
                tname = argv[1];
        for (;;) {
-               int ldisp = OTTYDISC;
-               int off = 0;
+               int off;
 
 
-               gettable(tname, tabent, tabstrs);
+               gettable(tname, tabent);
                if (OPset || EPset || APset)
                        APset++, OPset++, EPset++;
                setdefaults();
                if (OPset || EPset || APset)
                        APset++, OPset++, EPset++;
                setdefaults();
-               ioctl(0, TIOCFLUSH, 0);         /* clear out the crap */
+               off = 0;
+               ioctl(0, TIOCFLUSH, &off);      /* clear out the crap */
                ioctl(0, FIONBIO, &off);        /* turn off non-blocking mode */
                ioctl(0, FIOASYNC, &off);       /* ditto for async mode */
                if (IS)
                ioctl(0, FIONBIO, &off);        /* turn off non-blocking mode */
                ioctl(0, FIOASYNC, &off);       /* ditto for async mode */
                if (IS)
@@ -254,6 +269,7 @@ main(argc, argv)
        }
 }
 
        }
 }
 
+static int
 getname()
 {
        register int c;
 getname()
 {
        register int c;
@@ -339,6 +355,7 @@ short       tmspc10[] = {
        0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 15
 };
 
        0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 15
 };
 
+static void
 putpad(s)
        register char *s;
 {
 putpad(s)
        register char *s;
 {
@@ -380,6 +397,7 @@ putpad(s)
                putchr(*PC);
 }
 
                putchr(*PC);
 }
 
+static void
 puts(s)
        register char *s;
 {
 puts(s)
        register char *s;
 {
@@ -390,14 +408,18 @@ puts(s)
 char   outbuf[OBUFSIZ];
 int    obufcnt = 0;
 
 char   outbuf[OBUFSIZ];
 int    obufcnt = 0;
 
+static void
 putchr(cc)
 putchr(cc)
+       int 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)
        if (!UB) {
                outbuf[obufcnt++] = c;
                if (obufcnt >= OBUFSIZ)
@@ -406,6 +428,7 @@ putchr(cc)
                write(STDOUT_FILENO, &c, 1);
 }
 
                write(STDOUT_FILENO, &c, 1);
 }
 
+static void
 oflush()
 {
        if (obufcnt)
 oflush()
 {
        if (obufcnt)
@@ -413,6 +436,7 @@ oflush()
        obufcnt = 0;
 }
 
        obufcnt = 0;
 }
 
+static void
 prompt()
 {
 
 prompt()
 {
 
@@ -421,6 +445,7 @@ prompt()
                putchr('\n');
 }
 
                putchr('\n');
 }
 
+static void
 putf(cp)
        register char *cp;
 {
 putf(cp)
        register char *cp;
 {
@@ -436,7 +461,7 @@ putf(cp)
                switch (*++cp) {
 
                case 't':
                switch (*++cp) {
 
                case 't':
-                       slash = rindex(ttyn, '/');
+                       slash = strrchr(ttyn, '/');
                        if (slash == (char *) 0)
                                puts(ttyn);
                        else
                        if (slash == (char *) 0)
                                puts(ttyn);
                        else
@@ -447,12 +472,15 @@ putf(cp)
                        puts(editedhost);
                        break;
 
                        puts(editedhost);
                        break;
 
-               case 'd':
+               case 'd': {
+                       static char fmt[] = "%l:% %P on %A, %d %B %Y";
+
+                       fmt[4] = 'M';           /* I *hate* SCCS... */
                        (void)time(&t);
                        (void)time(&t);
-                       (void)strftime(db,
-                           sizeof(db), "%l:main.cP on %A, %d %B %Y", &t);
+                       (void)strftime(db, sizeof(db), fmt, localtime(&t));
                        puts(db);
                        break;
                        puts(db);
                        break;
+               }
 
                case '%':
                        putchr('%');
 
                case '%':
                        putchr('%');