]> code.citadel.org Git - citadel.git/blobdiff - webcit/tools.c
* Display PARTSTAT for attendees
[citadel.git] / webcit / tools.c
index 8bcccaed682a696b5d1703abd6ebec47cc741bdf..6912515cae5e1e73393c7ad88cbeb2a8de6d4977 100644 (file)
@@ -80,7 +80,7 @@ void extract_token(char *dest, char *source, int parmnum, char separator)
 
        if (strlen(source)==0) {
                return;
-               }
+       }
 
        for (i=0; i<strlen(source); ++i) {
                if (source[i]==separator) {
@@ -193,15 +193,41 @@ char ch;
  */
 void fmt_date(char *buf, time_t thetime) {
        struct tm *tm;
+       int hour;
 
        strcpy(buf, "");
        tm = localtime(&thetime);
+       hour = tm->tm_hour;
+       if (hour == 0) hour = 12;
+       else if (hour > 12) hour = hour - 12;
 
        sprintf(buf, "%s %d %d %2d:%02d%s",
                ascmonths[tm->tm_mon],
                tm->tm_mday,
                tm->tm_year + 1900,
-               ( (tm->tm_hour > 12) ? (tm->tm_hour - 12) : (tm->tm_hour) ),
+               hour,
+               tm->tm_min,
+               ( (tm->tm_hour > 12) ? "pm" : "am" )
+       );
+}
+
+
+
+/*
+ * Format TIME ONLY for output 
+ */
+void fmt_time(char *buf, time_t thetime) {
+       struct tm *tm;
+       int hour;
+
+       strcpy(buf, "");
+       tm = localtime(&thetime);
+       hour = tm->tm_hour;
+       if (hour == 0) hour = 12;
+       else if (hour > 12) hour = hour - 12;
+
+       sprintf(buf, "%d:%02d%s",
+               hour,
                tm->tm_min,
                ( (tm->tm_hour > 12) ? "pm" : "am" )
        );
@@ -262,4 +288,123 @@ char *memreadline(char *start, char *buf, int maxlen)
 
 
 
+/*
+ * pattern2()  -  searches for patn within search string, returns pos
+ */
+int pattern2(char *search, char *patn)
+{
+        int a;
+        for (a=0; a<strlen(search); ++a) {
+                if (!strncasecmp(&search[a],patn,strlen(patn))) return(a);
+                }
+        return(-1);
+        }
+
+
+/*
+ * Strip leading and trailing spaces from a string
+ */
+void striplt(char *buf)
+{
+        while ((strlen(buf) > 0) && (isspace(buf[0])))
+                strcpy(buf, &buf[1]);
+        while (isspace(buf[strlen(buf) - 1]))
+                buf[strlen(buf) - 1] = 0;
+}
+
+
+/*
+ * Determine whether the specified message number is contained within the
+ * specified set.
+ */
+int is_msg_in_mset(char *mset, long msgnum) {
+       int num_sets;
+       int s;
+       char setstr[SIZ], lostr[SIZ], histr[SIZ];       /* was 1024 */
+       long lo, hi;
+
+       /*
+        * Now set it for all specified messages.
+        */
+       num_sets = num_tokens(mset, ',');
+       for (s=0; s<num_sets; ++s) {
+               extract_token(setstr, mset, s, ',');
+
+               extract_token(lostr, setstr, 0, ':');
+               if (num_tokens(setstr, ':') >= 2) {
+                       extract_token(histr, setstr, 1, ':');
+                       if (!strcmp(histr, "*")) {
+                               snprintf(histr, sizeof histr, "%ld", LONG_MAX);
+                       }
+               } 
+               else {
+                       strcpy(histr, lostr);
+               }
+               lo = atol(lostr);
+               hi = atol(histr);
+
+               if ((msgnum >= lo) && (msgnum <= hi)) return(1);
+       }
+
+       return(0);
+}
+
+
+
+/*
+ * Read binary data from server into memory
+ */
+void read_server_binary(char *buffer, size_t total_len) {
+       char buf[SIZ];
+       size_t bytes = 0;
+       size_t thisblock = 0;
+
+       while (bytes < total_len) {
+               thisblock = 4095;
+               if ((total_len - bytes) < thisblock) {
+                       thisblock = total_len - bytes;
+               }
+               serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
+               serv_gets(buf);
+               if (buf[0] == '6') {
+                       thisblock = (size_t)atoi(&buf[4]);
+                       serv_read(&buffer[bytes], thisblock);
+                       bytes += thisblock;
+               }
+               else {
+                       wprintf("Error: %s<BR>\n", &buf[4]);
+               }
+       }
+}
+
+
+
+/*
+ * Strip a boundarized substring out of a string (for example, remove
+ * parentheses and anything inside them).
+ *
+ * This improved version can strip out *multiple* boundarized substrings.
+ */
+void stripout(char *str, char leftboundary, char rightboundary) {
+       int a;
+        int lb = (-1);
+        int rb = (-1);
+
+       do {
+               lb = (-1);
+               rb = (-1);
+       
+               for (a = 0; a < strlen(str); ++a) {
+                       if (str[a] == leftboundary) lb = a;
+                       if (str[a] == rightboundary) rb = a;
+               }
+
+               if ( (lb > 0) && (rb > lb) ) {
+                       strcpy(&str[lb - 1], &str[rb + 1]);
+               }
+
+       } while ( (lb > 0) && (rb > lb) );
+
+}
+