| 1 |
#!/bin/sh |
| 2 |
# $MawkId: hical,v 1.4 2009/08/21 00:36:34 tom Exp $ |
| 3 |
|
| 4 |
# @(#) hical - displays previous, current & next months - today highlighted |
| 5 |
# @(#) an "internationalizationable" version of a 3-month 'cal' display, it |
| 6 |
# @(#) may be edited for week to start with Sun or Mon & for local language |
| 7 |
|
| 8 |
prog=${TMPDIR-/tmp}/hical.$$ ; trap 'rm -f $prog ; trap 0 ; exit' 0 1 2 3 15 |
| 9 |
|
| 10 |
: ${so:=`tput smso`} ${se:=`tput rmso`} |
| 11 |
|
| 12 |
# USER EDITS MAY BE REQUIRED for the arguments to the 'date' command |
| 13 |
# the script presumes 'date' recognizes these arguments in these ways: |
| 14 |
# w - Day of the week - Sunday = 0 |
| 15 |
# m - Month of year - 01 to 12 |
| 16 |
# d - Day of month - 01 to 31 |
| 17 |
# T - Time as HH:MM:SS |
| 18 |
# Y - Year (including century), as decimal numbers |
| 19 |
DATE_ARGS='%w %m %d %T %Y' |
| 20 |
|
| 21 |
# the 'awk' program file is written to a temporary file to avoid any |
| 22 |
# "arg list too long" error messages, yet have all the code in one file. |
| 23 |
cat >$prog <<'EOF' |
| 24 |
{ |
| 25 |
# USER EDITS MAY BE REQUIRED (for FMT, day & month names, and the time stuff) |
| 26 |
# FMT = 0 # for weekdays ordered "Mo Tu We Th Fr Sa Su" |
| 27 |
FMT = 1 # for weekdays ordered "Su Mo Tu We Th Fr Sa" |
| 28 |
Header[0] = "Mo Tu We Th Fr Sa Su" |
| 29 |
Header[1] = "Su Mo Tu We Th Fr Sa" |
| 30 |
months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec" |
| 31 |
time_is = "The time is:" ; time_fmt = "%s %s %s %s\n" |
| 32 |
# NO MORE USER EDITS REQUIRED (I think!) |
| 33 |
split(months,M_Name) ; split("31 28 31 30 31 30 31 31 30 31 30 31",M_Len) |
| 34 |
daynum = $1 + FMT |
| 35 |
Mon[2] = $2 + 0 |
| 36 |
today = $3 + 0 |
| 37 |
time = $4 |
| 38 |
Year[1] = Year[2] = Year[3] = $NF |
| 39 |
if ( Mon[2] == 1 ) { Year[1] = Year[1] - 1 ; Mon[1] = 12 } |
| 40 |
else { Mon[1] = Mon[2] - 1 } |
| 41 |
if ( Mon[2] == 12 ) { Year[3] = Year[3] + 1 ; Mon[3] = 1 } |
| 42 |
else { Mon[3] = Mon[2] + 1 } |
| 43 |
if ( Year[2] % 4 == 0 && |
| 44 |
Year[2] % 100 != 0 || |
| 45 |
Year[2] % 400 == 0 ) M_Len[2] = 29 |
| 46 |
Start[2] = 7 - ( ( today - daynum ) % 7 ) |
| 47 |
Start[1] = 7 - ( ( M_Len[Mon[1]] - Start[2] ) % 7 ) |
| 48 |
Start[3] = ( M_Len[Mon[2]] + Start[2] ) % 7 |
| 49 |
for (i=1;i<=3;i++) { while ( Start[i] >= 7 ) Start[i] -= 7 } |
| 50 |
for (mm=1;mm<=3;mm++) { |
| 51 |
if ( Year[mm] != Year[mm-1] ) |
| 52 |
printf( "%s %s %s\n", so, Year[mm], se ) |
| 53 |
if ( mm == 1 ) printf( "%s %s %s\n", so, Header[FMT], se ) |
| 54 |
j = k = 1 |
| 55 |
while ( j <= M_Len[Mon[mm]] ) { |
| 56 |
line = "" |
| 57 |
for (i=1;i<=7;i++) { |
| 58 |
if ( Start[mm] > 0 || j > M_Len[Mon[mm]] ) { date = "" ; Start[mm]-- } |
| 59 |
else date = j++ |
| 60 |
if ( mm == 2 && date == today ) { So = so ; Se = se } |
| 61 |
else { So = Se = "" } |
| 62 |
line = sprintf( "%s%s%2s%s ", line, So, date, Se ) |
| 63 |
} |
| 64 |
m1 = substr(M_Name[Mon[mm]],k++,1) |
| 65 |
printf( "%s %1s %s %s%s %s\n", so, m1, se, line, so, se ) |
| 66 |
} |
| 67 |
} |
| 68 |
printf( time_fmt, so, time_is, time, se ) |
| 69 |
} |
| 70 |
EOF |
| 71 |
|
| 72 |
date +"$DATE_ARGS" | ${AWK:=mawk} -f $prog so=$so se=$se |
| 73 |
|
| 74 |
exit 0 |
| 75 |
|
| 76 |
# EOF 'hical' - Tue Dec 19 19:19:19 EST 1994 |
| 77 |
# Bob Stockler - [email protected] - CIS: 72726,452 |