]> code.citadel.org Git - citadel.git/blobdiff - webcit/subst.c
* made wc_subst private. todo solved.
[citadel.git] / webcit / subst.c
index 394af9ab8dc56f59244ad50ca4c188ac01a6bd9b..3231c931e086dfd5157eaf35f6b95b107ef81612 100644 (file)
@@ -43,6 +43,20 @@ WCTemplputParams NoCtx;
 #define SV_SUBTEMPL 5
 #define SV_PREEVALUATED 6
 
+
+/*
+ * \brief Dynamic content for variable substitution in templates
+ */
+typedef struct _wcsubst {
+       ContextFilter Filter;
+       int wcs_type;                       /* which type of Substitution are we */
+       char wcs_key[32];                   /* copy of our hashkey for debugging */
+       StrBuf *wcs_value;                  /* if we're a string, keep it here */
+       long lvalue;                        /* type long? keep data here */
+       WCHandlerFunc wcs_function; /* funcion hook ???*/
+} wcsubst;
+
+
 typedef struct _WCTemplate {
        StrBuf *Data;
        StrBuf *FileName;
@@ -1311,6 +1325,10 @@ void *prepare_template(StrBuf *filename, StrBuf *Key, HashList *PutThere)
        NewTemplate->nTokensUsed = 0;
        NewTemplate->TokenSpace = 0;
        NewTemplate->Tokens = NULL;
+       NewTemplate->MimeType = NewStrBufPlain(GuessMimeByFilename (SKEY(NewTemplate->FileName)), -1);
+       if (strstr(ChrPtr(NewTemplate->MimeType), "text") != NULL) {
+               StrBufAppendBufPlain(NewTemplate->MimeType, HKEY("; charset=utf-8"), 0);
+       }
 
        Put(PutThere, ChrPtr(Key), StrLength(Key), NewTemplate, FreeWCTemplate);
        return NewTemplate;
@@ -1737,14 +1755,14 @@ void RegisterITERATOR(const char *Name, long len,
        Put(Iterators, Name, len, It, NULL);
 }
 
-/* typedef struct _iteratestruct {
+typedef struct _iteratestruct {
        int GroupChange;
        int oddeven;
        const char *Key;
        long KeyLen;
        int n;
        int LastN;
-       }IterateStruct; */
+       }IterateStruct; 
 
 void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP)
 {
@@ -1826,21 +1844,21 @@ void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP)
        SubTP.Filter.ControlContextType = CTX_ITERATE;
        SubTP.ControlContext = &Status;
        
+       if (HAVE_PARAM(2)) {
+               StartAt = GetTemplateTokenNumber(Target, TP, 2, 0);
+       }
        if (HAVE_PARAM(3)) {
-               StartAt = GetTemplateTokenNumber(Target, TP, 3, 0);
+               StepWidth = GetTemplateTokenNumber(Target, TP, 3, 0);
        }
        if (HAVE_PARAM(4)) {
-               StepWidth = GetTemplateTokenNumber(Target, TP, 4, 0);
-       }
-       if (HAVE_PARAM(5)) {
-               StopAt = GetTemplateTokenNumber(Target, TP, 5, -1);
+               StopAt = GetTemplateTokenNumber(Target, TP, 4, -1);
        }
+       it = GetNewHashPos(List, StepWidth);
        if (StopAt < 0) {
-               StopAt = GetCount(List)  + 1;
+               StopAt = GetCount(List);
        }
-       it = GetNewHashPos(List, StepWidth);
        while (GetNextHashPos(List, it, &Status.KeyLen, &Status.Key, &vContext)) {
-               if ((Status.n > StartAt) && (Status.n < StopAt)) {
+               if ((Status.n >= StartAt) && (Status.n <= StopAt)) {
                        if (DetectGroupChange && Status.n > 0) {
                                Status.GroupChange = (SortBy->GroupChange(vContext, vLastContext))? 1:0;
                        }