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

  1. # QTAwk  utility  to  set  alarm  clock  for next appointment time appointments
  2. # stored in file "apptXX.dat" (XX == current year) 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  "apptXX.dat"  is  read  finding  all  appointments  for today. The
  9. # appointments are stored in the array "appt_list" indexed by appointment time.
  10. # Indexing  by    time  automatically  sorts  the  the  appointsments  by time in
  11. # "appt_list". Once  the file  has been  completely read,  array "appt_list" is
  12. # scanned for an  appointment for which  the appointment hour  is equal to  the
  13. # current hour and the appointment minute is greater than the current minute or
  14. # the appointment hour is greater than the current hour. An informative message
  15. # is issued about the time set for the appointment, and the program to set  the
  16. # alarm is invoked. Any appointment comments are displayed
  17. #
  18. # Times are military times ( 0 <= hh < 24 )
  19. #
  20. BEGIN {
  21.     if ( ARGC > 1 ) {
  22.     fprintf("stderr","Incorrect Invocation.\nUsage: Awkplus -ftclk.exp\n");
  23.     exit;
  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. # use following to allow more variation in date format
  30.     today = /^{_w}*({t0date}|{t1date}){_w}/;
  31.  
  32. # the following date formats would be used for European style dates
  33. #    t2date = sdate(2);     # todays date: dd/mm/yy
  34. #    t3date = sdate(3);     # todays date: dd/mm/yyyy
  35. # use following to allow more variation in date format
  36. #    today = /^{_w}*({t2date}|{t3date}){_w}/;
  37.  
  38.     time_pattern = /^[0-9]?[0-9]:[0-9][0-9]?$/;
  39.  
  40.     colon_s = /:/;
  41.     slash_s = /\//;
  42.  
  43.     hour = 1;
  44.     minute = 2;
  45.  
  46.     appt_set = FALSE; # appointment set flag
  47.     set_appt = FALSE; # appointment set flag
  48.  
  49.     appt_hdr = t0date ∩ " ==> Set Alarm time to: ";
  50.     appt_trl = "\nAppointment: ";
  51.  
  52.     not_hdr = t0date ∩ " ==> NOTICE: ";
  53.     notice_hr = 00; # set time for notices == 00:00
  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.     lunch_time = "11:30";   # lunch
  61.     split(lunch_time,lunch,colon_s);
  62.  
  63.     cob_time = "16:05";     # close of business
  64.     split(cob_time,cob,colon_s);
  65.  
  66.     if ( now[hour] <  lunch[hour] ||
  67.     (now[hour] == lunch[hour] && now[minute] < lunch[minute]) ) {
  68.     appt = lunch;
  69.     appt_list[lunch_time] = "Lunch Time";
  70.     set_appt = TRUE;
  71.     }
  72.  
  73.     if ( now[hour] <  cob[hour] ||
  74.     (now[hour] == cob[hour] && now[minute] < cob[minute]) ) {
  75.     appt = cob;
  76.     appt_list[cob_time] = "Closing Time";
  77.     set_appt = TRUE;
  78.     }
  79. }
  80.  
  81. # find only those lines with todays date to set appointments
  82. # use following to allow more variation in date format
  83. today {  # find records for today
  84.     local atime, ai;
  85.  
  86.     if ( $2 ~~ time_pattern ) {
  87.     split($2,atime,colon_s);
  88.     if ( atime[hour] == notice_hr &&
  89.          atime[minute] == 0 ) {
  90.         $1 = $2 = "";
  91.         notice[n_cnt++] = strim($0,TRUE,FALSE);
  92.         appt_set = TRUE;
  93.     } else if ( atime[hour] >  now[hour] ||
  94.            (atime[hour] == now[hour] && atime[minute] > now[minute]) ) {
  95.         appt = atime;
  96.         appt_time = $2;
  97.         $1 = $2 = "";
  98.         appt_list[appt_time] = strim($0,TRUE,FALSE);
  99.         appt_set = TRUE;
  100.     }
  101.     }
  102.     next;
  103. }
  104.  
  105.     {
  106.     if ( appt_set ) exit;
  107. }
  108.  
  109. END {    # set lunch or close of business time if no other alarm set
  110.     # and current time is before lunch or close of business
  111.     print ".=======================.";
  112.     if ( set_appt || appt_set ) {
  113.     for ( appt_time in notice    ) print not_hdr ∩ notice[appt_time];
  114.     for ( appt_time in appt_list ) {
  115.         system("alarm /S" ∩ appt_time); # invoke program to set alarm
  116.         print appt_hdr ∩ appt_time ∩ appt_trl ∩ appt_list[appt_time] ∩ "\nAppointment Set.";
  117.         break; # break off after setting first alarm
  118.     }
  119.     } else print "Past Closing Time";
  120.     print ".=======================.";
  121. }
  122.