#!/usr/bin/python

# @Martin Kellogg, 2015

import subprocess

subprocess.call(["rm","-f","php-run-neg-tests.c"])
subprocess.call(["touch", "php-run-neg-tests.c"])
f = open("php-run-tests.c")
for ln in f:
    if ln.strip().startswith("\""):
        l = ln.split(".")
        ln2 = l[0]
        for i in range(1, len(l) - 1):
            ln2 += l[i]
        ln = ln2 + "-detect."+l[len(l) - 1]
    if "if (res == 0) {" in ln:
        ln = "if (res != 0) {"
    f2 = open("php-run-neg-tests.c", "a")
    f2.write(ln)
    f2.close()

subprocess.call(["gcc", "-o", "php-run-neg-tests", "php-run-neg-tests.c"])
