Code indentation.
[midnight-commander.git] / src / filemanager / ext.c
blob6ce4f59f6e21b4711adab74e6b7dbc1f75496533
1 /*
2 Extension dependent execution.
4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2007, 2011
6 The Free Software Foundation, Inc.
8 Written by:
9 Jakub Jelinek, 1995
10 Miguel de Icaza, 1994
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 <http://www.gnu.org/licenses/>.
28 /** \file ext.c
29 * \brief Source: extension dependent execution
32 #include <config.h>
34 #include <ctype.h>
35 #include <errno.h>
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <unistd.h>
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"
46 #include "lib/util.h"
47 #include "lib/vfs/vfs.h"
48 #include "lib/widget.h"
49 #ifdef HAVE_CHARSET
50 #include "lib/charsets.h" /* get_codepage_index */
51 #endif
53 #include "src/setup.h" /* use_file_to_check_type */
54 #include "src/execute.h"
55 #include "src/history.h"
56 #include "src/main.h" /* do_cd */
58 #include "src/consaver/cons.saver.h"
59 #include "src/viewer/mcviewer.h"
61 #ifdef HAVE_CHARSET
62 #include "src/selcodepage.h" /* do_set_codepage */
63 #endif
65 #include "usermenu.h"
67 #include "ext.h"
69 /*** global variables ****************************************************************************/
71 /*** file scope macro definitions ****************************************************************/
73 #ifdef FILE_L
74 #define FILE_CMD "file -L "
75 #else
76 #define FILE_CMD "file "
77 #endif
79 /*** file scope type declarations ****************************************************************/
81 typedef char *(*quote_func_t) (const char *name, int quote_percent);
83 /*** file scope variables ************************************************************************/
85 /* This variable points to a copy of the mc.ext file in memory
86 * With this we avoid loading/parsing the file each time we
87 * need it
89 static char *data = NULL;
90 static vfs_path_t *localfilecopy_vpath = NULL;
91 static char buffer[BUF_1K];
93 static char *pbuffer = NULL;
94 static time_t localmtime = 0;
95 static quote_func_t quote_func = name_quote;
96 static gboolean run_view = FALSE;
97 static gboolean is_cd = FALSE;
98 static gboolean written_nonspace = FALSE;
99 static gboolean do_local_copy = FALSE;
101 /*** file scope functions ************************************************************************/
102 /* --------------------------------------------------------------------------------------------- */
104 static void
105 exec_cleanup_file_name (const vfs_path_t * filename_vpath, gboolean has_changed)
107 if (localfilecopy_vpath == NULL)
108 return;
110 if (has_changed)
112 struct stat mystat;
114 mc_stat (localfilecopy_vpath, &mystat);
115 has_changed = localmtime != mystat.st_mtime;
117 mc_ungetlocalcopy (filename_vpath, localfilecopy_vpath, has_changed);
118 vfs_path_free (localfilecopy_vpath);
119 localfilecopy_vpath = NULL;
122 /* --------------------------------------------------------------------------------------------- */
124 static char *
125 exec_get_file_name (const vfs_path_t * filename_vpath)
127 if (!do_local_copy)
128 return quote_func (vfs_path_get_last_path_str (filename_vpath), 0);
130 if (localfilecopy_vpath == NULL)
132 struct stat mystat;
133 localfilecopy_vpath = mc_getlocalcopy (filename_vpath);
134 if (localfilecopy_vpath == NULL)
135 return NULL;
137 mc_stat (localfilecopy_vpath, &mystat);
138 localmtime = mystat.st_mtime;
141 return quote_func (vfs_path_get_last_path_str (localfilecopy_vpath), 0);
144 /* --------------------------------------------------------------------------------------------- */
146 static char *
147 exec_get_export_variables (const vfs_path_t * filename_vpath)
149 char *text;
150 GString *export_vars_string;
151 size_t i;
153 /* *INDENT-OFF* */
154 struct
156 const char symbol;
157 const char *name;
158 } export_variables[] = {
159 {'p', "MC_EXT_BASENAME"},
160 {'d', "MC_EXT_CURRENTDIR"},
161 {'s', "MC_EXT_SELECTED"},
162 {'t', "MC_EXT_ONLYTAGGED"},
163 {'\0', NULL}
165 /* *INDENT-ON* */
167 text = exec_get_file_name (filename_vpath);
168 if (text == NULL)
169 return NULL;
171 export_vars_string = g_string_new ("MC_EXT_FILENAME=");
172 g_string_append_printf (export_vars_string, "%s\nexport MC_EXT_FILENAME\n", text);
173 g_free (text);
175 for (i = 0; export_variables[i].name != NULL; i++)
177 text = expand_format (NULL, export_variables[i].symbol, TRUE);
178 if (text != NULL)
180 g_string_append_printf (export_vars_string,
181 "%s=%s\nexport %s\n", export_variables[i].name, text,
182 export_variables[i].name);
183 g_free (text);
186 return g_string_free (export_vars_string, FALSE);
189 /* --------------------------------------------------------------------------------------------- */
191 static char *
192 exec_make_shell_string (const char *lc_data, const vfs_path_t * filename_vpath)
194 GString *shell_string;
195 char lc_prompt[80] = "\0";
196 gboolean parameter_found = FALSE;
197 gboolean expand_prefix_found = FALSE;
199 shell_string = g_string_new ("");
201 for (; *lc_data != '\0' && *lc_data != '\n'; lc_data++)
203 if (parameter_found)
205 if (*lc_data == '}')
207 char *parameter;
209 parameter_found = FALSE;
210 parameter = input_dialog (_("Parameter"), lc_prompt, MC_HISTORY_EXT_PARAMETER, "");
211 if (parameter == NULL)
213 /* User canceled */
214 g_string_free (shell_string, TRUE);
215 exec_cleanup_file_name (filename_vpath, FALSE);
216 return NULL;
218 g_string_append (shell_string, parameter);
219 written_nonspace = TRUE;
220 g_free (parameter);
222 else
224 size_t len = strlen (lc_prompt);
226 if (len < sizeof (lc_prompt) - 1)
228 lc_prompt[len] = *lc_data;
229 lc_prompt[len + 1] = '\0';
233 else if (expand_prefix_found)
235 expand_prefix_found = FALSE;
236 if (*lc_data == '{')
237 parameter_found = TRUE;
238 else
240 int i;
241 char *v;
243 i = check_format_view (lc_data);
244 if (i != 0)
246 lc_data += i - 1;
247 run_view = TRUE;
249 else
251 i = check_format_cd (lc_data);
252 if (i > 0)
254 is_cd = TRUE;
255 quote_func = fake_name_quote;
256 do_local_copy = FALSE;
257 pbuffer = buffer;
258 lc_data += i - 1;
260 else
262 i = check_format_var (lc_data, &v);
263 if (i > 0 && v != NULL)
265 g_string_append (shell_string, v);
266 g_free (v);
267 lc_data += i;
269 else
271 char *text;
273 if (*lc_data != 'f')
274 text = expand_format (NULL, *lc_data, !is_cd);
275 else
277 text = exec_get_file_name (filename_vpath);
278 if (text == NULL)
280 g_string_free (shell_string, TRUE);
281 return NULL;
285 if (!is_cd)
286 g_string_append (shell_string, text);
287 else
289 strcpy (pbuffer, text);
290 pbuffer = strchr (pbuffer, 0);
293 g_free (text);
294 written_nonspace = TRUE;
300 else if (*lc_data == '%')
301 expand_prefix_found = TRUE;
302 else
304 if (*lc_data != ' ' && *lc_data != '\t')
305 written_nonspace = TRUE;
306 if (is_cd)
307 *(pbuffer++) = *lc_data;
308 else
309 g_string_append_c (shell_string, *lc_data);
311 } /* for */
312 return g_string_free (shell_string, FALSE);
315 /* --------------------------------------------------------------------------------------------- */
317 static void
318 exec_extension_view (char *cmd, const vfs_path_t * filename_vpath, int start_line,
319 vfs_path_t * temp_file_name_vpath)
321 int def_hex_mode = mcview_default_hex_mode, changed_hex_mode = 0;
322 int def_nroff_flag = mcview_default_nroff_flag, changed_nroff_flag = 0;
324 mcview_altered_hex_mode = 0;
325 mcview_altered_nroff_flag = 0;
326 if (def_hex_mode != mcview_default_hex_mode)
327 changed_hex_mode = 1;
328 if (def_nroff_flag != mcview_default_nroff_flag)
329 changed_nroff_flag = 1;
331 /* If we've written whitespace only, then just load filename
332 * into view
334 if (written_nonspace)
336 mcview_viewer (cmd, filename_vpath, start_line);
337 mc_unlink (temp_file_name_vpath);
339 else
340 mcview_viewer (NULL, filename_vpath, start_line);
342 if (changed_hex_mode && !mcview_altered_hex_mode)
343 mcview_default_hex_mode = def_hex_mode;
344 if (changed_nroff_flag && !mcview_altered_nroff_flag)
345 mcview_default_nroff_flag = def_nroff_flag;
347 dialog_switch_process_pending ();
350 /* --------------------------------------------------------------------------------------------- */
352 static void
353 exec_extension_cd (void)
355 char *q;
356 vfs_path_t *p_vpath;
358 *pbuffer = '\0';
359 pbuffer = buffer;
360 /* while (*p == ' ' && *p == '\t')
361 * p++;
363 /* Search last non-space character. Start search at the end in order
364 not to short filenames containing spaces. */
365 q = pbuffer + strlen (pbuffer) - 1;
366 while (q >= pbuffer && (*q == ' ' || *q == '\t'))
367 q--;
368 q[1] = 0;
370 p_vpath = vfs_path_from_str_flags (pbuffer, VPF_NO_CANON);
371 do_cd (p_vpath, cd_parse_command);
372 vfs_path_free (p_vpath);
376 /* --------------------------------------------------------------------------------------------- */
378 static void
379 exec_extension (const vfs_path_t * filename_vpath, const char *lc_data, int start_line)
381 char *shell_string, *export_variables;
382 vfs_path_t *temp_file_name_vpath = NULL;
383 int cmd_file_fd;
384 FILE *cmd_file;
385 char *cmd = NULL;
387 g_return_if_fail (lc_data != NULL);
389 pbuffer = NULL;
390 localmtime = 0;
391 quote_func = name_quote;
392 run_view = FALSE;
393 is_cd = FALSE;
394 written_nonspace = FALSE;
396 /* Avoid making a local copy if we are doing a cd */
397 do_local_copy = !vfs_file_is_local (filename_vpath);
399 shell_string = exec_make_shell_string (lc_data, filename_vpath);
401 if (shell_string == NULL)
402 goto ret;
404 if (is_cd)
406 exec_extension_cd ();
407 g_free (shell_string);
408 goto ret;
412 * All commands should be run in /bin/sh regardless of user shell.
413 * To do that, create temporary shell script and run it.
414 * Sometimes it's not needed (e.g. for %cd and %view commands),
415 * but it's easier to create it anyway.
417 cmd_file_fd = mc_mkstemps (&temp_file_name_vpath, "mcext", SCRIPT_SUFFIX);
419 if (cmd_file_fd == -1)
421 message (D_ERROR, MSG_ERROR,
422 _("Cannot create temporary command file\n%s"), unix_error_string (errno));
423 goto ret;
426 cmd_file = fdopen (cmd_file_fd, "w");
427 fputs ("#! /bin/sh\n\n", cmd_file);
429 export_variables = exec_get_export_variables (filename_vpath);
430 if (export_variables != NULL)
432 fprintf (cmd_file, "%s\n", export_variables);
433 g_free (export_variables);
436 fputs (shell_string, cmd_file);
437 g_free (shell_string);
440 * Make the script remove itself when it finishes.
441 * Don't do it for the viewer - it may need to rerun the script,
442 * so we clean up after calling view().
444 if (!run_view)
446 char *file_name;
448 file_name = vfs_path_to_str (temp_file_name_vpath);
449 fprintf (cmd_file, "\n/bin/rm -f %s\n", file_name);
450 g_free (file_name);
453 fclose (cmd_file);
455 if ((run_view && !written_nonspace) || is_cd)
457 mc_unlink (temp_file_name_vpath);
458 vfs_path_free (temp_file_name_vpath);
459 temp_file_name_vpath = NULL;
461 else
463 char *file_name;
465 file_name = vfs_path_to_str (temp_file_name_vpath);
466 /* Set executable flag on the command file ... */
467 mc_chmod (temp_file_name_vpath, S_IRWXU);
468 /* ... but don't rely on it - run /bin/sh explicitly */
469 cmd = g_strconcat ("/bin/sh ", file_name, (char *) NULL);
470 g_free (file_name);
473 if (run_view)
474 exec_extension_view (cmd, filename_vpath, start_line, temp_file_name_vpath);
475 else
477 shell_execute (cmd, EXECUTE_INTERNAL);
478 if (mc_global.tty.console_flag != '\0')
480 handle_console (CONSOLE_SAVE);
481 if (output_lines && mc_global.keybar_visible)
482 show_console_contents (output_start_y,
483 LINES - mc_global.keybar_visible -
484 output_lines - 1, LINES - mc_global.keybar_visible - 1);
488 g_free (cmd);
490 exec_cleanup_file_name (filename_vpath, TRUE);
491 ret:
492 vfs_path_free (temp_file_name_vpath);
495 /* --------------------------------------------------------------------------------------------- */
497 * Run cmd_file with args, put result into buf.
498 * If error, put '\0' into buf[0]
499 * Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
501 * NOTES: buf is null-terminated string.
504 static int
505 get_popen_information (const char *cmd_file, const char *args, char *buf, int buflen)
507 gboolean read_bytes = FALSE;
508 char *command;
509 FILE *f;
511 command = g_strconcat (cmd_file, args, " 2>/dev/null", (char *) NULL);
512 f = popen (command, "r");
513 g_free (command);
515 if (f != NULL)
517 #ifdef __QNXNTO__
518 if (setvbuf (f, NULL, _IOFBF, 0) != 0)
520 (void) pclose (f);
521 return -1;
523 #endif
524 read_bytes = (fgets (buf, buflen, f) != NULL);
525 if (!read_bytes)
526 buf[0] = '\0'; /* Paranoid termination */
527 pclose (f);
529 else
531 buf[0] = '\0'; /* Paranoid termination */
532 return -1;
535 buf[buflen - 1] = '\0';
537 return read_bytes ? 1 : 0;
540 /* --------------------------------------------------------------------------------------------- */
542 * Run the "file" command on the local file.
543 * Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
546 static int
547 get_file_type_local (const vfs_path_t * filename_vpath, char *buf, int buflen)
549 char *tmp;
550 int ret;
552 tmp = name_quote (vfs_path_get_last_path_str (filename_vpath), 0);
553 ret = get_popen_information (FILE_CMD, tmp, buf, buflen);
554 g_free (tmp);
556 return ret;
559 /* --------------------------------------------------------------------------------------------- */
561 * Run the "enca" command on the local file.
562 * Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
565 #ifdef HAVE_CHARSET
566 static int
567 get_file_encoding_local (const vfs_path_t * filename_vpath, char *buf, int buflen)
569 char *tmp, *lang, *args;
570 int ret;
572 tmp = name_quote (vfs_path_get_last_path_str (filename_vpath), 0);
573 lang = name_quote (autodetect_codeset, 0);
574 args = g_strconcat (" -L", lang, " -i ", tmp, (char *) NULL);
576 ret = get_popen_information ("enca", args, buf, buflen);
578 g_free (args);
579 g_free (lang);
580 g_free (tmp);
582 return ret;
584 #endif /* HAVE_CHARSET */
586 /* --------------------------------------------------------------------------------------------- */
588 * Invoke the "file" command on the file and match its output against PTR.
589 * have_type is a flag that is set if we already have tried to determine
590 * the type of that file.
591 * Return 1 for match, 0 for no match, -1 errors.
594 static int
595 regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, int *have_type)
597 int found = 0;
599 /* Following variables are valid if *have_type is 1 */
600 static char content_string[2048];
601 #ifdef HAVE_CHARSET
602 static char encoding_id[21]; /* CSISO51INISCYRILLIC -- 20 */
603 #endif
604 static size_t content_shift = 0;
605 static int got_data = 0;
607 if (!use_file_to_check_type)
608 return 0;
610 if (*have_type == 0)
612 vfs_path_t *localfile_vpath;
613 const char *realname; /* name used with "file" */
615 #ifdef HAVE_CHARSET
616 int got_encoding_data;
617 #endif /* HAVE_CHARSET */
619 /* Don't repeate even unsuccessful checks */
620 *have_type = 1;
622 localfile_vpath = mc_getlocalcopy (filename_vpath);
623 if (localfile_vpath == NULL)
624 return -1;
626 realname = vfs_path_get_last_path_str (localfile_vpath);
628 #ifdef HAVE_CHARSET
629 got_encoding_data = is_autodetect_codeset_enabled
630 ? get_file_encoding_local (localfile_vpath, encoding_id, sizeof (encoding_id)) : 0;
632 if (got_encoding_data > 0)
634 char *pp;
635 int cp_id;
637 pp = strchr (encoding_id, '\n');
638 if (pp != NULL)
639 *pp = '\0';
641 cp_id = get_codepage_index (encoding_id);
642 if (cp_id == -1)
643 cp_id = default_source_codepage;
645 do_set_codepage (cp_id);
647 #endif /* HAVE_CHARSET */
649 mc_ungetlocalcopy (filename_vpath, localfile_vpath, FALSE);
651 got_data = get_file_type_local (localfile_vpath, content_string, sizeof (content_string));
653 if (got_data > 0)
655 char *pp;
656 size_t real_len;
658 pp = strchr (content_string, '\n');
659 if (pp != NULL)
660 *pp = '\0';
662 real_len = strlen (realname);
664 if (strncmp (content_string, realname, real_len) == 0)
666 /* Skip "realname: " */
667 content_shift = real_len;
668 if (content_string[content_shift] == ':')
670 /* Solaris' file prints tab(s) after ':' */
671 for (content_shift++;
672 content_string[content_shift] == ' '
673 || content_string[content_shift] == '\t'; content_shift++)
678 else
680 /* No data */
681 content_string[0] = '\0';
683 vfs_path_free (localfile_vpath);
686 if (got_data == -1)
687 return -1;
689 if (content_string[0] != '\0'
690 && mc_search (ptr, content_string + content_shift, MC_SEARCH_T_REGEX))
692 found = 1;
695 return found;
698 /* --------------------------------------------------------------------------------------------- */
699 /*** public functions ****************************************************************************/
700 /* --------------------------------------------------------------------------------------------- */
702 void
703 flush_extension_file (void)
705 g_free (data);
706 data = NULL;
709 /* --------------------------------------------------------------------------------------------- */
711 * The second argument is action, i.e. Open, View or Edit
713 * This function returns:
715 * -1 for a failure or user interrupt
716 * 0 if no command was run
717 * 1 if some command was run
719 * If action == "View" then a parameter is checked in the form of "View:%d",
720 * if the value for %d exists, then the viewer is started up at that line number.
724 regex_command (const vfs_path_t * filename_vpath, const char *action)
726 char *filename, *p, *q, *r, c;
727 size_t file_len;
728 int found = 0;
729 int error_flag = 0;
730 int ret = 0;
731 struct stat mystat;
732 int view_at_line_number;
733 char *include_target;
734 int include_target_len;
735 int have_type = 0; /* Flag used by regex_check_type() */
737 if (filename_vpath == NULL)
738 return 0;
740 /* Check for the special View:%d parameter */
741 if (strncmp (action, "View:", 5) == 0)
743 view_at_line_number = atoi (action + 5);
744 action = "View";
746 else
748 view_at_line_number = 0;
751 if (data == NULL)
753 char *extension_file;
754 int mc_user_ext = 1;
755 int home_error = 0;
757 extension_file = mc_config_get_full_path (MC_FILEBIND_FILE);
758 if (!exist_file (extension_file))
760 g_free (extension_file);
761 check_stock_mc_ext:
762 extension_file = mc_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
763 if (!exist_file (extension_file))
765 g_free (extension_file);
766 extension_file = mc_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
768 mc_user_ext = 0;
771 g_file_get_contents (extension_file, &data, NULL, NULL);
772 g_free (extension_file);
773 if (data == NULL)
774 return 0;
776 if (!strstr (data, "default/"))
778 if (!strstr (data, "regex/") && !strstr (data, "shell/") && !strstr (data, "type/"))
780 g_free (data);
781 data = NULL;
782 if (mc_user_ext)
784 home_error = 1;
785 goto check_stock_mc_ext;
787 else
789 char *title = g_strdup_printf (_(" %s%s file error"),
790 mc_global.sysconfig_dir, MC_LIB_EXT);
791 message (D_ERROR, title, _("The format of the %smc.ext "
792 "file has changed with version 3.0. It seems that "
793 "the installation failed. Please fetch a fresh "
794 "copy from the Midnight Commander package."),
795 mc_global.sysconfig_dir);
796 g_free (title);
797 return 0;
801 if (home_error)
803 char *filebind_filename = mc_config_get_full_path (MC_FILEBIND_FILE);
804 char *title = g_strdup_printf (_("%s file error"), filebind_filename);
805 message (D_ERROR, title,
806 _("The format of the %s file has "
807 "changed with version 3.0. You may either want to copy "
808 "it from %smc.ext or use that file as an example of how to write it."),
809 filebind_filename, mc_global.sysconfig_dir);
810 g_free (filebind_filename);
811 g_free (title);
815 mc_stat (filename_vpath, &mystat);
817 include_target = NULL;
818 include_target_len = 0;
819 filename = vfs_path_to_str (filename_vpath);
820 file_len = vfs_path_len (filename_vpath);
822 for (p = data; *p; p++)
824 for (q = p; *q == ' ' || *q == '\t'; q++);
825 if (*q == '\n' || !*q)
826 p = q; /* empty line */
827 if (*p == '#') /* comment */
828 while (*p && *p != '\n')
829 p++;
830 if (*p == '\n')
831 continue;
832 if (!*p)
833 break;
834 if (p == q)
835 { /* i.e. starts in the first column, should be
836 * keyword/descNL
838 found = 0;
839 q = strchr (p, '\n');
840 if (q == NULL)
841 q = strchr (p, 0);
842 c = *q;
843 *q = 0;
844 if (include_target)
846 if ((strncmp (p, "include/", 8) == 0)
847 && (strncmp (p + 8, include_target, include_target_len) == 0))
848 found = 1;
850 else if (!strncmp (p, "regex/", 6))
852 p += 6;
853 /* Do not transform shell patterns, you can use shell/ for
854 * that
856 if (mc_search (p, filename, MC_SEARCH_T_REGEX))
857 found = 1;
859 else if (!strncmp (p, "directory/", 10))
861 if (S_ISDIR (mystat.st_mode) && mc_search (p + 10, filename, MC_SEARCH_T_REGEX))
862 found = 1;
864 else if (!strncmp (p, "shell/", 6))
866 p += 6;
867 if (*p == '.' && file_len >= (size_t) (q - p))
869 if (!strncmp (p, filename + file_len - (q - p), q - p))
870 found = 1;
872 else
874 if ((size_t) (q - p) == file_len && !strncmp (p, filename, q - p))
875 found = 1;
878 else if (!strncmp (p, "type/", 5))
880 int res;
881 p += 5;
882 res = regex_check_type (filename_vpath, p, &have_type);
883 if (res == 1)
884 found = 1;
885 if (res == -1)
886 error_flag = 1; /* leave it if file cannot be opened */
888 else if (!strncmp (p, "default/", 8))
890 found = 1;
892 *q = c;
893 p = q;
894 if (!*p)
895 break;
897 else
898 { /* List of actions */
899 p = q;
900 q = strchr (p, '\n');
901 if (q == NULL)
902 q = strchr (p, 0);
903 if (found && !error_flag)
905 r = strchr (p, '=');
906 if (r != NULL)
908 c = *r;
909 *r = 0;
910 if (strcmp (p, "Include") == 0)
912 char *t;
914 include_target = p + 8;
915 t = strchr (include_target, '\n');
916 if (t)
917 *t = 0;
918 include_target_len = strlen (include_target);
919 if (t)
920 *t = '\n';
922 *r = c;
923 p = q;
924 found = 0;
926 if (!*p)
927 break;
928 continue;
931 if (strcmp (action, p) != 0)
932 *r = c;
933 else
935 *r = c;
937 for (p = r + 1; *p == ' ' || *p == '\t'; p++)
940 /* Empty commands just stop searching
941 * through, they don't do anything
943 if (p < q)
945 exec_extension (filename_vpath, r + 1, view_at_line_number);
946 ret = 1;
948 break;
952 p = q;
953 if (!*p)
954 break;
957 g_free (filename);
958 if (error_flag)
959 return -1;
960 return ret;
963 /* --------------------------------------------------------------------------------------------- */