Ejemplo n.º 1
0
Archivo: cmd.c Proyecto: ebichu/dd-wrt
int
view_file_at_line (const char *filename, int plain_view, int internal,
		   int start_line)
{
    static const char *viewer = NULL;
    int move_dir = 0;


    if (plain_view) {
	int changed_hex_mode = 0;
	int changed_nroff_flag = 0;
	int changed_magic_flag = 0;

	altered_hex_mode = 0;
	altered_nroff_flag = 0;
	altered_magic_flag = 0;
	if (default_hex_mode)
	    changed_hex_mode = 1;
	if (default_nroff_flag)
	    changed_nroff_flag = 1;
	if (default_magic_flag)
	    changed_magic_flag = 1;
	default_hex_mode = 0;
	default_nroff_flag = 0;
	default_magic_flag = 0;
	mc_internal_viewer (NULL, filename, &move_dir, start_line);
	if (changed_hex_mode && !altered_hex_mode)
	    default_hex_mode = 1;
	if (changed_nroff_flag && !altered_nroff_flag)
	    default_nroff_flag = 1;
	if (changed_magic_flag && !altered_magic_flag)
	    default_magic_flag = 1;
	repaint_screen ();
	return move_dir;
    }
    if (internal) {
	char view_entry[BUF_TINY];

	if (start_line != 0)
	    g_snprintf (view_entry, sizeof (view_entry), "View:%d",
			start_line);
	else
	    strcpy (view_entry, "View");

	if (regex_command (filename, view_entry, &move_dir) == 0) {
	    mc_internal_viewer (NULL, filename, &move_dir, start_line);
	    repaint_screen ();
	}
    } else {
	if (!viewer) {
	    viewer = getenv ("VIEWER");
	    if (!viewer)
		viewer = getenv ("PAGER");
	    if (!viewer)
		viewer = "view";
	}
	execute_with_vfs_arg (viewer, filename);
    }
    return move_dir;
}
Ejemplo n.º 2
0
Archivo: cmd.c Proyecto: ebichu/dd-wrt
void
filtered_view_cmd (void)
{
    char *command;

    command =
	input_dialog (_(" Filtered view "),
		      _(" Filter command and arguments:"),
		      MC_HISTORY_FM_FILTERED_VIEW,
		      selection (current_panel)->fname);
    if (!command)
	return;

    mc_internal_viewer (command, "", NULL, 0);

    g_free (command);
}
Ejemplo n.º 3
0
Archivo: user.c Proyecto: dborca/mc
/* FIXME: recode this routine on version 3.0, it could be cleaner */
static void
execute_menu_command (WEdit *edit_widget, const char *commands)
{
    FILE *cmd_file;
    int  cmd_file_fd;
    int  expand_prefix_found = 0;
    char *parameter = 0;
    int  do_quote = 0;
    char prompt [80];
    int  col;
    char *file_name;
    int run_view = 0;

    /* Skip menu entry title line */
    commands = strchr (commands, '\n');
    if (!commands){
	return;
    }

    cmd_file_fd = mc_mkstemps (&file_name, "mcusr", SCRIPT_SUFFIX);

    if (cmd_file_fd == -1){
	message (1, 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);
    commands++;
    
    for (col = 0; *commands; commands++){
	if (col == 0) {
	    if (*commands != ' ' && *commands != '\t')
		break;
	    while (*commands == ' ' || *commands == '\t')
	        commands++;
	    if (*commands == 0)
		break;
	}
	col++;
	if (*commands == '\n')
	    col = 0;
	if (parameter){
	    if (*commands == '}'){
		char *tmp;
		*parameter = 0;
		parameter = input_dialog (_(" Parameter "), prompt, INPUT_LAST_TEXT);
		if (!parameter){
		    /* User canceled */
		    fclose (cmd_file);
		    unlink (file_name);
                    g_free (file_name);
		    return;
		}
		if (do_quote) {
    		    fputs (tmp = name_quote (parameter, 0), cmd_file);
		    g_free (tmp);
		} else
		    fputs (parameter, cmd_file);
		g_free (parameter);
		parameter = 0;
	    } else {
		if (parameter < &prompt [sizeof (prompt) - 1]) {
		    *parameter++ = *commands;
		} 
	    }
	} else if (expand_prefix_found){
	    expand_prefix_found = 0;
	    if (isdigit ((unsigned char) *commands)) {
		do_quote = atoi (commands);
		while (isdigit ((unsigned char) *commands))
		    commands++;
	    }
	    if (*commands == '{')
		parameter = prompt;
	    else{
		char *text = expand_format (edit_widget, *commands, do_quote);
		fputs (text, cmd_file);
		g_free (text);
	    }
	} else {
	    if (*commands == '%') {
		int i = check_format_view (commands + 1);
		if (i) {
		    commands += i;
		    run_view = 1;
		} else {
		    do_quote = 1; /* Default: Quote expanded macro */
		    expand_prefix_found = 1;
		}
	    } else
		fputc (*commands, cmd_file);
	}
    }
    fclose (cmd_file);
    chmod (file_name, S_IRWXU);
    if (run_view) {
	run_view = 0;
	mc_internal_viewer (file_name, NULL, &run_view, 0);
#ifdef USE_DLGSWITCH
	dlgswitch_process_pending();
#endif
    } else {
	/* execute the command indirectly to allow execution even
	 * on no-exec filesystems. */
	char *cmd = g_strconcat("/bin/sh ", file_name, (char *)NULL);
	shell_execute (cmd, EXECUTE_HIDE);
	g_free(cmd);
    }
    unlink (file_name);
    g_free (file_name);
}