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

  1. # QTAwk program to print calender - 1770 to 2070 inclusive
  2. # years changed by changing yr1 and yr2 variables
  3. #
  4. # (C) Copyright 1989 - 1994 Terry D. Boldt, All Rights Reserved
  5. #
  6. #
  7. BEGIN {
  8.         #
  9.         # print calenders with day of week header
  10.         #
  11.     printf("\t(C) Copyright 1989, 1990  Terry D. Boldt\n\tAll Rights Reserved\n");
  12.     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");
  13.     printf("\t0  1  2  3  4  5  6  7\t1     1  2  3  4  5  6\t2        1  2  3  4  5\n");
  14.     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");
  15.     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");
  16.     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");
  17.     printf("\t  29 30 31            \t  28 29 30 31         \t  27 28 29 30 31\n");
  18.     printf("\t3           1  2  3  4\t4              1  2  3\t5                 1  2\n");
  19.     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");
  20.     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");
  21.     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");
  22.     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");
  23.     printf("\t                      \t                      \t  31\n");
  24.     printf("\t6                    1\n");
  25.     printf("\t   2  3  4  5  6  7  8\n");
  26.     printf("\t   9 10 11 12 13 14 15\n");
  27.     printf("\t  16 17 18 19 20 21 22\n");
  28.     printf("\t  23 24 25 26 27 28 29\n");
  29.     printf("\t  30 31\n");
  30.     printf("\t            0  │  1  │  2  │  3  │  4  │  5  │  6  │\n");
  31.     printf("\tJan (31d) F  N │A  J │B  M │C  G │D  L │E  H │I  K │\n");
  32.     printf("\tFeb (28d) D  L*│E* H │I  K*│F  N*│A  J*│B  M*│C  G*│\n");
  33.     printf("\tMar (31d) D  G │H  L │E  I │F  K │A  N │B  J │C  M │\n");
  34.     printf("\tApr (30d) A  N │B  J │C  M │D  G │H  L │E  I │F  K │\n");
  35.     printf("\tMay (31d) E  I │F  K │A  N │B  J │C  M │D  G │H  L │\n");
  36.     printf("\tJun (30d) C  M │D  G │H  L │E  I │F  K │A  N │B  J │\n");
  37.     printf("\tJul (31d) A  N │B  J │C  M │D  G │H  L │E  I │F  K │\n");
  38.     printf("\tAug (31d) H  L │E  I │F  K │A  N │B  J │C  M │D  G │\n");
  39.     printf("\tSep (30d) B  J │C  M │D  G │H  L │E  I │F  K │A  N │\n");
  40.     printf("\tOct (31d) F  K │A  N │B  J │C  M │D  G │H  L │E  I │\n");
  41.     printf("\tNov (30d) D  G │H  L │E  I │F  K │A  N │B  J │C  M │\n");
  42.     printf("\tDec (31d) B  J │C  M │D  G │H  L │E  I │F  K │A  N │\n\n\n");
  43.  
  44.  
  45. # define year patterns
  46.     m_indx[ 0] = "*144025036146";
  47.     m_indx[ 1] = "*255136140250";
  48.     m_indx[ 2] = "*366240251361";
  49.     m_indx[ 3] = "*400351362402";
  50.     m_indx[ 4] = "*512503514624*"; # leap year
  51.     m_indx[ 5] = "*033614625035";
  52.     m_indx[ 6] = "*360351362402*"; # leap year
  53.     m_indx[ 7] = "*511462403513";
  54.     m_indx[ 8] = "*622503514624";
  55.     m_indx[ 9] = "*145136140250*"; # leap year
  56.     m_indx[10] = "*623614625035*"; # leap year
  57.     m_indx[11] = "*401462403513*"; # leap year
  58.     m_indx[12] = "*256240251361*"; # leap year
  59.     m_indx[13] = "*034025036146*"; # leap year
  60.  
  61.     alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  62.  
  63.     stderr = "stderr";
  64. #
  65. # Gregorian/Julian calender flag.
  66. #   TRUE == julian
  67. #   FALSE == gregorian
  68. #
  69. #    greg_jul = FALSE;
  70.     yr_cnt = 0;
  71.     yr1 = 2080; # first year of range
  72.     yr2 = 2385; # second year of range
  73.                 # 1770 to 2080 fits nicely on a single page
  74.     printf("\t      0 1 2 3 4 5 6 7 8 9\n");
  75.     for ( yr = yr1 ; yr <= yr2 ; ) {
  76.         myr = yr % 100;
  77.         if ( myr == 00 || myr == 50 ) printf("\t      0 1 2 3 4 5 6 7 8 9\n");
  78.         printf("\t%4u: ",yr);
  79.         for ( mm = 0 ; mm < 10 ; yr++ , mm++ ) {
  80.             #
  81.             # use jdn function to compute julian day number of first day of
  82.             # each month of year. Then compute week-day of first day of
  83.             # month Sunday == 0, Monday == 1 ... Saturday == 6
  84.             #
  85.             for ( i = 1 , yr_num = '*' ; i <= 12 ; i++ ) {
  86.                 mn_num = (jdn(yr,i,1) + 1) % 7;
  87.                 yr_num ∩= mn_num; # build pattern for year
  88.             }
  89.              # check for leap year
  90.             fdf = substr(yr_num,3,1);
  91.             fdm = substr(yr_num,4,1);
  92.             if ( fdf != fdm ) {
  93.                 leap_yr = TRUE;
  94.                 yr_num ∩= '*';
  95.             } else leap_yr = FALSE;
  96.             found = FALSE;
  97.             for ( i in m_indx )
  98.                 # compare year pattern to matrix of patterns to find index
  99.                 # into Alpha string designating year
  100.                 if ( m_indx[i] == yr_num ) {
  101.                     yr_num = i;
  102.                     found = TRUE;
  103.                     break;
  104.                 }
  105.             # if year pattern wasn't found - error
  106.             if ( !found ) {
  107.                 fprintf(stderr,"another matrix element");
  108.                 exit;
  109.             }
  110.             # print element of decade - print '*' if leap year
  111.             printf("%c%c",substr(alpha,yr_num + 1,1),leap_yr ? '*' : ' ');
  112.         }
  113.         printf("\n");
  114.     }
  115. }
  116.