Annotation of 43BSDReno/usr.bin/finger/sprint.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1989 The Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * This code is derived from software contributed to Berkeley by
        !             6:  * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms are permitted provided
        !             9:  * that: (1) source distributions retain this entire copyright notice and
        !            10:  * comment, and (2) distributions including binaries display the following
        !            11:  * acknowledgement:  ``This product includes software developed by the
        !            12:  * University of California, Berkeley and its contributors'' in the
        !            13:  * documentation or other materials provided with the distribution and in
        !            14:  * all advertising materials mentioning features or use of this software.
        !            15:  * Neither the name of the University nor the names of its contributors may
        !            16:  * be used to endorse or promote products derived from this software without
        !            17:  * specific prior written permission.
        !            18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            19:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            20:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            21:  */
        !            22: 
        !            23: #ifndef lint
        !            24: static char sccsid[] = "@(#)sprint.c   5.7 (Berkeley) 6/1/90";
        !            25: #endif /* not lint */
        !            26: 
        !            27: #include <sys/types.h>
        !            28: #include <sys/time.h>
        !            29: #include <tzfile.h>
        !            30: #include <stdio.h>
        !            31: #include "finger.h"
        !            32: 
        !            33: extern int entries;
        !            34: 
        !            35: sflag_print()
        !            36: {
        !            37:        extern time_t now;
        !            38:        register PERSON *pn;
        !            39:        register WHERE *w;
        !            40:        register int cnt;
        !            41:        register char *p;
        !            42:        PERSON **list, **sort();
        !            43:        time_t time();
        !            44:        char *ctime(), *prphone();
        !            45: 
        !            46:        list = sort();
        !            47:        /*
        !            48:         * short format --
        !            49:         *      login name
        !            50:         *      real name
        !            51:         *      terminal name (the XX of ttyXX)
        !            52:         *      if terminal writeable (add an '*' to the terminal name
        !            53:         *              if not)
        !            54:         *      if logged in show idle time and day logged in, else
        !            55:         *              show last login date and time.  If > 6 moths,
        !            56:         *              show year instead of time.
        !            57:         *      office location
        !            58:         *      office phone
        !            59:         */
        !            60: #define        MAXREALNAME     20
        !            61:        (void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
        !            62:            "Name", "Tty  Idle  Login        Office     Office Phone");
        !            63:        for (cnt = 0; cnt < entries; ++cnt) {
        !            64:                pn = list[cnt];
        !            65:                for (w = pn->whead; w != NULL; w = w->next) {
        !            66:                        (void)printf("%-*.*s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE,
        !            67:                            pn->name, MAXREALNAME, MAXREALNAME,
        !            68:                            pn->realname ? pn->realname : "");
        !            69:                        if (!w->loginat) {
        !            70:                                (void)printf("  *     *  No logins   ");
        !            71:                                goto office;
        !            72:                        }
        !            73:                        (void)putchar(w->info == LOGGEDIN && !w->writable ?
        !            74:                            '*' : ' ');
        !            75:                        if (*w->tty)
        !            76:                                (void)printf("%-2.2s ",
        !            77:                                    w->tty[0] != 't' || w->tty[1] != 't' ||
        !            78:                                    w->tty[2] != 'y' ? w->tty : w->tty + 3);
        !            79:                        else
        !            80:                                (void)printf("   ");
        !            81:                        if (w->info == LOGGEDIN) {
        !            82:                                stimeprint(w);
        !            83:                                (void)printf("  ");
        !            84:                        } else
        !            85:                                (void)printf("    *  ");
        !            86:                        p = ctime(&w->loginat);
        !            87:                        (void)printf("%.6s", p + 4);
        !            88:                        if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2)
        !            89:                                (void)printf("  %.4s", p + 20);
        !            90:                        else
        !            91:                                (void)printf(" %.5s", p + 11);
        !            92: office:                        if (pn->office)
        !            93:                                (void)printf(" %-10.10s", pn->office);
        !            94:                        else if (pn->officephone)
        !            95:                                (void)printf(" %-10.10s", " ");
        !            96:                        if (pn->officephone)
        !            97:                                (void)printf(" %-.15s",
        !            98:                                    prphone(pn->officephone));
        !            99:                        putchar('\n');
        !           100:                }
        !           101:        }
        !           102: }
        !           103: 
        !           104: PERSON **
        !           105: sort()
        !           106: {
        !           107:        register PERSON *pn, **lp;
        !           108:        PERSON **list;
        !           109:        int psort();
        !           110:        char *malloc();
        !           111: 
        !           112:        if (!(list = (PERSON **)malloc((u_int)(entries * sizeof(PERSON *))))) {
        !           113:                (void)fprintf(stderr, "finger: out of space.\n");
        !           114:                exit(1);
        !           115:        }
        !           116:        for (lp = list, pn = phead; pn != NULL; pn = pn->next)
        !           117:                *lp++ = pn;
        !           118:        (void)qsort(list, entries, sizeof(PERSON *), psort);
        !           119:        return(list);
        !           120: }
        !           121: 
        !           122: psort(p, t)
        !           123:        PERSON **p, **t;
        !           124: {
        !           125:        return(strcmp((*p)->name, (*t)->name));
        !           126: }
        !           127: 
        !           128: stimeprint(w)
        !           129:        WHERE *w;
        !           130: {
        !           131:        register struct tm *delta;
        !           132: 
        !           133:        delta = gmtime(&w->idletime);
        !           134:        if (!delta->tm_yday)
        !           135:                if (!delta->tm_hour)
        !           136:                        if (!delta->tm_min)
        !           137:                                (void)printf("     ");
        !           138:                        else
        !           139:                                (void)printf("%5d", delta->tm_min);
        !           140:                else
        !           141:                        (void)printf("%2d:%02d",
        !           142:                            delta->tm_hour, delta->tm_min);
        !           143:        else
        !           144:                (void)printf("%4dd", delta->tm_yday);
        !           145: }

unix.superglobalmegacorp.com

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