Ticket #1648: implemented single-line boxes.
[kaloumi3.git] / src / user.c
blobf7444c6139b5a0366b02dc034bc882f47ee217d3
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 check_format_view (const char *p)
90 const char *q = p;
91 if (!strncmp (p, "view", 4)) {
92 q += 4;
93 if (*q == '{'){
94 for (q++;*q && *q != '}';q++) {
95 if (!strncmp (q, "ascii", 5)) {
96 mcview_default_hex_mode = 0;
97 q += 4;
98 } else if (!strncmp (q, "hex", 3)) {
99 mcview_default_hex_mode = 1;
100 q += 2;
101 } else if (!strncmp (q, "nroff", 5)) {
102 mcview_default_nroff_flag = 1;
103 q += 4;
104 } else if (!strncmp (q, "unform", 6)) {
105 mcview_default_nroff_flag = 0;
106 q += 5;
109 if (*q == '}')
110 q++;
112 return q - p;
114 return 0;
117 int check_format_cd (const char *p)
119 return (strncmp (p, "cd", 2)) ? 0 : 3;
122 /* Check if p has a "^var\{var-name\}" */
123 /* Returns the number of skipped characters (zero on not found) */
124 /* V will be set to the expanded variable name */
125 int check_format_var (const char *p, char **v)
127 const char *q = p;
128 char *var_name;
129 const char *value;
130 const char *dots = 0;
132 *v = 0;
133 if (!strncmp (p, "var{", 4)){
134 for (q += 4; *q && *q != '}'; q++){
135 if (*q == ':')
136 dots = q+1;
138 if (!*q)
139 return 0;
141 if (!dots || dots == q+5){
142 message (D_ERROR,
143 _(" Format error on file Extensions File "),
144 !dots ? _(" The %%var macro has no default ")
145 : _(" The %%var macro has no variable "));
146 return 0;
149 /* Copy the variable name */
150 var_name = g_strndup (p + 4, dots-2 - (p+3));
152 value = getenv (var_name);
153 g_free (var_name);
154 if (value){
155 *v = g_strdup (value);
156 return q-p;
158 var_name = g_strndup (dots, q - dots);
159 *v = var_name;
160 return q-p;
162 return 0;
165 /* strip file's extension */
166 static char *
167 strip_ext(char *ss)
169 register char *s = ss;
170 char *e = NULL;
171 while(*s) {
172 if(*s == '.') e = s;
173 if(*s == PATH_SEP && e) e=NULL; /* '.' in *directory* name */
174 s++;
176 if(e) *e = 0;
177 return ss;
180 char *
181 expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
183 WPanel *panel = NULL;
184 char *(*quote_func) (const char *, int);
185 char *fname = NULL;
186 char *result;
187 char c_lc;
189 #ifndef USE_INTERNAL_EDIT
190 (void) edit_widget;
191 #endif
193 if (c == '%')
194 return g_strdup ("%");
196 if (edit_one_file == NULL) {
197 if (g_ascii_islower ((gchar) c))
198 panel = current_panel;
199 else {
200 if (get_other_type () != view_listing)
201 return g_strdup ("");
202 panel = other_panel;
204 fname = panel->dir.list[panel->selected].fname;
206 #ifdef USE_INTERNAL_EDIT
207 else
208 fname = str_unconst (edit_get_file_name (edit_widget));
209 #endif
211 if (do_quote)
212 quote_func = name_quote;
213 else
214 quote_func = fake_name_quote;
216 c_lc = g_ascii_tolower ((gchar) c);
218 switch (c_lc) {
219 case 'f':
220 case 'p':
221 return (*quote_func) (fname, 0);
222 case 'x':
223 return (*quote_func) (extension (fname), 0);
224 case 'd':
226 char *cwd;
227 char *qstr;
229 cwd = g_malloc(MC_MAXPATHLEN + 1);
231 if (panel)
232 g_strlcpy(cwd, panel->cwd, MC_MAXPATHLEN + 1);
233 else
234 mc_get_current_wd(cwd, MC_MAXPATHLEN + 1);
236 qstr = (*quote_func) (cwd, 0);
238 g_free (cwd);
240 return qstr;
242 case 'i': /* indent equal number cursor position in line */
243 #ifdef USE_INTERNAL_EDIT
244 if (edit_widget)
245 return g_strnfill (edit_get_curs_col (edit_widget), ' ');
246 #endif
247 break;
248 case 'y': /* syntax type */
249 #ifdef USE_INTERNAL_EDIT
250 if (edit_widget) {
251 const char *syntax_type = edit_get_syntax_type (edit_widget);
252 if (syntax_type != NULL)
253 return g_strdup (syntax_type);
255 #endif
256 break;
257 case 'k': /* block file name */
258 case 'b': /* block file name / strip extension */ {
259 #ifdef USE_INTERNAL_EDIT
260 if (edit_widget) {
261 char *file = concat_dir_and_file (home_dir, EDIT_BLOCK_FILE);
262 fname = (*quote_func) (file, 0);
263 g_free (file);
264 return fname;
266 #endif
267 if (c_lc == 'b')
268 return strip_ext ((*quote_func) (fname, 0));
269 break;
271 case 'n': /* strip extension in editor */
272 #ifdef USE_INTERNAL_EDIT
273 if (edit_widget)
274 return strip_ext ((*quote_func) (fname, 0));
275 #endif
276 break;
277 case 'm': /* menu file name */
278 if (menu)
279 return (*quote_func) (menu, 0);
280 break;
281 case 's':
282 if (!panel || !panel->marked)
283 return (*quote_func) (fname, 0);
285 /* Fall through */
287 case 't':
288 case 'u':
290 int length = 2, i;
291 char *block, *tmp;
293 if (!panel)
294 return g_strdup ("");
296 for (i = 0; i < panel->count; i++)
297 if (panel->dir.list[i].f.marked)
298 length += strlen (panel->dir.list[i].fname) + 1; /* for space */
300 block = g_malloc (length * 2 + 1);
301 *block = 0;
302 for (i = 0; i < panel->count; i++)
303 if (panel->dir.list[i].f.marked) {
304 strcat (block, tmp =
305 (*quote_func) (panel->dir.list[i].fname, 0));
306 g_free (tmp);
307 strcat (block, " ");
308 if (c_lc == 'u')
309 do_file_mark (panel, i, 0);
311 return block;
312 } /* sub case block */
313 } /* switch */
314 result = g_strdup ("% ");
315 result[1] = c;
316 return result;
320 * Check for the "shell_patterns" directive. If it's found and valid,
321 * interpret it and move the pointer past the directive. Return the
322 * current pointer.
324 static char *
325 check_patterns (char *p)
327 static const char def_name[] = "shell_patterns=";
328 char *p0 = p;
330 if (strncmp (p, def_name, sizeof (def_name) - 1) != 0)
331 return p0;
333 p += sizeof (def_name) - 1;
334 if (*p == '1')
335 easy_patterns = 1;
336 else if (*p == '0')
337 easy_patterns = 0;
338 else
339 return p0;
341 /* Skip spaces */
342 p++;
343 while (*p == '\n' || *p == '\t' || *p == ' ')
344 p++;
345 return p;
348 /* Copies a whitespace separated argument from p to arg. Returns the
349 point after argument. */
350 static char *extract_arg (char *p, char *arg, int size)
352 char *np;
354 while (*p && (*p == ' ' || *p == '\t' || *p == '\n'))
355 p++;
356 /* support quote space .mnu */
357 while (*p && (*p != ' ' || *(p-1) == '\\') && *p != '\t' && *p != '\n') {
358 np = str_get_next_char (p);
359 if (np - p >= size) break;
360 memcpy (arg, p, np - p);
361 arg+= np - p;
362 size-= np - p;
363 p = np;
365 *arg = 0;
366 if (!*p || *p == '\n')
367 str_prev_char (&p);
368 return p;
371 /* Tests whether the selected file in the panel is of any of the types
372 specified in argument. */
373 static int test_type (WPanel *panel, char *arg)
375 int result = 0; /* False by default */
376 int st_mode = panel->dir.list [panel->selected].st.st_mode;
378 for (;*arg != 0; arg++){
379 switch (*arg){
380 case 'n': /* Not a directory */
381 result |= !S_ISDIR (st_mode);
382 break;
383 case 'r': /* Regular file */
384 result |= S_ISREG (st_mode);
385 break;
386 case 'd': /* Directory */
387 result |= S_ISDIR (st_mode);
388 break;
389 case 'l': /* Link */
390 result |= S_ISLNK (st_mode);
391 break;
392 case 'c': /* Character special */
393 result |= S_ISCHR (st_mode);
394 break;
395 case 'b': /* Block special */
396 result |= S_ISBLK (st_mode);
397 break;
398 case 'f': /* Fifo (named pipe) */
399 result |= S_ISFIFO (st_mode);
400 break;
401 case 's': /* Socket */
402 result |= S_ISSOCK (st_mode);
403 break;
404 case 'x': /* Executable */
405 result |= (st_mode & 0111) ? 1 : 0;
406 break;
407 case 't':
408 result |= panel->marked ? 1 : 0;
409 break;
410 default:
411 debug_error = 1;
412 break;
415 return result;
418 /* Calculates the truth value of the next condition starting from
419 p. Returns the point after condition. */
420 static char *
421 test_condition (WEdit *edit_widget, char *p, int *condition)
423 WPanel *panel;
424 char arg [256];
425 mc_search_type_t search_type;
427 if (easy_patterns) {
428 search_type = MC_SEARCH_T_GLOB;
429 } else {
430 search_type = MC_SEARCH_T_REGEX;
433 /* Handle one condition */
434 for (;*p != '\n' && *p != '&' && *p != '|'; p++){
435 /* support quote space .mnu */
436 if ((*p == ' ' && *(p-1) != '\\') || *p == '\t')
437 continue;
438 if (*p >= 'a')
439 panel = current_panel;
440 else {
441 if (get_other_type () == view_listing)
442 panel = other_panel;
443 else
444 panel = NULL;
446 *p |= 0x20;
448 switch (*p++){
449 case '!':
450 p = test_condition (edit_widget, p, condition);
451 *condition = ! *condition;
452 str_prev_char (&p);
453 break;
454 case 'f': /* file name pattern */
455 p = extract_arg (p, arg, sizeof (arg));
456 *condition = panel && mc_search (arg, panel->dir.list [panel->selected].fname, search_type);
457 break;
458 case 'y': /* syntax pattern */
459 #ifdef USE_INTERNAL_EDIT
460 if (edit_widget) {
461 const char *syntax_type = edit_get_syntax_type (edit_widget);
462 if (syntax_type != NULL) {
463 p = extract_arg (p, arg, sizeof (arg));
464 *condition = panel && mc_search (arg, syntax_type, MC_SEARCH_T_NORMAL);
467 #endif
468 break;
469 case 'd':
470 p = extract_arg (p, arg, sizeof (arg));
471 *condition = panel && mc_search (arg, panel->cwd, search_type);
472 break;
473 case 't':
474 p = extract_arg (p, arg, sizeof (arg));
475 *condition = panel && test_type (panel, arg);
476 break;
477 case 'x': /* executable */
479 struct stat status;
481 p = extract_arg (p, arg, sizeof (arg));
482 if (stat (arg, &status) == 0)
483 *condition = is_exe (status.st_mode);
484 else
485 *condition = 0;
486 break;
488 default:
489 debug_error = 1;
490 break;
491 } /* switch */
493 } /* while */
494 return p;
497 /* General purpose condition debug output handler */
498 static void
499 debug_out (char *start, char *end, int cond)
501 static char *msg;
502 int len;
504 if (start == NULL && end == NULL){
505 /* Show output */
506 if (debug_flag && msg) {
507 len = strlen (msg);
508 if (len)
509 msg [len - 1] = 0;
510 message (D_NORMAL, _(" Debug "), "%s", msg);
513 debug_flag = 0;
514 g_free (msg);
515 msg = NULL;
516 } else {
517 const char *type;
518 char *p;
520 /* Save debug info for later output */
521 if (!debug_flag)
522 return;
523 /* Save the result of the condition */
524 if (debug_error){
525 type = _(" ERROR: ");
526 debug_error = 0;
528 else if (cond)
529 type = _(" True: ");
530 else
531 type = _(" False: ");
532 /* This is for debugging, don't need to be super efficient. */
533 if (end == NULL)
534 p = g_strdup_printf ("%s%s%c \n", msg ? msg : "", type, *start);
535 else
536 p = g_strdup_printf ("%s%s%.*s \n", msg ? msg : "", type,
537 (int) (end - start), start);
538 g_free (msg);
539 msg = p;
543 /* Calculates the truth value of one lineful of conditions. Returns
544 the point just before the end of line. */
545 static char *
546 test_line (WEdit *edit_widget, char *p, int *result)
548 int condition;
549 char operator;
550 char *debug_start, *debug_end;
552 /* Repeat till end of line */
553 while (*p && *p != '\n') {
554 /* support quote space .mnu */
555 while ((*p == ' ' && *(p-1) != '\\' ) || *p == '\t')
556 p++;
557 if (!*p || *p == '\n')
558 break;
559 operator = *p++;
560 if (*p == '?'){
561 debug_flag = 1;
562 p++;
564 /* support quote space .mnu */
565 while ((*p == ' ' && *(p-1) != '\\' ) || *p == '\t')
566 p++;
567 if (!*p || *p == '\n')
568 break;
569 condition = 1; /* True by default */
571 debug_start = p;
572 p = test_condition (edit_widget, p, &condition);
573 debug_end = p;
574 /* Add one debug statement */
575 debug_out (debug_start, debug_end, condition);
577 switch (operator){
578 case '+':
579 case '=':
580 /* Assignment */
581 *result = condition;
582 break;
583 case '&': /* Logical and */
584 *result &= condition;
585 break;
586 case '|': /* Logical or */
587 *result |= condition;
588 break;
589 default:
590 debug_error = 1;
591 break;
592 } /* switch */
593 /* Add one debug statement */
594 debug_out (&operator, NULL, *result);
596 } /* while (*p != '\n') */
597 /* Report debug message */
598 debug_out (NULL, NULL, 1);
600 if (!*p || *p == '\n')
601 str_prev_char (&p);
602 return p;
605 /* FIXME: recode this routine on version 3.0, it could be cleaner */
606 static void
607 execute_menu_command (WEdit *edit_widget, const char *commands)
609 FILE *cmd_file;
610 int cmd_file_fd;
611 int expand_prefix_found = 0;
612 char *parameter = 0;
613 gboolean do_quote = FALSE;
614 char lc_prompt [80];
615 int col;
616 char *file_name;
617 int run_view = 0;
619 /* Skip menu entry title line */
620 commands = strchr (commands, '\n');
621 if (!commands){
622 return;
625 cmd_file_fd = mc_mkstemps (&file_name, "mcusr", SCRIPT_SUFFIX);
627 if (cmd_file_fd == -1){
628 message (D_ERROR, MSG_ERROR, _(" Cannot create temporary command file \n %s "),
629 unix_error_string (errno));
630 return;
632 cmd_file = fdopen (cmd_file_fd, "w");
633 fputs ("#! /bin/sh\n", cmd_file);
634 commands++;
636 for (col = 0; *commands; commands++){
637 if (col == 0) {
638 if (*commands != ' ' && *commands != '\t')
639 break;
640 while (*commands == ' ' || *commands == '\t')
641 commands++;
642 if (*commands == 0)
643 break;
645 col++;
646 if (*commands == '\n')
647 col = 0;
648 if (parameter){
649 if (*commands == '}'){
650 char *tmp;
651 *parameter = 0;
652 parameter = input_dialog (_(" Parameter "), lc_prompt, MC_HISTORY_FM_MENU_EXEC_PARAM, "");
653 if (!parameter || !*parameter){
654 /* User canceled */
655 fclose (cmd_file);
656 unlink (file_name);
657 g_free (file_name);
658 return;
660 if (do_quote) {
661 tmp = name_quote (parameter, 0);
662 fputs (tmp, cmd_file);
663 g_free (tmp);
664 } else
665 fputs (parameter, cmd_file);
666 g_free (parameter);
667 parameter = 0;
668 } else {
669 if (parameter < &lc_prompt [sizeof (lc_prompt) - 1]) {
670 *parameter++ = *commands;
673 } else if (expand_prefix_found){
674 expand_prefix_found = 0;
675 if (g_ascii_isdigit ((gchar) *commands)) {
676 do_quote = (atoi (commands) != 0);
677 while (g_ascii_isdigit ((gchar) *commands))
678 commands++;
680 if (*commands == '{')
681 parameter = lc_prompt;
682 else{
683 char *text = expand_format (edit_widget, *commands, do_quote);
684 fputs (text, cmd_file);
685 g_free (text);
687 } else {
688 if (*commands == '%') {
689 int i = check_format_view (commands + 1);
690 if (i) {
691 commands += i;
692 run_view = 1;
693 } else {
694 do_quote = TRUE; /* Default: Quote expanded macro */
695 expand_prefix_found = 1;
697 } else
698 fputc (*commands, cmd_file);
701 fclose (cmd_file);
702 chmod (file_name, S_IRWXU);
703 if (run_view) {
704 run_view = 0;
705 mcview_viewer (file_name, NULL, &run_view, 0);
706 } else {
707 /* execute the command indirectly to allow execution even
708 * on no-exec filesystems. */
709 char *cmd = g_strconcat("/bin/sh ", file_name, (char *) NULL);
710 shell_execute (cmd, EXECUTE_HIDE);
711 g_free(cmd);
713 unlink (file_name);
714 g_free (file_name);
718 ** Check owner of the menu file. Using menu file is allowed, if
719 ** owner of the menu is root or the actual user. In either case
720 ** file should not be group and word-writable.
722 ** Q. Should we apply this routine to system and home menu (and .ext files)?
724 static int
725 menu_file_own(char* path)
727 struct stat st;
729 if (stat (path, &st) == 0
730 && (!st.st_uid || (st.st_uid == geteuid ()))
731 && ((st.st_mode & (S_IWGRP | S_IWOTH)) == 0)
733 return 1;
735 if (verbose)
737 message (D_NORMAL, _(" Warning -- ignoring file "),
738 _("File %s is not owned by root or you or is world writable.\n"
739 "Using it may compromise your security"),
740 path
743 return 0;
747 * If edit_widget is NULL then we are called from the mc menu,
748 * otherwise we are called from the mcedit menu.
750 void
751 user_menu_cmd (struct WEdit *edit_widget)
753 char *p;
754 char *data, **entries;
755 int max_cols, menu_lines, menu_limit;
756 int col, i, accept_entry = 1;
757 int selected, old_patterns;
758 Listbox *listbox;
760 if (!vfs_current_is_local ()){
761 message (D_ERROR, MSG_ERROR,
762 _(" Cannot execute commands on non-local filesystems"));
763 return;
766 menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU);
767 if (!exist_file (menu) || !menu_file_own (menu)){
768 g_free (menu);
769 if (edit_widget)
770 menu = concat_dir_and_file (home_dir, EDIT_HOME_MENU);
771 else
772 menu = g_build_filename (home_dir, MC_USERCONF_DIR, MC_USERMENU_FILE, NULL);
775 if (!exist_file (menu)){
776 g_free (menu);
777 menu = concat_dir_and_file
778 (mc_home, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
779 if (!exist_file (menu)) {
780 g_free (menu);
781 menu = concat_dir_and_file
782 (mc_home_alt, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
787 if ((data = load_file (menu)) == NULL){
788 message (D_ERROR, MSG_ERROR, _(" Cannot open file %s \n %s "),
789 menu, unix_error_string (errno));
790 g_free (menu);
791 menu = NULL;
792 return;
795 max_cols = 0;
796 selected = 0;
797 menu_limit = 0;
798 entries = 0;
800 /* Parse the menu file */
801 old_patterns = easy_patterns;
802 p = check_patterns (data);
803 for (menu_lines = col = 0; *p; str_next_char (&p)){
804 if (menu_lines >= menu_limit){
805 char ** new_entries;
807 menu_limit += MAX_ENTRIES;
808 new_entries = g_try_realloc (entries, sizeof (new_entries[0]) * menu_limit);
810 if (new_entries == NULL)
811 break;
813 entries = new_entries;
814 new_entries += menu_limit;
815 while (--new_entries >= &entries[menu_lines])
816 *new_entries = NULL;
818 if (col == 0 && !entries [menu_lines]){
819 if (*p == '#'){
820 /* A commented menu entry */
821 accept_entry = 1;
822 } else if (*p == '+'){
823 if (*(p+1) == '='){
824 /* Combined adding and default */
825 p = test_line (edit_widget, p + 1, &accept_entry);
826 if (selected == 0 && accept_entry)
827 selected = menu_lines;
828 } else {
829 /* A condition for adding the entry */
830 p = test_line (edit_widget, p, &accept_entry);
832 } else if (*p == '='){
833 if (*(p+1) == '+'){
834 /* Combined adding and default */
835 p = test_line (edit_widget, p + 1, &accept_entry);
836 if (selected == 0 && accept_entry)
837 selected = menu_lines;
838 } else {
839 /* A condition for making the entry default */
840 i = 1;
841 p = test_line (edit_widget, p, &i);
842 if (selected == 0 && i)
843 selected = menu_lines;
846 else if (*p != ' ' && *p != '\t' && str_isprint (p)) {
847 /* A menu entry title line */
848 if (accept_entry)
849 entries [menu_lines] = p;
850 else
851 accept_entry = 1;
854 if (*p == '\n'){
855 if (entries [menu_lines]){
856 menu_lines++;
857 accept_entry = 1;
859 max_cols = max (max_cols, col);
860 col = 0;
861 } else {
862 if (*p == '\t')
863 *p = ' ';
864 col++;
868 if (menu_lines == 0)
869 message (D_ERROR, MSG_ERROR, _(" No suitable entries found in %s "), menu);
870 else {
871 max_cols = min (max (max_cols, col), MAX_ENTRY_LEN);
873 /* Create listbox */
874 listbox = create_listbox_window (menu_lines, max_cols + 2,_(" User menu "),
875 "[Menu File Edit]");
876 /* insert all the items found */
877 for (i = 0; i < menu_lines; i++) {
878 p = entries [i];
879 LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0],
880 extract_line (p, p + MAX_ENTRY_LEN), p);
882 /* Select the default entry */
883 listbox_select_entry (listbox->list, selected);
885 selected = run_listbox (listbox);
886 if (selected >= 0)
887 execute_menu_command (edit_widget, entries [selected]);
889 do_refresh ();
892 easy_patterns = old_patterns;
893 g_free (menu);
894 menu = NULL;
895 g_free (entries);
896 g_free (data);