|
|
1.1 ! root 1: /*- ! 2: * Copyright (c) 1990 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)attime.c 5.1 (Berkeley) 5/4/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include <sys/types.h> ! 25: #include <sys/time.h> ! 26: #include <stdio.h> ! 27: ! 28: #define HR (60 * 60) ! 29: #define DAY (24 * HR) ! 30: #define MON (30 * DAY) ! 31: ! 32: static time_t now; ! 33: /* ! 34: * prttime prints a time in hours and minutes or minutes and seconds. ! 35: * The character string tail is printed at the end, obvious ! 36: * strings to pass are "", " ", or "am". ! 37: */ ! 38: static char * ! 39: prttime(tim, tail) ! 40: time_t tim; ! 41: char *tail; ! 42: { ! 43: static char timebuf[32], *cp; ! 44: ! 45: if (tim >= 60) { ! 46: int mins = tim % 60; ! 47: sprintf(timebuf, "%2d:%02d", tim/60, mins); ! 48: } else if (tim >= 0) ! 49: sprintf(timebuf, " %2d", tim); ! 50: cp = timebuf; ! 51: while (*cp) ! 52: cp++; ! 53: sprintf(cp, "%s", tail); ! 54: ! 55: return (timebuf); ! 56: } ! 57: ! 58: static char *weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; ! 59: static char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", ! 60: "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; ! 61: ! 62: /* prtat prints a 12 hour time given a pointer to a time of day */ ! 63: char * ! 64: attime(started) ! 65: long *started; ! 66: { ! 67: struct tm *p; ! 68: register int hr, pm; ! 69: static char prbuff[64]; ! 70: ! 71: if (now == 0) ! 72: time(&now); ! 73: p = localtime(started); ! 74: hr = p->tm_hour; ! 75: pm = (hr > 11); ! 76: if (hr > 11) ! 77: hr -= 12; ! 78: if (hr == 0) ! 79: hr = 12; ! 80: if (now - *started <= 18 * HR) ! 81: return (prttime(hr * 60 + p->tm_min, pm ? "pm" : "am")); ! 82: else if (now - *started <= 7 * DAY) ! 83: sprintf(prbuff, "%*s%d%s", hr < 10 ? 4 : 3, ! 84: weekday[p->tm_wday], hr, pm ? "pm" : "am"); ! 85: else ! 86: sprintf(prbuff, "%2d%s%2d", p->tm_mday, month[p->tm_mon], ! 87: p->tm_year); ! 88: ! 89: return (prbuff); ! 90: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.