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

  1. # Utility to Add Repetitive Appoints to Calender
  2. # Input Line of Form:
  3. #
  4. # Start     Stop      Time  Rept.   Appointment Comments
  5. # xx/xx/xx  xx/xx/xx  xx:xx weekly  appointment comments --->
  6. #                daily
  7. #
  8. BEGIN {
  9.     stderr = "stderr";
  10.     greg_jul = FALSE;
  11.  
  12. # the following date formats would be used for U.S. style dates
  13.     t0date = sdate(0);       # todays date: mm/dd/yy
  14.     t1date = sdate(1);       # todays date: mm/dd/yyyy
  15.  
  16.     split(t1date,tdate,/\//);
  17.     today_jdn = jdn(tdate[3],tdate[1],tdate[2]);
  18.     century = tdate[3] / 100;
  19.  
  20.     tdc = /{_d}{1,2}/;
  21.     t_pattern = /{tdc}:{tdc}/;
  22.     time_pattern = /^{t_pattern}$/;
  23.     date_pattern = /{tdc}\/{tdc}\/{tdc}/;
  24.     double_date  = /({date_pattern}{_w}+){2,2}/;
  25.     appt_date = /^{_w}*{date_pattern}{_w}/;
  26.  
  27.     colon_s = /:/;
  28.     slash_s = /\//;
  29.  
  30. # input format
  31.     adate = /^{_w}*{double_date}{t_pattern}{_w}+/;
  32.  
  33.     split(t0date,cdate,slash_s);
  34.     apptfile = "c:\\appt" ∩ cdate[3] ∩ ".dat";
  35.     tmpf = "c:\\$tmp$.tmp";
  36.     system("copy " ∩ apptfile ∩ " " ∩ tmpf);
  37.  
  38.     split(stime(2),now,colon_s);
  39.  
  40.     hour = 1;
  41.     minute = 2;
  42. }
  43.  
  44. INITIAL {
  45.     if ( FILENAME == "stdin" ) {
  46.     print "Add Repeat Appointments.";
  47.     print "Input Appointments to Add.";
  48.     print "Format: (repeat == weekly/wkly/daily)";
  49.     print "start_date stop_date time repeat Appointment";
  50.     }
  51. }
  52.  
  53. adate {
  54.     local rc, ii = $1, tac, i;
  55.  
  56.     # index start date - element to stop date
  57.     split($2,tac,slash_s);
  58.     if ( tac[3] < 100 ) tac[3] += century * 100;
  59.     start_date[ii][0] = jdn(tac[3],tac[1],tac[2]);
  60.     start_date[ii][1] = $3; # index start date - element to appt. time
  61.     rc = strlwr($4) ~~ /w(ee)?kly/ ? 7 : 1;
  62.     start_date[ii][2] = rc; # index start date - element to repitition count
  63.     $1 = $2 = $3 = $4 = "";
  64.     start_date[ii][3] = $0; # index start date - appointment
  65. }
  66.  
  67. END {
  68.     local iline, cline, sd, atim, repc, appt;
  69.     local tac, tas, i, c_cnt,c_jdn, i_jdn;
  70.  
  71.     for ( s_date in start_date ) {
  72.     split(s_date,tac,slash_s);
  73.     if ( tac[3] < 100 ) tac[3] += century * 100;
  74.     sd = set_date(tac);
  75.     c_jdn = jdn(tac[3],tac[1],tac[2]);
  76.     stpd = start_date[s_date][0];
  77.     atim = start_date[s_date][1];
  78.     repc = start_date[s_date][2];
  79.     appt = start_date[s_date][3];
  80.     while ( c_cnt = fgetline(tmpf,iline) > 0 ) {
  81.         if ( iline ~~ appt_date ) {
  82.         split(iline,cline);
  83.         print cline[1];
  84.         split(cline[1],tas,slash_s);
  85.         if ( tas[3] < 100 ) tas[3] += century * 100;
  86.         i_jdn = jdn(tas[3],tas[1],tas[2]);
  87.         while ( tas[3] == tac[3]  && c_jdn <= i_jdn ) {
  88.             print(sd,atim,appt);
  89.             fprint(apptfile,sd,atim,appt);
  90.             if ( !(sd = set_next(tac,stpd,repc)) ) break;
  91.               else c_jdn = jdn(tac[3],tac[1],tac[2]);
  92.         }
  93.         }
  94.         fprint(apptfile,iline);
  95.         if ( !sd ) break;
  96.     }
  97.     }
  98.     while ( fgetline(tmpf,iline) > 0 ) fprint(apptfile,iline);
  99.     system("del " ∩ tmpf);
  100. }
  101.  
  102. # format date array passed as mm/dd/yy
  103. # date array passed as:
  104. #   date[1] == month
  105. #   date[2] == day
  106. #   date[3] == year
  107. function set_date(date) {
  108.     local rdate;
  109.  
  110.     rdate = sprintf("%02u/%02u/%02u",date[1],date[2],(date[3] + 0) % 100);
  111.     return rdate;
  112. }
  113.  
  114. # return date for next appointment or FALSE if past stop date
  115. # tac passes the current date in array and returns new date in array
  116. # tac[1] == month
  117. # tac[2] == day
  118. # tac[3] == year
  119. # function return is new date as string: mm/dd/yy
  120. function set_next(tac,stop_jdn,rept) {
  121.     local njdn;
  122.     local rdate = FALSE;
  123.  
  124.     njdn = jdn(tac[3],tac[1],tac[2]) + rept;
  125.     if ( njdn <= stop_jdn ) {
  126.     tac = caln(njdn);
  127.     rotate(tac);  # get proper order of month/day/year
  128.     rdate = set_date(tac);
  129.     }
  130.     return rdate;
  131. }
  132.  
  133. # function to convert year/month/day into julian day number
  134. function jdn(year,month,day) {
  135.     local yr;
  136.     local pfac = 0.6;
  137.     local ljdn;
  138.  
  139.     yr = year + (month - 3.0) / 12.0;
  140.     ljdn = int(367.0 * yr + pfac) - (2 * int(yr)) + int(yr/4.0)
  141.        + int(day) + 1721117;
  142.     if ( !greg_jul ) ljdn += -int(yr/100.0) + int(yr/400.0) + 2;
  143.     return ljdn;
  144. }
  145.  
  146. #  function to convert julian dday number to year/month/day
  147. # return array:
  148. #   date[1] = year
  149. #   date[2] = month
  150. #   date[3] = day
  151. function caln(cjdn) {
  152.     local n, ic, np, npp, mp;
  153.     local yr, mo, day;
  154.     local dte; # dte[1] == year, dte[2] == month, dte[3] == day
  155.  
  156.     n = int(cjdn) - 1721119;
  157.     ic = int((n - 0.2)/36524.25);
  158.     if ( greg_jul ) np = n + 2; else np = n + ic - (ic / 4);
  159.     yr = int((np - 0.2)/365.25);
  160.     npp = np - int(365.25 * yr);
  161.     mp = int((npp - 0.5)/30.6);
  162.     day = int(npp + 0.5 - 30.6 * mp);
  163.     if ( mp <= 9 ) mo = mp + 3;
  164.       else {
  165.     yr++;
  166.     mo = mp - 9;
  167.     }
  168.     dte[1] = yr;
  169.     dte[2] = mo;
  170.     dte[3] = day;
  171.     return dte; # return date ARRAY
  172. }
  173.