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++] = 0x80 + (v & 0x3f);
} }
buf[i] = 0; buf[i] = 0;
termpty_write(sd->pty, buf, strlen(buf)); termpty_write(sd->pty, buf, i);
ret = EINA_TRUE; ret = EINA_TRUE;
} }
break; break;
case MOUSE_EXT_SGR: // ESC.[.<.NUM.;.NUM.;.NUM.M case MOUSE_EXT_SGR: // ESC.[.<.NUM.;.NUM.;.NUM.M
{ {
int meta = evas_key_modifier_is_set(ev->modifiers, "Alt") ? 8 : 0; int meta = evas_key_modifier_is_set(ev->modifiers, "Alt") ? 8 : 0;
int len;
if (btn > 2) btn = 0; if (btn > 2) btn = 0;
snprintf(buf, sizeof(buf), "%c[<%i;%i;%iM", 0x1b, len = snprintf(buf, sizeof(buf), "%c[<%i;%i;%iM", 0x1b,
(btn | meta), cx + 1, cy + 1); (btn | meta), cx + 1, cy + 1);
termpty_write(sd->pty, buf, strlen(buf)); termpty_write(sd->pty, buf, len);
ret = EINA_TRUE; ret = EINA_TRUE;
} }
break; break;
case MOUSE_EXT_URXVT: // ESC.[.NUM.;.NUM.;.NUM.M case MOUSE_EXT_URXVT: // ESC.[.NUM.;.NUM.;.NUM.M
{ {
int meta = evas_key_modifier_is_set(ev->modifiers, "Alt") ? 8 : 0; int meta = evas_key_modifier_is_set(ev->modifiers, "Alt") ? 8 : 0;
int len;
if (btn > 2) btn = 0; if (btn > 2) btn = 0;
snprintf(buf, sizeof(buf), "%c[%i;%i;%iM", 0x1b, len = snprintf(buf, sizeof(buf), "%c[%i;%i;%iM", 0x1b,
(btn | meta) + ' ', (btn | meta) + ' ',
cx + 1, cy + 1); cx + 1, cy + 1);
termpty_write(sd->pty, buf, strlen(buf)); termpty_write(sd->pty, buf, len);
ret = EINA_TRUE; ret = EINA_TRUE;
} }
break; break;
@ -5547,10 +5549,11 @@ _smart_pty_command(void *data)
if (ty->cur_cmd[1] == 's') if (ty->cur_cmd[1] == 's')
{ {
char buf[256]; char buf[256];
int len;
snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n", len = snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n",
sd->grid.w, sd->grid.h, sd->font.chw, sd->font.chh); sd->grid.w, sd->grid.h, sd->font.chw, sd->font.chh);
termpty_write(ty, buf, strlen(buf)); termpty_write(ty, buf, len);
return; return;
} }
else if (ty->cur_cmd[1] == 'j') else if (ty->cur_cmd[1] == 'j')
@ -5790,10 +5793,11 @@ _smart_pty_command(void *data)
if (ty->cur_cmd[1] == 's') if (ty->cur_cmd[1] == 's')
{ {
char buf[256]; char buf[256];
int len;
snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n", len = snprintf(buf, sizeof(buf), "%i;%i;%i;%i\n",
sd->grid.w, sd->grid.h, sd->font.chw, sd->font.chh); sd->grid.w, sd->grid.h, sd->font.chw, sd->font.chh);
termpty_write(ty, buf, strlen(buf)); termpty_write(ty, buf, len);
return; return;
} }
else if (ty->cur_cmd[1] == 'j') 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; char *p, *p2, *p3, *tb;
tb = malloc(strlen(ev->data) + 1); tb = malloc(ev->len + 1);
if (tb) if (tb)
{ {
for (p = ev->data; p;) 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) // commands are stored in the buffer, 0 bytes not allowed (end marker)
cmd = eina_unicode_unicode_to_utf8(buf, NULL); cmd = eina_unicode_unicode_to_utf8(buf, NULL);
ty->cur_cmd = cmd; 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); 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) main(int argc, char **argv)
{ {
int i, perm = 0; int i, perm = 0;
int bytes;
ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1(); ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1();
@ -34,10 +35,11 @@ main(int argc, char **argv)
if (i >= argc) break; if (i >= argc) break;
} }
if (perm) if (perm)
snprintf(tbuf, sizeof(tbuf), "%c}ap%s", 0x1b, argv[i]); bytes = snprintf(tbuf, sizeof(tbuf), "%c}ap%s", 0x1b, argv[i]);
else else
snprintf(tbuf, sizeof(tbuf), "%c}at%s", 0x1b, argv[i]); bytes = snprintf(tbuf, sizeof(tbuf), "%c}at%s", 0x1b, argv[i]);
if (write(0, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write"); bytes++;
if (write(STDIN_FILENO, tbuf, bytes) != bytes) perror("write");
} }
return 0; return 0;
} }

View File

@ -29,7 +29,7 @@ main(int argc, char **argv)
{ {
char tbuf[32]; char tbuf[32];
snprintf(tbuf, sizeof(tbuf), "%c}bt", 0x1b); 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; return 0;
} }
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
@ -48,7 +48,7 @@ main(int argc, char **argv)
snprintf(tbuf, sizeof(tbuf), "%c}bp%s", 0x1b, path); snprintf(tbuf, sizeof(tbuf), "%c}bp%s", 0x1b, path);
else else
snprintf(tbuf, sizeof(tbuf), "%c}bt%s", 0x1b, path); 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; return 0;
} }

View File

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

View File

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

View File

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

View File

@ -29,7 +29,7 @@ main(int argc, char **argv)
path = argv[i]; path = argv[i];
if (realpath(path, buf)) path = buf; if (realpath(path, buf)) path = buf;
snprintf(tbuf, sizeof(tbuf), "%c}pq%s", 0x1b, path); 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; return 0;
} }