Encoder-nyuenc / src / main / parser.c
parser.c
Raw
#include <stdio.h>
#include <getopt.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#include "utils.h"

void parseCommand(int argc, char **argv) {

    int opt;
    jobs = 1;
    while ((opt = getopt(argc, argv, "j:")) != -1) {
        switch (opt) {
            case 'j':
                jobs = atoi(optarg);
                break;
            default:
                fprintf(stderr, "Usage: %s [-j jobs]\n", argv[0]);
                exit(0);
        }
    }

    int fileDescriptor;
    struct stat fileStatistics;
    fileCount = argc - optind;
    for (int i = 0; i < fileCount; i ++) {
        fileDescriptor = open(argv[optind + i], O_RDONLY);
        fstat(fileDescriptor, &fileStatistics);
        fileContents[i] = mmap(NULL, fileStatistics.st_size, PROT_READ, MAP_PRIVATE, fileDescriptor, 0);
        fileLengths[i] = fileStatistics.st_size;
    }

}