#include "streaksremove.h"

psString pathToDirectory(char *path)
{
    // insure that path ends in /
    int len = strlen(path);
    psString dir = NULL;
    if (strrchr(path, '/') != (path + len - 1)) {
        psStringAppend(&dir, "%s/", path);
    } else {
        dir = psStringCopy(path);
    }
    return dir;
}

ippStage
parseStage(psString stageStr)
{
    if (!strcmp("raw", stageStr)) {
        return IPP_STAGE_RAW;
    } else if (!strcmp("chip", stageStr)) {
        return IPP_STAGE_CHIP;
    } else if (!strcmp("warp", stageStr)) {
        return IPP_STAGE_WARP;
    } else if (!strcmp("diff", stageStr)) {
        return IPP_STAGE_DIFF;
    } else {
        psError(PS_ERR_UNKNOWN, true, "unknown stage string: %s\n", stageStr);
        streaksExit("", PS_EXIT_DATA_ERROR);
        // notreached
        return IPP_STAGE_NONE;
    }
}

// to enhance clarity in these programs we don't propagate errors up the stack
// we just bail out
void streaksExit(psString str, int exitCode) {
    psErrorStackPrint(stderr, str);
    exit(exitCode);
}

