#!/usr/bin/python

import subprocess

indices = []

try:
    f = open("list_of_indices")
    for ln in f:
        indices.append(int(ln))
    f.close()
except:
    pass

ctest = 1
f = open("list_of_tests")
for ln in f:
    if indices is [] or ctest in indices:
        ln = ln.strip()[1:-2]
        name_and_ext = ln.split(".")
        new_test = name_and_ext[0] + "-detect." + name_and_ext[1]
    #    print new_test
        subprocess.call(["rm", "-f", new_test])
        ot = open(ln)
        for l in ot:
            nt = open(new_test, "a")
            nt.write(l)
            nt.close()
            if "--EXPECT--" in l:
                break
            if "--EXPECTF--" in l:
                break
    ctest += 1
