Skip to content

Commit

Permalink
Reduce code duplication.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@81389 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
kalibera committed Dec 17, 2021
1 parent 30a4e76 commit 30e8b92
Showing 1 changed file with 6 additions and 45 deletions.
51 changes: 6 additions & 45 deletions src/gnuwin32/front-ends/rcmdfn.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 2000-2020 R Core Team
* Copyright (C) 2000-2021 R Core Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -119,7 +119,7 @@ int rcmdfn (int cmdarg, int argc, char **argv)
read R_HOME\etc\Rcmd_environ
launch %R_HOME%\bin\$*
*/
int i, iused, status = 0;
int i, iused;
char *p, cmd[CMD_LEN];
char RCMD[] = "R CMD";
int len = strlen(argv[0]);
Expand Down Expand Up @@ -167,21 +167,9 @@ int rcmdfn (int cmdarg, int argc, char **argv)
return(0);
}
snprintf(cmd, CMD_LEN, "\"\"%s/%s/Rterm.exe\"", getRHOME(3), BINDIR);
for (i = cmdarg + 1; i < argc; i++){
strcat(cmd, " ");
if (strlen(cmd) + strlen(argv[i]) > 9900) {
fprintf(stderr, "command line too long\n");
return(27);
}
strcat(cmd, "\"");
strcat(cmd, argv[i]);
strcat(cmd, "\"");
}
/* the outermost double quotes are needed for cmd.exe */
strcat(cmd, "\"");
/* R.exe should ignore Ctrl-C, and let Rterm.exe handle it */
SetConsoleCtrlHandler(NULL, TRUE);
return system(cmd);
PROCESS_CMD(" ");
}

/* From here on down, this was called as Rcmd or R CMD */
Expand Down Expand Up @@ -397,20 +385,7 @@ int rcmdfn (int cmdarg, int argc, char **argv)
snprintf(cmd, CMD_LEN,
"\"\"%s/%s/Rterm.exe\" -f \"%s/share/R/REMOVE.R\" R_DEFAULT_PACKAGES=NULL --no-restore --no-echo --args",
getRHOME(3), BINDIR, getRHOME(3));
for (i = cmdarg + 1; i < argc; i++){
strcat(cmd, " ");
if (strlen(cmd) + strlen(argv[i]) > 9900) {
fprintf(stderr, "command line too long\n");
return(27);
}
/* Library names could contain spaces and other special characters */
strcat(cmd, "\"");
strcat(cmd, argv[i]);
strcat(cmd, "\"");
}
/* the outermost double quotes are needed for cmd.exe */
strcat(cmd, "\"");
return(system(cmd));
PROCESS_CMD(" ");
} else if (!strcmp(argv[cmdarg], "build")) {
snprintf(cmd, CMD_LEN,
"\"\"%s/%s/Rterm.exe\" -e tools:::.build_packages() R_DEFAULT_PACKAGES= LC_COLLATE=C --no-restore --no-echo --args ",
Expand Down Expand Up @@ -483,21 +458,7 @@ int rcmdfn (int cmdarg, int argc, char **argv)
else strcpy(cmd, "\"");
strcat(cmd, p);
}

for (i = cmdarg + 1; i < argc; i++){
strcat(cmd, " ");
if (strlen(cmd) + strlen(argv[i]) > 9900) {
fprintf(stderr, "command line too long\n");
return(27);
}
strcat(cmd, "\"");
strcat(cmd, argv[i]);
strcat(cmd, "\"");
}
/* the outermost double quotes are needed for cmd.exe */
strcat(cmd, "\"");
/* printf("cmd is %s\n", cmd); */
status = system(cmd);
PROCESS_CMD(" ");
}
return(status);
/* not reachable */
}

0 comments on commit 30e8b92

Please sign in to comment.