Applied MC indentation policy.
[midnight-commander.git] / src / user.c
blob6d1aa51e986bc16f6aabda78adde9fed8df03717
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"
51 /* For the simple listbox manager */
52 #include "dialog.h"
53 #include "widget.h"
54 #include "wtools.h"
56 #define MAX_ENTRIES 16
57 #define MAX_ENTRY_LEN 60
59 static int debug_flag = 0;
60 static int debug_error = 0;
61 static char *menu = NULL;
63 /* Formats defined:
64 %% The % character
65 %f The current file (if non-local vfs, file will be copied locally and
66 %f will be full path to it).
67 %p The current file
68 %d The current working directory
69 %s "Selected files"; the tagged files if any, otherwise the current file
70 %t Tagged files
71 %u Tagged files (and they are untagged on return from expand_format)
72 %view Runs the commands and pipes standard output to the view command.
73 If %view is immediately followed by '{', recognize keywords
74 ascii, hex, nroff and unform
76 If the format letter is in uppercase, it refers to the other panel.
78 With a number followed the % character you can turn quoting on (default)
79 and off. For example:
80 %f quote expanded macro
81 %1f ditto
82 %0f don't quote expanded macro
84 expand_format returns a memory block that must be free()d.
87 /* Returns how many characters we should advance if %view was found */
88 int
89 check_format_view (const char *p)
91 const char *q = p;
92 if (!strncmp (p, "view", 4))
94 q += 4;
95 if (*q == '{')
97 for (q++; *q && *q != '}'; q++)
99 if (!strncmp (q, "ascii", 5))
101 mcview_default_hex_mode = 0;
102 q += 4;
104 else if (!strncmp (q, "hex", 3))
106 mcview_default_hex_mode = 1;
107 q += 2;
109 else if (!strncmp (q, "nroff", 5))
111 mcview_default_nroff_flag = 1;
112 q += 4;
114 else if (!strncmp (q, "unform", 6))
116 mcview_default_nroff_flag = 0;
117 q += 5;
120 if (*q == '}')
121 q++;
123 return q - p;
125 return 0;
129 check_format_cd (const char *p)
131 return (strncmp (p, "cd", 2)) ? 0 : 3;
134 /* Check if p has a "^var\{var-name\}" */
135 /* Returns the number of skipped characters (zero on not found) */
136 /* V will be set to the expanded variable name */
138 check_format_var (const char *p, char **v)
140 const char *q = p;
141 char *var_name;
142 const char *value;
143 const char *dots = 0;
145 *v = 0;
146 if (!strncmp (p, "var{", 4))
148 for (q += 4; *q && *q != '}'; q++)
150 if (*q == ':')
151 dots = q + 1;
153 if (!*q)
154 return 0;
156 if (!dots || dots == q + 5)
158 message (D_ERROR,
159 _("Format error on file Extensions File"),
160 !dots ? _("The %%var macro has no default")
161 : _("The %%var macro has no variable"));
162 return 0;
165 /* Copy the variable name */
166 var_name = g_strndup (p + 4, dots - 2 - (p + 3));
168 value = getenv (var_name);
169 g_free (var_name);
170 if (value)
172 *v = g_strdup (value);
173 return q - p;
175 var_name = g_strndup (dots, q - dots);
176 *v = var_name;
177 return q - p;
179 return 0;
182 /* strip file's extension */
183 static char *
184 strip_ext (char *ss)
186 register char *s = ss;
187 char *e = NULL;
188 while (*s)
190 if (*s == '.')
191 e = s;
192 if (*s == PATH_SEP && e)
193 e = NULL; /* '.' in *directory* name */
194 s++;
196 if (e)
197 *e = 0;
198 return ss;
201 char *
202 expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
204 WPanel *panel = NULL;
205 char *(*quote_func) (const char *, int);
206 char *fname = NULL;
207 char *result;
208 char c_lc;
210 #ifndef USE_INTERNAL_EDIT
211 (void) edit_widget;
212 #endif
214 if (c == '%')
215 return g_strdup ("%");
217 if (mc_run_mode == MC_RUN_FULL)
219 if (g_ascii_islower ((gchar) c))
220 panel = current_panel;
221 else
223 if (get_other_type () != view_listing)
224 return g_strdup ("");
225 panel = other_panel;
227 fname = panel->dir.list[panel->selected].fname;
229 #ifdef USE_INTERNAL_EDIT
230 else if (mc_run_mode == MC_RUN_EDITOR)
231 fname = str_unconst (edit_get_file_name (edit_widget));
232 #endif
234 if (do_quote)
235 quote_func = name_quote;
236 else
237 quote_func = fake_name_quote;
239 c_lc = g_ascii_tolower ((gchar) c);
241 switch (c_lc)
243 case 'f':
244 case 'p':
245 return (*quote_func) (fname, 0);
246 case 'x':
247 return (*quote_func) (extension (fname), 0);
248 case 'd':
250 char *cwd;
251 char *qstr;
253 cwd = g_malloc (MC_MAXPATHLEN + 1);
255 if (panel)
256 g_strlcpy (cwd, panel->cwd, MC_MAXPATHLEN + 1);
257 else
258 mc_get_current_wd (cwd, MC_MAXPATHLEN + 1);
260 qstr = (*quote_func) (cwd, 0);
262 g_free (cwd);
264 return qstr;
266 case 'i': /* indent equal number cursor position in line */
267 #ifdef USE_INTERNAL_EDIT
268 if (edit_widget)
269 return g_strnfill (edit_get_curs_col (edit_widget), ' ');
270 #endif
271 break;
272 case 'y': /* syntax type */
273 #ifdef USE_INTERNAL_EDIT
274 if (edit_widget)
276 const char *syntax_type = edit_get_syntax_type (edit_widget);
277 if (syntax_type != NULL)
278 return g_strdup (syntax_type);
280 #endif
281 break;
282 case 'k': /* block file name */
283 case 'b': /* block file name / strip extension */
285 #ifdef USE_INTERNAL_EDIT
286 if (edit_widget)
288 char *file = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE);
289 fname = (*quote_func) (file, 0);
290 g_free (file);
291 return fname;
293 #endif
294 if (c_lc == 'b')
295 return strip_ext ((*quote_func) (fname, 0));
296 break;
298 case 'n': /* strip extension in editor */
299 #ifdef USE_INTERNAL_EDIT
300 if (edit_widget)
301 return strip_ext ((*quote_func) (fname, 0));
302 #endif
303 break;
304 case 'm': /* menu file name */
305 if (menu)
306 return (*quote_func) (menu, 0);
307 break;
308 case 's':
309 if (!panel || !panel->marked)
310 return (*quote_func) (fname, 0);
312 /* Fall through */
314 case 't':
315 case 'u':
317 int length = 2, i;
318 char *block, *tmp;
320 if (!panel)
321 return g_strdup ("");
323 for (i = 0; i < panel->count; i++)
324 if (panel->dir.list[i].f.marked)
325 length += strlen (panel->dir.list[i].fname) + 1; /* for space */
327 block = g_malloc (length * 2 + 1);
328 *block = 0;
329 for (i = 0; i < panel->count; i++)
330 if (panel->dir.list[i].f.marked)
332 tmp = (*quote_func) (panel->dir.list[i].fname, 0);
333 strcat (block, tmp);
334 g_free (tmp);
335 strcat (block, " ");
336 if (c_lc == 'u')
337 do_file_mark (panel, i, 0);
339 return block;
340 } /* sub case block */
341 } /* switch */
342 result = g_strdup ("% ");
343 result[1] = c;
344 return result;
348 * Check for the "shell_patterns" directive. If it's found and valid,
349 * interpret it and move the pointer past the directive. Return the
350 * current pointer.
352 static char *
353 check_patterns (char *p)
355 static const char def_name[] = "shell_patterns=";
356 char *p0 = p;
358 if (strncmp (p, def_name, sizeof (def_name) - 1) != 0)
359 return p0;
361 p += sizeof (def_name) - 1;
362 if (*p == '1')
363 easy_patterns = 1;
364 else if (*p == '0')
365 easy_patterns = 0;
366 else
367 return p0;
369 /* Skip spaces */
370 p++;
371 while (*p == '\n' || *p == '\t' || *p == ' ')
372 p++;
373 return p;
376 /* Copies a whitespace separated argument from p to arg. Returns the
377 point after argument. */
378 static char *
379 extract_arg (char *p, char *arg, int size)
381 char *np;
383 while (*p && (*p == ' ' || *p == '\t' || *p == '\n'))
384 p++;
385 /* support quote space .mnu */
386 while (*p && (*p != ' ' || *(p - 1) == '\\') && *p != '\t' && *p != '\n')
388 np = str_get_next_char (p);
389 if (np - p >= size)
390 break;
391 memcpy (arg, p, np - p);
392 arg += np - p;
393 size -= np - p;
394 p = np;
396 *arg = 0;
397 if (!*p || *p == '\n')
398 str_prev_char (&p);
399 return p;
402 /* Tests whether the selected file in the panel is of any of the types
403 specified in argument. */
404 static int
405 test_type (WPanel * panel, char *arg)
407 int result = 0; /* False by default */
408 int st_mode = panel->dir.list[panel->selected].st.st_mode;
410 for (; *arg != 0; arg++)
412 switch (*arg)
414 case 'n': /* Not a directory */
415 result |= !S_ISDIR (st_mode);
416 break;
417 case 'r': /* Regular file */
418 result |= S_ISREG (st_mode);
419 break;
420 case 'd': /* Directory */
421 result |= S_ISDIR (st_mode);
422 break;
423 case 'l': /* Link */
424 result |= S_ISLNK (st_mode);
425 break;
426 case 'c': /* Character special */
427 result |= S_ISCHR (st_mode);
428 break;
429 case 'b': /* Block special */
430 result |= S_ISBLK (st_mode);
431 break;
432 case 'f': /* Fifo (named pipe) */
433 result |= S_ISFIFO (st_mode);
434 break;
435 case 's': /* Socket */
436 result |= S_ISSOCK (st_mode);
437 break;
438 case 'x': /* Executable */
439 result |= (st_mode & 0111) ? 1 : 0;
440 break;
441 case 't':
442 result |= panel->marked ? 1 : 0;
443 break;
444 default:
445 debug_error = 1;
446 break;
449 return result;
452 /* Calculates the truth value of the next condition starting from
453 p. Returns the point after condition. */
454 static char *
455 test_condition (WEdit * edit_widget, char *p, int *condition)
457 WPanel *panel;
458 char arg[256];
459 mc_search_type_t search_type;
461 if (easy_patterns)
463 search_type = MC_SEARCH_T_GLOB;
465 else
467 search_type = MC_SEARCH_T_REGEX;
470 /* Handle one condition */
471 for (; *p != '\n' && *p != '&' && *p != '|'; p++)
473 /* support quote space .mnu */
474 if ((*p == ' ' && *(p - 1) != '\\') || *p == '\t')
475 continue;
476 if (*p >= 'a')
477 panel = current_panel;
478 else
480 if (get_other_type () == view_listing)
481 panel = other_panel;
482 else
483 panel = NULL;
485 *p |= 0x20;
487 switch (*p++)
489 case '!':
490 p = test_condition (edit_widget, p, condition);
491 *condition = !*condition;
492 str_prev_char (&p);
493 break;
494 case 'f': /* file name pattern */
495 p = extract_arg (p, arg, sizeof (arg));
496 *condition = panel
497 && mc_search (arg, panel->dir.list[panel->selected].fname, search_type);
498 break;
499 case 'y': /* syntax pattern */
500 #ifdef USE_INTERNAL_EDIT
501 if (edit_widget)
503 const char *syntax_type = edit_get_syntax_type (edit_widget);
504 if (syntax_type != NULL)
506 p = extract_arg (p, arg, sizeof (arg));
507 *condition = panel && mc_search (arg, syntax_type, MC_SEARCH_T_NORMAL);
510 #endif
511 break;
512 case 'd':
513 p = extract_arg (p, arg, sizeof (arg));
514 *condition = panel && mc_search (arg, panel->cwd, search_type);
515 break;
516 case 't':
517 p = extract_arg (p, arg, sizeof (arg));
518 *condition = panel && test_type (panel, arg);
519 break;
520 case 'x': /* executable */
522 struct stat status;
524 p = extract_arg (p, arg, sizeof (arg));
525 if (stat (arg, &status) == 0)
526 *condition = is_exe (status.st_mode);
527 else
528 *condition = 0;
529 break;
531 default:
532 debug_error = 1;
533 break;
534 } /* switch */
536 } /* while */
537 return p;
540 /* General purpose condition debug output handler */
541 static void
542 debug_out (char *start, char *end, int cond)
544 static char *msg;
545 int len;
547 if (start == NULL && end == NULL)
549 /* Show output */
550 if (debug_flag && msg)
552 len = strlen (msg);
553 if (len)
554 msg[len - 1] = 0;
555 message (D_NORMAL, _("Debug"), "%s", msg);
558 debug_flag = 0;
559 g_free (msg);
560 msg = NULL;
562 else
564 const char *type;
565 char *p;
567 /* Save debug info for later output */
568 if (!debug_flag)
569 return;
570 /* Save the result of the condition */
571 if (debug_error)
573 type = _("ERROR:");
574 debug_error = 0;
576 else if (cond)
577 type = _("True:");
578 else
579 type = _("False:");
580 /* This is for debugging, don't need to be super efficient. */
581 if (end == NULL)
582 p = g_strdup_printf ("%s %s %c \n", msg ? msg : "", type, *start);
583 else
584 p = g_strdup_printf ("%s %s %.*s \n", msg ? msg : "", type, (int) (end - start), start);
585 g_free (msg);
586 msg = p;
590 /* Calculates the truth value of one lineful of conditions. Returns
591 the point just before the end of line. */
592 static char *
593 test_line (WEdit * edit_widget, char *p, int *result)
595 int condition;
596 char operator;
597 char *debug_start, *debug_end;
599 /* Repeat till end of line */
600 while (*p && *p != '\n')
602 /* support quote space .mnu */
603 while ((*p == ' ' && *(p - 1) != '\\') || *p == '\t')
604 p++;
605 if (!*p || *p == '\n')
606 break;
607 operator = *p++;
608 if (*p == '?')
610 debug_flag = 1;
611 p++;
613 /* support quote space .mnu */
614 while ((*p == ' ' && *(p - 1) != '\\') || *p == '\t')
615 p++;
616 if (!*p || *p == '\n')
617 break;
618 condition = 1; /* True by default */
620 debug_start = p;
621 p = test_condition (edit_widget, p, &condition);
622 debug_end = p;
623 /* Add one debug statement */
624 debug_out (debug_start, debug_end, condition);
626 switch (operator)
628 case '+':
629 case '=':
630 /* Assignment */
631 *result = condition;
632 break;
633 case '&': /* Logical and */
634 *result &= condition;
635 break;
636 case '|': /* Logical or */
637 *result |= condition;
638 break;
639 default:
640 debug_error = 1;
641 break;
642 } /* switch */
643 /* Add one debug statement */
644 debug_out (&operator, NULL, *result);
646 } /* while (*p != '\n') */
647 /* Report debug message */
648 debug_out (NULL, NULL, 1);
650 if (!*p || *p == '\n')
651 str_prev_char (&p);
652 return p;
655 /* FIXME: recode this routine on version 3.0, it could be cleaner */
656 static void
657 execute_menu_command (WEdit * edit_widget, const char *commands)
659 FILE *cmd_file;
660 int cmd_file_fd;
661 int expand_prefix_found = 0;
662 char *parameter = 0;
663 gboolean do_quote = FALSE;
664 char lc_prompt[80];
665 int col;
666 char *file_name;
667 int run_view = 0;
669 /* Skip menu entry title line */
670 commands = strchr (commands, '\n');
671 if (!commands)
673 return;
676 cmd_file_fd = mc_mkstemps (&file_name, "mcusr", SCRIPT_SUFFIX);
678 if (cmd_file_fd == -1)
680 message (D_ERROR, MSG_ERROR, _("Cannot create temporary command file\n%s"),
681 unix_error_string (errno));
682 return;
684 cmd_file = fdopen (cmd_file_fd, "w");
685 fputs ("#! /bin/sh\n", cmd_file);
686 commands++;
688 for (col = 0; *commands; commands++)
690 if (col == 0)
692 if (*commands != ' ' && *commands != '\t')
693 break;
694 while (*commands == ' ' || *commands == '\t')
695 commands++;
696 if (*commands == 0)
697 break;
699 col++;
700 if (*commands == '\n')
701 col = 0;
702 if (parameter)
704 if (*commands == '}')
706 char *tmp;
707 *parameter = 0;
708 parameter =
709 input_dialog (_("Parameter"), lc_prompt, MC_HISTORY_FM_MENU_EXEC_PARAM, "");
710 if (!parameter || !*parameter)
712 /* User canceled */
713 fclose (cmd_file);
714 unlink (file_name);
715 g_free (file_name);
716 return;
718 if (do_quote)
720 tmp = name_quote (parameter, 0);
721 fputs (tmp, cmd_file);
722 g_free (tmp);
724 else
725 fputs (parameter, cmd_file);
726 g_free (parameter);
727 parameter = 0;
729 else
731 if (parameter < &lc_prompt[sizeof (lc_prompt) - 1])
733 *parameter++ = *commands;
737 else if (expand_prefix_found)
739 expand_prefix_found = 0;
740 if (g_ascii_isdigit ((gchar) * commands))
742 do_quote = (atoi (commands) != 0);
743 while (g_ascii_isdigit ((gchar) * commands))
744 commands++;
746 if (*commands == '{')
747 parameter = lc_prompt;
748 else
750 char *text = expand_format (edit_widget, *commands, do_quote);
751 fputs (text, cmd_file);
752 g_free (text);
755 else
757 if (*commands == '%')
759 int i = check_format_view (commands + 1);
760 if (i)
762 commands += i;
763 run_view = 1;
765 else
767 do_quote = TRUE; /* Default: Quote expanded macro */
768 expand_prefix_found = 1;
771 else
772 fputc (*commands, cmd_file);
775 fclose (cmd_file);
776 chmod (file_name, S_IRWXU);
777 if (run_view)
779 run_view = 0;
780 mcview_viewer (file_name, NULL, &run_view, 0);
782 else
784 /* execute the command indirectly to allow execution even
785 * on no-exec filesystems. */
786 char *cmd = g_strconcat ("/bin/sh ", file_name, (char *) NULL);
787 shell_execute (cmd, EXECUTE_HIDE);
788 g_free (cmd);
790 unlink (file_name);
791 g_free (file_name);
795 ** Check owner of the menu file. Using menu file is allowed, if
796 ** owner of the menu is root or the actual user. In either case
797 ** file should not be group and word-writable.
799 ** Q. Should we apply this routine to system and home menu (and .ext files)?
801 static int
802 menu_file_own (char *path)
804 struct stat st;
806 if (stat (path, &st) == 0
807 && (!st.st_uid || (st.st_uid == geteuid ())) && ((st.st_mode & (S_IWGRP | S_IWOTH)) == 0))
809 return 1;
811 if (verbose)
813 message (D_NORMAL, _("Warning -- ignoring file"),
814 _("File %s is not owned by root or you or is world writable.\n"
815 "Using it may compromise your security"), path);
817 return 0;
821 * If edit_widget is NULL then we are called from the mc menu,
822 * otherwise we are called from the mcedit menu.
824 void
825 user_menu_cmd (struct WEdit *edit_widget)
827 char *p;
828 char *data, **entries;
829 int max_cols, menu_lines, menu_limit;
830 int col, i, accept_entry = 1;
831 int selected, old_patterns;
832 Listbox *listbox;
834 if (!vfs_current_is_local ())
836 message (D_ERROR, MSG_ERROR, "%s", _("Cannot execute commands on non-local filesystems"));
837 return;
840 menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU);
841 if (!exist_file (menu) || !menu_file_own (menu))
843 g_free (menu);
844 if (edit_widget)
845 menu = concat_dir_and_file (home_dir, EDIT_HOME_MENU);
846 else
847 menu = g_build_filename (home_dir, MC_USERCONF_DIR, MC_USERMENU_FILE, NULL);
850 if (!exist_file (menu))
852 g_free (menu);
853 menu = concat_dir_and_file (mc_home, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
854 if (!exist_file (menu))
856 g_free (menu);
857 menu = concat_dir_and_file
858 (mc_home_alt, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
863 data = load_file (menu);
864 if (data == NULL)
866 message (D_ERROR, MSG_ERROR, _("Cannot open file%s\n%s"), menu, unix_error_string (errno));
867 g_free (menu);
868 menu = NULL;
869 return;
872 max_cols = 0;
873 selected = 0;
874 menu_limit = 0;
875 entries = 0;
877 /* Parse the menu file */
878 old_patterns = easy_patterns;
879 p = check_patterns (data);
880 for (menu_lines = col = 0; *p; str_next_char (&p))
882 if (menu_lines >= menu_limit)
884 char **new_entries;
886 menu_limit += MAX_ENTRIES;
887 new_entries = g_try_realloc (entries, sizeof (new_entries[0]) * menu_limit);
889 if (new_entries == NULL)
890 break;
892 entries = new_entries;
893 new_entries += menu_limit;
894 while (--new_entries >= &entries[menu_lines])
895 *new_entries = NULL;
897 if (col == 0 && !entries[menu_lines])
899 if (*p == '#')
901 /* A commented menu entry */
902 accept_entry = 1;
904 else if (*p == '+')
906 if (*(p + 1) == '=')
908 /* Combined adding and default */
909 p = test_line (edit_widget, p + 1, &accept_entry);
910 if (selected == 0 && accept_entry)
911 selected = menu_lines;
913 else
915 /* A condition for adding the entry */
916 p = test_line (edit_widget, p, &accept_entry);
919 else if (*p == '=')
921 if (*(p + 1) == '+')
923 /* Combined adding and default */
924 p = test_line (edit_widget, p + 1, &accept_entry);
925 if (selected == 0 && accept_entry)
926 selected = menu_lines;
928 else
930 /* A condition for making the entry default */
931 i = 1;
932 p = test_line (edit_widget, p, &i);
933 if (selected == 0 && i)
934 selected = menu_lines;
937 else if (*p != ' ' && *p != '\t' && str_isprint (p))
939 /* A menu entry title line */
940 if (accept_entry)
941 entries[menu_lines] = p;
942 else
943 accept_entry = 1;
946 if (*p == '\n')
948 if (entries[menu_lines])
950 menu_lines++;
951 accept_entry = 1;
953 max_cols = max (max_cols, col);
954 col = 0;
956 else
958 if (*p == '\t')
959 *p = ' ';
960 col++;
964 if (menu_lines == 0)
965 message (D_ERROR, MSG_ERROR, _("No suitable entries found in %s"), menu);
966 else
968 max_cols = min (max (max_cols, col), MAX_ENTRY_LEN);
970 /* Create listbox */
971 listbox = create_listbox_window (menu_lines, max_cols + 2, _("User menu"),
972 "[Menu File Edit]");
973 /* insert all the items found */
974 for (i = 0; i < menu_lines; i++)
976 p = entries[i];
977 LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0],
978 extract_line (p, p + MAX_ENTRY_LEN), p);
980 /* Select the default entry */
981 listbox_select_entry (listbox->list, selected);
983 selected = run_listbox (listbox);
984 if (selected >= 0)
985 execute_menu_command (edit_widget, entries[selected]);
987 do_refresh ();
990 easy_patterns = old_patterns;
991 g_free (menu);
992 menu = NULL;
993 g_free (entries);
994 g_free (data);