Added command line argument for '-f <filename>' that executes the commands found in the file.
This commit is contained in:
Markus Makela 2014-12-04 14:16:45 +02:00
parent 84679a48ff
commit 5cfbfe39ac

View File

@ -55,6 +55,8 @@
#include <histedit.h>
#endif
#define BUFFSIZE 2048
static int connectMaxScale(char *hostname, char *port);
static int setipaddress(struct in_addr *a, char *p);
static int authMaxScale(int so, char *user, char *password);
@ -111,12 +113,16 @@ char *passwd = NULL;
int so;
int option_index = 0;
char c;
FILE* localfile = NULL;
while ((c = getopt_long(argc, argv, "h:p:P:u:v?",
while ((c = getopt_long(argc, argv, "f:h:p:P:u:v?",
long_options, &option_index))
>= 0)
{
switch (c) {
case 'f':
localfile = fopen(optarg,"r");
break;
case 'h':
hostname = strdup(optarg);
break;
@ -175,7 +181,19 @@ char c;
exit(1);
}
if (optind < argc) {
if(localfile){
char buffer[BUFFSIZE];
fgets(buffer,BUFFSIZE,localfile);
while(!feof(localfile)){
sendCommand(so, buffer);
fgets(buffer,BUFFSIZE,localfile);
}
fclose(localfile);
exit(0);
}else if (optind < argc) {
int i, len = 0;
char *cmd;