home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Header: calentool.c,v 2.1 89/05/09 15:28:43 billr Exp $
- */
- /*
- * calentool.c
- *
- * calentool - a year/month/week/day-at-a-glance calendar for Sun workstations.
- *
- * Author: Philip Heller, Sun Microsystems. Inc. <terrapin!heller@sun.com>
- *
- * Original source Copyright (C) 1987, Sun Microsystems, Inc.
- * All Rights Reserved
- * Permission is hereby granted to use and modify this program in source
- * or binary form as long as it is not sold for profit and this copyright
- * notice remains intact.
- *
- *
- * Changes/additions by: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
- *
- * Changes and additions Copyright (C) 1988, 1989 Tektronix, Inc.
- * All Rights Reserved
- * Permission is hereby granted to use and modify the modifications in source
- * or binary form as long as they are not sold for profit and this copyright
- * notice remains intact.
- */
- #include <stdio.h>
- #include <suntool/sunview.h>
- #include <suntool/panel.h>
- #include <sys/time.h>
- #include <sys/file.h>
- #include <signal.h>
- #include "ct.h"
-
- extern Pixfont *font, *sfont;
- extern char apts_pathname[], tmpapts_pathname[];
- extern char todays_date[];
- extern char version[];
- extern Panel_item clock_pi;
- extern Frame fframe;
- extern Panel panel;
- #ifndef NO_SUN_MOON
- extern Frame sframe;
- #endif
-
- Frame frame = 0;
- Pixwin *main_pixwin;
- int day_is_open;
- struct tm today, current;
- struct tm First, Last;
- struct tm olddate;
- int mainsw_state, selected_type;
- int x_coord, y_coord, startx, starty;
- int read_only;
- int nr_weekdays, dayslot_width, day_message_size, n_tslots;
- int week_message_size, weekslot_width, weekslot_height, dayslot_height;
- int ybox_height, ybox_width;
- struct dayslot slots[N_SLOTS];
- struct rect_limits boxlims[31];
- struct rect_limits mboxlims[12];
- struct week_arrow week_arrows[6];
- struct weekrect week_boxes[7];
- Pixrect *daybox_pr, *timeslot_pr, *gray_pr;
- Pixrect *weekslot_pr, *weekarrow_pr, *smallarrow_pr;
- Pixrect *arrowhead_pr, *arrowshaft_pr;
- Pixrect *weekarrowhead_pr, *weekarrowshaft_pr;
- Pixrect *triangle_pr;
- Pixrect *ydaybox_pr, *ymonthbox_pr;
- Pixrect *ic_pr, *rev_ic_pr, *na_ic_pr;
- Rect ilabel_rect = {1, 67, 62, 9}; /* location of timestring under icon */
- char *mailto = NULL;
- int one_based = 0, new_entry = 0, version2 = 0;
- int otherfile = 0;
- char *othername;
- int beep = 0, show_time = 0;
- int include_old = 0, save_old = 0;
- #ifndef NO_HOLIDAYS
- int holiday_a = 0, holiday_c = 0, holiday_i = 0;
- int holiday_j = 0, holiday_s = 0;
- #endif
- char *progname;
- struct itimerval cal_timer;
- int update_interval = 0;
- int show_future = 1;
- Icon icon, rev_icon, na_icon;
- Cursor year_cursor, month_cursor, week_cursor, day_cursor;
- Cursor wait_cursor;
- char orig_apts_pathname[160];
- int orig_ro;
- char timestr[16], datestr_day[3], datestr_mon[4];
- struct pr_prpos where;
- int working_msg;
-
- static short icon_data[] = {
- #include "std.icon"
- };
- static short rev_icon_data[] = {
- #include "rev.icon"
- };
- static short na_icon_data[] = {
- #include "nap.icon"
- };
- mpr_static(ic_mpr, 64, 64, 1, icon_data);
- mpr_static(rev_ic_mpr, 64, 64, 1, rev_icon_data);
- mpr_static(na_ic_mpr, 64, 64, 1, na_icon_data);
-
- static short year_cursor_data[] = {
- #include "year.cursor"
- };
- static short month_cursor_data[] = {
- #include "month.cursor"
- };
- static short week_cursor_data[] = {
- #include "week.cursor"
- };
- static short day_cursor_data[] = {
- #include "day.cursor"
- };
- static short wait_cursor_data[] = {
- #include <images/hglass.cursor>
- };
- mpr_static(year_cursor_pr, 16, 16, 1, year_cursor_data);
- mpr_static(month_cursor_pr, 16, 16, 1, month_cursor_data);
- mpr_static(week_cursor_pr, 16, 16, 1, week_cursor_data);
- mpr_static(day_cursor_pr, 16, 16, 1, day_cursor_data);
- mpr_static(wait_cursor_pr, 16, 16, 1, wait_cursor_data);
-
- #ifndef NO_SUN_MOON
- static short moon_icon_data[] = {
- #include "moony.icon"
- };
- static short sun_icon_data[] = {
- #include "sunny.icon"
- };
- mpr_static(moon_icon_pr, 64, 64, 1, moon_icon_data);
- mpr_static(sun_icon_pr, 64, 64, 1, sun_icon_data);
- #endif
-
- static short tri_up_data[] = {
- #include <images/tri_up.pr>
- };
- mpr_static(tri_up_pr, 16, 16, 1, tri_up_data);
-
- static short tri_right_data[] = {
- #include <images/tri_right.pr>
- };
- mpr_static(tri_right_pr, 16, 16, 1, tri_right_data);
-
- char *strcpy(), *strcat(), *rindex();
- static Notify_value cleanup(), itimer_handler();
- Notify_value myframe_interposer();
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int flag, i;
- int printit = 0, toolrunning = 1, user_pos = 0;
- extern char *optarg;
-
- if (progname = rindex(*argv, '/'))
- progname++;
- else
- progname = *argv;
-
- nr_weekdays = NR_WEEKDAYS;
- n_tslots = (N_TSLOTS > N_SLOTS ? N_SLOTS : N_TSLOTS);
-
- get_today(); /* initial day is today */
- current = today;
- read_only = 0;
- working_msg = 1;
-
- /*
- * Check for -p or -m option, which means we don't want
- * to create the tool. Also check for -Wp so we can supply
- * a resonable default if the user doesn't supply one.
- */
- i = argc;
- while (--i > 0) {
- if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "-m")
- || !strcmp(argv[i], "-P"))
- toolrunning = 0;
- if (!strcmp(argv[i], "-Wp"))
- user_pos = 1;
- }
- if (toolrunning) {
- /*
- ** Parse args: window_create must be called before getopt, so
- ** it can interpret and extract -W flags for SunView.
- */
- frame = window_create(NULL, FRAME,
- FRAME_ARGC_PTR_ARGV, &argc, argv,
- WIN_ERROR_MSG,
- "Can't create base frame. Are you in Suntools?",
- 0);
- }
-
- while ((flag = getopt(argc, argv, "57bd:f:im:opPrtu:zH:h:w")) != EOF)
- switch (flag) {
- case 'f': /* use this file */
- otherfile = 1;
- othername = optarg;
- break;
-
- case 'd': /* starting date */
- (void)parse_date(optarg, TRUE);
- break;
-
- case 'r': /* read only file */
- read_only = 1;
- break;
-
- case 'p': /* print and exit */
- read_only = 1;
- printit = 1;
- break;
-
- case 'P': /* print and exit (ignore some notes) */
- read_only = 1;
- printit = 3;
- break;
-
- case 'm': /* mail today's appts and exit */
- read_only = 1;
- printit = 2;
- mailto = optarg;
- break;
-
- case 'b': /* beep to console for pending appt */
- beep = 1;
- break;
-
- case 'i': /* include old appt files */
- include_old = 1;
- break;
-
- case 'o': /* save outdate appts to another file */
- save_old = 1;
- break;
-
- case 't': /* display current time under icon */
- show_time = 1;
- break;
-
- case '5': /* Mon - Fri week display */
- nr_weekdays = 5;
- break;
-
- case '7': /* Sun - Sat week display */
- nr_weekdays = 7;
- break;
-
- case 'u': /* update interval (in seconds) */
- update_interval = atoi(optarg);
- break;
-
- case 'w': /* don't display Working! message */
- working_msg = 0;
- break;
-
- case 'z': /* zero offset -- new style appts file */
- one_based = 1;
- break;
-
- #ifndef NO_HOLIDAYS
- case 'h':
- /* show certain holidays */
- switch (*optarg) {
- case 'A':
- /* all holidays */
- holiday_a = holiday_c = holiday_i = 1;
- holiday_j = holiday_s = 1;
- break;
- case 'a':
- /* astronomical events */
- holiday_a = 1;
- break;
- case 'c':
- /* Christian holidays */
- holiday_c = 1;
- break;
- case 'i':
- /* Islamic holidays */
- holiday_i = 1;
- break;
- case 'j':
- /* Jewish holidays */
- holiday_j = 1;
- break;
- case 's':
- /* secular holidays */
- holiday_s = 1;
- break;
- default:
- fprintf(stderr, "unknown holiday option (must be one of \"Aacijs\")");
- break;
- }
- break;
-
- case 'H':
- /* show certain holidays day/week display only */
- switch (*optarg) {
- case 'A':
- /* all holidays */
- holiday_a = holiday_c = holiday_i = 2;
- holiday_j = holiday_s = 2;
- break;
- case 'a':
- /* astronomical events */
- holiday_a = 2;
- break;
- case 'c':
- /* Christian holidays */
- holiday_c = 2;
- break;
- case 'i':
- /* Islamic holidays */
- holiday_i = 2;
- break;
- case 'j':
- /* Jewish holidays */
- holiday_j = 2;
- break;
- case 's':
- /* secular holidays */
- holiday_s = 2;
- break;
- default:
- fprintf(stderr, "unknown holiday option (must be one of \"Aacijs\")");
- break;
- }
- break;
- #else
- case 'h':
- case 'H':
- fprintf(stderr, "-h and -H options not available\n");
- break;
- #endif
- case '?':
- default:
- fprintf(stderr, "usage: %s [options...]\nwhere <options> are:\n", progname);
- fprintf(stderr, " -f <appointment_file>\n");
- fprintf(stderr, " -r // readonly\n");
- fprintf(stderr, " -p // print selected days appts and exit\n");
- fprintf(stderr, " -P // like -p, only don't print marked notes\n");
- fprintf(stderr, " -m <user> // mail selected days appts to <user>\n");
- fprintf(stderr, " [-5|-7] // 5-day or 7-day week display\n");
- fprintf(stderr, " -d <date> // display appts for <date>\n");
- fprintf(stderr, " -b // beep and display message when appt is pending\n");
- fprintf(stderr, " -i // auto-include outdated appts files\n");
- fprintf(stderr, " -o // create outdated include files\n");
- fprintf(stderr, " -t // display time below icon\n");
- fprintf(stderr, " -u <interval> // time update interval (seconds)\n");
- fprintf(stderr, " -w // don't display 'Working!' message\n");
- #ifndef NO_HOLIDAYS
- fprintf(stderr, " -h <Aacijs> // display selected computed holidays\n");
- fprintf(stderr, " // A=All, a=astronomical, c=Christian,\n");
- fprintf(stderr, " // i=Islamic, j=Jewish, s=secular\n");
- fprintf(stderr, " -H <Aacijs> // like -h, only flag them as marked\n");
- #endif
- fprintf(stderr, " -z // conversion flag (see INSTALL)\n");
- fprintf(stderr, " <window_opts> // Suntools -W options\n");
- exit(1);
- break;
- }
-
-
- if (toolrunning) {
- (void) notify_set_signal_func(frame, cleanup, SIGHUP, NOTIFY_ASYNC);
- (void) notify_set_signal_func(frame, cleanup, SIGINT, NOTIFY_ASYNC);
- (void) notify_set_signal_func(frame, cleanup, SIGTERM, NOTIFY_ASYNC);
- }
-
- /*
- ** Find the calendar file, etc.
- */
- if (do_files(FALSE))
- /* can't open (or create) appts file */
- exit(1);
- strcpy(orig_apts_pathname, apts_pathname);
- orig_ro = read_only;
- get_printer();
-
- if (printit) {
- print_apts(printit);
- exit(0);
- }
-
- get_fonts();
-
- if (!update_interval) {
- if (!strcmp(UPDATE_RATE, "minute"))
- update_interval = 60;
- else if (!strcmp(UPDATE_RATE, "second"))
- update_interval = 1; /* check in 1 sec */
- else {
- err_rpt("unknown update interval, defaulting to seconds", NON_FATAL);
- update_interval = 1; /* check in 1 sec */
- }
- }
-
- /* create the cursors */
- year_cursor = cursor_create(CURSOR_IMAGE, &year_cursor_pr,
- CURSOR_XHOT, 7, CURSOR_YHOT, 7,
- CURSOR_OP, PIX_SRC^PIX_DST,
- 0);
- month_cursor = cursor_create(CURSOR_IMAGE, &month_cursor_pr,
- CURSOR_XHOT, 7, CURSOR_YHOT, 7,
- CURSOR_OP, PIX_SRC^PIX_DST,
- 0);
- week_cursor = cursor_create(CURSOR_IMAGE, &week_cursor_pr,
- CURSOR_XHOT, 7, CURSOR_YHOT, 7,
- CURSOR_OP, PIX_SRC^PIX_DST,
- 0);
- day_cursor = cursor_create(CURSOR_IMAGE, &day_cursor_pr,
- CURSOR_XHOT, 7, CURSOR_YHOT, 7,
- CURSOR_OP, PIX_SRC^PIX_DST,
- 0);
- wait_cursor = cursor_create(CURSOR_IMAGE, &wait_cursor_pr,
- CURSOR_XHOT, 7, CURSOR_YHOT, 7,
- CURSOR_OP, PIX_SRC^PIX_DST,
- 0);
-
- /* create the icons */
- /*
- * make the icon big enough to display the time
- * underneath the base icon image if -t option
- */
- ic_pr = mem_create(64, (show_time ? 77 : 64), 1);
- rev_ic_pr = mem_create(64, (show_time ? 77 : 64), 1);
- na_ic_pr = mem_create(64, (show_time ? 77 : 64), 1);
- icon = icon_create(0);
- rev_icon = icon_create(0);
- na_icon = icon_create(0);
- strncpy(datestr_mon, todays_date+4, 3);
- datestr_mon[3] = '\0';
- strncpy(datestr_day, todays_date+8, 2);
- datestr_day[2] = '\0';
- /* the basic standard icon */
- pr_rop(ic_pr, 0, 0, 64, 64, PIX_SRC, &ic_mpr, 0, 0);
- if (show_time) {
- /* time string displayed below icon */
- strcpy(timestr, todays_date+10);
- if (update_interval == 60) {
- /* display hh:mm */
- timestr[6] = '\0';
- ilabel_rect.r_left += 2*sfont->pf_defaultsize.x - 2;
- ilabel_rect.r_width -= 2*sfont->pf_defaultsize.x;
- } else
- /* display hh:mm:ss */
- timestr[9] = '\0';
- /* draw a box around the time appendage */
- pr_vector(ic_pr, 0, 64, 63, 64, PIX_SET, 1);
- pr_vector(ic_pr, 63, 64, 63, 76, PIX_SET, 1);
- pr_vector(ic_pr, 63, 76, 0, 76, PIX_SET, 1);
- pr_vector(ic_pr, 0, 76, 0, 64, PIX_SET, 1);
-
- pr_rop(rev_ic_pr, 0, 0, 64, 77, PIX_SRC, ic_pr, 0, 0);
- pr_rop(rev_ic_pr, 0, 0, 64, 64, PIX_SRC, &rev_ic_mpr, 0, 0);
- pr_rop(na_ic_pr, 0, 0, 64, 77, PIX_SRC, ic_pr, 0, 0);
- pr_rop(na_ic_pr, 0, 0, 64, 64, PIX_SRC, &na_ic_mpr, 0, 0);
- } else {
- pr_rop(rev_ic_pr, 0, 0, 64, 64, PIX_SRC, &rev_ic_mpr, 0, 0);
- pr_rop(na_ic_pr, 0, 0, 64, 64, PIX_SRC, &na_ic_mpr, 0, 0);
- }
- /* add in the date */
- where.pr = ic_pr;
- where.pos.x = 13;
- where.pos.y = 49 + 5;
- pf_ttext(where, PIX_NOT(PIX_SRC), sfont, datestr_day);
- where.pr = na_ic_pr;
- pf_ttext(where, PIX_NOT(PIX_SRC), sfont, datestr_day);
- where.pr = rev_ic_pr;
- pf_ttext(where, PIX_SRC, sfont, datestr_day);
- where.pos.x = 39;
- where.pr = ic_pr;
- pf_ttext(where, PIX_NOT(PIX_SRC), sfont, datestr_mon);
- where.pr = na_ic_pr;
- pf_ttext(where, PIX_NOT(PIX_SRC), sfont, datestr_mon);
- where.pr = rev_ic_pr;
- pf_ttext(where, PIX_SRC, sfont, datestr_mon);
- (void)icon_init_from_pr(icon, ic_pr);
- (void)icon_init_from_pr(rev_icon, rev_ic_pr);
- (void)icon_init_from_pr(na_icon, na_ic_pr);
- if (show_time) {
- /* add label field */
- icon_set(icon, ICON_LABEL_RECT, &ilabel_rect,
- ICON_LABEL, timestr,
- ICON_FONT, sfont,
- 0);
- icon_set(rev_icon, ICON_LABEL_RECT, &ilabel_rect,
- ICON_LABEL, timestr,
- ICON_FONT, sfont,
- 0);
- icon_set(na_icon, ICON_LABEL_RECT, &ilabel_rect,
- ICON_LABEL, timestr,
- ICON_FONT, sfont,
- 0);
- }
-
- week_message_size = WEEK_MESSAGE_SIZE;
- weekslot_width = (font->pf_defaultsize.x * week_message_size) + 6;
- dayslot_width = (nr_weekdays - 1) * weekslot_width;
- day_message_size = dayslot_width / font->pf_defaultsize.x;
- ybox_height = dayslot_height = weekslot_height = font->pf_defaultsize.y + 6;
- ybox_width = 3 * font->pf_defaultsize.x;
-
- init_pixrects(); /* Initialize pictures. */
-
- /* Create the rest of the tool */
- if (user_pos)
- window_set(frame,
- WIN_WIDTH, (nr_weekdays+1)*weekslot_width+40,
- WIN_HEIGHT, (N_SLOTS+5)*weekslot_height+72,
- FRAME_ICON, icon,
- 0);
- else
- /* supply default position */
- window_set(frame,
- WIN_WIDTH, (nr_weekdays+1)*weekslot_width+40,
- WIN_HEIGHT, (N_SLOTS+5)*weekslot_height+72,
- WIN_X, 100, WIN_Y, 56,
- FRAME_ICON, icon,
- 0);
-
- create_panel();
- create_main_window();
- create_attr_frame(); /* normally hidden */
- create_del_frame(); /* normally hidden */
- create_file_frame(); /* normally hidden */
- create_date_frame(); /* normally hidden */
- #ifndef NO_PRINTER
- create_print_frame(); /* normally hidden */
- #endif
- check_calendar(); /* set proper icon */
-
- /* interpose on frame events (specifically open/close) */
- (void) notify_interpose_event_func(frame, myframe_interposer, NOTIFY_SAFE);
- /**
- (void) notify_interpose_event_func(panel, myframe_interposer, NOTIFY_SAFE);
- **/
-
- timerclear(&(cal_timer.it_interval));
- timerclear(&(cal_timer.it_value));
- cal_timer.it_value.tv_sec = (long)update_interval;
- cal_timer.it_value.tv_usec = 0L;
- (void) notify_set_itimer_func(frame, itimer_handler, ITIMER_REAL, &cal_timer, NULL);
-
- window_main_loop(frame);
-
- cleanup();
- }
-
-
- static Notify_value
- itimer_handler(me, which)
- Notify_client me;
- int which;
- {
- static int timeout_cntr = 0;
- Icon cur_icon;
-
- timerclear(&(cal_timer.it_interval));
- timerclear(&(cal_timer.it_value));
- cal_timer.it_value.tv_sec = (long)update_interval;
- cal_timer.it_value.tv_usec = 0L;
- (void) notify_set_itimer_func(frame, itimer_handler, ITIMER_REAL, &cal_timer, NULL);
- get_today();
- /* update date/time displayed in the panel */
- panel_set(clock_pi, PANEL_LABEL_STRING, todays_date, 0);
- if (show_time && (int)window_get(frame, FRAME_CLOSED)) {
- strcpy(timestr, todays_date+10);
- if (update_interval == 60)
- /* display hh:mm */
- timestr[6] = '\0';
- else
- /* display hh:mm:ss */
- timestr[9] = '\0';
- cur_icon = (Icon) window_get(frame, FRAME_ICON);
- icon_set(cur_icon, ICON_LABEL, timestr, 0);
- window_set(frame, FRAME_ICON, cur_icon, 0);
- }
- #ifndef NO_SUN_MOON
- /* update data in Sun Data frame (if it's open) */
- if (sframe)
- write_times();
- #endif
- /* only check appointments every TIME_OUT minutes */
- timeout_cntr += update_interval;
- if (timeout_cntr/60 < TIME_OUT)
- return(NOTIFY_DONE);
- timeout_cntr = 0;
- /* check todays appointments */
- check_calendar();
- return(NOTIFY_DONE);
- }
-
- /*
- * When timer has expired check to see if we are close to an
- * appointment. If so, switch to the other icon so we have a
- * visual indication and beep the console (if enabled).
- */
- check_calendar()
- {
- int appt_pending = 0; /* no appointments pending */
- int some_appts = 0; /* no appointments today */
- int slotno = 0; /* start with first timeslot */
- static int icon_in_use = STD_ICON;
- static int echoed_sno = -1;
- static int new_day = 0;
- int sno;
- Icon cur_icon;
- struct timeval gtime;
- struct timezone tz;
- struct tm Save;
- FILE *console, *msgf;
- char msgfile[128];
- char *getenv();
-
- sno = echoed_sno; /* assume no console echo */
- Save = current;
- strcpy(msgfile, getenv("HOME"));
- strcat(msgfile, "/.msgfile");
- /*
- * Check to see if we've run over into the next day. If so,
- * we need to update our slot information.
- */
- if (ymd_compare(current, today) != 0) {
- if (day_is_open)
- close_day();
- current = today;
- err2console(TRUE);
- get_day_appts();
- err2console(FALSE);
- day_is_open = TRUE;
- if (!new_day) {
- new_day++;
- sno = echoed_sno = -1;
- }
- } else
- new_day = 0;
- if (today.tm_hour >= START_HOUR) {
- slotno = (today.tm_hour - START_HOUR)*2 + today.tm_min/30;
- if (slotno < n_tslots) {
- if (slots[slotno].active != INACTIVE) {
- /* appointment is happening now */
- appt_pending++;
- if (slots[slotno].active == ACTIVE)
- sno = slotno;
- } else if (slotno+1 < n_tslots) {
- if (slots[slotno+1].active != INACTIVE)
- /* are we within 10 mins of an appointment? */
- if ((today.tm_min % 30) >= 20) {
- appt_pending++;
- if (slots[slotno+1].active == ACTIVE)
- sno = slotno+1;
- }
- }
- }
- }
- if (!appt_pending) {
- /*
- * Is there anything happening today (optionally
- * including memos)?
- * Don't care about things that happened before now
- * so start looking at <slotno>, which was set above to
- * reflect the current hour (or 0 if before START_HOUR).
- */
- /*
- * APPT_CHECK_LIMIT is typically either "n_tslots"
- * or "N_SLOTS" depending on whether we include the
- * notes section when indicating that we still have
- * appts today.
- */
- while (slotno < APPT_CHECK_LIMIT)
- if (slots[slotno++].active != INACTIVE) {
- some_appts++;
- break;
- }
- /* maybe change the icon */
- if ((some_appts && (icon_in_use != STD_ICON)) ||
- (!some_appts && (icon_in_use != NA_ICON))) {
- window_set(frame,
- FRAME_ICON, (some_appts?
- icon : na_icon),
- 0);
- icon_in_use = some_appts ? STD_ICON : NA_ICON;
- }
- /* clean out the ~/.msgfile file */
- if (beep && ((msgf = fopen(msgfile, "w")) != NULL)) {
- fprintf(msgf, "I'm out running around.");
- fclose(msgf);
- }
- } else {
- /* notify the user via the console (once) ... */
- if (beep && sno != echoed_sno) {
- echoed_sno = sno;
- window_bell(frame);
- if ((console = fopen("/dev/console", "w")) != NULL) {
- fprintf(console, "%s\n", slots[sno].cur_appt->str);
- fclose(console);
- }
- /*
- * also put a copy in ~/.msgfile, in case
- * nlock(1) is running
- */
- if ((msgf = fopen(msgfile, "w")) != NULL) {
- fprintf(msgf, "%s", slots[sno].cur_appt->str);
- fclose(msgf);
- }
- }
- /* ... and change the icon */
- if (icon_in_use != REV_ICON) {
- window_set(frame,
- FRAME_ICON, rev_icon,
- 0);
- icon_in_use = REV_ICON;
- }
- }
- if (new_day) {
- /* if we're iconic, then go ahead and update the current
- * day, otherwise restore it to what it was before.
- */
- if ((int)window_get(frame, FRAME_CLOSED)) {
- /* so that it opens on today */
- olddate = current = today;
- /* update date field of the icons */
- strncpy(datestr_mon, todays_date+4, 3);
- strncpy(datestr_day, todays_date+8, 2);
- /* replace the date */
- where.pr = ic_pr;
- where.pos.x = 13;
- where.pos.y = 49 + 5;
- pr_rop(where.pr, 14, 47, 10, 8, PIX_CLR, NULL, 0, 0);
- pr_rop(where.pr, 40, 47, 16, 8, PIX_CLR, NULL, 0, 0);
- pf_ttext(where, PIX_NOT(PIX_SRC), sfont, datestr_day);
- where.pr = na_ic_pr;
- pr_rop(where.pr, 14, 47, 10, 8, PIX_CLR, NULL, 0, 0);
- pr_rop(where.pr, 40, 47, 16, 8, PIX_CLR, NULL, 0, 0);
- pf_ttext(where, PIX_NOT(PIX_SRC), sfont, datestr_day);
- where.pr = rev_ic_pr;
- pr_rop(where.pr, 14, 47, 10, 8, PIX_SET, NULL, 0, 0);
- pr_rop(where.pr, 40, 47, 16, 8, PIX_SET, NULL, 0, 0);
- pf_ttext(where, PIX_SRC, sfont, datestr_day);
- where.pos.x = 39;
- where.pr = ic_pr;
- pf_ttext(where, PIX_NOT(PIX_SRC), sfont, datestr_mon);
- where.pr = na_ic_pr;
- pf_ttext(where, PIX_NOT(PIX_SRC), sfont, datestr_mon);
- where.pr = rev_ic_pr;
- pf_ttext(where, PIX_SRC, sfont, datestr_mon);
- icon_set(icon, ICON_IMAGE, ic_pr, 0);
- icon_set(rev_icon, ICON_IMAGE, rev_ic_pr, 0);
- icon_set(na_icon, ICON_IMAGE, na_ic_pr, 0);
- switch (icon_in_use) {
- case STD_ICON:
- window_set(frame, FRAME_ICON, icon, 0);
- break;
- case REV_ICON:
- window_set(frame, FRAME_ICON, rev_icon, 0);
- break;
- case NA_ICON:
- window_set(frame, FRAME_ICON, na_icon, 0);
- break;
- }
- new_day = 0;
- } else {
- if (day_is_open)
- close_day();
- current = Save;
- err2console(TRUE);
- get_day_appts();
- err2console(FALSE);
- day_is_open = TRUE;
- }
- show_future = 1; /* show future appts again */
- }
- }
-
- static Notify_value
- cleanup(me, signal, when)
- Notify_client me;
- int signal;
- Notify_signal_mode when;
- {
- if (day_is_open)
- close_day();
- if (access(tmpapts_pathname, R_OK) == 0 && unlink(tmpapts_pathname) < 0)
- perror(tmpapts_pathname);
- exit(0);
- /* NOTREACHED */
- return(NOTIFY_DONE);
- }
-