home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / calendar < prev    next >
Text File  |  2020-01-01  |  2KB  |  64 lines

  1. #!/usr/local/bin/kermit +
  2.  
  3. ; c a l e n d a r
  4. ;
  5. ; Prints a calendar of the given month of the given year, or if no year
  6. ; and month given, of the current month. To print a single month, e.g.
  7. ; March 2002:
  8. ;
  9. ;   calendar 2002 3
  10. ;
  11. ; To print a year (e.g. 2002):
  12. ;
  13. ;   for \%i 1 12 1 { take calendar 2002 \%i } 
  14. ;
  15. ; Requires:    C-Kermit 8.0 or later or K95 1.1.21 or later.
  16. ; Illustrates: Date arithmetic using Modified Julian Date (MJD).
  17. ; Author:      F. da Cruz, Columbia University, March 2002.
  18. ;
  19. local mm yyyy yyyymm dayone \&m[] \%a \%d \%e \%i \%s       ; Local variables
  20. dcl \&m[] = Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ; Month names
  21.  
  22. ; Validate arguments...
  23.  
  24. define usage {
  25.     if def \%1 echo \%1
  26.     exit 1 Usage: \fbasename(\v(cmdfile)) yyyy mm
  27. }
  28. switch \v(argc) {
  29.   :1, .\%1 := \:(\v(ndate)[1:4]), .\%2 := \:(\v(ndate):[5:2]), break
  30.   :3, break
  31.   :default, usage
  32. }
  33. if not numeric \%1 usage "Year not numeric"
  34. if not numeric \%2 usage "Month not numeric"
  35. if ( < \%1 1859 || > \%1 9999 ) usage "Year out of range (1859-9999)"
  36. if ( < \%2 1 || > \%2 12 ) usage "Month out of range (1-12)"
  37.  
  38. ; Interpret arguments...
  39.  
  40. .mm     := \flpad(\%2,2,0)                ; 2-digit month
  41. .yyyy   := \%1                            ; 4-digit year
  42. .yyyymm := \m(yyyy)\m(mm)                 ; Month and year
  43. .dayone := \m(yyyymm)01                   ; First day of month
  44.  
  45. .\%d ::= \fmjd(\m(dayone) +1month) - \fmjd(\m(dayone))  ; Days in month
  46. .\%e :=  \fnday(\m(dayone))               ; Day of week of first day of month
  47. .\%s ::= \fmod((7-\%e),7)                 ; Day of week of Saturday
  48.  
  49. ; Print calendar...
  50.  
  51. echo                                      ; Heading
  52. echo " \&m[\%2] \%1"
  53. echo "  S  M  T  W  T  F  S"
  54. xecho "\frepeat({   },\%e)"               ; Spacer for first week
  55.  
  56. for \%i 1 \%d 1 {                         ; Loop for each day of month
  57.   xecho \flpad(\%i,3)                     ; Print the day number
  58.   if == \fmod(\%i,7) \%s echo             ; End of week - start new line
  59. }
  60. if != \fmod(\%i,7) (\%s+1) echo           ; If week ended on Saturday
  61.  
  62. echo                                      ; Blank line at end
  63. if kerbang exit 0
  64.