|
1 | 1 | /*
|
2 | 2 | * R : A Computer Language for Statistical Data Analysis
|
3 |
| - * Copyright (C) 2006-2017 The R Core Team |
| 3 | + * Copyright (C) 2006-2018 The R Core Team |
4 | 4 | *
|
5 | 5 | * This program is free software; you can redistribute it and/or modify
|
6 | 6 | * it under the terms of the GNU General Public License as published by
|
@@ -132,24 +132,32 @@ int main(int argc_, char *argv_[])
|
132 | 132 |
|
133 | 133 | argv_[1] is split here into individual arguments assuming any space or
|
134 | 134 | tab is a separator - no quoting is supported
|
| 135 | +
|
| 136 | + This code is, however, also used with explicit invocation of Rscript |
| 137 | + where arguments are not joined and the first argument may be a file |
| 138 | + name, which is explicitly allowed to contain space. Thus, only split the |
| 139 | + first argument if it starts with "--" (a file name for Rscript cannot |
| 140 | + start with "--"; it can start with "-", but the only short option is "-e" |
| 141 | + and that is not usable with '#!' invocation). |
135 | 142 | */
|
136 | 143 |
|
137 | 144 | /* compute number of arguments included in argv_[1] */
|
138 | 145 | char *s = argv_[1];
|
139 | 146 | int njoined = 0;
|
140 | 147 | size_t j;
|
141 |
| - for(j = 0; s[j] != 0; j++) |
142 |
| - if (s[j] != ' ' && s[j] != '\t' && |
143 |
| - (j == 0 || s[j-1] == ' ' || s[j-1] == '\t')) |
144 |
| - /* first character of an argument */ |
145 |
| - njoined++; |
| 148 | + if (strncmp(s, "--", 2) == 0) |
| 149 | + for(j = 0; s[j] != 0; j++) |
| 150 | + if (s[j] != ' ' && s[j] != '\t' && |
| 151 | + (j == 0 || s[j-1] == ' ' || s[j-1] == '\t')) |
| 152 | + /* first character of an argument */ |
| 153 | + njoined++; |
146 | 154 |
|
147 | 155 | int argc;
|
148 | 156 | char **argv;
|
149 | 157 |
|
150 | 158 | if (njoined > 1) { /* need to split argv_[1] */
|
151 | 159 | argc = argc_ - 1 + njoined;
|
152 |
| - argv = (char **) malloc((size_t) (argc+1)*sizeof(char *)); |
| 160 | + argv = (char **) malloc((size_t) (argc+1)*sizeof(char *)); |
153 | 161 | if (!argv) {
|
154 | 162 | fprintf(stderr, "malloc failure\n");
|
155 | 163 | exit(1);
|
|
0 commit comments