home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / qtawkos2.zip / QTAUTL.ZIP / calndprt.exp < prev    next >
Text File  |  1994-11-21  |  3KB  |  77 lines

  1. # QTAwk program to print calenders
  2. #
  3. # Print calender for years specified.
  4. # input: years for calender - 1 year per line or year range
  5. # output: calender for each year input - leap years indicated
  6. #         with asteric
  7. #
  8. #
  9. BEGIN {
  10.         #
  11.         # print calenders with day of week header
  12.         #
  13.     printf("\t   S  M  T  W  T  F  S\t   S  M  T  W  T  F  S\t   S  M  T  W  T  F  S\n");
  14.     printf("\t0  1  2  3  4  5  6  7\t1     1  2  3  4  5  6\t2        1  2  3  4  5\n");
  15.     printf("\t   8  9 10 11 12 13 14\t   7  8  9 10 11 12 13\t   6  7  8  9 10 11 12\n");
  16.     printf("\t  15 16 17 18 19 20 21\t  14 15 16 17 18 19 20\t  13 14 15 16 17 18 19\n");
  17.     printf("\t  22 23 24 25 26 27 28\t  21 22 23 24 25 26 27\t  20 21 22 23 24 25 26\n");
  18.     printf("\t  29 30 31            \t  28 29 30 31         \t  27 28 29 30 31\n");
  19.     printf("\t3           1  2  3  4\t4              1  2  3\t5                 1  2\n");
  20.     printf("\t   5  6  7  8  9 10 11\t   4  5  6  7  8  9 10\t   3  4  5  6  7  8  9\n");
  21.     printf("\t  12 13 14 15 16 17 18\t  11 12 13 14 15 16 17\t  10 11 12 13 14 15 16\n");
  22.     printf("\t  19 20 21 22 23 24 25\t  18 19 20 21 22 23 24\t  17 18 19 20 21 22 23\n");
  23.     printf("\t  26 27 28 29 30 31   \t  25 26 27 28 29 30 31\t  24 25 26 27 28 29 30\n");
  24.     printf("\t                      \t                      \t  31\n");
  25.     printf("\t6                    1\n");
  26.     printf("\t   2  3  4  5  6  7  8\n");
  27.     printf("\t   9 10 11 12 13 14 15\n");
  28.     printf("\t  16 17 18 19 20 21 22\n");
  29.     printf("\t  23 24 25 26 27 28 29\n");
  30.     printf("\t  30 31\n\n");
  31.     printf("\t        J  F  M  A  M  J  J  A  S  O  N  D\n");
  32. #
  33. # Gregorian/Julian calender flag.
  34. #   TRUE == julian
  35. #   FALSE == gregorian
  36. #
  37. #    greg_jul = FALSE;
  38. }
  39.  
  40. # test for proper format
  41. # "year"
  42. # or
  43. # "year1 - year2"
  44. /^{_d}{4,4}({_w}+\-{_w}+{_d}{4,4})?$/ {
  45.     yr1 = yr2 = int($1);
  46.     if ( NF > 1 ) {
  47.         if ( $1 <= $3 ) yr2 = int($3);
  48.           else {
  49.             fprintf("stderr","Improper Format For Year Range.\nInput Line: %s",$0);
  50.             exit 2;
  51.         }
  52.     }
  53.     for ( yr = yr1 ; yr <= yr2 ; yr++ ) {
  54.         #
  55.         # use jdn function to compute julian day number of first day of
  56.         # each month of year. Then compute week-day of first day of
  57.         # month Sunday == 0, Monday == 1 ... Saturday == 6
  58.         #
  59.         for ( i = 1 ; i <= 12 ; i++ )
  60.             first_day[i] = (jdn(yr,i,1) + 1) % 7;
  61.          # check for leap year
  62.         if ( first_day[2] != first_day[3] ) printf("\t*%d*: ",yr); # yes
  63.           else printf("\t %d : ",yr); # no
  64.             # print first day of each month
  65.         for ( month = 1 ; month <= 12 ; month++ )
  66.           printf("%d  ",first_day[month]);
  67.         printf("\n");
  68.     }
  69.     printf("\n");
  70. }
  71.  
  72. END {
  73.         # print days in each month at bottom
  74.     printf("\n\t        3  2  3  3  3  3  3  3  3  3  3  3\n");
  75.     printf("\t        1  8  1  0  1  0  1  1  0  1  0  1\n");
  76. }
  77.