Ticket #2206: 0001-Add-lineno-support.patch

File 0001-Add-lineno-support.patch, 9.8 KB (added by bsv, 15 years ago)
  • lib/util.h

    From 4c3ef7d6f222112c5884672d3797be4b0e36d049 Mon Sep 17 00:00:00 2001
    From: Bezrodnev Sergey <bsvskip@rambler.ru>
    Date: Thu, 20 May 2010 16:16:28 +0400
    Subject: [PATCH] Add +lineno support for vim, emacs, nano after search for editing or
     viewing.
     Signed-off-by: Bezrodnev Sergey <bsvskip@rambler.ru>
    
    ---
     lib/util.h             |    2 +-
     lib/utilunix.c         |    7 +++++--
     lib/vfs/mc-vfs/extfs.c |    2 +-
     lib/vfs/mc-vfs/sfs.c   |    4 ++--
     src/cmd.c              |   46 ++++++++++++++++++++++++++++++++++++++++++++--
     src/execute.c          |   25 +++++++++++++------------
     src/execute.h          |    9 +++++----
     7 files changed, 71 insertions(+), 24 deletions(-)
    
    diff --git a/lib/util.h b/lib/util.h
    index 22c5d71..43d9962 100644
    a b void check_error_pipe (void); 
    138138int close_error_pipe (int error, const char *text); 
    139139 
    140140/* Process spawning */ 
    141 int my_system (int flags, const char *shell, const char *command); 
     141int my_system (int flags, const char *shell, const char *command, const char *arg); 
    142142void save_stop_handler (void); 
    143143extern struct sigaction startup_handler; 
    144144 
  • lib/utilunix.c

    diff --git a/lib/utilunix.c b/lib/utilunix.c
    index f7835fb..3cbebed 100644
    a b save_stop_handler (void) 
    146146} 
    147147 
    148148int 
    149 my_system (int flags, const char *shell, const char *command) 
     149my_system (int flags, const char *shell, const char *command, const char *arg) 
    150150{ 
    151151    struct sigaction ignore, save_intr, save_quit, save_stop; 
    152152    pid_t pid; 
    my_system (int flags, const char *shell, const char *command) 
    189189            else 
    190190                only_cmd = (*shell_tokens != NULL) ? *shell_tokens : shell; 
    191191 
    192             execlp (only_cmd, shell, command, (char *) NULL); 
     192            if (flags & EXECUTE_WITH_ARG) 
     193                execlp (only_cmd, shell, arg, command, (char *) NULL); 
     194            else 
     195                execlp (only_cmd, shell, command, (char *) NULL); 
    193196 
    194197            /* 
    195198               execlp will replace current process, 
  • lib/vfs/mc-vfs/extfs.c

    diff --git a/lib/vfs/mc-vfs/extfs.c b/lib/vfs/mc-vfs/extfs.c
    index 73a59ae..50f72b2 100644
    a b extfs_cmd (const char *str_extfs_cmd, struct archive *archive, 
    775775    g_free (archive_name); 
    776776 
    777777    open_error_pipe (); 
    778     retval = my_system (EXECUTE_AS_SHELL, shell, cmd); 
     778    retval = my_system (EXECUTE_AS_SHELL, shell, cmd, NULL); 
    779779    g_free (cmd); 
    780780    close_error_pipe (D_ERROR, NULL); 
    781781    return retval; 
  • lib/vfs/mc-vfs/sfs.c

    diff --git a/lib/vfs/mc-vfs/sfs.c b/lib/vfs/mc-vfs/sfs.c
    index 0c8d570..a6a1248 100644
    a b sfs_vfmake (struct vfs_class *me, const char *name, char *cache) 
    155155 
    156156    g_free (pqname); 
    157157    open_error_pipe (); 
    158     if (my_system (EXECUTE_AS_SHELL, "/bin/sh", pad)) { 
     158    if (my_system (EXECUTE_AS_SHELL, "/bin/sh", pad, NULL)) { 
    159159        close_error_pipe (D_ERROR, NULL); 
    160160        return -1; 
    161161    } 
    static int sfs_init (struct vfs_class *me) 
    388388            default: 
    389389                fprintf (stderr, _("Warning: Invalid flag %c in %s:\n%s\n"), 
    390390                         *c, "sfs.ini", key); 
    391             }        
     391            } 
    392392            c++; 
    393393        } 
    394394        if (!*c) 
  • src/cmd.c

    diff --git a/src/cmd.c b/src/cmd.c
    index 39b4cf1..78c4433 100644
    a b view_file_at_line (const char *filename, int plain_view, int internal, int start 
    170170    } 
    171171    else 
    172172    { 
     173        static char run_arg[20]; 
     174        static int use_arg = 0; 
     175 
    173176        if (!viewer) 
    174177        { 
     178            const char *viewers[] = { "vim", "emacs", "nano", NULL }; 
     179            int i = 0; 
     180 
    175181            viewer = getenv ("VIEWER"); 
    176182            if (!viewer) 
    177183                viewer = getenv ("PAGER"); 
    178184            if (!viewer) 
    179185                viewer = "view"; 
     186 
     187            while (viewers[i] != NULL) 
     188            { 
     189                if (strlen(viewer) == strlen(viewers[i]) && 
     190                    strncmp(viewer, viewers[i], strlen(viewers[i])) == 0) 
     191                { 
     192                    use_arg = 1; 
     193                    break; 
     194                } 
     195                i++; 
     196            } 
    180197        } 
    181         execute_with_vfs_arg (viewer, filename); 
     198 
     199        if (use_arg) 
     200            snprintf(run_arg, 20, "+%d", start_line); 
     201 
     202        execute_with_vfs_arg (viewer, filename, (use_arg ? run_arg : NULL)); 
    182203    } 
    183204    return move_dir; 
    184205} 
    do_edit_at_line (const char *what, int start_line) 
    324345    (void) start_line; 
    325346#endif /* USE_INTERNAL_EDIT */ 
    326347    { 
     348        static char run_arg[20]; 
     349        static int use_arg = 0; 
     350 
    327351        if (editor == NULL) 
    328352        { 
     353            const char *editors[] = { "vim", "emacs", "nano", NULL }; 
     354            int i = 0; 
     355 
    329356            editor = getenv ("EDITOR"); 
    330357            if (editor == NULL) 
    331358                editor = get_default_editor (); 
     359 
     360            while (editors[i] != NULL) 
     361            { 
     362                if (strlen(editor) == strlen(editors[i]) && 
     363                    strncmp(editor, editors[i], strlen(editors[i])) == 0) 
     364                { 
     365                    use_arg = 1; 
     366                    break; 
     367                } 
     368                i++; 
     369            } 
    332370        } 
    333         execute_with_vfs_arg (editor, what); 
     371 
     372        if (use_arg) 
     373            snprintf(run_arg, 20, "+%d", start_line); 
     374 
     375        execute_with_vfs_arg (editor, what, (use_arg ? run_arg : NULL)); 
    334376    } 
    335377    if (mc_run_mode == MC_RUN_FULL) 
    336378    { 
  • src/execute.c

    diff --git a/src/execute.c b/src/execute.c
    index 234429c..0db7e5f 100644
    a b  
    11/* Execution routines for GNU Midnight Commander 
    22   Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc. 
    3     
     3 
    44   This program is free software; you can redistribute it and/or modify 
    55   it under the terms of the GNU General Public License as published by 
    66   the Free Software Foundation; either version 2 of the License, or 
    77   (at your option) any later version. 
    8     
     8 
    99   This program is distributed in the hope that it will be useful, 
    1010   but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1111   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    do_possible_cd (const char *new_dir) 
    112112#endif                          /* HAVE_SUBSHELL_SUPPORT */ 
    113113 
    114114static void 
    115 do_execute (const char *lc_shell, const char *command, int flags) 
     115do_execute (const char *lc_shell, const char *command, int flags, const char *arg) 
    116116{ 
    117117#ifdef HAVE_SUBSHELL_SUPPORT 
    118118    char *new_dir = NULL; 
    do_execute (const char *lc_shell, const char *command, int flags) 
    146146#endif                          /* !ENABLE_VFS */ 
    147147    } else 
    148148#endif                          /* HAVE_SUBSHELL_SUPPORT */ 
    149         my_system (flags, lc_shell, command); 
     149        my_system (flags, lc_shell, command, arg); 
    150150 
    151151    if (!(flags & EXECUTE_INTERNAL)) { 
    152152        if ((pause_after_run == pause_always 
    shell_execute (const char *command, int flags) 
    210210#ifdef HAVE_SUBSHELL_SUPPORT 
    211211    if (use_subshell) 
    212212        if (subshell_state == INACTIVE) 
    213             do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL); 
     213            do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL, NULL); 
    214214        else 
    215215            message (D_ERROR, MSG_ERROR, 
    216216                     _(" The shell is already running a command ")); 
    217217    else 
    218218#endif                          /* HAVE_SUBSHELL_SUPPORT */ 
    219         do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL); 
     219        do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL, NULL); 
    220220 
    221221    g_free (cmd); 
    222222} 
    shell_execute (const char *command, int flags) 
    225225void 
    226226exec_shell (void) 
    227227{ 
    228     do_execute (shell, 0, 0); 
     228    do_execute (shell, 0, 0, NULL); 
    229229} 
    230230 
    231231 
    toggle_panels (void) 
    270270                     _("Type `exit' to return to the Midnight Commander")); 
    271271            fprintf (stderr, "\n\r\n\r"); 
    272272 
    273             my_system (EXECUTE_INTERNAL, shell, NULL); 
     273            my_system (EXECUTE_INTERNAL, shell, NULL, NULL); 
    274274        } else 
    275275            get_key_code (0); 
    276276    } 
    suspend_cmd (void) 
    358358 * Errors are reported to the user. 
    359359 */ 
    360360void 
    361 execute_with_vfs_arg (const char *command, const char *filename) 
     361execute_with_vfs_arg (const char *command, const char *filename, const char *arg) 
    362362{ 
    363363    char *localcopy; 
    364364    char *fn; 
    execute_with_vfs_arg (const char *command, const char *filename) 
    367367 
    368368    /* Simplest case, this file is local */ 
    369369    if (!filename || vfs_file_is_local (filename)) { 
     370        int flags = EXECUTE_INTERNAL | (arg == NULL ? 0 : EXECUTE_WITH_ARG); 
    370371        fn = vfs_canon_and_translate (filename); 
    371         do_execute (command, fn, EXECUTE_INTERNAL); 
     372        do_execute (command, fn, flags, arg); 
    372373        g_free (fn); 
    373         return; 
     374        return; 
    374375    } 
    375376 
    376377    /* FIXME: Creation of new files on VFS is not supported */ 
    execute_with_vfs_arg (const char *command, const char *filename) 
    392393    fn = g_strdup (filename); 
    393394    mc_stat (localcopy, &st); 
    394395    mtime = st.st_mtime; 
    395     do_execute (command, localcopy, EXECUTE_INTERNAL); 
     396    do_execute (command, localcopy, EXECUTE_INTERNAL, NULL); 
    396397    mc_stat (localcopy, &st); 
    397398    mc_ungetlocalcopy (fn, localcopy, mtime != st.st_mtime); 
    398399    g_free (localcopy); 
  • src/execute.h

    diff --git a/src/execute.h b/src/execute.h
    index 977961c..5caf7d4 100644
    a b  
    77#define MC_EXECUTE_H 
    88 
    99/* flags for shell_execute */ 
    10 #define EXECUTE_INTERNAL        (1 << 0) 
    11 #define EXECUTE_AS_SHELL        (1 << 2) 
    12 #define EXECUTE_HIDE            (1 << 3) 
     10#define EXECUTE_INTERNAL    (1 << 0) 
     11#define EXECUTE_AS_SHELL    (1 << 2) 
     12#define EXECUTE_HIDE        (1 << 3) 
     13#define EXECUTE_WITH_ARG    (1 << 4) 
    1314 
    1415/* Execute functions that use the shell to execute */ 
    1516void shell_execute (const char *command, int flags); 
    void toggle_panels (void); 
    2425void suspend_cmd (void); 
    2526 
    2627/* Execute command on a filename that can be on VFS */ 
    27 void execute_with_vfs_arg (const char *command, const char *filename); 
     28void execute_with_vfs_arg (const char *command, const char *filename, const char *arg); 
    2829 
    2930#endif /* !MC_EXECUTE_H */