1
1

Applied MC indentation policy.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
Andrew Borodin 2010-05-28 14:58:05 +04:00
родитель 0c551c6ed2
Коммит 2c15a595c1

275
src/ext.c
Просмотреть файл

@ -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;
@ -114,10 +113,10 @@ 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) {
if (cmd_file_fd == -1)
{
message (D_ERROR, MSG_ERROR,
_(" Cannot create temporary command file \n %s "),
unix_error_string (errno));
_(" Cannot create temporary command file \n %s "), unix_error_string (errno));
return;
}
@ -125,18 +124,24 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
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 == '}') {
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) {
parameter =
input_dialog (_(" Parameter "), lc_prompt, MC_HISTORY_EXT_PARAMETER, "");
if (parameter == NULL)
{
/* User canceled */
fclose (cmd_file);
unlink (file_name);
if (localcopy) {
if (localcopy)
{
mc_ungetlocalcopy (filename, localcopy, 0);
g_free (localcopy);
}
@ -146,49 +151,67 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
fputs (parameter, cmd_file);
written_nonspace = 1;
g_free (parameter);
} else {
}
else
{
size_t len = strlen (lc_prompt);
if (len < sizeof (lc_prompt) - 1) {
if (len < sizeof (lc_prompt) - 1)
{
lc_prompt[len] = *lc_data;
lc_prompt[len + 1] = '\0';
}
}
} else if (expand_prefix_found) {
}
else if (expand_prefix_found)
{
expand_prefix_found = 0;
if (*lc_data == '{')
parameter_found = 1;
else {
else
{
int i;
char *v;
i = check_format_view (lc_data);
if (i != 0) {
if (i != 0)
{
lc_data += i - 1;
run_view = 1;
} else {
}
else
{
i = check_format_cd (lc_data);
if (i > 0) {
if (i > 0)
{
is_cd = 1;
quote_func = fake_name_quote;
do_local_copy = 0;
p = buffer;
lc_data += i - 1;
} else {
}
else
{
i = check_format_var (lc_data, &v);
if (i > 0 && v != NULL) {
if (i > 0 && v != NULL)
{
fputs (v, cmd_file);
g_free (v);
lc_data += i;
} else {
}
else
{
char *text;
if (*lc_data != 'f')
text = expand_format (NULL, *lc_data, !is_cd);
else {
if (do_local_copy) {
else
{
if (do_local_copy)
{
localcopy = mc_getlocalcopy (filename);
if (localcopy == NULL) {
if (localcopy == NULL)
{
fclose (cmd_file);
unlink (file_name);
g_free (file_name);
@ -197,7 +220,9 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
mc_stat (localcopy, &mystat);
localmtime = mystat.st_mtime;
text = quote_func (localcopy, 0);
} else {
}
else
{
fn = vfs_canon_and_translate (filename);
text = quote_func (fn, 0);
g_free (fn);
@ -206,7 +231,8 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
if (!is_cd)
fputs (text, cmd_file);
else {
else
{
strcpy (p, text);
p = strchr (p, 0);
}
@ -217,9 +243,11 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
}
}
}
} else if (*lc_data == '%')
}
else if (*lc_data == '%')
expand_prefix_found = 1;
else {
else
{
if (*lc_data != ' ' && *lc_data != '\t')
written_nonspace = 1;
if (is_cd)
@ -239,18 +267,22 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
fclose (cmd_file);
if ((run_view && !written_nonspace) || is_cd) {
if ((run_view && !written_nonspace) || is_cd)
{
unlink (file_name);
g_free (file_name);
file_name = NULL;
} else {
}
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) {
if (run_view)
{
mcview_altered_hex_mode = 0;
mcview_altered_nroff_flag = 0;
if (def_hex_mode != mcview_default_hex_mode)
@ -261,10 +293,13 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
/* If we've written whitespace only, then just load filename
* into view
*/
if (written_nonspace) {
if (written_nonspace)
{
mcview_viewer (cmd, filename, move_dir, start_line);
unlink (file_name);
} else {
}
else
{
mcview_viewer (NULL, filename, move_dir, start_line);
}
if (changed_hex_mode && !mcview_altered_hex_mode)
@ -272,7 +307,9 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
if (changed_nroff_flag && !mcview_altered_nroff_flag)
mcview_default_nroff_flag = def_nroff_flag;
repaint_screen ();
} else if (is_cd) {
}
else if (is_cd)
{
char *q;
*p = 0;
p = buffer;
@ -286,15 +323,18 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
q--;
q[1] = 0;
do_cd (p, cd_parse_command);
} else {
}
else
{
shell_execute (cmd, EXECUTE_INTERNAL);
if (console_flag) {
if (console_flag)
{
handle_console (CONSOLE_SAVE);
if (output_lines && keybar_visible) {
if (output_lines && keybar_visible)
{
show_console_contents (output_start_y,
LINES - keybar_visible -
output_lines - 1,
LINES - keybar_visible - 1);
output_lines - 1, LINES - keybar_visible - 1);
}
}
}
@ -302,10 +342,10 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
g_free (file_name);
g_free (cmd);
if (localcopy) {
if (localcopy)
{
mc_stat (localcopy, &mystat);
mc_ungetlocalcopy (filename, localcopy,
localmtime != mystat.st_mtime);
mc_ungetlocalcopy (filename, localcopy, localmtime != mystat.st_mtime);
g_free (localcopy);
}
}
@ -334,9 +374,11 @@ 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) {
if (setvbuf (f, NULL, _IOFBF, 0) != 0)
{
(void) pclose (f);
return -1;
}
@ -345,7 +387,9 @@ get_popen_information (const char *cmd_file, const char *args, char *buf, int bu
if (!read_bytes)
buf[0] = '\0'; /* Paranoid termination */
pclose (f);
} else {
}
else
{
buf[0] = '\0'; /* Paranoid termination */
return -1;
}
@ -417,7 +461,8 @@ regex_check_type (const char *filename, const char *ptr, int *have_type)
if (!use_file_to_check_type)
return 0;
if (*have_type == 0) {
if (*have_type == 0)
{
char *realname; /* name used with "file" */
char *localfile;
@ -436,10 +481,10 @@ regex_check_type (const char *filename, const char *ptr, int *have_type)
#ifdef HAVE_CHARSET
got_encoding_data = is_autodetect_codeset_enabled
? get_file_encoding_local (localfile, encoding_id, sizeof (encoding_id))
: 0;
? get_file_encoding_local (localfile, encoding_id, sizeof (encoding_id)) : 0;
if (got_encoding_data > 0) {
if (got_encoding_data > 0)
{
char *pp;
int cp_id;
@ -459,7 +504,8 @@ regex_check_type (const char *filename, const char *ptr, int *have_type)
got_data = get_file_type_local (localfile, content_string, sizeof (content_string));
if (got_data > 0) {
if (got_data > 0)
{
char *pp;
size_t real_len;
@ -469,19 +515,22 @@ regex_check_type (const char *filename, const char *ptr, int *have_type)
real_len = strlen (realname);
if (strncmp (content_string, realname, real_len) == 0) {
if (strncmp (content_string, realname, real_len) == 0)
{
/* Skip "realname: " */
content_shift = real_len;
if (content_string[content_shift] == ':') {
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++)
|| content_string[content_shift] == '\t'; content_shift++)
;
}
}
} else {
}
else
{
/* No data */
content_string[0] = '\0';
}
@ -492,7 +541,8 @@ regex_check_type (const char *filename, const char *ptr, int *have_type)
return -1;
if (content_string[0] != '\0'
&& mc_search (ptr, content_string + content_shift, MC_SEARCH_T_REGEX)) {
&& mc_search (ptr, content_string + content_shift, MC_SEARCH_T_REGEX))
{
found = 1;
}
@ -526,24 +576,30 @@ regex_command (const char *filename, const char *action, int *move_dir)
int have_type = 0; /* Flag used by regex_check_type() */
/* Check for the special View:%d parameter */
if (strncmp (action, "View:", 5) == 0) {
if (strncmp (action, "View:", 5) == 0)
{
view_at_line_number = atoi (action + 5);
action = "View";
} else {
}
else
{
view_at_line_number = 0;
}
if (data == NULL) {
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)) {
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)) {
if (!exist_file (extension_file))
{
g_free (extension_file);
extension_file = concat_dir_and_file (mc_home_alt, MC_LIB_EXT);
}
@ -554,17 +610,20 @@ regex_command (const char *filename, const char *action, int *move_dir)
if (data == NULL)
return 0;
if (!strstr (data, "default/")) {
if (!strstr (data, "regex/") && !strstr (data, "shell/")
&& !strstr (data, "type/")) {
if (!strstr (data, "default/"))
{
if (!strstr (data, "regex/") && !strstr (data, "shell/") && !strstr (data, "type/"))
{
g_free (data);
data = NULL;
if (mc_user_ext) {
if (mc_user_ext)
{
home_error = 1;
goto check_stock_mc_ext;
} else {
char *title =
g_strdup_printf (_(" %s%s file error"),
}
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 "
@ -576,13 +635,16 @@ regex_command (const char *filename, const char *action, int *move_dir)
}
}
}
if (home_error) {
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 "
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);
"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);
}
}
@ -590,7 +652,8 @@ regex_command (const char *filename, const char *action, int *move_dir)
include_target = NULL;
include_target_len = 0;
for (p = data; *p; p++) {
for (p = data; *p; p++)
{
for (q = p; *q == ' ' || *q == '\t'; q++);
if (*q == '\n' || !*q)
p = q; /* empty line */
@ -601,7 +664,8 @@ regex_command (const char *filename, const char *action, int *move_dir)
continue;
if (!*p)
break;
if (p == q) { /* i.e. starts in the first column, should be
if (p == q)
{ /* i.e. starts in the first column, should be
* keyword/descNL
*/
found = 0;
@ -610,32 +674,42 @@ regex_command (const char *filename, const char *action, int *move_dir)
q = strchr (p, 0);
c = *q;
*q = 0;
if (include_target) {
if (include_target)
{
if ((strncmp (p, "include/", 8) == 0)
&& (strncmp (p + 8, include_target, include_target_len)
== 0))
&& (strncmp (p + 8, include_target, include_target_len) == 0))
found = 1;
} else if (!strncmp (p, "regex/", 6)) {
}
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))
}
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)) {
}
else if (!strncmp (p, "shell/", 6))
{
p += 6;
if (*p == '.' && file_len >= (q - p)) {
if (*p == '.' && file_len >= (q - p))
{
if (!strncmp (p, filename + file_len - (q - p), q - p))
found = 1;
} else {
}
else
{
if (q - p == file_len && !strncmp (p, filename, q - p))
found = 1;
}
} else if (!strncmp (p, "type/", 5)) {
}
else if (!strncmp (p, "type/", 5))
{
int res;
p += 5;
res = regex_check_type (filename, p, &have_type);
@ -643,24 +717,31 @@ regex_command (const char *filename, const char *action, int *move_dir)
found = 1;
if (res == -1)
error_flag = 1; /* leave it if file cannot be opened */
} else if (!strncmp (p, "default/", 8)) {
}
else if (!strncmp (p, "default/", 8))
{
found = 1;
}
*q = c;
p = q;
if (!*p)
break;
} else { /* List of actions */
}
else
{ /* List of actions */
p = q;
q = strchr (p, '\n');
if (q == NULL)
q = strchr (p, 0);
if (found && !error_flag) {
if (found && !error_flag)
{
r = strchr (p, '=');
if (r != NULL) {
if (r != NULL)
{
c = *r;
*r = 0;
if (strcmp (p, "Include") == 0) {
if (strcmp (p, "Include") == 0)
{
char *t;
include_target = p + 8;
@ -679,7 +760,8 @@ regex_command (const char *filename, const char *action, int *move_dir)
break;
continue;
}
if (!strcmp (action, p)) {
if (!strcmp (action, p))
{
*r = c;
for (p = r + 1; *p == ' ' || *p == '\t'; p++);
@ -691,17 +773,18 @@ regex_command (const char *filename, const char *action, int *move_dir)
* filename parameter invalid (ie, most of the time,
* we get filename as a pointer from current_panel->dir).
*/
if (p < q) {
if (p < q)
{
char *filename_copy = g_strdup (filename);
exec_extension (filename_copy, r + 1, move_dir,
view_at_line_number);
exec_extension (filename_copy, r + 1, move_dir, view_at_line_number);
g_free (filename_copy);
ret = 1;
}
break;
} else
}
else
*r = c;
}
}