// Version 1.00 04/11/96  First release as an applet.
//         1.01 04/04/97  Now available from button bar button (disabled).


string today_path;


void today_entry(int entry, int subcode)
{
 string y;
 string s;
 int    fh;
 int    m;
 int    d;
 int    size;


 gettimestring("%CE%YR",y);

 s=today_path+y;

 if(!objectexists(s))
 {
  osclis("wimptask run "+today_path+"DayMaker "+y+" "+s+" "+today_path+"Days");
 }

 if(objectexists(s))
 {
  fh=fileopen(s,"r");
  if(fh)
  {
   gettimestring("%DY",s);
   d=stoi(s)-1;
   gettimestring("%MN",s);
   m=stoi(s)-1;
   d+=m*31;

   fileseek(d*4,fh);

   d=filereadi(fh);

   if(d)
   {
    fileseek(d,fh);
    filereads(s,fh);
    s=mids(s,0,slen(s)-1);
    type(datestring() + "\n");
    size = getfontsize();
    setfontsize(size * 80 / 100);
    seteffect(ITALIC);
    type("("+s+")");
    seteffect(ITALIC);
    setfontsize(size);
   }
   else type(datestring());

   fileclose(fh);
  }
 }
}


// shade or un-shade 'Today' menu entry

int today_flags(int entry, string &text)
{
 return((activetype(TEXTFRAME) > 1) ? 0 : SHADED);
}


// add 'Today' option to Applets menu

void main(void)
{
 string help = "{TODAY_01}";

 today_path="OvationPro$AppletsDir";
 getenvs(today_path);
 today_path+=".!Today.";

 script_menu_initialise();
 addentry_menu(script_handle,"today_entry","today_flags","","CS_D","{TODAY_00}");

 if(isdefmacro("today") == -1)
 {
  translate(help);
  defmacro2(0, "today" ,"{if(activetype(TEXTFRAME)>1) today_entry(0, 0);else bbc_vdu(7)}" ,"today", help);
 }
}
