#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <pslib.h>
#include <psmodules.h>

#include "ppArith.h"

int main(int argc, char *argv[])
{
    psExit exitValue = PS_EXIT_SUCCESS; // Exit value
    psTimerStart("ppArith");
    psLibInit(NULL);

    pmConfig *config = pmConfigRead(&argc, argv, PPARITH_RECIPE); // Configuration
    if (!config) {
        psErrorStackPrint(stderr, "Error reading configuration.");
        exitValue = PS_EXIT_CONFIG_ERROR;
        goto die;
    }

    if (!ppArithArguments(argc, argv, config)) {
        psErrorStackPrint(stderr, "Error reading arguments.\n");
        exitValue = PS_EXIT_CONFIG_ERROR;
        goto die;
    }

    if (!ppArithLoop(config)) {
        psErrorStackPrint(stderr, "Error performing arithmetic.\n");
        exitValue = PS_EXIT_PROG_ERROR;
        goto die;
    }

 die:
    psTrace("ppArith", 1, "Finished at %f sec\n", psTimerMark("ppArith"));
    psTimerStop();

    psFree(config);
    pmConfigDone();
    psLibFinalize();

    exit(exitValue);
}
