#!/bin/sh # @(#) Revision 1.2 - 07/30/97 # textcal # # Usage: textcal [month year [dir]] # # textcal takes the output of cal and makes a bigger calendar (with 10x5 # squares). If you give it a 3rd optional parameter (directory), it will # look for files corresponding to days (e.g. file named 01, 02, etc.) in # this directory. For each day it is printing on the calendar, it checks # this file and prints the contents in the day square. (Since there are # only 5 lines in a square and 1 line contains the day and julian day numbers, # there is only room for 4 (10 character) lines to print in the day square.) # # ============================================================================= # Andrea Whitlock, Mobius Software Services # whitlock@mobius-soft.com # # Bug reports, questions, and suggestions should be emailed to: # mobius@mobius-soft.com # # This software is provided under the terms of the GNU copyleft # (ftp://prep.ai.mit.edu/pub/gnu/COPYING-2.0), without a warranty # of any kind. Use at your own risk. # ============================================================================= # # configure me ################################################################ # # part 1 # # your awk needs to support the use of getline in the following fashion: # while (getline bannerout < (file) > 0) { # #AWK=awk #AWK=gawk AWK=nawk # # part 2 # BANNER=/usr/bin/banner #BANNER=/usr/bin/sysvbanner # # part 3 # #PRINTJULIANDATE="yes" PRINTJULIANDATE="no" # # part 4 # # you need gnu date or a date command that supports the --date option. # (only if you want to print julian dates in the calendar) # #GNUDATE=/usr/local/bin/gdate GNUDATE=/bin/date # # configure me end ############################################################ # get calendar month month=$1 if [ ! "$1" ] then month=`date +%m` fi # get calendar year year=$2 if [ ! "$2" ] then year=`date +%Y` fi # look for day control files if [ "$3" ] then if [ -d $3 ] then cd $3 fi fi # get cal input and expand cal $month $year | $AWK 'BEGIN { dayline = "----------" printf "\n" } { lines++ # print month and year if (lines == 1) { month = $1 year = $2 file = sprintf("/tmp/textcal.%s", pid) arg = sprintf("%s %s | tail +2 > %s", banner, tolower(month), file) system(arg) while (getline bannerout < (file) > 0) { if (!over) for(i=1;i<=(80 - length(bannerout)) / 2;i++) over = sprintf(" %s", over) printf "%s%s\n", over, bannerout } arg = sprintf("rm -f %s", file) system(arg) for (i=1;i<=(80 - length(year)) / 2;i++) filler = sprintf(" %s", filler) printf "%s%s\n\n", filler, year next # print day headers } else if (lines == 2) { printf " %-10s %-10s %-10s %-10s %-10s %-10s %-10s\n","Sunday", "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" for (i=1;i<=7;i++) printf "|%s", dayline printf "|\n" next } # print day squares # is this the first week of the month? firstweek = 0 if (lines == 3) firstweek = 1 # get how many days are in this week of the month offset = 0 if (NF < 7) offset = 7 - NF # make 10x5 squares (10 characters across by 5 lines down) for (j=1;j<=5;j++) { if (!NF) next # 7 days across for (i=1;i<=NF+offset;i++) { # if there are not 7 days in this week if (offset) { # if first week of month, blank days to the left if (firstweek) { if (offset >= i) day = " " if (offset < i) day = $(i-offset) # if not first week (i.e. last week), blank days to the right } else { if (NF >= i) day = $i if (NF < i) day = " " } # else there are 7 days in this week } else { day = $i } if (day == " ") { jday = "" } else if (juliandate == "yes") { gdatecmd = sprintf("%s --date \"%s 1\" +%%m", gnudate, month) gdatecmd | getline monnum jdatecmd = sprintf("%s --date \"%s/%s/%s\" +%%j", gnudate, monnum, day, year) jdatecmd | getline jday } else { jday = "" } dayfile = sprintf("%02d", day) # first line of day squares if (j==1) { # print day number in upper left hand corner of day square theday = sprintf("%-2s %3s", day, jday) printf "|%-10s", theday # make array of messages to print in each day on each line h = 0 while (getline line < (dayfile) > 0) { h++ cline[dayfile,h] = line } # second line of day squares #} else if (j==2 && juliandate=="yes") { # # print the julian day in upper left hand side of day square # theday = jday # printf "|%-10s", theday # subsequent lines of day squares } else { # if message for this day and this line, print it if (day != " " && cline[dayfile,j-1] != "") { printf "|%-10s", cline[dayfile,j-1] # else print blanks } else { printf "|%-10s", " " } } } printf "|\n" } for (i=1;i<=7;i++) printf "|%s", dayline printf "|\n" }' pid=$$ banner="$BANNER" gnudate="$GNUDATE" juliandate="$PRINTJULIANDATE"