$B:dK\$G$9!#(B
>> >> $B$H$3$m$G!"%Z!<%8%c%b!<%I$G(B ANSI color $B%(%9%1!<%W%7!<%1%s%9$K(B
>> $B$3$l$J$s$G$9$,!"DL>o$OLdBj$J$$$b$N$N!"Bg$-$J%P%$%J%j(B(w3m $B<+?H$H$+(B)
>> $B$rFI$_9~$^$;$F$$$kESCf$G(B interrupt $B$rAw$k$H(B segmentation fault
>> $B$7$F$7$^$$$^$9!#(B
$B4X78$J$/Mn$A$k$h$&$G$9$M!#(B
$B$G$b$J$s$+Aj@-$,0-$$(B(100%$B6a$/Mn$A$k(B)$B$N$G$A$g$C$H$@$1Aj@-$,$$$$$h$&$J(B
patch $B$K:9$7BX$($^$9!#(B
PS.
$BK\F|$O(B m17n $BHG$O99?7L5$7!#(B
-----------------------------------
$B:dK\(B $B9@B'(B <hsaka@mth.biglobe.ne.jp>
http://www2u.biglobe.ne.jp/~hsaka/
diff -u buffer.c.orig buffer.c
--- buffer.c.orig Fri Dec 22 00:44:41 2000
+++ buffer.c Fri Dec 22 00:45:47 2000
@@ -548,6 +548,9 @@
Str tmp;
FILE *cache = NULL;
Line *l;
+#ifdef ANSI_COLOR
+ int colorflag;
+#endif
if (buf->savecache)
return -1;
@@ -570,8 +573,17 @@
fwrite1(l->usrflags, cache) ||
fwrite1(l->len, cache) ||
fwrite(l->lineBuf, 1, l->len, cache) < l->len ||
- fwrite(l->propBuf, sizeof(short), l->len, cache) < l->len)
+ fwrite(l->propBuf, sizeof(Lineprop), l->len, cache) < l->len)
goto _error;
+#ifdef ANSI_COLOR
+ colorflag = l->colorBuf ? 1 : 0;
+ if (fwrite1(colorflag, cache))
+ goto _error;
+ if (colorflag) {
+ if (fwrite(l->colorBuf, sizeof(Linecolor), l->len, cache) < l->len)
+ goto _error;
+ }
+#endif
}
fclose(cache);
@@ -590,6 +602,9 @@
FILE *cache;
Line *l = NULL, *prevl;
long lnum = 0, clnum, tlnum;
+#ifdef ANSI_COLOR
+ int colorflag;
+#endif
if (buf->savecache == NULL)
return -1;
@@ -623,8 +638,18 @@
l->lineBuf = New_N(char, l->len + 1);
fread(l->lineBuf, 1, l->len, cache);
l->lineBuf[l->len] = '\0';
- l->propBuf = New_N(short, l->len);
- fread(l->propBuf, sizeof(short), l->len, cache);
+ l->propBuf = New_N(Lineprop, l->len);
+ fread(l->propBuf, sizeof(Lineprop), l->len, cache);
+#ifdef ANSI_COLOR
+ if (fread1(colorflag, cache))
+ break;
+ if (colorflag) {
+ l->colorBuf = New_N(Linecolor, l->len);
+ fread(l->colorBuf, sizeof(Linecolor), l->len, cache);
+ } else {
+ l->colorBuf = NULL;
+ }
+#endif
}
buf->lastLine = prevl;
buf->lastLine->next = NULL;
diff -u configure.orig configure
--- configure.orig Fri Dec 22 00:44:42 2000
+++ configure Fri Dec 22 00:45:08 2000
@@ -435,6 +435,15 @@
def_use_nntp="#undef USE_NNTP"
fi
+echo "Do you want ANSI color escape sequences supprot?"
+yesno ansi_color "$ansi_color" n
+echo "ansi_color=$ansi_color" >> config.param
+if [ "$ansi_color" = y ]; then
+ def_ansi_color="#define ANSI_COLOR"
+else
+ def_ansi_color="#undef ANSI_COLOR"
+fi
+
echo ""
echo "Let's do some configurations. Choose config option among the list."
echo ""
@@ -1517,6 +1526,11 @@
* Support NNTP
*/
$def_use_nntp
+
+/*
+ * Support ANSI color escape sequences
+ */
+$def_ansi_color
/*
* Enable id attribute
diff -u display.c.orig display.c
--- display.c.orig Fri Dec 22 00:44:42 2000
+++ display.c Fri Dec 22 00:45:20 2000
@@ -163,6 +163,9 @@
#ifndef KANJI_SYMBOLS
static int graph_mode = 0;
#endif /* not KANJI_SYMBOLS */
+#ifdef ANSI_COLOR
+static Linecolor color_mode = 0;
+#endif
#ifdef BUFINFO
static Buffer *save_current_buf = NULL;
@@ -316,6 +319,9 @@
int column = buf->currentColumn;
char *p;
Lineprop *pr;
+#ifdef ANSI_COLOR
+ Linecolor *pc;
+#endif
if (l == NULL) {
if (buf->pagerSource) {
@@ -335,6 +341,12 @@
pos = columnPos(l, column);
p = &(l->lineBuf[pos]);
pr = &(l->propBuf[pos]);
+#ifdef ANSI_COLOR
+ if (useColor && l->colorBuf)
+ pc = &(l->colorBuf[pos]);
+ else
+ pc = NULL;
+#endif
rcol = COLPOS(l, pos);
#ifndef JP_CHARSET
@@ -350,6 +362,10 @@
ncol = COLPOS(l, pos + j + delta);
if (ncol - column > COLS)
break;
+#ifdef ANSI_COLOR
+ if (pc)
+ do_color(pc[j]);
+#endif
if (rcol < column) {
for (rcol = column; rcol < ncol; rcol++)
addChar(' ', 0);
@@ -409,6 +425,10 @@
graphend();
}
#endif /* not KANJI_SYMBOLS */
+#ifdef ANSI_COLOR
+ if (color_mode)
+ do_color(0);
+#endif
if (rcol - column < COLS)
clrtoeolx();
return l->next;
@@ -421,6 +441,9 @@
int column = buf->currentColumn;
char *p;
Lineprop *pr;
+#ifdef ANSI_COLOR
+ Linecolor *pc;
+#endif
int bcol, ecol;
if (l == NULL)
@@ -428,6 +451,12 @@
pos = columnPos(l, column);
p = &(l->lineBuf[pos]);
pr = &(l->propBuf[pos]);
+#ifdef ANSI_COLOR
+ if (useColor && l->colorBuf)
+ pc = &(l->colorBuf[pos]);
+ else
+ pc = NULL;
+#endif
rcol = COLPOS(l, pos);
bcol = bpos - pos;
ecol = epos - pos;
@@ -445,6 +474,10 @@
ncol = COLPOS(l, pos + j + delta);
if (ncol - column > COLS)
break;
+#ifdef ANSI_COLOR
+ if (pc)
+ do_color(pc[j]);
+#endif
if (j >= bcol && j < ecol) {
if (rcol < column) {
move(i, 0);
@@ -507,6 +540,10 @@
graphend();
}
#endif /* not KANJI_SYMBOLS */
+#ifdef ANSI_COLOR
+ if (color_mode)
+ do_color(0);
+#endif
return rcol - column;
}
@@ -561,6 +598,24 @@
}
#endif /* not KANJI_SYMBOLS */
}
+
+#ifdef ANSI_COLOR
+void
+do_color(Linecolor c)
+{
+ if (c & 0x8)
+ setfcolor(c & 0x7);
+ else if (color_mode & 0x8)
+ setfcolor(basic_color);
+#ifdef BG_COLOR
+ if (c & 0x80)
+ setbcolor((c >> 4) & 0x7);
+ else if (color_mode & 0x80)
+ setbcolor(bg_color);
+#endif
+ color_mode = c;
+}
+#endif
void
addChar(char c, Lineprop mode)
diff -u etc.c.orig etc.c
--- etc.c.orig Fri Dec 22 00:44:42 2000
+++ etc.c Fri Dec 22 01:31:36 2000
@@ -263,24 +263,125 @@
return allocStr(arg, p - arg);
}
+#ifdef ANSI_COLOR
+static int
+parse_ansi_color(char **str, Lineprop *effect, Linecolor *color)
+{
+ char *p = *str, *q;
+ Lineprop e = *effect;
+ Linecolor c = *color;
+ int i;
+
+ if (*p != ESC_CODE || *(p+1) != '[')
+ return 0;
+ p += 2;
+ for (q = p; IS_DIGIT(*q) || *q == ';'; q++)
+ ;
+ if (*q != 'm')
+ return 0;
+ *str = q + 1;
+ while (1) {
+ if (*p == 'm') {
+ e = PE_NORMAL;
+ c = 0;
+ break;
+ }
+ if (IS_DIGIT(*p)) {
+ q = p;
+ for (p++; IS_DIGIT(*p); p++)
+ ;
+ i = atoi(allocStr(q, p - q));
+ switch (i) {
+ case 0:
+ e = PE_NORMAL;
+ c = 0;
+ break;
+ case 1:
+ case 5:
+ e = PE_BOLD;
+ break;
+ case 4:
+ e = PE_UNDER;
+ break;
+ case 7:
+ e = PE_STAND;
+ break;
+ case 100: /* for EWS4800 kterm */
+ c = 0;
+ break;
+ case 39:
+ c &= 0xf0;
+ break;
+ case 49:
+ c &= 0x0f;
+ break;
+ default:
+ if (i >= 30 && i <= 37)
+ c = (c & 0xf0) | (i - 30) | 0x08;
+ else if (i >= 40 && i <= 47)
+ c = (c & 0x0f) | ((i - 40) << 4) | 0x80;
+ break;
+ }
+ if (*p == 'm')
+ break;
+ } else {
+ e = PE_NORMAL;
+ c = 0;
+ break;
+ }
+ p++; /* *p == ';' */
+ }
+ *effect = e;
+ *color = c;
+ return 1;
+}
+#endif
+
/*
* Check character type
*/
Str
-checkType(Str s, Lineprop * oprop, int len)
+checkType(Str s, Lineprop * oprop,
+#ifdef ANSI_COLOR
+ Linecolor * ocolor, int * check_color,
+#endif
+ int len)
{
Lineprop mode;
Lineprop effect = PE_NORMAL;
Lineprop *prop = oprop;
char *str = s->ptr, *endp = &s->ptr[s->length], *bs = NULL;
+#ifdef ANSI_COLOR
+ Lineprop ceffect = PE_NORMAL;
+ Linecolor cmode = 0;
+ Linecolor *color = NULL;
+ char *es = NULL;
+#endif
int do_copy = FALSE;
int size = (len < s->length) ? len : s->length;
- if (ShowEffect && (bs = memchr(str, '\b', s->length)) ||
- s->length > size) {
- s = Strnew_size(size);
- do_copy = TRUE;
+#ifdef ANSI_COLOR
+ if (check_color)
+ *check_color = FALSE;
+#endif
+ if (ShowEffect) {
+ bs = memchr(str, '\b', s->length);
+#ifdef ANSI_COLOR
+ if (ocolor) {
+ es = memchr(str, ESC_CODE, s->length);
+ if (es)
+ color = ocolor;
+ }
+#endif
+ if (s->length > size || (bs != NULL)
+#ifdef ANSI_COLOR
+ || (es != NULL)
+#endif
+ ) {
+ s = Strnew_size(size);
+ do_copy = TRUE;
+ }
}
while (str < endp) {
@@ -290,13 +391,15 @@
if (str == bs - 2 && !strncmp(str, "__\b\b", 4)) {
str += 4;
effect = PE_UNDER;
- bs = memchr(str, '\b', endp - str);
+ if (str < endp)
+ bs = memchr(str, '\b', endp - str);
continue;
}
else if (str == bs - 1 && *str == '_') {
str += 2;
effect = PE_UNDER;
- bs = memchr(str, '\b', endp - str);
+ if (str < endp)
+ bs = memchr(str, '\b', endp - str);
continue;
}
else if (str == bs) {
@@ -400,12 +503,36 @@
str++;
}
}
- bs = memchr(str, '\b', endp - str);
+ if (str < endp)
+ bs = memchr(str, '\b', endp - str);
continue;
}
+#ifdef ANSI_COLOR
+ else if (str > bs)
+ bs = memchr(str, '\b', endp - str);
+#endif
+ }
+#ifdef ANSI_COLOR
+ if (es != NULL) {
+ if (str == es) {
+ int ok = parse_ansi_color(&str, &ceffect, &cmode);
+ if (str < endp)
+ es = memchr(str, ESC_CODE, endp - str);
+ if (ok) {
+ if (cmode)
+ *check_color = TRUE;
+ continue;
+ }
+ }
+ else if (str > es)
+ es = memchr(str, ESC_CODE, endp - str);
}
+#endif
mode = get_mctype(str);
+#ifdef ANSI_COLOR
+ effect |= ceffect;
+#endif
#ifdef JP_CHARSET
if (mode == PC_KANJI) {
prop[0] = (effect | PC_KANJI1);
@@ -416,6 +543,13 @@
}
prop += 2;
str += 2;
+#ifdef ANSI_COLOR
+ if (color) {
+ color[0] = cmode;
+ color[1] = cmode;
+ color += 2;
+ }
+#endif
}
else
#endif /* JP_CHARSET */
@@ -425,6 +559,12 @@
Strcat_char(s, *str);
prop++;
str++;
+#ifdef ANSI_COLOR
+ if (color) {
+ *color = cmode;
+ color++;
+ }
+#endif
}
effect = PE_NORMAL;
}
diff -u file.c.orig file.c
--- file.c.orig Fri Dec 22 00:44:42 2000
+++ file.c Fri Dec 22 01:10:26 2000
@@ -34,9 +34,16 @@
Buffer * (*loadproc) (URLFile *, Buffer *),
Buffer *defaultbuf);
static void close_textarea(struct html_feed_environ *h_env);
-static void addnewline(Buffer * buf, char *line, Lineprop * prop, int pos, int nlines);
+static void addnewline(Buffer * buf, char *line, Lineprop * prop,
+#ifdef ANSI_COLOR
+ Linecolor * color,
+#endif
+ int pos, int nlines);
static Lineprop propBuffer[LINELEN];
+#ifdef ANSI_COLOR
+static Linecolor colorBuffer[LINELEN];
+#endif
static JMP_BUF AbortLoading;
@@ -494,10 +501,16 @@
for (p = lineBuf2->ptr; *p; p = q) {
for (q = p; *q && *q != '\r' && *q != '\n'; q++);
lineBuf2 = checkType(Strnew_charp(p), propBuffer,
+#ifdef ANSI_COLOR
+ NULL, NULL,
+#endif
min(LINELEN, q - p));
Strcat(tmp, lineBuf2);
if (thru)
addnewline(newBuf, lineBuf2->ptr, propBuffer,
+#ifdef ANSI_COLOR
+ NULL,
+#endif
lineBuf2->length, -1);
for (; *q && (*q == '\r' || *q == '\n'); q++);
}
@@ -697,7 +710,11 @@
lineBuf2 = NULL;
}
if (thru)
- addnewline(newBuf, "\n", propBuffer, 1, -1);
+ addnewline(newBuf, "\n", propBuffer,
+#ifdef ANSI_COLOR
+ NULL,
+#endif
+ 1, -1);
}
char *
@@ -3844,7 +3861,11 @@
}
}
/* end of processing for one line */
- addnewline(buf, outc, outp, pos, nlines);
+ addnewline(buf, outc, outp,
+#ifdef ANSI_COLOR
+ NULL,
+#endif
+ pos, nlines);
if (str != endp) {
line = Strsubstr(line, str - line->ptr, endp - str);
goto proc_again;
@@ -4324,7 +4345,11 @@
extern Lineprop NullProp[];
static void
-addnewline(Buffer * buf, char *line, Lineprop * prop, int pos, int nlines)
+addnewline(Buffer * buf, char *line, Lineprop * prop,
+#ifdef ANSI_COLOR
+ Linecolor * color,
+#endif
+ int pos, int nlines)
{
Line *l;
l = New(Line);
@@ -4332,12 +4357,20 @@
if (pos > 0) {
l->lineBuf = allocStr(line, pos);
l->propBuf = New_N(Lineprop, pos);
+ bcopy((void *) prop, (void *) l->propBuf, pos * sizeof(Lineprop));
}
else {
l->lineBuf = NullLine;
l->propBuf = NullProp;
}
- bcopy((void *) prop, (void *) l->propBuf, pos * sizeof(Lineprop));
+#ifdef ANSI_COLOR
+ if (pos > 0 && color) {
+ l->colorBuf = New_N(Linecolor, pos);
+ bcopy((void *) color, (void *) l->colorBuf, pos * sizeof(Linecolor));
+ } else {
+ l->colorBuf = NULL;
+ }
+#endif
l->len = pos;
l->prev = buf->currentLine;
if (buf->currentLine) {
@@ -4841,6 +4874,9 @@
int nlines;
Str tmpf;
int linelen = 0, trbyte = 0;
+#ifdef ANSI_COLOR
+ int check_color;
+#endif
MySignalHandler(*prevtrap) ();
if (newBuf == NULL)
@@ -4903,8 +4939,16 @@
}
#endif /* USE_NNTP */
Strchop(lineBuf2);
- lineBuf2 = checkType(lineBuf2, propBuffer, LINELEN);
- addnewline(newBuf, lineBuf2->ptr, propBuffer, lineBuf2->length, nlines);
+ lineBuf2 = checkType(lineBuf2, propBuffer,
+#ifdef ANSI_COLOR
+ colorBuffer, &check_color,
+#endif
+ LINELEN);
+ addnewline(newBuf, lineBuf2->ptr, propBuffer,
+#ifdef ANSI_COLOR
+ check_color ? colorBuffer : NULL,
+#endif
+ lineBuf2->length, nlines);
}
_end:
if (fmInitialized) {
@@ -5108,6 +5152,9 @@
URLFile uf;
char code;
int squeeze_flag = 0;
+#ifdef ANSI_COLOR
+ int check_color;
+#endif
if (buf->pagerSource == NULL)
return NULL;
@@ -5164,12 +5211,24 @@
lineBuf2 = tmp;
}
Strchop(lineBuf2);
- lineBuf2 = checkType(lineBuf2, propBuffer, LINELEN);
+ lineBuf2 = checkType(lineBuf2, propBuffer,
+#ifdef ANSI_COLOR
+ colorBuffer, &check_color,
+#endif
+ LINELEN);
len = lineBuf2->length;
l = New(Line);
l->lineBuf = lineBuf2->ptr;
l->propBuf = New_N(Lineprop, len);
bcopy((void *) propBuffer, (void *) l->propBuf, len * sizeof(Lineprop));
+#ifdef ANSI_COLOR
+ if (check_color) {
+ l->colorBuf = New_N(Linecolor, len);
+ bcopy((void *) colorBuffer, (void *) l->colorBuf, len * sizeof(Linecolor));
+ } else {
+ l->colorBuf = NULL;
+ }
+#endif
l->len = len;
l->prev = pl;
if (squeezeBlankLine) {
diff -u fm.h.orig fm.h
--- fm.h.orig Fri Dec 22 00:44:42 2000
+++ fm.h Fri Dec 22 00:47:55 2000
@@ -21,6 +21,10 @@
#define MENU_SELECT
#endif /* MENU */
+#ifndef COLOR
+#undef ANSI_COLOR
+#endif
+
#include "ctrlcode.h"
#include "html.h"
#include "gc.h"
@@ -248,6 +252,9 @@
*/
typedef unsigned short Lineprop;
+#ifdef ANSI_COLOR
+typedef unsigned char Linecolor;
+#endif
typedef struct _MapList {
Str name;
@@ -258,6 +265,9 @@
typedef struct _Line {
char *lineBuf;
Lineprop *propBuf;
+#ifdef ANSI_COLOR
+ Linecolor *colorBuf;
+#endif
struct _Line *next;
struct _Line *prev;
short len;
diff -u proto.h.orig proto.h
--- proto.h.orig Fri Dec 22 00:44:42 2000
+++ proto.h Fri Dec 22 01:09:40 2000
@@ -168,6 +168,9 @@
extern Line *redrawLine(Buffer * buf, Line * l, int i);
extern int redrawLineRegion(Buffer * buf, Line * l, int i, int bpos, int epos);
extern void do_effects(Lineprop m);
+#ifdef ANSI_COLOR
+extern void do_color(Linecolor c);
+#endif
extern void addChar(char c, Lineprop mode);
extern void message(char *s, int return_x, int return_y);
extern void disp_message_nsec(char *s, int redraw_current, int sec, int purge, int mouse);
@@ -192,7 +195,11 @@
extern Line *lineSkip(Buffer * buf, Line * line, int offset, int last);
extern int gethtmlcmd(char **s, int *status);
extern char *getAnchor(char *arg, char **arg_return);
-extern Str checkType(Str s, Lineprop * oprop, int len);
+extern Str checkType(Str s, Lineprop * oprop,
+#ifdef ANSI_COLOR
+ Linecolor * ocolor, int * check_color,
+#endif
+ int len);
extern int calcPosition(char *l, Lineprop *pr, int len, int pos, int bpos, int mode);
extern char *lastFileName(char *path);
extern char *mybasename(char *s);
This archive was generated by hypermail 2b29 : Thu Dec 21 2000 - 11:08:32 CST