/* This is a personal academic project. Dear PVS-Studio, please check it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com */ #define _POSIX_C_SOURCE 200112L #include #include #include #include "error.h" #include "shr_mem.h" #include "siglib.h" #include "view.h" int main(int argc, char * argv[]) { char amount[MAX_AMOUNT_SIZE] = {0}; char masterPid[MAX_PID_SIZE] = {0}; switch (argc) { case 1: fgets(amount, MAX_AMOUNT_SIZE, stdin); amount[strcspn(amount, "\n")] = '\0'; fgets(masterPid, MAX_PID_SIZE, stdin); masterPid[strcspn(masterPid, "\n")] = '\0'; break; case 3: strncpy(amount, argv[1], MAX_AMOUNT_SIZE - 1); strncpy(masterPid, argv[2], MAX_PID_SIZE - 1); amount[MAX_AMOUNT_SIZE - 1] = '\0'; masterPid[MAX_PID_SIZE - 1] = '\0'; break; default: printError("View must receive the amount of files and the pid of master process by argument or stdin -- ERROR"); } int files = atoi(amount); int mPid = atoi(masterPid); sendStartSignal(mPid); int totalSize = files * MAX_OUTPUT_SIZE; char * shmPointer, * shmStart; int fd = openCreatedShm(&shmPointer, totalSize); shmStart = shmPointer; char buf[MAX_SIZE]; while (files-- > 0) { shmPointer += readShm(shmPointer, buf, MAX_SIZE); printf("%s\n", buf); } closeCreatedShm(shmStart, totalSize, fd); sendFinishSignal(mPid); return EXIT_SUCCESS; }