Annotation of src/usr.bin/tmux/cmd.c, Revision 1.142
1.142 ! nicm 1: /* $OpenBSD: cmd.c,v 1.141 2018/10/18 08:38:01 nicm Exp $ */
1.1 nicm 2:
3: /*
1.120 nicm 4: * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1 nicm 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/time.h>
21:
1.5 nicm 22: #include <fnmatch.h>
23: #include <paths.h>
1.61 nicm 24: #include <pwd.h>
1.1 nicm 25: #include <stdlib.h>
26: #include <string.h>
27: #include <unistd.h>
28:
29: #include "tmux.h"
1.105 nicm 30:
31: extern const struct cmd_entry cmd_attach_session_entry;
32: extern const struct cmd_entry cmd_bind_key_entry;
33: extern const struct cmd_entry cmd_break_pane_entry;
34: extern const struct cmd_entry cmd_capture_pane_entry;
35: extern const struct cmd_entry cmd_choose_buffer_entry;
36: extern const struct cmd_entry cmd_choose_client_entry;
37: extern const struct cmd_entry cmd_choose_tree_entry;
38: extern const struct cmd_entry cmd_clear_history_entry;
39: extern const struct cmd_entry cmd_clock_mode_entry;
40: extern const struct cmd_entry cmd_command_prompt_entry;
41: extern const struct cmd_entry cmd_confirm_before_entry;
42: extern const struct cmd_entry cmd_copy_mode_entry;
43: extern const struct cmd_entry cmd_delete_buffer_entry;
44: extern const struct cmd_entry cmd_detach_client_entry;
45: extern const struct cmd_entry cmd_display_message_entry;
46: extern const struct cmd_entry cmd_display_panes_entry;
47: extern const struct cmd_entry cmd_down_pane_entry;
48: extern const struct cmd_entry cmd_find_window_entry;
49: extern const struct cmd_entry cmd_has_session_entry;
50: extern const struct cmd_entry cmd_if_shell_entry;
51: extern const struct cmd_entry cmd_join_pane_entry;
52: extern const struct cmd_entry cmd_kill_pane_entry;
53: extern const struct cmd_entry cmd_kill_server_entry;
54: extern const struct cmd_entry cmd_kill_session_entry;
55: extern const struct cmd_entry cmd_kill_window_entry;
56: extern const struct cmd_entry cmd_last_pane_entry;
57: extern const struct cmd_entry cmd_last_window_entry;
58: extern const struct cmd_entry cmd_link_window_entry;
59: extern const struct cmd_entry cmd_list_buffers_entry;
60: extern const struct cmd_entry cmd_list_clients_entry;
61: extern const struct cmd_entry cmd_list_commands_entry;
62: extern const struct cmd_entry cmd_list_keys_entry;
63: extern const struct cmd_entry cmd_list_panes_entry;
64: extern const struct cmd_entry cmd_list_sessions_entry;
65: extern const struct cmd_entry cmd_list_windows_entry;
66: extern const struct cmd_entry cmd_load_buffer_entry;
67: extern const struct cmd_entry cmd_lock_client_entry;
68: extern const struct cmd_entry cmd_lock_server_entry;
69: extern const struct cmd_entry cmd_lock_session_entry;
70: extern const struct cmd_entry cmd_move_pane_entry;
71: extern const struct cmd_entry cmd_move_window_entry;
72: extern const struct cmd_entry cmd_new_session_entry;
73: extern const struct cmd_entry cmd_new_window_entry;
74: extern const struct cmd_entry cmd_next_layout_entry;
75: extern const struct cmd_entry cmd_next_window_entry;
76: extern const struct cmd_entry cmd_paste_buffer_entry;
77: extern const struct cmd_entry cmd_pipe_pane_entry;
78: extern const struct cmd_entry cmd_previous_layout_entry;
79: extern const struct cmd_entry cmd_previous_window_entry;
80: extern const struct cmd_entry cmd_refresh_client_entry;
81: extern const struct cmd_entry cmd_rename_session_entry;
82: extern const struct cmd_entry cmd_rename_window_entry;
83: extern const struct cmd_entry cmd_resize_pane_entry;
1.141 nicm 84: extern const struct cmd_entry cmd_resize_window_entry;
1.105 nicm 85: extern const struct cmd_entry cmd_respawn_pane_entry;
86: extern const struct cmd_entry cmd_respawn_window_entry;
87: extern const struct cmd_entry cmd_rotate_window_entry;
88: extern const struct cmd_entry cmd_run_shell_entry;
89: extern const struct cmd_entry cmd_save_buffer_entry;
90: extern const struct cmd_entry cmd_select_layout_entry;
91: extern const struct cmd_entry cmd_select_pane_entry;
92: extern const struct cmd_entry cmd_select_window_entry;
93: extern const struct cmd_entry cmd_send_keys_entry;
94: extern const struct cmd_entry cmd_send_prefix_entry;
95: extern const struct cmd_entry cmd_set_buffer_entry;
96: extern const struct cmd_entry cmd_set_environment_entry;
1.107 nicm 97: extern const struct cmd_entry cmd_set_hook_entry;
1.105 nicm 98: extern const struct cmd_entry cmd_set_option_entry;
99: extern const struct cmd_entry cmd_set_window_option_entry;
100: extern const struct cmd_entry cmd_show_buffer_entry;
101: extern const struct cmd_entry cmd_show_environment_entry;
1.107 nicm 102: extern const struct cmd_entry cmd_show_hooks_entry;
1.105 nicm 103: extern const struct cmd_entry cmd_show_messages_entry;
104: extern const struct cmd_entry cmd_show_options_entry;
105: extern const struct cmd_entry cmd_show_window_options_entry;
106: extern const struct cmd_entry cmd_source_file_entry;
107: extern const struct cmd_entry cmd_split_window_entry;
108: extern const struct cmd_entry cmd_start_server_entry;
109: extern const struct cmd_entry cmd_suspend_client_entry;
110: extern const struct cmd_entry cmd_swap_pane_entry;
111: extern const struct cmd_entry cmd_swap_window_entry;
112: extern const struct cmd_entry cmd_switch_client_entry;
113: extern const struct cmd_entry cmd_unbind_key_entry;
114: extern const struct cmd_entry cmd_unlink_window_entry;
115: extern const struct cmd_entry cmd_up_pane_entry;
116: extern const struct cmd_entry cmd_wait_for_entry;
1.1 nicm 117:
118: const struct cmd_entry *cmd_table[] = {
119: &cmd_attach_session_entry,
120: &cmd_bind_key_entry,
121: &cmd_break_pane_entry,
1.34 nicm 122: &cmd_capture_pane_entry,
1.42 nicm 123: &cmd_choose_buffer_entry,
1.15 nicm 124: &cmd_choose_client_entry,
1.67 nicm 125: &cmd_choose_tree_entry,
1.1 nicm 126: &cmd_clear_history_entry,
127: &cmd_clock_mode_entry,
128: &cmd_command_prompt_entry,
129: &cmd_confirm_before_entry,
130: &cmd_copy_mode_entry,
131: &cmd_delete_buffer_entry,
132: &cmd_detach_client_entry,
1.7 nicm 133: &cmd_display_message_entry,
1.16 nicm 134: &cmd_display_panes_entry,
1.1 nicm 135: &cmd_find_window_entry,
136: &cmd_has_session_entry,
1.4 nicm 137: &cmd_if_shell_entry,
1.37 nicm 138: &cmd_join_pane_entry,
1.1 nicm 139: &cmd_kill_pane_entry,
140: &cmd_kill_server_entry,
141: &cmd_kill_session_entry,
142: &cmd_kill_window_entry,
1.45 nicm 143: &cmd_last_pane_entry,
1.1 nicm 144: &cmd_last_window_entry,
145: &cmd_link_window_entry,
146: &cmd_list_buffers_entry,
147: &cmd_list_clients_entry,
148: &cmd_list_commands_entry,
149: &cmd_list_keys_entry,
1.23 nicm 150: &cmd_list_panes_entry,
1.1 nicm 151: &cmd_list_sessions_entry,
152: &cmd_list_windows_entry,
153: &cmd_load_buffer_entry,
1.19 nicm 154: &cmd_lock_client_entry,
1.1 nicm 155: &cmd_lock_server_entry,
1.19 nicm 156: &cmd_lock_session_entry,
1.63 nicm 157: &cmd_move_pane_entry,
1.1 nicm 158: &cmd_move_window_entry,
159: &cmd_new_session_entry,
160: &cmd_new_window_entry,
161: &cmd_next_layout_entry,
162: &cmd_next_window_entry,
163: &cmd_paste_buffer_entry,
1.24 nicm 164: &cmd_pipe_pane_entry,
1.1 nicm 165: &cmd_previous_layout_entry,
166: &cmd_previous_window_entry,
167: &cmd_refresh_client_entry,
168: &cmd_rename_session_entry,
169: &cmd_rename_window_entry,
170: &cmd_resize_pane_entry,
1.141 nicm 171: &cmd_resize_window_entry,
1.56 nicm 172: &cmd_respawn_pane_entry,
1.1 nicm 173: &cmd_respawn_window_entry,
174: &cmd_rotate_window_entry,
1.17 nicm 175: &cmd_run_shell_entry,
1.1 nicm 176: &cmd_save_buffer_entry,
177: &cmd_select_layout_entry,
178: &cmd_select_pane_entry,
179: &cmd_select_window_entry,
180: &cmd_send_keys_entry,
181: &cmd_send_prefix_entry,
182: &cmd_set_buffer_entry,
1.13 nicm 183: &cmd_set_environment_entry,
1.107 nicm 184: &cmd_set_hook_entry,
1.1 nicm 185: &cmd_set_option_entry,
186: &cmd_set_window_option_entry,
187: &cmd_show_buffer_entry,
1.13 nicm 188: &cmd_show_environment_entry,
1.107 nicm 189: &cmd_show_hooks_entry,
1.32 nicm 190: &cmd_show_messages_entry,
1.1 nicm 191: &cmd_show_options_entry,
192: &cmd_show_window_options_entry,
193: &cmd_source_file_entry,
194: &cmd_split_window_entry,
195: &cmd_start_server_entry,
196: &cmd_suspend_client_entry,
197: &cmd_swap_pane_entry,
198: &cmd_swap_window_entry,
199: &cmd_switch_client_entry,
200: &cmd_unbind_key_entry,
201: &cmd_unlink_window_entry,
1.82 nicm 202: &cmd_wait_for_entry,
1.1 nicm 203: NULL
204: };
205:
1.140 nicm 206: void
207: cmd_log_argv(int argc, char **argv, const char *prefix)
208: {
209: int i;
210:
211: for (i = 0; i < argc; i++)
212: log_debug("%s: argv[%d]=%s", prefix, i, argv[i]);
213: }
214:
1.10 nicm 215: int
216: cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
217: {
218: size_t arglen;
219: int i;
1.91 nicm 220:
221: if (argc == 0)
222: return (0);
1.140 nicm 223: cmd_log_argv(argc, argv, __func__);
1.10 nicm 224:
225: *buf = '\0';
226: for (i = 0; i < argc; i++) {
227: if (strlcpy(buf, argv[i], len) >= len)
228: return (-1);
229: arglen = strlen(argv[i]) + 1;
230: buf += arglen;
231: len -= arglen;
232: }
233:
234: return (0);
235: }
236:
237: int
238: cmd_unpack_argv(char *buf, size_t len, int argc, char ***argv)
239: {
240: int i;
241: size_t arglen;
242:
243: if (argc == 0)
244: return (0);
245: *argv = xcalloc(argc, sizeof **argv);
246:
247: buf[len - 1] = '\0';
248: for (i = 0; i < argc; i++) {
249: if (len == 0) {
250: cmd_free_argv(argc, *argv);
251: return (-1);
252: }
253:
254: arglen = strlen(buf) + 1;
255: (*argv)[i] = xstrdup(buf);
1.140 nicm 256:
1.10 nicm 257: buf += arglen;
258: len -= arglen;
259: }
1.140 nicm 260: cmd_log_argv(argc, *argv, __func__);
1.10 nicm 261:
262: return (0);
1.46 nicm 263: }
264:
265: char **
1.93 nicm 266: cmd_copy_argv(int argc, char **argv)
1.46 nicm 267: {
268: char **new_argv;
269: int i;
270:
271: if (argc == 0)
272: return (NULL);
1.94 nicm 273: new_argv = xcalloc(argc + 1, sizeof *new_argv);
1.46 nicm 274: for (i = 0; i < argc; i++) {
275: if (argv[i] != NULL)
276: new_argv[i] = xstrdup(argv[i]);
277: }
278: return (new_argv);
1.10 nicm 279: }
280:
281: void
282: cmd_free_argv(int argc, char **argv)
283: {
284: int i;
285:
286: if (argc == 0)
1.35 nicm 287: return;
1.68 nicm 288: for (i = 0; i < argc; i++)
289: free(argv[i]);
290: free(argv);
1.94 nicm 291: }
292:
293: char *
294: cmd_stringify_argv(int argc, char **argv)
295: {
296: char *buf;
297: int i;
298: size_t len;
299:
300: if (argc == 0)
301: return (xstrdup(""));
302:
303: len = 0;
304: buf = NULL;
305:
306: for (i = 0; i < argc; i++) {
307: len += strlen(argv[i]) + 1;
1.98 nicm 308: buf = xrealloc(buf, len);
1.94 nicm 309:
310: if (i == 0)
311: *buf = '\0';
312: else
313: strlcat(buf, " ", len);
314: strlcat(buf, argv[i], len);
315: }
316: return (buf);
1.10 nicm 317: }
318:
1.135 nicm 319: static int
320: cmd_try_alias(int *argc, char ***argv)
321: {
1.142 ! nicm 322: struct options_entry *o;
! 323: struct options_array_item *a;
! 324: int old_argc = *argc, new_argc, i;
! 325: char **old_argv = *argv, **new_argv;
! 326: size_t wanted;
! 327: const char *s, *cp = NULL;
1.135 nicm 328:
329: o = options_get_only(global_options, "command-alias");
1.142 ! nicm 330: if (o == NULL)
1.135 nicm 331: return (-1);
1.142 ! nicm 332: wanted = strlen(old_argv[0]);
1.135 nicm 333:
1.142 ! nicm 334: a = options_array_first(o);
! 335: while (a != NULL) {
! 336: s = options_array_item_value(a);
! 337: if (s != NULL) {
! 338: cp = strchr(s, '=');
! 339: if (cp != NULL &&
! 340: (size_t)(cp - s) == wanted &&
! 341: strncmp(old_argv[0], s, wanted) == 0)
! 342: break;
! 343: }
! 344: a = options_array_next(a);
1.135 nicm 345: }
1.142 ! nicm 346: if (a == NULL)
1.135 nicm 347: return (-1);
348:
349: if (cmd_string_split(cp + 1, &new_argc, &new_argv) != 0)
350: return (-1);
351:
352: *argc = new_argc + old_argc - 1;
353: *argv = xcalloc((*argc) + 1, sizeof **argv);
354:
355: for (i = 0; i < new_argc; i++)
356: (*argv)[i] = xstrdup(new_argv[i]);
357: for (i = 1; i < old_argc; i++)
358: (*argv)[new_argc + i - 1] = xstrdup(old_argv[i]);
359:
360: log_debug("alias: %s=%s", old_argv[0], cp + 1);
361: for (i = 0; i < *argc; i++)
362: log_debug("alias: argv[%d] = %s", i, (*argv)[i]);
363:
364: cmd_free_argv(new_argc, new_argv);
365: return (0);
366: }
367:
1.1 nicm 368: struct cmd *
1.80 nicm 369: cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
1.1 nicm 370: {
1.135 nicm 371: const char *name;
1.1 nicm 372: const struct cmd_entry **entryp, *entry;
1.27 deraadt 373: struct cmd *cmd;
1.49 nicm 374: struct args *args;
1.1 nicm 375: char s[BUFSIZ];
1.135 nicm 376: int ambiguous, allocated = 0;
1.1 nicm 377:
378: *cause = NULL;
1.2 nicm 379: if (argc == 0) {
380: xasprintf(cause, "no command");
1.1 nicm 381: return (NULL);
1.2 nicm 382: }
1.135 nicm 383: name = argv[0];
1.1 nicm 384:
1.135 nicm 385: retry:
386: ambiguous = 0;
1.1 nicm 387: entry = NULL;
388: for (entryp = cmd_table; *entryp != NULL; entryp++) {
389: if ((*entryp)->alias != NULL &&
390: strcmp((*entryp)->alias, argv[0]) == 0) {
1.3 nicm 391: ambiguous = 0;
1.1 nicm 392: entry = *entryp;
393: break;
394: }
395:
396: if (strncmp((*entryp)->name, argv[0], strlen(argv[0])) != 0)
397: continue;
398: if (entry != NULL)
1.3 nicm 399: ambiguous = 1;
1.1 nicm 400: entry = *entryp;
401:
402: /* Bail now if an exact match. */
403: if (strcmp(entry->name, argv[0]) == 0)
404: break;
405: }
1.135 nicm 406: if ((ambiguous || entry == NULL) &&
407: server_proc != NULL &&
408: !allocated &&
409: cmd_try_alias(&argc, &argv) == 0) {
410: allocated = 1;
411: goto retry;
412: }
1.3 nicm 413: if (ambiguous)
414: goto ambiguous;
1.1 nicm 415: if (entry == NULL) {
1.135 nicm 416: xasprintf(cause, "unknown command: %s", name);
1.1 nicm 417: return (NULL);
418: }
1.140 nicm 419: cmd_log_argv(argc, argv, entry->name);
1.1 nicm 420:
1.117 nicm 421: args = args_parse(entry->args.template, argc, argv);
1.49 nicm 422: if (args == NULL)
423: goto usage;
1.117 nicm 424: if (entry->args.lower != -1 && args->argc < entry->args.lower)
1.49 nicm 425: goto usage;
1.117 nicm 426: if (entry->args.upper != -1 && args->argc > entry->args.upper)
1.49 nicm 427: goto usage;
1.1 nicm 428:
1.80 nicm 429: cmd = xcalloc(1, sizeof *cmd);
1.1 nicm 430: cmd->entry = entry;
1.49 nicm 431: cmd->args = args;
1.80 nicm 432:
433: if (file != NULL)
434: cmd->file = xstrdup(file);
435: cmd->line = line;
436:
1.135 nicm 437: if (allocated)
438: cmd_free_argv(argc, argv);
1.1 nicm 439: return (cmd);
440:
441: ambiguous:
442: *s = '\0';
443: for (entryp = cmd_table; *entryp != NULL; entryp++) {
444: if (strncmp((*entryp)->name, argv[0], strlen(argv[0])) != 0)
445: continue;
446: if (strlcat(s, (*entryp)->name, sizeof s) >= sizeof s)
447: break;
448: if (strlcat(s, ", ", sizeof s) >= sizeof s)
449: break;
450: }
451: s[strlen(s) - 2] = '\0';
1.135 nicm 452: xasprintf(cause, "ambiguous command: %s, could be: %s", name, s);
1.1 nicm 453: return (NULL);
454:
455: usage:
1.49 nicm 456: if (args != NULL)
457: args_free(args);
1.1 nicm 458: xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
459: return (NULL);
460: }
461:
1.106 nicm 462: char *
463: cmd_print(struct cmd *cmd)
1.1 nicm 464: {
1.106 nicm 465: char *out, *s;
466:
467: s = args_print(cmd->args);
468: if (*s != '\0')
469: xasprintf(&out, "%s %s", cmd->entry->name, s);
470: else
471: out = xstrdup(cmd->entry->name);
472: free(s);
1.49 nicm 473:
1.106 nicm 474: return (out);
1.1 nicm 475: }
476:
1.99 nicm 477: /* Adjust current mouse position for a pane. */
478: int
479: cmd_mouse_at(struct window_pane *wp, struct mouse_event *m, u_int *xp,
480: u_int *yp, int last)
481: {
482: u_int x, y;
483:
484: if (last) {
485: x = m->lx;
486: y = m->ly;
487: } else {
488: x = m->x;
489: y = m->y;
490: }
491:
492: if (m->statusat == 0 && y > 0)
493: y--;
494: else if (m->statusat > 0 && y >= (u_int)m->statusat)
495: y = m->statusat - 1;
496:
497: if (x < wp->xoff || x >= wp->xoff + wp->sx)
498: return (-1);
499: if (y < wp->yoff || y >= wp->yoff + wp->sy)
500: return (-1);
501:
1.123 nicm 502: if (xp != NULL)
503: *xp = x - wp->xoff;
504: if (yp != NULL)
505: *yp = y - wp->yoff;
1.99 nicm 506: return (0);
507: }
508:
509: /* Get current mouse window if any. */
510: struct winlink *
511: cmd_mouse_window(struct mouse_event *m, struct session **sp)
512: {
513: struct session *s;
514: struct window *w;
515:
516: if (!m->valid || m->s == -1 || m->w == -1)
517: return (NULL);
518: if ((s = session_find_by_id(m->s)) == NULL)
519: return (NULL);
520: if ((w = window_find_by_id(m->w)) == NULL)
521: return (NULL);
522:
523: if (sp != NULL)
524: *sp = s;
525: return (winlink_find_by_window(&s->windows, w));
526: }
527:
528: /* Get current mouse pane if any. */
529: struct window_pane *
1.104 nicm 530: cmd_mouse_pane(struct mouse_event *m, struct session **sp,
531: struct winlink **wlp)
1.99 nicm 532: {
533: struct winlink *wl;
534: struct window_pane *wp;
535:
536: if ((wl = cmd_mouse_window(m, sp)) == NULL)
537: return (NULL);
538: if ((wp = window_pane_find_by_id(m->wp)) == NULL)
539: return (NULL);
540: if (!window_has_pane(wl->window, wp))
541: return (NULL);
542:
543: if (wlp != NULL)
544: *wlp = wl;
1.43 nicm 545: return (wp);
1.15 nicm 546: }
547:
548: /* Replace the first %% or %idx in template by s. */
549: char *
1.75 nicm 550: cmd_template_replace(const char *template, const char *s, int idx)
1.15 nicm 551: {
1.75 nicm 552: char ch, *buf;
1.131 nicm 553: const char *ptr, *cp, quote[] = "\"\\$";
1.127 nicm 554: int replaced, quoted;
1.84 nicm 555: size_t len;
1.15 nicm 556:
1.76 nicm 557: if (strchr(template, '%') == NULL)
1.15 nicm 558: return (xstrdup(template));
559:
560: buf = xmalloc(1);
561: *buf = '\0';
562: len = 0;
563: replaced = 0;
564:
565: ptr = template;
566: while (*ptr != '\0') {
567: switch (ch = *ptr++) {
568: case '%':
569: if (*ptr < '1' || *ptr > '9' || *ptr - '0' != idx) {
570: if (*ptr != '%' || replaced)
571: break;
572: replaced = 1;
573: }
574: ptr++;
575:
1.127 nicm 576: quoted = (*ptr == '%');
577: if (quoted)
578: ptr++;
579:
1.132 nicm 580: buf = xrealloc(buf, len + (strlen(s) * 3) + 1);
1.127 nicm 581: for (cp = s; *cp != '\0'; cp++) {
1.131 nicm 582: if (quoted && strchr(quote, *cp) != NULL)
1.127 nicm 583: buf[len++] = '\\';
1.132 nicm 584: if (quoted && *cp == ';') {
585: buf[len++] = '\\';
586: buf[len++] = '\\';
587: }
1.127 nicm 588: buf[len++] = *cp;
589: }
590: buf[len] = '\0';
1.15 nicm 591: continue;
592: }
1.98 nicm 593: buf = xrealloc(buf, len + 2);
1.15 nicm 594: buf[len++] = ch;
595: buf[len] = '\0';
596: }
597:
598: return (buf);
1.1 nicm 599: }