/* * Format the appointment in the character array passed (assumed to be pointing * to allocated space) to contain the time followed by the what string. The * appointment string is truncated at "max" chars or at DEFAULT_APPT_LEN if * max is 0. */ extern void format_appt(Dtcm_appointment *appt, char *b, DisplayType display, int max) { int hr, mn, len, i = 0, j = 0; Tick tick; struct tm *tm; register char *what_ptr; _Xltimeparams localtime_buf; if (!appt || !b) return; _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick); tm = _XLocaltime(&tick, localtime_buf); hr = tm->tm_hour; mn = tm->tm_min; if (showtime_set(appt) && !magic_time(tick)) { if (display == HOUR12) { adjust_hour(&hr); sprintf(b, "%2d:%02d ", hr, mn); } else sprintf(b, "%02d%02d ", hr, mn); i = cm_strlen(b); } if (appt->what->value->item.string_value) { if (max <= 0) max = DEFAULT_APPT_LEN; len = max - i; what_ptr = appt->what->value->item.string_value; while ((i < len) && *what_ptr != '\n' && *what_ptr) b[i++] = *what_ptr++; b[i] = '\0'; } }
/* * This sends the new list of names to the properties database. Note it ignores * items that have been tagged for deletion. */ static void blist_write_list(Browselist *bl, Props *p) { int i, len = 0; char *buf; BlistData *bd; /* * First pass, count the number of bytes we're going to need */ for (i = 1; i <= bl->blist_data->count; i++) { bd = (BlistData *)CmDataListGetData(bl->blist_data, i); if (bd && bd->name && bd->tag != BLIST_DELETE) len += cm_strlen(bd->name) + 2; /* one for spacing */ } if (len <= 0) return; /* * We have names, so build the string, making sure to exclude items * tagged for delete. */ buf = (char *)ckalloc(len); memset(buf, '\0', len); for (i = 1; i <= bl->blist_data->count; i++) { bd = (BlistData *)CmDataListGetData(bl->blist_data, i); if (bd && bd->name && bd->tag != BLIST_DELETE) { cm_strcat(buf, bd->name); cm_strcat(buf, " "); bd->tag = BLIST_ACTIVE; } } set_char_prop(p, CP_DAYCALLIST, buf); save_props(p); free(buf); }
static int paint_entry(Calendar *c, int x, int y, int maxchars, Paint_cache *cache_entry, XRectangle *rect) { XFontSetExtents fontextents; Props *p = (Props*)c->properties; int nlines = 0, dt = get_int_prop(p, CP_DEFAULTDISP); new_XContext *xc = c->xcontext; char buf1[50], buf2[WHAT_LEN+1]; Week *w = (Week *)c->view->week_info; Tick tick; /* * Write an appointment entry into a day */ if (maxchars >= 40) /* maxed out possible=40 */ maxchars = 40; buf1[0] = '\0'; buf2[0] = '\0'; format_entry(cache_entry, buf1, buf2, dt); tick = cache_entry->start_time; if (cache_entry->show_time && !magic_time(tick) && (buf1[0] != '\0')) { maxchars = gr_nchars(w->day_width - 5, buf1,c->fonts->boldfont); buf1[min(cm_strlen(buf1), maxchars)] = '\0'; gr_text(xc, x, y, c->fonts->boldfont, buf1, rect); nlines++; CalFontExtents(c->fonts->boldfont, &fontextents); y += fontextents.max_logical_extent.height;; } if (buf2[0] != '\0') { maxchars = gr_nchars(w->day_width - 5, buf2, c->fonts->viewfont); buf2[min(cm_strlen(buf2), maxchars)] = '\0'; gr_text(xc, x, y, c->fonts->viewfont, buf2, rect); nlines++; } return(nlines); }
/* * Format the appointment in the character array passed (assumed to be pointing * to allocated space) to contain the formatted string for the group * appointment editor. The string is truncated at "max" chars or at * DEFAULT_GAPPT_LEN if max is 0. */ extern void format_gappt(Dtcm_appointment *appt, char *name, char *b, DisplayType display, int max) { int hr, mn, i, j; Tick tick; char *what_ptr; struct tm *tm; _Xltimeparams localtime_buf; if (!appt || !b) return; _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick); if ((tick > 0) && !magic_time(tick) && showtime_set(appt)) { tm = _XLocaltime(&tick, localtime_buf); hr = tm->tm_hour; mn = tm->tm_min; if (display == HOUR12) { adjust_hour(&hr); sprintf(b, "%2d:%02d ", hr, mn); } else sprintf(b, "%02d%02d ", hr, mn); } else sprintf(b, "%6s", " "); if (max <= 0) max = DEFAULT_GAPPT_LEN; i = cm_strlen(b); j = 0; while (j < 10 && i < max && name && name[j]) b[i++] = name[j++]; while (j < 11 && i < max) b[i++] = ' ', ++j; if (i >= max) { b[i - 1] = '\0'; return; } b[i] = '\0'; if (appt->what->value->item.string_value) { what_ptr = appt->what->value->item.string_value; while (i < max && *what_ptr != '\n' && *what_ptr) b[i++] = *what_ptr++; b[i] = '\0'; } }
/* The following routine is specific to using FMapType 3 composite fonts * in postscript. Kanji, Asian specific? */ char * euc_to_octal(char *srcStr) { int inKanji = FALSE; char buf[64]; static char dstStr[512]; int i; int len = cm_strlen(srcStr); #ifdef SVR4 memset(dstStr, 0, sizeof(dstStr)); #else bzero(dstStr, sizeof(dstStr)); #endif /* SVR4 */ for (i = 0; i < len; i++) { if (inKanji) { if (!isEUC(srcStr[i])) { inKanji = FALSE; /* NOT NEEDED FOR FMapType 4 (or 5) cm_strcat(dstStr, "\\377\\000"); */ } } else { if (isEUC(srcStr[i])) { inKanji = TRUE; /* NOT NEEDED FOR FMapType 4 (or 5) cm_strcat(dstStr, "\\377\\001"); */ } } if (inKanji) { sprintf(buf, "\\%3.3o\\%3.3o", srcStr[i] & 0xff, srcStr[i+1] & 0xff); i++; } else { sprintf(buf, "%c", srcStr[i]); } cm_strcat(dstStr, buf); } return dstStr; }
/* * Format 2 lines of appt data */ extern void format_line2(Dtcm_appointment *appt, char *buf1, char *buf2, DisplayType display) { Tick tick, end_tick = 0; int hour1, min1, hour2, min2; Lines *lines; char *s1, *s2; struct tm *tm; _Xltimeparams localtime_buf; _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick); if (appt->end_time) _csa_iso8601_to_tick(appt->end_time->value->item.string_value, &end_tick); /* * Extract an appointment and format it into 2 lines of no more * then maxchars */ *buf1 = *buf2 = NULL; if (appt == NULL || appt->what->value->item.string_value == NULL) return; tm = _XLocaltime(&tick, localtime_buf); hour1 = tm->tm_hour; min1 = tm->tm_min; if (!showtime_set(appt) || magic_time(tick)) { lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 1); if (lines==NULL) return; strncpy(buf2, lines->s, 256); destroy_lines(lines); return; } s1 = s2 = "am"; if (display == HOUR12 && !adjust_hour(&hour1)) s1="pm"; if (end_tick) { hour2 = hour(end_tick); min2 = minute(end_tick); if (display == HOUR12 && !adjust_hour(&hour2)) s2="pm"; } if (end_tick == 0 || (hour1 == hour2 && min1 == min2 && (strcmp(s1, s2) == 0))) { if (display == HOUR24) sprintf(buf1, "%02d%.2d", hour1, min1); else sprintf(buf1, "%d:%.2d%s", hour1, min1, s1); } else { if (display == HOUR12) sprintf(buf1, "%d:%.2d%s-%d:%.2d%s", hour1, min1, s1, hour2, min2, s2); else sprintf(buf1, "%02d%02d-%02d%02d", hour1, min1, hour2, min2); } lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 1); if (lines == NULL || lines->s == NULL || (cm_strlen(lines->s) == 1 && lines->s[0] == ' ')) buf2[0] = NULL; else sprintf(buf2, " %s", lines->s); destroy_lines(lines); }
/* * Format 2 lines of appt data */ extern void format_maxchars(Dtcm_appointment *appt, char *buf1, int maxchars, DisplayType display) { Tick tick, end_tick = 0; int hour1, min1, hour2, min2; Lines *lines; char *s1, *s2; struct tm *tm; _Xltimeparams localtime_buf; _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick); if (appt->end_time) _csa_iso8601_to_tick(appt->end_time->value->item.string_value, &end_tick); *buf1 = NULL; if (appt == NULL || appt->what->value->item.string_value == NULL) return; tm = _XLocaltime(&tick, localtime_buf); hour1 = tm->tm_hour; min1 = tm->tm_min; if (showtime_set(appt) && !magic_time(tick)) { s1 = s2 = "am"; if (display == HOUR12 && !adjust_hour(&hour1)) s1="pm"; if (end_tick) { hour2 = hour(end_tick); if (display == HOUR12 && !adjust_hour(&hour2)) s2="pm"; min2 = minute(end_tick); } if (end_tick == 0 || hour1 == hour2 && min1 == min2) { if (display == HOUR24) sprintf(buf1, "%02d%02d ", hour1, min1); else sprintf(buf1, "%d:%.2d%s ", hour1, min1, s1); } else { if (display == HOUR12) sprintf(buf1, "%d:%.2d%s-%d:%.2d%s ", hour1, min1, s1, hour2, min2, s2); else sprintf(buf1, "%02d%02d-%02d%02d ", hour1, min1, hour2, min2); } } lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 10); while (lines != NULL) { if ((cm_strlen(buf1) + cm_strlen(lines->s)) < (maxchars-2)) { cm_strcat(buf1, lines->s); lines = lines->next; if (lines != NULL) cm_strcat(buf1, " - "); } else { strncat(buf1, lines->s, (maxchars - cm_strlen(buf1)-1)); break; } } destroy_lines(lines); }
void main(int argc, char **argv) { int cnt, status = 0; char *date = NULL, *view = NULL, *target = NULL, *start = NULL, *end = NULL, *repeat = NULL, *numrepeat = NULL, *what = NULL, *uname, *loc; Props *p = NULL; CSA_entry_handle *list; CSA_session_handle c_handle; CSA_return_code stat; CSA_calendar_user csa_user; DisplayType dt; int version; char date_str[256]; #ifdef FNS char buf[256]; #endif init_time(); _DtEnvControl(DT_ENV_SET); /* set up environment variables */ setlocale(LC_ALL, ""); DT_catd = catopen(DTCM_CAT, NL_CAT_LOCALE); cm_tty_load_props(&p); dt = get_int_prop(p, CP_DEFAULTDISP); #ifdef FNS dtfns_init(); #endif if (argc > 1) { cm_args(argc,argv); /* parse command line */ if (cm_strlen(cm_target)) target = cm_target; else target = cm_get_credentials(); #ifdef FNS if (cmfns_use_fns(p)) { cmfns_lookup_calendar(target, buf, sizeof(buf)); target = buf; } #endif uname = cm_target2name(target); loc = cm_target2location(target); csa_user.user_name = target; csa_user.user_type = 0; csa_user.calendar_user_extensions = NULL; csa_user.calendar_address = target; stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL); if (stat != CSA_SUCCESS) { char *format = cm_strdup(catgets(DT_catd, 1, 206, "\nCould not open calendar %s\n")); fprintf(stderr, format, target ? target : catgets(DT_catd, 1, 209, "UNKNOWN")); free(format); free(uname); free(loc); exit(1); } version = get_data_version(c_handle); if (!cm_date[0]) format_tick(now(), get_int_prop(p, CP_DATEORDERING), get_int_prop(p, CP_DATESEPARATOR), cm_date); if (cm_strlen(cm_date)) date = cm_date; if (cm_strlen(cm_view)) view = cm_view; if (cm_strlen(cm_start)) start = cm_start; if (!cm_end[0] && cm_start[0]) { format_time((int)cm_getdate(cm_start, NULL) + hrsec, dt, cm_end); } if (cm_strlen(cm_end)) end = cm_end; if (cm_strlen(cm_repeatstr)) repeat = cm_repeatstr; if (cm_strlen(cm_for)) numrepeat = cm_for; if (cm_strlen(cm_what)) what = cm_what; if (!cm_appt_file[0]) status = cm_tty_insert(DT_catd, c_handle, version, date, start, end, repeat, numrepeat, what, NULL, p); else status = cm_tty_insert(DT_catd, c_handle, version, date, start, end, repeat, numrepeat, what, cm_appt_file, p); } else { prompt_for_insert(p); if (cm_strlen(cm_target)) target = cm_target; uname = cm_target2name(target); loc = cm_target2location(target); csa_user.user_name = target; csa_user.user_type = 0; csa_user.calendar_user_extensions = NULL; csa_user.calendar_address = target; stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL); if (stat !=CSA_SUCCESS) { char *format = cm_strdup(catgets(DT_catd, 1, 206, "\nCould not open calendar %s\n")); fprintf(stderr, format, target ? target : catgets(DT_catd, 1, 209, "UNKNOWN")); free(format); free(uname); free(loc); exit(1); } version = get_data_version(c_handle); if (cm_strlen(cm_date)) date = cm_date; if (cm_strlen(cm_view)) view = cm_view; if (cm_strlen(cm_start)) start = cm_start; if (cm_strlen(cm_end)) end = cm_end; if (cm_strlen(cm_repeatstr)) repeat = cm_repeatstr; if (cm_strlen(cm_for)) numrepeat = cm_for; if (cm_strlen(cm_what)) what = cm_what; status = cm_tty_insert(DT_catd, c_handle, version, date, start, end, repeat, numrepeat, what, NULL, p); } if ((cnt = cm_tty_lookup(DT_catd, c_handle, version, date, view, &list, p)) > 0) csa_free(list); csa_logoff(c_handle, NULL); props_clean_up(p); free(p); free(uname); free(loc); exit(status); }
int main(int argc, char **argv) { int cnt; char index[10], *target = NULL, *date = NULL, *view = NULL, *uname, *loc; Props *p = NULL; CSA_entry_handle *list; CSA_session_handle c_handle; CSA_return_code stat; CSA_calendar_user csa_user; int version; #ifdef FNS char buf[256]; #endif init_time(); setlocale(LC_ALL, ""); _DtEnvControl(DT_ENV_SET); /* set up environment variables */ DT_catd = catopen(DTCM_CAT, NL_CAT_LOCALE); cm_tty_load_props(&p); cm_args(argc,argv); /* parse command line */ target = (cm_strlen(cm_target)) ? cm_target : cm_get_credentials(); #ifdef FNS dtfns_init(); if (cmfns_use_fns(p)) { cmfns_lookup_calendar(target, buf, sizeof(buf)); target = buf; } #endif if (cm_strlen(cm_date)) date = cm_date; if (cm_strlen(cm_view)) view = cm_view; uname = cm_target2name(target); loc = cm_target2location(target); csa_user.user_name = target; csa_user.user_type = 0; csa_user.calendar_user_extensions = NULL; csa_user.calendar_address = target; stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL); if (stat != CSA_SUCCESS) { char *format = strdup(catgets(DT_catd, 1, 188, "\nCould not open calendar %s\n")); fprintf(stderr, format, target ? target : catgets(DT_catd, 1, 189, "UNKNOWN")); free(format); free(uname); free(loc); exit(1); } version = get_data_version(c_handle); while (!cm_index) { if ((cnt = cm_tty_lookup(DT_catd, c_handle, version, date, view, &list, p)) <= 0) { csa_logoff(c_handle, NULL); free(uname); free(loc); exit(0); } fprintf(stdout, catgets(DT_catd, 1, 190, "Item to delete (number)? ")); fgets(index, 9, stdin); fprintf(stdout,"\n\n"); if (*index < '0' || *index > '9') { csa_free(list); break; } cm_index = atoi(index); if (cnt >= cm_index) cm_tty_delete(DT_catd, c_handle, version, cm_index - 1, list); memset(index, '\0', 10); csa_free(list); cm_index = 0; } csa_logoff(c_handle, NULL); props_clean_up(p); free(p); free(uname); free(loc); return 0; }
static void paint_dayview_appts(Calendar *c, Paint_cache *cache, int a_total, void *rect) { int w = c->view->boxw; int h = c->view->boxh; int begin_time, end_time; int x, x2, y, y2, num_hrs, i, last_hr, hr, x_off; Cal_Font *pf = c->fonts->boldfont; Cal_Font *pf2 = c->fonts->viewfont; XFontSetExtents fontextents; XFontSetExtents fontextents2; Props *p = (Props*)c->properties; Boolean am = True; char buf[5], *appt_str; int pfy, curr_line, maxlines; Lines *lines = NULL, *headlines = NULL; DisplayType disp_t; Colormap cmap; Pixel fg; Tick start_tick, end_tick; int nop, hrbox_margin; CalFontExtents(pf, &fontextents); CalFontExtents(pf2, &fontextents2); XtVaGetValues(c->canvas, XmNcolormap, &cmap, XmNforeground, &fg, NULL); /* draw horizontal lines */ begin_time = get_int_prop(p, CP_DAYBEGIN); end_time = get_int_prop(p, CP_DAYEND); disp_t = get_int_prop(p, CP_DEFAULTDISP); num_hrs = end_time - begin_time + 1; if (disp_t == HOUR12) CalTextExtents(pf, "12pm", 4, &nop, &nop, &hrbox_margin, &nop); else CalTextExtents(pf, "24 ", 3, &nop, &nop, &hrbox_margin, &nop); x = MOBOX_AREA_WIDTH+2; x2 = x + w; y = c->view->topoffset; for (i = 0; i <= num_hrs; i++) { gr_draw_line(c->xcontext, x, y, x2, y, gr_solid, rect); y += h; } /* draw vertical line */ y = c->view->topoffset; y2 = y + num_hrs * h; x += hrbox_margin; gr_draw_line(c->xcontext, x, y, x, y2, gr_solid, rect); x = MOBOX_AREA_WIDTH+3; y += h/2+4; /* draw in hours */ for (i = begin_time - 1; i < end_time; i++) { hr = i; if (i < begin_time) (void) sprintf(buf, ""); else if (disp_t == HOUR12) { am = adjust_hour(&hr); (void) sprintf(buf, "%d%s", hr, am ? "a" : "p"); } else (void) sprintf(buf, "%02d", hr); x_off = gr_center(hrbox_margin, buf, pf); /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x+x_off, y, pf, buf, fg, cmap, rect); else */ gr_text(c->xcontext, x+x_off, y, pf, buf, rect); y += h; } /* draw in appointments */ x = MOBOX_AREA_WIDTH + hrbox_margin + 6; pfy = fontextents2.max_logical_extent.height; maxlines = (h - 6) / pfy; curr_line = last_hr = 0; /* loop thru, getting out the "no time" appointments */ for (i = 0; i < a_total; i++) { if (i != a_total) last_hr = hr; hr = begin_time; if (cache[i].show_time == 0) { if (last_hr != hr) curr_line = 0; y = c->view->topoffset + 2 + pfy; if (curr_line < maxlines) { y += (curr_line * pfy) + h * (hr - begin_time); headlines = lines = text_to_lines(cache[i].summary, 4); start_tick = cache[i].start_time; end_tick = cache[i].end_time; if (lines != NULL && lines->s != NULL) { appt_str = ckalloc(cm_strlen(lines->s)+18); format_line(start_tick, lines->s, appt_str, end_tick, cache[i].show_time, disp_t); lines = lines->next; } else { appt_str = ckalloc(15); format_line(start_tick, (char*)NULL, appt_str, end_tick, cache[i].show_time, disp_t); } appt_str[cm_strlen(appt_str)]=NULL; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); free(appt_str); appt_str = NULL; curr_line++; if (curr_line < maxlines && lines != NULL) { appt_str = ckalloc(324); cm_strcpy(appt_str, " "); while (lines != NULL) { if (lines->s != NULL) cm_strcat(appt_str, lines->s); lines = lines->next; if (lines != NULL && lines->s != NULL) cm_strcat(appt_str, " - "); } y += pfy; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); curr_line++; free(appt_str); appt_str = NULL; } destroy_lines(headlines); lines=NULL; } } } for (i = 0; i < a_total; i++) { if (i != a_total) last_hr = hr; start_tick = cache[i].start_time; end_tick = cache[i].end_time; hr = hour(start_tick); if (hr >= begin_time && hr < end_time && (cache[i].show_time && !magic_time(start_tick))) { if (last_hr != hr) curr_line = 0; y = c->view->topoffset + 2 + pfy; if (curr_line < maxlines) { y += (curr_line * pfy) + h * (hr - begin_time + 1); headlines = lines = text_to_lines(cache[i].summary, 4); if (lines != NULL && lines->s != NULL) { appt_str = ckalloc(cm_strlen(lines->s)+18); format_line(start_tick, lines->s, appt_str, end_tick, cache[i].show_time, disp_t); lines = lines->next; } else { appt_str = ckalloc(15); format_line(start_tick, (char*)NULL, appt_str, end_tick, cache[i].show_time, disp_t); } appt_str[cm_strlen(appt_str)]=NULL; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); free(appt_str); appt_str = NULL; curr_line++; if (curr_line < maxlines && lines != NULL) { appt_str = ckalloc(324); cm_strcpy(appt_str, " "); while (lines != NULL) { if (lines->s != NULL) cm_strcat(appt_str, lines->s); lines = lines->next; if (lines != NULL && lines->s != NULL) cm_strcat(appt_str, " - "); } y += pfy; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); curr_line++; free(appt_str); appt_str = NULL; } destroy_lines(headlines); lines=NULL; } } } }
static void draw_week(Calendar *c, XRectangle *rect, Boundary boundary) { Week *w = (Week *)c->view->week_info; register int current_day; register int n; register int x, y; int char_height; int start_date; char **day_names; char label[80]; char buf[MAXNAMELEN]; char *footer_message = NULL; int start_ind, end_ind; int today_dom, day_om; new_XContext *xc; Props *p = (Props*)c->properties; XRectangle chartrect; OrderingType ot = get_int_prop(p, CP_DATEORDERING); Tick start_tick, end_tick; time_t start, stop; CSA_return_code stat; CSA_entry_handle *list; CSA_attribute *range_attrs; CSA_enum *ops; CSA_uint32 a_total; int i, lower_bound = 0, upper_bound = 0; XFontSetExtents regfontextents, boldfontextents; int notused, width1, width2, width3; CalFontExtents(w->font, ®fontextents); char_height = regfontextents.max_logical_extent.height; start_date = w->start_date; xc = c->xcontext; start = (time_t) lowerbound(start_date); stop = (time_t) next_ndays(start, 7) - 1; if (c->paint_cache == NULL) { setup_range(&range_attrs, &ops, &i, start, stop, CSA_TYPE_EVENT, 0, B_FALSE, c->general->version); csa_list_entries(c->cal_handle, i, range_attrs, ops, &a_total, &list, NULL); free_range(&range_attrs, &ops, i); allocate_paint_cache(list, a_total, &c->paint_cache); c->paint_cache_size = a_total; csa_free(list); } gr_clear_box(xc, 0, 0, w->canvas_w, w->canvas_h); CalTextExtents(w->font, days2[3], cm_strlen(days2[3]), ¬used, ¬used, &width1, ¬used); CalTextExtents(w->font, " 00", cm_strlen(" 00"), ¬used, ¬used, &width2, ¬used); CalTextExtents(w->font, "Wed 00", cm_strlen("Wed 00"), ¬used, ¬used, &width3, ¬used); if (width1 + width2 <= w->day_width - 2) day_names = days2; else if (width3 <= w->day_width - 2) day_names = days; else day_names = days3; x = w->x; y = w->y; format_week_header(start_date, ot, label); gr_text(xc, x, y - char_height / 2, w->font, label, rect); /* * Draw bold box around first 5 days */ gr_draw_box(xc, x, y, w->width, w->day_height, rect); gr_draw_box(xc, x - 1, y - 1, w->width + 2, w->day_height + 2, rect); gr_draw_line(xc, x, y + w->label_height, x + w->width, y + w->label_height, gr_solid, rect); /* * Draw bold box around last 2 days */ x += 3 * w->day_width; y += w->day_height; gr_draw_box(xc, x, y, 2 * w->day_width, w->day_height, rect); gr_draw_box(xc, x - 1, y, 2 * w->day_width + 2, w->day_height + 1,rect); gr_draw_line(xc, x, y + w->label_height, x + 2 * w->day_width, y + w->label_height, gr_solid, rect); y = w->y; x = w->x + w->day_width; for (n = 0; n < 4; n++) { if (n < 3) { gr_draw_line(xc, x, y, x, y + w->day_height, gr_solid, rect); } else { gr_draw_line(xc, x, y, x, y + 2 * w->day_height, gr_solid, rect); } x += w->day_width; } /* * Fill in week with appointments */ x = w->x; y = w->y; current_day = start_date; today_dom = dom(time(0)); /* Crock alert!!!! The obscure code below is doing something really nasty. The variable boundary indicates whether the week being displayed falls across a boundary with the beginning or the end of time. In the case of the beginning of time, the code then assumes that the first 2 days in the week need to be unbuttoned, and the rest buttoned and painted. Likewise, with the end of time case, the code assumes the last 3 days of the week need similar treatment. */ for (n = 0; n < 7; n++) { if (n == 5) { y += w->day_height; x = w->x + 3 * w->day_width; } if (boundary == okay) { day_om = dom(current_day); display_hot_btn(c, n, day_om); fill_day(c, w, x, y, current_day, c->paint_cache, c->paint_cache_size, rect); current_day += daysec; if (lower_bound > 0) { sprintf(buf, "%s", catgets(c->DT_catd, 1, 623, "Calendar does not display dates prior to January 1, 1970")); footer_message = buf; } else footer_message = NULL; } else if (boundary == lower) { /* skip days before Jan 1, 1970 */ clear_hot_btn(c, n); if (lower_bound++ == 2) boundary = okay; } else if (boundary == upper) { day_om = dom(current_day); if (++upper_bound <= 4) display_hot_btn(c, n, day_om); fill_day(c, w, x, y, current_day, c->paint_cache, c->paint_cache_size, rect); current_day += daysec; sprintf(buf, "%s", catgets(c->DT_catd, 1, 624, "Calendar does not display dates after December 31, 2037")); footer_message = buf; if (upper_bound > 4) clear_hot_btn(c, n); } x += w->day_width; } if (rect != NULL) { CalFontExtents(w->small_bold_font, &boldfontextents); chartrect.x = w->x; chartrect.y = w->chart_y - w->label_height; chartrect.width = w->chart_width + 3*boldfontextents.max_logical_extent.width; chartrect.height = w->chart_height + 2*w->label_height; } if (rect == NULL || myrect_intersectsrect(rect, &chartrect)) { for (i = 0; i < c->paint_cache_size; i++) { start_tick = (c->paint_cache)[i].start_time; end_tick = (c->paint_cache)[i].end_time; cm_update_segs(w, start_tick, (end_tick ? (end_tick - start_tick) : 0), &start_ind, &end_ind, True); } chart_draw_appts(w, 0, w->segs_in_array); draw_chart(c, w, NULL); } /* do not repaint the footer message in a damage display. For some reason this causes the damage routine to get called again, resulting in a recursive dsaster. */ if (footer_message && !rect) set_message(c->message_text, footer_message); }
/* * Format 2 lines of appt data */ static void format_entry(Paint_cache *cache_entry, char *buf1, char *buf2, DisplayType display) { Tick tick, end_tick = 0; int hour1, min1, hour2, min2; Lines *lines; char *s1, *s2; struct tm *tm; _Xltimeparams localtime_buf; tick = cache_entry->start_time; end_tick = cache_entry->end_time; /* * Extract an appointment and format it into 2 lines of no more * then maxchars */ *buf1 = *buf2 = '\0'; if (cache_entry == NULL || cache_entry->summary == NULL) return; tm = _XLocaltime(&tick, localtime_buf); hour1 = tm->tm_hour; min1 = tm->tm_min; if (!cache_entry->show_time || magic_time(tick)) { lines = (Lines *) text_to_lines(cache_entry->summary, 1); if (lines==NULL) return; strncpy(buf2, lines->s, 256); destroy_lines(lines); return; } s1 = s2 = "am"; if (display == HOUR12 && !adjust_hour(&hour1)) s1="pm"; if (end_tick) { hour2 = hour(end_tick); min2 = minute(end_tick); if (display == HOUR12 && !adjust_hour(&hour2)) s2="pm"; } if (end_tick == 0 || (hour1 == hour2 && min1 == min2 && (strcmp(s1, s2) == 0))) { if (display == HOUR24) sprintf(buf1, "%02d%.2d", hour1, min1); else sprintf(buf1, "%d:%.2d%s", hour1, min1, s1); } else { if (display == HOUR12) sprintf(buf1, "%d:%.2d%s-%d:%.2d%s", hour1, min1, s1, hour2, min2, s2); else sprintf(buf1, "%02d%02d-%02d%02d", hour1, min1, hour2, min2); } lines = (Lines *) text_to_lines(cache_entry->summary, 1); if (lines == NULL || lines->s == NULL || (cm_strlen(lines->s) == 1 && lines->s[0] == ' ')) buf2[0] = '\0'; else sprintf(buf2, " %s", lines->s); destroy_lines(lines); }
int main(int argc, char **argv) { int cnt; char *target = NULL, *date = NULL, *view = NULL, *uname, *loc; Props *p = NULL; CSA_session_handle c_handle; CSA_entry_handle *list; CSA_return_code stat; CSA_calendar_user csa_user; int version; #ifdef FNS char buf[256]; #endif init_time(); _DtEnvControl(DT_ENV_SET); /* set up environment variables */ setlocale(LC_ALL, ""); DT_catd = catopen(DTCM_CAT, NL_CAT_LOCALE); cm_tty_load_props(&p); cm_args(argc,argv); /* parse command line */ target = (cm_strlen(cm_target)) ? cm_target : cm_get_credentials(); #ifdef FNS dtfns_init(); if (cmfns_use_fns(p)) { cmfns_lookup_calendar(target, buf, sizeof(buf)); target = buf; } #endif uname = cm_target2name(target); loc = cm_target2location(target); csa_user.user_name = target; csa_user.user_type = 0; csa_user.calendar_user_extensions = NULL; csa_user.calendar_address = target; stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL); if (stat != CSA_SUCCESS) { char *format = cm_strdup(catgets(DT_catd, 1, 208, "\nCould not open calendar \"%s\"\n")); fprintf(stderr, format, target ? target : catgets(DT_catd, 1, 209, "UNKNOWN")); free(format); free(uname); free(loc); exit(1); } version = get_data_version(c_handle); if (cm_strlen(cm_date)) date = cm_date; if (cm_strlen(cm_view)) view = cm_view; if ((cnt = cm_tty_lookup(DT_catd, c_handle, version, date, view, &list, p)) > 0) csa_free(list); csa_logoff(c_handle, NULL); props_clean_up(p); free(p); free(uname); free(loc); return 0; }