Compare commits

...

7 Commits

Author SHA1 Message Date
Jean Guyomarc'h 4e647ad274 termio: don't use strlen() when it can be avoided 2016-09-09 19:58:36 +02:00
Jean Guyomarc'h f403a29fdb termptyesc: fix logic of ty escapes handling 2016-09-09 19:58:36 +02:00
Jean Guyomarc'h e13f5f19e4 tyls: don't call strlen() 2016-09-09 19:58:36 +02:00
Jean Guyomarc'h a6d698a550 tyalpha: don't call strlen() 2016-09-09 19:58:36 +02:00
Jean Guyomarc'h f4e03704b1 ty*: use STDIN_FILENO 2016-09-09 19:58:36 +02:00
Jean Guyomarc'h 832db27dca tycat: avoid calls to strlen() when possible 2016-09-09 19:58:36 +02:00
Jean Guyomarc'h e97de30ec6 typop: don't use strlen() and use STDIN_FILENO 2016-09-09 19:58:36 +02:00
8 changed files with 44 additions and 35 deletions

View File

@ -3637,30 +3637,32 @@ _rep_mouse_down(Termio *sd, Evas_Event_Mouse_Down *ev, int cx, int cy)
buf[i++] = 0x80 + (v & 0x3f);
}
buf[i] = 0;
termpty_write(sd->pty, buf, strlen(buf));
termpty_write(sd->pty, buf, i);
ret = EINA_TRUE;
}
break;
case MOUSE_EXT_SGR: // ESC.[.<.NUM.;.NUM.;.NUM.M
{
int meta = evas_key_modifier_is_set(ev->modifiers, "Alt") ? 8 : 0;
int len;
if (btn > 2) btn = 0;
snprintf(buf, sizeof(buf), "%c[<%i;%i;%iM", 0x1b,
(btn | meta), cx + 1, cy + 1);
termpty_write(sd->pty, buf, strlen(buf));
len = snprintf(buf, sizeof(buf), "%c[<%i;%i;%iM", 0x1b,
(btn | meta), cx + 1, cy + 1);
termpty_write(sd->pty, buf, len);
ret = EINA_TRUE;
}
break;
case MOUSE_EXT_URXVT: // ESC.[.NUM.;.NUM.;.NUM.M
{
int meta = evas_key_modifier_is_set(ev->modifiers, "Alt") ? 8 : 0;
int len;
if (btn > 2) btn = 0;
snprintf(buf, sizeof(buf), "%c[%i;%i;%iM", 0x1b,
(btn | meta) + ' ',
cx + 1, cy + 1);
termpty_write(sd->pty, buf, strlen(buf));
len = snprintf(buf, sizeof(buf), "%c[%i;%i;%iM", 0x1b,
(btn | meta) + ' ',
cx + 1, cy + 1);
termpty_write(sd->pty, buf, len);
ret = EINA_TRUE;
}
break;
@ -5547,10 +5549,11 @@ _smart_pty_command(void *data)
if (ty->cur_cmd[1] == 's')
{
char buf[256];
int len;
snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n",
sd->grid.w, sd->grid.h, sd->font.chw, sd->font.chh);
termpty_write(ty, buf, strlen(buf));
len = snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n",
sd->grid.w, sd->grid.h, sd->font.chw, sd->font.chh);
termpty_write(ty, buf, len);
return;
}
else if (ty->cur_cmd[1] == 'j')
@ -5790,10 +5793,11 @@ _smart_pty_command(void *data)
if (ty->cur_cmd[1] == 's')
{
char buf[256];
int len;
snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n",
sd->grid.w, sd->grid.h, sd->font.chw, sd->font.chh);
termpty_write(ty, buf, strlen(buf));
len = snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n",
sd->grid.w, sd->grid.h, sd->font.chw, sd->font.chh);
termpty_write(ty, buf, len);
return;
}
else if (ty->cur_cmd[1] == 'j')
@ -5867,7 +5871,7 @@ _smart_cb_drop(void *data, Evas_Object *o EINA_UNUSED, Elm_Selection_Data *ev)
{
char *p, *p2, *p3, *tb;
tb = malloc(strlen(ev->data) + 1);
tb = malloc(ev->len + 1);
if (tb)
{
for (p = ev->data; p;)

View File

@ -1506,7 +1506,7 @@ _handle_esc_terminology(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *
// commands are stored in the buffer, 0 bytes not allowed (end marker)
cmd = eina_unicode_unicode_to_utf8(buf, NULL);
ty->cur_cmd = cmd;
if ((!config->ty_escapes) || (!_termpty_ext_handle(ty, cmd, buf)))
if ((config->ty_escapes) && (!_termpty_ext_handle(ty, cmd, buf)))
{
if (ty->cb.command.func) ty->cb.command.func(ty->cb.command.data);
}

View File

@ -11,6 +11,7 @@ int
main(int argc, char **argv)
{
int i, perm = 0;
int bytes;
ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
@ -34,10 +35,11 @@ main(int argc, char **argv)
if (i >= argc) break;
}
if (perm)
snprintf(tbuf, sizeof(tbuf), "%c}ap%s", 0x1b, argv[i]);
bytes = snprintf(tbuf, sizeof(tbuf), "%c}ap%s", 0x1b, argv[i]);
else
snprintf(tbuf, sizeof(tbuf), "%c}at%s", 0x1b, argv[i]);
if (write(0, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write");
bytes = snprintf(tbuf, sizeof(tbuf), "%c}at%s", 0x1b, argv[i]);
bytes++;
if (write(STDIN_FILENO, tbuf, bytes) != bytes) perror("write");
}
return 0;
}

View File

@ -29,7 +29,7 @@ main(int argc, char **argv)
{
char tbuf[32];
snprintf(tbuf, sizeof(tbuf), "%c}bt", 0x1b);
if (write(0, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write");
if (write(STDIN_FILENO, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write");
return 0;
}
for (i = 1; i < argc; i++)
@ -48,7 +48,7 @@ main(int argc, char **argv)
snprintf(tbuf, sizeof(tbuf), "%c}bp%s", 0x1b, path);
else
snprintf(tbuf, sizeof(tbuf), "%c}bt%s", 0x1b, path);
if (write(0, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write");
if (write(STDIN_FILENO, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write");
}
return 0;
}

View File

@ -86,17 +86,18 @@ prnt(const char *path, int w, int h, int mode)
{
int x, y, i;
char *line, buf[4096];
int bytes;
if ((w >= 512) || (h >= 512)) return;
line = malloc(w + 100);
if (!line) return;
if (mode == CENTER)
snprintf(buf, sizeof(buf), "%c}ic#%i;%i;%s", 0x1b, w, h, path);
bytes = snprintf(buf, sizeof(buf), "%c}ic#%i;%i;%s", 0x1b, w, h, path);
else if (mode == FILL)
snprintf(buf, sizeof(buf), "%c}if#%i;%i;%s", 0x1b, w, h, path);
bytes = snprintf(buf, sizeof(buf), "%c}if#%i;%i;%s", 0x1b, w, h, path);
else
snprintf(buf, sizeof(buf), "%c}is#%i;%i;%s", 0x1b, w, h, path);
if (write(0, buf, strlen(buf) + 1) < 0) perror("write");
bytes = snprintf(buf, sizeof(buf), "%c}is#%i;%i;%s", 0x1b, w, h, path);
if (write(STDIN_FILENO, buf, bytes + 1) < 0) perror("write");
i = 0;
line[i++] = 0x1b;
line[i++] = '}';
@ -112,7 +113,7 @@ prnt(const char *path, int w, int h, int mode)
line[i++] = '\n';
for (y = 0; y < h; y++)
{
if (write(0, line, i) < 0) perror("write");
if (write(STDIN_FILENO, line, i) < 0) perror("write");
}
free(line);
}
@ -309,6 +310,7 @@ main(int argc, char **argv)
int i;
char *rp;
Eina_List *file_q = NULL;
int bytes;
ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
@ -333,8 +335,8 @@ main(int argc, char **argv)
if (!ee) goto shutdown;
evas = ecore_evas_get(ee);
echo_off();
snprintf(buf, sizeof(buf), "%c}qs", 0x1b);
if (write(0, buf, strlen(buf) + 1) < 0) perror("write");
bytes = snprintf(buf, sizeof(buf), "%c}qs", 0x1b);
if (write(STDIN_FILENO, buf, bytes + 1) < 0) perror("write");
if (scanf("%i;%i;%i;%i", &tw, &th, &cw, &ch) != 4 ||
((tw <= 0) || (th <= 0) || (cw <= 1) || (ch <= 1)))
{

View File

@ -759,9 +759,9 @@ main(int argc, char **argv)
evas = ecore_evas_get(ee);
echo_off();
snprintf(buf, sizeof(buf), "%c}qs", 0x1b);
len = strlen(buf);
if (write(0, buf, len + 1) < (signed)len + 1) perror("write");
len = snprintf(buf, sizeof(buf), "%c}qs", 0x1b);
len++;
if (write(STDIN_FILENO, buf, len) < len) perror("write");
if ((scanf("%i;%i;%i;%i", &tw, &th, &cw, &ch) != 4)
|| (tw <= 0) || (th <= 0) || (cw <= 1) || (ch <= 1))
{

View File

@ -10,7 +10,7 @@
int
main(int argc, char **argv)
{
int i;
int i, bytes;
ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
@ -28,8 +28,9 @@ main(int argc, char **argv)
path = argv[i];
if (realpath(path, buf)) path = buf;
snprintf(tbuf, sizeof(tbuf), "%c}pn%s", 0x1b, path);
if (write(0, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write");
bytes = snprintf(tbuf, sizeof(tbuf), "%c}pn%s", 0x1b, path);
bytes++;
if (write(STDIN_FILENO, tbuf, bytes) != bytes) perror("write");
}
return 0;
}

View File

@ -29,7 +29,7 @@ main(int argc, char **argv)
path = argv[i];
if (realpath(path, buf)) path = buf;
snprintf(tbuf, sizeof(tbuf), "%c}pq%s", 0x1b, path);
if (write(0, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write");
if (write(STDIN_FILENO, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write");
}
return 0;
}