| 1 | /* edit starting at current location. */ |
| 2 | /* Print working directory. */ |
| 3 | /* Copyright (C) 2004-2005, 2007-2009, 2011, 2020 R. Bernstein |
| 4 | <[email protected]> |
| 5 | This file is part of GNU Make (remake variant). |
| 6 | |
| 7 | GNU Make is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2, or (at your option) |
| 10 | any later version. |
| 11 | |
| 12 | GNU Make is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with GNU Make; see the file COPYING. If not, write to |
| 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | Boston, MA 02111-1307, USA. */ |
| 21 | |
| 22 | /** \file libdebugger/command/edit.c |
| 23 | * |
| 24 | * \brief Debugger `edit` command. |
| 25 | */ |
| 26 | |
| 27 | |
| 28 | #include "../../src/makeint.h" |
| 29 | #include "../../src/function.h" |
| 30 | #include "../../src/trace.h" |
| 31 | #include "../fns.h" |
| 32 | |
| 33 | |
| 34 | extern debug_return_t |
| 35 | dbg_cmd_edit(char *psz_args) |
| 36 | { |
| 37 | const char *editor; |
| 38 | |
| 39 | if ((editor = (char *) getenv ("EDITOR")) == NULL) |
| 40 | editor = "/bin/ex"; |
| 41 | |
| 42 | if (!psz_args || 0==strlen(psz_args)) { |
| 43 | const gmk_floc *p_floc = get_current_floc(); |
| 44 | if (p_floc) { |
| 45 | unsigned int cmd_size = strlen(editor) + strlen(p_floc->filenm) + 20; |
| 46 | char *edit_cmd = calloc(1, cmd_size); |
| 47 | int rc; |
| 48 | /* Quote the file name, in case it has whitespace or other special |
| 49 | characters. */ |
| 50 | snprintf(edit_cmd, cmd_size, |
| 51 | "%s +%lu \"%s\"", editor, p_floc->lineno, p_floc->filenm); |
| 52 | printf(_("Running %s\n"), edit_cmd); |
| 53 | rc = system (edit_cmd); |
| 54 | shell_rc_status(rc); |
| 55 | } else { |
| 56 | printf (_("cannot get target file location\n")); |
| 57 | } |
| 58 | } else { |
| 59 | printf(_("The \"edit\" command does not take an argument: %s\n"), psz_args); |
| 60 | } |
| 61 | return debug_readloop; |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Local variables: |
| 66 | * eval: (c-set-style "gnu") |
| 67 | * indent-tabs-mode: nil |
| 68 | * End: |
| 69 | */ |