home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / qtawk / apptdis.exp < prev    next >
Text File  |  1990-07-25  |  4KB  |  143 lines

  1. # QTAwk utility to set alarm clock for next appointment time
  2. # appointments stored in file "appoint.fle" in format:
  3. #
  4. # mm/dd/yy hh:mm appointment comments/description/place
  5. # or
  6. # mm/dd/yyyy hh:mm appointment comments/description/place
  7. #
  8. # the file "appoint.fle" is read until an appointment if found for today
  9. # for which the appointment hour is equal to the current hour and
  10. # the appointment minute is greater than the current minute
  11. # or
  12. # the appointment hour is greater than the current hour
  13. # An informative message is issued about the time set for the
  14. # appointment, and the program to set the alarm is invoked.
  15. # Any appointment comments are displayed
  16. # Times are military times ( 0 <= hh < 24 )
  17. #
  18. BEGIN {
  19.     stderr = "stderr";
  20.     if ( ARGC > 1 ) {
  21.     fprintf(stderr,"Incorrect Invocation.\nUsage: QTAwk -ftclk.exp\n");
  22.     exit;
  23.     }
  24.  
  25. # the following date formats would be used for U.S. style dates
  26.     t0date = sdate(0);       # todays date: mm/dd/yy
  27.     t1date = sdate(1);       # todays date: mm/dd/yyyy
  28.  
  29.     greg_jul = FALSE;
  30.     split(t1date,tdate,/\//);
  31.     today_jdn = jdn(tdate[3],tdate[1],tdate[2]);
  32.  
  33.     # special date
  34.     special_date = "08/31/1996";
  35.     split(special_date,spldate,/\//);
  36.     spl_date_jdn = jdn(spldate[3],spldate[1],spldate[2]);
  37.     days_rem = spl_date_jdn - today_jdn;
  38.     spl_day = (spl_date_jdn + 1) % 7;
  39.     last_week = spl_day ? 1 : 0;
  40.  
  41. # use following to allow more variation in date format
  42.     today = /^{_w}*({t0date}|{t1date}){_w}/;
  43.  
  44. # the following date formats would be used for European style dates
  45. #    t2date = sdate(2);     # todays date: dd/mm/yy
  46. #    t3date = sdate(3);     # todays date: dd/mm/yyyy
  47. # use following to allow more variation in date format
  48. #    today = /^{_w}*({t2date}|{t3date}){_w}/;
  49.  
  50.     time_pattern = /^[0-9]?[0-9]:[0-9][0-9]?$/;
  51.  
  52.     colon_s = /:/;
  53.     slash_s = /\//;
  54.  
  55.     split(t0date,cdate,slash_s);
  56.     ARGV[ARGC++] = "c:\\appt" ∩ cdate[3] ∩ ".dat";
  57.  
  58.     split(stime(2),now,colon_s);
  59.  
  60.     hour = 1;
  61.     minute = 2;
  62.  
  63.     appt_set = FALSE; # appointment set flag
  64.  
  65.     notice_hr = 00; # set time for notices == 00:00
  66.  
  67.     l1_hdr = ".======== " ∩ t1date ∩ " ========.";
  68.     l2_hdr = ".==================.";
  69.     spl_hdr = "*> " ∩ t1date ∩ " <> " ∩ special_date ∩ " <";
  70.     print l1_hdr;
  71.     print "Appointments: " ∩ t0date;
  72.     print " Time\tPurpose";
  73.     print ".---.\t.----------->";
  74.  
  75.     lunch_time = "11:30";   # lunch
  76.     split(lunch_time,lunch,colon_s);
  77.  
  78.     cob_time = "16:05";     # close of business
  79.     split(cob_time,cob,colon_s);
  80.  
  81.     if ( now[hour] <  lunch[hour] ||
  82.     (now[hour] == lunch[hour] && now[minute] < lunch[minute]) ) {
  83.     appt_list[lunch_time] = "Lunch Time";
  84.     }
  85.  
  86.     if ( now[hour] <  cob[hour] ||
  87.     (now[hour] == cob[hour] && now[minute] < cob[minute]) ) {
  88.     appt_list[cob_time] = "Closing Time";
  89.     }
  90. }
  91.  
  92. # find only those lines with todays date to set appointments
  93. # use following to allow more variation in date format
  94. today {  # find records for today
  95.     local atime, ai, apt_time;
  96.  
  97.     if ( $2 ~~ time_pattern ) {
  98.     split($2,atime,colon_s);
  99.     if ( atime[hour] == notice_hr &&
  100.          atime[minute] == 0 ) {
  101.         $1 = $2 = "";
  102.         notice[n_cnt++] = strim($0,TRUE,FALSE);
  103.         appt_set = TRUE;
  104.     } else if ( atime[hour] >  now[hour] ||
  105.            (atime[hour] == now[hour] && atime[minute] > now[minute]) ) {
  106.         appt_time = $2;
  107.         $1 = $2 = "";
  108.         appt_list[appt_time] = strim($0,TRUE,FALSE);
  109.         appt_set = TRUE;
  110.     }
  111.     }
  112.     next;
  113. }
  114.  
  115.     {
  116.     if ( appt_set ) exit;
  117. }
  118.  
  119. END {
  120.     for ( appt_time in notice     ) printf("NOTICE\t%s\n",notice[appt_time]);
  121.     for ( appt_time in appt_list ) printf("%s\t%s\n",appt_time,appt_list[appt_time]);
  122. #    print l1_hdr;
  123.     print spl_hdr;
  124.     remg = "\tRemaining";
  125.     print "*\tDays: " ∩ days_rem ∩ remg;
  126.     print "*\tWeeks: " ∩ ((days_rem - spl_day)/7 + last_week) ∩ remg;
  127.     print "*\tMonths: " ∩ days_rem/30 ∩ remg;
  128.     print spl_hdr;
  129. }
  130.  
  131. # function to convert year/month/day into julian day number
  132. function jdn(year,month,day) {
  133.     local yr;
  134.     local pfac = 0.6;
  135.     local ljdn;
  136.  
  137.     yr = year + (month - 3.0) / 12.0;
  138.     ljdn = int(367.0 * yr + pfac) - (2 * int(yr)) + int(yr/4.0)
  139.        + int(day) + 1721117;
  140.     if ( !greg_jul ) ljdn += -int(yr/100.0) + int(yr/400.0) + 2;
  141.     return ljdn;
  142. }
  143.