| 51536 |
ripley |
1 |
/*
|
|
|
2 |
* R : A Computer Language for Statistical Data Analysis
|
| 59039 |
ripley |
3 |
* Copyright (C) 2010 R Core Team
|
| 51536 |
ripley |
4 |
*
|
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
8 |
* (at your option) any later version.
|
|
|
9 |
*
|
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
13 |
* GNU General Public License for more details.
|
|
|
14 |
*
|
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
|
16 |
* along with this program; if not, a copy is available at
|
|
|
17 |
* http://www.r-project.org/Licenses/
|
|
|
18 |
*/
|
|
|
19 |
|
|
|
20 |
#include <stdlib.h> /* for exit */
|
|
|
21 |
#include <string.h>
|
|
|
22 |
#include <stdio.h>
|
|
|
23 |
|
| 52990 |
ripley |
24 |
extern char *getRHOME(int); /* in ../rhome.c */
|
| 51891 |
ripley |
25 |
|
| 52990 |
ripley |
26 |
static void Usage (char *RCMD, char *arch)
|
|
|
27 |
{
|
|
|
28 |
fprintf(stderr, "%s %s %s", "Usage:", RCMD, "[command args]\n\n");
|
|
|
29 |
fprintf(stderr, "%s%s%s",
|
|
|
30 |
"where 'command args' can be\n\n",
|
|
|
31 |
" --arch n for n=i386, x64, 32 or 64\n",
|
|
|
32 |
" any other arguments listed by ");
|
|
|
33 |
fprintf(stderr, "%s --arch %s --help\n", RCMD, arch);
|
|
|
34 |
}
|
| 51891 |
ripley |
35 |
|
| 51536 |
ripley |
36 |
#define CMD_LEN 10000
|
|
|
37 |
int main (int argc, char **argv)
|
|
|
38 |
{
|
|
|
39 |
int cmdarg = 1;
|
| 51891 |
ripley |
40 |
char arch[10] = R_ARCH, cmd[CMD_LEN], *p;
|
| 51536 |
ripley |
41 |
|
| 52990 |
ripley |
42 |
if (argc > 1 && strcmp(argv[1], "--help") == 0) {
|
|
|
43 |
Usage(argv[0], arch);
|
|
|
44 |
exit(0);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
if (argc > 1 && strcmp(argv[1], "--arch") == 0) {
|
| 51536 |
ripley |
48 |
cmdarg = 3;
|
| 52990 |
ripley |
49 |
if(argc < 3) {
|
|
|
50 |
Usage(argv[0], arch);
|
|
|
51 |
exit(0);
|
|
|
52 |
}
|
| 51536 |
ripley |
53 |
strncpy(arch, argv[2], 10); arch[9] = '\0';
|
|
|
54 |
if(strcmp(arch, "32") == 0) strcpy(arch, "i386");
|
|
|
55 |
if(strcmp(arch, "64") == 0) strcpy(arch, "x64");
|
|
|
56 |
if(strcmp(arch, "i386") && strcmp(arch, "x64")) {
|
|
|
57 |
fprintf(stderr, "valid values for --arch are i386, x64, 32, 64\n");
|
|
|
58 |
exit(1);
|
|
|
59 |
}
|
| 51891 |
ripley |
60 |
} else if ((p = getenv("R_ARCH")))
|
|
|
61 |
strncpy(arch, p+1, 10); /* skip leading slash */
|
|
|
62 |
|
| 51536 |
ripley |
63 |
|
| 51891 |
ripley |
64 |
if (stricmp(argv[0] + strlen(argv[0]) - 11, "Rscript.exe") == 0
|
|
|
65 |
|| stricmp(argv[0] + strlen(argv[0]) - 7, "Rscript") == 0)
|
|
|
66 |
snprintf(cmd, CMD_LEN, "%s\\bin\\%s\\Rscript.exe", getRHOME(2), arch);
|
|
|
67 |
else
|
|
|
68 |
snprintf(cmd, CMD_LEN, "%s\\bin\\%s\\R.exe", getRHOME(2), arch);
|
|
|
69 |
|
| 51536 |
ripley |
70 |
for(int i = cmdarg; i < argc; i++) {
|
|
|
71 |
strcat(cmd, " ");
|
|
|
72 |
if(strchr(argv[i], ' ')) {
|
| 51891 |
ripley |
73 |
strcat(cmd, "\"");
|
| 51875 |
ripley |
74 |
/* We should really escape " here, I believe */
|
| 51536 |
ripley |
75 |
strcat(cmd, argv[i]);
|
|
|
76 |
strcat(cmd, "\"");
|
|
|
77 |
} else strcat(cmd, argv[i]);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
exit(system(cmd));
|
|
|
81 |
}
|