Skip to content

Commit 30e8b92

Browse files
author
kalibera
committed
Reduce code duplication.
git-svn-id: https://svn.r-project.org/R/trunk@81389 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 30a4e76 commit 30e8b92

File tree

1 file changed

+6
-45
lines changed

1 file changed

+6
-45
lines changed

src/gnuwin32/front-ends/rcmdfn.c

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* R : A Computer Language for Statistical Data Analysis
3-
* Copyright (C) 2000-2020 R Core Team
3+
* Copyright (C) 2000-2021 R Core Team
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -119,7 +119,7 @@ int rcmdfn (int cmdarg, int argc, char **argv)
119119
read R_HOME\etc\Rcmd_environ
120120
launch %R_HOME%\bin\$*
121121
*/
122-
int i, iused, status = 0;
122+
int i, iused;
123123
char *p, cmd[CMD_LEN];
124124
char RCMD[] = "R CMD";
125125
int len = strlen(argv[0]);
@@ -167,21 +167,9 @@ int rcmdfn (int cmdarg, int argc, char **argv)
167167
return(0);
168168
}
169169
snprintf(cmd, CMD_LEN, "\"\"%s/%s/Rterm.exe\"", getRHOME(3), BINDIR);
170-
for (i = cmdarg + 1; i < argc; i++){
171-
strcat(cmd, " ");
172-
if (strlen(cmd) + strlen(argv[i]) > 9900) {
173-
fprintf(stderr, "command line too long\n");
174-
return(27);
175-
}
176-
strcat(cmd, "\"");
177-
strcat(cmd, argv[i]);
178-
strcat(cmd, "\"");
179-
}
180-
/* the outermost double quotes are needed for cmd.exe */
181-
strcat(cmd, "\"");
182170
/* R.exe should ignore Ctrl-C, and let Rterm.exe handle it */
183171
SetConsoleCtrlHandler(NULL, TRUE);
184-
return system(cmd);
172+
PROCESS_CMD(" ");
185173
}
186174

187175
/* From here on down, this was called as Rcmd or R CMD */
@@ -397,20 +385,7 @@ int rcmdfn (int cmdarg, int argc, char **argv)
397385
snprintf(cmd, CMD_LEN,
398386
"\"\"%s/%s/Rterm.exe\" -f \"%s/share/R/REMOVE.R\" R_DEFAULT_PACKAGES=NULL --no-restore --no-echo --args",
399387
getRHOME(3), BINDIR, getRHOME(3));
400-
for (i = cmdarg + 1; i < argc; i++){
401-
strcat(cmd, " ");
402-
if (strlen(cmd) + strlen(argv[i]) > 9900) {
403-
fprintf(stderr, "command line too long\n");
404-
return(27);
405-
}
406-
/* Library names could contain spaces and other special characters */
407-
strcat(cmd, "\"");
408-
strcat(cmd, argv[i]);
409-
strcat(cmd, "\"");
410-
}
411-
/* the outermost double quotes are needed for cmd.exe */
412-
strcat(cmd, "\"");
413-
return(system(cmd));
388+
PROCESS_CMD(" ");
414389
} else if (!strcmp(argv[cmdarg], "build")) {
415390
snprintf(cmd, CMD_LEN,
416391
"\"\"%s/%s/Rterm.exe\" -e tools:::.build_packages() R_DEFAULT_PACKAGES= LC_COLLATE=C --no-restore --no-echo --args ",
@@ -483,21 +458,7 @@ int rcmdfn (int cmdarg, int argc, char **argv)
483458
else strcpy(cmd, "\"");
484459
strcat(cmd, p);
485460
}
486-
487-
for (i = cmdarg + 1; i < argc; i++){
488-
strcat(cmd, " ");
489-
if (strlen(cmd) + strlen(argv[i]) > 9900) {
490-
fprintf(stderr, "command line too long\n");
491-
return(27);
492-
}
493-
strcat(cmd, "\"");
494-
strcat(cmd, argv[i]);
495-
strcat(cmd, "\"");
496-
}
497-
/* the outermost double quotes are needed for cmd.exe */
498-
strcat(cmd, "\"");
499-
/* printf("cmd is %s\n", cmd); */
500-
status = system(cmd);
461+
PROCESS_CMD(" ");
501462
}
502-
return(status);
463+
/* not reachable */
503464
}

0 commit comments

Comments
 (0)