printInfo
This commit is contained in:
@ -23,6 +23,8 @@ typedef struct openfiles_s {
|
|||||||
files_t *f;
|
files_t *f;
|
||||||
char *wDir; // for files sent from the server after openFile
|
char *wDir; // for files sent from the server after openFile
|
||||||
char *rDir; // for files read from the server
|
char *rDir; // for files read from the server
|
||||||
|
int print; // whether to print
|
||||||
|
FILE *out; // where to print
|
||||||
} openfiles_t;
|
} openfiles_t;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -62,6 +64,8 @@ int openConnection(const char* sockname, int msec, const struct timespec abstime
|
|||||||
openedFiles->numOfFiles = 0;
|
openedFiles->numOfFiles = 0;
|
||||||
openedFiles->rDir = NULL;
|
openedFiles->rDir = NULL;
|
||||||
openedFiles->wDir = NULL;
|
openedFiles->wDir = NULL;
|
||||||
|
openedFiles->print = 0;
|
||||||
|
openedFiles->out = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sockaddr_un sa;
|
struct sockaddr_un sa;
|
||||||
@ -178,7 +182,10 @@ int setDirectory(char* Dir, int rw) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printInfo(int p) {
|
void printInfo(int p, FILE *stream) {
|
||||||
|
// 1 prints, 0 does not print
|
||||||
|
openedFiles->print = (p)? 1: 0;
|
||||||
|
openedFiles->out = stream;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,6 +38,6 @@ int removeFile(const char* pathname);
|
|||||||
|
|
||||||
int setDirectory(char* Dir, int rw);
|
int setDirectory(char* Dir, int rw);
|
||||||
|
|
||||||
void printInfo(int p);
|
void printInfo(int p, FILE *stream);
|
||||||
|
|
||||||
#endif /* _API_CLIENT */
|
#endif /* _API_CLIENT */
|
||||||
|
|||||||
@ -134,7 +134,7 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'p': // print to stdout
|
case 'p': // print to stdout
|
||||||
printInfo(1);
|
printInfo(1, stdout);
|
||||||
++print;
|
++print;
|
||||||
break;
|
break;
|
||||||
case 'w': // send files from folder (n is specified after)
|
case 'w': // send files from folder (n is specified after)
|
||||||
@ -656,13 +656,13 @@ int cmd_r(char *filelist, char *dir, int print) {
|
|||||||
void *buf = NULL;
|
void *buf = NULL;
|
||||||
size_t size = -1;
|
size_t size = -1;
|
||||||
|
|
||||||
printInfo(0);
|
printInfo(0, stdout);
|
||||||
// read the content of the file
|
// read the content of the file
|
||||||
if (ok && readFile(token, &buf, &size) == -1) {
|
if (ok && readFile(token, &buf, &size) == -1) {
|
||||||
ok = 0;
|
ok = 0;
|
||||||
}
|
}
|
||||||
if (print) {
|
if (print) {
|
||||||
printInfo(1);
|
printInfo(1, stdout);
|
||||||
}
|
}
|
||||||
if (ok && print) {
|
if (ok && print) {
|
||||||
printf("Dimensione: %zu B\t", size);
|
printf("Dimensione: %zu B\t", size);
|
||||||
|
|||||||
Reference in New Issue
Block a user