This commit is contained in:
elvis
2022-04-24 01:36:43 +02:00
parent 4fe23200bc
commit 9eaf9cdd49
9 changed files with 163 additions and 82 deletions

View File

@ -107,7 +107,6 @@ int main(int argc, char* argv[]) {
// lista dei comandi
cmd_t *cmds = NULL;
cmds = calloc(1, sizeof(cmd_t));
int opt = 0;
char args[MAXARGLENGTH];
@ -246,7 +245,6 @@ int addCommand(cmd_t **l, char cmd, char *arg) {
strncpy(new->arg, arg, strnlen(arg, MAXARGLENGTH-1)+1);
}
new->next = NULL;
cmd_t *tail = *l;
// se lista vuota aggiungo in cima, altrimenti scorro la lista
if (*l == NULL) {
@ -254,6 +252,7 @@ int addCommand(cmd_t **l, char cmd, char *arg) {
return 0;
}
cmd_t *tail = *l;
while (tail->next) {
tail = tail->next;
}
@ -290,7 +289,7 @@ int execute(cmd_t *l, int print) {
interval.tv_sec = (num/1000);
if (print)
printf("\nt - Tempo fra due richieste: %ld ms\tEsito: ok\n", num);
fprintf(stdout, "t - Tempo fra due richieste: %ld ms\tEsito: ok\n", num);
break;
}
@ -300,6 +299,8 @@ int execute(cmd_t *l, int print) {
tmp = tmp->next;
}
fflush(stdout);
// loop that serches for -f
tmp = l;
while(tmp) {
@ -313,7 +314,7 @@ int execute(cmd_t *l, int print) {
ok = 0;
}
if (print) {
printf("\nf - Connessione al socket: %s\tEsito: ", globalSocket);
fprintf(stdout, "f - Connessione al socket: %s\tEsito: ", globalSocket);
if(ok)
printf("ok\n");
if(!ok)
@ -329,8 +330,11 @@ int execute(cmd_t *l, int print) {
default:
break;
}
tmp = tmp->next;
if(tmp)
tmp = tmp->next;
}
fflush(stdout);
// loop that checks for consistencies:
// 1) -D with no -w or -W after
// 2) -d with no -r or -R after
@ -341,7 +345,7 @@ int execute(cmd_t *l, int print) {
switch (tmp->name) {
case 'D':
if(unmachedD) {
printf("\nError: -D has no -w or -W matching after\n");
fprintf(stdout, "\nError: -D has no -w or -W matching after\n");
return 0;
}
unmachedD = 1;
@ -352,7 +356,7 @@ int execute(cmd_t *l, int print) {
break;
case 'd':
if(unmachedd) {
printf("\nError: -d has no -r or -R matching after\n");
fprintf(stdout, "\nError: -d has no -r or -R matching after\n");
return 0;
}
unmachedd = 1;
@ -367,13 +371,14 @@ int execute(cmd_t *l, int print) {
tmp = tmp->next;
}
if(unmachedD) {
printf("\nError: -D has no -w or -W matching after\n");
fprintf(stdout, "\nError: -D has no -w or -W matching after\n");
return 0;
}
if(unmachedd) {
printf("\nError: -d has no -r or -R matching after\n");
fprintf(stdout, "\nError: -d has no -r or -R matching after\n");
return 0;
}
fflush(stdout);
char *Dir = NULL; // -D folder
char *dir = NULL; // -d folder
@ -509,7 +514,7 @@ int cmd_w(char *dirname, char *Dir, int print) {
}
if (print) {
printf("\nw - Scrivo i seguenti file sul server:");
printf("\nw - Scrivo i seguenti file sul server: ");
fflush(stdout);
}
@ -568,7 +573,7 @@ int cmd_W(char *filelist, char *Dir, int print) {
char *string = tofree;
if (print == 1) {
printf("W - Scrivo i seguenti file sul server:\n");
printf("W - Scrivo i seguenti file sul server: \n");
fflush(stdout);
}