home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / qtawkos2.zip / QTAUTL.ZIP / apptadd.exp < prev    next >
Text File  |  1991-05-30  |  4KB  |  134 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.  
  11. # the following date formats would be used for U.S. style dates
  12.     t0date = sdate(0);       # todays date: mm/dd/yy
  13.     t1date = sdate(1);       # todays date: mm/dd/yyyy
  14.  
  15.     split(t1date,tdate,/\//);
  16.     today_jdn = jdn(tdate[3],tdate[1],tdate[2]);
  17.     century = tdate[3] / 100;
  18.  
  19.     tdc = /{_d}{1,2}/;
  20.     t_pattern = /{tdc}:{tdc}/;
  21.     time_pattern = /^{t_pattern}$/;
  22.     date_pattern = /{tdc}\/{tdc}\/{tdc}/;
  23.     double_date  = /({date_pattern}{_w}+){2,2}/;
  24.     appt_date = /^{_w}*{date_pattern}{_w}/;
  25.  
  26.     colon_s = /:/;
  27.     slash_s = /\//;
  28.  
  29. # input format
  30.     adate = /^{_w}*{double_date}{t_pattern}{_w}+/;
  31.  
  32.     split(t0date,cdate,slash_s);
  33.     apptfile = "c:\\appt" ∩ cdate[3] ∩ ".dat";
  34.     tmpf = "c:\\$tmp$.tmp";
  35.     system("copy " ∩ apptfile ∩ " " ∩ tmpf);
  36.  
  37.     split(stime(2),now,colon_s);
  38.  
  39.     hour = 1;
  40.     minute = 2;
  41. }
  42.  
  43. INITIAL {
  44.     if ( FILENAME == "stdin" ) {
  45.     print "Add Repeat Appointments.";
  46.     print "Input Appointments to Add.";
  47.     print "Format: (repeat == weekly/wkly/daily)";
  48.     print "start_date stop_date time repeat Appointment";
  49.     }
  50. }
  51.  
  52. adate {
  53.     local rc, ii = $1, tac, i;
  54.  
  55.     # index start date - element to stop date
  56.     split($2,tac,slash_s);
  57.     if ( tac[3] < 100 ) tac[3] += century * 100;
  58.     start_date[ii][0] = jdn(tac[3],tac[1],tac[2]);
  59.     start_date[ii][1] = $3; # index start date - element to appt. time
  60.     rc = strlwr($4) ~~ /w(ee)?kly/ ? 7 : 1;
  61.     start_date[ii][2] = rc; # index start date - element to repitition count
  62.     $1 = $2 = $3 = $4 = "";
  63.     start_date[ii][3] = $0; # index start date - appointment
  64. }
  65.  
  66. END {
  67.     local iline, cline, sd, atim, repc, appt;
  68.     local tac, tas, i, c_cnt,c_jdn, i_jdn;
  69.  
  70.     for ( s_date in start_date ) {
  71.     split(s_date,tac,slash_s);
  72.     if ( tac[3] < 100 ) tac[3] += century * 100;
  73.     sd = set_date(tac);
  74.     c_jdn = jdn(tac[3],tac[1],tac[2]);
  75.     stpd = start_date[s_date][0];
  76.     atim = start_date[s_date][1];
  77.     repc = start_date[s_date][2];
  78.     appt = start_date[s_date][3];
  79.     while ( c_cnt = fgetline(tmpf,iline) > 0 ) {
  80.         if ( iline ~~ appt_date ) {
  81.         split(iline,cline);
  82.         print cline[1];
  83.         split(cline[1],tas,slash_s);
  84.         if ( tas[3] < 100 ) tas[3] += century * 100;
  85.         i_jdn = jdn(tas[3],tas[1],tas[2]);
  86.         while ( tas[3] == tac[3]  && c_jdn <= i_jdn ) {
  87.             print(sd,atim,appt);
  88.             fprint(apptfile,sd,atim,appt);
  89.             if ( !(sd = set_next(tac,stpd,repc)) ) break;
  90.               else c_jdn = jdn(tac[3],tac[1],tac[2]);
  91.         }
  92.         }
  93.         fprint(apptfile,iline);
  94.         if ( !sd ) break;
  95.     }
  96.     }
  97.     while ( fgetline(tmpf,iline) > 0 ) fprint(apptfile,iline);
  98.     system("del " ∩ tmpf);
  99. }
  100.  
  101. # format date array passed as mm/dd/yy
  102. # date array passed as:
  103. #   date[1] == month
  104. #   date[2] == day
  105. #   date[3] == year
  106. function set_date(date) {
  107.     local rdate;
  108.  
  109.     rdate = sprintf("%02u/%02u/%02u",date[1],date[2],(date[3] + 0) % 100);
  110.     return rdate;
  111. }
  112.  
  113. # return date for next appointment or FALSE if past stop date
  114. # tac passes the current date in array and returns new date in array
  115. # tac[1] == month
  116. # tac[2] == day
  117. # tac[3] == year
  118. # function return is new date as string: mm/dd/yy
  119. function set_next(tac,stop_jdn,rept) {
  120.     local njdn;
  121.     local rdate = FALSE;
  122.  
  123.     njdn = jdn(tac[3],tac[1],tac[2]) + rept;
  124.     if ( njdn <= stop_jdn ) {
  125.     tac = caln(njdn);
  126.     rotate(tac);  # get proper order of month/day/year
  127.     rdate = set_date(tac);
  128.     }
  129.     return rdate;
  130. }
  131.  
  132. # function to convert year/month/day into julian day number
  133. #include <jdn.exp>
  134.