Skip to content

Commit

Permalink
new base64 encoded xterm-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Hallen committed Apr 6, 2005
1 parent 70651fb commit dbd5b60
Show file tree
Hide file tree
Showing 6 changed files with 649 additions and 653 deletions.
28 changes: 14 additions & 14 deletions TODO
Expand Up @@ -703,19 +703,19 @@ ESC c compile (supposed to be center line)
-----------------
notepad/cua mode?
-----------------
^A select all
^F find
^G goto line
^H replace
^J return
^N new blank file
^O edit file (asks to save current)
- ^A select all
- ^F find
- ^G goto line
X ^H replace
X ^J return
- ^N new blank file
- ^O edit file (asks to save current)
^P print
^S save
^V paste
^Z undo
^X cut
^C copy
F3 find next
F5 date/time
- ^S save
- ^V paste
- ^Z undo
- ^X cut
- ^C copy
- F3 find next
- F5 date/time

2 changes: 1 addition & 1 deletion joerc.in
Expand Up @@ -1063,7 +1063,7 @@ if,"char==65",then,"it's an A",else,"it's not an a",endif ^[ q
correct, it will override these later on.

paste ^[ [ 2 0 2 ~ Bracketed paste
paste ^[ [ 2 0 0 ~ Bracketed paste

insc ^[ [ 2 ~
insc ^[ [ L SCO

Expand Down
110 changes: 96 additions & 14 deletions mouse.c
Expand Up @@ -112,7 +112,7 @@ int uxtmouse(BW *bw)
else if ((maint->curwin->watom->what & TYPETW ||
maint->curwin->watom->what & TYPEPW) &&
joexterm && (Cb & 3) == 1) /* Paste */
ttputs(US "\33[y");
ttputs(US "\33[?P");
return 0;
}

Expand Down Expand Up @@ -145,6 +145,83 @@ void mousedn(int x,int y)
}
}

/* Return base64 code character given 6-bit number */

char base64_code[]="\
ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz\
0123456789+/";

int base64_accu = 0;
int base64_count = 0;
int base64_pad = 0;

static void ttputs64(unsigned char *p, unsigned length)
{
unsigned char buf[65];
unsigned x = 0;
while (length--) {
switch (base64_count) {
case 0:
buf[x++] = base64_code[*p >> 2];
base64_accu = (*p & 0x3);
base64_count = 2;
++p;
break;
case 2:
buf[x++] = base64_code[(base64_accu << 4) + (*p >> 4)];
base64_accu = (*p & 0xF);
base64_count = 4;
++p;
break;
case 4:
buf[x++] = base64_code[(base64_accu << 2) + (*p >> 6)];
buf[x++] = base64_code[*p & 0x3F];
base64_accu = 0;
base64_count = 0;
++p;
break;
}
if (x >= 63) {
/* Write 63 or 64 characters */
base64_pad += x;
buf[x] = 0;
ttputs(buf);
x = 0;
}
}
if (x != 0) {
base64_pad += x;
buf[x] = 0;
ttputs(buf);
}
}

static void ttputs64_flush()
{
unsigned char x;
switch (base64_count) {
case 0:
break;
case 2:
x = base64_code[base64_accu << 4];
ttputc(x);
break;
case 4:
x = base64_code[base64_accu << 2];
ttputc(x);
break;
}
if (base64_pad & 3) {
x = 4 - (base64_pad & 3);
while (x--)
ttputc('=');
}
base64_count = 0;
base64_accu = 0;
base64_pad = 0;
}

void select_done(struct charmap *map)
{
/* Feed text to xterm */
Expand All @@ -153,8 +230,10 @@ void select_done(struct charmap *map)
long right = markk->xcol;
P *q = pdup(markb);
int c;
ttputs(US "\33[1y");
ttputs(US "\33[?2P");
while (q->byte < markk->byte) {
unsigned char buf[16];
int len;
/* Skip until we're within columns */
while (q->byte < markk->byte && square && (piscol(q) < left || piscol(q) >= right))
pgetc(q);
Expand All @@ -165,35 +244,38 @@ void select_done(struct charmap *map)
if (map->type)
if (locale_map->type) {
/* UTF-8 char to UTF-8 terminal */
unsigned char buf[16];
utf8_encode(buf,c);
ttputs(buf);
len = utf8_encode(buf,c);
ttputs64(buf, len);
} else {
/* UTF-8 char to non-UTF-8 terminal */
c = from_uni(locale_map,c);
if (c ==-1)
if (c == -1)
c = '?';
ttputc(c);
buf[0] = c;
ttputs64(buf, 1);
}
else
if (locale_map->type) {
/* Non-UTF-8 to UTF-8 terminal */
unsigned char buf[16];
c = to_uni(map, c);
if (c == -1)
c = '?';
utf8_encode(buf,c);
ttputs(buf);
len = utf8_encode(buf,c);
ttputs64(buf, len);
} else {
/* Non-UTF-8 to non-UTF-8 terminal */
ttputc(c);
buf[0] = c;
ttputs64(buf, 1);
}
}
/* Add a new line if we went past right edge of column */
if (square && q->byte<markk->byte && piscol(q) >= right)
ttputc(10);
if (square && q->byte<markk->byte && piscol(q) >= right) {
buf[0] = 10;
ttputs64(buf, 1);
}
}
ttputs(US "\33\33");
ttputs64_flush();
ttputs(US "\33");
prm(q);
}
}
Expand Down
63 changes: 49 additions & 14 deletions uedit.c
Expand Up @@ -2350,34 +2350,69 @@ int uname_joe(BW *bw)
return 0;
}

/* Insert until magic code: "ESC [ 2 0 1 ~" received */
/* Insert until non-base64 character received */

int upaste(BW *bw, int k)
{
unsigned char buf[6];
int buf_len = 0;
int c;
int accu;
int count;
int tmp_ww = bw->o.wordwrap;
int tmp_ai = bw->o.autoindent;

bw->o.wordwrap = 0;
bw->o.autoindent = 0;
count = 0;

while ((c = ttgetc()) != -1) {
if (buf_len == 6) {
if (buf[0] == 13)
rtntw(bw);
else
utypebw(bw, buf[0]);
memmove(buf, buf+1, 5);
buf[5] = c;
} else
buf[buf_len++] = c;
if (buf_len == 6 && !strncmp((char *)buf, "\033[201~", 6)) {
if (c >= 'A' && c <= 'Z')
c = c - 'A';
else if (c >= 'a' && c <= 'z')
c = c - 'a' + 26;
else if (c >= '0' && c <= '9')
c = c - '0' + 52;
else if (c == '+')
c = 62;
else if (c == '/')
c = 63;
else if (c == '=')
continue;
else
break;

switch (count) {
case 0:
accu = c;
count = 6;
break;
case 2:
accu = (accu << 6) + c;
if (accu == 13)
rtntw(bw);
else
utypebw(bw, accu);
count = 0;
break;
case 4:
accu = (accu << 4) + (c >> 2);
if (accu == 13)
rtntw(bw);
else
utypebw(bw, accu);
accu = (c & 0x3);
count = 2;
break;
case 6:
accu = (accu << 2) + (c >> 4);
if (accu == 13)
rtntw(bw);
else
utypebw(bw, accu);
accu = (c & 0xF);
count = 4;
break;
}
}

bw->o.wordwrap = tmp_ww;
bw->o.autoindent = tmp_ai;

Expand Down

0 comments on commit dbd5b60

Please sign in to comment.