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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
/*
* Silly little bodge for getting GNU make to pass long commands
* to broken programs like the Microsoft and Watcom linkers. This
* tool is built with gcc, and invoked using GNU make. It echoes
* the arguments into a temporary file, and then passes that as a
* script to the utility in question. Ugly, but it does the job.
* An @ symbol marks that all commands from here on should go in
* the argument file, and a \ character indicates to convert slashes
* from / to \ format.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char **__crt0_glob_function(char *_arg)
{
/* don't let djgpp glob our command line arguments */
return NULL;
}
int main(int argc, char *argv[])
{
char buf[256] = "";
FILE *f = NULL;
int flip_slashes = 0;
int ret, i, j;
char *p;
if (argc < 2) {
printf("Usage: runner program args\n");
return 1;
}
for (i=1; i<argc; i++) {
if ((strcmp(argv[i], "\\") == 0) || (strcmp(argv[i], "\\\\") == 0)) {
flip_slashes = 1;
}
else if (strcmp(argv[i], "@") == 0) {
if (!f) {
f = fopen("_tmpfile.arg", "w");
if (!f) {
printf("Error writing _tmpfile.arg\n");
return 1;
}
}
}
else if (f) {
if (flip_slashes) {
for (j=0; argv[i][j]; j++) {
if (argv[i][j] == '/')
fputc('\\', f);
else
fputc(argv[i][j], f);
}
fputc('\n', f);
}
else
fprintf(f, "%s\n", argv[i]);
}
else {
if (buf[0])
strncat(buf, " ", sizeof(buf)-1);
if (flip_slashes) {
j = strlen(buf);
strncat(buf, argv[i], sizeof(buf)-1);
while (buf[j]) {
if (buf[j] == '/')
buf[j] = '\\';
j++;
}
}
else
strncat(buf, argv[i], sizeof(buf)-1);
}
}
if (f) {
fclose(f);
strncat(buf, " @_tmpfile.arg", sizeof(buf)-1);
}
p = strchr(buf, ' ');
if (p) {
if (strlen(p) >= 126) {
fprintf(stderr, "Runner oops: command line is longer than 126 characters!\n");
remove("_tmpfile.arg");
return 1;
}
}
ret = system(buf);
remove("_tmpfile.arg");
return ret;
}
|