From 2c15a595c16626c0980bd8fe5e7582975fc169f6 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 28 May 2010 14:58:05 +0400 Subject: [PATCH] Applied MC indentation policy. Signed-off-by: Andrew Borodin --- src/ext.c | 899 +++++++++++++++++++++++++++++------------------------- 1 file changed, 491 insertions(+), 408 deletions(-) diff --git a/src/ext.c b/src/ext.c index 89f216da6..00fba855b 100644 --- a/src/ext.c +++ b/src/ext.c @@ -3,7 +3,7 @@ 2005, 2007 Free Software Foundation, Inc. Written by: 1995 Jakub Jelinek - 1994 Miguel de Icaza + 1994 Miguel de Icaza This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -49,8 +49,8 @@ #include "history.h" #include "layout.h" #ifdef HAVE_CHARSET -#include "charsets.h" /* get_codepage_index */ -#include "selcodepage.h" /* do_set_codepage */ +#include "charsets.h" /* get_codepage_index */ +#include "selcodepage.h" /* do_set_codepage */ #endif #include "ext.h" @@ -73,8 +73,7 @@ flush_extension_file (void) typedef char *(*quote_func_t) (const char *name, int quote_percent); static void -exec_extension (const char *filename, const char *lc_data, int *move_dir, - int start_line) +exec_extension (const char *filename, const char *lc_data, int *move_dir, int start_line) { char *fn; char *file_name; @@ -102,9 +101,9 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, /* Avoid making a local copy if we are doing a cd */ if (!vfs_file_is_local (filename)) - do_local_copy = 1; + do_local_copy = 1; else - do_local_copy = 0; + do_local_copy = 0; /* * All commands should be run in /bin/sh regardless of user shell. @@ -114,120 +113,149 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, */ cmd_file_fd = mc_mkstemps (&file_name, "mcext", SCRIPT_SUFFIX); - if (cmd_file_fd == -1) { - message (D_ERROR, MSG_ERROR, - _(" Cannot create temporary command file \n %s "), - unix_error_string (errno)); - return; + if (cmd_file_fd == -1) + { + message (D_ERROR, MSG_ERROR, + _(" Cannot create temporary command file \n %s "), unix_error_string (errno)); + return; } cmd_file = fdopen (cmd_file_fd, "w"); fputs ("#! /bin/sh\n", cmd_file); lc_prompt[0] = '\0'; - for (; *lc_data != '\0' && *lc_data != '\n'; lc_data++) { - if (parameter_found) { - if (*lc_data == '}') { - char *parameter; + for (; *lc_data != '\0' && *lc_data != '\n'; lc_data++) + { + if (parameter_found) + { + if (*lc_data == '}') + { + char *parameter; - parameter_found = 0; - parameter = input_dialog (_(" Parameter "), lc_prompt, MC_HISTORY_EXT_PARAMETER, ""); - if (parameter == NULL) { - /* User canceled */ - fclose (cmd_file); - unlink (file_name); - if (localcopy) { - mc_ungetlocalcopy (filename, localcopy, 0); - g_free (localcopy); - } - g_free (file_name); - return; - } - fputs (parameter, cmd_file); - written_nonspace = 1; - g_free (parameter); - } else { - size_t len = strlen (lc_prompt); + parameter_found = 0; + parameter = + input_dialog (_(" Parameter "), lc_prompt, MC_HISTORY_EXT_PARAMETER, ""); + if (parameter == NULL) + { + /* User canceled */ + fclose (cmd_file); + unlink (file_name); + if (localcopy) + { + mc_ungetlocalcopy (filename, localcopy, 0); + g_free (localcopy); + } + g_free (file_name); + return; + } + fputs (parameter, cmd_file); + written_nonspace = 1; + g_free (parameter); + } + else + { + size_t len = strlen (lc_prompt); - if (len < sizeof (lc_prompt) - 1) { - lc_prompt[len] = *lc_data; - lc_prompt[len + 1] = '\0'; - } - } - } else if (expand_prefix_found) { - expand_prefix_found = 0; - if (*lc_data == '{') - parameter_found = 1; - else { - int i; - char *v; + if (len < sizeof (lc_prompt) - 1) + { + lc_prompt[len] = *lc_data; + lc_prompt[len + 1] = '\0'; + } + } + } + else if (expand_prefix_found) + { + expand_prefix_found = 0; + if (*lc_data == '{') + parameter_found = 1; + else + { + int i; + char *v; - i = check_format_view (lc_data); - if (i != 0) { - lc_data += i - 1; - run_view = 1; - } else { - i = check_format_cd (lc_data); - if (i > 0) { - is_cd = 1; - quote_func = fake_name_quote; - do_local_copy = 0; - p = buffer; - lc_data += i - 1; - } else { - i = check_format_var (lc_data, &v); - if (i > 0 && v != NULL) { - fputs (v, cmd_file); - g_free (v); - lc_data += i; - } else { - char *text; + i = check_format_view (lc_data); + if (i != 0) + { + lc_data += i - 1; + run_view = 1; + } + else + { + i = check_format_cd (lc_data); + if (i > 0) + { + is_cd = 1; + quote_func = fake_name_quote; + do_local_copy = 0; + p = buffer; + lc_data += i - 1; + } + else + { + i = check_format_var (lc_data, &v); + if (i > 0 && v != NULL) + { + fputs (v, cmd_file); + g_free (v); + lc_data += i; + } + else + { + char *text; - if (*lc_data != 'f') - text = expand_format (NULL, *lc_data, !is_cd); - else { - if (do_local_copy) { - localcopy = mc_getlocalcopy (filename); - if (localcopy == NULL) { - fclose (cmd_file); - unlink (file_name); - g_free (file_name); - return; - } - mc_stat (localcopy, &mystat); - localmtime = mystat.st_mtime; - text = quote_func (localcopy, 0); - } else { - fn = vfs_canon_and_translate (filename); - text = quote_func (fn, 0); - g_free (fn); - } - } + if (*lc_data != 'f') + text = expand_format (NULL, *lc_data, !is_cd); + else + { + if (do_local_copy) + { + localcopy = mc_getlocalcopy (filename); + if (localcopy == NULL) + { + fclose (cmd_file); + unlink (file_name); + g_free (file_name); + return; + } + mc_stat (localcopy, &mystat); + localmtime = mystat.st_mtime; + text = quote_func (localcopy, 0); + } + else + { + fn = vfs_canon_and_translate (filename); + text = quote_func (fn, 0); + g_free (fn); + } + } - if (!is_cd) - fputs (text, cmd_file); - else { - strcpy (p, text); - p = strchr (p, 0); - } + if (!is_cd) + fputs (text, cmd_file); + else + { + strcpy (p, text); + p = strchr (p, 0); + } - g_free (text); - written_nonspace = 1; - } - } - } - } - } else if (*lc_data == '%') - expand_prefix_found = 1; - else { - if (*lc_data != ' ' && *lc_data != '\t') - written_nonspace = 1; - if (is_cd) - *(p++) = *lc_data; - else - fputc (*lc_data, cmd_file); - } - } /* for */ + g_free (text); + written_nonspace = 1; + } + } + } + } + } + else if (*lc_data == '%') + expand_prefix_found = 1; + else + { + if (*lc_data != ' ' && *lc_data != '\t') + written_nonspace = 1; + if (is_cd) + *(p++) = *lc_data; + else + fputc (*lc_data, cmd_file); + } + } /* for */ /* * Make the script remove itself when it finishes. @@ -235,78 +263,90 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, * so we clean up after calling view(). */ if (!run_view) - fprintf (cmd_file, "\n/bin/rm -f %s\n", file_name); + fprintf (cmd_file, "\n/bin/rm -f %s\n", file_name); fclose (cmd_file); - if ((run_view && !written_nonspace) || is_cd) { - unlink (file_name); - g_free (file_name); - file_name = NULL; - } else { - /* Set executable flag on the command file ... */ - chmod (file_name, S_IRWXU); - /* ... but don't rely on it - run /bin/sh explicitly */ - cmd = g_strconcat ("/bin/sh ", file_name, (char *) NULL); + if ((run_view && !written_nonspace) || is_cd) + { + unlink (file_name); + g_free (file_name); + file_name = NULL; + } + else + { + /* Set executable flag on the command file ... */ + chmod (file_name, S_IRWXU); + /* ... but don't rely on it - run /bin/sh explicitly */ + cmd = g_strconcat ("/bin/sh ", file_name, (char *) NULL); } - if (run_view) { - mcview_altered_hex_mode = 0; - mcview_altered_nroff_flag = 0; - if (def_hex_mode != mcview_default_hex_mode) - changed_hex_mode = 1; - if (def_nroff_flag != mcview_default_nroff_flag) - changed_nroff_flag = 1; + if (run_view) + { + mcview_altered_hex_mode = 0; + mcview_altered_nroff_flag = 0; + if (def_hex_mode != mcview_default_hex_mode) + changed_hex_mode = 1; + if (def_nroff_flag != mcview_default_nroff_flag) + changed_nroff_flag = 1; - /* If we've written whitespace only, then just load filename - * into view - */ - if (written_nonspace) { - mcview_viewer (cmd, filename, move_dir, start_line); - unlink (file_name); - } else { - mcview_viewer (NULL, filename, move_dir, start_line); - } - if (changed_hex_mode && !mcview_altered_hex_mode) - mcview_default_hex_mode = def_hex_mode; - if (changed_nroff_flag && !mcview_altered_nroff_flag) - mcview_default_nroff_flag = def_nroff_flag; - repaint_screen (); - } else if (is_cd) { - char *q; - *p = 0; - p = buffer; -/* while (*p == ' ' && *p == '\t') - * p++; - */ - /* Search last non-space character. Start search at the end in order - not to short filenames containing spaces. */ - q = p + strlen (p) - 1; - while (q >= p && (*q == ' ' || *q == '\t')) - q--; - q[1] = 0; - do_cd (p, cd_parse_command); - } else { - shell_execute (cmd, EXECUTE_INTERNAL); - if (console_flag) { - handle_console (CONSOLE_SAVE); - if (output_lines && keybar_visible) { - show_console_contents (output_start_y, - LINES - keybar_visible - - output_lines - 1, - LINES - keybar_visible - 1); - } - } + /* If we've written whitespace only, then just load filename + * into view + */ + if (written_nonspace) + { + mcview_viewer (cmd, filename, move_dir, start_line); + unlink (file_name); + } + else + { + mcview_viewer (NULL, filename, move_dir, start_line); + } + if (changed_hex_mode && !mcview_altered_hex_mode) + mcview_default_hex_mode = def_hex_mode; + if (changed_nroff_flag && !mcview_altered_nroff_flag) + mcview_default_nroff_flag = def_nroff_flag; + repaint_screen (); + } + else if (is_cd) + { + char *q; + *p = 0; + p = buffer; + /* while (*p == ' ' && *p == '\t') + * p++; + */ + /* Search last non-space character. Start search at the end in order + not to short filenames containing spaces. */ + q = p + strlen (p) - 1; + while (q >= p && (*q == ' ' || *q == '\t')) + q--; + q[1] = 0; + do_cd (p, cd_parse_command); + } + else + { + shell_execute (cmd, EXECUTE_INTERNAL); + if (console_flag) + { + handle_console (CONSOLE_SAVE); + if (output_lines && keybar_visible) + { + show_console_contents (output_start_y, + LINES - keybar_visible - + output_lines - 1, LINES - keybar_visible - 1); + } + } } g_free (file_name); g_free (cmd); - if (localcopy) { - mc_stat (localcopy, &mystat); - mc_ungetlocalcopy (filename, localcopy, - localmtime != mystat.st_mtime); - g_free (localcopy); + if (localcopy) + { + mc_stat (localcopy, &mystat); + mc_ungetlocalcopy (filename, localcopy, localmtime != mystat.st_mtime); + g_free (localcopy); } } @@ -334,20 +374,24 @@ get_popen_information (const char *cmd_file, const char *args, char *buf, int bu f = popen (command, "r"); g_free (command); - if (f != NULL) { + if (f != NULL) + { #ifdef __QNXNTO__ - if (setvbuf (f, NULL, _IOFBF, 0) != 0) { - (void) pclose (f); - return -1; - } + if (setvbuf (f, NULL, _IOFBF, 0) != 0) + { + (void) pclose (f); + return -1; + } #endif - read_bytes = (fgets (buf, buflen, f) != NULL); - if (!read_bytes) - buf[0] = '\0'; /* Paranoid termination */ - pclose (f); - } else { - buf[0] = '\0'; /* Paranoid termination */ - return -1; + read_bytes = (fgets (buf, buflen, f) != NULL); + if (!read_bytes) + buf[0] = '\0'; /* Paranoid termination */ + pclose (f); + } + else + { + buf[0] = '\0'; /* Paranoid termination */ + return -1; } buf[buflen - 1] = '\0'; @@ -385,7 +429,7 @@ get_file_encoding_local (const char *filename, char *buf, int buflen) tmp = name_quote (filename, 0); lang = name_quote (autodetect_codeset, 0); - args= g_strconcat (" -L", lang, " -i ", tmp, (char *) NULL); + args = g_strconcat (" -L", lang, " -i ", tmp, (char *) NULL); ret = get_popen_information ("enca", args, buf, buflen); @@ -410,90 +454,96 @@ regex_check_type (const char *filename, const char *ptr, int *have_type) /* Following variables are valid if *have_type is 1 */ static char content_string[2048]; - static char encoding_id[21]; /* CSISO51INISCYRILLIC -- 20 */ + static char encoding_id[21]; /* CSISO51INISCYRILLIC -- 20 */ static size_t content_shift = 0; static int got_data = 0; if (!use_file_to_check_type) - return 0; + return 0; - if (*have_type == 0) { - char *realname; /* name used with "file" */ - char *localfile; + if (*have_type == 0) + { + char *realname; /* name used with "file" */ + char *localfile; #ifdef HAVE_CHARSET - int got_encoding_data; + int got_encoding_data; #endif /* HAVE_CHARSET */ - /* Don't repeate even unsuccessful checks */ - *have_type = 1; + /* Don't repeate even unsuccessful checks */ + *have_type = 1; - localfile = mc_getlocalcopy (filename); - if (localfile == NULL) - return -1; + localfile = mc_getlocalcopy (filename); + if (localfile == NULL) + return -1; - realname = localfile; + realname = localfile; #ifdef HAVE_CHARSET - got_encoding_data = is_autodetect_codeset_enabled - ? get_file_encoding_local (localfile, encoding_id, sizeof (encoding_id)) - : 0; + got_encoding_data = is_autodetect_codeset_enabled + ? get_file_encoding_local (localfile, encoding_id, sizeof (encoding_id)) : 0; - if (got_encoding_data > 0) { - char *pp; - int cp_id; + if (got_encoding_data > 0) + { + char *pp; + int cp_id; - pp = strchr (encoding_id, '\n'); - if (pp != NULL) - *pp = '\0'; + pp = strchr (encoding_id, '\n'); + if (pp != NULL) + *pp = '\0'; - cp_id = get_codepage_index (encoding_id); - if (cp_id == -1) - cp_id = default_source_codepage; + cp_id = get_codepage_index (encoding_id); + if (cp_id == -1) + cp_id = default_source_codepage; - do_set_codepage (cp_id); - } + do_set_codepage (cp_id); + } #endif /* HAVE_CHARSET */ - mc_ungetlocalcopy (filename, localfile, 0); + mc_ungetlocalcopy (filename, localfile, 0); - got_data = get_file_type_local (localfile, content_string, sizeof (content_string)); + got_data = get_file_type_local (localfile, content_string, sizeof (content_string)); - if (got_data > 0) { - char *pp; - size_t real_len; + if (got_data > 0) + { + char *pp; + size_t real_len; - pp = strchr (content_string, '\n'); - if (pp != NULL) - *pp = '\0'; + pp = strchr (content_string, '\n'); + if (pp != NULL) + *pp = '\0'; - real_len = strlen (realname); + real_len = strlen (realname); - if (strncmp (content_string, realname, real_len) == 0) { - /* Skip "realname: " */ - content_shift = real_len; - if (content_string[content_shift] == ':') { - /* Solaris' file prints tab(s) after ':' */ - for (content_shift++; - content_string[content_shift] == ' ' - || content_string[content_shift] == '\t'; - content_shift++) - ; - } - } - } else { - /* No data */ - content_string[0] = '\0'; - } - g_free (realname); + if (strncmp (content_string, realname, real_len) == 0) + { + /* Skip "realname: " */ + content_shift = real_len; + if (content_string[content_shift] == ':') + { + /* Solaris' file prints tab(s) after ':' */ + for (content_shift++; + content_string[content_shift] == ' ' + || content_string[content_shift] == '\t'; content_shift++) + ; + } + } + } + else + { + /* No data */ + content_string[0] = '\0'; + } + g_free (realname); } if (got_data == -1) - return -1; + return -1; if (content_string[0] != '\0' - && mc_search (ptr, content_string + content_shift, MC_SEARCH_T_REGEX)) { - found = 1; + && mc_search (ptr, content_string + content_shift, MC_SEARCH_T_REGEX)) + { + found = 1; } return found; @@ -523,194 +573,227 @@ regex_command (const char *filename, const char *action, int *move_dir) int view_at_line_number; char *include_target; int include_target_len; - int have_type = 0; /* Flag used by regex_check_type() */ + int have_type = 0; /* Flag used by regex_check_type() */ /* Check for the special View:%d parameter */ - if (strncmp (action, "View:", 5) == 0) { - view_at_line_number = atoi (action + 5); - action = "View"; - } else { - view_at_line_number = 0; + if (strncmp (action, "View:", 5) == 0) + { + view_at_line_number = atoi (action + 5); + action = "View"; + } + else + { + view_at_line_number = 0; } - if (data == NULL) { - char *extension_file; - int mc_user_ext = 1; - int home_error = 0; + if (data == NULL) + { + char *extension_file; + int mc_user_ext = 1; + int home_error = 0; - extension_file = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FILEBIND_FILE, NULL); - if (!exist_file (extension_file)) { - g_free (extension_file); - check_stock_mc_ext: - extension_file = concat_dir_and_file (mc_home, MC_LIB_EXT); - if (!exist_file (extension_file)) { - g_free (extension_file); - extension_file = concat_dir_and_file (mc_home_alt, MC_LIB_EXT); - } - mc_user_ext = 0; - } - data = load_file (extension_file); - g_free (extension_file); - if (data == NULL) - return 0; + extension_file = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FILEBIND_FILE, NULL); + if (!exist_file (extension_file)) + { + g_free (extension_file); + check_stock_mc_ext: + extension_file = concat_dir_and_file (mc_home, MC_LIB_EXT); + if (!exist_file (extension_file)) + { + g_free (extension_file); + extension_file = concat_dir_and_file (mc_home_alt, MC_LIB_EXT); + } + mc_user_ext = 0; + } + data = load_file (extension_file); + g_free (extension_file); + if (data == NULL) + return 0; - if (!strstr (data, "default/")) { - if (!strstr (data, "regex/") && !strstr (data, "shell/") - && !strstr (data, "type/")) { - g_free (data); - data = NULL; - if (mc_user_ext) { - home_error = 1; - goto check_stock_mc_ext; - } else { - char *title = - g_strdup_printf (_(" %s%s file error"), - mc_home, MC_LIB_EXT); - message (D_ERROR, title, _("The format of the %smc.ext " - "file has changed with version 3.0. It seems that " - "the installation failed. Please fetch a fresh " - "copy from the Midnight Commander package."), - mc_home); - g_free (title); - return 0; - } - } - } - if (home_error) { - char *title = - g_strdup_printf (_(" ~/%s file error "), MC_USERCONF_DIR PATH_SEP_STR MC_FILEBIND_FILE); - message (D_ERROR, title, _("The format of the ~/%s file has " - "changed with version 3.0. You may either want to copy " - "it from %smc.ext or use that file as an example of how " - "to write it."), MC_USERCONF_DIR PATH_SEP_STR MC_FILEBIND_FILE, mc_home); - g_free (title); - } + if (!strstr (data, "default/")) + { + if (!strstr (data, "regex/") && !strstr (data, "shell/") && !strstr (data, "type/")) + { + g_free (data); + data = NULL; + if (mc_user_ext) + { + home_error = 1; + goto check_stock_mc_ext; + } + else + { + char *title = g_strdup_printf (_(" %s%s file error"), + mc_home, MC_LIB_EXT); + message (D_ERROR, title, _("The format of the %smc.ext " + "file has changed with version 3.0. It seems that " + "the installation failed. Please fetch a fresh " + "copy from the Midnight Commander package."), + mc_home); + g_free (title); + return 0; + } + } + } + if (home_error) + { + char *title = + g_strdup_printf (_(" ~/%s file error "), + MC_USERCONF_DIR PATH_SEP_STR MC_FILEBIND_FILE); + message (D_ERROR, title, + _("The format of the ~/%s file has " + "changed with version 3.0. You may either want to copy " + "it from %smc.ext or use that file as an example of how " "to write it."), + MC_USERCONF_DIR PATH_SEP_STR MC_FILEBIND_FILE, mc_home); + g_free (title); + } } mc_stat (filename, &mystat); include_target = NULL; include_target_len = 0; - for (p = data; *p; p++) { - for (q = p; *q == ' ' || *q == '\t'; q++); - if (*q == '\n' || !*q) - p = q; /* empty line */ - if (*p == '#') /* comment */ - while (*p && *p != '\n') - p++; - if (*p == '\n') - continue; - if (!*p) - break; - if (p == q) { /* i.e. starts in the first column, should be - * keyword/descNL - */ - found = 0; - q = strchr (p, '\n'); - if (q == NULL) - q = strchr (p, 0); - c = *q; - *q = 0; - if (include_target) { - if ((strncmp (p, "include/", 8) == 0) - && (strncmp (p + 8, include_target, include_target_len) - == 0)) - found = 1; - } else if (!strncmp (p, "regex/", 6)) { - p += 6; - /* Do not transform shell patterns, you can use shell/ for - * that - */ - if (mc_search (p, filename, MC_SEARCH_T_REGEX)) - found = 1; - } else if (!strncmp (p, "directory/", 10)) { - if (S_ISDIR (mystat.st_mode) - && mc_search (p + 10, filename, MC_SEARCH_T_REGEX)) - found = 1; - } else if (!strncmp (p, "shell/", 6)) { - p += 6; - if (*p == '.' && file_len >= (q - p)) { - if (!strncmp (p, filename + file_len - (q - p), q - p)) - found = 1; - } else { - if (q - p == file_len && !strncmp (p, filename, q - p)) - found = 1; - } - } else if (!strncmp (p, "type/", 5)) { - int res; - p += 5; - res = regex_check_type (filename, p, &have_type); - if (res == 1) - found = 1; - if (res == -1) - error_flag = 1; /* leave it if file cannot be opened */ - } else if (!strncmp (p, "default/", 8)) { - found = 1; - } - *q = c; - p = q; - if (!*p) - break; - } else { /* List of actions */ - p = q; - q = strchr (p, '\n'); - if (q == NULL) - q = strchr (p, 0); - if (found && !error_flag) { - r = strchr (p, '='); - if (r != NULL) { - c = *r; - *r = 0; - if (strcmp (p, "Include") == 0) { - char *t; + for (p = data; *p; p++) + { + for (q = p; *q == ' ' || *q == '\t'; q++); + if (*q == '\n' || !*q) + p = q; /* empty line */ + if (*p == '#') /* comment */ + while (*p && *p != '\n') + p++; + if (*p == '\n') + continue; + if (!*p) + break; + if (p == q) + { /* i.e. starts in the first column, should be + * keyword/descNL + */ + found = 0; + q = strchr (p, '\n'); + if (q == NULL) + q = strchr (p, 0); + c = *q; + *q = 0; + if (include_target) + { + if ((strncmp (p, "include/", 8) == 0) + && (strncmp (p + 8, include_target, include_target_len) == 0)) + found = 1; + } + else if (!strncmp (p, "regex/", 6)) + { + p += 6; + /* Do not transform shell patterns, you can use shell/ for + * that + */ + if (mc_search (p, filename, MC_SEARCH_T_REGEX)) + found = 1; + } + else if (!strncmp (p, "directory/", 10)) + { + if (S_ISDIR (mystat.st_mode) && mc_search (p + 10, filename, MC_SEARCH_T_REGEX)) + found = 1; + } + else if (!strncmp (p, "shell/", 6)) + { + p += 6; + if (*p == '.' && file_len >= (q - p)) + { + if (!strncmp (p, filename + file_len - (q - p), q - p)) + found = 1; + } + else + { + if (q - p == file_len && !strncmp (p, filename, q - p)) + found = 1; + } + } + else if (!strncmp (p, "type/", 5)) + { + int res; + p += 5; + res = regex_check_type (filename, p, &have_type); + if (res == 1) + found = 1; + if (res == -1) + error_flag = 1; /* leave it if file cannot be opened */ + } + else if (!strncmp (p, "default/", 8)) + { + found = 1; + } + *q = c; + p = q; + if (!*p) + break; + } + else + { /* List of actions */ + p = q; + q = strchr (p, '\n'); + if (q == NULL) + q = strchr (p, 0); + if (found && !error_flag) + { + r = strchr (p, '='); + if (r != NULL) + { + c = *r; + *r = 0; + if (strcmp (p, "Include") == 0) + { + char *t; - include_target = p + 8; - t = strchr (include_target, '\n'); - if (t) - *t = 0; - include_target_len = strlen (include_target); - if (t) - *t = '\n'; + include_target = p + 8; + t = strchr (include_target, '\n'); + if (t) + *t = 0; + include_target_len = strlen (include_target); + if (t) + *t = '\n'; - *r = c; - p = q; - found = 0; + *r = c; + p = q; + found = 0; - if (!*p) - break; - continue; - } - if (!strcmp (action, p)) { - *r = c; - for (p = r + 1; *p == ' ' || *p == '\t'; p++); + if (!*p) + break; + continue; + } + if (!strcmp (action, p)) + { + *r = c; + for (p = r + 1; *p == ' ' || *p == '\t'; p++); - /* Empty commands just stop searching - * through, they don't do anything - * - * We need to copy the filename because exec_extension - * may end up invoking update_panels thus making the - * filename parameter invalid (ie, most of the time, - * we get filename as a pointer from current_panel->dir). - */ - if (p < q) { - char *filename_copy = g_strdup (filename); + /* Empty commands just stop searching + * through, they don't do anything + * + * We need to copy the filename because exec_extension + * may end up invoking update_panels thus making the + * filename parameter invalid (ie, most of the time, + * we get filename as a pointer from current_panel->dir). + */ + if (p < q) + { + char *filename_copy = g_strdup (filename); - exec_extension (filename_copy, r + 1, move_dir, - view_at_line_number); - g_free (filename_copy); + exec_extension (filename_copy, r + 1, move_dir, view_at_line_number); + g_free (filename_copy); - ret = 1; - } - break; - } else - *r = c; - } - } - p = q; - if (!*p) - break; - } + ret = 1; + } + break; + } + else + *r = c; + } + } + p = q; + if (!*p) + break; + } } if (error_flag) - return -1; + return -1; return ret; }