remake  4.3+dbg-1.5
source.h
Go to the documentation of this file.
1 /* Continue until the next command to be executed. */
2 #define DEPENDS_COMMANDS " depends commands"
3 
4 #include <glob.h>
5 #include "help/source.h"
6 
7 static debug_return_t
8 dbg_cmd_source(char *psz_filename)
9 {
10  if (psz_filename && *psz_filename) {
11  FILE *p_source_file;
12  char *psz_expanded_file;
13  glob_t p;
14 
15  glob(psz_filename, 0, NULL, &p);
16  if (0 == p.gl_pathc) {
17  struct stat stat_buf;
18  int ret = stat(psz_filename, &stat_buf);
19  if (ret != 0) {
20  dbg_errmsg("Can't find file %s:\n\t%s", psz_filename, strerror(errno));
21  return debug_cmd_error;
22  }
23  psz_expanded_file = psz_filename;
24  } else if (1 != p.gl_pathc) {
25  dbg_errmsg("Expansion of %s doesn't lead to a single filename. \n"
26  "Got %zu matches",
27  psz_filename, (size_t)p.gl_pathv);
28  return debug_cmd_error;
29 
30  } else {
31  psz_expanded_file = p.gl_pathv[0];
32  }
33 
34  p_source_file = fopen(psz_expanded_file, "r");
35 
36  if (p_source_file != NULL) {
37  debug_return_t debug_return = debug_readloop;
38  char line[2048];
39  while (!feof(p_source_file) && debug_return == debug_readloop)
40  {
41  char *s;
42  char *shut_up_gcc_warning = fgets(line, 2048, p_source_file);
43  if (feof(p_source_file)) break;
44  chomp(shut_up_gcc_warning);
45  if ( *(s=stripwhite(line)) ) debug_return=execute_line(s);
46  }
47  fclose(p_source_file);
48  } else
49  dbg_errmsg("error reading file %s (expanded to %s):\n\t%s",
50  psz_filename, psz_expanded_file, strerror(errno));
51 
52  globfree(&p);
53  } else {
54  dbg_errmsg("Expecting a file name");
55  return debug_cmd_error;
56  }
57  return debug_readloop;
58 }
59 
60 static void
61 dbg_cmd_source_init(unsigned int c)
62 {
63  short_command[c].func = &dbg_cmd_source;
64  short_command[c].use = _("source *file-glob*");
65 }
66 
67 
68 /*
69  * Local variables:
70  * eval: (c-set-style "gnu")
71  * indent-tabs-mode: nil
72  * End:
73  */
debug_return_t execute_line(char *psz_line)
void dbg_errmsg()
void chomp(char *line)
char * stripwhite(char *string)
debug_return_t
Definition: trace.h:32
#define _(msgid)
Definition: make.h:293
Definition: trace.h:40
int errno
Definition: trace.h:42