home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TICKLE11.ZIP / TICKLE.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1987-07-17  |  22.4 KB  |  815 lines

  1. program tickle;
  2.  
  3. const
  4.   ver      = '1.01';
  5.   dataname = 'TICKLE.DTA';
  6.   logname  = 'TICKLOG.DTA';
  7.   bs       = #8;
  8.   ff       = #12;
  9.   nuldate  = '50-50-50';
  10.   scroll   = 20;
  11.  
  12. type
  13.   datestr  = string[8];
  14.   notestr  = string[80];
  15.   string3  = string[3];
  16.  
  17.   tickletype = record
  18.                  date: datestr;
  19.                  note: notestr;
  20.                end;
  21.  
  22.   regpack    = record
  23.                   ax,bx,cx,dx,bp,di,si,ds,es,flags:integer;
  24.                end;
  25.  
  26.   sortary    = array[0..500] of datestr;
  27.  
  28. var
  29.   backfile: file of tickletype;
  30.   backrec: tickletype;
  31.   logfile: file of tickletype;
  32.   logrec: tickletype;
  33.   ticklefile: file of tickletype;
  34.   ticklerec: tickletype;
  35.   sourcefile: file of tickletype;
  36.   sourcerec: tickletype;
  37.   filename: string[14];
  38.   horizon,indate,searchdate: datestr;
  39.   innote: notestr;
  40.   code,delno,i,j,numnotes,words: integer;
  41.   match: boolean;
  42.   commandkey,response: char;
  43.  
  44.   sortkey: sortary;
  45.   dateary: array[0..500] of datestr;
  46.   noteary: array[0..500] of notestr;
  47.   dispary: array[0..500] of datestr;
  48.  
  49. function allcaps(instr:notestr):notestr;
  50. var
  51.   temp:notestr;
  52. begin
  53.   temp:='';
  54.   for j:=1 to length(instr) do temp:=temp+upcase(instr[j]);
  55.   allcaps:=temp;
  56. end;
  57.  
  58. procedure beep;begin write(#7);delay(100);end;
  59.  
  60. function gooddate:boolean;
  61. var
  62.   ch: char;
  63.   temp: boolean;
  64. begin
  65.   temp:=true;
  66.   if (length(paramstr(1))>1) and (length(paramstr(1))<8) then temp:=false
  67.   else for j:=2 to length(paramstr(1)) do begin
  68.     ch:=copy(paramstr(1),j,1);
  69.     case j of
  70.       1,2,4,5,7,8: if not(ch in ['0'..'9','?']) then temp:=false;
  71.       3,6        : if not(ch in ['-','/']) then temp:=false;
  72.     end;
  73.   end;
  74.   gooddate:=temp;
  75. end;
  76.  
  77. function goodentry:boolean;
  78. var
  79.   temp: boolean;
  80. begin
  81.   temp:=false;
  82.   if paramstr(1)='' then temp:=true
  83.   else begin
  84.     commandkey:=copy(paramstr(1),1,1);
  85.     if commandkey in
  86.       ['A','a','B','b','C','c','D','d','E','e','L','l','M','m','O','o',
  87.       'P','p','Q','q','R','r','S','s','T','t','V','v','W','w','X','x',
  88.       'Y','y','?'] then temp:=true
  89.     else if (commandkey in ['0'..'9']) and (length(paramstr(1))>1) then
  90.       if gooddate then temp:=true;
  91.   end;
  92.   goodentry:=temp;
  93. end;
  94.  
  95. function clockdate:datestr;
  96. var
  97.   recpack:regpack;
  98.   month,day:string[2];
  99.   year:string[4];
  100.   dx,cx:integer;
  101. begin
  102.   recpack.ax:=$2a shl 8;
  103.   msdos(recpack);
  104.   str(recpack.cx,year);
  105.   str(recpack.dx mod 256,day);
  106.   str(recpack.dx shr 8,month);
  107.   if length(month)=1 then month:='0'+month;
  108.   if length(day)=1 then day:='0'+day;
  109.   year:=copy(year,3,2);
  110.   clockdate:=month+'-'+day+'-'+year;
  111. end;
  112.  
  113. function daysinmonth(mo,yr:integer):integer;
  114. begin
  115.   case mo of
  116.     1,3,5,7,8,10,12 : daysinmonth:=31;
  117.            4,6,9,11 : daysinmonth:=30;
  118.                   2 : if (yr mod 4=0) then daysinmonth:=29 else daysinmonth:=28;
  119.   end;
  120. end;
  121.  
  122. function date2num(date:datestr): integer;
  123. var day,i,month,temp,year:integer; {dates good only from 01-01-81 to 12-31-99}
  124.  
  125.   function daynum(date:datestr):integer;
  126.   var code,temp:integer;
  127.   begin
  128.     val(copy(date,4,2),temp,code);
  129.     daynum:=temp;
  130.   end;
  131.  
  132.   function monthnum(date:datestr):integer;
  133.   var code,temp:integer;
  134.   begin
  135.     val(copy(date,1,2),temp,code);
  136.     monthnum:=temp;
  137.   end;
  138.  
  139.   function yearnum(date:datestr):integer;
  140.   var code,temp:integer;
  141.   begin
  142.     val(copy(date,7,2),temp,code);
  143.     yearnum:=temp;
  144.   end;
  145.  
  146. begin
  147.   temp:=0;
  148.   day:=daynum(date);month:=monthnum(date);year:=yearnum(date);
  149.   year:=year-80;
  150.   for i:=1 to year-1 do
  151.     if ((i mod 4)=0) then temp:=temp+366 else temp:=temp+365;
  152.   for i:=1 to month-1 do temp:=temp+daysinmonth(i,year);
  153.   temp:=temp+day;
  154.   date2num:=temp;
  155. end;
  156.  
  157. function num2date(daynum:integer):datestr;
  158. label getmo,getdy,start;
  159. var i,day,month,year:integer;daystr,monthstr,yearstr:string[2];
  160. begin
  161.   year:=81;
  162.   start:
  163.   for i:=1 to 4 do begin
  164.     if i in [1..3] then daynum:=daynum-365
  165.     else daynum:=daynum-366;
  166.     if daynum<=0 then goto getmo;
  167.     year:=year+1;
  168.   end;
  169.   if daynum>0 then goto start;
  170.   getmo:
  171.   if i in [1..3] then daynum:=daynum+365 else daynum:=daynum+366;
  172.   for i:=1 to 12 do begin
  173.     daynum:=daynum-daysinmonth(i,year);
  174.     if daynum<=0 then goto getdy;
  175.   end;
  176.   getdy:
  177.   daynum:=daynum+daysinmonth(i,year);
  178.   month:=i;
  179.   day:=daynum;
  180.   str(day,daystr);if day<10 then daystr:='0'+daystr;
  181.   str(month,monthstr);if month<10 then monthstr:='0'+monthstr;
  182.   str(year,yearstr);if year<10 then yearstr:='0'+yearstr;
  183.   num2date:=monthstr+'-'+daystr+'-'+yearstr;
  184. end;
  185.  
  186. function sortdate(indate:datestr):datestr;
  187. begin
  188.   sortdate:=copy(indate,7,2)+'-'+copy(indate,1,5);
  189. end;
  190.  
  191. function adddate(indate:datestr;adddy,addmo,addyr:integer):datestr;
  192. var
  193.   code,day_no,
  194.   carry,enddy,endmo,endyr,startmo,startyr : integer;
  195.   endmo_str,endyr_str,temp : datestr;
  196.  
  197. begin
  198.   if length(indate)=8 then begin
  199.     if adddy<>0 then begin
  200.       day_no:=date2num(indate);
  201.       day_no:=day_no+adddy;
  202.       if day_no>6939 then temp:='Bad Date' else temp:=num2date(day_no);
  203.     end
  204.     else begin
  205.       endmo:=0;endyr:=0;
  206.       val(copy(indate,1,2),startmo,code);
  207.       val(copy(indate,7,2),startyr,code);
  208.       endmo:=startmo+addmo;
  209.       if endmo>12 then begin endmo:=endmo-12;carry:=1;end else carry:=0;
  210.       endyr:=startyr+addyr+carry;
  211.       if endyr>=100 then endyr:=endyr-100;
  212.       str(endyr,endyr_str);
  213.       if length(endyr_str)=1 then endyr_str:='0'+endyr_str;
  214.       str(endmo,endmo_str);
  215.       if length(endmo_str)=1 then endmo_str:='0'+endmo_str;
  216.       temp:=endmo_str+copy(indate,3,4)+endyr_str;
  217.       if sortdate(temp)>'99-12-31' then temp:='Bad Date';
  218.     end
  219.   end
  220.   else temp:='';
  221.   adddate:=temp;
  222. end;
  223.  
  224. procedure shell_sort;
  225. var
  226.   done  :boolean;
  227.   jump,i,j,swno: integer;
  228.   tempsort: datestr;
  229.   tempdate: datestr;
  230.   tempdisp: datestr;
  231.   tempnote: notestr;
  232.  
  233. function firstjump(length: integer): integer;
  234. var
  235.   temp : integer;
  236. begin
  237.   temp:=1;
  238.   while temp<=length do temp:=temp*2;
  239.   firstjump:=temp
  240. end;
  241.  
  242. begin
  243.   swno:=0;
  244.   jump:=firstjump(numnotes);
  245.   while jump>1 do begin
  246.     jump:=(jump-1) div 2;
  247.       repeat
  248.         done:=true;
  249.         for j:=0 to numnotes-1-jump do begin
  250.           i:=j+jump;
  251.           if sortkey[j]>sortkey[i] then begin
  252.             swno:=swno+1;
  253.             tempsort:=sortkey[j];sortkey[j]:=sortkey[i];sortkey[i]:=tempsort;
  254.             tempnote:=noteary[j];noteary[j]:=noteary[i];noteary[i]:=tempnote;
  255.             tempdate:=dateary[j];dateary[j]:=dateary[i];dateary[i]:=tempdate;
  256.             tempdisp:=dispary[j];dispary[j]:=dispary[i];dispary[i]:=tempdisp;
  257.             done:=false;
  258.           end;
  259.         end;
  260.       until done
  261.   end;
  262. end;
  263.  
  264. function wildcard(target:datestr):datestr;
  265. var
  266.   indate,outdate,thisdate: datestr;
  267.  
  268.   function wildmonth:string3;
  269.   begin
  270.     wildmonth:=copy(thisdate,1,3);
  271.   end;
  272.  
  273.   function wildyear:string3;
  274.   begin
  275.     wildyear:=copy(thisdate,7,2);
  276.   end;
  277.  
  278. begin
  279.   thisdate:=clockdate;
  280.   indate:=target;
  281.   outdate:='';
  282.   if (copy(indate,1,1)='?') or (copy(indate,2,1)='?') then
  283.     outdate:=outdate+wildmonth
  284.   else outdate:=outdate+copy(indate,1,3);
  285.   if (copy(indate,4,1)='?') or (copy(indate,5,1)='?') then
  286.     outdate:=outdate+copy(thisdate,4,3)
  287.   else outdate:=outdate+copy(indate,4,3);
  288.   if (copy(indate,7,1)='?') or (copy(indate,8,1)='?') then
  289.     outdate:=outdate+wildyear
  290.   else outdate:=outdate+copy(indate,7,2);
  291.   if (copy(indate,1,1)='?') or (copy(indate,2,1)='?') then
  292.     if sortdate(outdate)<sortdate(clockdate) then
  293.       outdate:=adddate(outdate,0,1,0);
  294.   if (copy(indate,7,1)='?') or (copy(indate,8,1)='?') then
  295.     if sortdate(outdate)<sortdate(clockdate) then
  296.       outdate:=adddate(outdate,0,0,1);
  297.   wildcard:=outdate;
  298. end;
  299.  
  300. procedure readnotes;begin
  301.   assign(ticklefile,dataname);
  302.   reset(ticklefile);
  303.   numnotes:=0;
  304.   while not eof(ticklefile) do begin
  305.     read(ticklefile,ticklerec);
  306.     dateary[numnotes]:=ticklerec.date;
  307.     if pos('?',ticklerec.date)<>0 then
  308.       dispary[numnotes]:=wildcard(ticklerec.date)
  309.     else dispary[numnotes]:=ticklerec.date;
  310.     if pos('?',ticklerec.date)<>0 then
  311.       sortkey[numnotes]:=sortdate(wildcard(ticklerec.date))
  312.     else sortkey[numnotes]:=sortdate(ticklerec.date);
  313.     noteary[numnotes]:=ticklerec.note;
  314.     numnotes:=numnotes+1;
  315.   end;
  316.   numnotes:=filesize(ticklefile);
  317.   close(ticklefile);
  318. end;
  319.  
  320. procedure savenotes;
  321. var
  322.   k:integer;
  323. begin
  324.   assign(ticklefile,'TICKLE.DTA');
  325.   rewrite(ticklefile);
  326.   for k:= 0 to numnotes-1 do begin
  327.     ticklerec.date:=dateary[k];
  328.     ticklerec.note:=noteary[k];
  329.     write(ticklefile,ticklerec);
  330.   end;
  331.   close(ticklefile);
  332. end;
  333.  
  334. procedure add(date:datestr;note:notestr);begin
  335.   numnotes:=numnotes+1;
  336.   ticklerec.date:=date;
  337.   ticklerec.note:=note;
  338.   assign(ticklefile,dataname);
  339.   reset(ticklefile);
  340.   seek(ticklefile,filesize(ticklefile));
  341.   write(ticklefile,ticklerec);
  342.   close(ticklefile);
  343. end;
  344.  
  345. procedure addlog(note:notestr);begin
  346.   logrec.date:=clockdate;
  347.   logrec.note:=note;
  348.   assign(logfile,logname);
  349.   reset(logfile);
  350.   seek(logfile,filesize(logfile));
  351.   write(logfile,logrec);
  352.   close(logfile);
  353. end;
  354.  
  355. procedure delete(number:integer);
  356. var
  357.   k: integer;
  358. begin
  359.   for k:=number to numnotes-2 do begin
  360.     dateary[k]:=dateary[k+1];
  361.     noteary[k]:=noteary[k+1];
  362.     dispary[k]:=dispary[k+1];
  363.   end;
  364.   numnotes:=numnotes-1;
  365.   savenotes;
  366. end;
  367.  
  368. procedure addnote;begin
  369.   indate:=paramstr(1);
  370.   words:=paramcount;
  371.   innote:='';
  372.   for i:=2 to paramcount do innote:=innote+paramstr(i)+' ';
  373.   writeln;writeln('Adding:  ',indate,'   ',innote);
  374.   add(indate,innote);
  375. end;
  376.  
  377. procedure backup;
  378. var
  379.   drive: char;
  380.   k: integer;
  381. begin
  382.   writeln;write('Drive for backup (A,B): ');readln(drive);
  383.   drive:=upcase(drive);
  384.   if drive in ['A'..'B'] then begin
  385.     filename:=drive+':'+dataname;
  386.     writeln;write('Backing Up Data File...');
  387.     assign(sourcefile,dataname);
  388.     reset(sourcefile);
  389.     assign(backfile,filename);
  390.     rewrite(backfile);
  391.     while not eof(sourcefile) do begin
  392.       read(sourcefile,sourcerec);
  393.       backrec.date:=sourcerec.date;
  394.       backrec.note:=sourcerec.note;
  395.       write(backfile,backrec);
  396.     end;
  397.     close(sourcefile);
  398.     close(backfile);
  399.     writeln('Done...');
  400.     filename:=drive+':'+logname;
  401.     writeln;write('Backing Up Log File...');
  402.     assign(sourcefile,logname);
  403.     reset(sourcefile);
  404.     assign(backfile,filename);
  405.     rewrite(backfile);
  406.     while not eof(sourcefile) do begin
  407.       read(sourcefile,sourcerec);
  408.       backrec.date:=sourcerec.date;
  409.       backrec.note:=sourcerec.note;
  410.       write(backfile,backrec);
  411.     end;
  412.     close(sourcefile);
  413.     close(backfile);
  414.     writeln('Done...');
  415.   end
  416.   else begin writeln;writeln('Invalid Drive--Backup Aborted');end;
  417. end;
  418.  
  419. procedure calculate;
  420. var
  421.   days2add,mos2add,yrs2add: integer;
  422.   startdate,
  423.   calcdate: datestr;
  424. begin
  425.   startdate:=nuldate;
  426.   writeln;write('Start Date: ');readln(startdate);
  427.   if startdate<>nuldate then begin
  428.     repeat
  429.       writeln;
  430.       write('Add (1) Days (2) Months/Years: ');readln(response);
  431.     until response in ['1'..'2'];
  432.     if response='1' then begin
  433.       days2add:=0;
  434.       writeln;write('Number Days: ');readln(days2add);
  435.       calcdate:=num2date(date2num(startdate)+days2add);
  436.     end
  437.     else begin
  438.       mos2add:=0;
  439.       writeln;write('Number Months: ');readln(mos2add);
  440.       yrs2add:=0;
  441.       writeln;write('Number Years: ');readln(yrs2add);
  442.       calcdate:=adddate(startdate,0,mos2add,yrs2add);
  443.     end;
  444.     writeln;innote:='';
  445.     write('Note: ');readln(innote);
  446.     writeln;writeln('Adding:  ',calcdate,'   ',innote);
  447.     add(calcdate,innote);
  448.   end;
  449. end;
  450.  
  451. procedure delnote;
  452. var
  453.   delno_str: string[2];
  454.   resetdate: datestr;
  455. begin
  456.   match:=false;
  457.   searchdate:=nuldate;
  458.   writeln;write('Delete Date: ');readln(searchdate);
  459.   if searchdate<>nuldate then begin
  460.     for i:=0 to numnotes-1 do begin
  461.       if dispary[i]=searchdate then begin
  462.         match:=true;writeln;
  463.         write('  ',dispary[i]);
  464.         if pos('?',dateary[i])<>0 then write(' + ') else write('   ');
  465.         writeln(noteary[i]);
  466.         response:='N';writeln;
  467.         if pos('?',dateary[i])<>0 then begin
  468.           write('Wildcard Note-Delete ? (Y/N) : N',bs);
  469.           beep;
  470.         end
  471.         else write('Delete ? (Y/N) : N',bs);
  472.         read(response);response:=upcase(response);
  473.         if response='Y' then begin
  474.           delete(i);
  475.           i:=i-1;
  476.           writeln('     Done...');
  477.         end
  478.         else writeln;
  479.       end;
  480.     end;
  481.   end;
  482.   if not match then begin writeln;writeln('Date Not Found');end;
  483. end;
  484.  
  485. procedure listheader(instring:notestr);begin
  486.   writeln('TICKLE ',ver,'   Today`s Date: ',clockdate,'   ',instring);
  487. end;
  488.  
  489. procedure listall;begin
  490.   if numnotes=0 then begin writeln;writeln('No Notes in Tickle File');end
  491.   else begin
  492.     writeln;listheader('All Notes');writeln;
  493.     for i:= 0 to numnotes-1 do begin
  494.       if sortdate(dispary[i])<sortdate(clockdate) then begin
  495.         write('- ',dispary[i]);
  496.         if pos('?',dateary[i])<>0 then write(' + ') else write('   ');
  497.         writeln(noteary[i]);
  498.       end
  499.       else if sortdate(dispary[i])=sortdate(clockdate) then begin
  500.         write('* ',dispary[i]);
  501.         if pos('?',dateary[i])<>0 then write(' + ') else write('   ');
  502.         writeln(noteary[i]);
  503.         beep
  504.       end
  505.       else begin
  506.         write('  ',dispary[i]);
  507.         if pos('?',dateary[i])<>0 then write(' + ') else write('   ');
  508.         writeln(noteary[i]);
  509.       end;
  510.       if (i>0) and (i mod scroll=0) then begin
  511.         writeln;write('Press Any Key to Continue...');
  512.         repeat until keypressed;writeln;writeln;
  513.       end;
  514.     end;
  515.   end;
  516. end;
  517.  
  518. procedure lognote;
  519. begin
  520.   match:=false;
  521.   searchdate:=nuldate;
  522.   writeln;write('Log Date: ');readln(searchdate);
  523.   if searchdate<>nuldate then begin
  524.     assign(logfile,logname);
  525.     {$I-} reset(logfile) {$I+};
  526.     if ioresult=1 then rewrite(logfile);
  527.     for i:= 0 to numnotes-1 do begin
  528.       if sortdate(dispary[i])=sortdate(searchdate) then begin
  529.         match:=true;
  530.         writeln;
  531.         write('  ',dispary[i]);
  532.         if pos('?',dateary[i])<>0 then write(' + ') else write('   ');
  533.         writeln(noteary[i]);writeln;
  534.         response:='N';write('Log? (Y/N) : N',bs);read(response);
  535.         response:=upcase(response);
  536.         if response='Y' then begin
  537.           addlog(noteary[i]);
  538.           if pos('?',dateary[i])=0 then begin
  539.             delete(i);
  540.             i:=i-1;
  541.           end;
  542.           numnotes:=numnotes-1;
  543.           writeln('     Done...');
  544.         end
  545.         else writeln;
  546.       end;
  547.     end;
  548.     if not match then begin writeln;writeln('Log Date Not Found');end;
  549.   end;
  550. end;
  551.  
  552. procedure eraselog;begin
  553.   assign(logfile,logname);
  554.   {$I-} reset(logfile) {$I+};
  555.   if ioresult=0 then begin
  556.     response:='N';
  557.     writeln;write('Erase Log ? (Y/N) : N',bs);readln(response);
  558.     response:=upcase(response);
  559.     if response='Y' then begin;
  560.       erase(logfile);
  561.       writeln;
  562.       writeln('Log File Erased');
  563.     end;
  564.   end;
  565. end;
  566.  
  567. procedure viewlog;
  568. begin
  569.   writeln;
  570.   assign(logfile,logname);
  571.   {$I-} reset(logfile) {$I+};
  572.   if ioresult=0 then begin
  573.     listheader('TICKLE Log');writeln;
  574.     reset(logfile);
  575.     while not eof(logfile) do begin
  576.       read(logfile,logrec);
  577.       writeln('  ',logrec.date,'  ',logrec.note);
  578.       if (i>0) and (i mod scroll=0) then begin
  579.         write('Press Any Key to Continue...');
  580.         repeat until keypressed;writeln;writeln;
  581.       end;
  582.     end;
  583.   end
  584.   else begin
  585.     writeln('Log File Does Not Exist');
  586.   end;
  587. end;
  588.  
  589. procedure overdue;
  590. var
  591.   response: char;
  592. begin
  593.   for i:= 0 to numnotes-1 do begin
  594.     if sortdate(dispary[i])<sortdate(clockdate) then begin
  595.       writeln;
  596.       write('  ',dispary[i]);
  597.       if pos('?',dateary[i])<>0 then write(' + ') else write('   ');
  598.       writeln(noteary[i]);
  599.       response:='N';write('Delete ? (Y/N) : N',bs);readln(response);
  600.       response:=upcase(response);
  601.       if response='Y' then begin delete(i);i:=i-1;end;
  602.     end;
  603.   end;
  604. end;
  605.  
  606. procedure lookahead(days:integer);
  607. var
  608.   n: integer;
  609. begin
  610.   horizon:=num2date(date2num(clockdate)+days);
  611.   n:=0;
  612.   for i:= 0 to numnotes-1 do begin
  613.     if sortdate(dispary[i])<sortdate(clockdate) then begin
  614.       n:=n+1;
  615.       write('- ',dispary[i]);
  616.       if pos('?',dateary[i])<>0 then write(' + ') else write('   ');
  617.       writeln(noteary[i]);
  618.     end
  619.     else if sortdate(dispary[i])<=sortdate(horizon) then
  620.       if sortdate(dispary[i])=sortdate(clockdate) then begin
  621.         n:=n+1;
  622.         write('* ',dispary[i]);
  623.         if pos('?',dateary[i])<>0 then write(' + ') else write('   ');
  624.         writeln(noteary[i]);
  625.         beep
  626.       end
  627.       else begin
  628.         n:=n+1;
  629.         write('  ',dispary[i]);
  630.         if pos('?',dateary[i])<>0 then write(' + ') else write('   ');
  631.         writeln(noteary[i]);
  632.       end;
  633.     if (i>0) and (sortdate(dispary[i])<=sortdate(horizon))
  634.     and (n mod scroll=0) then begin
  635.       writeln;write('Press Any Key to Continue...');
  636.       repeat until keypressed;writeln;writeln;
  637.     end;
  638.   end;
  639. end;
  640.  
  641. procedure listtoday;begin
  642.   writeln;listheader('Notes for TODAY');writeln;
  643.   lookahead(0);
  644. end;
  645.  
  646. procedure listday;begin
  647.   writeln;listheader('Notes for Next DAY');writeln;
  648.   lookahead(1);
  649. end;
  650.  
  651. procedure listmonth;begin
  652.   writeln;listheader('Notes for Next MONTH');writeln;
  653.   lookahead(31);
  654. end;
  655.  
  656. procedure listquarter;begin
  657.   writeln;listheader('Notes for Next QUARTER');writeln;
  658.   lookahead(92);
  659. end;
  660.  
  661. procedure listweek;begin
  662.   writeln;listheader('Notes for Next WEEK');writeln;
  663.   lookahead(7);
  664. end;
  665.  
  666. procedure listyear;begin
  667.   writeln;listheader('Notes for Next YEAR');writeln;
  668.   lookahead(365);
  669. end;
  670.  
  671. procedure printnotes;begin
  672.   writeln;write('Press Any Key When Printer Ready...');
  673.   repeat until keypressed;
  674.   if numnotes=0 then begin writeln;writeln('No Notes in Tickle File');end
  675.   else begin
  676.     writeln;
  677.     writeln(lst,'TICKLE File        Date: ',clockdate);writeln(lst);
  678.     for i:=0 to numnotes-1 do begin
  679.       if i>0 then if copy(dispary[i],1,2)<>copy(dispary[i-1],1,2) then writeln(lst);
  680.       writeln(lst,dispary[i],' ',noteary[i]);
  681.     end;
  682.     writeln(lst,ff,ff);
  683.   end;
  684. end;
  685.  
  686. procedure reschedule;
  687. var
  688.   newdate: datestr;
  689. begin
  690.   match:=false;
  691.   searchdate:=nuldate;
  692.   writeln;write('Date to be Reset: ');readln(searchdate);
  693.   if searchdate<>nuldate then begin
  694.     writeln;
  695.     for i:=0 to numnotes-1 do begin
  696.       if dispary[i]=searchdate then begin
  697.         match:=true;
  698.         delno:=i;
  699.         write('  ',dispary[i]);
  700.         if pos('?',dateary[i])<>0 then write(' + ') else write('   ');
  701.         writeln(noteary[i]);writeln;
  702.         response:='N';write('Reschedule? (Y/N) : N',bs);readln(response);
  703.         response:=upcase(response);
  704.         if response='Y' then begin
  705.           newdate:='';
  706.           writeln;write('New Date: ');read(newdate);
  707.           if newdate<>'' then begin
  708.             dateary[numnotes]:=newdate;
  709.             dispary[numnotes]:=wildcard(newdate);
  710.             noteary[numnotes]:=noteary[delno];
  711.             add(newdate,noteary[delno]);
  712.             delete(delno);
  713.             i:=i-1;
  714.             writeln('     Done...');writeln;
  715.           end;
  716.         end
  717.         else writeln;
  718.       end;
  719.     end;
  720.   end;
  721. end;
  722.  
  723. procedure searchnote;
  724. var
  725.   searchstr: string[20];
  726.   found: boolean;
  727. begin
  728.   found:=false;
  729.   searchstr:='';
  730.   writeln;write('Search String: ');readln(searchstr);
  731.   if searchstr<>'' then begin
  732.     writeln;
  733.     for i:=0 to numnotes-1 do
  734.       if pos(allcaps(searchstr),allcaps(noteary[i]))<>0 then  begin
  735.         write('  ',dispary[i]);
  736.         if pos('?',dateary[i])<>0 then write(' + ') else write('   ');
  737.         writeln(noteary[i]);
  738.         found:=true;
  739.       end;
  740.    end;
  741.    if not found then writeln('String Not Found');
  742. end;
  743.  
  744. procedure help;begin
  745.   writeln;
  746.   writeln('TICKLE   Ver. ',ver);
  747.   writeln('Copr. 1987 M. Lee Murrah');
  748.   writeln('10 Cottage Grove Woods, S.E., Cedar Rapids, IA 52403');
  749.   writeln;
  750.   writeln('Notes may be entered in the TICKLE data file by entering the following on the');
  751.   writeln('command line:');
  752.   writeln;
  753.   writeln('  TICKLE MM/DD/YY Note up to 80 characters long');
  754.   writeln;
  755.   writeln('Wild card character "?" may be used for M,Y,and D.');
  756.   writeln;
  757.   writeln('The following tickle commands may be entered on the command line (upper or');
  758.   writeln('lower case) instead of a date and note:');
  759.   writeln;
  760.   writeln('A - List all notes in TICKLE file       Q - List TICKLE file for next quarter');
  761.   writeln('B - Backup TICKLE file                  R - Reschedule TICKLE note');
  762.   writeln('C - Calculate TICKLE date               S - Search for TICKLE note');
  763.   writeln('D - List TICKLE notes for tomorrow      T - List TICKLE file for today');
  764.   writeln('E - Erase TICKLE log                    V - View TICKLE log');
  765.   writeln('L - Save note to log file               W - List TICKLE notes for next week');
  766.   writeln('M - List TICKLE notes for next month    X - Delete TICKLE note');
  767.   writeln('O - Remove overdue TICKLE notes         Y - List TICKLE notes for next year');
  768.   writeln('P - Print TICKLE notes file');
  769. end;
  770.  
  771. procedure process;begin
  772.   assign(ticklefile,dataname);              {create datafile if not existent}
  773.   {$I-} reset(ticklefile) {$I+};
  774.   if ioresult=1 then rewrite(ticklefile);
  775.   assign(logfile,logname);                  {create log file if not existent}
  776.   {$I-} reset(logfile) {$I+};
  777.   if ioresult=1 then rewrite(logfile);
  778.   readnotes;
  779.   if numnotes>0 then shell_sort;
  780.   if paramstr(1)='' then help
  781.   else begin
  782.     commandkey:=copy(paramstr(1),1,1);
  783.     case commandkey of
  784.       'A','a'     : listall;
  785.       'B','b'     : backup;
  786.       'C','c'     : calculate;
  787.       'D','d'     : listday;
  788.       'E','e'     : eraselog;
  789.       'L','l'     : lognote;
  790.       'M','m'     : listmonth;
  791.       'O','o'     : overdue;
  792.       'P','p'     : printnotes;
  793.       'Q','q'     : listquarter;
  794.       'R','r'     : reschedule;
  795.       'S','s'     : searchnote;
  796.       'T','t'     : listtoday;
  797.       'V','v'     : viewlog;
  798.       'W','w'     : listweek;
  799.       'X','x'     : delnote;
  800.       'Y','y'     : listyear;
  801.       '0'..'9','?': addnote;
  802.       {be sure new commands are added to the goodentry function and help procedure}
  803.     end;
  804.   end;
  805. end;
  806.  
  807. begin
  808.   if goodentry then process else begin
  809.     writeln;
  810.     if not gooddate then writeln('Incorrect Date Format')
  811.     else writeln('Incorrect Command');
  812.   end;
  813. end.
  814.  
  815.