static int count_week_pages (Calendar *c, int lines_per_page, Tick start_date) { time_t start, stop; CSA_return_code stat; CSA_entry_handle *list; CSA_attribute *range_attrs; CSA_enum *ops; CSA_uint32 a_total; int num_appts, i, j, max = 0, pages; /* count the times and text of appts */ for (i = 1; i <= 7; i++) { /* setup a time limit for appts searched */ start = (time_t) lowerbound (start_date); stop = (time_t) next_ndays(start_date, 1) - 1; setup_range(&range_attrs, &ops, &j, start, stop, CSA_TYPE_EVENT, 0, B_FALSE, c->general->version); csa_list_entries(c->cal_handle, j, range_attrs, ops, &a_total, &list, NULL); free_range(&range_attrs, &ops, j); num_appts = count_multi_appts(list, a_total, c); if (num_appts > max) max = num_appts; start_date = nextday(start_date); csa_free(list); } pages = max / lines_per_page; if ((max % lines_per_page) > 0) pages++; return(pages); }
static Boolean _print_day(Calendar *c, int num_page, void *xp, Tick first_date, Props *p, Boolean first) { char buf[100]; int n, i, j, timeslots, num_appts, pages; int max = 0; int daybegin = get_int_prop(p, CP_DAYBEGIN); int dayend = get_int_prop(p, CP_DAYEND); OrderingType ord_t = get_int_prop(p, CP_DATEORDERING); Boolean more, done = False, all_done = True; char *location; CSA_return_code stat; CSA_entry_handle *list; CSA_attribute *range_attrs; CSA_enum *ops; CSA_uint32 a_total; time_t start, stop; int lines_per_page; static Tick tick = 0; static int total_pages = 0; /* * Need to find the max number of timeslots which will be shown * in one column, for later calculation of box height. */ if ((!morning(daybegin)) || dayend <= 12) timeslots = dayend - daybegin; else timeslots = ((12-daybegin) > (dayend-12)) ? (12-daybegin) : (dayend-12); x_init_printer(xp, PORTRAIT); x_init_day(xp, timeslots); lines_per_page = x_get_day_lines_per_page(xp); if (first) tick = first_date; if (num_page > 1) tick = prevday(tick); else total_pages = (lines_per_page > 0) ? count_day_pages(c, lines_per_page, tick) : 1; format_date(tick, ord_t, buf, 1, 0, 0); x_print_header(xp, buf, num_page, total_pages); x_day_header(xp); for (i=daybegin; i < dayend; i++) { start = (time_t) lower_bound(i, tick); stop = (time_t) next_nhours(start+1, 1) - 1; setup_range(&range_attrs, &ops, &j, start, stop, CSA_TYPE_EVENT, NULL, B_FALSE, c->general->version); csa_list_entries(c->cal_handle, j, range_attrs, ops, &a_total, &list, NULL); free_range(&range_attrs, &ops, j); num_appts = count_multi_appts(list, a_total, c); if ((lines_per_page > 0) && (num_appts > (lines_per_page * num_page))) more = True; else more = False; x_day_timeslots (xp, i, more); if (lines_per_page > 0) done = x_print_multi_appts (xp, list, a_total, num_page, dayGlance); else done = True; if (!done) all_done = False; csa_free(list); } x_finish_printer(xp); tick = nextday(tick); return(all_done); }
static Boolean print_week (Calendar *c, int num_page, void *xp, Tick first_date, Props *p, Boolean first) { Boolean more, done = False, all_done = True; int num_appts, day_of_week; char buf[128]; int i, j; OrderingType ot = get_int_prop(p, CP_DATEORDERING); time_t start, stop; CSA_return_code stat; CSA_entry_handle *list; CSA_attribute *range_attrs; CSA_enum *ops; CSA_uint32 a_total; int lines_per_page; static Tick start_date = 0; static int total_pages; static char *days[] = { (char *)NULL, (char *)NULL, (char *)NULL, (char *)NULL, (char *)NULL, (char *)NULL, (char *)NULL }; if (days[0] == (char *)NULL) { days[0] = XtNewString(catgets(c->DT_catd, 1, 596, "Monday %d")); days[1] = XtNewString(catgets(c->DT_catd, 1, 597, "Tuesday %d")); days[2] = XtNewString(catgets(c->DT_catd, 1, 598, "Wednesday %d")); days[3] = XtNewString(catgets(c->DT_catd, 1, 599, "Thursday %d")); days[4] = XtNewString(catgets(c->DT_catd, 1, 600, "Friday %d")); days[5] = XtNewString(catgets(c->DT_catd, 1, 601, "Saturday %d")); days[6] = XtNewString(catgets(c->DT_catd, 1, 602, "Sunday %d")); } x_init_printer(xp, LANDSCAPE); x_init_week(xp); lines_per_page = x_get_week_lines_per_page(xp); if (first) start_date = first_date; if (num_page > 1) { start_date = prevweek(start_date); if (!timeok(start_date)) start_date = get_bot(); } else total_pages = (lines_per_page > 0) ? count_week_pages(c, lines_per_page, start_date) : 1; format_week_header(start_date, ot, buf); x_print_header(xp, buf, num_page, total_pages); x_week_appt_boxes(xp); x_week_sched_boxes(xp); /* print the times and text of appts */ for (i = (dow(start_date) + 6) % 7; i < 7; i++) { /* print <Weekday DD> centered at top of appt box */ x_week_sched_init(xp); sprintf(buf, days[i], dom(start_date)); /* setup a time limit for appts searched */ start = (time_t) lowerbound (start_date); stop = (time_t) next_ndays(start_date, 1) - 1; setup_range(&range_attrs, &ops, &j, start, stop, CSA_TYPE_EVENT, 0, B_FALSE, c->general->version); csa_list_entries(c->cal_handle, j, range_attrs, ops, &a_total, &list, NULL); free_range(&range_attrs, &ops, j); num_appts = count_multi_appts(list, a_total, c); if ((lines_per_page > 0) && (num_appts > (lines_per_page * num_page))) more = True; else more = False; x_week_daynames(xp, buf, i, more); /* print out times and appts */ if (lines_per_page > 0) done = x_print_multi_appts(xp, list, a_total, num_page, weekGlance); else done = True; if (!done) all_done = False; x_week_sched_draw(xp, i); start_date = nextday(start_date); csa_free(list); } x_finish_printer(xp); return(all_done); }