| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#include "../../src/trace.h" |
| 27 |
#include "../cmd.h" |
| 28 |
#include "../fns.h" |
| 29 |
#include "../msg.h" |
| 30 |
|
| 31 |
#define DEPENDS_COMMANDS " depends commands" |
| 32 |
|
| 33 |
#include <glob.h> |
| 34 |
#include "help/source.h" |
| 35 |
|
| 36 |
extern debug_return_t |
| 37 |
dbg_cmd_source(char *psz_filename) |
| 38 |
{ |
| 39 |
if (psz_filename && *psz_filename) { |
| 40 |
FILE *p_source_file; |
| 41 |
char *psz_expanded_file; |
| 42 |
glob_t p; |
| 43 |
|
| 44 |
glob(psz_filename, 0, NULL, &p); |
| 45 |
if (0 == p.gl_pathc) { |
| 46 |
struct stat stat_buf; |
| 47 |
int ret = stat(psz_filename, &stat_buf); |
| 48 |
if (ret != 0) { |
| 49 |
dbg_errmsg("Can't find file %s:\n\t%s", psz_filename, strerror(errno)); |
| 50 |
return debug_cmd_error; |
| 51 |
} |
| 52 |
psz_expanded_file = psz_filename; |
| 53 |
} else if (1 != p.gl_pathc) { |
| 54 |
dbg_errmsg("Expansion of %s doesn't lead to a single filename. \n" |
| 55 |
"Got %zu matches", |
| 56 |
psz_filename, (size_t)p.gl_pathv); |
| 57 |
return debug_cmd_error; |
| 58 |
|
| 59 |
} else { |
| 60 |
psz_expanded_file = p.gl_pathv[0]; |
| 61 |
} |
| 62 |
|
| 63 |
p_source_file = fopen(psz_expanded_file, "r"); |
| 64 |
|
| 65 |
if (p_source_file != NULL) { |
| 66 |
debug_return_t debug_return = debug_readloop; |
| 67 |
char line[2048]; |
| 68 |
while (!feof(p_source_file) && debug_return == debug_readloop) |
| 69 |
{ |
| 70 |
char *s; |
| 71 |
char *shut_up_gcc_warning = fgets(line, 2048, p_source_file); |
| 72 |
if (feof(p_source_file)) break; |
| 73 |
chomp(shut_up_gcc_warning); |
| 74 |
if ( *(s=stripwhite(line)) ) debug_return=execute_line(s); |
| 75 |
} |
| 76 |
fclose(p_source_file); |
| 77 |
} else |
| 78 |
dbg_errmsg("error reading file %s (expanded to %s):\n\t%s", |
| 79 |
psz_filename, psz_expanded_file, strerror(errno)); |
| 80 |
|
| 81 |
globfree(&p); |
| 82 |
} else { |
| 83 |
dbg_errmsg("Expecting a file name"); |
| 84 |
return debug_cmd_error; |
| 85 |
} |
| 86 |
return debug_readloop; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|