Rename Widget* events into Input* events.
[midnight-commander.git] / src / user.c
blobd5f3702329ceb6ae8645ce7b6de4d1fc52b0cac0
1 /* User Menu implementation
2 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /** \file user.c
20 * \brief Source: user menu implementation
23 #include <config.h>
25 #include <ctype.h>
26 #include <errno.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
31 #include "global.h"
32 #include "../src/tty/tty.h"
33 #include "../src/skin/skin.h"
34 #include "dir.h"
35 #include "panel.h"
36 #include "main.h"
37 #include "user.h"
38 #include "layout.h"
39 #include "execute.h"
40 #include "setup.h"
41 #include "history.h"
42 #include "strutil.h"
43 #include "../src/search/search.h"
45 #include "../edit/edit.h" /* WEdit, BLOCK_FILE */
47 /* For the simple listbox manager */
48 #include "dialog.h"
49 #include "widget.h"
50 #include "wtools.h"
51 #include "../src/viewer/mcviewer.h" /* for default_* externs */
53 #define MAX_ENTRIES 16
54 #define MAX_ENTRY_LEN 60
56 static int debug_flag = 0;
57 static int debug_error = 0;
58 static char *menu = NULL;
60 /* Formats defined:
61 %% The % character
62 %f The current file (if non-local vfs, file will be copied locally and
63 %f will be full path to it).
64 %p The current file
65 %d The current working directory
66 %s "Selected files"; the tagged files if any, otherwise the current file
67 %t Tagged files
68 %u Tagged files (and they are untagged on return from expand_format)
69 %view Runs the commands and pipes standard output to the view command.
70 If %view is immediately followed by '{', recognize keywords
71 ascii, hex, nroff and unform
73 If the format letter is in uppercase, it refers to the other panel.
75 With a number followed the % character you can turn quoting on (default)
76 and off. For example:
77 %f quote expanded macro
78 %1f ditto
79 %0f don't quote expanded macro
81 expand_format returns a memory block that must be free()d.
84 /* Returns how many characters we should advance if %view was found */
85 int check_format_view (const char *p)
87 const char *q = p;
88 if (!strncmp (p, "view", 4)) {
89 q += 4;
90 if (*q == '{'){
91 for (q++;*q && *q != '}';q++) {
92 if (!strncmp (q, "ascii", 5)) {
93 mcview_default_hex_mode = 0;
94 q += 4;
95 } else if (!strncmp (q, "hex", 3)) {
96 mcview_default_hex_mode = 1;
97 q += 2;
98 } else if (!strncmp (q, "nroff", 5)) {
99 mcview_default_nroff_flag = 1;
100 q += 4;
101 } else if (!strncmp (q, "unform", 6)) {
102 mcview_default_nroff_flag = 0;
103 q += 5;
106 if (*q == '}')
107 q++;
109 return q - p;
111 return 0;
114 int check_format_cd (const char *p)
116 return (strncmp (p, "cd", 2)) ? 0 : 3;
119 /* Check if p has a "^var\{var-name\}" */
120 /* Returns the number of skipped characters (zero on not found) */
121 /* V will be set to the expanded variable name */
122 int check_format_var (const char *p, char **v)
124 const char *q = p;
125 char *var_name;
126 const char *value;
127 const char *dots = 0;
129 *v = 0;
130 if (!strncmp (p, "var{", 4)){
131 for (q += 4; *q && *q != '}'; q++){
132 if (*q == ':')
133 dots = q+1;
135 if (!*q)
136 return 0;
138 if (!dots || dots == q+5){
139 message (D_ERROR,
140 _(" Format error on file Extensions File "),
141 !dots ? _(" The %%var macro has no default ")
142 : _(" The %%var macro has no variable "));
143 return 0;
146 /* Copy the variable name */
147 var_name = g_strndup (p + 4, dots-2 - (p+3));
149 value = getenv (var_name);
150 g_free (var_name);
151 if (value){
152 *v = g_strdup (value);
153 return q-p;
155 var_name = g_strndup (dots, q - dots);
156 *v = var_name;
157 return q-p;
159 return 0;
162 /* strip file's extension */
163 static char *
164 strip_ext(char *ss)
166 register char *s = ss;
167 char *e = NULL;
168 while(*s) {
169 if(*s == '.') e = s;
170 if(*s == PATH_SEP && e) e=NULL; /* '.' in *directory* name */
171 s++;
173 if(e) *e = 0;
174 return ss;
177 char *
178 expand_format (WEdit *edit_widget, char c, int quote)
180 WPanel *panel = NULL;
181 char *(*quote_func) (const char *, int);
182 char *fname = NULL;
183 char *result;
184 char c_lc;
186 if (c == '%')
187 return g_strdup ("%");
189 if (edit_one_file == NULL) {
190 if (g_ascii_islower ((gchar) c))
191 panel = current_panel;
192 else {
193 if (get_other_type () != view_listing)
194 return g_strdup ("");
195 panel = other_panel;
197 fname = panel->dir.list[panel->selected].fname;
199 #ifdef USE_INTERNAL_EDIT
200 else
201 fname = str_unconst (edit_get_file_name (edit_widget));
202 #endif
204 if (quote)
205 quote_func = name_quote;
206 else
207 quote_func = fake_name_quote;
209 c_lc = g_ascii_tolower ((gchar) c);
211 switch (c_lc) {
212 case 'f':
213 case 'p':
214 return (*quote_func) (fname, 0);
215 case 'x':
216 return (*quote_func) (extension (fname), 0);
217 case 'd':
219 char *cwd;
220 char *qstr;
222 cwd = g_malloc(MC_MAXPATHLEN + 1);
224 if (panel)
225 g_strlcpy(cwd, panel->cwd, MC_MAXPATHLEN + 1);
226 else
227 mc_get_current_wd(cwd, MC_MAXPATHLEN + 1);
229 qstr = (*quote_func) (cwd, 0);
231 g_free (cwd);
233 return qstr;
235 case 'i': /* indent equal number cursor position in line */
236 #ifdef USE_INTERNAL_EDIT
237 if (edit_widget)
238 return g_strnfill (edit_get_curs_col (edit_widget), ' ');
239 #endif
240 break;
241 case 'y': /* syntax type */
242 #ifdef USE_INTERNAL_EDIT
243 if (edit_widget) {
244 const char *syntax_type = edit_get_syntax_type (edit_widget);
245 if (syntax_type != NULL)
246 return g_strdup (syntax_type);
248 #endif
249 break;
250 case 'k': /* block file name */
251 case 'b': /* block file name / strip extension */ {
252 #ifdef USE_INTERNAL_EDIT
253 if (edit_widget) {
254 char *file = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE);
255 fname = (*quote_func) (file, 0);
256 g_free (file);
257 return fname;
259 #endif
260 if (c_lc == 'b')
261 return strip_ext ((*quote_func) (fname, 0));
262 break;
264 case 'n': /* strip extension in editor */
265 #ifdef USE_INTERNAL_EDIT
266 if (edit_widget)
267 return strip_ext ((*quote_func) (fname, 0));
268 #endif
269 break;
270 case 'm': /* menu file name */
271 if (menu)
272 return (*quote_func) (menu, 0);
273 break;
274 case 's':
275 if (!panel || !panel->marked)
276 return (*quote_func) (fname, 0);
278 /* Fall through */
280 case 't':
281 case 'u':
283 int length = 2, i;
284 char *block, *tmp;
286 if (!panel)
287 return g_strdup ("");
289 for (i = 0; i < panel->count; i++)
290 if (panel->dir.list[i].f.marked)
291 length += strlen (panel->dir.list[i].fname) + 1; /* for space */
293 block = g_malloc (length * 2 + 1);
294 *block = 0;
295 for (i = 0; i < panel->count; i++)
296 if (panel->dir.list[i].f.marked) {
297 strcat (block, tmp =
298 (*quote_func) (panel->dir.list[i].fname, 0));
299 g_free (tmp);
300 strcat (block, " ");
301 if (c_lc == 'u')
302 do_file_mark (panel, i, 0);
304 return block;
305 } /* sub case block */
306 } /* switch */
307 result = g_strdup ("% ");
308 result[1] = c;
309 return result;
313 * Check for the "shell_patterns" directive. If it's found and valid,
314 * interpret it and move the pointer past the directive. Return the
315 * current pointer.
317 static char *
318 check_patterns (char *p)
320 static const char def_name[] = "shell_patterns=";
321 char *p0 = p;
323 if (strncmp (p, def_name, sizeof (def_name) - 1) != 0)
324 return p0;
326 p += sizeof (def_name) - 1;
327 if (*p == '1')
328 easy_patterns = 1;
329 else if (*p == '0')
330 easy_patterns = 0;
331 else
332 return p0;
334 /* Skip spaces */
335 p++;
336 while (*p == '\n' || *p == '\t' || *p == ' ')
337 p++;
338 return p;
341 /* Copies a whitespace separated argument from p to arg. Returns the
342 point after argument. */
343 static char *extract_arg (char *p, char *arg, int size)
345 char *np;
347 while (*p && (*p == ' ' || *p == '\t' || *p == '\n'))
348 p++;
349 /* support quote space .mnu */
350 while (*p && (*p != ' ' || *(p-1) == '\\') && *p != '\t' && *p != '\n') {
351 np = str_get_next_char (p);
352 if (np - p >= size) break;
353 memcpy (arg, p, np - p);
354 arg+= np - p;
355 size-= np - p;
356 p = np;
358 *arg = 0;
359 if (!*p || *p == '\n')
360 str_prev_char (&p);
361 return p;
364 /* Tests whether the selected file in the panel is of any of the types
365 specified in argument. */
366 static int test_type (WPanel *panel, char *arg)
368 int result = 0; /* False by default */
369 int st_mode = panel->dir.list [panel->selected].st.st_mode;
371 for (;*arg != 0; arg++){
372 switch (*arg){
373 case 'n': /* Not a directory */
374 result |= !S_ISDIR (st_mode);
375 break;
376 case 'r': /* Regular file */
377 result |= S_ISREG (st_mode);
378 break;
379 case 'd': /* Directory */
380 result |= S_ISDIR (st_mode);
381 break;
382 case 'l': /* Link */
383 result |= S_ISLNK (st_mode);
384 break;
385 case 'c': /* Character special */
386 result |= S_ISCHR (st_mode);
387 break;
388 case 'b': /* Block special */
389 result |= S_ISBLK (st_mode);
390 break;
391 case 'f': /* Fifo (named pipe) */
392 result |= S_ISFIFO (st_mode);
393 break;
394 case 's': /* Socket */
395 result |= S_ISSOCK (st_mode);
396 break;
397 case 'x': /* Executable */
398 result |= (st_mode & 0111) ? 1 : 0;
399 break;
400 case 't':
401 result |= panel->marked ? 1 : 0;
402 break;
403 default:
404 debug_error = 1;
405 break;
408 return result;
411 /* Calculates the truth value of the next condition starting from
412 p. Returns the point after condition. */
413 static char *
414 test_condition (WEdit *edit_widget, char *p, int *condition)
416 WPanel *panel;
417 char arg [256];
418 mc_search_type_t search_type;
420 if (easy_patterns) {
421 search_type = MC_SEARCH_T_GLOB;
422 } else {
423 search_type = MC_SEARCH_T_REGEX;
426 /* Handle one condition */
427 for (;*p != '\n' && *p != '&' && *p != '|'; p++){
428 /* support quote space .mnu */
429 if ((*p == ' ' && *(p-1) != '\\') || *p == '\t')
430 continue;
431 if (*p >= 'a')
432 panel = current_panel;
433 else {
434 if (get_other_type () == view_listing)
435 panel = other_panel;
436 else
437 panel = NULL;
439 *p |= 0x20;
441 switch (*p++){
442 case '!':
443 p = test_condition (edit_widget, p, condition);
444 *condition = ! *condition;
445 str_prev_char (&p);
446 break;
447 case 'f': /* file name pattern */
448 p = extract_arg (p, arg, sizeof (arg));
449 *condition = panel && mc_search (arg, panel->dir.list [panel->selected].fname, search_type);
450 break;
451 case 'y': /* syntax pattern */
452 #ifdef USE_INTERNAL_EDIT
453 if (edit_widget) {
454 const char *syntax_type = edit_get_syntax_type (edit_widget);
455 if (syntax_type != NULL) {
456 p = extract_arg (p, arg, sizeof (arg));
457 *condition = panel && mc_search (arg, syntax_type, MC_SEARCH_T_NORMAL);
460 #endif
461 break;
462 case 'd':
463 p = extract_arg (p, arg, sizeof (arg));
464 *condition = panel && mc_search (arg, panel->cwd, search_type);
465 break;
466 case 't':
467 p = extract_arg (p, arg, sizeof (arg));
468 *condition = panel && test_type (panel, arg);
469 break;
470 case 'x': /* executable */
472 struct stat status;
474 p = extract_arg (p, arg, sizeof (arg));
475 if (stat (arg, &status) == 0)
476 *condition = is_exe (status.st_mode);
477 else
478 *condition = 0;
479 break;
481 default:
482 debug_error = 1;
483 break;
484 } /* switch */
486 } /* while */
487 return p;
490 /* General purpose condition debug output handler */
491 static void
492 debug_out (char *start, char *end, int cond)
494 static char *msg;
495 int len;
497 if (start == NULL && end == NULL){
498 /* Show output */
499 if (debug_flag && msg) {
500 len = strlen (msg);
501 if (len)
502 msg [len - 1] = 0;
503 message (D_NORMAL, _(" Debug "), "%s", msg);
506 debug_flag = 0;
507 g_free (msg);
508 msg = NULL;
509 } else {
510 const char *type;
511 char *p;
513 /* Save debug info for later output */
514 if (!debug_flag)
515 return;
516 /* Save the result of the condition */
517 if (debug_error){
518 type = _(" ERROR: ");
519 debug_error = 0;
521 else if (cond)
522 type = _(" True: ");
523 else
524 type = _(" False: ");
525 /* This is for debugging, don't need to be super efficient. */
526 if (end == NULL)
527 p = g_strdup_printf ("%s%s%c \n", msg ? msg : "", type, *start);
528 else
529 p = g_strdup_printf ("%s%s%.*s \n", msg ? msg : "", type,
530 (int) (end - start), start);
531 g_free (msg);
532 msg = p;
536 /* Calculates the truth value of one lineful of conditions. Returns
537 the point just before the end of line. */
538 static char *
539 test_line (WEdit *edit_widget, char *p, int *result)
541 int condition;
542 char operator;
543 char *debug_start, *debug_end;
545 /* Repeat till end of line */
546 while (*p && *p != '\n') {
547 /* support quote space .mnu */
548 while ((*p == ' ' && *(p-1) != '\\' ) || *p == '\t')
549 p++;
550 if (!*p || *p == '\n')
551 break;
552 operator = *p++;
553 if (*p == '?'){
554 debug_flag = 1;
555 p++;
557 /* support quote space .mnu */
558 while ((*p == ' ' && *(p-1) != '\\' ) || *p == '\t')
559 p++;
560 if (!*p || *p == '\n')
561 break;
562 condition = 1; /* True by default */
564 debug_start = p;
565 p = test_condition (edit_widget, p, &condition);
566 debug_end = p;
567 /* Add one debug statement */
568 debug_out (debug_start, debug_end, condition);
570 switch (operator){
571 case '+':
572 case '=':
573 /* Assignment */
574 *result = condition;
575 break;
576 case '&': /* Logical and */
577 *result &= condition;
578 break;
579 case '|': /* Logical or */
580 *result |= condition;
581 break;
582 default:
583 debug_error = 1;
584 break;
585 } /* switch */
586 /* Add one debug statement */
587 debug_out (&operator, NULL, *result);
589 } /* while (*p != '\n') */
590 /* Report debug message */
591 debug_out (NULL, NULL, 1);
593 if (!*p || *p == '\n')
594 str_prev_char (&p);
595 return p;
598 /* FIXME: recode this routine on version 3.0, it could be cleaner */
599 static void
600 execute_menu_command (WEdit *edit_widget, const char *commands)
602 FILE *cmd_file;
603 int cmd_file_fd;
604 int expand_prefix_found = 0;
605 char *parameter = 0;
606 int do_quote = 0;
607 char prompt [80];
608 int col;
609 char *file_name;
610 int run_view = 0;
612 /* Skip menu entry title line */
613 commands = strchr (commands, '\n');
614 if (!commands){
615 return;
618 cmd_file_fd = mc_mkstemps (&file_name, "mcusr", SCRIPT_SUFFIX);
620 if (cmd_file_fd == -1){
621 message (D_ERROR, MSG_ERROR, _(" Cannot create temporary command file \n %s "),
622 unix_error_string (errno));
623 return;
625 cmd_file = fdopen (cmd_file_fd, "w");
626 fputs ("#! /bin/sh\n", cmd_file);
627 commands++;
629 for (col = 0; *commands; commands++){
630 if (col == 0) {
631 if (*commands != ' ' && *commands != '\t')
632 break;
633 while (*commands == ' ' || *commands == '\t')
634 commands++;
635 if (*commands == 0)
636 break;
638 col++;
639 if (*commands == '\n')
640 col = 0;
641 if (parameter){
642 if (*commands == '}'){
643 char *tmp;
644 *parameter = 0;
645 parameter = input_dialog (_(" Parameter "), prompt, MC_HISTORY_FM_MENU_EXEC_PARAM, "");
646 if (!parameter || !*parameter){
647 /* User canceled */
648 fclose (cmd_file);
649 unlink (file_name);
650 g_free (file_name);
651 return;
653 if (do_quote) {
654 fputs (tmp = name_quote (parameter, 0), cmd_file);
655 g_free (tmp);
656 } else
657 fputs (parameter, cmd_file);
658 g_free (parameter);
659 parameter = 0;
660 } else {
661 if (parameter < &prompt [sizeof (prompt) - 1]) {
662 *parameter++ = *commands;
665 } else if (expand_prefix_found){
666 expand_prefix_found = 0;
667 if (g_ascii_isdigit ((gchar) *commands)) {
668 do_quote = atoi (commands);
669 while (g_ascii_isdigit ((gchar) *commands))
670 commands++;
672 if (*commands == '{')
673 parameter = prompt;
674 else{
675 char *text = expand_format (edit_widget, *commands, do_quote);
676 fputs (text, cmd_file);
677 g_free (text);
679 } else {
680 if (*commands == '%') {
681 int i = check_format_view (commands + 1);
682 if (i) {
683 commands += i;
684 run_view = 1;
685 } else {
686 do_quote = 1; /* Default: Quote expanded macro */
687 expand_prefix_found = 1;
689 } else
690 fputc (*commands, cmd_file);
693 fclose (cmd_file);
694 chmod (file_name, S_IRWXU);
695 if (run_view) {
696 run_view = 0;
697 mcview_viewer (file_name, NULL, &run_view, 0);
698 } else {
699 /* execute the command indirectly to allow execution even
700 * on no-exec filesystems. */
701 char *cmd = g_strconcat("/bin/sh ", file_name, (char *)NULL);
702 shell_execute (cmd, EXECUTE_HIDE);
703 g_free(cmd);
705 unlink (file_name);
706 g_free (file_name);
710 ** Check owner of the menu file. Using menu file is allowed, if
711 ** owner of the menu is root or the actual user. In either case
712 ** file should not be group and word-writable.
714 ** Q. Should we apply this routine to system and home menu (and .ext files)?
716 static int
717 menu_file_own(char* path)
719 struct stat st;
721 if (stat (path, &st) == 0
722 && (!st.st_uid || (st.st_uid == geteuid ()))
723 && ((st.st_mode & (S_IWGRP | S_IWOTH)) == 0)
725 return 1;
727 if (verbose)
729 message (D_NORMAL, _(" Warning -- ignoring file "),
730 _("File %s is not owned by root or you or is world writable.\n"
731 "Using it may compromise your security"),
732 path
735 return 0;
739 * If edit_widget is NULL then we are called from the mc menu,
740 * otherwise we are called from the mcedit menu.
742 void
743 user_menu_cmd (WEdit *edit_widget)
745 char *p;
746 char *data, **entries;
747 int max_cols, menu_lines, menu_limit;
748 int col, i, accept_entry = 1;
749 int selected, old_patterns;
750 Listbox *listbox;
752 if (!vfs_current_is_local ()){
753 message (D_ERROR, MSG_ERROR,
754 _(" Cannot execute commands on non-local filesystems"));
755 return;
758 menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU);
759 if (!exist_file (menu) || !menu_file_own (menu)){
760 g_free (menu);
761 menu = concat_dir_and_file
762 (home_dir, edit_widget ? EDIT_HOME_MENU : MC_HOME_MENU);
763 if (!exist_file (menu)){
764 g_free (menu);
765 menu = concat_dir_and_file
766 (mc_home, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
767 if (!exist_file (menu)) {
768 g_free (menu);
769 menu = concat_dir_and_file
770 (mc_home_alt, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
775 if ((data = load_file (menu)) == NULL){
776 message (D_ERROR, MSG_ERROR, _(" Cannot open file %s \n %s "),
777 menu, unix_error_string (errno));
778 g_free (menu);
779 menu = NULL;
780 return;
783 max_cols = 0;
784 selected = 0;
785 menu_limit = 0;
786 entries = 0;
788 /* Parse the menu file */
789 old_patterns = easy_patterns;
790 p = check_patterns (data);
791 for (menu_lines = col = 0; *p; str_next_char (&p)){
792 if (menu_lines >= menu_limit){
793 char ** new_entries;
795 menu_limit += MAX_ENTRIES;
796 new_entries = g_realloc (entries, sizeof (new_entries[0]) * menu_limit);
798 if (new_entries == 0)
799 break;
801 entries = new_entries;
802 new_entries += menu_limit;
803 while (--new_entries >= &entries[menu_lines])
804 *new_entries = 0;
806 if (col == 0 && !entries [menu_lines]){
807 if (*p == '#'){
808 /* A commented menu entry */
809 accept_entry = 1;
810 } else if (*p == '+'){
811 if (*(p+1) == '='){
812 /* Combined adding and default */
813 p = test_line (edit_widget, p + 1, &accept_entry);
814 if (selected == 0 && accept_entry)
815 selected = menu_lines;
816 } else {
817 /* A condition for adding the entry */
818 p = test_line (edit_widget, p, &accept_entry);
820 } else if (*p == '='){
821 if (*(p+1) == '+'){
822 /* Combined adding and default */
823 p = test_line (edit_widget, p + 1, &accept_entry);
824 if (selected == 0 && accept_entry)
825 selected = menu_lines;
826 } else {
827 /* A condition for making the entry default */
828 i = 1;
829 p = test_line (edit_widget, p, &i);
830 if (selected == 0 && i)
831 selected = menu_lines;
834 else if (*p != ' ' && *p != '\t' && str_isprint (p)) {
835 /* A menu entry title line */
836 if (accept_entry)
837 entries [menu_lines] = p;
838 else
839 accept_entry = 1;
842 if (*p == '\n'){
843 if (entries [menu_lines]){
844 menu_lines++;
845 accept_entry = 1;
847 max_cols = max (max_cols, col);
848 col = 0;
849 } else {
850 if (*p == '\t')
851 *p = ' ';
852 col++;
856 if (menu_lines == 0)
857 message (D_ERROR, MSG_ERROR, _(" No suitable entries found in %s "), menu);
858 else {
859 max_cols = min (max (max_cols, col), MAX_ENTRY_LEN);
861 /* Create listbox */
862 listbox = create_listbox_window (max_cols+2, menu_lines, _(" User menu "),
863 "[Menu File Edit]");
864 /* insert all the items found */
865 for (i = 0; i < menu_lines; i++) {
866 p = entries [i];
867 LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0],
868 extract_line (p, p + MAX_ENTRY_LEN), p);
870 /* Select the default entry */
871 listbox_select_by_number (listbox->list, selected);
873 selected = run_listbox (listbox);
874 if (selected >= 0)
875 execute_menu_command (edit_widget, entries [selected]);
877 do_refresh ();
880 easy_patterns = old_patterns;
881 g_free (menu);
882 menu = NULL;
883 g_free (entries);
884 g_free (data);