#include <stdlib.h>
#include <locale.h>

#include "Reduce.h"
#include "Errors.h"

int main(int argc, char *argv[])
{
    char *output_file = DReduceOutputFileName;
    int nreducers = 1;

    if (argc > 3) {
        Error("[WordCountReduce] Usage: WordCountReduce [output_file] [nreducers]");
    }

    if (argc >= 2) {
        output_file = argv[1];
    }

    if (argc == 3) {
        nreducers = atoi(argv[2]);
    }

    if (nreducers < 1) {
        Error("[WordCountReduce] Invalid number of reducers");
    }

    setlocale(LC_ALL, "");
    wordcount_reducer(output_file, nreducers);

    return 0;
}
