]> code.citadel.org Git - citadel.git/commitdiff
* html.c: speed improvement in html-to-ascii converter
authorArt Cancro <ajc@citadel.org>
Tue, 1 Oct 2002 04:00:13 +0000 (04:00 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 1 Oct 2002 04:00:13 +0000 (04:00 +0000)
* messages.c: MASSIVE speed improvement in message output

citadel/ChangeLog
citadel/html.c
citadel/messages.c

index b86452a7f7bd9add938badfc3f628ce9f97bd01f..7883ea6d408e9a122c80a7a75491f47c1f32b660 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 601.15  2002/10/01 04:00:13  ajc
+ * html.c: speed improvement in html-to-ascii converter
+ * messages.c: MASSIVE speed improvement in message output
+
  Revision 601.14  2002/09/30 08:07:11  error
  * ipcdef.h: add extern "C" for linking to C++ programs
 
@@ -4036,3 +4040,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 0a6686a17c58cfb1de86eb79b1eaece605ec5667..d717393b4de4cfe77739d2e6c9e116ccc22a3006 100644 (file)
@@ -60,7 +60,8 @@ char *html_to_ascii(char *inputmsg, int screenwidth, int do_citaformat) {
        int done_reading = 0;
        char *inptr;
        char *outptr;
-       size_t outlen;
+       size_t outptr_buffer_size;
+       size_t output_len = 0;
        int i, j, ch, did_out, rb;
        int nest = 0;           /* Bracket nesting level */
 
@@ -68,10 +69,11 @@ char *html_to_ascii(char *inputmsg, int screenwidth, int do_citaformat) {
        strcpy(inbuf, "");
        strcpy(outbuf, "");
 
-       outptr = mallok(strlen(inptr) + SIZ);
+       outptr_buffer_size = strlen(inptr) + SIZ;
+       outptr = mallok(outptr_buffer_size);
        if (outptr == NULL) return NULL;
        strcpy(outptr, "");
-       outlen = 0;
+       output_len = 0;
 
        do {
                /* Fill the input buffer */
@@ -234,9 +236,10 @@ char *html_to_ascii(char *inputmsg, int screenwidth, int do_citaformat) {
                }
 
                /* Make sure the output buffer is big enough */
-               if ((strlen(outptr) + strlen(outbuf) + 128) > outlen) {
-                       outlen += 128;
-                       outptr = realloc(outptr, outlen);
+               if ((output_len + strlen(outbuf) + 128)
+                  > outptr_buffer_size) {
+                       outptr_buffer_size += 128;
+                       outptr = realloc(outptr, outptr_buffer_size);
                }
 
                /* Output any lines terminated with hard line breaks */
@@ -245,10 +248,17 @@ char *html_to_ascii(char *inputmsg, int screenwidth, int do_citaformat) {
                        if (strlen(outbuf)>0)
                            for (i = 0; i<strlen(outbuf); ++i) {
                                if ( (i<(screenwidth-2)) && (outbuf[i]=='\n')) {
-                                       strncat(outptr, outbuf, i+1);
-                                       /* strcat(outptr, "\n"); */
-                                       if (do_citaformat)
-                                               strcat(outptr, " ");
+
+                                       strncpy(&outptr[output_len],
+                                               outbuf, i+1);
+                                       output_len += (i+1);
+
+                                       if (do_citaformat) {
+                                               strcpy(&outptr[output_len],
+                                                       " ");
+                                               ++output_len;
+                                       }
+
                                        strcpy(outbuf, &outbuf[i+1]);
                                        i = 0;
                                        did_out = 1;
@@ -263,26 +273,50 @@ char *html_to_ascii(char *inputmsg, int screenwidth, int do_citaformat) {
                                if (outbuf[i]==32) rb = i;
                        }
                        if (rb>=0) {
-                               strncat(outptr, outbuf, rb);
-                               strcat(outptr, "\n");
-                               if (do_citaformat)
-                                       strcat(outptr, " ");
+                               strncpy(&outptr[output_len], outbuf, rb);
+                               output_len += rb;
+                               strcpy(&outptr[output_len], "\n");
+                               output_len += 1;
+                               if (do_citaformat) {
+                                       strcpy(&outptr[output_len], " ");
+                                       ++output_len;
+                               }
                                strcpy(outbuf, &outbuf[rb+1]);
                        } else {
-
-                               strncat(outptr, outbuf, screenwidth-2);
-                               strcat(outptr, "\n");
-                               if (do_citaformat)
-                                       strcat(outptr, " ");
+                               strncpy(&outptr[output_len], outbuf,
+                                       screenwidth-2);
+                               output_len += (screenwidth-2);
+                               strcpy(&outptr[output_len], "\n");
+                               output_len += 1;
+                               if (do_citaformat) {
+                                       strcpy(&outptr[output_len], " ");
+                                       ++output_len;
+                               }
                                strcpy(outbuf, &outbuf[screenwidth-2]);
                        }
                }
 
        } while (done_reading == 0);
 
-       strcat(outptr, outbuf);
-       striplt(outptr);
-       if (outptr[strlen(outptr)-1] != '\n') strcat(outptr, "\n");
+       strcpy(&outptr[output_len], outbuf);
+       output_len += strlen(outbuf);
+
+       /* Strip leading/trailing whitespace.  We can't do this with
+        * striplt() because it uses too many strlen()'s
+        */
+       while ((output_len > 0) && (isspace(outptr[0]))) {
+               strcpy(outptr, &outptr[1]);
+               --output_len;
+       }
+       while ((output_len > 0) && (isspace(outptr[output_len-1]))) {
+               outptr[output_len-1] = 0;
+               --output_len;
+       }
+
+       if (outptr[output_len-1] != '\n') {
+               strcat(outptr, "\n");
+               ++output_len;
+       }
 
        return outptr;
 
index 1f796d8a19ff1ed99e376f366abc909cef4ac3e3..b9655d3d3ad123a714d3bed30672062f89526d9b 100644 (file)
@@ -588,17 +588,21 @@ int read_message(CtdlIPC *ipc,
                fr = fmout(screenwidth, NULL, message->text, dest,
                           ((pagin == 1) ? 1 : 0), screenheight, (-1), 1);
        } else {
-               int i;
+               char *msgtext;
+               char *lineptr;
+
+               msgtext = message->text;
+
+               while (lineptr = strtok(msgtext, "\n"), lineptr != NULL) {
+                       msgtext = NULL;
 
-               for (i = 0; i < num_tokens(message->text, '\n'); i++) {
                        if (sigcaught == 0) {
-                               extract_token(buf, message->text, i, '\n');
                                if (dest) {
-                                       fprintf(dest, "%s\n", buf);
+                                       fprintf(dest, "%s\n", lineptr);
                                } else {
-                                       scr_printf("%s\n", buf);
+                                       scr_printf("%s\n", lineptr);
                                        lines_printed = lines_printed + 1 +
-                                           (strlen(buf) / screenwidth);
+                                           (strlen(lineptr) / screenwidth);
                                        lines_printed =
                                            checkpagin(lines_printed, pagin,
                                                       screenheight);