2 * Copyright 2005-2007, Ingo Weinhold, bonefish@cs.tu-berlin.de.
3 * Distributed under the terms of the MIT License.
6 #include "fs_shell_command.h"
14 add_char(char *&buffer
, int &bufferSize
, char c
)
16 if (bufferSize
<= 0) {
17 fprintf(stderr
, "Error: Command line too long\n");
28 prepare_command_string(const char *const *argv
, int argc
, char *buffer
,
31 for (int argi
= 0; argi
< argc
; argi
++) {
32 const char *arg
= argv
[argi
];
35 add_char(buffer
, bufferSize
, ' ');
38 if (strchr(" \"'\\", *arg
))
39 add_char(buffer
, bufferSize
, '\\');
40 add_char(buffer
, bufferSize
, *arg
);
45 add_char(buffer
, bufferSize
, '\0');
50 main(int argc
, const char *const *argv
)
53 fprintf(stderr
, "Error: No command given.\n");
57 if (strcmp(argv
[1], "--uses-fifos") == 0)
58 exit(gUsesFifos
? 0 : 1);
60 // prepare the command string
62 prepare_command_string(argv
+ 1, argc
- 1, command
, sizeof(command
));
66 if (!send_external_command(command
, &result
))
71 fprintf(stderr
, "Error: Command failed: %s\n", strerror(result
));
72 fprintf(stderr
, "Error: Command was:\n %s\n", command
);