experimental ansi messages in www

This commit is contained in:
Andrew Pamment 2017-03-30 22:49:49 +10:00
parent f29ed7e0b0
commit 2d7d585fcc
8 changed files with 388 additions and 23 deletions

View File

@ -29,7 +29,7 @@ $(CDK):
cd deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses
cd deps/cdk-5.0-20161210/ && $(MAKE) cd deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -34,7 +34,7 @@ $(CDK):
cd deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses
cd deps/cdk-5.0-20161210/ && $(MAKE) cd deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o hashmap/hashmap.o OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o hashmap/hashmap.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -34,7 +34,7 @@ $(CDK):
cd deps/cdk-5.0-20161210/ && ./configure cd deps/cdk-5.0-20161210/ && ./configure
cd deps/cdk-5.0-20161210/ && $(MAKE) cd deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o hashmap/hashmap.o OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o hashmap/hashmap.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -34,7 +34,7 @@ $(CDK):
cd deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses cd deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses
cd deps/cdk-5.0-20161210/ && $(MAKE) cd deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o hashmap/hashmap.o OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o hashmap/hashmap.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

View File

@ -34,7 +34,7 @@ $(CDK):
cd deps/cdk-5.0-20161210/ && ./configure cd deps/cdk-5.0-20161210/ && ./configure
cd deps/cdk-5.0-20161210/ && $(MAKE) cd deps/cdk-5.0-20161210/ && $(MAKE)
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o hashmap/hashmap.o OBJ = deps/aha/aha.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o hashmap/hashmap.o
%.o: %.c $(DEPS) %.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS) $(CC) -c -o $@ $< $(CFLAGS)

1
bbs.h
View File

@ -258,6 +258,7 @@ extern int msg_is_to(struct user_record *user, char *addressed_to, char *address
extern int msg_is_from(struct user_record *user, char *addressed_from, char *address, int type, int rn, int msgconf); extern int msg_is_from(struct user_record *user, char *addressed_from, char *address, int type, int rn, int msgconf);
extern unsigned long generate_msgid(); extern unsigned long generate_msgid();
extern int door_menu(struct user_record *user); extern int door_menu(struct user_record *user);
extern void rundoor(struct user_record *user, char *cmd, int stdio); extern void rundoor(struct user_record *user, char *cmd, int stdio);
extern void runexternal(struct user_record *user, char *cmd, int stdio, char **argv, char *cwd, int raw); extern void runexternal(struct user_record *user, char *cmd, int stdio, char **argv, char *cwd, int raw);

363
deps/aha/aha.c vendored Normal file
View File

@ -0,0 +1,363 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
Alternatively, the contents of this file may be used under the terms
of the GNU Lesser General Public license version 2 or later (LGPL2+),
in which case the provisions of LGPL License are applicable instead of
those above.
For feedback and questions about my Files and Projects please mail me,
Alexander Matthes (Ziz) , ziz_at_mailbox.org
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
extern void unmangle_ansi(char *body, int len, char **body_out, int *body_len);
typedef struct selem *pelem;
typedef struct selem {
unsigned char digit[8];
unsigned char digitcount;
pelem next;
} telem;
pelem parseInsert(char* s)
{
pelem firstelem=NULL;
pelem momelem=NULL;
unsigned char digit[8];
unsigned char digitcount=0;
int pos=0;
for (pos=0;pos<1024;pos++)
{
if (s[pos]=='[')
continue;
if (s[pos]==';' || s[pos]==0)
{
if (digitcount==0)
{
digit[0]=0;
digitcount=1;
}
pelem newelem=(pelem)malloc(sizeof(telem));
for (unsigned char a=0;a<8;a++)
newelem->digit[a]=digit[a];
newelem->digitcount=digitcount;
newelem->next=NULL;
if (momelem==NULL)
firstelem=newelem;
else
momelem->next=newelem;
momelem=newelem;
digitcount=0;
memset(digit,0,8);
if (s[pos]==0)
break;
}
else
if (digitcount<8)
{
digit[digitcount]=s[pos]-'0';
digitcount++;
}
}
return firstelem;
}
void deleteParse(pelem elem)
{
while (elem!=NULL)
{
pelem temp=elem->next;
free(elem);
elem=temp;
}
}
void append_output(char *output, char *stuff, int *size, int *at) {
if (*at + strlen(stuff) + 1 >= *size) {
*size += 256;
output = realloc(output, *size);
}
strcat(output, stuff);
*at += strlen(stuff);
}
char * aha(char *input)
{
//Searching Parameters
char *unmangle_out;
int unmangle_out_len;
unmangle_ansi(input, strlen(input), &unmangle_out, &unmangle_out_len);
//Begin of Conversion
unsigned int c;
int fc = -1; //Standard Foreground Color //IRC-Color+8
int bc = -1; //Standard Background Color //IRC-Color+8
int ul = 0; //Not underlined
int bo = 0; //Not bold
int bl = 0; //No Blinking
int ofc,obc,oul,obo,obl; //old values
int line=0;
int momline=0;
int newline=-1;
int temp;
char *ptr = unmangle_out;
char *output = (char *)malloc(256);
int size;
int outat = 0;
char minibuf[2];
while (*ptr != '\0')
{
c = *ptr++;
if (c=='\033')
{
//Saving old values
ofc=fc;
obc=bc;
oul=ul;
obo=bo;
obl=bl;
//Searching the end (a letter) and safe the insert:
c= *ptr++;
if ( c == '[' ) // CSI code, see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
{
char buffer[1024];
buffer[0] = '[';
int counter=1;
while ((c<'A') || ((c>'Z') && (c<'a')) || (c>'z'))
{
c=*ptr++;
buffer[counter]=c;
if (c=='>') //end of htop
break;
counter++;
if (counter>1022)
break;
}
buffer[counter-1]=0;
pelem elem;
switch (c)
{
case 'm':
//printf("\n%s\n",buffer); //DEBUG
elem=parseInsert(buffer);
pelem momelem=elem;
while (momelem!=NULL)
{
//jump over zeros
int mompos=0;
while (mompos<momelem->digitcount && momelem->digit[mompos]==0)
mompos++;
if (mompos==momelem->digitcount) //only zeros => delete all
{
bo=0;ul=0;bl=0;fc=-1;bc=-1;
}
else
{
switch (momelem->digit[mompos])
{
case 1: if (mompos+1==momelem->digitcount) // 1, 1X not supported
bo=1;
break;
case 2: if (mompos+1<momelem->digitcount) // 2X, 2 not supported
switch (momelem->digit[mompos+1])
{
case 1: //Reset and double underline (which aha doesn't support)
case 2: //Reset bold
bo=0;
break;
case 4: //Reset underline
ul=0;
break;
case 5: //Reset blink
bl=0;
break;
case 7: //Reset Inverted
if (bc == -1)
bc = 8;
if (fc == -1)
fc = 9;
temp = bc;
bc = fc;
fc = temp;
break;
}
break;
case 3: if (mompos+1<momelem->digitcount) // 3X, 3 not supported
fc=momelem->digit[mompos+1];
break;
case 4: if (mompos+1==momelem->digitcount) // 4
ul=1;
else // 4X
bc=momelem->digit[mompos+1];
break;
case 5: if (mompos+1==momelem->digitcount) //5, 5X not supported
bl=1;
break;
//6 and 6X not supported at all
case 7: if (bc == -1) //7, 7X is mot defined (and supported)
bc = 8;
if (fc == -1)
fc = 9;
temp = bc;
bc = fc;
fc = temp;
break;
//8 and 9 not supported
}
}
momelem=momelem->next;
}
deleteParse(elem);
break;
}
//Checking the differences
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))
{
append_output(output, "<span style=\"", &size, &outat);
switch (fc)
{
case 0:
append_output(output, "color:dimgray;", &size, &outat);
break; //Black
case 1:
append_output(output, "color:red;", &size, &outat);
break; //Red
case 2:
append_output(output, "color:lime;", &size, &outat);
break; //Green
case 3:
append_output(output, "color:yellow;", &size, &outat);
break; //Yellow
case 4:
append_output(output, "color:#3333FF;", &size, &outat);
break; //Blue
case 5:
append_output(output, "color:fuchsia;", &size, &outat);
break; //Purple
case 6:
append_output(output, "color:aqua;", &size, &outat);
break; //Cyan
case 7:
append_output(output, "color:white;", &size, &outat);
break; //White
case 8:
append_output(output, "color:black;", &size, &outat);
break; //Background Colour
case 9:
append_output(output, "color:white;", &size, &outat);
break; //Foreground Color
}
switch (bc)
{
case 0:
append_output(output, "background-color:black;", &size, &outat);
break; //Black
case 1:
append_output(output, "background-color:red;", &size, &outat);
break; //Red
case 2:
append_output(output, "background-color:lime;", &size, &outat);
break; //Green
case 3:
append_output(output, "background-color:yellow;", &size, &outat);
break; //Yellow
case 4:
append_output(output, "background-color:#3333FF;", &size, &outat);
break; //Blue
case 5:
append_output(output, "background-color:fuchsia;", &size, &outat);
break; //Purple
case 6:
append_output(output, "background-color:aqua;", &size, &outat);
break; //Cyan
case 7:
append_output(output, "background-color:white;", &size, &outat);
break; //White
case 8:
append_output(output, "background-color:black;", &size, &outat);
break; //Background Colour
case 9:
append_output(output, "background-color:white;", &size, &outat);
break; //Foreground Colour
}
if (ul)
{
append_output(output, "text-decoration:underline;", &size, &outat);
}
if (bo)
{
append_output(output, "font-weight:bold;", &size, &outat);
}
if (bl)
{
append_output(output, "text-decoration:blink;", &size, &outat);
}
append_output(output, "\">", &size, &outat);
}
}
}
}
else
if (c==13)
{
for (;line<80;line++)
append_output(output, " ", &size, &outat);
line=0;
momline++;
append_output(output, "\n", &size, &outat);
}
else if (c!=8)
{
line++;
if (newline>=0)
{
while (newline>line)
{
append_output(output, " ", &size, &outat);
line++;
}
newline=-1;
}
switch (c)
{
case '&': append_output(output, "&amp;", &size, &outat); break;
case '\"': append_output(output, "&quot;", &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;
default: {
sprintf(minibuf, "%c", c);
append_output(output, minibuf, &size, &outat);
}
}
}
}
//Footer
if ((fc!=-1) || (bc!=-1) || (ul!=0) || (bo!=0) || (bl!=0))
append_output(output, "</span>\n", &size, &outat);
return 0;
}

View File

@ -12,7 +12,7 @@
#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;
static int new_messages(struct user_record *user, int conference, int area) { static int new_messages(struct user_record *user, int conference, int area) {
@ -269,6 +269,10 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
char buffer[4096]; char buffer[4096];
int chars; int chars;
int i; int i;
char *aha_text;
char *aha_out;
if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) { if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) {
return NULL; return NULL;
} }
@ -461,23 +465,20 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i
len += strlen(buffer); len += strlen(buffer);
for (z=0;z<jmh.TxtLen;z++) { aha_text = (char *)malloc(jmh.TxtLen + 1);
if (body[z] == '\r') {
sprintf(buffer, "<br />"); memcpy(aha_text, body, jmh.TxtLen);
} else if (body[z] == '<') { aha_text[jmh.TxtLen] = '\0';
sprintf(buffer, "&lt;");
} else if (body[z] == '>') { aha_out = aha(aha_text);
sprintf(buffer, "&gt;");
} else { while (len + strlen(aha_out) > max_len - 1) {
sprintf(buffer, "%c", body[z]); max_len += 4096;
} page = (char *)realloc(page, max_len);
if (len + strlen(buffer) > max_len - 1) { }
max_len += 4096; strcat(page, aha_out);
page = (char *)realloc(page, max_len); len += strlen(aha_out);
}
strcat(page, buffer);
len += strlen(buffer);
}
sprintf(buffer, "</div>\n"); sprintf(buffer, "</div>\n");
if (len + strlen(buffer) > max_len - 1) { if (len + strlen(buffer) > max_len - 1) {