remake  4.3+dbg-1.5
edit.h
Go to the documentation of this file.
1 /* edit starting at current location. */
2 /* Print working directory. */
3 /* Copyright (C) 2004-2005, 2007-2009, 2011, 2020 R. Bernstein
4 <rocky@gnu.org>
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 static debug_return_t
22 dbg_cmd_edit(char *psz_args)
23 {
24  const char *editor;
25 
26  if ((editor = (char *) getenv ("EDITOR")) == NULL)
27  editor = "/bin/ex";
28 
29  if (!psz_args || 0==strlen(psz_args)) {
30  const gmk_floc *p_floc = get_current_floc();
31  if (p_floc) {
32  unsigned int cmd_size = strlen(editor) + strlen(p_floc->filenm) + 20;
33  char *edit_cmd = calloc(1, cmd_size);
34  int rc;
35  /* Quote the file name, in case it has whitespace or other special
36  characters. */
37  snprintf(edit_cmd, cmd_size,
38  "%s +%lu \"%s\"", editor, p_floc->lineno, p_floc->filenm);
39  printf(_("Running %s\n"), edit_cmd);
40  rc = system (edit_cmd);
41  shell_rc_status(rc);
42  } else {
43  printf (_("cannot get target file location\n"));
44  }
45  } else {
46  printf(_("The \"edit\" command does not take an argument: %s\n"), psz_args);
47  }
48  return debug_readloop;
49 }
50 
51 static void
52 dbg_cmd_edit_init(unsigned int c)
53 {
54  short_command[c].func = &dbg_cmd_edit;
55  short_command[c].use = _("edit");
56 }
57 
58 /*
59  * Local variables:
60  * eval: (c-set-style "gnu")
61  * indent-tabs-mode: nil
62  * End:
63  */
void shell_rc_status(int rc)
const gmk_floc * get_current_floc(void)
debug_return_t
Definition: trace.h:32
#define _(msgid)
Definition: make.h:293
Definition: trace.h:40
unsigned long lineno
Definition: gnuremake.h:26
Definition: gnuremake.h:23
const char * filenm
Definition: gnuremake.h:25