+ icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
+ icalproperty *p;
+ icalproperty_kind Kind;
+ const char *str;
+
+ Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 0, ICAL_ANY_PROPERTY);
+ p = icalcomponent_get_first_property(cal, Kind);
+ if (p != NULL) {
+ str = icalproperty_get_comment (p);
+ StrBufAppendTemplateStr(Target, TP, str, 1);
+ }
+}
+
+void tmplput_CtxICalProperty(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalproperty *p = (icalproperty *) CTX(CTX_ICALPROPERTY);
+ const char *str;
+
+ str = icalproperty_get_comment (p);
+ StrBufAppendTemplateStr(Target, TP, str, 0);
+}
+
+int ReleaseIcalSubCtx(StrBuf *Target, WCTemplputParams *TP)
+{
+ WCTemplputParams *TPP = TP;
+ UnStackContext(TP);
+ free(TPP);
+ return 0;
+}
+int cond_ICalIsA(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
+ icalcomponent_kind c = GetTemplateTokenNumber(Target, TP, 2, ICAL_NO_COMPONENT);
+ return icalcomponent_isa(cal) == c;
+}
+
+int cond_ICalHaveItem(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
+ icalproperty *p;
+ icalproperty_kind Kind;
+
+ Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 2, ICAL_ANY_PROPERTY);
+ p = icalcomponent_get_first_property(cal, Kind);
+ if (p != NULL) {
+ WCTemplputParams *DynamicTP;
+
+ DynamicTP = (WCTemplputParams*) malloc(sizeof(WCTemplputParams));
+ StackDynamicContext (TP,
+ DynamicTP,
+ p,
+ CTX_ICALPROPERTY,
+ 0,
+ TP->Tokens,
+ ReleaseIcalSubCtx,
+ TP->Tokens->Params[1]->lvalue);
+
+ return 1;
+ }
+ return 0;
+}
+
+int ReleaseIcalTimeCtx(StrBuf *Target, WCTemplputParams *TP)
+{
+ WCTemplputParams *TPP = TP;
+
+ UnStackContext(TP);
+ free(TPP);
+ return 0;
+}
+
+int cond_ICalHaveTimeItem(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
+ icalproperty *p;
+ icalproperty_kind Kind;
+
+ Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 2, ICAL_ANY_PROPERTY);
+ p = icalcomponent_get_first_property(cal, Kind);
+ if (p != NULL) {
+ struct icaltimetype *t;
+ struct icaltimetype tt;
+ WCTemplputParams *DynamicTP;
+
+ DynamicTP = (WCTemplputParams*) malloc(sizeof(WCTemplputParams) +
+ sizeof(struct icaltimetype));
+ t = (struct icaltimetype *) ((char*)DynamicTP) + sizeof(WCTemplputParams);
+ memset(&tt, 0, sizeof(struct icaltimetype));
+ switch (Kind)
+ {
+ case ICAL_DTSTART_PROPERTY:
+ tt = icalproperty_get_dtstart(p);
+ break;
+ case ICAL_DTEND_PROPERTY:
+ tt = icalproperty_get_dtend(p);
+ break;
+ default:
+ break;
+ }
+ memcpy(t, &tt, sizeof(struct icaltimetype));
+
+ StackDynamicContext (TP,
+ DynamicTP,
+ t,
+ CTX_ICALTIME,
+ 0,
+ TP->Tokens,
+ ReleaseIcalTimeCtx,
+ TP->Tokens->Params[1]->lvalue);
+
+ return 1;
+ }
+ return 0;
+}
+
+
+int cond_ICalTimeIsDate(StrBuf *Target, WCTemplputParams *TP)
+{
+ struct icaltimetype *t = (struct icaltimetype *) CTX(CTX_ICALTIME);
+ return t->is_date;
+}
+
+void tmplput_ICalTime_Date(StrBuf *Target, WCTemplputParams *TP)
+{
+ struct tm d_tm;
+ long len;
+ char buf[256];
+ struct icaltimetype *t = (struct icaltimetype *) CTX(CTX_ICALTIME);
+
+ memset(&d_tm, 0, sizeof d_tm);
+ d_tm.tm_year = t->year - 1900;
+ d_tm.tm_mon = t->month - 1;
+ d_tm.tm_mday = t->day;
+ len = wc_strftime(buf, sizeof(buf), "%x", &d_tm);
+ StrBufAppendBufPlain(Target, buf, len, 0);
+}
+void tmplput_ICalTime_Time(StrBuf *Target, WCTemplputParams *TP)
+{
+ long len;
+ char buf[256];
+ struct icaltimetype *t = (struct icaltimetype *) CTX(CTX_ICALTIME);
+ time_t tt;
+
+ tt = icaltime_as_timet(*t);
+ len = webcit_fmt_date(buf, sizeof(buf), tt, DATEFMT_FULL);
+ StrBufAppendBufPlain(Target, buf, len, 0);
+}