(edit_set_filename): expand tilde while setting file name.
[pantumic.git] / src / user.c
blob6374f218e97db7fa3027819390a2405a65f57250
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 "lib/global.h"
32 #include "lib/tty/tty.h"
33 #include "lib/skin.h"
34 #include "lib/search.h"
35 #include "lib/vfs/mc-vfs/vfs.h"
36 #include "lib/strutil.h"
38 #include "src/editor/edit.h" /* WEdit, BLOCK_FILE */
39 #include "src/viewer/mcviewer.h" /* for default_* externs */
41 #include "dir.h"
42 #include "panel.h"
43 #include "main.h"
44 #include "user.h"
45 #include "layout.h"
46 #include "execute.h"
47 #include "setup.h"
48 #include "history.h"
50 #include "dialog.h"
51 #include "dialog-switch.h"
52 #include "widget.h"
53 #include "wtools.h"
55 #define MAX_ENTRIES 16
56 #define MAX_ENTRY_LEN 60
58 static int debug_flag = 0;
59 static int debug_error = 0;
60 static char *menu = NULL;
62 /* Formats defined:
63 %% The % character
64 %f The current file (if non-local vfs, file will be copied locally and
65 %f will be full path to it).
66 %p The current file
67 %d The current working directory
68 %s "Selected files"; the tagged files if any, otherwise the current file
69 %t Tagged files
70 %u Tagged files (and they are untagged on return from expand_format)
71 %view Runs the commands and pipes standard output to the view command.
72 If %view is immediately followed by '{', recognize keywords
73 ascii, hex, nroff and unform
75 If the format letter is in uppercase, it refers to the other panel.
77 With a number followed the % character you can turn quoting on (default)
78 and off. For example:
79 %f quote expanded macro
80 %1f ditto
81 %0f don't quote expanded macro
83 expand_format returns a memory block that must be free()d.
86 /* Returns how many characters we should advance if %view was found */
87 int
88 check_format_view (const char *p)
90 const char *q = p;
91 if (!strncmp (p, "view", 4))
93 q += 4;
94 if (*q == '{')
96 for (q++; *q && *q != '}'; q++)
98 if (!strncmp (q, "ascii", 5))
100 mcview_default_hex_mode = 0;
101 q += 4;
103 else if (!strncmp (q, "hex", 3))
105 mcview_default_hex_mode = 1;
106 q += 2;
108 else if (!strncmp (q, "nroff", 5))
110 mcview_default_nroff_flag = 1;
111 q += 4;
113 else if (!strncmp (q, "unform", 6))
115 mcview_default_nroff_flag = 0;
116 q += 5;
119 if (*q == '}')
120 q++;
122 return q - p;
124 return 0;
128 check_format_cd (const char *p)
130 return (strncmp (p, "cd", 2)) ? 0 : 3;
133 /* Check if p has a "^var\{var-name\}" */
134 /* Returns the number of skipped characters (zero on not found) */
135 /* V will be set to the expanded variable name */
137 check_format_var (const char *p, char **v)
139 const char *q = p;
140 char *var_name;
141 const char *value;
142 const char *dots = 0;
144 *v = 0;
145 if (!strncmp (p, "var{", 4))
147 for (q += 4; *q && *q != '}'; q++)
149 if (*q == ':')
150 dots = q + 1;
152 if (!*q)
153 return 0;
155 if (!dots || dots == q + 5)
157 message (D_ERROR,
158 _("Format error on file Extensions File"),
159 !dots ? _("The %%var macro has no default")
160 : _("The %%var macro has no variable"));
161 return 0;
164 /* Copy the variable name */
165 var_name = g_strndup (p + 4, dots - 2 - (p + 3));
167 value = getenv (var_name);
168 g_free (var_name);
169 if (value)
171 *v = g_strdup (value);
172 return q - p;
174 var_name = g_strndup (dots, q - dots);
175 *v = var_name;
176 return q - p;
178 return 0;
181 /* strip file's extension */
182 static char *
183 strip_ext (char *ss)
185 register char *s = ss;
186 char *e = NULL;
187 while (*s)
189 if (*s == '.')
190 e = s;
191 if (*s == PATH_SEP && e)
192 e = NULL; /* '.' in *directory* name */
193 s++;
195 if (e)
196 *e = 0;
197 return ss;
200 char *
201 expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
203 WPanel *panel = NULL;
204 char *(*quote_func) (const char *, int);
205 char *fname = NULL;
206 char *result;
207 char c_lc;
209 #ifndef USE_INTERNAL_EDIT
210 (void) edit_widget;
211 #endif
213 if (c == '%')
214 return g_strdup ("%");
216 if (mc_run_mode == MC_RUN_FULL)
218 if (g_ascii_islower ((gchar) c))
219 panel = current_panel;
220 else
222 if (get_other_type () != view_listing)
223 return g_strdup ("");
224 panel = other_panel;
226 fname = panel->dir.list[panel->selected].fname;
228 #ifdef USE_INTERNAL_EDIT
229 else if (mc_run_mode == MC_RUN_EDITOR)
230 fname = str_unconst (edit_get_file_name (edit_widget));
231 #endif
233 if (do_quote)
234 quote_func = name_quote;
235 else
236 quote_func = fake_name_quote;
238 c_lc = g_ascii_tolower ((gchar) c);
240 switch (c_lc)
242 case 'f':
243 case 'p':
244 return (*quote_func) (fname, 0);
245 case 'x':
246 return (*quote_func) (extension (fname), 0);
247 case 'd':
249 char *cwd;
250 char *qstr;
252 cwd = g_malloc (MC_MAXPATHLEN + 1);
254 if (panel)
255 g_strlcpy (cwd, panel->cwd, MC_MAXPATHLEN + 1);
256 else
257 mc_get_current_wd (cwd, MC_MAXPATHLEN + 1);
259 qstr = (*quote_func) (cwd, 0);
261 g_free (cwd);
263 return qstr;
265 case 'i': /* indent equal number cursor position in line */
266 #ifdef USE_INTERNAL_EDIT
267 if (edit_widget)
268 return g_strnfill (edit_get_curs_col (edit_widget), ' ');
269 #endif
270 break;
271 case 'y': /* syntax type */
272 #ifdef USE_INTERNAL_EDIT
273 if (edit_widget)
275 const char *syntax_type = edit_get_syntax_type (edit_widget);
276 if (syntax_type != NULL)
277 return g_strdup (syntax_type);
279 #endif
280 break;
281 case 'k': /* block file name */
282 case 'b': /* block file name / strip extension */
284 #ifdef USE_INTERNAL_EDIT
285 if (edit_widget)
287 char *file = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE);
288 fname = (*quote_func) (file, 0);
289 g_free (file);
290 return fname;
292 #endif
293 if (c_lc == 'b')
294 return strip_ext ((*quote_func) (fname, 0));
295 break;
297 case 'n': /* strip extension in editor */
298 #ifdef USE_INTERNAL_EDIT
299 if (edit_widget)
300 return strip_ext ((*quote_func) (fname, 0));
301 #endif
302 break;
303 case 'm': /* menu file name */
304 if (menu)
305 return (*quote_func) (menu, 0);
306 break;
307 case 's':
308 if (!panel || !panel->marked)
309 return (*quote_func) (fname, 0);
311 /* Fall through */
313 case 't':
314 case 'u':
316 int length = 2, i;
317 char *block, *tmp;
319 if (!panel)
320 return g_strdup ("");
322 for (i = 0; i < panel->count; i++)
323 if (panel->dir.list[i].f.marked)
324 length += strlen (panel->dir.list[i].fname) + 1; /* for space */
326 block = g_malloc (length * 2 + 1);
327 *block = 0;
328 for (i = 0; i < panel->count; i++)
329 if (panel->dir.list[i].f.marked)
331 tmp = (*quote_func) (panel->dir.list[i].fname, 0);
332 strcat (block, tmp);
333 g_free (tmp);
334 strcat (block, " ");
335 if (c_lc == 'u')
336 do_file_mark (panel, i, 0);
338 return block;
339 } /* sub case block */
340 } /* switch */
341 result = g_strdup ("% ");
342 result[1] = c;
343 return result;
347 * Check for the "shell_patterns" directive. If it's found and valid,
348 * interpret it and move the pointer past the directive. Return the
349 * current pointer.
351 static char *
352 check_patterns (char *p)
354 static const char def_name[] = "shell_patterns=";
355 char *p0 = p;
357 if (strncmp (p, def_name, sizeof (def_name) - 1) != 0)
358 return p0;
360 p += sizeof (def_name) - 1;
361 if (*p == '1')
362 easy_patterns = 1;
363 else if (*p == '0')
364 easy_patterns = 0;
365 else
366 return p0;
368 /* Skip spaces */
369 p++;
370 while (*p == '\n' || *p == '\t' || *p == ' ')
371 p++;
372 return p;
375 /* Copies a whitespace separated argument from p to arg. Returns the
376 point after argument. */
377 static char *
378 extract_arg (char *p, char *arg, int size)
380 char *np;
382 while (*p && (*p == ' ' || *p == '\t' || *p == '\n'))
383 p++;
384 /* support quote space .mnu */
385 while (*p && (*p != ' ' || *(p - 1) == '\\') && *p != '\t' && *p != '\n')
387 np = str_get_next_char (p);
388 if (np - p >= size)
389 break;
390 memcpy (arg, p, np - p);
391 arg += np - p;
392 size -= np - p;
393 p = np;
395 *arg = 0;
396 if (!*p || *p == '\n')
397 str_prev_char (&p);
398 return p;
401 /* Tests whether the selected file in the panel is of any of the types
402 specified in argument. */
403 static int
404 test_type (WPanel * panel, char *arg)
406 int result = 0; /* False by default */
407 int st_mode = panel->dir.list[panel->selected].st.st_mode;
409 for (; *arg != 0; arg++)
411 switch (*arg)
413 case 'n': /* Not a directory */
414 result |= !S_ISDIR (st_mode);
415 break;
416 case 'r': /* Regular file */
417 result |= S_ISREG (st_mode);
418 break;
419 case 'd': /* Directory */
420 result |= S_ISDIR (st_mode);
421 break;
422 case 'l': /* Link */
423 result |= S_ISLNK (st_mode);
424 break;
425 case 'c': /* Character special */
426 result |= S_ISCHR (st_mode);
427 break;
428 case 'b': /* Block special */
429 result |= S_ISBLK (st_mode);
430 break;
431 case 'f': /* Fifo (named pipe) */
432 result |= S_ISFIFO (st_mode);
433 break;
434 case 's': /* Socket */
435 result |= S_ISSOCK (st_mode);
436 break;
437 case 'x': /* Executable */
438 result |= (st_mode & 0111) ? 1 : 0;
439 break;
440 case 't':
441 result |= panel->marked ? 1 : 0;
442 break;
443 default:
444 debug_error = 1;
445 break;
448 return result;
451 /* Calculates the truth value of the next condition starting from
452 p. Returns the point after condition. */
453 static char *
454 test_condition (WEdit * edit_widget, char *p, int *condition)
456 WPanel *panel;
457 char arg[256];
458 mc_search_type_t search_type;
460 if (easy_patterns)
462 search_type = MC_SEARCH_T_GLOB;
464 else
466 search_type = MC_SEARCH_T_REGEX;
469 /* Handle one condition */
470 for (; *p != '\n' && *p != '&' && *p != '|'; p++)
472 /* support quote space .mnu */
473 if ((*p == ' ' && *(p - 1) != '\\') || *p == '\t')
474 continue;
475 if (*p >= 'a')
476 panel = current_panel;
477 else
479 if (get_other_type () == view_listing)
480 panel = other_panel;
481 else
482 panel = NULL;
484 *p |= 0x20;
486 switch (*p++)
488 case '!':
489 p = test_condition (edit_widget, p, condition);
490 *condition = !*condition;
491 str_prev_char (&p);
492 break;
493 case 'f': /* file name pattern */
494 p = extract_arg (p, arg, sizeof (arg));
495 *condition = panel
496 && mc_search (arg, panel->dir.list[panel->selected].fname, search_type);
497 break;
498 case 'y': /* syntax pattern */
499 #ifdef USE_INTERNAL_EDIT
500 if (edit_widget)
502 const char *syntax_type = edit_get_syntax_type (edit_widget);
503 if (syntax_type != NULL)
505 p = extract_arg (p, arg, sizeof (arg));
506 *condition = panel && mc_search (arg, syntax_type, MC_SEARCH_T_NORMAL);
509 #endif
510 break;
511 case 'd':
512 p = extract_arg (p, arg, sizeof (arg));
513 *condition = panel && mc_search (arg, panel->cwd, search_type);
514 break;
515 case 't':
516 p = extract_arg (p, arg, sizeof (arg));
517 *condition = panel && test_type (panel, arg);
518 break;
519 case 'x': /* executable */
521 struct stat status;
523 p = extract_arg (p, arg, sizeof (arg));
524 if (stat (arg, &status) == 0)
525 *condition = is_exe (status.st_mode);
526 else
527 *condition = 0;
528 break;
530 default:
531 debug_error = 1;
532 break;
533 } /* switch */
535 } /* while */
536 return p;
539 /* General purpose condition debug output handler */
540 static void
541 debug_out (char *start, char *end, int cond)
543 static char *msg;
544 int len;
546 if (start == NULL && end == NULL)
548 /* Show output */
549 if (debug_flag && msg)
551 len = strlen (msg);
552 if (len)
553 msg[len - 1] = 0;
554 message (D_NORMAL, _("Debug"), "%s", msg);
557 debug_flag = 0;
558 g_free (msg);
559 msg = NULL;
561 else
563 const char *type;
564 char *p;
566 /* Save debug info for later output */
567 if (!debug_flag)
568 return;
569 /* Save the result of the condition */
570 if (debug_error)
572 type = _("ERROR:");
573 debug_error = 0;
575 else if (cond)
576 type = _("True:");
577 else
578 type = _("False:");
579 /* This is for debugging, don't need to be super efficient. */
580 if (end == NULL)
581 p = g_strdup_printf ("%s %s %c \n", msg ? msg : "", type, *start);
582 else
583 p = g_strdup_printf ("%s %s %.*s \n", msg ? msg : "", type, (int) (end - start), start);
584 g_free (msg);
585 msg = p;
589 /* Calculates the truth value of one lineful of conditions. Returns
590 the point just before the end of line. */
591 static char *
592 test_line (WEdit * edit_widget, char *p, int *result)
594 int condition;
595 char operator;
596 char *debug_start, *debug_end;
598 /* Repeat till end of line */
599 while (*p && *p != '\n')
601 /* support quote space .mnu */
602 while ((*p == ' ' && *(p - 1) != '\\') || *p == '\t')
603 p++;
604 if (!*p || *p == '\n')
605 break;
606 operator = *p++;
607 if (*p == '?')
609 debug_flag = 1;
610 p++;
612 /* support quote space .mnu */
613 while ((*p == ' ' && *(p - 1) != '\\') || *p == '\t')
614 p++;
615 if (!*p || *p == '\n')
616 break;
617 condition = 1; /* True by default */
619 debug_start = p;
620 p = test_condition (edit_widget, p, &condition);
621 debug_end = p;
622 /* Add one debug statement */
623 debug_out (debug_start, debug_end, condition);
625 switch (operator)
627 case '+':
628 case '=':
629 /* Assignment */
630 *result = condition;
631 break;
632 case '&': /* Logical and */
633 *result &= condition;
634 break;
635 case '|': /* Logical or */
636 *result |= condition;
637 break;
638 default:
639 debug_error = 1;
640 break;
641 } /* switch */
642 /* Add one debug statement */
643 debug_out (&operator, NULL, *result);
645 } /* while (*p != '\n') */
646 /* Report debug message */
647 debug_out (NULL, NULL, 1);
649 if (!*p || *p == '\n')
650 str_prev_char (&p);
651 return p;
654 /* FIXME: recode this routine on version 3.0, it could be cleaner */
655 static void
656 execute_menu_command (WEdit * edit_widget, const char *commands)
658 FILE *cmd_file;
659 int cmd_file_fd;
660 int expand_prefix_found = 0;
661 char *parameter = 0;
662 gboolean do_quote = FALSE;
663 char lc_prompt[80];
664 int col;
665 char *file_name;
666 int run_view = 0;
668 /* Skip menu entry title line */
669 commands = strchr (commands, '\n');
670 if (!commands)
672 return;
675 cmd_file_fd = mc_mkstemps (&file_name, "mcusr", SCRIPT_SUFFIX);
677 if (cmd_file_fd == -1)
679 message (D_ERROR, MSG_ERROR, _("Cannot create temporary command file\n%s"),
680 unix_error_string (errno));
681 return;
683 cmd_file = fdopen (cmd_file_fd, "w");
684 fputs ("#! /bin/sh\n", cmd_file);
685 commands++;
687 for (col = 0; *commands; commands++)
689 if (col == 0)
691 if (*commands != ' ' && *commands != '\t')
692 break;
693 while (*commands == ' ' || *commands == '\t')
694 commands++;
695 if (*commands == 0)
696 break;
698 col++;
699 if (*commands == '\n')
700 col = 0;
701 if (parameter)
703 if (*commands == '}')
705 char *tmp;
706 *parameter = 0;
707 parameter =
708 input_dialog (_("Parameter"), lc_prompt, MC_HISTORY_FM_MENU_EXEC_PARAM, "");
709 if (!parameter || !*parameter)
711 /* User canceled */
712 fclose (cmd_file);
713 unlink (file_name);
714 g_free (file_name);
715 return;
717 if (do_quote)
719 tmp = name_quote (parameter, 0);
720 fputs (tmp, cmd_file);
721 g_free (tmp);
723 else
724 fputs (parameter, cmd_file);
725 g_free (parameter);
726 parameter = 0;
728 else
730 if (parameter < &lc_prompt[sizeof (lc_prompt) - 1])
732 *parameter++ = *commands;
736 else if (expand_prefix_found)
738 expand_prefix_found = 0;
739 if (g_ascii_isdigit ((gchar) * commands))
741 do_quote = (atoi (commands) != 0);
742 while (g_ascii_isdigit ((gchar) * commands))
743 commands++;
745 if (*commands == '{')
746 parameter = lc_prompt;
747 else
749 char *text = expand_format (edit_widget, *commands, do_quote);
750 fputs (text, cmd_file);
751 g_free (text);
754 else
756 if (*commands == '%')
758 int i = check_format_view (commands + 1);
759 if (i)
761 commands += i;
762 run_view = 1;
764 else
766 do_quote = TRUE; /* Default: Quote expanded macro */
767 expand_prefix_found = 1;
770 else
771 fputc (*commands, cmd_file);
774 fclose (cmd_file);
775 chmod (file_name, S_IRWXU);
776 if (run_view)
778 mcview_viewer (file_name, NULL, 0);
779 dialog_switch_process_pending ();
781 else
783 /* execute the command indirectly to allow execution even
784 * on no-exec filesystems. */
785 char *cmd = g_strconcat ("/bin/sh ", file_name, (char *) NULL);
786 shell_execute (cmd, EXECUTE_HIDE);
787 g_free (cmd);
789 unlink (file_name);
790 g_free (file_name);
794 ** Check owner of the menu file. Using menu file is allowed, if
795 ** owner of the menu is root or the actual user. In either case
796 ** file should not be group and word-writable.
798 ** Q. Should we apply this routine to system and home menu (and .ext files)?
800 static int
801 menu_file_own (char *path)
803 struct stat st;
805 if (stat (path, &st) == 0
806 && (!st.st_uid || (st.st_uid == geteuid ())) && ((st.st_mode & (S_IWGRP | S_IWOTH)) == 0))
808 return 1;
810 if (verbose)
812 message (D_NORMAL, _("Warning -- ignoring file"),
813 _("File %s is not owned by root or you or is world writable.\n"
814 "Using it may compromise your security"), path);
816 return 0;
820 * If edit_widget is NULL then we are called from the mc menu,
821 * otherwise we are called from the mcedit menu.
823 void
824 user_menu_cmd (struct WEdit *edit_widget)
826 char *p;
827 char *data, **entries;
828 int max_cols, menu_lines, menu_limit;
829 int col, i, accept_entry = 1;
830 int selected, old_patterns;
831 Listbox *listbox;
833 if (!vfs_current_is_local ())
835 message (D_ERROR, MSG_ERROR, "%s", _("Cannot execute commands on non-local filesystems"));
836 return;
839 menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU);
840 if (!exist_file (menu) || !menu_file_own (menu))
842 g_free (menu);
843 if (edit_widget)
844 menu = concat_dir_and_file (home_dir, EDIT_HOME_MENU);
845 else
846 menu = g_build_filename (home_dir, MC_USERCONF_DIR, MC_USERMENU_FILE, NULL);
849 if (!exist_file (menu))
851 g_free (menu);
852 menu = concat_dir_and_file (mc_home, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
853 if (!exist_file (menu))
855 g_free (menu);
856 menu = concat_dir_and_file
857 (mc_home_alt, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
862 data = load_file (menu);
863 if (data == NULL)
865 message (D_ERROR, MSG_ERROR, _("Cannot open file%s\n%s"), menu, unix_error_string (errno));
866 g_free (menu);
867 menu = NULL;
868 return;
871 max_cols = 0;
872 selected = 0;
873 menu_limit = 0;
874 entries = 0;
876 /* Parse the menu file */
877 old_patterns = easy_patterns;
878 p = check_patterns (data);
879 for (menu_lines = col = 0; *p; str_next_char (&p))
881 if (menu_lines >= menu_limit)
883 char **new_entries;
885 menu_limit += MAX_ENTRIES;
886 new_entries = g_try_realloc (entries, sizeof (new_entries[0]) * menu_limit);
888 if (new_entries == NULL)
889 break;
891 entries = new_entries;
892 new_entries += menu_limit;
893 while (--new_entries >= &entries[menu_lines])
894 *new_entries = NULL;
896 if (col == 0 && !entries[menu_lines])
898 if (*p == '#')
900 /* A commented menu entry */
901 accept_entry = 1;
903 else if (*p == '+')
905 if (*(p + 1) == '=')
907 /* Combined adding and default */
908 p = test_line (edit_widget, p + 1, &accept_entry);
909 if (selected == 0 && accept_entry)
910 selected = menu_lines;
912 else
914 /* A condition for adding the entry */
915 p = test_line (edit_widget, p, &accept_entry);
918 else if (*p == '=')
920 if (*(p + 1) == '+')
922 /* Combined adding and default */
923 p = test_line (edit_widget, p + 1, &accept_entry);
924 if (selected == 0 && accept_entry)
925 selected = menu_lines;
927 else
929 /* A condition for making the entry default */
930 i = 1;
931 p = test_line (edit_widget, p, &i);
932 if (selected == 0 && i)
933 selected = menu_lines;
936 else if (*p != ' ' && *p != '\t' && str_isprint (p))
938 /* A menu entry title line */
939 if (accept_entry)
940 entries[menu_lines] = p;
941 else
942 accept_entry = 1;
945 if (*p == '\n')
947 if (entries[menu_lines])
949 menu_lines++;
950 accept_entry = 1;
952 max_cols = max (max_cols, col);
953 col = 0;
955 else
957 if (*p == '\t')
958 *p = ' ';
959 col++;
963 if (menu_lines == 0)
964 message (D_ERROR, MSG_ERROR, _("No suitable entries found in %s"), menu);
965 else
967 max_cols = min (max (max_cols, col), MAX_ENTRY_LEN);
969 /* Create listbox */
970 listbox = create_listbox_window (menu_lines, max_cols + 2, _("User menu"),
971 "[Menu File Edit]");
972 /* insert all the items found */
973 for (i = 0; i < menu_lines; i++)
975 p = entries[i];
976 LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0],
977 extract_line (p, p + MAX_ENTRY_LEN), p);
979 /* Select the default entry */
980 listbox_select_entry (listbox->list, selected);
982 selected = run_listbox (listbox);
983 if (selected >= 0)
984 execute_menu_command (edit_widget, entries[selected]);
986 do_refresh ();
989 easy_patterns = old_patterns;
990 g_free (menu);
991 menu = NULL;
992 g_free (entries);
993 g_free (data);