+/*
+ * 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
}
+/*
+ * 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) );
+
+}