Changes for build after moving util.[ch]
[midnight-commander.git] / src / user.c
blobf4d1489d0142900f1bc2ac91c861b88288ebdbc1
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/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 "lib/search/search.h"
45 #include "lib/vfs/mc-vfs/vfs.h"
47 #include "src/editor/edit.h" /* WEdit, BLOCK_FILE */
49 /* For the simple listbox manager */
50 #include "dialog.h"
51 #include "widget.h"
52 #include "wtools.h"
53 #include "src/viewer/mcviewer.h" /* for default_* externs */
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 check_format_view (const char *p)
89 const char *q = p;
90 if (!strncmp (p, "view", 4)) {
91 q += 4;
92 if (*q == '{'){
93 for (q++;*q && *q != '}';q++) {
94 if (!strncmp (q, "ascii", 5)) {
95 mcview_default_hex_mode = 0;
96 q += 4;
97 } else if (!strncmp (q, "hex", 3)) {
98 mcview_default_hex_mode = 1;
99 q += 2;
100 } else if (!strncmp (q, "nroff", 5)) {
101 mcview_default_nroff_flag = 1;
102 q += 4;
103 } else if (!strncmp (q, "unform", 6)) {
104 mcview_default_nroff_flag = 0;
105 q += 5;
108 if (*q == '}')
109 q++;
111 return q - p;
113 return 0;
116 int check_format_cd (const char *p)
118 return (strncmp (p, "cd", 2)) ? 0 : 3;
121 /* Check if p has a "^var\{var-name\}" */
122 /* Returns the number of skipped characters (zero on not found) */
123 /* V will be set to the expanded variable name */
124 int check_format_var (const char *p, char **v)
126 const char *q = p;
127 char *var_name;
128 const char *value;
129 const char *dots = 0;
131 *v = 0;
132 if (!strncmp (p, "var{", 4)){
133 for (q += 4; *q && *q != '}'; q++){
134 if (*q == ':')
135 dots = q+1;
137 if (!*q)
138 return 0;
140 if (!dots || dots == q+5){
141 message (D_ERROR,
142 _(" Format error on file Extensions File "),
143 !dots ? _(" The %%var macro has no default ")
144 : _(" The %%var macro has no variable "));
145 return 0;
148 /* Copy the variable name */
149 var_name = g_strndup (p + 4, dots-2 - (p+3));
151 value = getenv (var_name);
152 g_free (var_name);
153 if (value){
154 *v = g_strdup (value);
155 return q-p;
157 var_name = g_strndup (dots, q - dots);
158 *v = var_name;
159 return q-p;
161 return 0;
164 /* strip file's extension */
165 static char *
166 strip_ext(char *ss)
168 register char *s = ss;
169 char *e = NULL;
170 while(*s) {
171 if(*s == '.') e = s;
172 if(*s == PATH_SEP && e) e=NULL; /* '.' in *directory* name */
173 s++;
175 if(e) *e = 0;
176 return ss;
179 char *
180 expand_format (WEdit *edit_widget, char c, int lc_quote)
182 WPanel *panel = NULL;
183 char *(*quote_func) (const char *, int);
184 char *fname = NULL;
185 char *result;
186 char c_lc;
188 #ifndef USE_INTERNAL_EDIT
189 (void) edit_widget;
190 #endif
192 if (c == '%')
193 return g_strdup ("%");
195 if (edit_one_file == NULL) {
196 if (g_ascii_islower ((gchar) c))
197 panel = current_panel;
198 else {
199 if (get_other_type () != view_listing)
200 return g_strdup ("");
201 panel = other_panel;
203 fname = panel->dir.list[panel->selected].fname;
205 #ifdef USE_INTERNAL_EDIT
206 else
207 fname = str_unconst (edit_get_file_name (edit_widget));
208 #endif
210 if (lc_quote)
211 quote_func = name_quote;
212 else
213 quote_func = fake_name_quote;
215 c_lc = g_ascii_tolower ((gchar) c);
217 switch (c_lc) {
218 case 'f':
219 case 'p':
220 return (*quote_func) (fname, 0);
221 case 'x':
222 return (*quote_func) (extension (fname), 0);
223 case 'd':
225 char *cwd;
226 char *qstr;
228 cwd = g_malloc(MC_MAXPATHLEN + 1);
230 if (panel)
231 g_strlcpy(cwd, panel->cwd, MC_MAXPATHLEN + 1);
232 else
233 mc_get_current_wd(cwd, MC_MAXPATHLEN + 1);
235 qstr = (*quote_func) (cwd, 0);
237 g_free (cwd);
239 return qstr;
241 case 'i': /* indent equal number cursor position in line */
242 #ifdef USE_INTERNAL_EDIT
243 if (edit_widget)
244 return g_strnfill (edit_get_curs_col (edit_widget), ' ');
245 #endif
246 break;
247 case 'y': /* syntax type */
248 #ifdef USE_INTERNAL_EDIT
249 if (edit_widget) {
250 const char *syntax_type = edit_get_syntax_type (edit_widget);
251 if (syntax_type != NULL)
252 return g_strdup (syntax_type);
254 #endif
255 break;
256 case 'k': /* block file name */
257 case 'b': /* block file name / strip extension */ {
258 #ifdef USE_INTERNAL_EDIT
259 if (edit_widget) {
260 char *file = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE);
261 fname = (*quote_func) (file, 0);
262 g_free (file);
263 return fname;
265 #endif
266 if (c_lc == 'b')
267 return strip_ext ((*quote_func) (fname, 0));
268 break;
270 case 'n': /* strip extension in editor */
271 #ifdef USE_INTERNAL_EDIT
272 if (edit_widget)
273 return strip_ext ((*quote_func) (fname, 0));
274 #endif
275 break;
276 case 'm': /* menu file name */
277 if (menu)
278 return (*quote_func) (menu, 0);
279 break;
280 case 's':
281 if (!panel || !panel->marked)
282 return (*quote_func) (fname, 0);
284 /* Fall through */
286 case 't':
287 case 'u':
289 int length = 2, i;
290 char *block, *tmp;
292 if (!panel)
293 return g_strdup ("");
295 for (i = 0; i < panel->count; i++)
296 if (panel->dir.list[i].f.marked)
297 length += strlen (panel->dir.list[i].fname) + 1; /* for space */
299 block = g_malloc (length * 2 + 1);
300 *block = 0;
301 for (i = 0; i < panel->count; i++)
302 if (panel->dir.list[i].f.marked) {
303 strcat (block, tmp =
304 (*quote_func) (panel->dir.list[i].fname, 0));
305 g_free (tmp);
306 strcat (block, " ");
307 if (c_lc == 'u')
308 do_file_mark (panel, i, 0);
310 return block;
311 } /* sub case block */
312 } /* switch */
313 result = g_strdup ("% ");
314 result[1] = c;
315 return result;
319 * Check for the "shell_patterns" directive. If it's found and valid,
320 * interpret it and move the pointer past the directive. Return the
321 * current pointer.
323 static char *
324 check_patterns (char *p)
326 static const char def_name[] = "shell_patterns=";
327 char *p0 = p;
329 if (strncmp (p, def_name, sizeof (def_name) - 1) != 0)
330 return p0;
332 p += sizeof (def_name) - 1;
333 if (*p == '1')
334 easy_patterns = 1;
335 else if (*p == '0')
336 easy_patterns = 0;
337 else
338 return p0;
340 /* Skip spaces */
341 p++;
342 while (*p == '\n' || *p == '\t' || *p == ' ')
343 p++;
344 return p;
347 /* Copies a whitespace separated argument from p to arg. Returns the
348 point after argument. */
349 static char *extract_arg (char *p, char *arg, int size)
351 char *np;
353 while (*p && (*p == ' ' || *p == '\t' || *p == '\n'))
354 p++;
355 /* support quote space .mnu */
356 while (*p && (*p != ' ' || *(p-1) == '\\') && *p != '\t' && *p != '\n') {
357 np = str_get_next_char (p);
358 if (np - p >= size) break;
359 memcpy (arg, p, np - p);
360 arg+= np - p;
361 size-= np - p;
362 p = np;
364 *arg = 0;
365 if (!*p || *p == '\n')
366 str_prev_char (&p);
367 return p;
370 /* Tests whether the selected file in the panel is of any of the types
371 specified in argument. */
372 static int test_type (WPanel *panel, char *arg)
374 int result = 0; /* False by default */
375 int st_mode = panel->dir.list [panel->selected].st.st_mode;
377 for (;*arg != 0; arg++){
378 switch (*arg){
379 case 'n': /* Not a directory */
380 result |= !S_ISDIR (st_mode);
381 break;
382 case 'r': /* Regular file */
383 result |= S_ISREG (st_mode);
384 break;
385 case 'd': /* Directory */
386 result |= S_ISDIR (st_mode);
387 break;
388 case 'l': /* Link */
389 result |= S_ISLNK (st_mode);
390 break;
391 case 'c': /* Character special */
392 result |= S_ISCHR (st_mode);
393 break;
394 case 'b': /* Block special */
395 result |= S_ISBLK (st_mode);
396 break;
397 case 'f': /* Fifo (named pipe) */
398 result |= S_ISFIFO (st_mode);
399 break;
400 case 's': /* Socket */
401 result |= S_ISSOCK (st_mode);
402 break;
403 case 'x': /* Executable */
404 result |= (st_mode & 0111) ? 1 : 0;
405 break;
406 case 't':
407 result |= panel->marked ? 1 : 0;
408 break;
409 default:
410 debug_error = 1;
411 break;
414 return result;
417 /* Calculates the truth value of the next condition starting from
418 p. Returns the point after condition. */
419 static char *
420 test_condition (WEdit *edit_widget, char *p, int *condition)
422 WPanel *panel;
423 char arg [256];
424 mc_search_type_t search_type;
426 if (easy_patterns) {
427 search_type = MC_SEARCH_T_GLOB;
428 } else {
429 search_type = MC_SEARCH_T_REGEX;
432 /* Handle one condition */
433 for (;*p != '\n' && *p != '&' && *p != '|'; p++){
434 /* support quote space .mnu */
435 if ((*p == ' ' && *(p-1) != '\\') || *p == '\t')
436 continue;
437 if (*p >= 'a')
438 panel = current_panel;
439 else {
440 if (get_other_type () == view_listing)
441 panel = other_panel;
442 else
443 panel = NULL;
445 *p |= 0x20;
447 switch (*p++){
448 case '!':
449 p = test_condition (edit_widget, p, condition);
450 *condition = ! *condition;
451 str_prev_char (&p);
452 break;
453 case 'f': /* file name pattern */
454 p = extract_arg (p, arg, sizeof (arg));
455 *condition = panel && mc_search (arg, panel->dir.list [panel->selected].fname, search_type);
456 break;
457 case 'y': /* syntax pattern */
458 #ifdef USE_INTERNAL_EDIT
459 if (edit_widget) {
460 const char *syntax_type = edit_get_syntax_type (edit_widget);
461 if (syntax_type != NULL) {
462 p = extract_arg (p, arg, sizeof (arg));
463 *condition = panel && mc_search (arg, syntax_type, MC_SEARCH_T_NORMAL);
466 #endif
467 break;
468 case 'd':
469 p = extract_arg (p, arg, sizeof (arg));
470 *condition = panel && mc_search (arg, panel->cwd, search_type);
471 break;
472 case 't':
473 p = extract_arg (p, arg, sizeof (arg));
474 *condition = panel && test_type (panel, arg);
475 break;
476 case 'x': /* executable */
478 struct stat status;
480 p = extract_arg (p, arg, sizeof (arg));
481 if (stat (arg, &status) == 0)
482 *condition = is_exe (status.st_mode);
483 else
484 *condition = 0;
485 break;
487 default:
488 debug_error = 1;
489 break;
490 } /* switch */
492 } /* while */
493 return p;
496 /* General purpose condition debug output handler */
497 static void
498 debug_out (char *start, char *end, int cond)
500 static char *msg;
501 int len;
503 if (start == NULL && end == NULL){
504 /* Show output */
505 if (debug_flag && msg) {
506 len = strlen (msg);
507 if (len)
508 msg [len - 1] = 0;
509 message (D_NORMAL, _(" Debug "), "%s", msg);
512 debug_flag = 0;
513 g_free (msg);
514 msg = NULL;
515 } else {
516 const char *type;
517 char *p;
519 /* Save debug info for later output */
520 if (!debug_flag)
521 return;
522 /* Save the result of the condition */
523 if (debug_error){
524 type = _(" ERROR: ");
525 debug_error = 0;
527 else if (cond)
528 type = _(" True: ");
529 else
530 type = _(" False: ");
531 /* This is for debugging, don't need to be super efficient. */
532 if (end == NULL)
533 p = g_strdup_printf ("%s%s%c \n", msg ? msg : "", type, *start);
534 else
535 p = g_strdup_printf ("%s%s%.*s \n", msg ? msg : "", type,
536 (int) (end - start), start);
537 g_free (msg);
538 msg = p;
542 /* Calculates the truth value of one lineful of conditions. Returns
543 the point just before the end of line. */
544 static char *
545 test_line (WEdit *edit_widget, char *p, int *result)
547 int condition;
548 char operator;
549 char *debug_start, *debug_end;
551 /* Repeat till end of line */
552 while (*p && *p != '\n') {
553 /* support quote space .mnu */
554 while ((*p == ' ' && *(p-1) != '\\' ) || *p == '\t')
555 p++;
556 if (!*p || *p == '\n')
557 break;
558 operator = *p++;
559 if (*p == '?'){
560 debug_flag = 1;
561 p++;
563 /* support quote space .mnu */
564 while ((*p == ' ' && *(p-1) != '\\' ) || *p == '\t')
565 p++;
566 if (!*p || *p == '\n')
567 break;
568 condition = 1; /* True by default */
570 debug_start = p;
571 p = test_condition (edit_widget, p, &condition);
572 debug_end = p;
573 /* Add one debug statement */
574 debug_out (debug_start, debug_end, condition);
576 switch (operator){
577 case '+':
578 case '=':
579 /* Assignment */
580 *result = condition;
581 break;
582 case '&': /* Logical and */
583 *result &= condition;
584 break;
585 case '|': /* Logical or */
586 *result |= condition;
587 break;
588 default:
589 debug_error = 1;
590 break;
591 } /* switch */
592 /* Add one debug statement */
593 debug_out (&operator, NULL, *result);
595 } /* while (*p != '\n') */
596 /* Report debug message */
597 debug_out (NULL, NULL, 1);
599 if (!*p || *p == '\n')
600 str_prev_char (&p);
601 return p;
604 /* FIXME: recode this routine on version 3.0, it could be cleaner */
605 static void
606 execute_menu_command (WEdit *edit_widget, const char *commands)
608 FILE *cmd_file;
609 int cmd_file_fd;
610 int expand_prefix_found = 0;
611 char *parameter = 0;
612 int do_quote = 0;
613 char lc_prompt [80];
614 int col;
615 char *file_name;
616 int run_view = 0;
618 /* Skip menu entry title line */
619 commands = strchr (commands, '\n');
620 if (!commands){
621 return;
624 cmd_file_fd = mc_mkstemps (&file_name, "mcusr", SCRIPT_SUFFIX);
626 if (cmd_file_fd == -1){
627 message (D_ERROR, MSG_ERROR, _(" Cannot create temporary command file \n %s "),
628 unix_error_string (errno));
629 return;
631 cmd_file = fdopen (cmd_file_fd, "w");
632 fputs ("#! /bin/sh\n", cmd_file);
633 commands++;
635 for (col = 0; *commands; commands++){
636 if (col == 0) {
637 if (*commands != ' ' && *commands != '\t')
638 break;
639 while (*commands == ' ' || *commands == '\t')
640 commands++;
641 if (*commands == 0)
642 break;
644 col++;
645 if (*commands == '\n')
646 col = 0;
647 if (parameter){
648 if (*commands == '}'){
649 char *tmp;
650 *parameter = 0;
651 parameter = input_dialog (_(" Parameter "), lc_prompt, MC_HISTORY_FM_MENU_EXEC_PARAM, "");
652 if (!parameter || !*parameter){
653 /* User canceled */
654 fclose (cmd_file);
655 unlink (file_name);
656 g_free (file_name);
657 return;
659 if (do_quote) {
660 fputs (tmp = name_quote (parameter, 0), cmd_file);
661 g_free (tmp);
662 } else
663 fputs (parameter, cmd_file);
664 g_free (parameter);
665 parameter = 0;
666 } else {
667 if (parameter < &lc_prompt [sizeof (lc_prompt) - 1]) {
668 *parameter++ = *commands;
671 } else if (expand_prefix_found){
672 expand_prefix_found = 0;
673 if (g_ascii_isdigit ((gchar) *commands)) {
674 do_quote = atoi (commands);
675 while (g_ascii_isdigit ((gchar) *commands))
676 commands++;
678 if (*commands == '{')
679 parameter = lc_prompt;
680 else{
681 char *text = expand_format (edit_widget, *commands, do_quote);
682 fputs (text, cmd_file);
683 g_free (text);
685 } else {
686 if (*commands == '%') {
687 int i = check_format_view (commands + 1);
688 if (i) {
689 commands += i;
690 run_view = 1;
691 } else {
692 do_quote = 1; /* Default: Quote expanded macro */
693 expand_prefix_found = 1;
695 } else
696 fputc (*commands, cmd_file);
699 fclose (cmd_file);
700 chmod (file_name, S_IRWXU);
701 if (run_view) {
702 run_view = 0;
703 mcview_viewer (file_name, NULL, &run_view, 0);
704 } else {
705 /* execute the command indirectly to allow execution even
706 * on no-exec filesystems. */
707 char *cmd = g_strconcat("/bin/sh ", file_name, (char *) NULL);
708 shell_execute (cmd, EXECUTE_HIDE);
709 g_free(cmd);
711 unlink (file_name);
712 g_free (file_name);
716 ** Check owner of the menu file. Using menu file is allowed, if
717 ** owner of the menu is root or the actual user. In either case
718 ** file should not be group and word-writable.
720 ** Q. Should we apply this routine to system and home menu (and .ext files)?
722 static int
723 menu_file_own(char* path)
725 struct stat st;
727 if (stat (path, &st) == 0
728 && (!st.st_uid || (st.st_uid == geteuid ()))
729 && ((st.st_mode & (S_IWGRP | S_IWOTH)) == 0)
731 return 1;
733 if (verbose)
735 message (D_NORMAL, _(" Warning -- ignoring file "),
736 _("File %s is not owned by root or you or is world writable.\n"
737 "Using it may compromise your security"),
738 path
741 return 0;
745 * If edit_widget is NULL then we are called from the mc menu,
746 * otherwise we are called from the mcedit menu.
748 void
749 user_menu_cmd (WEdit *edit_widget)
751 char *p;
752 char *data, **entries;
753 int max_cols, menu_lines, menu_limit;
754 int col, i, accept_entry = 1;
755 int selected, old_patterns;
756 Listbox *listbox;
758 if (!vfs_current_is_local ()){
759 message (D_ERROR, MSG_ERROR,
760 _(" Cannot execute commands on non-local filesystems"));
761 return;
764 menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU);
765 if (!exist_file (menu) || !menu_file_own (menu)){
766 g_free (menu);
767 if (edit_widget)
768 menu = concat_dir_and_file (home_dir, EDIT_HOME_MENU);
769 else
770 menu = g_build_filename (home_dir, MC_USERCONF_DIR, MC_USERMENU_FILE, NULL);
773 if (!exist_file (menu)){
774 g_free (menu);
775 menu = concat_dir_and_file
776 (mc_home, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
777 if (!exist_file (menu)) {
778 g_free (menu);
779 menu = concat_dir_and_file
780 (mc_home_alt, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
785 if ((data = load_file (menu)) == NULL){
786 message (D_ERROR, MSG_ERROR, _(" Cannot open file %s \n %s "),
787 menu, unix_error_string (errno));
788 g_free (menu);
789 menu = NULL;
790 return;
793 max_cols = 0;
794 selected = 0;
795 menu_limit = 0;
796 entries = 0;
798 /* Parse the menu file */
799 old_patterns = easy_patterns;
800 p = check_patterns (data);
801 for (menu_lines = col = 0; *p; str_next_char (&p)){
802 if (menu_lines >= menu_limit){
803 char ** new_entries;
805 menu_limit += MAX_ENTRIES;
806 new_entries = g_try_realloc (entries, sizeof (new_entries[0]) * menu_limit);
808 if (new_entries == NULL)
809 break;
811 entries = new_entries;
812 new_entries += menu_limit;
813 while (--new_entries >= &entries[menu_lines])
814 *new_entries = NULL;
816 if (col == 0 && !entries [menu_lines]){
817 if (*p == '#'){
818 /* A commented menu entry */
819 accept_entry = 1;
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 adding the entry */
828 p = test_line (edit_widget, p, &accept_entry);
830 } else if (*p == '='){
831 if (*(p+1) == '+'){
832 /* Combined adding and default */
833 p = test_line (edit_widget, p + 1, &accept_entry);
834 if (selected == 0 && accept_entry)
835 selected = menu_lines;
836 } else {
837 /* A condition for making the entry default */
838 i = 1;
839 p = test_line (edit_widget, p, &i);
840 if (selected == 0 && i)
841 selected = menu_lines;
844 else if (*p != ' ' && *p != '\t' && str_isprint (p)) {
845 /* A menu entry title line */
846 if (accept_entry)
847 entries [menu_lines] = p;
848 else
849 accept_entry = 1;
852 if (*p == '\n'){
853 if (entries [menu_lines]){
854 menu_lines++;
855 accept_entry = 1;
857 max_cols = max (max_cols, col);
858 col = 0;
859 } else {
860 if (*p == '\t')
861 *p = ' ';
862 col++;
866 if (menu_lines == 0)
867 message (D_ERROR, MSG_ERROR, _(" No suitable entries found in %s "), menu);
868 else {
869 max_cols = min (max (max_cols, col), MAX_ENTRY_LEN);
871 /* Create listbox */
872 listbox = create_listbox_window (menu_lines, max_cols + 2,_(" User menu "),
873 "[Menu File Edit]");
874 /* insert all the items found */
875 for (i = 0; i < menu_lines; i++) {
876 p = entries [i];
877 LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0],
878 extract_line (p, p + MAX_ENTRY_LEN), p);
880 /* Select the default entry */
881 listbox_select_by_number (listbox->list, selected);
883 selected = run_listbox (listbox);
884 if (selected >= 0)
885 execute_menu_command (edit_widget, entries [selected]);
887 do_refresh ();
890 easy_patterns = old_patterns;
891 g_free (menu);
892 menu = NULL;
893 g_free (entries);
894 g_free (data);