process remaining non-option command line arguments as command string

or command file to source (as before)
This commit is contained in:
Hartmut Holzgraefe
2014-09-22 18:37:27 +02:00
parent 6a03976e4f
commit 1c07f10d50

View File

@ -107,15 +107,10 @@ char *hostname = "localhost";
char *port = "6603"; char *port = "6603";
char *user = "admin"; char *user = "admin";
char *passwd = NULL; char *passwd = NULL;
int so, cmdlen; int so;
char *cmd;
int option_index = 0; int option_index = 0;
char c; char c;
cmd = malloc(1);
*cmd = 0;
cmdlen = 1;
while ((c = getopt_long(argc, argv, "h:p:P:u:v?", while ((c = getopt_long(argc, argv, "h:p:P:u:v?",
long_options, &option_index)) long_options, &option_index))
>= 0) >= 0)
@ -179,14 +174,28 @@ char c;
exit(1); exit(1);
} }
if (cmdlen > 1) if (optind < argc) {
{ int i, len = 0;
cmd[cmdlen - 2] = '\0'; /* Remove trailing space */ char *cmd;
if (access(cmd, R_OK) == 0)
DoSource(so, cmd); for (i = optind; i < argc; i++) {
else len += strlen(argv[i]) + 1;
sendCommand(so, cmd); }
exit(0);
cmd = malloc(len);
strcpy(cmd, argv[optind]);
for (i = optind +1; i < argc; i++) {
strcat(cmd, " ");
strcat(cmd, argv[i]);
}
if (access(cmd, R_OK) == 0)
DoSource(so, cmd);
else
sendCommand(so, cmd);
free(cmd);
exit(0);
} }
(void) setlocale(LC_CTYPE, ""); (void) setlocale(LC_CTYPE, "");