* In the HTML-to-HTML converter:
authorArt Cancro <ajc@citadel.org>
Mon, 9 Sep 2002 03:51:01 +0000 (03:51 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 9 Sep 2002 03:51:01 +0000 (03:51 +0000)
  --> Open links in new window (as with text msgs)
  --> Convert loose URL's to hot links (as with text msgs)

webcit/ChangeLog
webcit/html2html.c

index 95a85c087cf575aa508fb3ff7435971fcfdceb92..9692936fcb78dbcda91fbdc4446875380dae7550 100644 (file)
@@ -1,4 +1,9 @@
 $Log$
+Revision 323.68  2002/09/09 03:51:01  ajc
+* In the HTML-to-HTML converter:
+  --> Open links in new window (as with text msgs)
+  --> Convert loose URL's to hot links (as with text msgs)
+
 Revision 323.67  2002/09/06 03:59:11  ajc
 * Added an "About this server" panel to the Summary page.
   (Useless fluff, but better than an empty column.)
@@ -929,4 +934,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index 903e9696152cb7b5b8a235770246337948111381..023ab7c4af8184dfc9193003d28079a8d3964f38 100644 (file)
@@ -37,11 +37,18 @@ void output_html(void) {
        char *ptr;
        char *msgstart;
        char *msgend;
+       char *converted_msg;
        int buffer_length = 1;
        int line_length = 0;
        int content_length = 0;
+       int output_length = 0;
+       char new_window[SIZ];
+       int brak = 0;
+       int i;
+       int linklen;
 
        msg = strdup("");
+       sprintf(new_window, "<A TARGET=\"%s\" HREF=", TARGET);
 
        while (serv_gets(buf), strcmp(buf, "000")) {
                line_length = strlen(buf);
@@ -100,13 +107,72 @@ void output_html(void) {
                ++ptr;
        }
 
-       write(WC->http_sock, msgstart, strlen(msgstart));
+       converted_msg = malloc(content_length);
+       strcpy(converted_msg, "");
+       ptr = msgstart;
+       while (ptr < msgend) {
+               /* Make links open in a separate window */
+               if (!strncasecmp(ptr, "<A HREF=", 8)) {
+                       content_length += 64;
+                       converted_msg = realloc(converted_msg, content_length);
+                       sprintf(&converted_msg[output_length], new_window);
+                       output_length += strlen(new_window);
+                       ptr = &ptr[8];
+                       ++brak;
+               }
+               /* Turn loose URL's into hot links */
+               else if ( (brak == 0)
+                    && (!strncasecmp(ptr, "http://", 7))) {
+                               linklen = 0;
+                               /* Find the end of the link */
+                               for (i=0; i<=strlen(ptr); ++i) {
+                                       if ((ptr[i]==0)
+                                          ||(isspace(ptr[i]))
+                                          ||(ptr[i]==10)
+                                          ||(ptr[i]==13)
+                                          ||(ptr[i]==')')
+                                          ||(ptr[i]=='>')
+                                          ||(ptr[i]==']')
+                                       ) linklen = i;
+                                       if (linklen > 0) break;
+                               }
+                               if (linklen > 0) {
+                                       content_length += (32 + linklen);
+                                       converted_msg = realloc(converted_msg, content_length);
+                                       sprintf(&converted_msg[output_length], new_window);
+                                       output_length += strlen(new_window);
+                                       converted_msg[output_length] = '\"';
+                                       converted_msg[++output_length] = 0;
+                                       for (i=0; i<linklen; ++i) {
+                                               converted_msg[output_length] = ptr[i];
+                                               converted_msg[++output_length] = 0;
+                                       }
+                                       sprintf(&converted_msg[output_length], "\">");
+                                       output_length += 2;
+                                       for (i=0; i<linklen; ++i) {
+                                               converted_msg[output_length] = *ptr++;
+                                               converted_msg[++output_length] = 0;
+                                       }
+                                       sprintf(&converted_msg[output_length], "</A>");
+                                       output_length += 4;
+                               }
+               }
+               else {
+                       if (*ptr == '<') ++brak;
+                       if (*ptr == '>') --brak;
+                       converted_msg[output_length] = *ptr++;
+                       converted_msg[++output_length] = 0;
+               }
+       }
+
+       /* Output our big pile of markup */
+       write(WC->http_sock, converted_msg, output_length);
 
        /* A little trailing vertical whitespace... */
        wprintf("<BR><BR>\n");
 
        /* Now give back the memory */
+       free(converted_msg);
        free(msg);
-
 }