]> code.citadel.org Git - citadel.git/commitdiff
* Improvements to the new message formatter, including URL support and
authorMichael Hampton <io_error@uncensored.citadel.org>
Mon, 2 Dec 2002 08:09:00 +0000 (08:09 +0000)
committerMichael Hampton <io_error@uncensored.citadel.org>
Mon, 2 Dec 2002 08:09:00 +0000 (08:09 +0000)
  doing the Right Thing for text/plain messages.

citadel/ChangeLog
citadel/citadel.c
citadel/commands.c
citadel/messages.c

index 6184af63251a8579aea17a28639861b34225d1ce..a9fb67a67e98caaee0bdc551854a2acb846a0803 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 601.81  2002/12/02 08:09:00  error
+ * Improvements to the new message formatter, including URL support and
+   doing the Right Thing for text/plain messages.
+
  Revision 601.80  2002/12/01 11:02:57  error
  * New experimental message formatter - try it, you'll like it!
 
@@ -4270,3 +4274,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index 99dd7448f41a1bc20cbcff7bf7f95e30e9b26182..62a79774b08b4cd601633d0424a3f8bed6b9b167 100644 (file)
@@ -190,7 +190,7 @@ void formout(CtdlIPC *ipc, char *name)
                return;
        }
        if (text) {
-               fmout(screenwidth, NULL, text, NULL,
+               fmout2(screenwidth, NULL, text, NULL,
                      ((userflags & US_PAGINATOR) ? 1 : 0),
                      screenheight, 1, 1);
                free(text);
index fc6322170077ae52274e59ba6723fe06f21f0c1a..7257976396ac786063d80e2e088d397ffbbcfc88 100644 (file)
@@ -1344,10 +1344,8 @@ FMTA:    while ((eof_flag == 0) && (strlen(buffer) < 126)) {
        if (a <= 0)
                goto FMTEND;
 
-       /*
        if (a == 10) scr_printf("<a==10>");
        if (a == 13) scr_printf("<a==13>");
-       */
 
        if ((a == 13) || (a == 10)) {
                if ((old != 13) && (old != 10))
@@ -1453,6 +1451,8 @@ int fmout2(
        int column = 0;         /* Current column */
        size_t i;               /* Generic counter */
 
+       num_urls = 0;   /* Start with a clean slate of embedded URL's */
+
        word = (char *)calloc(1, width);
        if (!word) {
                err_printf("Can't alloc memory to print message: %s!\n",
@@ -1463,8 +1463,9 @@ int fmout2(
        if (fpin) {
                size_t got = 0;
 
-               rewind(fpin);
+               fseek(fpin, 0, SEEK_END);
                i = ftell(fpin);
+               rewind(fpin);
                buffer = (char *)calloc(1, i + 1);
                if (!buffer) {
                        err_printf("Can't alloc memory for message: %s!\n",
@@ -1485,12 +1486,11 @@ int fmout2(
        } else {
                buffer = text;
        }
+       e = buffer;
 
        if (starting_lp >= 0)
                lines_printed = starting_lp;
 
-       e = buffer;
-
        while (*e) {
                /* First, are we looking at a newline? */
                if (*e == '\n') {
@@ -1537,17 +1537,52 @@ int fmout2(
                        continue;
                }
 
-               /* Read a word and decide what to do with it */
+               /* Read a word, slightly messy */
                i = 0;
-               while (*e) {
+               while (e[i]) {
+                       if (!isprint(e[i]) && !isspace(e[i]))
+                               e[i] = ' ';
                        if (isspace(e[i]))
                                break;
                        i++;
                }
-               if (i >= width)         /* Break up really long words */
+
+               /* We should never see these, but... slightly messy */
+               if (e[i] == '\t' || e[i] == '\f' || e[i] == '\v')
+                       e[i] = ' ';
+
+               /*
+                * Check for and copy URLs
+                * We will get the entire URL even if it's longer than the
+                * screen width, as long as the server didn't break it up
+                */
+               if (!strncasecmp(e, "http://", 7) ||
+                   !strncasecmp(e, "ftp://", 6)) {
+                       int j;
+
+                       strncpy(urls[num_urls], e, i);
+                       urls[num_urls][i] = 0;
+                       for (j = 0; j < strlen(e); j++) {
+                               char c;
+
+                               c = urls[num_urls][j];
+                               if (c == '>' || c == '\"' || c == ')' ||
+                                   c == ' ' || c == '\n') {
+                                       urls[num_urls][j] = 0;
+                                       break;
+                               }
+                       }
+                       num_urls++;
+               }
+
+               /* Break up really long words */
+               /* TODO: auto-hyphenation someday? */
+               if (i >= width) 
                        i = width - 1;
                strncpy(word, e, i);
                word[i] = 0;
+
+               /* Decide where to print the word */
                if (column + i >= width) {
                        if (fpout) {
                                fprintf(fpout, "\n");
@@ -1558,19 +1593,21 @@ int fmout2(
                        }
                        column = 0;
                }
+
+               /* Print the word */
                if (fpout) {
                        fprintf(fpout, "%s", word);
                } else {
                        scr_printf("%s", word);
                }
                column += i;
-               e += i;
+               e += i;         /* Start with the whitepsace! */
        }
 
        free(word);
-       if (fpin)
+       if (fpin)               /* We allocated this, remember? */
                free(buffer);
-       return 0;
+       return sigcaught;
 }
 
 
index 71b5bbc8dc9726bca4c1356c3efd11c6755a52e9..9ad2330dea93f352d657c76007d7134dd10c60a1 100644 (file)
@@ -577,6 +577,11 @@ int read_message(CtdlIPC *ipc,
                }
        }
 
+       /* Text/plain is a different type */
+       if (!strcasecmp(message->content_type, "text/plain")) {
+               format_type = 1;
+       }
+
        /*
         * Here we go
         */
@@ -584,6 +589,7 @@ int read_message(CtdlIPC *ipc,
                fr = fmout2(screenwidth, NULL, message->text, dest,
                           ((pagin == 1) ? 1 : 0), screenheight, (-1), 1);
        } else {
+               /* FIXME: renderer for text/plain */
                char *msgtext;
                char *lineptr;