Annotation of 3BSD/cmd/wall.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <utmp.h>
        !             3: #include <time.h>
        !             4: #define        USERS   50
        !             5: 
        !             6: char   mesg[3000];
        !             7: int    msize,sline;
        !             8: struct utmp utmp[USERS];
        !             9: char   *strcpy();
        !            10: char   *strcat();
        !            11: char who[9] = "???";
        !            12: long   clock;
        !            13: struct tm *localtime();
        !            14: struct tm *localclock;
        !            15: 
        !            16: main(argc, argv)
        !            17: char *argv[];
        !            18: {
        !            19:        register i;
        !            20:        register char c;
        !            21:        register struct utmp *p;
        !            22:        FILE *f;
        !            23: 
        !            24:        if((f = fopen("/etc/utmp", "r")) == NULL) {
        !            25:                fprintf(stderr, "Cannot open /etc/utmp\n");
        !            26:                exit(1);
        !            27:        }
        !            28:        clock = time( 0 );
        !            29:        localclock = localtime( &clock );
        !            30:        fread((char *)utmp, sizeof(struct utmp), USERS, f);
        !            31:        fclose(f);
        !            32:        f = stdin;
        !            33:        if(argc >= 2) {
        !            34:                /* take message from unix file instead of standard input */
        !            35:                if((f = fopen(argv[1], "r")) == NULL) {
        !            36:                        fprintf(stderr,"Cannot open %s\n", argv[1]);
        !            37:                        exit(1);
        !            38:                }
        !            39:        }
        !            40:        while((i = getc(f)) != EOF) mesg[msize++] = i;
        !            41:        fclose(f);
        !            42:        sline = ttyslot(2); /* 'utmp' slot no. of sender */
        !            43:        if (sline) {
        !            44:                for (i=0;c=utmp[sline].ut_name[i];i++)
        !            45:                        who[i]=c;
        !            46:                who[i] = '\0'; /* sender initials */
        !            47:                }
        !            48:        for(i=0; i<USERS; i++) {
        !            49:                p = &utmp[i];
        !            50:                if(p->ut_name[0] == 0)
        !            51:                        continue;
        !            52:                sleep(1);
        !            53:                sendmes(p->ut_line);
        !            54:        }
        !            55:        exit(0);
        !            56: }
        !            57: 
        !            58: sendmes(tty)
        !            59: char *tty;
        !            60: {
        !            61:        register i;
        !            62:        char t[50], buf[BUFSIZ];
        !            63:        register char *cp;
        !            64:        register int c, ch;
        !            65:        FILE *f;
        !            66: 
        !            67:        i = fork();
        !            68:        if(i == -1) {
        !            69:                fprintf(stderr, "Try again\n");
        !            70:                return;
        !            71:        }
        !            72:        if(i)
        !            73:                return;
        !            74:        strcpy(t, "/dev/");
        !            75:        strcat(t, tty);
        !            76: 
        !            77:        if((f = fopen(t, "w")) == NULL) {
        !            78:                fprintf(stderr,"cannot open %s\n", t);
        !            79:                exit(1);
        !            80:        }
        !            81:        setbuf(f, buf);
        !            82:        fprintf(f, "\nBroadcast Message from %s (%s) at %d:%02d ...\r\n\n"
        !            83:               ,who, utmp[sline].ut_line
        !            84:               , localclock -> tm_hour , localclock -> tm_min );
        !            85:        /* fwrite(mesg, msize, 1, f); */
        !            86:        for (cp = mesg, c = msize; c-- > 0; cp++) {
        !            87:                ch = *cp;
        !            88:                if (ch == '\n')
        !            89:                        putc('\r', f);
        !            90:                putc(ch, f);
        !            91:        }
        !            92: 
        !            93:        /*
        !            94:         * Bitchin'.
        !            95:         */
        !            96: 
        !            97:        exit(0);
        !            98: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.