#include "leak_detector.h"

#include <cstdio>
#include <cstdlib>

#include <string>
#include <vector>

#include "errors.h"
#include "SgUtils.h"

#include "StdCapture.h"

using namespace std;

extern int pppa_analyzer(int argv, char** argc);

int pppaAnalyzer(const char* options)
{
    string optionsS(options);
    vector<string> splited = splitAndArgvCreate(optionsS);

    char** argv = new char* [splited.size()];
    for (int z = 0; z < splited.size(); ++z)
        argv[z] = (char*)splited[z].c_str();

    StdCapture::Init();
    string errorMessage = "";
    int retCode = pppa_analyzer(splited.size(), argv);
    StdCapture::EndCapture();
    errorMessage = StdCapture::GetCapture();

    delete []argv;
    return retCode;
}

void pppaAnalyzer(int argc, char** argv)
{
    int code = pppa_analyzer(argc, argv);
    if (code == 0)
        printf("PPPA was completed successfully\n");
    else
        printf("PPPA was completed with error code %d\n", code);
    exit(0);
}
