]> code.citadel.org Git - citadel.git/blobdiff - webcit/tools.c
* Display PARTSTAT for attendees
[citadel.git] / webcit / tools.c
index a5b943b27843521b1b022e7e2de954d7f68bd8aa..6912515cae5e1e73393c7ad88cbeb2a8de6d4977 100644 (file)
@@ -213,6 +213,28 @@ void fmt_date(char *buf, time_t thetime) {
 
 
 
+/*
+ * 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" )
+       );
+}
+
+
+
 
 /*
  * Format a date/time stamp to the format used in HTTP headers
@@ -328,3 +350,61 @@ int is_msg_in_mset(char *mset, long msgnum) {
 }
 
 
+
+/*
+ * 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) );
+
+}
+
+