-w, -W, -r all working

This commit is contained in:
elvis
2022-04-29 01:26:31 +02:00
parent 59814f06db
commit b0b9310acc
4 changed files with 40 additions and 14 deletions

View File

@ -491,7 +491,7 @@ int cmd_w(char *dirname, char *Dir, int print) {
int num;
// we copy dirname because we are nice
char *tofree = malloc(strnlen(dirname, MAXARGLENGTH)+1);
char *tofree = calloc(strnlen(dirname, MAXARGLENGTH)+1, sizeof(char));
if(!tofree) {
perror("malloc");
return -1;
@ -522,7 +522,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: \n");
fflush(stdout);
}
@ -544,12 +544,22 @@ int cmd_w(char *dirname, char *Dir, int print) {
snprintf(tmp, child->fts_namelen + child->fts_pathlen + 2, "%s/%s", child->fts_path, child->fts_name);
if(print) {
printf("%s\n", tmp);
printf("%s [", tmp);
}
// we send the file with the other function but set print to
// 0 since we do the printing before
cmd_W(tmp, Dir, 0);
int r = cmd_W(tmp, Dir, 0);
if(print && !r) {
printf("Esito: ok");
} else if (print && r) {
printf("Esito: errore");
}
if(print) {
printf("]\n");
}
free(tmp);
--num;
@ -586,6 +596,7 @@ int cmd_W(char *filelist, char *Dir, int print) {
fflush(stdout);
}
int r = 0;
while ((token = strsep_gnu(&string, ",")) != NULL) {
int ok = 1;
int opened = 0;
@ -624,10 +635,12 @@ int cmd_W(char *filelist, char *Dir, int print) {
printf("]\n");
fflush(stdout);
}
if(!ok)
r = -1;
}
free(tofree);
return 0;
return r;
}
int cmd_r(char *filelist, char *dir, int print) {