2 Extension dependent execution.
4 Copyright (C) 1994-2025
5 Free Software Foundation, Inc.
10 Slava Zanko <slavazanko@gmail.com>, 2013
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <https://www.gnu.org/licenses/>.
29 * \brief Source: extension dependent execution
41 #include "lib/global.h"
42 #include "lib/tty/tty.h"
43 #include "lib/search.h"
44 #include "lib/fileloc.h"
45 #include "lib/mcconfig.h"
47 #include "lib/vfs/vfs.h"
48 #include "lib/widget.h"
50 # include "lib/charsets.h" // get_codepage_index
54 # include "src/setup.h" // use_file_to_check_type
56 #include "src/execute.h"
57 #include "src/history.h"
58 #include "src/usermenu.h"
60 #include "src/consaver/cons.saver.h"
61 #include "src/viewer/mcviewer.h"
64 # include "src/selcodepage.h" // do_set_codepage
67 #include "filemanager.h" // current_panel
68 #include "panel.h" // panel_cd
72 /*** global variables ****************************************************************************/
74 /*** file scope macro definitions ****************************************************************/
78 # define FILE_CMD "file -z " FILE_B FILE_S FILE_L
80 # define FILE_CMD "file -z " FILE_S FILE_L
84 /*** file scope type declarations ****************************************************************/
86 typedef char *(*quote_func_t
) (const char *name
, gboolean quote_percent
);
88 /*** forward declarations (file scope functions) *************************************************/
90 /*** file scope variables ************************************************************************/
92 /* This variable points to a copy of the mc.ext file in memory
93 * With this we avoid loading/parsing the file each time we
96 static mc_config_t
*ext_ini
= NULL
;
97 static gchar
**ext_ini_groups
= NULL
;
98 static vfs_path_t
*localfilecopy_vpath
= NULL
;
99 static char buffer
[BUF_1K
];
101 static char *pbuffer
= NULL
;
102 static time_t localmtime
= 0;
103 static quote_func_t quote_func
= name_quote
;
104 static gboolean run_view
= FALSE
;
105 static gboolean is_cd
= FALSE
;
106 static gboolean written_nonspace
= FALSE
;
107 static gboolean do_local_copy
= FALSE
;
109 static const char *descr_group
= "mc.ext.ini";
110 static const char *default_group
= "Default";
112 /* --------------------------------------------------------------------------------------------- */
113 /*** file scope functions ************************************************************************/
114 /* --------------------------------------------------------------------------------------------- */
117 exec_cleanup_script (vfs_path_t
*script_vpath
)
119 if (script_vpath
!= NULL
)
121 (void) mc_unlink (script_vpath
);
122 vfs_path_free (script_vpath
, TRUE
);
126 /* --------------------------------------------------------------------------------------------- */
129 exec_cleanup_file_name (const vfs_path_t
*filename_vpath
, gboolean has_changed
)
131 if (localfilecopy_vpath
== NULL
)
138 mc_stat (localfilecopy_vpath
, &mystat
);
139 has_changed
= localmtime
!= mystat
.st_mtime
;
141 mc_ungetlocalcopy (filename_vpath
, localfilecopy_vpath
, has_changed
);
142 vfs_path_free (localfilecopy_vpath
, TRUE
);
143 localfilecopy_vpath
= NULL
;
146 /* --------------------------------------------------------------------------------------------- */
149 exec_get_file_name (const vfs_path_t
*filename_vpath
)
152 return quote_func (vfs_path_get_last_path_str (filename_vpath
), FALSE
);
154 if (localfilecopy_vpath
== NULL
)
157 localfilecopy_vpath
= mc_getlocalcopy (filename_vpath
);
158 if (localfilecopy_vpath
== NULL
)
161 mc_stat (localfilecopy_vpath
, &mystat
);
162 localmtime
= mystat
.st_mtime
;
165 return quote_func (vfs_path_get_last_path_str (localfilecopy_vpath
), FALSE
);
168 /* --------------------------------------------------------------------------------------------- */
171 exec_expand_format (char symbol
, gboolean is_result_quoted
)
175 text
= expand_format (NULL
, symbol
, TRUE
);
176 if (is_result_quoted
&& text
!= NULL
)
180 quoted_text
= g_strdup_printf ("\"%s\"", text
);
187 /* --------------------------------------------------------------------------------------------- */
190 exec_get_export_variables (const vfs_path_t
*filename_vpath
)
193 GString
*export_vars_string
;
200 const gboolean is_result_quoted
;
201 } export_variables
[] = {
202 { 'p', "MC_EXT_BASENAME", FALSE
},
203 { 'd', "MC_EXT_CURRENTDIR", FALSE
},
204 { 's', "MC_EXT_SELECTED", TRUE
},
205 { 't', "MC_EXT_ONLYTAGGED", TRUE
},
206 { '\0', NULL
, FALSE
},
209 text
= exec_get_file_name (filename_vpath
);
213 export_vars_string
= g_string_new ("MC_EXT_FILENAME=");
214 g_string_append_printf (export_vars_string
, "%s\nexport MC_EXT_FILENAME\n", text
);
217 for (i
= 0; export_variables
[i
].name
!= NULL
; i
++)
220 exec_expand_format (export_variables
[i
].symbol
, export_variables
[i
].is_result_quoted
);
223 g_string_append_printf (export_vars_string
, "%s=%s\nexport %s\n",
224 export_variables
[i
].name
, text
, export_variables
[i
].name
);
229 return export_vars_string
;
232 /* --------------------------------------------------------------------------------------------- */
235 exec_make_shell_string (const char *lc_data
, const vfs_path_t
*filename_vpath
)
237 GString
*shell_string
;
238 char lc_prompt
[80] = "\0";
239 gboolean parameter_found
= FALSE
;
240 gboolean expand_prefix_found
= FALSE
;
242 shell_string
= g_string_new ("");
244 for (; *lc_data
!= '\0' && *lc_data
!= '\n'; lc_data
++)
252 parameter_found
= FALSE
;
253 parameter
= input_dialog (_ ("Parameter"), lc_prompt
, MC_HISTORY_EXT_PARAMETER
, "",
254 INPUT_COMPLETE_NONE
);
255 if (parameter
== NULL
)
258 g_string_free (shell_string
, TRUE
);
259 exec_cleanup_file_name (filename_vpath
, FALSE
);
262 g_string_append (shell_string
, parameter
);
263 written_nonspace
= TRUE
;
268 size_t len
= strlen (lc_prompt
);
270 if (len
< sizeof (lc_prompt
) - 1)
272 lc_prompt
[len
] = *lc_data
;
273 lc_prompt
[len
+ 1] = '\0';
277 else if (expand_prefix_found
)
279 expand_prefix_found
= FALSE
;
281 parameter_found
= TRUE
;
286 i
= check_format_view (lc_data
);
294 i
= check_format_cd (lc_data
);
298 quote_func
= fake_name_quote
;
299 do_local_copy
= FALSE
;
307 i
= check_format_var (lc_data
, &v
);
310 g_string_append (shell_string
, v
);
319 text
= expand_format (NULL
, *lc_data
, !is_cd
);
322 text
= exec_get_file_name (filename_vpath
);
325 g_string_free (shell_string
, TRUE
);
333 g_string_append (shell_string
, text
);
336 strcpy (pbuffer
, text
);
337 pbuffer
= strchr (pbuffer
, '\0');
343 written_nonspace
= TRUE
;
349 else if (*lc_data
== '%')
350 expand_prefix_found
= TRUE
;
353 if (!whitespace (*lc_data
))
354 written_nonspace
= TRUE
;
356 *(pbuffer
++) = *lc_data
;
358 g_string_append_c (shell_string
, *lc_data
);
365 /* --------------------------------------------------------------------------------------------- */
368 exec_extension_view (void *target
, char *cmd
, const vfs_path_t
*filename_vpath
, int start_line
)
370 mcview_mode_flags_t def_flags
= {
372 .hex
= mcview_global_flags
.hex
,
374 .nroff
= mcview_global_flags
.nroff
,
377 mcview_mode_flags_t changed_flags
;
379 mcview_clear_mode_flags (&changed_flags
);
380 mcview_altered_flags
.hex
= FALSE
;
381 mcview_altered_flags
.nroff
= FALSE
;
382 if (def_flags
.hex
!= mcview_global_flags
.hex
)
383 changed_flags
.hex
= TRUE
;
384 if (def_flags
.nroff
!= mcview_global_flags
.nroff
)
385 changed_flags
.nroff
= TRUE
;
388 mcview_viewer (cmd
, filename_vpath
, start_line
, 0, 0);
390 mcview_load ((WView
*) target
, cmd
, vfs_path_as_str (filename_vpath
), start_line
, 0, 0);
392 if (changed_flags
.hex
&& !mcview_altered_flags
.hex
)
393 mcview_global_flags
.hex
= def_flags
.hex
;
394 if (changed_flags
.nroff
&& !mcview_altered_flags
.nroff
)
395 mcview_global_flags
.nroff
= def_flags
.nroff
;
397 dialog_switch_process_pending ();
400 /* --------------------------------------------------------------------------------------------- */
403 exec_extension_cd (WPanel
*panel
)
410 /* Search last non-space character. Start search at the end in order
411 not to short filenames containing spaces. */
412 q
= pbuffer
+ strlen (pbuffer
) - 1;
413 while (q
>= pbuffer
&& whitespace (*q
))
417 p_vpath
= vfs_path_from_str_flags (pbuffer
, VPF_NO_CANON
);
418 panel_cd (panel
, p_vpath
, cd_parse_command
);
419 vfs_path_free (p_vpath
, TRUE
);
422 /* --------------------------------------------------------------------------------------------- */
425 exec_extension (WPanel
*panel
, void *target
, const vfs_path_t
*filename_vpath
, const char *lc_data
,
428 GString
*shell_string
, *export_variables
;
429 vfs_path_t
*script_vpath
= NULL
;
436 quote_func
= name_quote
;
439 written_nonspace
= FALSE
;
441 // Avoid making a local copy if we are doing a cd
442 do_local_copy
= !vfs_file_is_local (filename_vpath
);
444 shell_string
= exec_make_shell_string (lc_data
, filename_vpath
);
445 if (shell_string
== NULL
)
450 exec_extension_cd (panel
);
451 g_string_free (shell_string
, TRUE
);
456 * All commands should be run in /bin/sh regardless of user shell.
457 * To do that, create temporary shell script and run it.
458 * Sometimes it's not needed (e.g. for %cd and %view commands),
459 * but it's easier to create it anyway.
461 cmd_file_fd
= mc_mkstemps (&script_vpath
, "mcext", SCRIPT_SUFFIX
);
463 if (cmd_file_fd
== -1)
465 message (D_ERROR
, MSG_ERROR
, _ ("Cannot create temporary command file\n%s"),
466 unix_error_string (errno
));
467 g_string_free (shell_string
, TRUE
);
471 cmd_file
= fdopen (cmd_file_fd
, "w");
472 fputs ("#! /bin/sh\n\n", cmd_file
);
474 export_variables
= exec_get_export_variables (filename_vpath
);
475 if (export_variables
!= NULL
)
477 fputs (export_variables
->str
, cmd_file
);
478 g_string_free (export_variables
, TRUE
);
481 fputs (shell_string
->str
, cmd_file
);
482 g_string_free (shell_string
, TRUE
);
485 * Make the script remove itself when it finishes.
486 * Don't do it for the viewer - it may need to rerun the script,
487 * so we clean up after calling view().
490 fprintf (cmd_file
, "\n/bin/rm -f %s\n", vfs_path_as_str (script_vpath
));
494 if ((run_view
&& !written_nonspace
) || is_cd
)
496 exec_cleanup_script (script_vpath
);
501 // Set executable flag on the command file ...
502 mc_chmod (script_vpath
, S_IRWXU
);
503 // ... but don't rely on it - run /bin/sh explicitly
504 cmd
= g_strconcat ("/bin/sh ", vfs_path_as_str (script_vpath
), (char *) NULL
);
509 // If we've written whitespace only, then just load filename into view
510 if (!written_nonspace
)
511 exec_extension_view (target
, NULL
, filename_vpath
, start_line
);
513 exec_extension_view (target
, cmd
, filename_vpath
, start_line
);
517 shell_execute (cmd
, EXECUTE_INTERNAL
);
518 if (mc_global
.tty
.console_flag
!= '\0')
520 handle_console (CONSOLE_SAVE
);
521 if (output_lines
!= 0 && mc_global
.keybar_visible
)
523 unsigned char end_line
;
525 end_line
= LINES
- (mc_global
.keybar_visible
? 1 : 0) - 1;
526 show_console_contents (output_start_y
, end_line
- output_lines
, end_line
);
533 exec_cleanup_file_name (filename_vpath
, TRUE
);
538 /* --------------------------------------------------------------------------------------------- */
540 * Run cmd_file with args, put result into buf.
541 * If error, put '\0' into buf[0]
542 * Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
544 * NOTES: buf is null-terminated string.
549 get_popen_information (const char *cmd_file
, const char *args
, char *buf
, int buflen
)
551 gboolean read_bytes
= FALSE
;
555 command
= g_strconcat (cmd_file
, args
, " 2>/dev/null", (char *) NULL
);
556 f
= popen (command
, "r");
562 if (setvbuf (f
, NULL
, _IOFBF
, 0) != 0)
568 read_bytes
= (fgets (buf
, buflen
, f
) != NULL
);
570 buf
[0] = '\0'; // Paranoid termination
575 buf
[0] = '\0'; // Paranoid termination
579 buf
[buflen
- 1] = '\0';
581 return read_bytes
? 1 : 0;
584 /* --------------------------------------------------------------------------------------------- */
586 * Run the "file" command on the local file.
587 * Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
591 get_file_type_local (const vfs_path_t
*filename_vpath
, char *buf
, int buflen
)
593 char *filename_quoted
;
596 filename_quoted
= name_quote (vfs_path_get_last_path_str (filename_vpath
), FALSE
);
597 if (filename_quoted
!= NULL
)
599 ret
= get_popen_information (FILE_CMD
, filename_quoted
, buf
, buflen
);
600 g_free (filename_quoted
);
606 /* --------------------------------------------------------------------------------------------- */
608 * Run the "enca" command on the local file.
609 * Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
614 get_file_encoding_local (const vfs_path_t
*filename_vpath
, char *buf
, int buflen
)
616 char *filename_quoted
;
619 filename_quoted
= name_quote (vfs_path_get_last_path_str (filename_vpath
), FALSE
);
620 if (filename_quoted
!= NULL
)
624 lang
= name_quote (autodetect_codeset
, FALSE
);
629 args
= g_strdup_printf (" -L %s -i %s", lang
, filename_quoted
);
632 ret
= get_popen_information ("enca", args
, buf
, buflen
);
636 g_free (filename_quoted
);
643 /* --------------------------------------------------------------------------------------------- */
645 * Invoke the "file" command on the file and match its output against PTR.
646 * have_type is a flag that is set if we already have tried to determine
647 * the type of that file.
648 * Return TRUE for match, FALSE otherwise.
652 regex_check_type (const vfs_path_t
*filename_vpath
, const char *ptr
, gboolean case_insense
,
653 gboolean
*have_type
, GError
**mcerror
)
655 gboolean found
= FALSE
;
657 // Following variables are valid if *have_type is TRUE
658 static char content_string
[2048];
659 static size_t content_shift
= 0;
660 static int got_data
= 0;
662 mc_return_val_if_error (mcerror
, FALSE
);
666 vfs_path_t
*localfile_vpath
;
669 static char encoding_id
[21]; // CSISO51INISCYRILLIC -- 20
670 int got_encoding_data
;
673 // Don't repeate even unsuccessful checks
676 localfile_vpath
= mc_getlocalcopy (filename_vpath
);
677 if (localfile_vpath
== NULL
)
679 mc_propagate_error (mcerror
, 0, _ ("Cannot fetch a local copy of %s"),
680 vfs_path_as_str (filename_vpath
));
685 got_encoding_data
= is_autodetect_codeset_enabled
686 ? get_file_encoding_local (localfile_vpath
, encoding_id
, sizeof (encoding_id
))
689 if (got_encoding_data
> 0)
694 pp
= strchr (encoding_id
, '\n');
698 cp_id
= get_codepage_index (encoding_id
);
700 cp_id
= default_source_codepage
;
702 do_set_codepage (cp_id
);
706 got_data
= get_file_type_local (localfile_vpath
, content_string
, sizeof (content_string
));
708 mc_ungetlocalcopy (filename_vpath
, localfile_vpath
, FALSE
);
714 pp
= strchr (content_string
, '\n');
720 const char *real_name
; // name used with "file"
723 real_name
= vfs_path_get_last_path_str (localfile_vpath
);
724 real_len
= strlen (real_name
);
726 if (strncmp (content_string
, real_name
, real_len
) == 0)
728 // Skip "real_name: "
729 content_shift
= real_len
;
731 // Solaris' file prints tab(s) after ':'
732 if (content_string
[content_shift
] == ':')
733 for (content_shift
++; whitespace (content_string
[content_shift
]);
743 content_string
[0] = '\0';
745 vfs_path_free (localfile_vpath
, TRUE
);
750 mc_propagate_error (mcerror
, 0, "%s", _ ("Pipe failed"));
754 if (content_string
[0] != '\0')
758 search
= mc_search_new (ptr
, DEFAULT_CHARSET
);
761 search
->search_type
= MC_SEARCH_T_REGEX
;
762 search
->is_case_sensitive
= !case_insense
;
763 found
= mc_search_run (search
, content_string
+ content_shift
, 0,
764 sizeof (content_string
) - 1, NULL
);
765 mc_search_free (search
);
769 mc_propagate_error (mcerror
, 0, "%s", _ ("Regular expression error"));
777 /* --------------------------------------------------------------------------------------------- */
780 check_old_extension_file (void)
782 char *extension_old_file
;
784 extension_old_file
= mc_config_get_full_path (MC_EXT_OLD_FILE
);
785 if (exist_file (extension_old_file
))
786 message (D_ERROR
, _ ("Warning"),
787 _ ("You have an outdated %s file.\nMidnight Commander now uses %s file.\n"
788 "Please copy your modifications of the old file to the new one."),
789 extension_old_file
, MC_EXT_FILE
);
790 g_free (extension_old_file
);
793 /* --------------------------------------------------------------------------------------------- */
796 load_extension_file (void)
798 char *extension_file
;
799 gboolean mc_user_ext
= TRUE
;
800 gboolean home_error
= FALSE
;
802 extension_file
= mc_config_get_full_path (MC_EXT_FILE
);
803 if (!exist_file (extension_file
))
805 g_free (extension_file
);
807 check_old_extension_file ();
810 extension_file
= mc_build_filename (mc_global
.sysconfig_dir
, MC_EXT_FILE
, (char *) NULL
);
811 if (!exist_file (extension_file
))
813 g_free (extension_file
);
815 mc_build_filename (mc_global
.share_data_dir
, MC_EXT_FILE
, (char *) NULL
);
816 if (!exist_file (extension_file
))
817 MC_PTR_FREE (extension_file
);
822 if (extension_file
!= NULL
)
824 ext_ini
= mc_config_init (extension_file
, TRUE
);
825 g_free (extension_file
);
831 if (!mc_config_has_group (ext_ini
, descr_group
))
833 flush_extension_file ();
837 message (D_ERROR
, MSG_ERROR
,
838 _ ("The format of the\n%s%s\nfile has changed with version 4.0.\n"
839 "It seems that the installation has failed.\nPlease fetch a fresh copy "
840 "from the Midnight Commander package."),
841 mc_global
.sysconfig_dir
, MC_EXT_FILE
);
846 goto check_stock_mc_ext
;
851 extension_file
= mc_config_get_full_path (MC_EXT_FILE
);
854 _ ("The format of the\n%s\nfile has changed with version 4.0.\nYou may either want "
855 "to copy it from\n%s%s\nor use that file as an example of how to write it."),
856 extension_file
, mc_global
.sysconfig_dir
, MC_EXT_FILE
);
857 g_free (extension_file
);
863 /* --------------------------------------------------------------------------------------------- */
864 /*** public functions ****************************************************************************/
865 /* --------------------------------------------------------------------------------------------- */
868 flush_extension_file (void)
870 g_strfreev (ext_ini_groups
);
871 ext_ini_groups
= NULL
;
873 mc_config_deinit (ext_ini
);
877 /* --------------------------------------------------------------------------------------------- */
879 * The second argument is action, i.e. Open, View or Edit
880 * Use target object to open file in.
882 * This function returns:
884 * -1 for a failure or user interrupt
885 * 0 if no command was run
886 * 1 if some command was run
888 * If action == "View" then a parameter is checked in the form of "View:%d",
889 * if the value for %d exists, then the viewer is started up at that line number.
893 regex_command_for (void *target
, const vfs_path_t
*filename_vpath
, const char *action
,
894 vfs_path_t
**script_vpath
)
896 const char *filename
;
898 gboolean found
= FALSE
;
899 gboolean error_flag
= FALSE
;
902 int view_at_line_number
= 0;
904 gboolean have_type
= FALSE
; // Flag used by regex_check_type()
907 char *include_group
= NULL
;
908 const char *current_group
;
910 if (filename_vpath
== NULL
)
913 if (script_vpath
!= NULL
)
914 *script_vpath
= NULL
;
916 // Check for the special View:%d parameter
917 if (strncmp (action
, "View:", 5) == 0)
919 view_at_line_number
= atoi (action
+ 5);
923 if (ext_ini
== NULL
&& !load_extension_file ())
926 mc_stat (filename_vpath
, &mystat
);
928 filename
= vfs_path_get_last_path_str (filename_vpath
);
929 filename
= x_basename (filename
);
930 filename_len
= strlen (filename
);
932 if (ext_ini_groups
== NULL
)
933 ext_ini_groups
= mc_config_get_groups (ext_ini
, NULL
);
935 // find matched type, regex or shell pattern
936 for (group_iter
= ext_ini_groups
; *group_iter
!= NULL
&& !found
; group_iter
++)
943 } type_state
= TYPE_UNUSED
;
945 const gchar
*g
= *group_iter
;
947 gboolean ignore_case
;
949 if (strcmp (g
, descr_group
) == 0 || strncmp (g
, "Include/", 8) == 0
950 || strcmp (g
, default_group
) == 0)
953 /* The "Directory" parameter is a special case: if it's present then
954 "Type", "Regex", and "Shell" parameters are ignored */
955 pattern
= mc_config_get_string_raw (ext_ini
, g
, "Directory", NULL
);
958 found
= S_ISDIR (mystat
.st_mode
)
959 && mc_search (pattern
, DEFAULT_CHARSET
, vfs_path_as_str (filename_vpath
),
963 continue; // stop if found
967 if (use_file_to_check_type
)
969 pattern
= mc_config_get_string_raw (ext_ini
, g
, "Type", NULL
);
972 GError
*mcerror
= NULL
;
974 ignore_case
= mc_config_get_bool (ext_ini
, g
, "TypeIgnoreCase", FALSE
);
976 regex_check_type (filename_vpath
, pattern
, ignore_case
, &have_type
, &mcerror
)
981 if (mc_error_message (&mcerror
, NULL
))
982 error_flag
= TRUE
; // leave it if file cannot be opened
984 if (type_state
== TYPE_NOT_FOUND
)
990 pattern
= mc_config_get_string_raw (ext_ini
, g
, "Regex", NULL
);
995 ignore_case
= mc_config_get_bool (ext_ini
, g
, "RegexIgnoreCase", FALSE
);
996 search
= mc_search_new (pattern
, DEFAULT_CHARSET
);
1001 search
->search_type
= MC_SEARCH_T_REGEX
;
1002 search
->is_case_sensitive
= !ignore_case
;
1003 found
= mc_search_run (search
, filename
, 0, filename_len
, NULL
);
1004 mc_search_free (search
);
1007 found
= found
&& (type_state
== TYPE_UNUSED
|| type_state
== TYPE_FOUND
);
1011 pattern
= mc_config_get_string_raw (ext_ini
, g
, "Shell", NULL
);
1012 if (pattern
!= NULL
)
1014 int (*cmp_func
) (const char *s1
, const char *s2
, size_t n
);
1017 ignore_case
= mc_config_get_bool (ext_ini
, g
, "ShellIgnoreCase", FALSE
);
1018 cmp_func
= ignore_case
? strncasecmp
: strncmp
;
1019 pattern_len
= strlen (pattern
);
1021 if (*pattern
== '.' && filename_len
>= pattern_len
)
1023 cmp_func (pattern
, filename
+ filename_len
- pattern_len
, pattern_len
) == 0;
1025 found
= pattern_len
== filename_len
1026 && cmp_func (pattern
, filename
, filename_len
) == 0;
1030 found
= found
&& (type_state
== TYPE_UNUSED
|| type_state
== TYPE_FOUND
);
1033 found
= type_state
== TYPE_FOUND
;
1037 // group is found, process actions
1040 char *include_value
;
1044 // "Include" parameter has the highest priority over any actions
1045 include_value
= mc_config_get_string_raw (ext_ini
, *group_iter
, "Include", NULL
);
1046 if (include_value
!= NULL
)
1048 // find "Include/include_value" group
1049 include_group
= g_strconcat ("Include/", include_value
, (char *) NULL
);
1050 g_free (include_value
);
1051 found
= mc_config_has_group (ext_ini
, include_group
);
1056 current_group
= include_group
!= NULL
? include_group
: *group_iter
;
1059 current_group
= default_group
;
1060 found
= mc_config_has_group (ext_ini
, current_group
);
1063 if (found
&& !error_flag
)
1065 gchar
*action_value
;
1067 action_value
= mc_config_get_string_raw (ext_ini
, current_group
, action
, NULL
);
1068 if (action_value
== NULL
)
1070 // Not found, try the action from default section
1071 action_value
= mc_config_get_string_raw (ext_ini
, default_group
, action
, NULL
);
1072 found
= (action_value
!= NULL
&& *action_value
!= '\0');
1076 // If action's value is empty, ignore action from default section
1077 found
= (*action_value
!= '\0');
1084 sv
= exec_extension (current_panel
, target
, filename_vpath
, action_value
,
1085 view_at_line_number
);
1086 if (script_vpath
!= NULL
)
1089 exec_cleanup_script (sv
);
1094 g_free (action_value
);
1097 g_free (include_group
);
1099 return (error_flag
? -1 : ret
);
1102 /* --------------------------------------------------------------------------------------------- */