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