Rewrite aha to work with new tree system ready for messages and files

This commit is contained in:
Andrew Pamment 2018-10-21 23:05:17 +10:00
parent 71b465eba2
commit 947d4ab37f
5 changed files with 653 additions and 272 deletions

367
deps/aha/aha.c vendored
View File

@ -20,6 +20,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "../../src/www_tree.h"
extern void unmangle_ansi(char *body, int len, char **body_out, int *body_len); extern void unmangle_ansi(char *body, int len, char **body_out, int *body_len);
@ -84,17 +85,7 @@ void deleteParse(pelem elem)
} }
} }
void append_output(char **output, char *stuff, int *size, int *at) { struct www_tag * aha(char *input, struct www_tag *parent)
while (*at + strlen(stuff) + 1 >= *size) {
*size += 256;
*output = realloc(*output, *size);
}
strcat(*output, stuff);
*at += strlen(stuff);
}
char * aha(char *input)
{ {
//Searching Parameters //Searching Parameters
char *unmangle_out; char *unmangle_out;
@ -116,13 +107,11 @@ char * aha(char *input)
int newline=-1; int newline=-1;
int temp; int temp;
char *ptr = unmangle_out; char *ptr = unmangle_out;
char *output = (char *)malloc(256);
int size = 256; int size = 256;
int outat = 0; int outat = 0;
char minibuf[2]; char minibuf[2];
struct www_tag *child = NULL;
stralloc data = EMPTY_STRALLOC;
memset(output, 0, 256);
while (*ptr != '\0') while (*ptr != '\0')
{ {
@ -138,7 +127,7 @@ char * aha(char *input)
//Searching the end (a letter) and safe the insert: //Searching the end (a letter) and safe the insert:
c= *ptr++; c= *ptr++;
if (c == '\0') { if (c == '\0') {
return output; return parent;
} }
if ( c == '[' ) // CSI code, see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors if ( c == '[' ) // CSI code, see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
{ {
@ -149,7 +138,7 @@ char * aha(char *input)
{ {
c=*ptr++; c=*ptr++;
if (c == '\0') { if (c == '\0') {
return output; return parent;
} }
buffer[counter]=c; buffer[counter]=c;
if (c=='>') //end of htop if (c=='>') //end of htop
@ -238,340 +227,202 @@ char * aha(char *input)
//Checking the differences //Checking the differences
if ((fc!=ofc) || (bc!=obc) || (ul!=oul) || (bo!=obo) || (bl!=obl)) //ANY Change if ((fc!=ofc) || (bc!=obc) || (ul!=oul) || (bo!=obo) || (bl!=obl)) //ANY Change
{ {
if ((ofc!=-1) || (obc!=-1) || (oul!=0) || (obo!=0) || (obl!=0))
append_output(&output, "</span>", &size, &outat);
if ((fc!=-1) || (bc!=-1) || (ul!=0) || (bo!=0) || (bl!=0)) if ((fc!=-1) || (bc!=-1) || (ul!=0) || (bo!=0) || (bl!=0))
{ {
append_output(&output, "<span style=\"", &size, &outat); if (data.len > 0) {
stralloc_0(&data);
struct www_tag *datatag = www_tag_new(NULL, data.s);
free(data.s);
data = EMPTY_STRALLOC;
if (child == NULL) {
www_tag_add_child(parent, datatag);
} else {
www_tag_add_child(child, datatag);
www_tag_add_child(parent, child);
}
}
child = www_tag_new("span", NULL);
stralloc output = EMPTY_STRALLOC;
switch (fc) switch (fc)
{ {
case 0: case 0:
if (bo) { if (bo) {
append_output(&output, "color:dimgray;", &size, &outat); stralloc_cats(&output, "color:dimgray;");
} else { } else {
append_output(&output, "color:dimgray;", &size, &outat); stralloc_cats(&output, "color:dimgray;");
} }
break; //Black break; //Black
case 1: case 1:
if (bo) { if (bo) {
append_output(&output, "color:#FF8888;", &size, &outat); stralloc_cats(&output, "color:#FF8888;");
} else { } else {
append_output(&output, "color:red;", &size, &outat); stralloc_cats(&output, "color:red;");
} }
break; //Red break; //Red
case 2: case 2:
if (bo) { if (bo) {
append_output(&output, "color:lime;", &size, &outat); stralloc_cats(&output, "color:lime;");
} else { } else {
append_output(&output, "color:#00ff00;", &size, &outat); stralloc_cats(&output, "color:#00FF00;");
} }
break; //Green break; //Green
case 3: case 3:
if (bo) { if (bo) {
append_output(&output, "color:yellow;", &size, &outat); stralloc_cats(&output, "color:yellow;");
} else { } else {
append_output(&output, "color:olive;", &size, &outat); stralloc_cats(&output, "color:olive;");
} }
break; //Yellow break; //Yellow
case 4: case 4:
if (bo) { if (bo) {
append_output(&output, "color:#8888FF;", &size, &outat); stralloc_cats(&output, "color:#8888FF;");
} else { } else {
append_output(&output, "color:#0000FF;", &size, &outat); stralloc_cats(&output, "color:#0000FF;");
} }
break; //Blue break; //Blue
case 5: case 5:
if (bo) { if (bo) {
append_output(&output, "color:fuchsia;", &size, &outat); stralloc_cats(&output, "color:fuchsia;");
} else { } else {
append_output(&output, "color:#FF00FF;", &size, &outat); stralloc_cats(&output, "color:#FF00FF;");
} }
break; //Purple break; //Purple
case 6: case 6:
if (bo) { if (bo) {
append_output(&output, "color:aqua;", &size, &outat); stralloc_cats(&output, "color:aqua;");
} else { } else {
append_output(&output, "color:#008888;", &size, &outat); stralloc_cats(&output, "color:#008888;");
} }
break; //Cyan break; //Cyan
case 7: case 7:
if (bo) { if (bo) {
append_output(&output, "color:white;", &size, &outat); stralloc_cats(&output, "color:white;");
} else { } else {
append_output(&output, "color:grey;", &size, &outat); stralloc_cats(&output, "color:grey;");
} }
break; //White break; //White
case 8: case 8:
append_output(&output, "color:black;", &size, &outat); stralloc_cats(&output, "color:black;");
break; //Background Colour break; //Background Colour
case 9: case 9:
append_output(&output, "color:white;", &size, &outat); stralloc_cats(&output, "color:white;");
break; //Foreground Color break; //Foreground Color
} }
switch (bc) switch (bc)
{ {
case 0: case 0:
append_output(&output, "background-color:black;", &size, &outat); stralloc_cats(&output, "background-color:black;");
break; //Black break; //Black
case 1: case 1:
append_output(&output, "background-color:red;", &size, &outat); stralloc_cats(&output, "background-color:red;");
break; //Red break; //Red
case 2: case 2:
append_output(&output, "background-color:lime;", &size, &outat); stralloc_cats(&output, "background-color:lime;");
break; //Green break; //Green
case 3: case 3:
append_output(&output, "background-color:yellow;", &size, &outat); stralloc_cats(&output, "background-color:yellow;");
break; //Yellow break; //Yellow
case 4: case 4:
append_output(&output, "background-color:#3333FF;", &size, &outat); stralloc_cats(&output, "background-color:#3333FF;");
break; //Blue break; //Blue
case 5: case 5:
append_output(&output, "background-color:fuchsia;", &size, &outat); stralloc_cats(&output, "background-color:fuchsia;");
break; //Purple break; //Purple
case 6: case 6:
append_output(&output, "background-color:aqua;", &size, &outat); stralloc_cats(&output, "background-color:aqua;");
break; //Cyan break; //Cyan
case 7: case 7:
append_output(&output, "background-color:white;", &size, &outat); stralloc_cats(&output, "background-color:white;");
break; //White break; //White
case 8: case 8:
append_output(&output, "background-color:black;", &size, &outat); stralloc_cats(&output, "background-color:black;");
break; //Background Colour break; //Background Colour
case 9: case 9:
append_output(&output, "background-color:white;", &size, &outat); stralloc_cats(&output, "background-color:white;");
break; //Foreground Colour break; //Foreground Colour
} }
if (ul) if (ul)
{ {
append_output(&output, "text-decoration:underline;", &size, &outat); stralloc_cats(&output, "text-decoration:underline;");
} }
if (bl) if (bl)
{ {
append_output(&output, "text-decoration:blink;", &size, &outat); stralloc_cats(&output, "text-decoration:blink;");
} }
append_output(&output, "\">", &size, &outat); stralloc_0(&output);
www_tag_add_attrib(child, "style", output.s);
free(output.s);
} }
} }
} }
} }
else
if (c==13)
{
//for (;line<80;line++)
// append_output(&output, "&nbsp;", &size, &outat);
line=0;
momline++;
append_output(&output, "<br />\n", &size, &outat);
}
else if (c!=8) else if (c!=8)
{ {
line++; line++;
if (newline>=0)
{
while (newline>line)
{
append_output(&output, " ", &size, &outat);
line++;
}
newline=-1;
}
switch (c) switch (c)
{ {
case '\x01' : append_output(&output, "&#x263A;", &size, &outat); break;
case '\x02' : append_output(&output, "&#x263B;", &size, &outat); break; case '\n':
case '\x03' : append_output(&output, "&#x2665;", &size, &outat); break; case 13:
case '\x04' : append_output(&output, "&#x2666;", &size, &outat); break; momline++;
case '\x05' : append_output(&output, "&#x2663;", &size, &outat); break; line=0;
case '\x06' : append_output(&output, "&#x2660;", &size, &outat); break; struct www_tag *brtag = www_tag_new("br", NULL);
case '\x07' : append_output(&output, "&#x2022;", &size, &outat); break; if (data.len > 0) {
case '\x08' : append_output(&output, "&#x25D8;", &size, &outat); break; if (child != NULL) {
case '\x09' : append_output(&output, "&#x25CB;", &size, &outat); break; stralloc_0(&data);
//case '\x0a' : append_output(&output, "&#x25D8;", &size, &outat); break; struct www_tag *datatag = www_tag_new(NULL, data.s);
case '\x0b' : append_output(&output, "&#x2642;", &size, &outat); break; free(data.s);
case '\x0c' : append_output(&output, "&#x2640;", &size, &outat); break; data = EMPTY_STRALLOC;
//case '\x0d' : append_output(&output, "&#x266A;", &size, &outat); break; www_tag_add_child(child, datatag);
case '\x0e' : append_output(&output, "&#x266B;", &size, &outat); break; www_tag_add_child(child, brtag);
case '\x0f' : append_output(&output, "&#x263C;", &size, &outat); break; www_tag_add_child(parent, child);
case '\x10' : append_output(&output, "&#x25B8;", &size, &outat); break; child = www_tag_duplicate(child);
case '\x11' : append_output(&output, "&#x25C2;", &size, &outat); break; } else {
case '\x12' : append_output(&output, "&#x2195;", &size, &outat); break; stralloc_0(&data);
case '\x13' : append_output(&output, "&#x203C;", &size, &outat); break; struct www_tag *datatag = www_tag_new(NULL, data.s);
case '\x14' : append_output(&output, "&#x00B6;", &size, &outat); break; free(data.s);
case '\x15' : append_output(&output, "&#x00A7;", &size, &outat); break; data = EMPTY_STRALLOC;
case '\x16' : append_output(&output, "&#x25AC;", &size, &outat); break; www_tag_add_child(parent, datatag);
case '\x17' : append_output(&output, "&#x21A8;", &size, &outat); break; www_tag_add_child(parent, brtag);
case '\x18' : append_output(&output, "&#x2191;", &size, &outat); break; }
case '\x19' : append_output(&output, "&#x2193;", &size, &outat); break; } else {
case '\x1a' : append_output(&output, "&#x2192;", &size, &outat); break;
case '\x1b' : append_output(&output, "&#x2190;", &size, &outat); break;
case '\x1c' : append_output(&output, "&#x221F;", &size, &outat); break; if (child != NULL) {
case '\x1d' : append_output(&output, "&#x2194;", &size, &outat); break; www_tag_add_child(child, brtag);
case '\x1e' : append_output(&output, "&#x25B4;", &size, &outat); break; www_tag_add_child(parent, child);
case '\x1f' : append_output(&output, "&#x25BE;", &size, &outat); break; child = www_tag_duplicate(child);
case '\x21' : append_output(&output, "&#x0021;", &size, &outat); break;
case '\x22' : append_output(&output, "&#x0022;", &size, &outat); break; } else {
case '\x23' : append_output(&output, "&#x0023;", &size, &outat); break; www_tag_add_child(parent, brtag);
case '\x24' : append_output(&output, "&#x0024;", &size, &outat); break; }
case '\x25' : append_output(&output, "&#x0025;", &size, &outat); break; }
case '\x26' : append_output(&output, "&#x0026;", &size, &outat); break; break;
case '\x27' : append_output(&output, "&#x0027;", &size, &outat); break;
case '\x28' : append_output(&output, "&#x0028;", &size, &outat); break;
case '\x29' : append_output(&output, "&#x0029;", &size, &outat); break;
case '\x2a' : append_output(&output, "&#x002A;", &size, &outat); break;
case '\x2b' : append_output(&output, "&#x002B;", &size, &outat); break;
case '\x2c' : append_output(&output, "&#x002C;", &size, &outat); break;
case '\x2d' : append_output(&output, "&#x002D;", &size, &outat); break;
case '\x2e' : append_output(&output, "&#x002E;", &size, &outat); break;
case '\x2f' : append_output(&output, "&#x002F;", &size, &outat); break;
case '\x7f' : append_output(&output, "&#x2302;", &size, &outat); break;
case '\x80' : append_output(&output, "&#x00C7;", &size, &outat); break;
case '\x81' : append_output(&output, "&#x00FC;", &size, &outat); break;
case '\x82' : append_output(&output, "&#x00E9;", &size, &outat); break;
case '\x83' : append_output(&output, "&#x00E2;", &size, &outat); break;
case '\x84' : append_output(&output, "&#x00E4;", &size, &outat); break;
case '\x85' : append_output(&output, "&#x00E0;", &size, &outat); break;
case '\x86' : append_output(&output, "&#x00E5;", &size, &outat); break;
case '\x87' : append_output(&output, "&#x00E7;", &size, &outat); break;
case '\x88' : append_output(&output, "&#x00EA;", &size, &outat); break;
case '\x89' : append_output(&output, "&#x00EB;", &size, &outat); break;
case '\x8a' : append_output(&output, "&#x00E8;", &size, &outat); break;
case '\x8b' : append_output(&output, "&#x00EF;", &size, &outat); break;
case '\x8c' : append_output(&output, "&#x00EE;", &size, &outat); break;
case '\x8d' : append_output(&output, "&#x00EC;", &size, &outat); break;
case '\x8e' : append_output(&output, "&#x00C4;", &size, &outat); break;
case '\x8f' : append_output(&output, "&#x00C5;", &size, &outat); break;
case '\x90' : append_output(&output, "&#x00C9;", &size, &outat); break;
case '\x91' : append_output(&output, "&#x00E6;", &size, &outat); break;
case '\x92' : append_output(&output, "&#x00C6;", &size, &outat); break;
case '\x93' : append_output(&output, "&#x00F4;", &size, &outat); break;
case '\x94' : append_output(&output, "&#x00F6;", &size, &outat); break;
case '\x95' : append_output(&output, "&#x00F2;", &size, &outat); break;
case '\x96' : append_output(&output, "&#x00FB;", &size, &outat); break;
case '\x97' : append_output(&output, "&#x00F9;", &size, &outat); break;
case '\x98' : append_output(&output, "&#x00FF;", &size, &outat); break;
case '\x99' : append_output(&output, "&#x00D6;", &size, &outat); break;
case '\x9a' : append_output(&output, "&#x00DC;", &size, &outat); break;
case '\x9b' : append_output(&output, "&#x00A2;", &size, &outat); break;
case '\x9c' : append_output(&output, "&#x00A3;", &size, &outat); break;
case '\x9d' : append_output(&output, "&#x00A5;", &size, &outat); break;
case '\x9e' : append_output(&output, "&#x20A7;", &size, &outat); break;
case '\x9f' : append_output(&output, "&#x0192;", &size, &outat); break;
case '\xa0' : append_output(&output, "&#x00E1;", &size, &outat); break;
case '\xa1' : append_output(&output, "&#x00ED;", &size, &outat); break;
case '\xa2' : append_output(&output, "&#x00F3;", &size, &outat); break;
case '\xa3' : append_output(&output, "&#x00FA;", &size, &outat); break;
case '\xa4' : append_output(&output, "&#x00F1;", &size, &outat); break;
case '\xa5' : append_output(&output, "&#x00D1;", &size, &outat); break;
case '\xa6' : append_output(&output, "&#x00AA;", &size, &outat); break;
case '\xa7' : append_output(&output, "&#x00BA;", &size, &outat); break;
case '\xa8' : append_output(&output, "&#x00BF;", &size, &outat); break;
case '\xa9' : append_output(&output, "&#x2310;", &size, &outat); break;
case '\xaa' : append_output(&output, "&#x00AC;", &size, &outat); break;
case '\xab' : append_output(&output, "&#x00BD;", &size, &outat); break;
case '\xac' : append_output(&output, "&#x00BC;", &size, &outat); break;
case '\xad' : append_output(&output, "&#x00A1;", &size, &outat); break;
case '\xae' : append_output(&output, "&#x00AB;", &size, &outat); break;
case '\xaf' : append_output(&output, "&#x00BB;", &size, &outat); break;
case '\xb0' : append_output(&output, "&#x2591;", &size, &outat); break;
case '\xb1' : append_output(&output, "&#x2592;", &size, &outat); break;
case '\xb2' : append_output(&output, "&#x2593;", &size, &outat); break;
case '\xb3' : append_output(&output, "&#x2502;", &size, &outat); break;
case '\xb4' : append_output(&output, "&#x2524;", &size, &outat); break;
case '\xb5' : append_output(&output, "&#x2561;", &size, &outat); break;
case '\xb6' : append_output(&output, "&#x2562;", &size, &outat); break;
case '\xb7' : append_output(&output, "&#x2556;", &size, &outat); break;
case '\xb8' : append_output(&output, "&#x2555;", &size, &outat); break;
case '\xb9' : append_output(&output, "&#x2563;", &size, &outat); break;
case '\xba' : append_output(&output, "&#x2551;", &size, &outat); break;
case '\xbb' : append_output(&output, "&#x2557;", &size, &outat); break;
case '\xbc' : append_output(&output, "&#x255D;", &size, &outat); break;
case '\xbd' : append_output(&output, "&#x255C;", &size, &outat); break;
case '\xbe' : append_output(&output, "&#x255B;", &size, &outat); break;
case '\xbf' : append_output(&output, "&#x2510;", &size, &outat); break;
case '\xc0' : append_output(&output, "&#x2514;", &size, &outat); break;
case '\xc1' : append_output(&output, "&#x2534;", &size, &outat); break;
case '\xc2' : append_output(&output, "&#x252C;", &size, &outat); break;
case '\xc3' : append_output(&output, "&#x251C;", &size, &outat); break;
case '\xc4' : append_output(&output, "&#x2500;", &size, &outat); break;
case '\xc5' : append_output(&output, "&#x253C;", &size, &outat); break;
case '\xc6' : append_output(&output, "&#x255E;", &size, &outat); break;
case '\xc7' : append_output(&output, "&#x255F;", &size, &outat); break;
case '\xc8' : append_output(&output, "&#x255A;", &size, &outat); break;
case '\xc9' : append_output(&output, "&#x2554;", &size, &outat); break;
case '\xca' : append_output(&output, "&#x2569;", &size, &outat); break;
case '\xcb' : append_output(&output, "&#x2566;", &size, &outat); break;
case '\xcc' : append_output(&output, "&#x2560;", &size, &outat); break;
case '\xcd' : append_output(&output, "&#x2550;", &size, &outat); break;
case '\xce' : append_output(&output, "&#x256C;", &size, &outat); break;
case '\xcf' : append_output(&output, "&#x2567;", &size, &outat); break;
case '\xd0' : append_output(&output, "&#x2568;", &size, &outat); break;
case '\xd1' : append_output(&output, "&#x2564;", &size, &outat); break;
case '\xd2' : append_output(&output, "&#x2565;", &size, &outat); break;
case '\xd3' : append_output(&output, "&#x2559;", &size, &outat); break;
case '\xd4' : append_output(&output, "&#x255B;", &size, &outat); break;
case '\xd5' : append_output(&output, "&#x2552;", &size, &outat); break;
case '\xd6' : append_output(&output, "&#x2553;", &size, &outat); break;
case '\xd7' : append_output(&output, "&#x256B;", &size, &outat); break;
case '\xd8' : append_output(&output, "&#x256A;", &size, &outat); break;
case '\xd9' : append_output(&output, "&#x2518;", &size, &outat); break;
case '\xda' : append_output(&output, "&#x250C;", &size, &outat); break;
case '\xdb' : append_output(&output, "&#x2588;", &size, &outat); break;
case '\xdc' : append_output(&output, "&#x2584;", &size, &outat); break;
case '\xdd' : append_output(&output, "&#x258C;", &size, &outat); break;
case '\xde' : append_output(&output, "&#x2590;", &size, &outat); break;
case '\xdf' : append_output(&output, "&#x2580;", &size, &outat); break;
case '\xe0' : append_output(&output, "&#x03B1;", &size, &outat); break;
case '\xe1' : append_output(&output, "&#x03B2;", &size, &outat); break;
case '\xe2' : append_output(&output, "&#x0393;", &size, &outat); break;
case '\xe3' : append_output(&output, "&#x03C0;", &size, &outat); break;
case '\xe4' : append_output(&output, "&#x03A3;", &size, &outat); break;
case '\xe5' : append_output(&output, "&#x03C3;", &size, &outat); break;
case '\xe6' : append_output(&output, "&#x00B5;", &size, &outat); break;
case '\xe7' : append_output(&output, "&#x03C4;", &size, &outat); break;
case '\xe8' : append_output(&output, "&#x03A6;", &size, &outat); break;
case '\xe9' : append_output(&output, "&#x0398;", &size, &outat); break;
case '\xea' : append_output(&output, "&#x03A9;", &size, &outat); break;
case '\xeb' : append_output(&output, "&#x03B4;", &size, &outat); break;
case '\xec' : append_output(&output, "&#x221E;", &size, &outat); break;
case '\xed' : append_output(&output, "&#x2205;", &size, &outat); break;
case '\xee' : append_output(&output, "&#x2208;", &size, &outat); break;
case '\xef' : append_output(&output, "&#x2229;", &size, &outat); break;
case '\xf0' : append_output(&output, "&#x2261;", &size, &outat); break;
case '\xf1' : append_output(&output, "&#x00B1;", &size, &outat); break;
case '\xf2' : append_output(&output, "&#x2265;", &size, &outat); break;
case '\xf3' : append_output(&output, "&#x2264;", &size, &outat); break;
case '\xf4' : append_output(&output, "&#x2320;", &size, &outat); break;
case '\xf5' : append_output(&output, "&#x2321;", &size, &outat); break;
case '\xf6' : append_output(&output, "&#x00F7;", &size, &outat); break;
case '\xf7' : append_output(&output, "&#x2248;", &size, &outat); break;
case '\xf8' : append_output(&output, "&#x00B0;", &size, &outat); break;
case '\xf9' : append_output(&output, "&#x2219;", &size, &outat); break;
case '\xfa' : append_output(&output, "&#x00B7;", &size, &outat); break;
case '\xfb' : append_output(&output, "&#x221A;", &size, &outat); break;
case '\xfc' : append_output(&output, "&#x207F;", &size, &outat); break;
case '\xfd' : append_output(&output, "&#x00B2;", &size, &outat); break;
case '\xfe' : append_output(&output, "&#x25AA;", &size, &outat); break;
case '<': append_output(&output, "&lt;", &size, &outat); break;
case '>': append_output(&output, "&gt;", &size, &outat); break;
case '\n':case 13: momline++;
line=0;
append_output(&output, "<br />\n", &size, &outat);
break;
case ' ': append_output(&output, "&nbsp;", &size, &outat); break;
default: { default: {
sprintf(minibuf, "%c", c); stralloc_append1(&data, c);
append_output(&output, minibuf, &size, &outat); break;
} }
} }
} }
} }
//Footer if (data.len > 0) {
if ((fc!=-1) || (bc!=-1) || (ul!=0) || (bo!=0) || (bl!=0)) stralloc_0(&data);
append_output(&output, "</span>\n", &size, &outat); struct www_tag *datatag = www_tag_new(NULL, data.s);
free(data.s);
data = EMPTY_STRALLOC;
if (child == NULL) {
www_tag_add_child(parent, datatag);
} else {
www_tag_add_child(child, datatag);
www_tag_add_child(parent, child);
}
}
free(unmangle_out); free(unmangle_out);
return output; return parent;
} }

View File

@ -7,11 +7,12 @@
#include "../deps/hashids/hashids.h" #include "../deps/hashids/hashids.h"
#include "www_tree.h"
#include "bbs.h" #include "bbs.h"
extern struct bbs_config conf; extern struct bbs_config conf;
extern struct user_record *gUser; extern struct user_record *gUser;
extern char *aha(char *input); extern struct www_tag * aha(char *input, struct www_tag *parent);
static int digit2nibble(int digit) { static int digit2nibble(int digit) {
static const char *const hex = "0123456789abcdef"; static const char *const hex = "0123456789abcdef";
@ -298,7 +299,6 @@ char *www_files_display_listing(int dir, int sub) {
stralloc page = EMPTY_STRALLOC; stralloc page = EMPTY_STRALLOC;
char pathbuf[PATH_MAX]; char pathbuf[PATH_MAX];
char *aha_out = NULL;
sqlite3 *db = NULL; sqlite3 *db = NULL;
sqlite3_stmt *res = NULL; sqlite3_stmt *res = NULL;
int rc = 0; int rc = 0;
@ -372,9 +372,13 @@ char *www_files_display_listing(int dir, int sub) {
if (*p == '\n') if (*p == '\n')
*p = '\r'; *p = '\r';
} }
aha_out = aha(description); struct www_tag *aha_out = www_tag_new(NULL, "");
stralloc_cats(&page, aha_out); aha(description, aha_out);
free(aha_out);
char *aha_data = www_tag_unwravel(aha_out);
stralloc_cats(&page, aha_data);
free(aha_data);
free(description); free(description);
free(filename); free(filename);

View File

@ -6,7 +6,7 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <iconv.h> #include <iconv.h>
#include "www_tree.h"
#include "jamlib/jam.h" #include "jamlib/jam.h"
#include "libuuid/uuid.h" #include "libuuid/uuid.h"
@ -15,9 +15,8 @@
#define IN 0 #define IN 0
#define OUT 1 #define OUT 1
extern char *aha(char *input);
extern struct bbs_config conf; extern struct bbs_config conf;
extern struct www_tag * aha(char *input, struct www_tag *parent);
static char *www_wordwrap(char *content, int cutoff); static char *www_wordwrap(char *content, int cutoff);
char *www_sanitize(char *inp) { char *www_sanitize(char *inp) {
int i; int i;
@ -241,7 +240,6 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
char *to_s; char *to_s;
int l1, l2; int l1, l2;
char *aha_text; char *aha_text;
char *aha_out;
char *nodename; char *nodename;
struct fido_addr *nodeno; struct fido_addr *nodeno;
@ -421,10 +419,13 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
stralloc_cats(&page, "<div id=\"msgbody\">\n"); stralloc_cats(&page, "<div id=\"msgbody\">\n");
aha_text = strndup(body, jmh.TxtLen); aha_text = strndup(body, jmh.TxtLen);
aha_out = aha(aha_text); struct www_tag *aha_out = www_tag_new(NULL, "");
stralloc_cats(&page, aha_out); aha(aha_text, aha_out);
free(aha_out); char *aha_data = www_tag_unwravel(aha_out);
stralloc_cats(&page, aha_data);
free(aha_data);
free(aha_text); free(aha_text);
stralloc_cats(&page, "</div>\n"); stralloc_cats(&page, "</div>\n");

View File

@ -28,12 +28,528 @@ struct www_tag *www_tag_new(char *tag, char *data) {
case '>': case '>':
stralloc_cats(&str, "&gt;"); stralloc_cats(&str, "&gt;");
break; break;
case '\x01':
stralloc_cats(&str, "&#x263A;");
break;
case '\x02':
stralloc_cats(&str, "&#x263B;");
break;
case '\x03':
stralloc_cats(&str, "&#x2665;");
break;
case '\x04':
stralloc_cats(&str, "&#x2666;");
break;
case '\x05':
stralloc_cats(&str, "&#x2663;");
break;
case '\x06':
stralloc_cats(&str, "&#x2660;");
break;
case '\x07':
stralloc_cats(&str, "&#x2022;");
break;
case '\x08':
stralloc_cats(&str, "&#x25D8;");
break;
case '\x09':
stralloc_cats(&str, "&#x25CB;");
break;
case '\x0b':
stralloc_cats(&str, "&#x2642;");
break;
case '\x0c':
stralloc_cats(&str, "&#x2640;");
break;
case '\x0e':
stralloc_cats(&str, "&#x266B;");
break;
case '\x0f':
stralloc_cats(&str, "&#x263C;");
break;
case '\x10':
stralloc_cats(&str, "&#x25B8;");
break;
case '\x11':
stralloc_cats(&str, "&#x25C2;");
break;
case '\x12':
stralloc_cats(&str, "&#x2195;");
break;
case '\x13':
stralloc_cats(&str, "&#x203C;");
break;
case '\x14':
stralloc_cats(&str, "&#x00B6;");
break;
case '\x15':
stralloc_cats(&str, "&#x00A7;");
break;
case '\x16':
stralloc_cats(&str, "&#x25AC;");
break;
case '\x17':
stralloc_cats(&str, "&#x21A8;");
break;
case '\x18':
stralloc_cats(&str, "&#x2191;");
break;
case '\x19':
stralloc_cats(&str, "&#x2193;");
break;
case '\x1a':
stralloc_cats(&str, "&#x2192;");
break;
case '\x1b':
stralloc_cats(&str, "&#x2190;");
break;
case '\x1c':
stralloc_cats(&str, "&#x221F;");
break;
case '\x1d':
stralloc_cats(&str, "&#x2194;");
break;
case '\x1e':
stralloc_cats(&str, "&#x25B4;");
break;
case '\x1f':
stralloc_cats(&str, "&#x25BE;");
break;
case '\x21':
stralloc_cats(&str, "&#x0021;");
break;
case '\x22':
stralloc_cats(&str, "&#x0022;");
break;
case '\x23':
stralloc_cats(&str, "&#x0023;");
break;
case '\x24':
stralloc_cats(&str, "&#x0024;");
break;
case '\x25':
stralloc_cats(&str, "&#x0025;");
break;
case '\x27':
stralloc_cats(&str, "&#x0027;");
break;
case '\x28':
stralloc_cats(&str, "&#x0028;");
break;
case '\x29':
stralloc_cats(&str, "&#x0029;");
break;
case '\x2a':
stralloc_cats(&str, "&#x002A;");
break;
case '\x2b':
stralloc_cats(&str, "&#x002B;");
break;
case '\x2c':
stralloc_cats(&str, "&#x002C;");
break;
case '\x2d':
stralloc_cats(&str, "&#x002D;");
break;
case '\x2e':
stralloc_cats(&str, "&#x002E;");
break;
case '\x2f':
stralloc_cats(&str, "&#x002F;");
break;
case '\x7f':
stralloc_cats(&str, "&#x2302;");
break;
case '\x80':
stralloc_cats(&str, "&#x00C7;");
break;
case '\x81':
stralloc_cats(&str, "&#x00FC;");
break;
case '\x82':
stralloc_cats(&str, "&#x00E9;");
break;
case '\x83':
stralloc_cats(&str, "&#x00E2;");
break;
case '\x84':
stralloc_cats(&str, "&#x00E4;");
break;
case '\x85':
stralloc_cats(&str, "&#x00E0;");
break;
case '\x86':
stralloc_cats(&str, "&#x00E5;");
break;
case '\x87':
stralloc_cats(&str, "&#x00E7;");
break;
case '\x88':
stralloc_cats(&str, "&#x00EA;");
break;
case '\x89':
stralloc_cats(&str, "&#x00EB;");
break;
case '\x8a':
stralloc_cats(&str, "&#x00E8;");
break;
case '\x8b':
stralloc_cats(&str, "&#x00EF;");
break;
case '\x8c':
stralloc_cats(&str, "&#x00EE;");
break;
case '\x8d':
stralloc_cats(&str, "&#x00EC;");
break;
case '\x8e':
stralloc_cats(&str, "&#x00C4;");
break;
case '\x8f':
stralloc_cats(&str, "&#x00C5;");
break;
case '\x90':
stralloc_cats(&str, "&#x00C9;");
break;
case '\x91':
stralloc_cats(&str, "&#x00E6;");
break;
case '\x92':
stralloc_cats(&str, "&#x00C6;");
break;
case '\x93':
stralloc_cats(&str, "&#x00F4;");
break;
case '\x94':
stralloc_cats(&str, "&#x00F6;");
break;
case '\x95':
stralloc_cats(&str, "&#x00F2;");
break;
case '\x96':
stralloc_cats(&str, "&#x00FB;");
break;
case '\x97':
stralloc_cats(&str, "&#x00F9;");
break;
case '\x98':
stralloc_cats(&str, "&#x00FF;");
break;
case '\x99':
stralloc_cats(&str, "&#x00D6;");
break;
case '\x9a':
stralloc_cats(&str, "&#x00DC;");
break;
case '\x9b':
stralloc_cats(&str, "&#x00A2;");
break;
case '\x9c':
stralloc_cats(&str, "&#x00A3;");
break;
case '\x9d':
stralloc_cats(&str, "&#x00A5;");
break;
case '\x9e':
stralloc_cats(&str, "&#x20A7;");
break;
case '\x9f':
stralloc_cats(&str, "&#x0192;");
break;
case '\xa0':
stralloc_cats(&str, "&#x00E1;");
break;
case '\xa1':
stralloc_cats(&str, "&#x00ED;");
break;
case '\xa2':
stralloc_cats(&str, "&#x00F3;");
break;
case '\xa3':
stralloc_cats(&str, "&#x00FA;");
break;
case '\xa4':
stralloc_cats(&str, "&#x00F1;");
break;
case '\xa5':
stralloc_cats(&str, "&#x00D1;");
break;
case '\xa6':
stralloc_cats(&str, "&#x00AA;");
break;
case '\xa7':
stralloc_cats(&str, "&#x00BA;");
break;
case '\xa8':
stralloc_cats(&str, "&#x00BF;");
break;
case '\xa9':
stralloc_cats(&str, "&#x2310;");
break;
case '\xaa':
stralloc_cats(&str, "&#x00AC;");
break;
case '\xab':
stralloc_cats(&str, "&#x00BD;");
break;
case '\xac':
stralloc_cats(&str, "&#x00BC;");
break;
case '\xad':
stralloc_cats(&str, "&#x00A1;");
break;
case '\xae':
stralloc_cats(&str, "&#x00AB;");
break;
case '\xaf':
stralloc_cats(&str, "&#x00BB;");
break;
case '\xb0':
stralloc_cats(&str, "&#x2591;");
break;
case '\xb1':
stralloc_cats(&str, "&#x2592;");
break;
case '\xb2':
stralloc_cats(&str, "&#x2593;");
break;
case '\xb3':
stralloc_cats(&str, "&#x2502;");
break;
case '\xb4':
stralloc_cats(&str, "&#x2524;");
break;
case '\xb5':
stralloc_cats(&str, "&#x2561;");
break;
case '\xb6':
stralloc_cats(&str, "&#x2562;");
break;
case '\xb7':
stralloc_cats(&str, "&#x2556;");
break;
case '\xb8':
stralloc_cats(&str, "&#x2555;");
break;
case '\xb9':
stralloc_cats(&str, "&#x2563;");
break;
case '\xba':
stralloc_cats(&str, "&#x2551;");
break;
case '\xbb':
stralloc_cats(&str, "&#x2557;");
break;
case '\xbc':
stralloc_cats(&str, "&#x255D;");
break;
case '\xbd':
stralloc_cats(&str, "&#x255C;");
break;
case '\xbe':
stralloc_cats(&str, "&#x255B;");
break;
case '\xbf':
stralloc_cats(&str, "&#x2510;");
break;
case '\xc0':
stralloc_cats(&str, "&#x2514;");
break;
case '\xc1':
stralloc_cats(&str, "&#x2534;");
break;
case '\xc2':
stralloc_cats(&str, "&#x252C;");
break;
case '\xc3':
stralloc_cats(&str, "&#x251C;");
break;
case '\xc4':
stralloc_cats(&str, "&#x2500;");
break;
case '\xc5':
stralloc_cats(&str, "&#x253C;");
break;
case '\xc6':
stralloc_cats(&str, "&#x255E;");
break;
case '\xc7':
stralloc_cats(&str, "&#x255F;");
break;
case '\xc8':
stralloc_cats(&str, "&#x255A;");
break;
case '\xc9':
stralloc_cats(&str, "&#x2554;");
break;
case '\xca':
stralloc_cats(&str, "&#x2569;");
break;
case '\xcb':
stralloc_cats(&str, "&#x2566;");
break;
case '\xcc':
stralloc_cats(&str, "&#x2560;");
break;
case '\xcd':
stralloc_cats(&str, "&#x2550;");
break;
case '\xce':
stralloc_cats(&str, "&#x256C;");
break;
case '\xcf':
stralloc_cats(&str, "&#x2567;");
break;
case '\xd0':
stralloc_cats(&str, "&#x2568;");
break;
case '\xd1':
stralloc_cats(&str, "&#x2564;");
break;
case '\xd2':
stralloc_cats(&str, "&#x2565;");
break;
case '\xd3':
stralloc_cats(&str, "&#x2559;");
break;
case '\xd4':
stralloc_cats(&str, "&#x255B;");
break;
case '\xd5':
stralloc_cats(&str, "&#x2552;");
break;
case '\xd6':
stralloc_cats(&str, "&#x2553;");
break;
case '\xd7':
stralloc_cats(&str, "&#x256B;");
break;
case '\xd8':
stralloc_cats(&str, "&#x256A;");
break;
case '\xd9':
stralloc_cats(&str, "&#x2518;");
break;
case '\xda':
stralloc_cats(&str, "&#x250C;");
break;
case '\xdb':
stralloc_cats(&str, "&#x2588;");
break;
case '\xdc':
stralloc_cats(&str, "&#x2584;");
break;
case '\xdd':
stralloc_cats(&str, "&#x258C;");
break;
case '\xde':
stralloc_cats(&str, "&#x2590;");
break;
case '\xdf':
stralloc_cats(&str, "&#x2580;");
break;
case '\xe0':
stralloc_cats(&str, "&#x03B1;");
break;
case '\xe1':
stralloc_cats(&str, "&#x03B2;");
break;
case '\xe2':
stralloc_cats(&str, "&#x0393;");
break;
case '\xe3':
stralloc_cats(&str, "&#x03C0;");
break;
case '\xe4':
stralloc_cats(&str, "&#x03A3;");
break;
case '\xe5':
stralloc_cats(&str, "&#x03C3;");
break;
case '\xe6':
stralloc_cats(&str, "&#x00B5;");
break;
case '\xe7':
stralloc_cats(&str, "&#x03C4;");
break;
case '\xe8':
stralloc_cats(&str, "&#x03A6;");
break;
case '\xe9':
stralloc_cats(&str, "&#x0398;");
break;
case '\xea':
stralloc_cats(&str, "&#x03A9;");
break;
case '\xeb':
stralloc_cats(&str, "&#x03B4;");
break;
case '\xec':
stralloc_cats(&str, "&#x221E;");
break;
case '\xed':
stralloc_cats(&str, "&#x2205;");
break;
case '\xee':
stralloc_cats(&str, "&#x2208;");
break;
case '\xef':
stralloc_cats(&str, "&#x2229;");
break;
case '\xf0':
stralloc_cats(&str, "&#x2261;");
break;
case '\xf1':
stralloc_cats(&str, "&#x00B1;");
break;
case '\xf2':
stralloc_cats(&str, "&#x2265;");
break;
case '\xf3':
stralloc_cats(&str, "&#x2264;");
break;
case '\xf4':
stralloc_cats(&str, "&#x2320;");
break;
case '\xf5':
stralloc_cats(&str, "&#x2321;");
break;
case '\xf6':
stralloc_cats(&str, "&#x00F7;");
break;
case '\xf7':
stralloc_cats(&str, "&#x2248;");
break;
case '\xf8':
stralloc_cats(&str, "&#x00B0;");
break;
case '\xf9':
stralloc_cats(&str, "&#x2219;");
break;
case '\xfa':
stralloc_cats(&str, "&#x00B7;");
break;
case '\xfb':
stralloc_cats(&str, "&#x221A;");
break;
case '\xfc':
stralloc_cats(&str, "&#x207F;");
break;
case '\xfd':
stralloc_cats(&str, "&#x00B2;");
break;
case '\xfe':
stralloc_cats(&str, "&#x25AA;");
break;
case ' ':
stralloc_cats(&str, "&nbsp;");
break;
default: default:
stralloc_append1(&str, *p); stralloc_append1(&str, *p);
break; break;
} }
} }
stralloc_0(&str);
new_tag->data = str.s; new_tag->data = str.s;
} else { } else {
new_tag->tag = strdup(tag); new_tag->tag = strdup(tag);
@ -48,6 +564,14 @@ struct www_tag *www_tag_new(char *tag, char *data) {
return new_tag; return new_tag;
} }
struct www_tag *www_tag_duplicate(struct www_tag *oldtag) {
struct www_tag *newtag = www_tag_new(oldtag->tag, oldtag->data);
for (int i=0;i<oldtag->attribs.len;i++) {
www_tag_add_attrib(newtag, strdup(ptr_vector_get(&oldtag->attribs, i)), strdup(ptr_vector_get(&oldtag->values, i)));
}
return newtag;
}
void www_tag_add_attrib(struct www_tag *tag, char *attrib, char *value) { void www_tag_add_attrib(struct www_tag *tag, char *attrib, char *value) {
ptr_vector_append(&tag->attribs, strdup(attrib)); ptr_vector_append(&tag->attribs, strdup(attrib));
ptr_vector_append(&tag->values, strdup(value)); ptr_vector_append(&tag->values, strdup(value));

View File

@ -15,6 +15,7 @@ struct www_tag {
extern struct www_tag *www_tag_new(char *tag, char *data); extern struct www_tag *www_tag_new(char *tag, char *data);
extern void www_tag_add_attrib(struct www_tag *tag, char *attrib, char *value); extern void www_tag_add_attrib(struct www_tag *tag, char *attrib, char *value);
extern struct www_tag *www_tag_duplicate(struct www_tag *oldtag);
extern void www_tag_add_child(struct www_tag *tag, struct www_tag *child); extern void www_tag_add_child(struct www_tag *tag, struct www_tag *child);
extern char *www_tag_unwravel(struct www_tag *tag); extern char *www_tag_unwravel(struct www_tag *tag);
#endif #endif