struct linebuf lbuf;
input = skip_whitespace (input);
- for (p = input; !isspace ((int) *p); p++) {
+ /*for (p = input; !isspace ((int) *p); p++) {
if (*p == '/') {
*p = '\\';
}
- }
+ }*/
if ((p = strchr (input, ' '))) {
}
- } else {
+ }/* else {
if (lpApplicationName) {
free (lpApplicationName);
lpApplicationName = 0;
- }
+ }*/
memset (&sa, 0, sizeof (sa));
memset (&si, 0, sizeof (si));
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ()));
+ if (state->keep_going) {
+ return 0;
+ }
+
exit (EXIT_FAILURE);
}
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ()));
+ if (state->keep_going) {
+ return 0;
+ }
+
exit (EXIT_FAILURE);
}
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ()));
+ if (state->keep_going) {
+ return 0;
+ }
+
exit (EXIT_FAILURE);
}
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ()));
+ if (state->keep_going) {
+ return 0;
+ }
+
exit (EXIT_FAILURE);
}
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ()));
+ if (state->keep_going) {
+ return 0;
+ }
+
exit (EXIT_FAILURE);
}
#if defined (_WIN32) || defined (__WIN32__)
# include <windows.h>
-static void pipe_command (const char *filename, unsigned long line_no, char *input, int is_ignoring_errors, const char *name) {
+static char *internal_commands[] = {
+
+ "assoc",
+ "break",
+ "call",
+ "cd",
+ "chcp",
+ "chdir",
+ "cls",
+ "color",
+ "copy",
+ "ctty",
+ "date",
+ "del",
+ "dir",
+ "echo",
+ "echo.",
+ "endlocal",
+ "erase",
+ "exit",
+ "for",
+ "ftype",
+ "goto",
+ "if",
+ "md",
+ "mkdir",
+ "move",
+ "path",
+ "pause",
+ "prompt",
+ "rd",
+ "rem",
+ "ren",
+ "rename",
+ "rmdir",
+ "set",
+ "setlocal",
+ "shift",
+ "time",
+ "title",
+ "type",
+ "ver",
+ "verify",
+ "vol",
+ 0
+
+};
+
+static int pipe_command (const char *filename, unsigned long line_no, char *input, int is_ignoring_errors, const char *name) {
DWORD dwExitCode;
HANDLE hStdInPipeRead, hStdInPipeWrite;
HANDLE hStdOutPipeRead, hStdOutPipeWrite;
- char *lpApplicationName = getenv ("COMSPEC"), *lpCommandLine = 0;
- struct linebuf lbuf;
+ char *lpApplicationName = 0, *lpCommandLine = 0;
+ char *p;
+ struct linebuf lbuf;
input = skip_whitespace (input);
/*for (p = input; !isspace ((int) *p); p++) {
}*/
- lpCommandLine = xmalloc (4 + strlen (input) + 1);
- sprintf (lpCommandLine, "/C %s", input);
+ if ((p = strchr (input, ' '))) {
+
+ lpApplicationName = xstrndup (input, p - input);
+ lpCommandLine = xstrdup (skip_whitespace (p));
+
+ } else {
+ lpApplicationName = xstrdup (skip_whitespace (input));
+ }
+
+ if (!(p = strchr (lpApplicationName, '\\'))) {
+
+ unsigned long count = sizeof (internal_commands) / sizeof (internal_commands[0]), i;
+
+ for (i = 0; i < count; i++) {
+
+ if (strcasecmp (lpApplicationName, internal_commands[i]) == 0) {
+
+ if (lpApplicationName) {
+ free (lpApplicationName);
+ }
+
+ if (lpCommandLine) {
+ free (lpCommandLine);
+ }
+
+ lpCommandLine = xmalloc (4 + strlen (input) + 1);
+ sprintf (lpCommandLine, "/C %s", input);
+
+ lpApplicationName = xstrdup (getenv ("COMSPEC"));
+ break;
+
+ }
+
+ }
+
+ }/* else {
+
+ if (lpApplicationName) {
+ free (lpApplicationName);
+ }
+
+ lpApplicationName = 0;
+
+ }*/
memset (&sa, 0, sizeof (sa));
memset (&si, 0, sizeof (si));
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ()));
+ if (state->keep_going) {
+ return 1;
+ }
+
exit (EXIT_FAILURE);
}
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ()));
+ if (state->keep_going) {
+ return 1;
+ }
+
exit (EXIT_FAILURE);
}
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ()));
+ if (state->keep_going) {
+ return 1;
+ }
+
exit (EXIT_FAILURE);
}
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ()));
+ if (state->keep_going) {
+ return 1;
+ }
+
exit (EXIT_FAILURE);
}
fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input);
fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ()));
+ if (state->keep_going) {
+ return 1;
+ }
+
exit (EXIT_FAILURE);
}
fprintf (stderr, "%s", lbuf.start);
fprintf (stderr, "%s: *** [%s:%lu: %s] Error %ld\n", program_name, filename, line_no, name, dwExitCode);
+ if (state->keep_going) {
+ return dwExitCode;
+ }
+
exit (EXIT_FAILURE);
}
} else {
printf ("%s", lbuf.start);
}
+
+ return 0;
}
#elif defined (_WIN32) || defined (__WIN32__) || defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__)
# include <sys/wait.h>
# include <errno.h>
# include <unistd.h>
-static void pipe_command (const char *filename, unsigned long line_no, char *input, int is_ignoring_errors, const char *name) {
+static int pipe_command (const char *filename, unsigned long line_no, char *input, int is_ignoring_errors, const char *name) {
int pipefd[2], pid, status;
if (pid == 0) {
- char *name = input, *space = 0, *slash;
+ char *prog = input, *space = 0, *slash;
- if ((space = strchr (name, ' '))) {
- name = xstrndup (name, space - name);
+ if ((space = strchr (prog, ' '))) {
+ prog = xstrndup (prog, space - prog);
}
dup2 (pipefd[1], STDOUT_FILENO);
close (pipefd[0]);
close (pipefd[1]);
- execlp (name, (slash = strrchr (name, '/')) ? (slash + 1) : name, space ? skip_whitespace (space) : NULL, NULL);
+ execlp (prog, (slash = strrchr (prog, '/')) ? (slash + 1) : prog, space ? skip_whitespace (space) : NULL, NULL);
+
+ printf ("%s: %s: %s\n", program_name, prog, strerror (errno));
exit (EXIT_FAILURE);
}
}
- if (status) {
-
- if (!is_ignoring_errors) {
-
- char *space, *p = input;
-
- if ((space = strchr (p, ' '))) {
- p = xstrndup (p, space - p);
- }
-
- fprintf (stderr, "%s: %s: No such file or directory\n", program_name, p);
- fprintf (stderr, "%s: *** [%s:%lu: %s] Error %d\n", program_name, filename, line_no, name, status);
-
- exit (EXIT_FAILURE);
-
- }
-
- } else {
+ {
char *p = lbuf.start, ch;
if (isspace ((int) *(p - 1))) {
*(p - 1) = '\0';
}
+
+ }
+
+ if (status) {
+
+ if (!is_ignoring_errors) {
- printf ("%s\n", lbuf.start);
+ fprintf (stderr, "%s\n", lbuf.start);
+ fprintf (stderr, "%s: *** [%s:%lu: %s] Error %d\n", program_name, filename, line_no, name, status);
+
+ if (state->keep_going) {
+ return status;
+ }
+
+ exit (EXIT_FAILURE);
+
+ }
+ } else {
+ printf ("%s\n", lbuf.start);
}
+
+ return 0;
}
#endif
static int rule_run_command (const char *filename, unsigned long line_no, const char *name, char *p, char *q) {
char *new_cmds, *s;
+ int status = 0;
int is_ignoring_errors = state->ignore_errors;
int is_quiet = state->quiet;
if (should_execute) {
#if defined (_WIN32) || defined (__WIN32__) || defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__)
- pipe_command (filename, line_no, s, is_ignoring_errors, name);
+ status = pipe_command (filename, line_no, s, is_ignoring_errors, name);
#else
- int status = system (s);
-
- if (!is_ignoring_errors && status) {
+ if ((status = system (s)) && !is_ignoring_errors) {
char *space, *p = s;
fprintf (stderr, "%s: %s: No such file or directory\n", program_name, p);
fprintf (stderr, "%s: *** [%s:%lu: %s] Error %d\n", program_name, filename, line_no, name, status);
+
+ if (!keep_going) {
+ exit (EXIT_FAILURE);
+ }
}
#endif
}
free (new_cmds);
- return 0;
+ return status;
}
if (!q) { break; };
- if ((error = rule_run_command (filename, line_no, name, p, q)) < 0) {
+ if ((error = rule_run_command (filename, line_no, name, p, q))) {
return error;
}
for (i = 0; i < state->nb_goals; i++) {
if ((ret = rule_search_and_build (state->goals[i]))) {
- goto out;
+
+ if (!state->keep_going) {
+ goto out;
+ }
+
}
}