Annotation of src/usr.bin/tmux/window.c, Revision 1.35
1.35 ! nicm 1: /* $OpenBSD: window.c,v 1.34 2009/10/22 12:30:00 nicm Exp $ */
1.1 nicm 2:
3: /*
4: * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15: * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16: * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: #include <sys/types.h>
20: #include <sys/ioctl.h>
21:
22: #include <errno.h>
23: #include <fcntl.h>
1.5 nicm 24: #include <fnmatch.h>
1.1 nicm 25: #include <paths.h>
1.8 nicm 26: #include <pwd.h>
1.1 nicm 27: #include <signal.h>
28: #include <stdint.h>
29: #include <stdlib.h>
30: #include <string.h>
31: #include <termios.h>
32: #include <unistd.h>
33: #include <util.h>
34:
35: #include "tmux.h"
36:
37: /*
1.14 nicm 38: * Each window is attached to a number of panes, each of which is a pty. This
1.1 nicm 39: * file contains code to handle them.
40: *
41: * A pane has two buffers attached, these are filled and emptied by the main
42: * server poll loop. Output data is received from pty's in screen format,
43: * translated and returned as a series of escape sequences and strings via
44: * input_parse (in input.c). Input data is received as key codes and written
45: * directly via input_key.
46: *
47: * Each pane also has a "virtual" screen (screen.c) which contains the current
48: * state and is redisplayed when the window is reattached to a client.
49: *
50: * Windows are stored directly on a global array and wrapped in any number of
51: * winlink structs to be linked onto local session RB trees. A reference count
52: * is maintained and a window removed from the global list and destroyed when
53: * it reaches zero.
54: */
55:
56: /* Global window list. */
57: struct windows windows;
58:
59: RB_GENERATE(winlinks, winlink, entry, winlink_cmp);
60:
61: int
62: winlink_cmp(struct winlink *wl1, struct winlink *wl2)
63: {
64: return (wl1->idx - wl2->idx);
1.12 nicm 65: }
66:
67: struct winlink *
68: winlink_find_by_window(struct winlinks *wwl, struct window *w)
69: {
70: struct winlink *wl;
71:
72: RB_FOREACH(wl, winlinks, wwl) {
73: if (wl->window == w)
74: return (wl);
75: }
76:
77: return (NULL);
1.1 nicm 78: }
79:
80: struct winlink *
81: winlink_find_by_index(struct winlinks *wwl, int idx)
82: {
83: struct winlink wl;
84:
85: if (idx < 0)
86: fatalx("bad index");
87:
88: wl.idx = idx;
89: return (RB_FIND(winlinks, wwl, &wl));
90: }
91:
92: int
1.22 nicm 93: winlink_next_index(struct winlinks *wwl, int idx)
1.1 nicm 94: {
1.22 nicm 95: int i;
1.1 nicm 96:
1.22 nicm 97: i = idx;
98: do {
1.1 nicm 99: if (winlink_find_by_index(wwl, i) == NULL)
100: return (i);
1.22 nicm 101: if (i == INT_MAX)
102: i = 0;
103: else
104: i++;
105: } while (i != idx);
106: return (-1);
1.1 nicm 107: }
108:
109: u_int
110: winlink_count(struct winlinks *wwl)
111: {
112: struct winlink *wl;
113: u_int n;
114:
115: n = 0;
116: RB_FOREACH(wl, winlinks, wwl)
117: n++;
118:
119: return (n);
120: }
121:
122: struct winlink *
123: winlink_add(struct winlinks *wwl, struct window *w, int idx)
124: {
125: struct winlink *wl;
126:
1.22 nicm 127: if (idx < 0) {
128: if ((idx = winlink_next_index(wwl, -idx - 1)) == -1)
129: return (NULL);
130: } else if (winlink_find_by_index(wwl, idx) != NULL)
1.1 nicm 131: return (NULL);
132:
133: wl = xcalloc(1, sizeof *wl);
134: wl->idx = idx;
135: wl->window = w;
136: RB_INSERT(winlinks, wwl, wl);
137:
138: w->references++;
139:
140: return (wl);
141: }
142:
143: void
144: winlink_remove(struct winlinks *wwl, struct winlink *wl)
145: {
146: struct window *w = wl->window;
147:
148: RB_REMOVE(winlinks, wwl, wl);
149: xfree(wl);
150:
151: if (w->references == 0)
152: fatal("bad reference count");
153: w->references--;
154: if (w->references == 0)
155: window_destroy(w);
156: }
157:
158: struct winlink *
159: winlink_next(unused struct winlinks *wwl, struct winlink *wl)
160: {
161: return (RB_NEXT(winlinks, wwl, wl));
162: }
163:
164: struct winlink *
165: winlink_previous(unused struct winlinks *wwl, struct winlink *wl)
166: {
167: return (RB_PREV(winlinks, wwl, wl));
168: }
169:
170: void
171: winlink_stack_push(struct winlink_stack *stack, struct winlink *wl)
172: {
173: if (wl == NULL)
174: return;
175:
176: winlink_stack_remove(stack, wl);
1.28 nicm 177: TAILQ_INSERT_HEAD(stack, wl, sentry);
1.1 nicm 178: }
179:
180: void
181: winlink_stack_remove(struct winlink_stack *stack, struct winlink *wl)
182: {
183: struct winlink *wl2;
184:
185: if (wl == NULL)
186: return;
1.28 nicm 187:
188: TAILQ_FOREACH(wl2, stack, sentry) {
1.1 nicm 189: if (wl2 == wl) {
1.28 nicm 190: TAILQ_REMOVE(stack, wl, sentry);
1.1 nicm 191: return;
192: }
193: }
194: }
195:
196: int
197: window_index(struct window *s, u_int *i)
198: {
199: for (*i = 0; *i < ARRAY_LENGTH(&windows); (*i)++) {
200: if (s == ARRAY_ITEM(&windows, *i))
201: return (0);
202: }
203: return (-1);
204: }
205:
206: struct window *
207: window_create1(u_int sx, u_int sy)
208: {
209: struct window *w;
210: u_int i;
211:
212: w = xmalloc(sizeof *w);
213: w->name = NULL;
214: w->flags = 0;
215:
216: TAILQ_INIT(&w->panes);
217: w->active = NULL;
1.14 nicm 218:
1.17 nicm 219: w->lastlayout = -1;
1.14 nicm 220: w->layout_root = NULL;
221:
1.1 nicm 222: w->sx = sx;
223: w->sy = sy;
224:
1.7 nicm 225: options_init(&w->options, &global_w_options);
1.1 nicm 226:
227: for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
228: if (ARRAY_ITEM(&windows, i) == NULL) {
229: ARRAY_SET(&windows, i, w);
230: break;
231: }
232: }
233: if (i == ARRAY_LENGTH(&windows))
234: ARRAY_ADD(&windows, w);
235: w->references = 0;
236:
237: return (w);
238: }
239:
240: struct window *
1.23 nicm 241: window_create(const char *name, const char *cmd, const char *shell,
242: const char *cwd, struct environ *env, struct termios *tio,
243: u_int sx, u_int sy, u_int hlimit,char **cause)
1.1 nicm 244: {
1.14 nicm 245: struct window *w;
246: struct window_pane *wp;
1.1 nicm 247:
248: w = window_create1(sx, sy);
1.16 nicm 249: wp = window_add_pane(w, hlimit);
1.14 nicm 250: layout_init(w);
1.23 nicm 251: if (window_pane_spawn(wp, cmd, shell, cwd, env, tio, cause) != 0) {
1.1 nicm 252: window_destroy(w);
253: return (NULL);
254: }
255: w->active = TAILQ_FIRST(&w->panes);
256: if (name != NULL) {
257: w->name = xstrdup(name);
258: options_set_number(&w->options, "automatic-rename", 0);
259: } else
260: w->name = default_window_name(w);
261: return (w);
262: }
263:
264: void
265: window_destroy(struct window *w)
266: {
267: u_int i;
268:
269: if (window_index(w, &i) != 0)
270: fatalx("index not found");
271: ARRAY_SET(&windows, i, NULL);
272: while (!ARRAY_EMPTY(&windows) && ARRAY_LAST(&windows) == NULL)
273: ARRAY_TRUNC(&windows, 1);
274:
1.14 nicm 275: if (w->layout_root != NULL)
276: layout_free(w);
277:
1.1 nicm 278: options_free(&w->options);
279:
280: window_destroy_panes(w);
281:
282: if (w->name != NULL)
283: xfree(w->name);
284: xfree(w);
285: }
286:
1.15 nicm 287: void
1.1 nicm 288: window_resize(struct window *w, u_int sx, u_int sy)
289: {
290: w->sx = sx;
291: w->sy = sy;
292: }
293:
294: void
295: window_set_active_pane(struct window *w, struct window_pane *wp)
296: {
297: w->active = wp;
1.10 nicm 298: while (!window_pane_visible(w->active)) {
1.1 nicm 299: w->active = TAILQ_PREV(w->active, window_panes, entry);
1.10 nicm 300: if (w->active == NULL)
301: w->active = TAILQ_LAST(&w->panes, window_panes);
302: if (w->active == wp)
303: return;
1.29 nicm 304: }
305: }
306:
307: void
308: window_set_active_at(struct window *w, u_int x, u_int y)
309: {
310: struct window_pane *wp;
311:
312: TAILQ_FOREACH(wp, &w->panes, entry) {
313: if (!window_pane_visible(wp))
314: continue;
315: if (x < wp->xoff || x >= wp->xoff + wp->sx)
316: continue;
317: if (y < wp->yoff || y >= wp->yoff + wp->sy)
318: continue;
319: window_set_active_pane(w, wp);
320: break;
1.10 nicm 321: }
1.1 nicm 322: }
323:
324: struct window_pane *
1.16 nicm 325: window_add_pane(struct window *w, u_int hlimit)
1.1 nicm 326: {
327: struct window_pane *wp;
328:
1.14 nicm 329: wp = window_pane_create(w, w->sx, w->sy, hlimit);
1.1 nicm 330: if (TAILQ_EMPTY(&w->panes))
331: TAILQ_INSERT_HEAD(&w->panes, wp, entry);
332: else
333: TAILQ_INSERT_AFTER(&w->panes, w->active, wp, entry);
334: return (wp);
335: }
336:
337: void
338: window_remove_pane(struct window *w, struct window_pane *wp)
339: {
340: w->active = TAILQ_PREV(wp, window_panes, entry);
341: if (w->active == NULL)
342: w->active = TAILQ_NEXT(wp, entry);
343:
344: TAILQ_REMOVE(&w->panes, wp, entry);
345: window_pane_destroy(wp);
346: }
347:
348: struct window_pane *
349: window_pane_at_index(struct window *w, u_int idx)
350: {
351: struct window_pane *wp;
352: u_int n;
353:
354: n = 0;
355: TAILQ_FOREACH(wp, &w->panes, entry) {
356: if (n == idx)
357: return (wp);
358: n++;
359: }
360: return (NULL);
1.13 nicm 361: }
362:
363: u_int
364: window_pane_index(struct window *w, struct window_pane *wp)
365: {
366: struct window_pane *wq;
367: u_int n;
368:
369: n = 0;
370: TAILQ_FOREACH(wq, &w->panes, entry) {
371: if (wp == wq)
372: break;
373: n++;
374: }
375: return (n);
1.1 nicm 376: }
377:
378: u_int
379: window_count_panes(struct window *w)
380: {
381: struct window_pane *wp;
382: u_int n;
383:
384: n = 0;
385: TAILQ_FOREACH(wp, &w->panes, entry)
386: n++;
387: return (n);
388: }
389:
390: void
391: window_destroy_panes(struct window *w)
392: {
393: struct window_pane *wp;
394:
395: while (!TAILQ_EMPTY(&w->panes)) {
396: wp = TAILQ_FIRST(&w->panes);
397: TAILQ_REMOVE(&w->panes, wp, entry);
398: window_pane_destroy(wp);
399: }
400: }
401:
402: struct window_pane *
403: window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
404: {
405: struct window_pane *wp;
406:
407: wp = xcalloc(1, sizeof *wp);
408: wp->window = w;
409:
410: wp->cmd = NULL;
1.23 nicm 411: wp->shell = NULL;
1.1 nicm 412: wp->cwd = NULL;
413:
414: wp->fd = -1;
415: wp->in = buffer_create(BUFSIZ);
416: wp->out = buffer_create(BUFSIZ);
417:
418: wp->mode = NULL;
1.14 nicm 419:
420: wp->layout_cell = NULL;
1.1 nicm 421:
422: wp->xoff = 0;
423: wp->yoff = 0;
424:
425: wp->sx = sx;
426: wp->sy = sy;
427:
1.32 nicm 428: wp->pipe_fd = -1;
429: wp->pipe_buf = NULL;
430: wp->pipe_off = 0;
431:
1.9 nicm 432: wp->saved_grid = NULL;
433:
1.1 nicm 434: screen_init(&wp->base, sx, sy, hlimit);
435: wp->screen = &wp->base;
436:
437: input_init(wp);
438:
439: return (wp);
440: }
441:
442: void
443: window_pane_destroy(struct window_pane *wp)
444: {
445: if (wp->fd != -1)
446: close(wp->fd);
447:
448: input_free(wp);
449:
450: window_pane_reset_mode(wp);
451: screen_free(&wp->base);
1.9 nicm 452: if (wp->saved_grid != NULL)
453: grid_destroy(wp->saved_grid);
1.1 nicm 454:
1.32 nicm 455: if (wp->pipe_fd != -1) {
456: buffer_destroy(wp->pipe_buf);
457: close(wp->pipe_fd);
1.35 ! nicm 458: event_del(&wp->pipe_event);
1.32 nicm 459: }
460:
1.1 nicm 461: buffer_destroy(wp->in);
462: buffer_destroy(wp->out);
1.35 ! nicm 463: event_del(&wp->event);
1.1 nicm 464:
465: if (wp->cwd != NULL)
466: xfree(wp->cwd);
1.23 nicm 467: if (wp->shell != NULL)
468: xfree(wp->shell);
1.1 nicm 469: if (wp->cmd != NULL)
470: xfree(wp->cmd);
471: xfree(wp);
472: }
473:
474: int
1.23 nicm 475: window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
1.21 nicm 476: const char *cwd, struct environ *env, struct termios *tio, char **cause)
1.1 nicm 477: {
1.18 nicm 478: struct winsize ws;
479: int mode;
480: char *argv0, **varp, *var;
481: ARRAY_DECL(, char *) varlist;
482: struct environ_entry *envent;
483: const char *ptr;
484: struct timeval tv;
1.25 nicm 485: struct termios tio2;
1.18 nicm 486: u_int i;
1.1 nicm 487:
488: if (wp->fd != -1)
489: close(wp->fd);
490: if (cmd != NULL) {
491: if (wp->cmd != NULL)
492: xfree(wp->cmd);
493: wp->cmd = xstrdup(cmd);
494: }
1.23 nicm 495: if (shell != NULL) {
496: if (wp->shell != NULL)
497: xfree(wp->shell);
498: wp->shell = xstrdup(shell);
499: }
1.1 nicm 500: if (cwd != NULL) {
501: if (wp->cwd != NULL)
502: xfree(wp->cwd);
503: wp->cwd = xstrdup(cwd);
504: }
505:
506: memset(&ws, 0, sizeof ws);
507: ws.ws_col = screen_size_x(&wp->base);
508: ws.ws_row = screen_size_y(&wp->base);
509:
510: if (gettimeofday(&wp->window->name_timer, NULL) != 0)
1.26 nicm 511: fatal("gettimeofday failed");
1.1 nicm 512: tv.tv_sec = 0;
513: tv.tv_usec = NAME_INTERVAL * 1000L;
514: timeradd(&wp->window->name_timer, &tv, &wp->window->name_timer);
515:
1.25 nicm 516: switch (wp->pid = forkpty(&wp->fd, wp->tty, NULL, &ws)) {
1.1 nicm 517: case -1:
518: wp->fd = -1;
519: xasprintf(cause, "%s: %s", cmd, strerror(errno));
520: return (-1);
521: case 0:
522: if (chdir(wp->cwd) != 0)
523: chdir("/");
1.25 nicm 524:
525: if (tcgetattr(STDIN_FILENO, &tio2) != 0)
526: fatal("tcgetattr failed");
527: if (tio != NULL)
528: memcpy(tio2.c_cc, tio->c_cc, sizeof tio2.c_cc);
529: tio2.c_cc[VERASE] = '\177';
530: if (tcsetattr(STDIN_FILENO, TCSANOW, &tio2) != 0)
531: fatal("tcgetattr failed");
1.18 nicm 532:
533: ARRAY_INIT(&varlist);
534: for (varp = environ; *varp != NULL; varp++) {
535: var = xstrdup(*varp);
536: var[strcspn(var, "=")] = '\0';
537: ARRAY_ADD(&varlist, var);
538: }
539: for (i = 0; i < ARRAY_LENGTH(&varlist); i++) {
540: var = ARRAY_ITEM(&varlist, i);
541: unsetenv(var);
1.1 nicm 542: }
1.18 nicm 543: RB_FOREACH(envent, environ, env) {
544: if (envent->value != NULL)
545: setenv(envent->name, envent->value, 1);
546: }
547:
1.35 ! nicm 548: server_signal_clear();
1.1 nicm 549: log_close();
550:
1.8 nicm 551: if (*wp->cmd != '\0') {
1.24 nicm 552: /* Set SHELL but only if it is currently not useful. */
553: shell = getenv("SHELL");
554: if (shell == NULL || *shell == '\0' || areshell(shell))
555: setenv("SHELL", wp->shell, 1);
556:
1.8 nicm 557: execl(_PATH_BSHELL, "sh", "-c", wp->cmd, (char *) NULL);
558: fatal("execl failed");
559: }
560:
561: /* No command; fork a login shell. */
1.23 nicm 562: ptr = strrchr(wp->shell, '/');
563: if (ptr != NULL && *(ptr + 1) != '\0')
1.8 nicm 564: xasprintf(&argv0, "-%s", ptr + 1);
565: else
1.23 nicm 566: xasprintf(&argv0, "-%s", wp->shell);
1.24 nicm 567: setenv("SHELL", wp->shell, 1);
1.23 nicm 568: execl(wp->shell, argv0, (char *) NULL);
1.1 nicm 569: fatal("execl failed");
570: }
571:
572: if ((mode = fcntl(wp->fd, F_GETFL)) == -1)
573: fatal("fcntl failed");
574: if (fcntl(wp->fd, F_SETFL, mode|O_NONBLOCK) == -1)
575: fatal("fcntl failed");
576: if (fcntl(wp->fd, F_SETFD, FD_CLOEXEC) == -1)
577: fatal("fcntl failed");
578:
579: return (0);
580: }
581:
1.15 nicm 582: void
1.1 nicm 583: window_pane_resize(struct window_pane *wp, u_int sx, u_int sy)
584: {
585: struct winsize ws;
586:
587: if (sx == wp->sx && sy == wp->sy)
1.15 nicm 588: return;
1.1 nicm 589: wp->sx = sx;
590: wp->sy = sy;
591:
592: memset(&ws, 0, sizeof ws);
593: ws.ws_col = sx;
594: ws.ws_row = sy;
595:
596: screen_resize(&wp->base, sx, sy);
597: if (wp->mode != NULL)
598: wp->mode->resize(wp, sx, sy);
599:
600: if (wp->fd != -1 && ioctl(wp->fd, TIOCSWINSZ, &ws) == -1)
601: fatal("ioctl failed");
602: }
603:
604: int
605: window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode)
606: {
607: struct screen *s;
608:
1.15 nicm 609: if (wp->mode != NULL)
1.1 nicm 610: return (1);
611: wp->mode = mode;
612:
613: if ((s = wp->mode->init(wp)) != NULL)
614: wp->screen = s;
1.34 nicm 615: wp->flags |= PANE_REDRAW;
1.1 nicm 616: return (0);
617: }
618:
619: void
620: window_pane_reset_mode(struct window_pane *wp)
621: {
622: if (wp->mode == NULL)
623: return;
624:
625: wp->mode->free(wp);
626: wp->mode = NULL;
627:
628: wp->screen = &wp->base;
1.34 nicm 629: wp->flags |= PANE_REDRAW;
1.1 nicm 630: }
631:
632: void
633: window_pane_parse(struct window_pane *wp)
634: {
1.32 nicm 635: size_t new_size;
1.33 nicm 636:
637: if (wp->mode != NULL)
638: return;
1.32 nicm 639:
640: new_size = BUFFER_USED(wp->in) - wp->pipe_off;
641: if (wp->pipe_fd != -1 && new_size > 0)
642: buffer_write(wp->pipe_buf, BUFFER_OUT(wp->in), new_size);
643:
1.1 nicm 644: input_parse(wp);
1.32 nicm 645:
646: wp->pipe_off = BUFFER_USED(wp->in);
1.1 nicm 647: }
648:
649: void
650: window_pane_key(struct window_pane *wp, struct client *c, int key)
651: {
1.27 nicm 652: struct window_pane *wp2;
653:
1.30 nicm 654: if (!window_pane_visible(wp))
1.3 nicm 655: return;
656:
1.1 nicm 657: if (wp->mode != NULL) {
658: if (wp->mode->key != NULL)
659: wp->mode->key(wp, c, key);
1.27 nicm 660: return;
1.30 nicm 661: }
1.27 nicm 662:
1.30 nicm 663: if (wp->fd == -1)
664: return;
1.27 nicm 665: input_key(wp, key);
666: if (options_get_number(&wp->window->options, "synchronize-panes")) {
667: TAILQ_FOREACH(wp2, &wp->window->panes, entry) {
668: if (wp2 == wp || wp2->mode != NULL)
669: continue;
670: if (wp2->fd != -1 && window_pane_visible(wp2))
671: input_key(wp2, key);
672: }
673: }
1.1 nicm 674: }
675:
676: void
677: window_pane_mouse(
1.31 nicm 678: struct window_pane *wp, struct client *c, struct mouse_event *m)
1.1 nicm 679: {
1.30 nicm 680: if (!window_pane_visible(wp))
1.3 nicm 681: return;
682:
1.31 nicm 683: if (m->x < wp->xoff || m->x >= wp->xoff + wp->sx)
1.1 nicm 684: return;
1.31 nicm 685: if (m->y < wp->yoff || m->y >= wp->yoff + wp->sy)
1.1 nicm 686: return;
1.31 nicm 687: m->x -= wp->xoff;
688: m->y -= wp->yoff;
1.1 nicm 689:
690: if (wp->mode != NULL) {
691: if (wp->mode->mouse != NULL)
1.31 nicm 692: wp->mode->mouse(wp, c, m);
1.30 nicm 693: } else if (wp->fd != -1)
1.31 nicm 694: input_mouse(wp, m);
1.10 nicm 695: }
696:
697: int
698: window_pane_visible(struct window_pane *wp)
699: {
700: struct window *w = wp->window;
701:
702: if (wp->xoff >= w->sx || wp->yoff >= w->sy)
703: return (0);
704: if (wp->xoff + wp->sx > w->sx || wp->yoff + wp->sy > w->sy)
705: return (0);
706: return (1);
1.1 nicm 707: }
708:
709: char *
1.5 nicm 710: window_pane_search(struct window_pane *wp, const char *searchstr, u_int *lineno)
1.1 nicm 711: {
1.4 nicm 712: struct screen *s = &wp->base;
1.5 nicm 713: char *newsearchstr, *line, *msg;
1.4 nicm 714: u_int i;
715:
1.5 nicm 716: msg = NULL;
717: xasprintf(&newsearchstr, "*%s*", searchstr);
718:
1.4 nicm 719: for (i = 0; i < screen_size_y(s); i++) {
720: line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
1.5 nicm 721: if (fnmatch(newsearchstr, line, 0) == 0) {
722: msg = line;
723: if (lineno != NULL)
724: *lineno = i;
725: break;
726: }
1.4 nicm 727: xfree(line);
728: }
1.5 nicm 729:
730: xfree(newsearchstr);
731: return (msg);
1.1 nicm 732: }