Ticket #1787: remove obsolete checks for <stdlib.h>
[free-mc.git] / src / user.c
blob10e1dbc54a9ba49528112be16190217ba1794c96
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 lc_quote)
180 WPanel *panel = NULL;
181 char *(*quote_func) (const char *, int);
182 char *fname = NULL;
183 char *result;
184 char c_lc;
186 #ifndef USE_INTERNAL_EDIT
187 (void) edit_widget;
188 #endif
190 if (c == '%')
191 return g_strdup ("%");
193 if (edit_one_file == NULL) {
194 if (g_ascii_islower ((gchar) c))
195 panel = current_panel;
196 else {
197 if (get_other_type () != view_listing)
198 return g_strdup ("");
199 panel = other_panel;
201 fname = panel->dir.list[panel->selected].fname;
203 #ifdef USE_INTERNAL_EDIT
204 else
205 fname = str_unconst (edit_get_file_name (edit_widget));
206 #endif
208 if (lc_quote)
209 quote_func = name_quote;
210 else
211 quote_func = fake_name_quote;
213 c_lc = g_ascii_tolower ((gchar) c);
215 switch (c_lc) {
216 case 'f':
217 case 'p':
218 return (*quote_func) (fname, 0);
219 case 'x':
220 return (*quote_func) (extension (fname), 0);
221 case 'd':
223 char *cwd;
224 char *qstr;
226 cwd = g_malloc(MC_MAXPATHLEN + 1);
228 if (panel)
229 g_strlcpy(cwd, panel->cwd, MC_MAXPATHLEN + 1);
230 else
231 mc_get_current_wd(cwd, MC_MAXPATHLEN + 1);
233 qstr = (*quote_func) (cwd, 0);
235 g_free (cwd);
237 return qstr;
239 case 'i': /* indent equal number cursor position in line */
240 #ifdef USE_INTERNAL_EDIT
241 if (edit_widget)
242 return g_strnfill (edit_get_curs_col (edit_widget), ' ');
243 #endif
244 break;
245 case 'y': /* syntax type */
246 #ifdef USE_INTERNAL_EDIT
247 if (edit_widget) {
248 const char *syntax_type = edit_get_syntax_type (edit_widget);
249 if (syntax_type != NULL)
250 return g_strdup (syntax_type);
252 #endif
253 break;
254 case 'k': /* block file name */
255 case 'b': /* block file name / strip extension */ {
256 #ifdef USE_INTERNAL_EDIT
257 if (edit_widget) {
258 char *file = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE);
259 fname = (*quote_func) (file, 0);
260 g_free (file);
261 return fname;
263 #endif
264 if (c_lc == 'b')
265 return strip_ext ((*quote_func) (fname, 0));
266 break;
268 case 'n': /* strip extension in editor */
269 #ifdef USE_INTERNAL_EDIT
270 if (edit_widget)
271 return strip_ext ((*quote_func) (fname, 0));
272 #endif
273 break;
274 case 'm': /* menu file name */
275 if (menu)
276 return (*quote_func) (menu, 0);
277 break;
278 case 's':
279 if (!panel || !panel->marked)
280 return (*quote_func) (fname, 0);
282 /* Fall through */
284 case 't':
285 case 'u':
287 int length = 2, i;
288 char *block, *tmp;
290 if (!panel)
291 return g_strdup ("");
293 for (i = 0; i < panel->count; i++)
294 if (panel->dir.list[i].f.marked)
295 length += strlen (panel->dir.list[i].fname) + 1; /* for space */
297 block = g_malloc (length * 2 + 1);
298 *block = 0;
299 for (i = 0; i < panel->count; i++)
300 if (panel->dir.list[i].f.marked) {
301 strcat (block, tmp =
302 (*quote_func) (panel->dir.list[i].fname, 0));
303 g_free (tmp);
304 strcat (block, " ");
305 if (c_lc == 'u')
306 do_file_mark (panel, i, 0);
308 return block;
309 } /* sub case block */
310 } /* switch */
311 result = g_strdup ("% ");
312 result[1] = c;
313 return result;
317 * Check for the "shell_patterns" directive. If it's found and valid,
318 * interpret it and move the pointer past the directive. Return the
319 * current pointer.
321 static char *
322 check_patterns (char *p)
324 static const char def_name[] = "shell_patterns=";
325 char *p0 = p;
327 if (strncmp (p, def_name, sizeof (def_name) - 1) != 0)
328 return p0;
330 p += sizeof (def_name) - 1;
331 if (*p == '1')
332 easy_patterns = 1;
333 else if (*p == '0')
334 easy_patterns = 0;
335 else
336 return p0;
338 /* Skip spaces */
339 p++;
340 while (*p == '\n' || *p == '\t' || *p == ' ')
341 p++;
342 return p;
345 /* Copies a whitespace separated argument from p to arg. Returns the
346 point after argument. */
347 static char *extract_arg (char *p, char *arg, int size)
349 char *np;
351 while (*p && (*p == ' ' || *p == '\t' || *p == '\n'))
352 p++;
353 /* support quote space .mnu */
354 while (*p && (*p != ' ' || *(p-1) == '\\') && *p != '\t' && *p != '\n') {
355 np = str_get_next_char (p);
356 if (np - p >= size) break;
357 memcpy (arg, p, np - p);
358 arg+= np - p;
359 size-= np - p;
360 p = np;
362 *arg = 0;
363 if (!*p || *p == '\n')
364 str_prev_char (&p);
365 return p;
368 /* Tests whether the selected file in the panel is of any of the types
369 specified in argument. */
370 static int test_type (WPanel *panel, char *arg)
372 int result = 0; /* False by default */
373 int st_mode = panel->dir.list [panel->selected].st.st_mode;
375 for (;*arg != 0; arg++){
376 switch (*arg){
377 case 'n': /* Not a directory */
378 result |= !S_ISDIR (st_mode);
379 break;
380 case 'r': /* Regular file */
381 result |= S_ISREG (st_mode);
382 break;
383 case 'd': /* Directory */
384 result |= S_ISDIR (st_mode);
385 break;
386 case 'l': /* Link */
387 result |= S_ISLNK (st_mode);
388 break;
389 case 'c': /* Character special */
390 result |= S_ISCHR (st_mode);
391 break;
392 case 'b': /* Block special */
393 result |= S_ISBLK (st_mode);
394 break;
395 case 'f': /* Fifo (named pipe) */
396 result |= S_ISFIFO (st_mode);
397 break;
398 case 's': /* Socket */
399 result |= S_ISSOCK (st_mode);
400 break;
401 case 'x': /* Executable */
402 result |= (st_mode & 0111) ? 1 : 0;
403 break;
404 case 't':
405 result |= panel->marked ? 1 : 0;
406 break;
407 default:
408 debug_error = 1;
409 break;
412 return result;
415 /* Calculates the truth value of the next condition starting from
416 p. Returns the point after condition. */
417 static char *
418 test_condition (WEdit *edit_widget, char *p, int *condition)
420 WPanel *panel;
421 char arg [256];
422 mc_search_type_t search_type;
424 if (easy_patterns) {
425 search_type = MC_SEARCH_T_GLOB;
426 } else {
427 search_type = MC_SEARCH_T_REGEX;
430 /* Handle one condition */
431 for (;*p != '\n' && *p != '&' && *p != '|'; p++){
432 /* support quote space .mnu */
433 if ((*p == ' ' && *(p-1) != '\\') || *p == '\t')
434 continue;
435 if (*p >= 'a')
436 panel = current_panel;
437 else {
438 if (get_other_type () == view_listing)
439 panel = other_panel;
440 else
441 panel = NULL;
443 *p |= 0x20;
445 switch (*p++){
446 case '!':
447 p = test_condition (edit_widget, p, condition);
448 *condition = ! *condition;
449 str_prev_char (&p);
450 break;
451 case 'f': /* file name pattern */
452 p = extract_arg (p, arg, sizeof (arg));
453 *condition = panel && mc_search (arg, panel->dir.list [panel->selected].fname, search_type);
454 break;
455 case 'y': /* syntax pattern */
456 #ifdef USE_INTERNAL_EDIT
457 if (edit_widget) {
458 const char *syntax_type = edit_get_syntax_type (edit_widget);
459 if (syntax_type != NULL) {
460 p = extract_arg (p, arg, sizeof (arg));
461 *condition = panel && mc_search (arg, syntax_type, MC_SEARCH_T_NORMAL);
464 #endif
465 break;
466 case 'd':
467 p = extract_arg (p, arg, sizeof (arg));
468 *condition = panel && mc_search (arg, panel->cwd, search_type);
469 break;
470 case 't':
471 p = extract_arg (p, arg, sizeof (arg));
472 *condition = panel && test_type (panel, arg);
473 break;
474 case 'x': /* executable */
476 struct stat status;
478 p = extract_arg (p, arg, sizeof (arg));
479 if (stat (arg, &status) == 0)
480 *condition = is_exe (status.st_mode);
481 else
482 *condition = 0;
483 break;
485 default:
486 debug_error = 1;
487 break;
488 } /* switch */
490 } /* while */
491 return p;
494 /* General purpose condition debug output handler */
495 static void
496 debug_out (char *start, char *end, int cond)
498 static char *msg;
499 int len;
501 if (start == NULL && end == NULL){
502 /* Show output */
503 if (debug_flag && msg) {
504 len = strlen (msg);
505 if (len)
506 msg [len - 1] = 0;
507 message (D_NORMAL, _(" Debug "), "%s", msg);
510 debug_flag = 0;
511 g_free (msg);
512 msg = NULL;
513 } else {
514 const char *type;
515 char *p;
517 /* Save debug info for later output */
518 if (!debug_flag)
519 return;
520 /* Save the result of the condition */
521 if (debug_error){
522 type = _(" ERROR: ");
523 debug_error = 0;
525 else if (cond)
526 type = _(" True: ");
527 else
528 type = _(" False: ");
529 /* This is for debugging, don't need to be super efficient. */
530 if (end == NULL)
531 p = g_strdup_printf ("%s%s%c \n", msg ? msg : "", type, *start);
532 else
533 p = g_strdup_printf ("%s%s%.*s \n", msg ? msg : "", type,
534 (int) (end - start), start);
535 g_free (msg);
536 msg = p;
540 /* Calculates the truth value of one lineful of conditions. Returns
541 the point just before the end of line. */
542 static char *
543 test_line (WEdit *edit_widget, char *p, int *result)
545 int condition;
546 char operator;
547 char *debug_start, *debug_end;
549 /* Repeat till end of line */
550 while (*p && *p != '\n') {
551 /* support quote space .mnu */
552 while ((*p == ' ' && *(p-1) != '\\' ) || *p == '\t')
553 p++;
554 if (!*p || *p == '\n')
555 break;
556 operator = *p++;
557 if (*p == '?'){
558 debug_flag = 1;
559 p++;
561 /* support quote space .mnu */
562 while ((*p == ' ' && *(p-1) != '\\' ) || *p == '\t')
563 p++;
564 if (!*p || *p == '\n')
565 break;
566 condition = 1; /* True by default */
568 debug_start = p;
569 p = test_condition (edit_widget, p, &condition);
570 debug_end = p;
571 /* Add one debug statement */
572 debug_out (debug_start, debug_end, condition);
574 switch (operator){
575 case '+':
576 case '=':
577 /* Assignment */
578 *result = condition;
579 break;
580 case '&': /* Logical and */
581 *result &= condition;
582 break;
583 case '|': /* Logical or */
584 *result |= condition;
585 break;
586 default:
587 debug_error = 1;
588 break;
589 } /* switch */
590 /* Add one debug statement */
591 debug_out (&operator, NULL, *result);
593 } /* while (*p != '\n') */
594 /* Report debug message */
595 debug_out (NULL, NULL, 1);
597 if (!*p || *p == '\n')
598 str_prev_char (&p);
599 return p;
602 /* FIXME: recode this routine on version 3.0, it could be cleaner */
603 static void
604 execute_menu_command (WEdit *edit_widget, const char *commands)
606 FILE *cmd_file;
607 int cmd_file_fd;
608 int expand_prefix_found = 0;
609 char *parameter = 0;
610 int do_quote = 0;
611 char lc_prompt [80];
612 int col;
613 char *file_name;
614 int run_view = 0;
616 /* Skip menu entry title line */
617 commands = strchr (commands, '\n');
618 if (!commands){
619 return;
622 cmd_file_fd = mc_mkstemps (&file_name, "mcusr", SCRIPT_SUFFIX);
624 if (cmd_file_fd == -1){
625 message (D_ERROR, MSG_ERROR, _(" Cannot create temporary command file \n %s "),
626 unix_error_string (errno));
627 return;
629 cmd_file = fdopen (cmd_file_fd, "w");
630 fputs ("#! /bin/sh\n", cmd_file);
631 commands++;
633 for (col = 0; *commands; commands++){
634 if (col == 0) {
635 if (*commands != ' ' && *commands != '\t')
636 break;
637 while (*commands == ' ' || *commands == '\t')
638 commands++;
639 if (*commands == 0)
640 break;
642 col++;
643 if (*commands == '\n')
644 col = 0;
645 if (parameter){
646 if (*commands == '}'){
647 char *tmp;
648 *parameter = 0;
649 parameter = input_dialog (_(" Parameter "), lc_prompt, MC_HISTORY_FM_MENU_EXEC_PARAM, "");
650 if (!parameter || !*parameter){
651 /* User canceled */
652 fclose (cmd_file);
653 unlink (file_name);
654 g_free (file_name);
655 return;
657 if (do_quote) {
658 fputs (tmp = name_quote (parameter, 0), cmd_file);
659 g_free (tmp);
660 } else
661 fputs (parameter, cmd_file);
662 g_free (parameter);
663 parameter = 0;
664 } else {
665 if (parameter < &lc_prompt [sizeof (lc_prompt) - 1]) {
666 *parameter++ = *commands;
669 } else if (expand_prefix_found){
670 expand_prefix_found = 0;
671 if (g_ascii_isdigit ((gchar) *commands)) {
672 do_quote = atoi (commands);
673 while (g_ascii_isdigit ((gchar) *commands))
674 commands++;
676 if (*commands == '{')
677 parameter = lc_prompt;
678 else{
679 char *text = expand_format (edit_widget, *commands, do_quote);
680 fputs (text, cmd_file);
681 g_free (text);
683 } else {
684 if (*commands == '%') {
685 int i = check_format_view (commands + 1);
686 if (i) {
687 commands += i;
688 run_view = 1;
689 } else {
690 do_quote = 1; /* Default: Quote expanded macro */
691 expand_prefix_found = 1;
693 } else
694 fputc (*commands, cmd_file);
697 fclose (cmd_file);
698 chmod (file_name, S_IRWXU);
699 if (run_view) {
700 run_view = 0;
701 mcview_viewer (file_name, NULL, &run_view, 0);
702 } else {
703 /* execute the command indirectly to allow execution even
704 * on no-exec filesystems. */
705 char *cmd = g_strconcat("/bin/sh ", file_name, (char *)NULL);
706 shell_execute (cmd, EXECUTE_HIDE);
707 g_free(cmd);
709 unlink (file_name);
710 g_free (file_name);
714 ** Check owner of the menu file. Using menu file is allowed, if
715 ** owner of the menu is root or the actual user. In either case
716 ** file should not be group and word-writable.
718 ** Q. Should we apply this routine to system and home menu (and .ext files)?
720 static int
721 menu_file_own(char* path)
723 struct stat st;
725 if (stat (path, &st) == 0
726 && (!st.st_uid || (st.st_uid == geteuid ()))
727 && ((st.st_mode & (S_IWGRP | S_IWOTH)) == 0)
729 return 1;
731 if (verbose)
733 message (D_NORMAL, _(" Warning -- ignoring file "),
734 _("File %s is not owned by root or you or is world writable.\n"
735 "Using it may compromise your security"),
736 path
739 return 0;
743 * If edit_widget is NULL then we are called from the mc menu,
744 * otherwise we are called from the mcedit menu.
746 void
747 user_menu_cmd (WEdit *edit_widget)
749 char *p;
750 char *data, **entries;
751 int max_cols, menu_lines, menu_limit;
752 int col, i, accept_entry = 1;
753 int selected, old_patterns;
754 Listbox *listbox;
756 if (!vfs_current_is_local ()){
757 message (D_ERROR, MSG_ERROR,
758 _(" Cannot execute commands on non-local filesystems"));
759 return;
762 menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU);
763 if (!exist_file (menu) || !menu_file_own (menu)){
764 g_free (menu);
765 if (edit_widget)
766 menu = concat_dir_and_file (home_dir, EDIT_HOME_MENU);
767 else
768 menu = g_build_filename (home_dir, MC_USERCONF_DIR, MC_USERMENU_FILE, NULL);
771 if (!exist_file (menu)){
772 g_free (menu);
773 menu = concat_dir_and_file
774 (mc_home, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
775 if (!exist_file (menu)) {
776 g_free (menu);
777 menu = concat_dir_and_file
778 (mc_home_alt, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
783 if ((data = load_file (menu)) == NULL){
784 message (D_ERROR, MSG_ERROR, _(" Cannot open file %s \n %s "),
785 menu, unix_error_string (errno));
786 g_free (menu);
787 menu = NULL;
788 return;
791 max_cols = 0;
792 selected = 0;
793 menu_limit = 0;
794 entries = 0;
796 /* Parse the menu file */
797 old_patterns = easy_patterns;
798 p = check_patterns (data);
799 for (menu_lines = col = 0; *p; str_next_char (&p)){
800 if (menu_lines >= menu_limit){
801 char ** new_entries;
803 menu_limit += MAX_ENTRIES;
804 new_entries = g_realloc (entries, sizeof (new_entries[0]) * menu_limit);
806 if (new_entries == 0)
807 break;
809 entries = new_entries;
810 new_entries += menu_limit;
811 while (--new_entries >= &entries[menu_lines])
812 *new_entries = 0;
814 if (col == 0 && !entries [menu_lines]){
815 if (*p == '#'){
816 /* A commented menu entry */
817 accept_entry = 1;
818 } else if (*p == '+'){
819 if (*(p+1) == '='){
820 /* Combined adding and default */
821 p = test_line (edit_widget, p + 1, &accept_entry);
822 if (selected == 0 && accept_entry)
823 selected = menu_lines;
824 } else {
825 /* A condition for adding the entry */
826 p = test_line (edit_widget, p, &accept_entry);
828 } else if (*p == '='){
829 if (*(p+1) == '+'){
830 /* Combined adding and default */
831 p = test_line (edit_widget, p + 1, &accept_entry);
832 if (selected == 0 && accept_entry)
833 selected = menu_lines;
834 } else {
835 /* A condition for making the entry default */
836 i = 1;
837 p = test_line (edit_widget, p, &i);
838 if (selected == 0 && i)
839 selected = menu_lines;
842 else if (*p != ' ' && *p != '\t' && str_isprint (p)) {
843 /* A menu entry title line */
844 if (accept_entry)
845 entries [menu_lines] = p;
846 else
847 accept_entry = 1;
850 if (*p == '\n'){
851 if (entries [menu_lines]){
852 menu_lines++;
853 accept_entry = 1;
855 max_cols = max (max_cols, col);
856 col = 0;
857 } else {
858 if (*p == '\t')
859 *p = ' ';
860 col++;
864 if (menu_lines == 0)
865 message (D_ERROR, MSG_ERROR, _(" No suitable entries found in %s "), menu);
866 else {
867 max_cols = min (max (max_cols, col), MAX_ENTRY_LEN);
869 /* Create listbox */
870 listbox = create_listbox_window (menu_lines, max_cols + 2,_(" User menu "),
871 "[Menu File Edit]");
872 /* insert all the items found */
873 for (i = 0; i < menu_lines; i++) {
874 p = entries [i];
875 LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0],
876 extract_line (p, p + MAX_ENTRY_LEN), p);
878 /* Select the default entry */
879 listbox_select_by_number (listbox->list, selected);
881 selected = run_listbox (listbox);
882 if (selected >= 0)
883 execute_menu_command (edit_widget, entries [selected]);
885 do_refresh ();
888 easy_patterns = old_patterns;
889 g_free (menu);
890 menu = NULL;
891 g_free (entries);
892 g_free (data);